author | celestar |
Tue, 13 Feb 2007 12:34:54 +0000 | |
changeset 6321 | 62564548351b |
parent 6317 | c73bda71ac16 |
child 6322 | 3d191e6e89bc |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
3 |
/** @file station_cmd.c */ |
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" |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5568
diff
changeset
|
7 |
#include "bridge_map.h" |
1299
0a6510cc889b
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1295
diff
changeset
|
8 |
#include "debug.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2148
diff
changeset
|
9 |
#include "functions.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
|
10 |
#include "station_map.h" |
1363
01d3de5d8039
(svn r1867) Include tables/sprites.h only in files which need it
tron
parents:
1335
diff
changeset
|
11 |
#include "table/sprites.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
500
diff
changeset
|
12 |
#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
|
13 |
#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
|
14 |
#include "tile.h" |
0 | 15 |
#include "station.h" |
16 |
#include "gfx.h" |
|
17 |
#include "window.h" |
|
18 |
#include "viewport.h" |
|
19 |
#include "command.h" |
|
20 |
#include "town.h" |
|
21 |
#include "vehicle.h" |
|
22 |
#include "news.h" |
|
23 |
#include "saveload.h" |
|
24 |
#include "economy.h" |
|
25 |
#include "player.h" |
|
26 |
#include "airport.h" |
|
405
6830ae7a0d5d
(svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents:
403
diff
changeset
|
27 |
#include "sprite.h" |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
28 |
#include "depot.h" |
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2671
diff
changeset
|
29 |
#include "train.h" |
3111
1edf71aa942e
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3102
diff
changeset
|
30 |
#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
|
31 |
#include "industry_map.h" |
3754
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
32 |
#include "newgrf_callbacks.h" |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
33 |
#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
|
34 |
#include "yapf/yapf.h" |
4261
2ec8f5a9747b
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4231
diff
changeset
|
35 |
#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
|
36 |
#include "helpers.hpp" |
6095
55d5c0e6be3a
(svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents:
6088
diff
changeset
|
37 |
#include "misc/autoptr.hpp" |
5917
e0d30aba24a3
(svn r8126) -Fix (r8125): missing #include fixes compilation error on g++ (still some warnings, working on it)
KUDr
parents:
5916
diff
changeset
|
38 |
|
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
39 |
/** |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
40 |
* 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
|
41 |
*/ |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
42 |
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
|
43 |
{ |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
44 |
Station *st; |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
45 |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
46 |
/* 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
|
47 |
* TODO - This is just a temporary stage, this will be removed. */ |
4980 | 48 |
for (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
|
49 |
} |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
50 |
|
3587 | 51 |
static void StationPoolCleanBlock(uint start_item, uint end_item) |
52 |
{ |
|
53 |
uint i; |
|
54 |
||
55 |
for (i = start_item; i <= end_item; i++) { |
|
56 |
Station *st = GetStation(i); |
|
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
|
57 |
if (IsValidStation(st)) st->~Station(); |
3587 | 58 |
} |
59 |
} |
|
60 |
||
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
61 |
/** |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
62 |
* 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
|
63 |
*/ |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
64 |
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
|
65 |
{ |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
66 |
RoadStop *rs; |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
67 |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
68 |
/* 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
|
69 |
* TODO - This is just a temporary stage, this will be removed. */ |
5969 | 70 |
for (rs = GetRoadStop(start_item); rs != NULL; rs = (rs->index + 1U < GetRoadStopPoolSize()) ? GetRoadStop(rs->index + 1U) : NULL) { |
71 |
rs->xy = INVALID_TILE; |
|
72 |
rs->index = start_item++; |
|
73 |
} |
|
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
74 |
} |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
75 |
|
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
|
76 |
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
|
77 |
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
|
78 |
|
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
79 |
|
0 | 80 |
extern void UpdateAirplanesOnNewStation(Station *st); |
81 |
||
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
82 |
|
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
|
83 |
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
|
84 |
{ |
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
85 |
const Station* st = GetStationByTile(tile); |
2639 | 86 |
RoadStop* rs; |
87 |
||
6127 | 88 |
for (rs = st->GetPrimaryRoadStop(type); rs->xy != tile; rs = rs->next) { |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
89 |
assert(rs->next != NULL); |
2639 | 90 |
} |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
91 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
92 |
return rs; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
93 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
94 |
|
6164 | 95 |
|
96 |
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
|
97 |
{ |
2549 | 98 |
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
|
99 |
const RoadStop *rs; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
100 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
101 |
assert(st != NULL); |
6127 | 102 |
for (rs = st->GetPrimaryRoadStop(type); rs != NULL; rs = rs->next) num++; |
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 |
{ |
5852
cb3f71b16e1a
(svn r8055) -Codechange: Replace the different max, dmax, maxu whatever macros by a simple template function max(), that requires two arguments of the same type. While I'm at it change a variable called "max" to "maxval" in a function that calls max().
celestar
parents:
5838
diff
changeset
|
112 |
CatchmentAera ret = CA_NONE; |
703
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
113 |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
114 |
if (st->bus_stops != NULL) ret = max(ret, CA_BUS); |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
115 |
if (st->truck_stops != NULL) ret = max(ret, CA_TRUCK); |
703
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
116 |
if (st->train_tile) ret = max(ret, CA_TRAIN); |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
117 |
if (st->dock_tile) ret = max(ret, CA_DOCK); |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
118 |
|
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
119 |
if (st->airport_tile) { |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
120 |
switch (st->airport_type) { |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
121 |
case AT_OILRIG: ret = max(ret, CA_AIR_OILPAD); break; |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
122 |
case AT_SMALL: ret = max(ret, CA_AIR_SMALL); break; |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
123 |
case AT_HELIPORT: ret = max(ret, CA_AIR_HELIPORT); break; |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
124 |
case AT_LARGE: ret = max(ret, CA_AIR_LARGE); break; |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
125 |
case AT_METROPOLITAN: ret = max(ret, CA_AIR_METRO); break; |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
126 |
case AT_INTERNATIONAL: ret = max(ret, CA_AIR_INTER); break; |
4059
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
127 |
case AT_COMMUTER: ret = max(ret, CA_AIR_COMMUTER); break; |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
128 |
case AT_HELIDEPOT: ret = max(ret, CA_AIR_HELIDEPOT); break; |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
129 |
case AT_INTERCON: ret = max(ret, CA_AIR_INTERCON); break; |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
130 |
case AT_HELISTATION: ret = max(ret, CA_AIR_HELISTATION); break; |
703
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
131 |
} |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
132 |
} |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
133 |
|
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
134 |
return ret; |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
135 |
} |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
136 |
|
0 | 137 |
#define CHECK_STATIONS_ERR ((Station*)-1) |
138 |
||
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
|
139 |
static Station* GetStationAround(TileIndex tile, int w, int h, StationID closest_station) |
0 | 140 |
{ |
141 |
// check around to see if there's any stations there |
|
1981 | 142 |
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
|
143 |
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
|
144 |
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
|
145 |
{ |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
146 |
Station *st = GetStation(t); |
28
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
147 |
// you cannot take control of an oilrig!! |
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
148 |
if (st->airport_type == AT_OILRIG && st->facilities == (FACIL_AIRPORT|FACIL_DOCK)) |
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
149 |
continue; |
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
150 |
} |
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
151 |
|
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
|
152 |
if (closest_station == INVALID_STATION) { |
0 | 153 |
closest_station = t; |
154 |
} else if (closest_station != t) { |
|
155 |
_error_message = STR_3006_ADJOINS_MORE_THAN_ONE_EXISTING; |
|
156 |
return CHECK_STATIONS_ERR; |
|
157 |
} |
|
158 |
} |
|
1981 | 159 |
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
|
160 |
return (closest_station == INVALID_STATION) ? NULL : GetStation(closest_station); |
0 | 161 |
} |
162 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1078
diff
changeset
|
163 |
static Station *AllocateStation(void) |
0 | 164 |
{ |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
165 |
Station *st = NULL; |
0 | 166 |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
167 |
/* 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
|
168 |
* TODO - This is just a temporary stage, this will be removed. */ |
4980 | 169 |
for (st = GetStation(0); st != NULL; st = (st->index + 1U < GetStationPoolSize()) ? GetStation(st->index + 1U) : NULL) { |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
170 |
if (!IsValidStation(st)) { |
1551
eb05e6a90e67
(svn r2055) -CodeChange: Begun introducting StationID
celestar
parents:
1527
diff
changeset
|
171 |
StationID index = st->index; |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
172 |
|
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
173 |
memset(st, 0, sizeof(Station)); |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
174 |
st->index = index; |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
175 |
return st; |
0 | 176 |
} |
177 |
} |
|
178 |
||
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
179 |
/* Check if we can add a block to the pool */ |
4980 | 180 |
if (AddBlockToPool(&_Station_pool)) return AllocateStation(); |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
181 |
|
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
182 |
_error_message = STR_3008_TOO_MANY_STATIONS_LOADING; |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
183 |
return NULL; |
0 | 184 |
} |
185 |
||
186 |
||
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
|
187 |
/** |
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
|
188 |
* 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
|
189 |
* @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
|
190 |
* @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
|
191 |
* @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
|
192 |
* in all other cases this parameter is ignored |
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
|
193 |
* @result the noumber of matching tiles 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
|
194 |
*/ |
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
|
195 |
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
|
196 |
{ |
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
|
197 |
TileIndex 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
|
198 |
int dx, dy; |
0 | 199 |
int num = 0; |
200 |
||
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
|
201 |
for (dx = -3; dx <= 3; dx++) { |
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
|
202 |
for (dy = -3; dy <= 3; dy++) { |
3682
481e92a35a3e
(svn r4602) - Fix: an assertion triggered when building a station near the south corner of the map (appeared in r4367)
glx
parents:
3676
diff
changeset
|
203 |
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
|
204 |
|
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
|
205 |
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
|
206 |
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
|
207 |
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
|
208 |
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
|
209 |
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
|
210 |
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
|
211 |
|
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
|
212 |
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
|
213 |
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
|
214 |
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
|
215 |
/* 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
|
216 |
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
|
217 |
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
|
218 |
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
|
219 |
|
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
|
220 |
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
|
221 |
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
|
222 |
} |
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
|
223 |
} |
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
|
224 |
} |
0 | 225 |
} |
226 |
||
227 |
return num; |
|
228 |
} |
|
229 |
||
230 |
#define M(x) ((x) - STR_SV_STNAME) |
|
231 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
232 |
static bool GenerateStationName(Station *st, TileIndex tile, int flag) |
0 | 233 |
{ |
234 |
static const uint32 _gen_station_name_bits[] = { |
|
1454 | 235 |
0, /* 0 */ |
236 |
1 << M(STR_SV_STNAME_AIRPORT), /* 1 */ |
|
237 |
1 << M(STR_SV_STNAME_OILFIELD), /* 2 */ |
|
238 |
1 << M(STR_SV_STNAME_DOCKS), /* 3 */ |
|
239 |
0x1FF << M(STR_SV_STNAME_BUOY_1), /* 4 */ |
|
240 |
1 << M(STR_SV_STNAME_HELIPORT), /* 5 */ |
|
0 | 241 |
}; |
242 |
||
243 |
Town *t = st->town; |
|
244 |
uint32 free_names = (uint32)-1; |
|
245 |
int found; |
|
246 |
uint z,z2; |
|
247 |
unsigned long tmp; |
|
248 |
||
249 |
{ |
|
250 |
Station *s; |
|
251 |
||
252 |
FOR_ALL_STATIONS(s) { |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
253 |
if (s != st && s->town==t) { |
0 | 254 |
uint str = M(s->string_id); |
255 |
if (str <= 0x20) { |
|
256 |
if (str == M(STR_SV_STNAME_FOREST)) |
|
257 |
str = M(STR_SV_STNAME_WOODS); |
|
258 |
CLRBIT(free_names, str); |
|
259 |
} |
|
260 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
261 |
} |
0 | 262 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
263 |
|
0 | 264 |
/* check default names */ |
265 |
tmp = free_names & _gen_station_name_bits[flag]; |
|
266 |
if (tmp != 0) { |
|
267 |
found = FindFirstBit(tmp); |
|
268 |
goto done; |
|
269 |
} |
|
270 |
||
271 |
/* check mine? */ |
|
272 |
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
|
273 |
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
|
274 |
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
|
275 |
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
|
276 |
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
|
277 |
CountMapSquareAround(tile, MP_INDUSTRY, IT_DIAMOND_MINE) >= 2) { |
1454 | 278 |
found = M(STR_SV_STNAME_MINES); |
279 |
goto done; |
|
280 |
} |
|
0 | 281 |
} |
282 |
||
283 |
/* check close enough to town to get central as name? */ |
|
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1239
diff
changeset
|
284 |
if (DistanceMax(tile,t->xy) < 8) { |
0 | 285 |
found = M(STR_SV_STNAME); |
286 |
if (HASBIT(free_names, M(STR_SV_STNAME))) goto done; |
|
287 |
||
288 |
found = M(STR_SV_STNAME_CENTRAL); |
|
289 |
if (HASBIT(free_names, M(STR_SV_STNAME_CENTRAL))) goto done; |
|
290 |
} |
|
291 |
||
292 |
/* Check lakeside */ |
|
1472
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
293 |
if (HASBIT(free_names, M(STR_SV_STNAME_LAKESIDE)) && |
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
294 |
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
|
295 |
CountMapSquareAround(tile, MP_WATER, 0) >= 5) { |
1454 | 296 |
found = M(STR_SV_STNAME_LAKESIDE); |
297 |
goto done; |
|
298 |
} |
|
0 | 299 |
|
300 |
/* Check woods */ |
|
1472
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
301 |
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
|
302 |
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
|
303 |
CountMapSquareAround(tile, MP_INDUSTRY, IT_FOREST) >= 2) |
1472
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
304 |
) { |
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
305 |
found = _opt.landscape == LT_DESERT ? |
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
306 |
M(STR_SV_STNAME_FOREST) : M(STR_SV_STNAME_WOODS); |
1454 | 307 |
goto done; |
0 | 308 |
} |
309 |
||
310 |
/* check elevation compared to town */ |
|
311 |
z = GetTileZ(tile); |
|
312 |
z2 = GetTileZ(t->xy); |
|
313 |
if (z < z2) { |
|
314 |
found = M(STR_SV_STNAME_VALLEY); |
|
315 |
if (HASBIT(free_names, M(STR_SV_STNAME_VALLEY))) goto done; |
|
316 |
} else if (z > z2) { |
|
317 |
found = M(STR_SV_STNAME_HEIGHTS); |
|
318 |
if (HASBIT(free_names, M(STR_SV_STNAME_HEIGHTS))) goto done; |
|
319 |
} |
|
320 |
||
321 |
/* check direction compared to town */ |
|
322 |
{ |
|
323 |
static const int8 _direction_and_table[] = { |
|
324 |
~( (1<<M(STR_SV_STNAME_WEST)) | (1<<M(STR_SV_STNAME_EAST)) | (1<<M(STR_SV_STNAME_NORTH)) ), |
|
325 |
~( (1<<M(STR_SV_STNAME_SOUTH)) | (1<<M(STR_SV_STNAME_WEST)) | (1<<M(STR_SV_STNAME_NORTH)) ), |
|
326 |
~( (1<<M(STR_SV_STNAME_SOUTH)) | (1<<M(STR_SV_STNAME_EAST)) | (1<<M(STR_SV_STNAME_NORTH)) ), |
|
327 |
~( (1<<M(STR_SV_STNAME_SOUTH)) | (1<<M(STR_SV_STNAME_WEST)) | (1<<M(STR_SV_STNAME_EAST)) ), |
|
328 |
}; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
329 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
330 |
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
|
331 |
(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
|
332 |
(TileY(tile) < TileY(t->xy)) * 2]; |
0 | 333 |
} |
334 |
||
335 |
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)); |
|
336 |
if (tmp == 0) { |
|
337 |
_error_message = STR_3007_TOO_MANY_STATIONS_LOADING; |
|
338 |
return false; |
|
339 |
} |
|
340 |
found = FindFirstBit(tmp); |
|
341 |
||
342 |
done: |
|
343 |
st->string_id = found + STR_SV_STNAME; |
|
344 |
return true; |
|
345 |
} |
|
346 |
#undef M |
|
347 |
||
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
|
348 |
static Station* GetClosestStationFromTile(TileIndex tile, uint threshold, PlayerID owner) |
0 | 349 |
{ |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
350 |
Station* best_station = NULL; |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
351 |
Station* st; |
0 | 352 |
|
353 |
FOR_ALL_STATIONS(st) { |
|
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4638
diff
changeset
|
354 |
if ((owner == PLAYER_SPECTATOR || st->owner == owner)) { |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
355 |
uint cur_dist = DistanceManhattan(tile, st->xy); |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
356 |
|
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
357 |
if (cur_dist < threshold) { |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
358 |
threshold = cur_dist; |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
359 |
best_station = st; |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
360 |
} |
0 | 361 |
} |
362 |
} |
|
363 |
||
364 |
return best_station; |
|
365 |
} |
|
366 |
||
367 |
// Update the virtual coords needed to draw the station sign. |
|
368 |
// st = Station to update for. |
|
369 |
static void UpdateStationVirtCoord(Station *st) |
|
370 |
{ |
|
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
|
371 |
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
|
372 |
|
0 | 373 |
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
|
374 |
if (st->facilities & FACIL_AIRPORT && st->airport_type == AT_OILRIG) pt.y -= 16; |
0 | 375 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
376 |
SetDParam(0, st->index); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
377 |
SetDParam(1, st->facilities); |
0 | 378 |
UpdateViewportSignPos(&st->sign, pt.x, pt.y, STR_305C_0); |
379 |
} |
|
380 |
||
381 |
// Update the virtual coords needed to draw the station sign for all stations. |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1078
diff
changeset
|
382 |
void UpdateAllStationVirtCoord(void) |
0 | 383 |
{ |
2639 | 384 |
Station* st; |
385 |
||
0 | 386 |
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
|
387 |
UpdateStationVirtCoord(st); |
0 | 388 |
} |
389 |
} |
|
390 |
||
391 |
// Update the station virt coords while making the modified parts dirty. |
|
392 |
static void UpdateStationVirtCoordDirty(Station *st) |
|
393 |
{ |
|
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
|
394 |
st->MarkDirty(); |
0 | 395 |
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
|
396 |
st->MarkDirty(); |
0 | 397 |
} |
398 |
||
399 |
// 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
|
400 |
static uint GetAcceptanceMask(const Station *st) |
0 | 401 |
{ |
402 |
uint mask = 0; |
|
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
403 |
uint i; |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
404 |
|
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
405 |
for (i = 0; i != NUM_CARGO; i++) { |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
406 |
if (st->goods[i].waiting_acceptance & 0x8000) mask |= 1 << i; |
0 | 407 |
} |
408 |
return mask; |
|
409 |
} |
|
410 |
||
411 |
// Items contains the two cargo names that are to be accepted or rejected. |
|
412 |
// 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
|
413 |
static void ShowRejectOrAcceptNews(const Station *st, uint num_items, CargoID *cargo, StringID msg) |
0 | 414 |
{ |
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
|
415 |
for (uint i = 0; i < num_items; 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
|
416 |
SetDParam(i + 1, _cargoc.names_s[cargo[i]]); |
0 | 417 |
} |
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
|
418 |
|
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
|
419 |
SetDParam(0, st->index); |
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
|
420 |
AddNewsItem(msg, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_TILE, NT_ACCEPTANCE, 0), st->xy, 0); |
0 | 421 |
} |
422 |
||
423 |
// 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
|
424 |
void GetProductionAroundTiles(AcceptedCargo produced, TileIndex tile, |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
425 |
int w, int h, int rad) |
0 | 426 |
{ |
427 |
int x,y; |
|
428 |
int x1,y1,x2,y2; |
|
429 |
int xc,yc; |
|
430 |
||
2133 | 431 |
memset(produced, 0, sizeof(AcceptedCargo)); |
0 | 432 |
|
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
|
433 |
x = 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
|
434 |
y = TileY(tile); |
0 | 435 |
|
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
436 |
// expand the region by rad tiles on each side |
0 | 437 |
// while making sure that we remain inside the board. |
856
07dc27d0503e
(svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents:
847
diff
changeset
|
438 |
x2 = min(x + w + rad, MapSizeX()); |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
439 |
x1 = max(x - rad, 0); |
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
440 |
|
856
07dc27d0503e
(svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents:
847
diff
changeset
|
441 |
y2 = min(y + h + rad, MapSizeY()); |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
442 |
y1 = max(y - rad, 0); |
0 | 443 |
|
444 |
assert(x1 < x2); |
|
445 |
assert(y1 < y2); |
|
446 |
assert(w > 0); |
|
447 |
assert(h > 0); |
|
448 |
||
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
449 |
for (yc = y1; yc != y2; yc++) { |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
450 |
for (xc = x1; xc != x2; xc++) { |
0 | 451 |
if (!(IS_INSIDE_1D(xc, x, w) && IS_INSIDE_1D(yc, y, h))) { |
452 |
GetProducedCargoProc *gpc; |
|
1981 | 453 |
TileIndex tile = TileXY(xc, yc); |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
454 |
|
1214
33e07bbb7779
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1209
diff
changeset
|
455 |
gpc = _tile_type_procs[GetTileType(tile)]->get_produced_cargo_proc; |
0 | 456 |
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
|
457 |
CargoID cargos[2] = { CT_INVALID, CT_INVALID }; |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
458 |
|
0 | 459 |
gpc(tile, cargos); |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
460 |
if (cargos[0] != CT_INVALID) { |
0 | 461 |
produced[cargos[0]]++; |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
462 |
if (cargos[1] != CT_INVALID) { |
0 | 463 |
produced[cargos[1]]++; |
464 |
} |
|
465 |
} |
|
466 |
} |
|
467 |
} |
|
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
468 |
} |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
469 |
} |
0 | 470 |
} |
471 |
||
472 |
// 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
|
473 |
void GetAcceptanceAroundTiles(AcceptedCargo accepts, TileIndex tile, |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
474 |
int w, int h, int rad) |
0 | 475 |
{ |
476 |
int x,y; |
|
477 |
int x1,y1,x2,y2; |
|
478 |
int xc,yc; |
|
473
0da86c59e3ae
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
457
diff
changeset
|
479 |
|
0da86c59e3ae
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
457
diff
changeset
|
480 |
memset(accepts, 0, sizeof(AcceptedCargo)); |
0 | 481 |
|
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
|
482 |
x = 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
|
483 |
y = TileY(tile); |
0 | 484 |
|
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
485 |
// expand the region by rad tiles on each side |
0 | 486 |
// while making sure that we remain inside the board. |
856
07dc27d0503e
(svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents:
847
diff
changeset
|
487 |
x2 = min(x + w + rad, MapSizeX()); |
07dc27d0503e
(svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents:
847
diff
changeset
|
488 |
y2 = min(y + h + rad, MapSizeY()); |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
489 |
x1 = max(x - rad, 0); |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
490 |
y1 = max(y - rad, 0); |
0 | 491 |
|
492 |
assert(x1 < x2); |
|
493 |
assert(y1 < y2); |
|
494 |
assert(w > 0); |
|
495 |
assert(h > 0); |
|
496 |
||
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
497 |
for (yc = y1; yc != y2; yc++) { |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
498 |
for (xc = x1; xc != x2; xc++) { |
1981 | 499 |
TileIndex tile = TileXY(xc, yc); |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
500 |
|
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
|
501 |
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
|
502 |
AcceptedCargo ac; |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
503 |
uint i; |
473
0da86c59e3ae
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
457
diff
changeset
|
504 |
|
0da86c59e3ae
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
457
diff
changeset
|
505 |
GetAcceptedCargo(tile, ac); |
2639 | 506 |
for (i = 0; i < lengthof(ac); ++i) accepts[i] += ac[i]; |
0 | 507 |
} |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
508 |
} |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
509 |
} |
0 | 510 |
} |
511 |
||
2793
d613eb566917
(svn r3341) -Codechange: make mingw32 happy, and renamed Rectangle, because it already exists on that platform
truelight
parents:
2767
diff
changeset
|
512 |
typedef 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
|
513 |
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
|
514 |
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
|
515 |
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
|
516 |
uint max_y; |
2793
d613eb566917
(svn r3341) -Codechange: make mingw32 happy, and renamed Rectangle, because it already exists on that platform
truelight
parents:
2767
diff
changeset
|
517 |
} ottd_Rectangle; |
d613eb566917
(svn r3341) -Codechange: make mingw32 happy, and renamed Rectangle, because it already exists on that platform
truelight
parents:
2767
diff
changeset
|
518 |
|
5103
db210d789741
(svn r7174) -CodeChange: CheckStationSpreadOut() now uses MergePoint() for bounding rectangle calculation.
KUDr
parents:
5098
diff
changeset
|
519 |
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
|
520 |
{ |
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 |
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
|
522 |
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
|
523 |
|
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 |
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
|
525 |
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
|
526 |
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
|
527 |
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
|
528 |
} |
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
|
529 |
|
0 | 530 |
// Update the acceptance for a station. |
531 |
// show_msg controls whether to display a message that acceptance was changed. |
|
532 |
static void UpdateStationAcceptance(Station *st, bool show_msg) |
|
533 |
{ |
|
534 |
uint old_acc, new_acc; |
|
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
|
535 |
const RoadStop *cur_rs; |
0 | 536 |
int i; |
2793
d613eb566917
(svn r3341) -Codechange: make mingw32 happy, and renamed Rectangle, because it already exists on that platform
truelight
parents:
2767
diff
changeset
|
537 |
ottd_Rectangle rect; |
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
|
538 |
int rad; |
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
|
539 |
AcceptedCargo accepts; |
0 | 540 |
|
1507
2d09b13f049f
(svn r2011) - Fix: [ 1162209 ] Fix OS/2 build (orudge) #2
darkvater
parents:
1477
diff
changeset
|
541 |
rect.min_x = MapSizeX(); |
2d09b13f049f
(svn r2011) - Fix: [ 1162209 ] Fix OS/2 build (orudge) #2
darkvater
parents:
1477
diff
changeset
|
542 |
rect.min_y = MapSizeY(); |
2d09b13f049f
(svn r2011) - Fix: [ 1162209 ] Fix OS/2 build (orudge) #2
darkvater
parents:
1477
diff
changeset
|
543 |
rect.max_x = rect.max_y = 0; |
0 | 544 |
// Don't update acceptance for a buoy |
6147
2345f00d2a33
(svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents:
6141
diff
changeset
|
545 |
if (st->IsBuoy()) return; |
0 | 546 |
|
547 |
/* old accepted goods types */ |
|
548 |
old_acc = GetAcceptanceMask(st); |
|
549 |
||
550 |
// Put all the tiles that span an area in the table. |
|
551 |
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
|
552 |
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
|
553 |
MergePoint(&rect, |
1981 | 554 |
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
|
555 |
); |
0 | 556 |
} |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
557 |
|
0 | 558 |
if (st->airport_tile != 0) { |
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
|
559 |
const AirportFTAClass* afc = GetAirport(st->airport_type); |
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
|
560 |
|
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
|
561 |
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
|
562 |
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
|
563 |
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
|
564 |
); |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
565 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
566 |
|
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
|
567 |
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
|
568 |
|
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
|
569 |
for (cur_rs = st->bus_stops; cur_rs != NULL; cur_rs = cur_rs->next) { |
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
|
570 |
MergePoint(&rect, cur_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
|
571 |
} |
0 | 572 |
|
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
|
573 |
for (cur_rs = st->truck_stops; cur_rs != NULL; cur_rs = cur_rs->next) { |
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
|
574 |
MergePoint(&rect, cur_rs->xy); |
0 | 575 |
} |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
576 |
|
2631
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
577 |
rad = (_patches.modified_catchment) ? FindCatchmentRadius(st) : 4; |
0 | 578 |
|
579 |
// And retrieve the acceptance. |
|
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
|
580 |
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
|
581 |
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
|
582 |
accepts, |
1981 | 583 |
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
|
584 |
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
|
585 |
rect.max_y - rect.min_y + 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
|
586 |
rad |
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
|
587 |
); |
0 | 588 |
} else { |
589 |
memset(accepts, 0, sizeof(accepts)); |
|
590 |
} |
|
591 |
||
592 |
// Adjust in case our station only accepts fewer kinds of goods |
|
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
593 |
for (i = 0; i != NUM_CARGO; i++) { |
0 | 594 |
uint amt = min(accepts[i], 15); |
595 |
||
596 |
// Make sure the station can accept the goods type. |
|
597 |
if ((i != CT_PASSENGERS && !(st->facilities & (byte)~FACIL_BUS_STOP)) || |
|
598 |
(i == CT_PASSENGERS && !(st->facilities & (byte)~FACIL_TRUCK_STOP))) |
|
599 |
amt = 0; |
|
600 |
||
2504
7c27fc230cda
(svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents:
2502
diff
changeset
|
601 |
SB(st->goods[i].waiting_acceptance, 12, 4, amt); |
0 | 602 |
} |
603 |
||
604 |
// Only show a message in case the acceptance was actually changed. |
|
605 |
new_acc = GetAcceptanceMask(st); |
|
606 |
if (old_acc == new_acc) |
|
607 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
608 |
|
0 | 609 |
// show a message to report that the acceptance was changed? |
610 |
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
|
611 |
/* 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
|
612 |
* 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
|
613 |
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
|
614 |
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
|
615 |
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
|
616 |
}; |
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
|
617 |
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
|
618 |
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
|
619 |
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
|
620 |
}; |
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
|
621 |
|
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
|
622 |
/* 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
|
623 |
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
|
624 |
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
|
625 |
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
|
626 |
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
|
627 |
|
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
|
628 |
/* 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
|
629 |
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
|
630 |
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
|
631 |
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
|
632 |
/* 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
|
633 |
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
|
634 |
} |
0 | 635 |
} 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
|
636 |
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
|
637 |
/* 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
|
638 |
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
|
639 |
} |
0 | 640 |
} |
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
|
641 |
} |
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
|
642 |
|
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
|
643 |
/* 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
|
644 |
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
|
645 |
if (num_rej > 0) ShowRejectOrAcceptNews(st, num_rej, rejects, reject_msg[num_rej - 1]); |
0 | 646 |
} |
647 |
||
648 |
// redraw the station view since acceptance changed |
|
649 |
InvalidateWindowWidget(WC_STATION_VIEW, st->index, 4); |
|
650 |
} |
|
651 |
||
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
|
652 |
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
|
653 |
{ |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
654 |
StationRect *r = &st->rect; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
655 |
|
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
656 |
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
|
657 |
|
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
|
658 |
// 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
|
659 |
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
|
660 |
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
|
661 |
} |
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
|
662 |
|
0 | 663 |
// This is called right after a station was deleted. |
664 |
// It checks if the whole station is free of substations, and if so, the station will be |
|
665 |
// deleted after a little while. |
|
2639 | 666 |
static void DeleteStationIfEmpty(Station* st) |
667 |
{ |
|
0 | 668 |
if (st->facilities == 0) { |
669 |
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
|
670 |
RebuildStationLists(); |
28
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
671 |
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
|
672 |
} |
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
|
673 |
/* 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
|
674 |
UpdateStationSignCoord(st); |
0 | 675 |
} |
676 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
677 |
static int32 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
|
678 |
|
0 | 679 |
// Tries to clear the given area. Returns the cost in case of success. |
680 |
// Or an error code if it failed. |
|
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
|
681 |
int32 CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invalid_dirs, StationID* station) |
0 | 682 |
{ |
683 |
int32 cost = 0, ret; |
|
684 |
||
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
685 |
Slope tileh; |
1335
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1328
diff
changeset
|
686 |
uint z; |
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1328
diff
changeset
|
687 |
int allowed_z = -1; |
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1328
diff
changeset
|
688 |
int flat_z; |
0 | 689 |
|
690 |
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
|
691 |
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
|
692 |
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
|
693 |
} |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5568
diff
changeset
|
694 |
|
2639 | 695 |
if (!EnsureNoVehicle(tile_cur)) return CMD_ERROR; |
0 | 696 |
|
697 |
tileh = GetTileSlope(tile_cur, &z); |
|
698 |
||
2085
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
699 |
/* Prohibit building if |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
700 |
* 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
|
701 |
* -OR- |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
702 |
* 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
|
703 |
* 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
|
704 |
* -OR- |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
705 |
* 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
|
706 |
*/ |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
707 |
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
|
708 |
((_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
|
709 |
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
0 | 710 |
} |
711 |
||
712 |
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
|
713 |
if (tileh != SLOPE_FLAT) { |
0 | 714 |
// need to check so the entrance to the station is not pointing at a slope. |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
715 |
if ((invalid_dirs&1 && !(tileh & SLOPE_NE) && (uint)w_cur == w) || |
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
|
716 |
(invalid_dirs&2 && !(tileh & SLOPE_SE) && h_cur == 1) || |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
717 |
(invalid_dirs&4 && !(tileh & SLOPE_SW) && w_cur == 1) || |
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
718 |
(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
|
719 |
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
0 | 720 |
} |
721 |
cost += _price.terraform; |
|
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
722 |
flat_z += TILE_HEIGHT; |
0 | 723 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
724 |
|
0 | 725 |
// get corresponding flat level and make sure that all parts of the station have the same level. |
726 |
if (allowed_z == -1) { |
|
727 |
// first tile |
|
728 |
allowed_z = flat_z; |
|
729 |
} else if (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
|
730 |
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
0 | 731 |
} |
732 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
733 |
// if station is set, then we have special handling to allow building on top of already existing stations. |
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
|
734 |
// so station points to INVALID_STATION if we can build on any station. or it points to a station if we're only allowed to build |
0 | 735 |
// on exactly that station. |
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
|
736 |
if (station != NULL && IsTileType(tile_cur, MP_STATION)) { |
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
737 |
if (!IsRailwayStation(tile_cur)) { |
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
|
738 |
return ClearTile_Station(tile_cur, DC_AUTO); // get error message |
0 | 739 |
} 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
|
740 |
StationID st = GetStationIndex(tile_cur); |
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
|
741 |
if (*station == INVALID_STATION) { |
0 | 742 |
*station = st; |
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
|
743 |
} else if (*station != st) { |
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
|
744 |
return_cmd_error(STR_3006_ADJOINS_MORE_THAN_ONE_EXISTING); |
0 | 745 |
} |
746 |
} |
|
747 |
} else { |
|
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
|
748 |
ret = DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
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
|
749 |
if (CmdFailed(ret)) return ret; |
0 | 750 |
cost += ret; |
751 |
} |
|
752 |
END_TILE_LOOP(tile_cur, w, h, tile) |
|
753 |
||
754 |
return cost; |
|
755 |
} |
|
756 |
||
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
757 |
static bool CanExpandRailroadStation(Station* st, uint* fin, Axis axis) |
0 | 758 |
{ |
759 |
uint curw = st->trainst_w, curh = st->trainst_h; |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
760 |
TileIndex tile = fin[0]; |
0 | 761 |
uint w = fin[1]; |
762 |
uint h = fin[2]; |
|
763 |
||
764 |
if (_patches.nonuniform_stations) { |
|
765 |
// 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
|
766 |
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
|
767 |
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
|
768 |
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
|
769 |
curh = max(TileY(st->train_tile) + curh, TileY(tile) + h) - y; |
1981 | 770 |
tile = TileXY(x, y); |
0 | 771 |
} else { |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
772 |
// 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
|
773 |
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
|
774 |
_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
|
775 |
return false; |
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
776 |
} |
0 | 777 |
|
778 |
// check if the new station adjoins the old station in either direction |
|
1981 | 779 |
if (curw == w && st->train_tile == tile + TileDiffXY(0, h)) { |
0 | 780 |
// above |
781 |
curh += h; |
|
1981 | 782 |
} else if (curw == w && st->train_tile == tile - TileDiffXY(0, curh)) { |
0 | 783 |
// below |
1981 | 784 |
tile -= TileDiffXY(0, curh); |
0 | 785 |
curh += h; |
1981 | 786 |
} else if (curh == h && st->train_tile == tile + TileDiffXY(w, 0)) { |
0 | 787 |
// to the left |
788 |
curw += w; |
|
1981 | 789 |
} else if (curh == h && st->train_tile == tile - TileDiffXY(curw, 0)) { |
0 | 790 |
// to the right |
1981 | 791 |
tile -= TileDiffXY(curw, 0); |
0 | 792 |
curw += w; |
1189
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
793 |
} else { |
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
794 |
_error_message = STR_306D_NONUNIFORM_STATIONS_DISALLOWED; |
0 | 795 |
return false; |
1189
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
796 |
} |
0 | 797 |
} |
798 |
// 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
|
799 |
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
|
800 |
_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
|
801 |
return false; |
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
802 |
} |
0 | 803 |
|
804 |
// now tile contains the new value for st->train_tile |
|
805 |
// curw, curh contain the new value for width and height |
|
806 |
fin[0] = tile; |
|
807 |
fin[1] = curw; |
|
808 |
fin[2] = curh; |
|
809 |
return true; |
|
810 |
} |
|
811 |
||
536 | 812 |
static inline byte *CreateSingle(byte *layout, int n) |
0 | 813 |
{ |
814 |
int i = n; |
|
815 |
do *layout++ = 0; while (--i); |
|
816 |
layout[((n-1) >> 1)-n] = 2; |
|
817 |
return layout; |
|
818 |
} |
|
819 |
||
536 | 820 |
static inline byte *CreateMulti(byte *layout, int n, byte b) |
0 | 821 |
{ |
822 |
int i = n; |
|
823 |
do *layout++ = b; while (--i); |
|
824 |
if (n > 4) { |
|
825 |
layout[0-n] = 0; |
|
826 |
layout[n-1-n] = 0; |
|
827 |
} |
|
828 |
return layout; |
|
829 |
} |
|
830 |
||
3676
48444d881fbe
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3657
diff
changeset
|
831 |
static void GetStationLayout(byte *layout, int numtracks, int plat_len, const StationSpec *statspec) |
0 | 832 |
{ |
3676
48444d881fbe
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3657
diff
changeset
|
833 |
if (statspec != NULL && statspec->lengths >= plat_len && |
48444d881fbe
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3657
diff
changeset
|
834 |
statspec->platforms[plat_len - 1] >= numtracks && |
48444d881fbe
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3657
diff
changeset
|
835 |
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
|
836 |
/* Custom layout defined, follow it. */ |
3676
48444d881fbe
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3657
diff
changeset
|
837 |
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
|
838 |
plat_len * numtracks); |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
839 |
return; |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
840 |
} |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
841 |
|
0 | 842 |
if (plat_len == 1) { |
843 |
CreateSingle(layout, numtracks); |
|
844 |
} else { |
|
2639 | 845 |
if (numtracks & 1) layout = CreateSingle(layout, plat_len); |
846 |
numtracks >>= 1; |
|
0 | 847 |
|
848 |
while (--numtracks >= 0) { |
|
849 |
layout = CreateMulti(layout, plat_len, 4); |
|
850 |
layout = CreateMulti(layout, plat_len, 6); |
|
851 |
} |
|
852 |
} |
|
853 |
} |
|
854 |
||
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
|
855 |
/** 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
|
856 |
* @param tile_org starting position of station dragging/placement |
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
|
857 |
* @param p1 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
|
858 |
* - p1 = (bit 0) - orientation (p1 & 1) |
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
|
859 |
* - 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
|
860 |
* - p1 = (bit 16-23) - platform length |
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
|
861 |
* @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
|
862 |
* - p2 = (bit 0- 3) - railtype (p2 & 0xF) |
3587 | 863 |
* - p2 = (bit 8-15) - custom station class |
864 |
* - p2 = (bit 16-23) - custom station id |
|
0 | 865 |
*/ |
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
|
866 |
int32 CmdBuildRailroadStation(TileIndex tile_org, uint32 flags, uint32 p1, uint32 p2) |
0 | 867 |
{ |
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
|
868 |
Station *st; |
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
|
869 |
int w_org, h_org; |
0 | 870 |
int32 cost, ret; |
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
|
871 |
StationID est; |
0 | 872 |
int plat_len, numtracks; |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
873 |
Axis axis; |
0 | 874 |
uint finalvalues[3]; |
3587 | 875 |
const StationSpec *statspec; |
876 |
int specindex; |
|
0 | 877 |
|
878 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
879 |
||
880 |
/* 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
|
881 |
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
|
882 |
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
|
883 |
|
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
|
884 |
/* unpack parameters */ |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
885 |
axis = (Axis)(p1 & 1); |
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
|
886 |
numtracks = GB(p1, 8, 8); |
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
|
887 |
plat_len = GB(p1, 16, 8); |
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
|
888 |
/* w = length, h = num_tracks */ |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
889 |
if (axis == AXIS_X) { |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
890 |
w_org = plat_len; |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
891 |
h_org = numtracks; |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
892 |
} 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
|
893 |
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
|
894 |
w_org = numtracks; |
0 | 895 |
} |
896 |
||
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
|
897 |
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
|
898 |
|
0 | 899 |
// these values are those that will be stored in train_tile and station_platforms |
900 |
finalvalues[0] = tile_org; |
|
901 |
finalvalues[1] = w_org; |
|
902 |
finalvalues[2] = h_org; |
|
903 |
||
904 |
// Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station) |
|
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
|
905 |
est = INVALID_STATION; |
313
6660bb7b38f1
(svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents:
243
diff
changeset
|
906 |
// 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
|
907 |
// 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
|
908 |
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
|
909 |
if (CmdFailed(ret)) return ret; |
0 | 910 |
cost = ret + (numtracks * _price.train_station_track + _price.train_station_length) * plat_len; |
911 |
||
912 |
// Make sure there are no similar stations around us. |
|
913 |
st = GetStationAround(tile_org, w_org, h_org, est); |
|
914 |
if (st == CHECK_STATIONS_ERR) return CMD_ERROR; |
|
915 |
||
916 |
// See if there is a deleted station close to us. |
|
917 |
if (st == NULL) { |
|
918 |
st = GetClosestStationFromTile(tile_org, 8, _current_player); |
|
919 |
if (st != NULL && st->facilities) st = NULL; |
|
920 |
} |
|
921 |
||
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
|
922 |
/* 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
|
923 |
* 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
|
924 |
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
|
925 |
|
0 | 926 |
if (st != NULL) { |
927 |
// Reuse an existing station. |
|
928 |
if (st->owner != OWNER_NONE && st->owner != _current_player) |
|
929 |
return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION); |
|
930 |
||
931 |
if (st->train_tile != 0) { |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
71
diff
changeset
|
932 |
// 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
|
933 |
if (_is_old_ai_player || !_patches.join_stations) |
0 | 934 |
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
|
935 |
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
|
936 |
return CMD_ERROR; |
0 | 937 |
} |
938 |
||
1189
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
939 |
//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
|
940 |
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
|
941 |
} 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
|
942 |
/* 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
|
943 |
st = new Station(tile_org); |
2639 | 944 |
if (st == NULL) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
945 |
|
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
|
946 |
/* 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
|
947 |
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
|
948 |
|
0 | 949 |
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
|
950 |
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
|
951 |
|
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
|
952 |
if (IsValidPlayer(_current_player) && (flags & DC_EXEC) != 0) { |
0 | 953 |
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
|
954 |
} |
0 | 955 |
} |
956 |
||
3587 | 957 |
/* Check if the given station class is valid */ |
958 |
if (GB(p2, 8, 8) >= STAT_CLASS_MAX) return CMD_ERROR; |
|
959 |
||
960 |
/* Check if we can allocate a custom stationspec to this station */ |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
961 |
statspec = GetCustomStationSpec((StationClassID)GB(p2, 8, 8), GB(p2, 16, 8)); |
3587 | 962 |
specindex = AllocateSpecToStation(statspec, st, flags & DC_EXEC); |
963 |
if (specindex == -1) return CMD_ERROR; |
|
964 |
||
3754
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
965 |
if (statspec != NULL) { |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
966 |
/* Perform NewStation checks */ |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
967 |
|
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
968 |
/* Check if the station size is permitted */ |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
969 |
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
|
970 |
return CMD_ERROR; |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
971 |
} |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
972 |
|
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
973 |
/* Check if the station is buildable */ |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
974 |
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
|
975 |
return CMD_ERROR; |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
976 |
} |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
977 |
} |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
978 |
|
0 | 979 |
if (flags & DC_EXEC) { |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
980 |
TileIndexDiff tile_delta; |
0 | 981 |
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
|
982 |
byte numtracks_orig; |
2824
a7a9d3239884
(svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents:
2817
diff
changeset
|
983 |
Track track; |
0 | 984 |
|
313
6660bb7b38f1
(svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents:
243
diff
changeset
|
985 |
// 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
|
986 |
// 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
|
987 |
// (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
|
988 |
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
|
989 |
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
|
990 |
|
0 | 991 |
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
|
992 |
st->AddFacility(FACIL_TRAIN, finalvalues[0]); |
0 | 993 |
|
994 |
st->trainst_w = finalvalues[1]; |
|
995 |
st->trainst_h = finalvalues[2]; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
996 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
997 |
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
|
998 |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
999 |
tile_delta = (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); |
4158 | 1000 |
track = AxisToTrack(axis); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1001 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1002 |
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
|
1003 |
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
|
1004 |
|
3769
2fd087fd336f
(svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents:
3766
diff
changeset
|
1005 |
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
|
1006 |
|
0 | 1007 |
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
|
1008 |
TileIndex tile = tile_org; |
0 | 1009 |
int w = plat_len; |
1010 |
do { |
|
3769
2fd087fd336f
(svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents:
3766
diff
changeset
|
1011 |
byte layout = *layout_ptr++; |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1012 |
MakeRailStation(tile, st->owner, st->index, axis, layout, (RailType)GB(p2, 0, 4)); |
3587 | 1013 |
SetCustomStationSpecIndex(tile, specindex); |
3742
8528d7737361
(svn r4724) - Newstations: Add per-tile random data for station tiles.
peter1138
parents:
3741
diff
changeset
|
1014 |
SetStationTileRandomBits(tile, GB(Random(), 0, 4)); |
0 | 1015 |
|
3754
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
1016 |
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
|
1017 |
/* 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
|
1018 |
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
|
1019 |
uint16 callback = GetStationCallback(CBID_STATION_TILE_LAYOUT, platinfo, 0, statspec, st, tile); |
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
|
1020 |
if (callback != CALLBACK_FAILED && callback < 8) SetStationGfx(tile, callback + axis); |
3754
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
1021 |
} |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
1022 |
|
0 | 1023 |
tile += tile_delta; |
1024 |
} while (--w); |
|
2824
a7a9d3239884
(svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents:
2817
diff
changeset
|
1025 |
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
|
1026 |
YapfNotifyTrackLayoutChange(tile_org, track); |
1981 | 1027 |
tile_org += tile_delta ^ TileDiffXY(1, 1); // perpendicular to tile_delta |
0 | 1028 |
} while (--numtracks); |
1029 |
||
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
|
1030 |
st->MarkTilesDirty(); |
0 | 1031 |
UpdateStationVirtCoordDirty(st); |
1032 |
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
|
1033 |
RebuildStationLists(); |
0 | 1034 |
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
|
1035 |
/* success, so don't delete the new station */ |
6095
55d5c0e6be3a
(svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents:
6088
diff
changeset
|
1036 |
st_auto_delete.Release(); |
0 | 1037 |
} |
1038 |
||
1039 |
return cost; |
|
1040 |
} |
|
1041 |
||
1042 |
static void MakeRailwayStationAreaSmaller(Station *st) |
|
1043 |
{ |
|
1044 |
uint w = st->trainst_w; |
|
1045 |
uint h = st->trainst_h; |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1046 |
TileIndex tile = st->train_tile; |
0 | 1047 |
uint i; |
1048 |
||
1049 |
restart: |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1050 |
|
0 | 1051 |
// too small? |
1052 |
if (w != 0 && h != 0) { |
|
1053 |
// check the left side, x = constant, y changes |
|
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
|
1054 |
for (i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(0, i));) { |
0 | 1055 |
// the left side is unused? |
1981 | 1056 |
if (++i == h) { |
1057 |
tile += TileDiffXY(1, 0); |
|
1058 |
w--; |
|
1059 |
goto restart; |
|
1060 |
} |
|
1061 |
} |
|
0 | 1062 |
|
1063 |
// check the right side, x = constant, y changes |
|
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
|
1064 |
for (i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(w - 1, i));) { |
0 | 1065 |
// the right side is unused? |
1981 | 1066 |
if (++i == h) { |
1067 |
w--; |
|
1068 |
goto restart; |
|
1069 |
} |
|
1070 |
} |
|
0 | 1071 |
|
1072 |
// check the upper side, y = constant, x changes |
|
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
|
1073 |
for (i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(i, 0));) { |
0 | 1074 |
// the left side is unused? |
1981 | 1075 |
if (++i == w) { |
1076 |
tile += TileDiffXY(0, 1); |
|
1077 |
h--; |
|
1078 |
goto restart; |
|
1079 |
} |
|
1080 |
} |
|
0 | 1081 |
|
1082 |
// check the lower side, y = constant, x changes |
|
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
|
1083 |
for (i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(i, h - 1));) { |
0 | 1084 |
// the left side is unused? |
1981 | 1085 |
if (++i == w) { |
1086 |
h--; |
|
1087 |
goto restart; |
|
1088 |
} |
|
1089 |
} |
|
0 | 1090 |
} else { |
1091 |
tile = 0; |
|
1092 |
} |
|
1093 |
||
1094 |
st->trainst_w = w; |
|
1095 |
st->trainst_h = h; |
|
1096 |
st->train_tile = tile; |
|
1097 |
} |
|
1098 |
||
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1099 |
/** Remove a single tile from a railroad station. |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1100 |
* 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
|
1101 |
* @param tile tile of station piece to remove |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1102 |
* @param p1 unused |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1103 |
* @param p2 unused |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1104 |
*/ |
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
|
1105 |
int32 CmdRemoveFromRailroadStation(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1106 |
{ |
1107 |
Station *st; |
|
1108 |
||
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
|
1109 |
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
|
1110 |
|
0 | 1111 |
// make sure the specified tile belongs to the current player, and that it is a railroad station. |
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1112 |
if (!IsTileType(tile, MP_STATION) || !IsRailwayStation(tile) || !_patches.nonuniform_stations) return CMD_ERROR; |
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
1113 |
st = GetStationByTile(tile); |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
123
diff
changeset
|
1114 |
if (_current_player != OWNER_WATER && (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile))) return CMD_ERROR; |
0 | 1115 |
|
1116 |
// if we reached here, it means we can actually delete it. do that. |
|
1117 |
if (flags & DC_EXEC) { |
|
3587 | 1118 |
uint specindex = GetCustomStationSpecIndex(tile); |
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1119 |
Track track = GetRailStationTrack(tile); |
0 | 1120 |
DoClearSquare(tile); |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1121 |
st->rect.AfterRemoveTile(st, tile); |
2824
a7a9d3239884
(svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents:
2817
diff
changeset
|
1122 |
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
|
1123 |
YapfNotifyTrackLayoutChange(tile, track); |
3587 | 1124 |
|
1125 |
DeallocateSpecFromStation(st, specindex); |
|
1126 |
||
0 | 1127 |
// now we need to make the "spanned" area of the railway station smaller if we deleted something at the edges. |
1128 |
// we also need to adjust train_tile. |
|
1129 |
MakeRailwayStationAreaSmaller(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
|
1130 |
st->MarkTilesDirty(); |
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
|
1131 |
UpdateStationSignCoord(st); |
0 | 1132 |
|
1133 |
// if we deleted the whole station, delete the train facility. |
|
1134 |
if (st->train_tile == 0) { |
|
1135 |
st->facilities &= ~FACIL_TRAIN; |
|
1136 |
UpdateStationVirtCoordDirty(st); |
|
1137 |
DeleteStationIfEmpty(st); |
|
1138 |
} |
|
1139 |
} |
|
1140 |
return _price.remove_rail_station; |
|
1141 |
} |
|
1142 |
||
1143 |
// determine the number of platforms for the station |
|
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
|
1144 |
uint GetStationPlatforms(const Station *st, TileIndex tile) |
0 | 1145 |
{ |
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
|
1146 |
TileIndex t; |
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
1147 |
TileIndexDiff delta; |
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1148 |
Axis axis; |
2639 | 1149 |
uint len; |
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
|
1150 |
assert(st->TileBelongsToRailStation(tile)); |
0 | 1151 |
|
1152 |
len = 0; |
|
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1153 |
axis = GetRailStationAxis(tile); |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1154 |
delta = (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); |
0 | 1155 |
|
1156 |
// find starting tile.. |
|
1157 |
t = tile; |
|
2639 | 1158 |
do { |
1159 |
t -= delta; |
|
1160 |
len++; |
|
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
|
1161 |
} while (st->TileBelongsToRailStation(t) && GetRailStationAxis(t) == axis); |
0 | 1162 |
|
1163 |
// find ending tile |
|
1164 |
t = tile; |
|
2639 | 1165 |
do { |
1166 |
t += delta; |
|
1167 |
len++; |
|
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
|
1168 |
} while (st->TileBelongsToRailStation(t) && GetRailStationAxis(t) == axis); |
0 | 1169 |
|
1170 |
return len - 1; |
|
1171 |
} |
|
1172 |
||
3928
791f04fb29ad
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1173 |
/** Determines the REMAINING length of a platform, starting at (and including) |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
1174 |
* the given tile. |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
1175 |
* @param tile the tile from which to start searching. Must be a railway station tile |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
1176 |
* @param dir The direction in which to search. |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
1177 |
* @return The platform length |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
1178 |
*/ |
3928
791f04fb29ad
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1179 |
uint GetPlatformLength(TileIndex tile, DiagDirection dir) |
791f04fb29ad
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1180 |
{ |
791f04fb29ad
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1181 |
TileIndex start_tile = tile; |
791f04fb29ad
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1182 |
uint length = 0; |
791f04fb29ad
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1183 |
assert(IsRailwayStationTile(tile)); |
791f04fb29ad
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1184 |
assert(dir < DIAGDIR_END); |
791f04fb29ad
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1185 |
|
791f04fb29ad
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1186 |
do { |
791f04fb29ad
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1187 |
length ++; |
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
1188 |
tile += TileOffsByDiagDir(dir); |
3928
791f04fb29ad
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1189 |
} while (IsCompatibleTrainStationTile(tile, start_tile)); |
791f04fb29ad
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1190 |
|
791f04fb29ad
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1191 |
return length; |
791f04fb29ad
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1192 |
} |
791f04fb29ad
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1193 |
|
791f04fb29ad
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1194 |
|
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
123
diff
changeset
|
1195 |
static int32 RemoveRailroadStation(Station *st, TileIndex tile, uint32 flags) |
0 | 1196 |
{ |
1197 |
int w,h; |
|
5550
51afc7c8dafa
(svn r7547) -Fix: The cost of rail station removal was calculated based on the area occupied by the station. This produced unreasonably large removal costs for non-uniform stations. Now it is based on number of station tiles actually removed.
KUDr
parents:
5247
diff
changeset
|
1198 |
int32 cost = 0; |
0 | 1199 |
|
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
123
diff
changeset
|
1200 |
/* 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
|
1201 |
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
|
1202 |
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
|
1203 |
|
0 | 1204 |
/* Current player owns the station? */ |
1205 |
if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) |
|
1206 |
return CMD_ERROR; |
|
1207 |
||
1208 |
/* determine width and height of platforms */ |
|
1209 |
tile = st->train_tile; |
|
1210 |
w = st->trainst_w; |
|
1211 |
h = st->trainst_h; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1212 |
|
0 | 1213 |
assert(w != 0 && h != 0); |
1214 |
||
1215 |
/* clear all areas of the station */ |
|
1216 |
do { |
|
1217 |
int w_bak = w; |
|
1218 |
do { |
|
1219 |
// 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
|
1220 |
if (st->TileBelongsToRailStation(tile)) { |
0 | 1221 |
if (!EnsureNoVehicle(tile)) |
1222 |
return CMD_ERROR; |
|
5550
51afc7c8dafa
(svn r7547) -Fix: The cost of rail station removal was calculated based on the area occupied by the station. This produced unreasonably large removal costs for non-uniform stations. Now it is based on number of station tiles actually removed.
KUDr
parents:
5247
diff
changeset
|
1223 |
cost += _price.remove_rail_station; |
2824
a7a9d3239884
(svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents:
2817
diff
changeset
|
1224 |
if (flags & DC_EXEC) { |
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1225 |
Track track = GetRailStationTrack(tile); |
0 | 1226 |
DoClearSquare(tile); |
2824
a7a9d3239884
(svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents:
2817
diff
changeset
|
1227 |
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
|
1228 |
YapfNotifyTrackLayoutChange(tile, track); |
2824
a7a9d3239884
(svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents:
2817
diff
changeset
|
1229 |
} |
0 | 1230 |
} |
1981 | 1231 |
tile += TileDiffXY(1, 0); |
0 | 1232 |
} while (--w); |
1233 |
w = w_bak; |
|
1981 | 1234 |
tile += TileDiffXY(-w, 1); |
0 | 1235 |
} while (--h); |
1236 |
||
1237 |
if (flags & DC_EXEC) { |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1238 |
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
|
1239 |
|
0 | 1240 |
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
|
1241 |
st->trainst_w = st->trainst_h = 0; |
0 | 1242 |
st->facilities &= ~FACIL_TRAIN; |
1243 |
||
3587 | 1244 |
free(st->speclist); |
1245 |
st->num_specs = 0; |
|
1246 |
st->speclist = NULL; |
|
1247 |
||
0 | 1248 |
UpdateStationVirtCoordDirty(st); |
1249 |
DeleteStationIfEmpty(st); |
|
1250 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1251 |
|
0 | 1252 |
return cost; |
1253 |
} |
|
1254 |
||
3435
f299c6f48763
(svn r4265) - Fix: compile warning on VS2005 (parameter 2 different from declaration)
Darkvater
parents:
3431
diff
changeset
|
1255 |
int32 DoConvertStationRail(TileIndex tile, RailType totype, bool exec) |
0 | 1256 |
{ |
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
1257 |
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
|
1258 |
|
0 | 1259 |
if (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile)) return CMD_ERROR; |
1260 |
||
1261 |
// 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
|
1262 |
if (!IsRailwayStation(tile)) return CMD_ERROR; |
0 | 1263 |
|
3242
1cefa03f0d5e
(svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents:
3222
diff
changeset
|
1264 |
if (GetRailType(tile) == totype) return CMD_ERROR; |
0 | 1265 |
|
5116
2a33a74925c5
(svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents:
5103
diff
changeset
|
1266 |
// '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
|
1267 |
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
|
1268 |
|
0 | 1269 |
if (exec) { |
3242
1cefa03f0d5e
(svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents:
3222
diff
changeset
|
1270 |
SetRailType(tile, totype); |
0 | 1271 |
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
|
1272 |
YapfNotifyTrackLayoutChange(tile, GetRailStationTrack(tile)); |
0 | 1273 |
} |
1274 |
||
1275 |
return _price.build_rail >> 1; |
|
1276 |
} |
|
1277 |
||
6157 | 1278 |
/** |
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
|
1279 |
* @param[in] truck_station Determines whether a stop is RoadStop::BUS or RoadStop::TRUCK |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
1280 |
* @param[in] station The station to do the whole procedure for |
6157 | 1281 |
* @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
|
1282 |
*/ |
6157 | 1283 |
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
|
1284 |
{ |
3691
7e1ad0718ed8
(svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents:
3687
diff
changeset
|
1285 |
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
|
1286 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1287 |
if (*primary_stop == NULL) { |
3691
7e1ad0718ed8
(svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents:
3687
diff
changeset
|
1288 |
//we have no roadstop of the type yet, so write a "primary stop" |
6157 | 1289 |
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
|
1290 |
} else { |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1291 |
//there are stops already, so append to the end of the list |
6157 | 1292 |
RoadStop *stop = *primary_stop; |
1293 |
while (stop->next != NULL) stop = stop->next; |
|
1294 |
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
|
1295 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1296 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1297 |
|
3691
7e1ad0718ed8
(svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents:
3687
diff
changeset
|
1298 |
/** 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
|
1299 |
* @param tile tile to build the stop at |
3333 | 1300 |
* @param p1 entrance direction (DiagDirection) |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1301 |
* @param p2 0 for Bus stops, 1 for truck stops |
0 | 1302 |
*/ |
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
|
1303 |
int32 CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1304 |
{ |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1305 |
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
|
1306 |
RoadStop *road_stop; |
0 | 1307 |
int32 cost; |
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
|
1308 |
int32 ret; |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1309 |
bool type = !!p2; |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1310 |
|
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1311 |
/* 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
|
1312 |
if (!IsValidDiagDirection((DiagDirection)p1)) return CMD_ERROR; |
0 | 1313 |
|
1314 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
1315 |
||
1316 |
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) |
|
1317 |
return CMD_ERROR; |
|
1318 |
||
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
|
1319 |
ret = CheckFlatLandBelow(tile, 1, 1, flags, 1 << p1, 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
|
1320 |
if (CmdFailed(ret)) return ret; |
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
|
1321 |
cost = ret; |
0 | 1322 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1323 |
st = GetStationAround(tile, 1, 1, INVALID_STATION); |
2639 | 1324 |
if (st == CHECK_STATIONS_ERR) return CMD_ERROR; |
0 | 1325 |
|
1326 |
/* Find a station close to us */ |
|
1327 |
if (st == NULL) { |
|
1328 |
st = GetClosestStationFromTile(tile, 8, _current_player); |
|
2989 | 1329 |
if (st != NULL && st->facilities != 0) st = NULL; |
0 | 1330 |
} |
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 |
//give us a road stop in the list, and check if something went wrong |
5967 | 1333 |
road_stop = new RoadStop(tile); |
2951 | 1334 |
if (road_stop == NULL) { |
1335 |
return_cmd_error(type ? STR_3008B_TOO_MANY_TRUCK_STOPS : STR_3008A_TOO_MANY_BUS_STOPS); |
|
1336 |
} |
|
1337 |
||
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
|
1338 |
/* 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
|
1339 |
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
|
1340 |
|
2989 | 1341 |
if (st != NULL && |
6088
c11f7acc18bd
(svn r8403) -Fix (r8402): Forgot to remove an enum
celestar
parents:
6087
diff
changeset
|
1342 |
GetNumRoadStopsInStation(st, RoadStop::BUS) + GetNumRoadStopsInStation(st, RoadStop::TRUCK) >= RoadStop::LIMIT) { |
2951 | 1343 |
return_cmd_error(type ? STR_3008B_TOO_MANY_TRUCK_STOPS : STR_3008A_TOO_MANY_BUS_STOPS); |
1344 |
} |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1345 |
|
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
|
1346 |
/* 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
|
1347 |
* 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
|
1348 |
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
|
1349 |
|
0 | 1350 |
if (st != NULL) { |
2951 | 1351 |
if (st->owner != OWNER_NONE && st->owner != _current_player) { |
0 | 1352 |
return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION); |
2951 | 1353 |
} |
1354 |
||
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1355 |
if (!st->rect.BeforeAddTile(tile, StationRect::ADD_TEST)) return CMD_ERROR; |
0 | 1356 |
} 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
|
1357 |
/* 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
|
1358 |
st = new Station(tile); |
2639 | 1359 |
if (st == NULL) return CMD_ERROR; |
0 | 1360 |
|
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
|
1361 |
/* 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
|
1362 |
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
|
1363 |
|
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
|
1364 |
|
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
|
1365 |
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
|
1366 |
if (!GenerateStationName(st, tile, 0)) return CMD_ERROR; |
0 | 1367 |
|
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
|
1368 |
if (IsValidPlayer(_current_player) && (flags & DC_EXEC) != 0) { |
0 | 1369 |
SETBIT(t->have_ratings, _current_player); |
2951 | 1370 |
} |
0 | 1371 |
|
1372 |
st->sign.width_1 = 0; |
|
1373 |
} |
|
1374 |
||
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1375 |
cost += (type) ? _price.build_truck_station : _price.build_bus_station; |
0 | 1376 |
|
1377 |
if (flags & DC_EXEC) { |
|
6157 | 1378 |
// Insert into linked list of RoadStops |
1379 |
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
|
1380 |
*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
|
1381 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1382 |
//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
|
1383 |
st->AddFacility((type) ? FACIL_TRUCK_STOP : FACIL_BUS_STOP, tile); |
0 | 1384 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1385 |
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
|
1386 |
|
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
|
1387 |
MakeRoadStop(tile, st->owner, st->index, type ? RoadStop::TRUCK : RoadStop::BUS, (DiagDirection)p1); |
0 | 1388 |
|
1389 |
UpdateStationVirtCoordDirty(st); |
|
1390 |
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
|
1391 |
RebuildStationLists(); |
0 | 1392 |
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
|
1393 |
/* success, so don't delete the new station and the new road stop */ |
6095
55d5c0e6be3a
(svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents:
6088
diff
changeset
|
1394 |
st_auto_delete.Release(); |
55d5c0e6be3a
(svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents:
6088
diff
changeset
|
1395 |
rs_auto_delete.Release(); |
0 | 1396 |
} |
1397 |
return cost; |
|
1398 |
} |
|
1399 |
||
1400 |
// Remove a bus station |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1401 |
static int32 RemoveRoadStop(Station *st, uint32 flags, TileIndex tile) |
0 | 1402 |
{ |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1403 |
RoadStop **primary_stop; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1404 |
RoadStop *cur_stop; |
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1405 |
bool is_truck = IsTruckStop(tile); |
0 | 1406 |
|
2951 | 1407 |
if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) { |
0 | 1408 |
return CMD_ERROR; |
2951 | 1409 |
} |
0 | 1410 |
|
2639 | 1411 |
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
|
1412 |
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
|
1413 |
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
|
1414 |
} else { |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1415 |
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
|
1416 |
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
|
1417 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1418 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1419 |
assert(cur_stop != NULL); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1420 |
|
2951 | 1421 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 1422 |
|
1423 |
if (flags & DC_EXEC) { |
|
6118 | 1424 |
if (*primary_stop == cur_stop) { |
1425 |
// removed the first stop in the list |
|
1426 |
*primary_stop = cur_stop->next; |
|
1427 |
// removed the only stop? |
|
1428 |
if (*primary_stop == NULL) { |
|
1429 |
st->facilities &= (is_truck ? ~FACIL_TRUCK_STOP : ~FACIL_BUS_STOP); |
|
1430 |
} |
|
1431 |
} else { |
|
1432 |
// tell the predecessor in the list to skip this stop |
|
1433 |
RoadStop *pred = *primary_stop; |
|
1434 |
while (pred->next != cur_stop) pred = pred->next; |
|
1435 |
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
|
1436 |
} |
0 | 1437 |
|
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
|
1438 |
delete cur_stop; |
4398
e889842a75a1
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
1439 |
DoClearSquare(tile); |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1440 |
st->rect.AfterRemoveTile(st, tile); |
4398
e889842a75a1
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
1441 |
|
0 | 1442 |
UpdateStationVirtCoordDirty(st); |
1443 |
DeleteStationIfEmpty(st); |
|
1444 |
} |
|
1445 |
||
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1446 |
return (is_truck) ? _price.remove_truck_station : _price.remove_bus_station; |
0 | 1447 |
} |
1448 |
||
1449 |
||
1450 |
||
1451 |
// FIXME -- need to move to its corresponding Airport variable |
|
1452 |
// Country Airfield (small) |
|
3429
12d01022976a
(svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents:
3422
diff
changeset
|
1453 |
static const byte _airport_sections_country[] = { |
0 | 1454 |
54, 53, 52, 65, |
1455 |
58, 57, 56, 55, |
|
1456 |
64, 63, 63, 62 |
|
1457 |
}; |
|
1458 |
||
1459 |
// City Airport (large) |
|
3429
12d01022976a
(svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents:
3422
diff
changeset
|
1460 |
static const byte _airport_sections_town[] = { |
2549 | 1461 |
31, 9, 33, 9, 9, 32, |
1462 |
27, 36, 29, 34, 8, 10, |
|
0 | 1463 |
30, 11, 35, 13, 20, 21, |
1464 |
51, 12, 14, 17, 19, 28, |
|
1465 |
38, 13, 15, 16, 18, 39, |
|
1466 |
26, 22, 23, 24, 25, 26 |
|
1467 |
}; |
|
1468 |
||
1469 |
// Metropolitain Airport (large) - 2 runways |
|
3429
12d01022976a
(svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents:
3422
diff
changeset
|
1470 |
static const byte _airport_sections_metropolitan[] = { |
2549 | 1471 |
31, 9, 33, 9, 9, 32, |
1472 |
27, 36, 29, 34, 8, 10, |
|
1473 |
30, 11, 35, 13, 20, 21, |
|
1474 |
102, 8, 8, 8, 8, 28, |
|
1475 |
83, 84, 84, 84, 84, 83, |
|
1476 |
26, 23, 23, 23, 23, 26 |
|
0 | 1477 |
}; |
1478 |
||
1479 |
// International Airport (large) - 2 runways |
|
3429
12d01022976a
(svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents:
3422
diff
changeset
|
1480 |
static const byte _airport_sections_international[] = { |
3554
c16eadc2d060
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
1481 |
88, 89, 89, 89, 89, 89, 88, |
c16eadc2d060
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
1482 |
51, 8, 8, 8, 8, 8, 32, |
2549 | 1483 |
30, 8, 11, 27, 11, 8, 10, |
0 | 1484 |
32, 8, 11, 27, 11, 8, 114, |
1485 |
87, 8, 11, 85, 11, 8, 114, |
|
2549 | 1486 |
87, 8, 8, 8, 8, 8, 90, |
1487 |
26, 23, 23, 23, 23, 23, 26 |
|
0 | 1488 |
}; |
1489 |
||
4059
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1490 |
// Intercontinental Airport (vlarge) - 4 runways |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1491 |
static const byte _airport_sections_intercontinental[] = { |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
1492 |
102, 120, 89, 89, 89, 89, 89, 89, 118, |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
1493 |
120, 22, 22, 22, 22, 22, 22, 119, 117, |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
1494 |
87, 54, 87, 8, 8, 8, 8, 51, 117, |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
1495 |
87, 162, 87, 85, 116, 116, 8, 9, 10, |
4059
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1496 |
87, 8, 8, 11, 31, 11, 8, 160, 32, |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1497 |
32, 160, 8, 11, 27, 11, 8, 8, 10, |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1498 |
87, 8, 8, 11, 30, 11, 8, 8, 10, |
4066
108eb446f1ae
(svn r5362) - Fix: Updated sprites in New Airports to be allow cleaner replacement by newgrf graphics. All tiles now use SPR_AIRPORT_APRON as the tarmac. Created two new sprites in airports.grf for half-grass half-tarmac tiles on Intercontinental airport.
richk
parents:
4059
diff
changeset
|
1499 |
87, 142, 8, 11, 29, 11, 10, 163, 10, |
108eb446f1ae
(svn r5362) - Fix: Updated sprites in New Airports to be allow cleaner replacement by newgrf graphics. All tiles now use SPR_AIRPORT_APRON as the tarmac. Created two new sprites in airports.grf for half-grass half-tarmac tiles on Intercontinental airport.
richk
parents:
4059
diff
changeset
|
1500 |
87, 164, 87, 8, 8, 8, 10, 37, 117, |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
1501 |
87, 120, 89, 89, 89, 89, 89, 89, 119, |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
1502 |
121, 22, 22, 22, 22, 22, 22, 119, 37 |
4059
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1503 |
}; |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1504 |
|
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1505 |
|
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1506 |
// Commuter Airfield (small) |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1507 |
static const byte _airport_sections_commuter[] = { |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1508 |
85, 30, 115, 115, 32, |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1509 |
87, 8, 8, 8, 10, |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1510 |
87, 11, 11, 11, 10, |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1511 |
26, 23, 23, 23, 26 |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1512 |
}; |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1513 |
|
0 | 1514 |
// Heliport |
3429
12d01022976a
(svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents:
3422
diff
changeset
|
1515 |
static const byte _airport_sections_heliport[] = { |
0 | 1516 |
66, |
1517 |
}; |
|
1518 |
||
4059
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1519 |
// Helidepot |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1520 |
static const byte _airport_sections_helidepot[] = { |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1521 |
124, 32, |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1522 |
122, 123 |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1523 |
}; |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1524 |
|
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1525 |
// Helistation |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1526 |
static const byte _airport_sections_helistation[] = { |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1527 |
32, 134, 159, 158, |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1528 |
161, 142, 142, 157 |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1529 |
}; |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1530 |
|
3471
c31dc50d54fb
(svn r4316) -Codechange: finished r4257 (forgot one variable there)
celestar
parents:
3435
diff
changeset
|
1531 |
static const byte * const _airport_sections[] = { |
4059
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1532 |
_airport_sections_country, // Country Airfield (small) |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1533 |
_airport_sections_town, // City Airport (large) |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1534 |
_airport_sections_heliport, // Heliport |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1535 |
_airport_sections_metropolitan, // Metropolitain Airport (large) |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1536 |
_airport_sections_international, // International Airport (xlarge) |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1537 |
_airport_sections_commuter, // Commuter Airport (small) |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1538 |
_airport_sections_helidepot, // Helidepot |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1539 |
_airport_sections_intercontinental, // Intercontinental Airport (xxlarge) |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1540 |
_airport_sections_helistation // Helistation |
0 | 1541 |
}; |
1542 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1543 |
/** 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
|
1544 |
* @param tile tile where airport will be built |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1545 |
* @param p1 airport type, @see airport.h |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1546 |
* @param p2 unused |
0 | 1547 |
*/ |
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
|
1548 |
int32 CmdBuildAirport(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1549 |
{ |
1550 |
Town *t; |
|
1551 |
Station *st; |
|
1552 |
int32 cost; |
|
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
|
1553 |
int32 ret; |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1554 |
int w, h; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1555 |
bool airport_upgrade = true; |
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
|
1556 |
const AirportFTAClass* afc; |
0 | 1557 |
|
1558 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
1559 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1560 |
/* Check if a valid, buildable airport was chosen for construction */ |
3471
c31dc50d54fb
(svn r4316) -Codechange: finished r4257 (forgot one variable there)
celestar
parents:
3435
diff
changeset
|
1561 |
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
|
1562 |
|
0 | 1563 |
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) |
1564 |
return CMD_ERROR; |
|
1565 |
||
1566 |
t = ClosestTownFromTile(tile, (uint)-1); |
|
1567 |
||
1568 |
/* Check if local auth refuses a new airport */ |
|
1569 |
{ |
|
1570 |
uint num = 0; |
|
1571 |
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
|
1572 |
if (st->town == t && st->facilities&FACIL_AIRPORT && st->airport_type != AT_OILRIG) |
0 | 1573 |
num++; |
1574 |
} |
|
1575 |
if (num >= 2) { |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1576 |
SetDParam(0, t->index); |
0 | 1577 |
return_cmd_error(STR_2035_LOCAL_AUTHORITY_REFUSES); |
1578 |
} |
|
1579 |
} |
|
1580 |
||
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
|
1581 |
afc = GetAirport(p1); |
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
|
1582 |
w = afc->size_x; |
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
|
1583 |
h = afc->size_y; |
0 | 1584 |
|
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
|
1585 |
ret = CheckFlatLandBelow(tile, w, h, flags, 0, 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
|
1586 |
if (CmdFailed(ret)) return ret; |
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
|
1587 |
cost = ret; |
0 | 1588 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1589 |
st = GetStationAround(tile, w, h, INVALID_STATION); |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1590 |
if (st == CHECK_STATIONS_ERR) return CMD_ERROR; |
0 | 1591 |
|
1592 |
/* Find a station close to us */ |
|
1593 |
if (st == NULL) { |
|
1594 |
st = GetClosestStationFromTile(tile, 8, _current_player); |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1595 |
if (st != NULL && st->facilities) st = NULL; |
0 | 1596 |
} |
1597 |
||
5764
483bcb05ccf3
(svn r7810) -Fix: FS#504 Building airport whose size exceeds max station spread-out caused assert. (Zuu)
KUDr
parents:
5726
diff
changeset
|
1598 |
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
|
1599 |
_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
|
1600 |
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
|
1601 |
} |
483bcb05ccf3
(svn r7810) -Fix: FS#504 Building airport whose size exceeds max station spread-out caused assert. (Zuu)
KUDr
parents:
5726
diff
changeset
|
1602 |
|
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
|
1603 |
/* 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
|
1604 |
* 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
|
1605 |
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
|
1606 |
|
0 | 1607 |
if (st != NULL) { |
1608 |
if (st->owner != OWNER_NONE && st->owner != _current_player) |
|
1609 |
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
|
1610 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1611 |
if (!st->rect.BeforeAddRect(tile, w, h, StationRect::ADD_TEST)) return CMD_ERROR; |
0 | 1612 |
|
1613 |
if (st->airport_tile != 0) |
|
1614 |
return_cmd_error(STR_300D_TOO_CLOSE_TO_ANOTHER_AIRPORT); |
|
1615 |
} else { |
|
1616 |
airport_upgrade = false; |
|
1617 |
||
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
|
1618 |
/* 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
|
1619 |
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
|
1620 |
if (st == NULL) return CMD_ERROR; |
0 | 1621 |
|
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
|
1622 |
/* 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
|
1623 |
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
|
1624 |
|
1265
0430e635b116
(svn r1769) Don't compute the same value twice, remove one function call
tron
parents:
1247
diff
changeset
|
1625 |
st->town = t; |
0 | 1626 |
|
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
|
1627 |
if (IsValidPlayer(_current_player) && (flags & DC_EXEC) != 0) { |
0 | 1628 |
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
|
1629 |
} |
0 | 1630 |
|
1631 |
st->sign.width_1 = 0; |
|
1632 |
||
1633 |
// if airport type equals Heliport then generate |
|
1634 |
// type 5 name, which is heliport, otherwise airport names (1) |
|
4059
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1635 |
if (!GenerateStationName(st, tile, (p1 == AT_HELIPORT)||(p1 == AT_HELIDEPOT)||(p1 == AT_HELISTATION) ? 5 : 1)) |
0 | 1636 |
return CMD_ERROR; |
1637 |
} |
|
1638 |
||
1639 |
cost += _price.build_airport * w * h; |
|
1640 |
||
1641 |
if (flags & DC_EXEC) { |
|
1642 |
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
|
1643 |
st->AddFacility(FACIL_AIRPORT, tile); |
0 | 1644 |
st->airport_type = (byte)p1; |
1645 |
st->airport_flags = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1646 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1647 |
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
|
1648 |
|
2639 | 1649 |
/* if airport was demolished while planes were en-route to it, the |
1650 |
* positions can no longer be the same (v->u.air.pos), since different |
|
1651 |
* airports have different indexes. So update all planes en-route to this |
|
1652 |
* airport. Only update if |
|
1653 |
* 1. airport is upgraded |
|
1654 |
* 2. airport is added to existing station (unfortunately unavoideable) |
|
1655 |
*/ |
|
2549 | 1656 |
if (airport_upgrade) UpdateAirplanesOnNewStation(st); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1657 |
|
0 | 1658 |
{ |
3471
c31dc50d54fb
(svn r4316) -Codechange: finished r4257 (forgot one variable there)
celestar
parents:
3435
diff
changeset
|
1659 |
const byte *b = _airport_sections[p1]; |
2549 | 1660 |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1661 |
BEGIN_TILE_LOOP(tile_cur, w, h, tile) { |
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1662 |
MakeAirport(tile_cur, st->owner, st->index, *b++); |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1663 |
} END_TILE_LOOP(tile_cur, w, h, tile) |
0 | 1664 |
} |
1665 |
||
1666 |
UpdateStationVirtCoordDirty(st); |
|
1667 |
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
|
1668 |
RebuildStationLists(); |
0 | 1669 |
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
|
1670 |
/* success, so don't delete the new station */ |
6095
55d5c0e6be3a
(svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents:
6088
diff
changeset
|
1671 |
st_auto_delete.Release(); |
0 | 1672 |
} |
1673 |
||
1674 |
return cost; |
|
1675 |
} |
|
1676 |
||
1677 |
static int32 RemoveAirport(Station *st, uint32 flags) |
|
1678 |
{ |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1679 |
TileIndex tile; |
0 | 1680 |
int w,h; |
1681 |
int32 cost; |
|
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
|
1682 |
const AirportFTAClass* afc; |
0 | 1683 |
|
1684 |
if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) |
|
1685 |
return CMD_ERROR; |
|
1686 |
||
1687 |
tile = st->airport_tile; |
|
1688 |
||
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
|
1689 |
afc = GetAirport(st->airport_type); |
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
|
1690 |
w = afc->size_x; |
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
|
1691 |
h = afc->size_y; |
0 | 1692 |
|
1693 |
cost = w * h * _price.remove_airport; |
|
1694 |
||
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1695 |
BEGIN_TILE_LOOP(tile_cur, w, h, tile) { |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1696 |
if (!EnsureNoVehicle(tile_cur)) return CMD_ERROR; |
0 | 1697 |
|
1698 |
if (flags & DC_EXEC) { |
|
1699 |
DeleteAnimatedTile(tile_cur); |
|
1700 |
DoClearSquare(tile_cur); |
|
1701 |
} |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1702 |
} END_TILE_LOOP(tile_cur, w,h,tile) |
0 | 1703 |
|
1704 |
if (flags & DC_EXEC) { |
|
700 | 1705 |
uint i; |
1706 |
||
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1707 |
for (i = 0; i < afc->nof_depots; ++i) { |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1708 |
DeleteWindowById( |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1709 |
WC_VEHICLE_DEPOT, tile + ToTileIndexDiff(afc->airport_depots[i]) |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1710 |
); |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1711 |
} |
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
|
1712 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1713 |
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
|
1714 |
|
0 | 1715 |
st->airport_tile = 0; |
1716 |
st->facilities &= ~FACIL_AIRPORT; |
|
1717 |
||
1718 |
UpdateStationVirtCoordDirty(st); |
|
1719 |
DeleteStationIfEmpty(st); |
|
1720 |
} |
|
1721 |
||
1722 |
return cost; |
|
1723 |
} |
|
1724 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1725 |
/** 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
|
1726 |
* @param tile tile where to place the bouy |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1727 |
* @param p1 unused |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1728 |
* @param p2 unused |
0 | 1729 |
*/ |
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
|
1730 |
int32 CmdBuildBuoy(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1731 |
{ |
1732 |
Station *st; |
|
1733 |
||
1734 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
1735 |
||
3374
9721c51bea25
(svn r4173) -Codechange: Use IsClearWaterTile for buoy construction
celestar
parents:
3362
diff
changeset
|
1736 |
if (!IsClearWaterTile(tile) || tile == 0) return_cmd_error(STR_304B_SITE_UNSUITABLE); |
0 | 1737 |
|
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
|
1738 |
/* 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
|
1739 |
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
|
1740 |
if (st == NULL) return CMD_ERROR; |
0 | 1741 |
|
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
|
1742 |
/* 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
|
1743 |
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
|
1744 |
|
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
|
1745 |
st->town = ClosestTownFromTile(tile, (uint)-1); |
0 | 1746 |
st->sign.width_1 = 0; |
1747 |
||
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
|
1748 |
if (!GenerateStationName(st, tile, 4)) return CMD_ERROR; |
0 | 1749 |
|
1750 |
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
|
1751 |
st->dock_tile = tile; |
0 | 1752 |
st->facilities |= FACIL_DOCK; |
1751
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1706
diff
changeset
|
1753 |
/* 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
|
1754 |
* braindead.. */ |
0 | 1755 |
st->had_vehicle_of_type |= HVOT_BUOY; |
1756 |
st->owner = OWNER_NONE; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1757 |
|
71
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
65
diff
changeset
|
1758 |
st->build_date = _date; |
0 | 1759 |
|
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1760 |
MakeBuoy(tile, st->index); |
0 | 1761 |
|
1762 |
UpdateStationVirtCoordDirty(st); |
|
1763 |
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
|
1764 |
RebuildStationLists(); |
0 | 1765 |
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
|
1766 |
/* success, so don't delete the new station */ |
6095
55d5c0e6be3a
(svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents:
6088
diff
changeset
|
1767 |
st_auto_delete.Release(); |
0 | 1768 |
} |
1769 |
||
1770 |
return _price.build_dock; |
|
1771 |
} |
|
1772 |
||
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
|
1773 |
/* 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
|
1774 |
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
|
1775 |
{ |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1776 |
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
|
1777 |
FOR_ALL_VEHICLES(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
|
1778 |
if (v->type == VEH_Ship) { |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1779 |
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
|
1780 |
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
|
1781 |
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
|
1782 |
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
|
1783 |
} |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1784 |
} |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1785 |
} |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1786 |
} |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1787 |
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
|
1788 |
} |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1789 |
|
0 | 1790 |
static int32 RemoveBuoy(Station *st, uint32 flags) |
1791 |
{ |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1792 |
TileIndex tile; |
0 | 1793 |
|
4850
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4848
diff
changeset
|
1794 |
/* XXX: strange stuff */ |
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4848
diff
changeset
|
1795 |
if (!IsValidPlayer(_current_player)) return_cmd_error(INVALID_STRING_ID); |
0 | 1796 |
|
1797 |
tile = st->dock_tile; |
|
1798 |
||
2639 | 1799 |
if (CheckShipsOnBuoy(st)) return_cmd_error(STR_BUOY_IS_IN_USE); |
1800 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
|
0 | 1801 |
|
1802 |
if (flags & DC_EXEC) { |
|
1803 |
st->dock_tile = 0; |
|
1751
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1706
diff
changeset
|
1804 |
/* 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
|
1805 |
* braindead.. */ |
0 | 1806 |
st->facilities &= ~FACIL_DOCK; |
1807 |
st->had_vehicle_of_type &= ~HVOT_BUOY; |
|
1808 |
||
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
|
1809 |
/* 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
|
1810 |
* 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
|
1811 |
* 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
|
1812 |
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
|
1813 |
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
|
1814 |
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
|
1815 |
} 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
|
1816 |
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
|
1817 |
} |
3111
1edf71aa942e
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3102
diff
changeset
|
1818 |
MarkTileDirtyByTile(tile); |
0 | 1819 |
|
1820 |
UpdateStationVirtCoordDirty(st); |
|
1821 |
DeleteStationIfEmpty(st); |
|
1822 |
} |
|
1823 |
||
1824 |
return _price.remove_truck_station; |
|
1825 |
} |
|
1826 |
||
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1827 |
static const TileIndexDiffC _dock_tileoffs_chkaround[] = { |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1828 |
{-1, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1829 |
{ 0, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1830 |
{ 0, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1831 |
{ 0, -1} |
0 | 1832 |
}; |
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
|
1833 |
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
|
1834 |
static const byte _dock_h_chk[4] = { 1, 2, 1, 2 }; |
0 | 1835 |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1836 |
/** 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
|
1837 |
* @param tile tile where dock will be built |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1838 |
* @param p1 unused |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1839 |
* @param p2 unused |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1840 |
*/ |
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
|
1841 |
int32 CmdBuildDock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1842 |
{ |
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
|
1843 |
TileIndex tile_cur; |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
1844 |
DiagDirection direction; |
0 | 1845 |
int32 cost; |
1846 |
Station *st; |
|
1847 |
||
1848 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
1849 |
||
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
|
1850 |
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
|
1851 |
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
|
1852 |
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
|
1853 |
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
|
1854 |
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
|
1855 |
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
|
1856 |
} |
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
|
1857 |
|
4619
fc11bc6a7fe7
(svn r6477) - Fix a loop-hole that allowed docks to be built regardless of town authority rating.
peter1138
parents:
4559
diff
changeset
|
1858 |
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
|
1859 |
|
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
|
1860 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
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
|
1861 |
|
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
|
1862 |
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
|
1863 |
if (CmdFailed(cost)) return CMD_ERROR; |
0 | 1864 |
|
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
1865 |
tile_cur = tile + TileOffsByDiagDir(direction); |
0 | 1866 |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1867 |
if (!EnsureNoVehicle(tile_cur)) return CMD_ERROR; |
0 | 1868 |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
1869 |
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
|
1870 |
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
|
1871 |
} |
0 | 1872 |
|
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
|
1873 |
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
|
1874 |
if (CmdFailed(cost)) return CMD_ERROR; |
0 | 1875 |
|
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
1876 |
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
|
1877 |
if (!IsTileType(tile_cur, MP_WATER) || GetTileSlope(tile_cur, NULL) != SLOPE_FLAT) { |
0 | 1878 |
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
|
1879 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1880 |
|
0 | 1881 |
/* middle */ |
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1882 |
st = GetStationAround( |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1883 |
tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]), |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1884 |
_dock_w_chk[direction], _dock_h_chk[direction], INVALID_STATION); |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1885 |
if (st == CHECK_STATIONS_ERR) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1886 |
|
0 | 1887 |
/* Find a station close to us */ |
1888 |
if (st == NULL) { |
|
1889 |
st = GetClosestStationFromTile(tile, 8, _current_player); |
|
1890 |
if (st!=NULL && st->facilities) st = NULL; |
|
1891 |
} |
|
1892 |
||
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
|
1893 |
/* 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
|
1894 |
* 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
|
1895 |
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
|
1896 |
|
0 | 1897 |
if (st != NULL) { |
1898 |
if (st->owner != OWNER_NONE && st->owner != _current_player) |
|
1899 |
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
|
1900 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1901 |
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
|
1902 |
|
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1903 |
if (st->dock_tile != 0) return_cmd_error(STR_304C_TOO_CLOSE_TO_ANOTHER_DOCK); |
0 | 1904 |
} 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
|
1905 |
/* 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
|
1906 |
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
|
1907 |
if (st == NULL) return CMD_ERROR; |
0 | 1908 |
|
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
|
1909 |
/* 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
|
1910 |
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
|
1911 |
|
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
|
1912 |
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
|
1913 |
|
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
|
1914 |
if (IsValidPlayer(_current_player) && (flags & DC_EXEC) != 0) { |
0 | 1915 |
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
|
1916 |
} |
0 | 1917 |
|
1918 |
st->sign.width_1 = 0; |
|
1919 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1920 |
if (!GenerateStationName(st, tile, 3)) return CMD_ERROR; |
0 | 1921 |
} |
1922 |
||
1923 |
if (flags & DC_EXEC) { |
|
1924 |
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
|
1925 |
st->AddFacility(FACIL_DOCK, tile); |
0 | 1926 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1927 |
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
|
1928 |
|
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1929 |
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
|
1930 |
|
0 | 1931 |
UpdateStationVirtCoordDirty(st); |
1932 |
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
|
1933 |
RebuildStationLists(); |
0 | 1934 |
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
|
1935 |
/* success, so don't delete the new station */ |
6095
55d5c0e6be3a
(svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents:
6088
diff
changeset
|
1936 |
st_auto_delete.Release(); |
0 | 1937 |
} |
1938 |
return _price.build_dock; |
|
1939 |
} |
|
1940 |
||
1941 |
static int32 RemoveDock(Station *st, uint32 flags) |
|
1942 |
{ |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1943 |
TileIndex tile1; |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1944 |
TileIndex tile2; |
0 | 1945 |
|
2639 | 1946 |
if (!CheckOwnership(st->owner)) return CMD_ERROR; |
0 | 1947 |
|
1948 |
tile1 = st->dock_tile; |
|
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
1949 |
tile2 = tile1 + TileOffsByDiagDir(GetDockDirection(tile1)); |
0 | 1950 |
|
2639 | 1951 |
if (!EnsureNoVehicle(tile1)) return CMD_ERROR; |
1952 |
if (!EnsureNoVehicle(tile2)) return CMD_ERROR; |
|
0 | 1953 |
|
1954 |
if (flags & DC_EXEC) { |
|
1955 |
DoClearSquare(tile1); |
|
3111
1edf71aa942e
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3102
diff
changeset
|
1956 |
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
|
1957 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1958 |
st->rect.AfterRemoveTile(st, tile1); |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1959 |
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
|
1960 |
|
3111
1edf71aa942e
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3102
diff
changeset
|
1961 |
MarkTileDirtyByTile(tile2); |
0 | 1962 |
|
1963 |
st->dock_tile = 0; |
|
1964 |
st->facilities &= ~FACIL_DOCK; |
|
1965 |
||
1966 |
UpdateStationVirtCoordDirty(st); |
|
1967 |
DeleteStationIfEmpty(st); |
|
1968 |
} |
|
1969 |
||
1970 |
return _price.remove_dock; |
|
1971 |
} |
|
1972 |
||
1973 |
#include "table/station_land.h" |
|
1974 |
||
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
|
1975 |
const DrawTileSprites *GetStationTileLayout(byte gfx) |
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
|
1976 |
{ |
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
|
1977 |
return &_station_display_datas[gfx]; |
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
|
1978 |
} |
0 | 1979 |
|
6214
aab08beb5652
(svn r8635) -Fix: draw canal edges under buoys that are in a canal.
rubidium
parents:
6204
diff
changeset
|
1980 |
/* 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
|
1981 |
extern void DrawCanalWater(TileIndex tile); |
aab08beb5652
(svn r8635) -Fix: draw canal edges under buoys that are in a canal.
rubidium
parents:
6204
diff
changeset
|
1982 |
|
0 | 1983 |
static void DrawTile_Station(TileInfo *ti) |
1984 |
{ |
|
1985 |
const DrawTileSeqStruct *dtss; |
|
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1986 |
const DrawTileSprites *t = NULL; |
3242
1cefa03f0d5e
(svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents:
3222
diff
changeset
|
1987 |
RailType railtype = GetRailType(ti->tile); |
2254
72f8883ff3ac
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2213
diff
changeset
|
1988 |
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
|
1989 |
uint32 relocation = 0; |
3775
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
1990 |
const Station *st = NULL; |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
1991 |
const StationSpec *statspec = NULL; |
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
|
1992 |
PlayerID owner = GetTileOwner(ti->tile); |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
1993 |
SpriteID image; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
1994 |
SpriteID palette; |
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
|
1995 |
|
4850
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4848
diff
changeset
|
1996 |
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
|
1997 |
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
|
1998 |
} 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
|
1999 |
// 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
|
2000 |
palette = PALETTE_TO_GREY; |
0 | 2001 |
} |
2002 |
||
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2003 |
// 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
|
2004 |
if (ti->tileh != SLOPE_FLAT && !IsDock(ti->tile)) |
0 | 2005 |
DrawFoundation(ti, ti->tileh); |
2006 |
||
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
|
2007 |
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
|
2008 |
// look for customization |
3775
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2009 |
st = GetStationByTile(ti->tile); |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2010 |
statspec = st->speclist[GetCustomStationSpecIndex(ti->tile)].spec; |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2011 |
|
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2012 |
//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
|
2013 |
|
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2014 |
if (statspec != NULL) { |
3576
007e6b163bf5
(svn r4462) - Newstations: ensure the chosen tile layout is available from a custom station
peter1138
parents:
3574
diff
changeset
|
2015 |
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
|
2016 |
|
3751
785501c18d0d
(svn r4739) - Newstations: remove cargo type parameter of GetCustomStationRelocation() as we can determine it internally
peter1138
parents:
3742
diff
changeset
|
2017 |
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
|
2018 |
|
3754
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
2019 |
if (HASBIT(statspec->callbackmask, CBM_CUSTOM_LAYOUT)) { |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
2020 |
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
|
2021 |
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
|
2022 |
} |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
2023 |
|
3576
007e6b163bf5
(svn r4462) - Newstations: ensure the chosen tile layout is available from a custom station
peter1138
parents:
3574
diff
changeset
|
2024 |
/* 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
|
2025 |
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
|
2026 |
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
|
2027 |
} |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2028 |
} |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2029 |
} |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2030 |
|
3737
26341085bbbf
(svn r4719) - Newstations: instead of drawing nothing, fall back to the default sprite layout if a station layout specifies so.
peter1138
parents:
3699
diff
changeset
|
2031 |
if (t == NULL || t->seq == NULL) t = &_station_display_datas[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
|
2032 |
|
bf1303e754ff
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
2033 |
image = t->ground_sprite; |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
2034 |
if (HASBIT(image, SPRITE_MODIFIER_USE_OFFSET)) { |
3775
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2035 |
image += GetCustomStationGroundRelocation(statspec, st, ti->tile); |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2036 |
image += rti->custom_ground_offset; |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2037 |
} else { |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2038 |
image += rti->total_offset; |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2039 |
} |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2040 |
|
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2041 |
// 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
|
2042 |
// 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
|
2043 |
DrawGroundSprite(image, HASBIT(image, PALETTE_MODIFIER_COLOR) ? palette : PAL_NONE); |
0 | 2044 |
|
3789
bf75e48227de
(svn r4785) - Newstations: don't draw catenary on non-track tiles
glx
parents:
3784
diff
changeset
|
2045 |
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
|
2046 |
|
6214
aab08beb5652
(svn r8635) -Fix: draw canal edges under buoys that are in a canal.
rubidium
parents:
6204
diff
changeset
|
2047 |
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
|
2048 |
|
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
|
2049 |
foreach_draw_tile_seq(dtss, t->seq) { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
2050 |
SpriteID pal; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
2051 |
|
3775
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2052 |
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
|
2053 |
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
|
2054 |
image += rti->total_offset; |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2055 |
} else { |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2056 |
image += relocation; |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2057 |
} |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2058 |
|
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
|
2059 |
if (_display_opt & DO_TRANS_BUILDINGS) { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
2060 |
SETBIT(image, PALETTE_MODIFIER_TRANSPARENT); |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
2061 |
pal = PALETTE_TO_TRANSPARENT; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
2062 |
} 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
|
2063 |
pal = palette; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
2064 |
} else { |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
2065 |
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
|
2066 |
} |
bf1303e754ff
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
2067 |
|
0 | 2068 |
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
|
2069 |
AddSortableSpriteToDraw( |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
2070 |
image, pal, |
4230
cd86b1c47f33
(svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents:
4227
diff
changeset
|
2071 |
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
|
2072 |
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
|
2073 |
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
|
2074 |
); |
0 | 2075 |
} else { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
2076 |
AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y); |
0 | 2077 |
} |
2078 |
} |
|
2079 |
} |
|
2080 |
||
2520
75eb66d6e371
(svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents:
2517
diff
changeset
|
2081 |
void StationPickerDrawSprite(int x, int y, RailType railtype, int image) |
0 | 2082 |
{ |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
2083 |
SpriteID pal, img; |
0 | 2084 |
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
|
2085 |
const DrawTileSprites *t; |
2254
72f8883ff3ac
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2213
diff
changeset
|
2086 |
const RailtypeInfo *rti = GetRailTypeInfo(railtype); |
0 | 2087 |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
2088 |
pal = PLAYER_SPRITE_COLOR(_local_player); |
0 | 2089 |
|
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
|
2090 |
t = &_station_display_datas[image]; |
bf1303e754ff
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
2091 |
|
bf1303e754ff
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
2092 |
img = t->ground_sprite; |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
2093 |
DrawSprite(img + rti->total_offset, HASBIT(img, PALETTE_MODIFIER_COLOR) ? pal : PAL_NONE, x, y); |
0 | 2094 |
|
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
|
2095 |
foreach_draw_tile_seq(dtss, t->seq) { |
0 | 2096 |
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
|
2097 |
DrawSprite(dtss->image + rti->total_offset, pal, x + pt.x, y + pt.y); |
0 | 2098 |
} |
2099 |
} |
|
2100 |
||
4231
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4230
diff
changeset
|
2101 |
static uint GetSlopeZ_Station(TileIndex tile, uint x, uint y) |
0 | 2102 |
{ |
4231
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4230
diff
changeset
|
2103 |
return GetTileMaxZ(tile); |
0 | 2104 |
} |
2105 |
||
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
2106 |
static Slope GetSlopeTileh_Station(TileIndex tile, Slope tileh) |
39 | 2107 |
{ |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
2108 |
return SLOPE_FLAT; |
39 | 2109 |
} |
2110 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2111 |
static void GetAcceptedCargo_Station(TileIndex tile, AcceptedCargo ac) |
0 | 2112 |
{ |
2113 |
/* not used */ |
|
2114 |
} |
|
2115 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2116 |
static void GetTileDesc_Station(TileIndex tile, TileDesc *td) |
0 | 2117 |
{ |
2118 |
StringID str; |
|
2119 |
||
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
|
2120 |
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
|
2121 |
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
|
2122 |
|
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2123 |
switch (GetStationType(tile)) { |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2124 |
default: NOT_REACHED(); |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2125 |
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
|
2126 |
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
|
2127 |
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
|
2128 |
break; |
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2129 |
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
|
2130 |
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
|
2131 |
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
|
2132 |
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
|
2133 |
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
|
2134 |
} |
0 | 2135 |
td->str = str; |
2136 |
} |
|
2137 |
||
2138 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2139 |
static uint32 GetTileTrackStatus_Station(TileIndex tile, TransportType mode) |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2140 |
{ |
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
|
2141 |
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
|
2142 |
case TRANSPORT_RAIL: |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
2143 |
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
|
2144 |
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
|
2145 |
} |
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
|
2146 |
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
|
2147 |
|
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
|
2148 |
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
|
2149 |
// 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
|
2150 |
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
|
2151 |
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
|
2152 |
// 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
|
2153 |
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
|
2154 |
// 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
|
2155 |
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
|
2156 |
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
|
2157 |
} |
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
|
2158 |
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
|
2159 |
|
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
2160 |
case TRANSPORT_ROAD: |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
2161 |
if (IsRoadStopTile(tile)) { |
4158 | 2162 |
return AxisToTrackBits(DiagDirToAxis(GetRoadStopDir(tile))) * 0x101; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
2163 |
} |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
2164 |
break; |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
2165 |
|
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
|
2166 |
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
|
2167 |
break; |
0 | 2168 |
} |
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
|
2169 |
|
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2170 |
return 0; |
0 | 2171 |
} |
2172 |
||
2660 | 2173 |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2174 |
static void TileLoop_Station(TileIndex tile) |
0 | 2175 |
{ |
2660 | 2176 |
// FIXME -- GetTileTrackStatus_Station -> animated stationtiles |
2177 |
// hardcoded.....not good |
|
3540
83bd858fe9fe
(svn r4403) CodeChange : Add GetStationGfx and make use of [G|S]etStationGfx accessors. Also, use GetStationGfx instead of directly accessing the map for functions in station_map.h
belugas
parents:
3527
diff
changeset
|
2178 |
switch (GetStationGfx(tile)) { |
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
|
2179 |
case GFX_RADAR_LARGE_FIRST: |
3e66bf329257
(svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents:
3540
diff
changeset
|
2180 |
case GFX_WINDSACK_FIRST : // for small airport |
3554
c16eadc2d060
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2181 |
case GFX_RADAR_INTERNATIONAL_FIRST: |
c16eadc2d060
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2182 |
case GFX_RADAR_METROPOLITAN_FIRST: |
4059
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
2183 |
case GFX_RADAR_DISTRICTWE_FIRST: // radar district W-E airport |
4066
108eb446f1ae
(svn r5362) - Fix: Updated sprites in New Airports to be allow cleaner replacement by newgrf graphics. All tiles now use SPR_AIRPORT_APRON as the tarmac. Created two new sprites in airports.grf for half-grass half-tarmac tiles on Intercontinental airport.
richk
parents:
4059
diff
changeset
|
2184 |
case GFX_WINDSACK_INTERCON_FIRST : // for intercontinental airport |
2660 | 2185 |
AddAnimatedTile(tile); |
2186 |
break; |
|
2187 |
||
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
|
2188 |
case GFX_OILRIG_BASE: //(station part) |
3e66bf329257
(svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents:
3540
diff
changeset
|
2189 |
case GFX_BUOY_BASE: |
2660 | 2190 |
TileLoop_Water(tile); |
2191 |
break; |
|
2192 |
||
2193 |
default: break; |
|
2194 |
} |
|
0 | 2195 |
} |
2196 |
||
2197 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2198 |
static void AnimateTile_Station(TileIndex tile) |
0 | 2199 |
{ |
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
|
2200 |
typedef struct AnimData { |
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
|
2201 |
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
|
2202 |
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
|
2203 |
byte delay; |
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
|
2204 |
} AnimData; |
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
|
2205 |
|
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
|
2206 |
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
|
2207 |
{ 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
|
2208 |
{ 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
|
2209 |
{ 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
|
2210 |
{ 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
|
2211 |
{ 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
|
2212 |
{ 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
|
2213 |
}; |
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
|
2214 |
|
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
|
2215 |
StationGfx gfx = GetStationGfx(tile); |
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
|
2216 |
const AnimData* i; |
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
|
2217 |
|
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
|
2218 |
for (i = data; i != endof(data); i++) { |
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
|
2219 |
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
|
2220 |
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
|
2221 |
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
|
2222 |
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
|
2223 |
} |
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
|
2224 |
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
|
2225 |
} |
0 | 2226 |
} |
2227 |
} |
|
2228 |
||
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
2229 |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2230 |
static void ClickTile_Station(TileIndex tile) |
0 | 2231 |
{ |
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2232 |
if (IsHangar(tile)) { |
4638
8abe4f10b94b
(svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents:
4619
diff
changeset
|
2233 |
ShowDepotWindow(tile, VEH_Aircraft); |
0 | 2234 |
} 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
|
2235 |
ShowStationViewWindow(GetStationIndex(tile)); |
0 | 2236 |
} |
2237 |
} |
|
2238 |
||
2239 |
static const byte _enter_station_speedtable[12] = { |
|
2240 |
215, 195, 175, 155, 135, 115, 95, 75, 55, 35, 15, 0 |
|
2241 |
}; |
|
2242 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2243 |
static uint32 VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y) |
0 | 2244 |
{ |
2245 |
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
|
2246 |
if (IsRailwayStation(tile) && IsFrontEngine(v) && |
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
2247 |
!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
|
2248 |
StationID station_id = GetStationIndex(tile); |
2989 | 2249 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
2250 |
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
|
2251 |
(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
|
2252 |
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
|
2253 |
v->current_order.type != OT_LEAVESTATION && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
2254 |
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
|
2255 |
DiagDirection dir = DirToDiagDir(v->direction); |
2989 | 2256 |
|
0 | 2257 |
x &= 0xF; |
2258 |
y &= 0xF; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2259 |
|
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
|
2260 |
if (DiagDirToAxis(dir) != AXIS_X) intswap(x, y); |
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
2261 |
if (y == TILE_SIZE / 2) { |
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
2262 |
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
|
2263 |
if (x == 12) return VETSB_ENTERED_STATION | (station_id << VETS_STATION_ID_OFFSET); /* enter station */ |
0 | 2264 |
if (x < 12) { |
2639 | 2265 |
uint16 spd; |
2266 |
||
0 | 2267 |
v->vehstatus |= VS_TRAIN_SLOWING; |
2268 |
spd = _enter_station_speedtable[x]; |
|
2639 | 2269 |
if (spd < v->cur_speed) v->cur_speed = spd; |
0 | 2270 |
} |
2271 |
} |
|
2272 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2273 |
} |
0 | 2274 |
} |
2275 |
} else if (v->type == VEH_Road) { |
|
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
|
2276 |
if (v->u.road.state < 16 && !HASBIT(v->u.road.state, 2) && v->u.road.frame == 0) { |
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2277 |
if (IsRoadStop(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
|
2278 |
/* 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
|
2279 |
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
|
2280 |
|
6316
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6214
diff
changeset
|
2281 |
/* 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
|
2282 |
if (rs->IsEntranceBusy() || !rs->HasFreeBay()) return VETSB_CANNOT_ENTER; |
0 | 2283 |
|
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
|
2284 |
v->u.road.state += 32; |
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
|
2285 |
|
6316
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6214
diff
changeset
|
2286 |
/* 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
|
2287 |
uint bay_nr = rs->AllocateBay(); |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6214
diff
changeset
|
2288 |
SB(v->u.road.state, 1, 1, bay_nr); |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6214
diff
changeset
|
2289 |
|
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6214
diff
changeset
|
2290 |
/* Mark the station entrace as busy */ |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6214
diff
changeset
|
2291 |
rs->SetEntranceBusy(true); |
0 | 2292 |
} |
2293 |
} |
|
2294 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2295 |
|
6317
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6316
diff
changeset
|
2296 |
return VETSB_CONTINUE; |
0 | 2297 |
} |
2298 |
||
2299 |
/* this function is called for one station each tick */ |
|
2300 |
static void StationHandleBigTick(Station *st) |
|
2301 |
{ |
|
2302 |
UpdateStationAcceptance(st, true); |
|
2303 |
||
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
|
2304 |
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
|
2305 |
|
0 | 2306 |
} |
2307 |
||
500
ef288590e096
(svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents:
497
diff
changeset
|
2308 |
static inline void byte_inc_sat(byte *p) { byte b = *p + 1; if (b != 0) *p = b; } |
0 | 2309 |
|
2310 |
static void UpdateStationRating(Station *st) |
|
2311 |
{ |
|
2312 |
GoodsEntry *ge; |
|
1551
eb05e6a90e67
(svn r2055) -CodeChange: Begun introducting StationID
celestar
parents:
1527
diff
changeset
|
2313 |
int rating; |
eb05e6a90e67
(svn r2055) -CodeChange: Begun introducting StationID
celestar
parents:
1527
diff
changeset
|
2314 |
StationID index; |
0 | 2315 |
int waiting; |
2316 |
bool waiting_changed = false; |
|
2317 |
||
2318 |
byte_inc_sat(&st->time_since_load); |
|
2319 |
byte_inc_sat(&st->time_since_unload); |
|
2320 |
||
2321 |
ge = st->goods; |
|
2322 |
do { |
|
1266
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1265
diff
changeset
|
2323 |
if (ge->enroute_from != INVALID_STATION) { |
0 | 2324 |
byte_inc_sat(&ge->enroute_time); |
2325 |
byte_inc_sat(&ge->days_since_pickup); |
|
2326 |
||
2327 |
rating = 0; |
|
2328 |
||
2329 |
{ |
|
2330 |
int b = ge->last_speed; |
|
2331 |
if ((b-=85) >= 0) |
|
2332 |
rating += b >> 2; |
|
2333 |
} |
|
2334 |
||
2335 |
{ |
|
2336 |
byte age = ge->last_age; |
|
2337 |
(age >= 3) || |
|
2338 |
(rating += 10, age >= 2) || |
|
2339 |
(rating += 10, age >= 1) || |
|
2340 |
(rating += 13, true); |
|
2341 |
} |
|
2342 |
||
4850
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4848
diff
changeset
|
2343 |
if (IsValidPlayer(st->owner) && HASBIT(st->town->statues, st->owner)) rating += 26; |
0 | 2344 |
|
2345 |
{ |
|
2346 |
byte days = ge->days_since_pickup; |
|
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
|
2347 |
if (st->last_vehicle_type == VEH_Ship) |
0 | 2348 |
days >>= 2; |
2349 |
(days > 21) || |
|
2350 |
(rating += 25, days > 12) || |
|
2351 |
(rating += 25, days > 6) || |
|
2352 |
(rating += 45, days > 3) || |
|
2353 |
(rating += 35, true); |
|
2354 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2355 |
|
0 | 2356 |
{ |
2504
7c27fc230cda
(svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents:
2502
diff
changeset
|
2357 |
waiting = GB(ge->waiting_acceptance, 0, 12); |
0 | 2358 |
(rating -= 90, waiting > 1500) || |
2359 |
(rating += 55, waiting > 1000) || |
|
2360 |
(rating += 35, waiting > 600) || |
|
2361 |
(rating += 10, waiting > 300) || |
|
2362 |
(rating += 20, waiting > 100) || |
|
2363 |
(rating += 10, true); |
|
2364 |
} |
|
2365 |
||
2366 |
{ |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
2367 |
int or_ = ge->rating; // old rating |
0 | 2368 |
|
2369 |
// 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
|
2370 |
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
|
2371 |
|
0 | 2372 |
// if rating is <= 64 and more than 200 items waiting, remove some random amount of goods from the station |
2373 |
if (rating <= 64 && waiting >= 200) { |
|
2374 |
int dec = Random() & 0x1F; |
|
2375 |
if (waiting < 400) dec &= 7; |
|
2376 |
waiting -= dec + 1; |
|
2377 |
waiting_changed = true; |
|
2378 |
} |
|
2379 |
||
2380 |
// if rating is <= 127 and there are any items waiting, maybe remove some goods. |
|
2381 |
if (rating <= 127 && waiting != 0) { |
|
2382 |
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
|
2383 |
if (rating <= (int)GB(r, 0, 7)) { |
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
|
2384 |
waiting = max(waiting - (int)GB(r, 8, 2) - 1, 0); |
0 | 2385 |
waiting_changed = true; |
2386 |
} |
|
2387 |
} |
|
2388 |
||
2504
7c27fc230cda
(svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents:
2502
diff
changeset
|
2389 |
if (waiting_changed) SB(ge->waiting_acceptance, 0, 12, waiting); |
0 | 2390 |
} |
2391 |
} |
|
2392 |
} while (++ge != endof(st->goods)); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2393 |
|
0 | 2394 |
index = st->index; |
2395 |
||
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
2396 |
if (waiting_changed) { |
0 | 2397 |
InvalidateWindow(WC_STATION_VIEW, index); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
2398 |
} else { |
0 | 2399 |
InvalidateWindowWidget(WC_STATION_VIEW, index, 5); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
2400 |
} |
0 | 2401 |
} |
2402 |
||
2403 |
/* called for every station each tick */ |
|
2404 |
static void StationHandleSmallTick(Station *st) |
|
2405 |
{ |
|
2406 |
byte b; |
|
2407 |
||
2639 | 2408 |
if (st->facilities == 0) return; |
0 | 2409 |
|
2410 |
b = st->delete_ctr + 1; |
|
2411 |
if (b >= 185) b = 0; |
|
2412 |
st->delete_ctr = b; |
|
2413 |
||
2639 | 2414 |
if (b == 0) UpdateStationRating(st); |
0 | 2415 |
} |
2416 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1078
diff
changeset
|
2417 |
void OnTick_Station(void) |
0 | 2418 |
{ |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
2419 |
uint i; |
0 | 2420 |
Station *st; |
2421 |
||
2639 | 2422 |
if (_game_mode == GM_EDITOR) return; |
0 | 2423 |
|
2424 |
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
|
2425 |
if (++_station_tick_ctr > GetMaxStationIndex()) _station_tick_ctr = 0; |
0 | 2426 |
|
4352
8ddb01bc6075
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
2427 |
if (IsValidStationID(i)) StationHandleBigTick(GetStation(i)); |
0 | 2428 |
|
2429 |
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
|
2430 |
StationHandleSmallTick(st); |
0 | 2431 |
} |
2432 |
} |
|
2433 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1078
diff
changeset
|
2434 |
void StationMonthlyLoop(void) |
0 | 2435 |
{ |
2436 |
} |
|
2437 |
||
2438 |
||
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
|
2439 |
void ModifyStationRatingAround(TileIndex tile, PlayerID owner, int amount, uint radius) |
0 | 2440 |
{ |
2441 |
Station *st; |
|
2442 |
||
2443 |
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
|
2444 |
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
|
2445 |
DistanceManhattan(tile, st->xy) <= radius) { |
2549 | 2446 |
uint i; |
2447 |
||
2448 |
for (i = 0; i != NUM_CARGO; i++) { |
|
2449 |
GoodsEntry* ge = &st->goods[i]; |
|
2450 |
||
1266
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1265
diff
changeset
|
2451 |
if (ge->enroute_from != INVALID_STATION) { |
0 | 2452 |
ge->rating = clamp(ge->rating + amount, 0, 255); |
2453 |
} |
|
2454 |
} |
|
2455 |
} |
|
2456 |
} |
|
2457 |
} |
|
2458 |
||
2459 |
static void UpdateStationWaiting(Station *st, int type, uint amount) |
|
2460 |
{ |
|
2504
7c27fc230cda
(svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents:
2502
diff
changeset
|
2461 |
SB(st->goods[type].waiting_acceptance, 0, 12, |
7c27fc230cda
(svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents:
2502
diff
changeset
|
2462 |
min(0xFFF, GB(st->goods[type].waiting_acceptance, 0, 12) + amount) |
7c27fc230cda
(svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents:
2502
diff
changeset
|
2463 |
); |
0 | 2464 |
|
2465 |
st->goods[type].enroute_time = 0; |
|
2466 |
st->goods[type].enroute_from = st->index; |
|
5934
9f91cc4e2b17
(svn r8144) -Fix: [FS#163] When a station is removed, vehicles do not get excessive payment any longer, as the origin TILE is now stored as long as the origin STATION for the transported cargos. Basically this is only a temporary fix until cargopackets are implemented, but it fixes one of the oldest known bugs (Special Thanks to Darkvater for lots of testing)
celestar
parents:
5930
diff
changeset
|
2467 |
st->goods[type].enroute_from_xy = st->xy; |
0 | 2468 |
InvalidateWindow(WC_STATION_VIEW, st->index); |
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
|
2469 |
st->MarkTilesDirty(); |
0 | 2470 |
} |
2471 |
||
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
|
2472 |
/** 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
|
2473 |
* @param tile unused |
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
|
2474 |
* @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
|
2475 |
* @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
|
2476 |
*/ |
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
|
2477 |
int32 CmdRenameStation(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 2478 |
{ |
2639 | 2479 |
StringID str; |
0 | 2480 |
Station *st; |
2481 |
||
4352
8ddb01bc6075
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
2482 |
if (!IsValidStationID(p1) || _cmd_text[0] == '\0') 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
|
2483 |
st = GetStation(p1); |
0fc4a31265c2
(svn r2278) When renaming a station, check if the station exists and belongs to the correct player
tron
parents:
1751
diff
changeset
|
2484 |
|
4352
8ddb01bc6075
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
2485 |
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
|
2486 |
|
1820
9b6458526480
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1786
diff
changeset
|
2487 |
str = AllocateNameUnique(_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
|
2488 |
if (str == 0) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2489 |
|
0 | 2490 |
if (flags & DC_EXEC) { |
2639 | 2491 |
StringID old_str = st->string_id; |
2492 |
||
0 | 2493 |
st->string_id = str; |
2494 |
UpdateStationVirtCoord(st); |
|
2495 |
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
|
2496 |
ResortStationLists(); |
0 | 2497 |
MarkWholeScreenDirty(); |
2498 |
} else { |
|
2499 |
DeleteName(str); |
|
2500 |
} |
|
2501 |
||
2502 |
return 0; |
|
2503 |
} |
|
2504 |
||
2505 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2506 |
uint MoveGoodsToStation(TileIndex tile, int w, int h, int type, uint amount) |
0 | 2507 |
{ |
3002
c4f3a6ebfb25
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2508 |
Station* around[8]; |
c4f3a6ebfb25
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2509 |
uint i; |
0 | 2510 |
uint moved; |
2511 |
uint best_rating, best_rating2; |
|
2512 |
Station *st1, *st2; |
|
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
|
2513 |
uint t; |
711d2ababe20
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2514 |
int rad = 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
|
2515 |
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
|
2516 |
int h_prod; |
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2517 |
int max_rad; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2518 |
|
3002
c4f3a6ebfb25
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2519 |
for (i = 0; i < lengthof(around); i++) around[i] = NULL; |
0 | 2520 |
|
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2521 |
if (_patches.modified_catchment) { |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2522 |
w_prod = w; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2523 |
h_prod = h; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2524 |
w += 16; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2525 |
h += 16; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2526 |
max_rad = 8; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2527 |
} 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
|
2528 |
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
|
2529 |
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
|
2530 |
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
|
2531 |
h += 8; |
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2532 |
max_rad = 4; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2533 |
} |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2534 |
|
1981 | 2535 |
BEGIN_TILE_LOOP(cur_tile, w, h, tile - TileDiffXY(max_rad, max_rad)) |
3002
c4f3a6ebfb25
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2536 |
Station* 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
|
2537 |
|
0 | 2538 |
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
|
2539 |
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
|
2540 |
|
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
2541 |
st = GetStationByTile(cur_tile); |
3002
c4f3a6ebfb25
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2542 |
|
c4f3a6ebfb25
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2543 |
for (i = 0; i != lengthof(around); i++) { |
c4f3a6ebfb25
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2544 |
if (around[i] == NULL) { |
6147
2345f00d2a33
(svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents:
6141
diff
changeset
|
2545 |
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
|
2546 |
(st->town->exclusive_counter == 0 || st->town->exclusivity == st->owner) && // check exclusive transport rights |
711d2ababe20
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2547 |
st->goods[type].rating != 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
|
2548 |
(!_patches.selectgoods || st->goods[type].last_speed > 0) && // if last_speed is 0, no vehicle has been there. |
711d2ababe20
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2549 |
((st->facilities & ~FACIL_BUS_STOP) != 0 || type == CT_PASSENGERS) && // if we have other fac. than a bus stop, or the cargo is passengers |
711d2ababe20
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2550 |
((st->facilities & ~FACIL_TRUCK_STOP) != 0 || type != CT_PASSENGERS)) { // if we have other fac. than a cargo bay or the cargo is not passengers |
3001
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2551 |
int x_dist; |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2552 |
int y_dist; |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2553 |
|
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2554 |
if (_patches.modified_catchment) { |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2555 |
// 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
|
2556 |
const int x_min_prod = 9; |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2557 |
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
|
2558 |
const int y_min_prod = 9; |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2559 |
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
|
2560 |
|
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2561 |
rad = FindCatchmentRadius(st); |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2562 |
|
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2563 |
x_dist = min(w_cur - x_min_prod, x_max_prod - w_cur); |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2564 |
if (w_cur < x_min_prod) { |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2565 |
x_dist = x_min_prod - w_cur; |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2566 |
} else if (w_cur > x_max_prod) { |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2567 |
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
|
2568 |
} |
3001
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2569 |
|
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2570 |
y_dist = min(h_cur - y_min_prod, y_max_prod - h_cur); |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2571 |
if (h_cur < y_min_prod) { |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2572 |
y_dist = y_min_prod - h_cur; |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2573 |
} else if (h_cur > y_max_prod) { |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2574 |
y_dist = h_cur - y_max_prod; |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2575 |
} |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2576 |
} else { |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2577 |
x_dist = 0; |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2578 |
y_dist = 0; |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2579 |
} |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2580 |
|
3002
c4f3a6ebfb25
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2581 |
if (x_dist <= rad && y_dist <= rad) around[i] = st; |
3001
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2582 |
} |
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
|
2583 |
break; |
3002
c4f3a6ebfb25
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2584 |
} 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
|
2585 |
break; |
0 | 2586 |
} |
2587 |
} |
|
1981 | 2588 |
END_TILE_LOOP(cur_tile, w, h, tile - TileDiffXY(max_rad, max_rad)) |
0 | 2589 |
|
2590 |
/* 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
|
2591 |
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
|
2592 |
|
c4f3a6ebfb25
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2593 |
if (around[1] == NULL) { |
0 | 2594 |
/* only one station around */ |
3002
c4f3a6ebfb25
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2595 |
moved = (amount * around[0]->goods[type].rating >> 8) + 1; |
c4f3a6ebfb25
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2596 |
UpdateStationWaiting(around[0], type, moved); |
0 | 2597 |
return moved; |
2598 |
} |
|
2599 |
||
2600 |
/* several stations around, find the two with the highest rating */ |
|
2601 |
st2 = st1 = NULL; |
|
2602 |
best_rating = best_rating2 = 0; |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2603 |
|
3002
c4f3a6ebfb25
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2604 |
for (i = 0; i != lengthof(around) && around[i] != NULL; i++) { |
c4f3a6ebfb25
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2605 |
if (around[i]->goods[type].rating >= best_rating) { |
0 | 2606 |
best_rating2 = best_rating; |
2607 |
st2 = st1; |
|
2608 |
||
3002
c4f3a6ebfb25
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2609 |
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
|
2610 |
st1 = around[i]; |
c4f3a6ebfb25
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2611 |
} 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
|
2612 |
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
|
2613 |
st2 = around[i]; |
0 | 2614 |
} |
2615 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2616 |
|
0 | 2617 |
assert(st1 != NULL); |
2618 |
assert(st2 != NULL); |
|
2619 |
assert(best_rating != 0 || best_rating2 != 0); |
|
2620 |
||
2621 |
/* the 2nd highest one gets a penalty */ |
|
2622 |
best_rating2 >>= 1; |
|
2623 |
||
2624 |
/* amount given to station 1 */ |
|
2625 |
t = (best_rating * (amount + 1)) / (best_rating + best_rating2); |
|
2626 |
||
2627 |
moved = 0; |
|
2628 |
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
|
2629 |
moved = t * best_rating / 256 + 1; |
0 | 2630 |
amount -= t; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2631 |
UpdateStationWaiting(st1, type, moved); |
0 | 2632 |
} |
2633 |
||
2634 |
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
|
2635 |
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
|
2636 |
moved += amount; |
0 | 2637 |
UpdateStationWaiting(st2, type, amount); |
2638 |
} |
|
2639 |
||
2640 |
return moved; |
|
2641 |
} |
|
2642 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2643 |
void BuildOilRig(TileIndex tile) |
0 | 2644 |
{ |
2639 | 2645 |
uint j; |
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
|
2646 |
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
|
2647 |
|
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
|
2648 |
if (st == NULL) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5550
diff
changeset
|
2649 |
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
|
2650 |
return; |
0 | 2651 |
} |
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
|
2652 |
if (!GenerateStationName(st, tile, 2)) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5550
diff
changeset
|
2653 |
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
|
2654 |
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
|
2655 |
} |
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
|
2656 |
|
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
|
2657 |
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
|
2658 |
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
|
2659 |
|
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2660 |
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
|
2661 |
|
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
|
2662 |
st->owner = OWNER_NONE; |
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
|
2663 |
st->airport_flags = 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
|
2664 |
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
|
2665 |
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
|
2666 |
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
|
2667 |
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
|
2668 |
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
|
2669 |
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
|
2670 |
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
|
2671 |
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
|
2672 |
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
|
2673 |
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
|
2674 |
st->delete_ctr = 0; |
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
|
2675 |
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
|
2676 |
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
|
2677 |
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
|
2678 |
|
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
|
2679 |
for (j = 0; j != NUM_CARGO; j++) { |
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
|
2680 |
st->goods[j].waiting_acceptance = 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
|
2681 |
st->goods[j].days_since_pickup = 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
|
2682 |
st->goods[j].enroute_from = INVALID_STATION; |
5934
9f91cc4e2b17
(svn r8144) -Fix: [FS#163] When a station is removed, vehicles do not get excessive payment any longer, as the origin TILE is now stored as long as the origin STATION for the transported cargos. Basically this is only a temporary fix until cargopackets are implemented, but it fixes one of the oldest known bugs (Special Thanks to Darkvater for lots of testing)
celestar
parents:
5930
diff
changeset
|
2683 |
st->goods[j].enroute_from_xy = INVALID_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
|
2684 |
st->goods[j].rating = 175; |
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
|
2685 |
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
|
2686 |
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
|
2687 |
} |
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
|
2688 |
|
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
|
2689 |
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
|
2690 |
UpdateStationAcceptance(st, false); |
0 | 2691 |
} |
2692 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2693 |
void DeleteOilRig(TileIndex tile) |
0 | 2694 |
{ |
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
2695 |
Station* st = GetStationByTile(tile); |
0 | 2696 |
|
6138 | 2697 |
MakeWater(tile); |
0 | 2698 |
|
2699 |
st->dock_tile = 0; |
|
2700 |
st->airport_tile = 0; |
|
2701 |
st->facilities &= ~(FACIL_AIRPORT | FACIL_DOCK); |
|
2702 |
st->airport_flags = 0; |
|
2703 |
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
|
2704 |
if (st->facilities == 0) delete st; |
0 | 2705 |
} |
2706 |
||
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
|
2707 |
static void ChangeTileOwner_Station(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 2708 |
{ |
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
|
2709 |
if (!IsTileOwner(tile, old_player)) return; |
0 | 2710 |
|
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4638
diff
changeset
|
2711 |
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
|
2712 |
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
|
2713 |
|
1902 | 2714 |
SetTileOwner(tile, new_player); |
0 | 2715 |
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
|
2716 |
RebuildStationLists(); |
65
f9f866bc609c
(svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents:
59
diff
changeset
|
2717 |
InvalidateWindowClasses(WC_STATION_LIST); |
0 | 2718 |
} else { |
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
|
2719 |
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
0 | 2720 |
} |
2721 |
} |
|
2722 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2723 |
static int32 ClearTile_Station(TileIndex tile, byte flags) |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2724 |
{ |
0 | 2725 |
Station *st; |
2726 |
||
2727 |
if (flags & DC_AUTO) { |
|
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2728 |
switch (GetStationType(tile)) { |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2729 |
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
|
2730 |
case STATION_AIRPORT: return_cmd_error(STR_300E_MUST_DEMOLISH_AIRPORT_FIRST); |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2731 |
case STATION_TRUCK: return_cmd_error(STR_3047_MUST_DEMOLISH_TRUCK_STATION); |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2732 |
case STATION_BUS: return_cmd_error(STR_3046_MUST_DEMOLISH_BUS_STATION); |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2733 |
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
|
2734 |
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
|
2735 |
case STATION_OILRIG: |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2736 |
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
|
2737 |
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
|
2738 |
} |
0 | 2739 |
} |
2740 |
||
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
2741 |
st = GetStationByTile(tile); |
0 | 2742 |
|
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2743 |
switch (GetStationType(tile)) { |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2744 |
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
|
2745 |
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
|
2746 |
case STATION_TRUCK: |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2747 |
case STATION_BUS: return RemoveRoadStop(st, flags, tile); |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2748 |
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
|
2749 |
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
|
2750 |
default: break; |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2751 |
} |
0 | 2752 |
|
2753 |
return CMD_ERROR; |
|
2754 |
} |
|
2755 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1078
diff
changeset
|
2756 |
void InitializeStations(void) |
0 | 2757 |
{ |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
2758 |
/* Clean the station pool and create 1 block in it */ |
4980 | 2759 |
CleanPool(&_Station_pool); |
2760 |
AddBlockToPool(&_Station_pool); |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
2761 |
|
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
2762 |
/* 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
|
2763 |
CleanPool(&_RoadStop_pool); |
f19132348a43
(svn r6984) Use the pool macros for the RoadStop pool
tron
parents:
4980
diff
changeset
|
2764 |
AddBlockToPool(&_RoadStop_pool); |
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
2765 |
|
0 | 2766 |
_station_tick_ctr = 0; |
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
2767 |
|
0 | 2768 |
} |
2769 |
||
2770 |
||
3765
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2771 |
void AfterLoadStations(void) |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2772 |
{ |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2773 |
Station *st; |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2774 |
uint i; |
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
|
2775 |
TileIndex tile; |
3765
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2776 |
|
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2777 |
/* Update the speclists of all stations to point to the currently loaded custom stations. */ |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2778 |
FOR_ALL_STATIONS(st) { |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2779 |
for (i = 0; i < st->num_specs; i++) { |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2780 |
if (st->speclist[i].grfid == 0) continue; |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2781 |
|
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2782 |
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
|
2783 |
} |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2784 |
} |
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
|
2785 |
|
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
|
2786 |
for (tile = 0; tile < MapSize(); tile++) { |
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
|
2787 |
if (GetTileType(tile) != MP_STATION) continue; |
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
|
2788 |
st = GetStationByTile(tile); |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
2789 |
st->rect.BeforeAddTile(tile, StationRect::ADD_FORCE); |
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
|
2790 |
} |
3765
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2791 |
} |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2792 |
|
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2793 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
2794 |
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
|
2795 |
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
|
2796 |
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
|
2797 |
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
|
2798 |
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
|
2799 |
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
|
2800 |
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
|
2801 |
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
|
2802 |
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
|
2803 |
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
|
2804 |
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
|
2805 |
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
|
2806 |
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
|
2807 |
GetSlopeTileh_Station, /* get_slope_tileh_proc */ |
0 | 2808 |
}; |
2809 |
||
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
|
2810 |
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
|
2811 |
SLE_VAR(RoadStop,xy, SLE_UINT32), |
5969 | 2812 |
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
|
2813 |
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
|
2814 |
/* 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
|
2815 |
SLE_CONDNULL(4, 0, 8), |
5967 | 2816 |
SLE_CONDNULL(2, 0, 44), |
3479
a4d992b5d24d
(svn r4324) Remove the unused road stop type attribute from struct RoadStop
tron
parents:
3478
diff
changeset
|
2817 |
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
|
2818 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2819 |
SLE_REF(RoadStop,next, REF_ROADSTOPS), |
6118 | 2820 |
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
|
2821 |
|
3431 | 2822 |
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
|
2823 |
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
|
2824 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2825 |
SLE_END() |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2826 |
}; |
0 | 2827 |
|
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
|
2828 |
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
|
2829 |
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
|
2830 |
SLE_CONDVAR(Station, xy, SLE_UINT32, 6, SL_MAX_VERSION), |
6130 | 2831 |
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
|
2832 |
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
|
2833 |
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
|
2834 |
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
|
2835 |
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
|
2836 |
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
|
2837 |
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
|
2838 |
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
|
2839 |
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
|
2840 |
SLE_CONDVAR(Station, trainst_h, SLE_UINT8, 2, SL_MAX_VERSION), |
0 | 2841 |
|
2842 |
// 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
|
2843 |
SLE_CONDNULL(1, 0, 3), |
0 | 2844 |
|
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
|
2845 |
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
|
2846 |
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
|
2847 |
|
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
|
2848 |
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
|
2849 |
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
|
2850 |
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
|
2851 |
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
|
2852 |
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
|
2853 |
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
|
2854 |
|
6129 | 2855 |
SLE_CONDNULL(2, 0, 5), // Truck/bus stop status |
6128 | 2856 |
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
|
2857 |
|
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
|
2858 |
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
|
2859 |
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
|
2860 |
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
|
2861 |
|
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
|
2862 |
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
|
2863 |
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
|
2864 |
|
3574
bf5f6c1af32c
(svn r4460) - Newstations: remove unused class_id / stat_id variables from the
peter1138
parents:
3568
diff
changeset
|
2865 |
// Was custom station class and id |
bf5f6c1af32c
(svn r4460) - Newstations: remove unused class_id / stat_id variables from the
peter1138
parents:
3568
diff
changeset
|
2866 |
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
|
2867 |
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
|
2868 |
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
|
2869 |
|
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
|
2870 |
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
|
2871 |
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
|
2872 |
|
3687
109ec5cdb932
(svn r4612) - NewStations: add random bits (for graphic variation) to stations
peter1138
parents:
3682
diff
changeset
|
2873 |
/* 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
|
2874 |
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
|
2875 |
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
|
2876 |
SLE_CONDVAR(Station, num_specs, SLE_UINT8, 27, SL_MAX_VERSION), |
3687
109ec5cdb932
(svn r4612) - NewStations: add random bits (for graphic variation) to stations
peter1138
parents:
3682
diff
changeset
|
2877 |
|
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
|
2878 |
// 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
|
2879 |
SLE_CONDNULL(32, 2, SL_MAX_VERSION), |
0 | 2880 |
|
2881 |
SLE_END() |
|
2882 |
}; |
|
2883 |
||
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
|
2884 |
static const SaveLoad _goods_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
|
2885 |
SLE_VAR(GoodsEntry, waiting_acceptance, 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
|
2886 |
SLE_VAR(GoodsEntry, days_since_pickup, 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
|
2887 |
SLE_VAR(GoodsEntry, rating, 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
|
2888 |
SLE_CONDVAR(GoodsEntry, enroute_from, SLE_FILE_U8 | SLE_VAR_U16, 0, 6), |
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
|
2889 |
SLE_CONDVAR(GoodsEntry, enroute_from, SLE_UINT16, 7, SL_MAX_VERSION), |
5934
9f91cc4e2b17
(svn r8144) -Fix: [FS#163] When a station is removed, vehicles do not get excessive payment any longer, as the origin TILE is now stored as long as the origin STATION for the transported cargos. Basically this is only a temporary fix until cargopackets are implemented, but it fixes one of the oldest known bugs (Special Thanks to Darkvater for lots of testing)
celestar
parents:
5930
diff
changeset
|
2890 |
SLE_CONDVAR(GoodsEntry, enroute_from_xy, SLE_UINT32, 44, SL_MAX_VERSION), |
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
|
2891 |
SLE_VAR(GoodsEntry, enroute_time, 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
|
2892 |
SLE_VAR(GoodsEntry, last_speed, 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
|
2893 |
SLE_VAR(GoodsEntry, last_age, 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
|
2894 |
SLE_CONDVAR(GoodsEntry, feeder_profit, SLE_INT32, 14, SL_MAX_VERSION), |
0 | 2895 |
|
2896 |
SLE_END() |
|
2897 |
}; |
|
2898 |
||
3765
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2899 |
static const SaveLoad _station_speclist_desc[] = { |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2900 |
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
|
2901 |
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
|
2902 |
|
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2903 |
SLE_END() |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2904 |
}; |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2905 |
|
0 | 2906 |
|
2907 |
static void SaveLoad_STNS(Station *st) |
|
2908 |
{ |
|
3765
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2909 |
uint i; |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2910 |
|
0 | 2911 |
SlObject(st, _station_desc); |
1266
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1265
diff
changeset
|
2912 |
for (i = 0; i != NUM_CARGO; i++) { |
0 | 2913 |
SlObject(&st->goods[i], _goods_desc); |
1266
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1265
diff
changeset
|
2914 |
|
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1265
diff
changeset
|
2915 |
/* In older versions, enroute_from had 0xFF as INVALID_STATION, is now 0xFFFF */ |
2685
00111d5ca47f
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2676
diff
changeset
|
2916 |
if (CheckSavegameVersion(7) && st->goods[i].enroute_from == 0xFF) { |
2469
1bfbb0dc0b75
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2436
diff
changeset
|
2917 |
st->goods[i].enroute_from = INVALID_STATION; |
2639 | 2918 |
} |
5948
f835a89667df
(svn r8161) -Fix (FS#555, r8144): enroute_from_xy was not set properly for old savegames.
rubidium
parents:
5941
diff
changeset
|
2919 |
if (CheckSavegameVersion(44)) { |
f835a89667df
(svn r8161) -Fix (FS#555, r8144): enroute_from_xy was not set properly for old savegames.
rubidium
parents:
5941
diff
changeset
|
2920 |
/* Store position of the station where the goods come from, so there are no |
f835a89667df
(svn r8161) -Fix (FS#555, r8144): enroute_from_xy was not set properly for old savegames.
rubidium
parents:
5941
diff
changeset
|
2921 |
* very high payments when stations get removed. However, if the station |
f835a89667df
(svn r8161) -Fix (FS#555, r8144): enroute_from_xy was not set properly for old savegames.
rubidium
parents:
5941
diff
changeset
|
2922 |
* where the goods came from is already removed, the source information is |
f835a89667df
(svn r8161) -Fix (FS#555, r8144): enroute_from_xy was not set properly for old savegames.
rubidium
parents:
5941
diff
changeset
|
2923 |
* lost. In that case we set it to the position of this station */ |
f835a89667df
(svn r8161) -Fix (FS#555, r8144): enroute_from_xy was not set properly for old savegames.
rubidium
parents:
5941
diff
changeset
|
2924 |
st->goods[i].enroute_from_xy = IsValidStationID(st->goods[i].enroute_from) ? GetStation(st->goods[i].enroute_from)->xy : st->xy; |
f835a89667df
(svn r8161) -Fix (FS#555, r8144): enroute_from_xy was not set properly for old savegames.
rubidium
parents:
5941
diff
changeset
|
2925 |
} |
1266
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1265
diff
changeset
|
2926 |
} |
3765
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2927 |
|
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2928 |
if (st->num_specs != 0) { |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2929 |
/* 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
|
2930 |
if (st->speclist == NULL) st->speclist = CallocT<StationSpecList>(st->num_specs); |
3765
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2931 |
for (i = 0; i < st->num_specs; i++) SlObject(&st->speclist[i], _station_speclist_desc); |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2932 |
} |
0 | 2933 |
} |
2934 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1078
diff
changeset
|
2935 |
static void Save_STNS(void) |
0 | 2936 |
{ |
2937 |
Station *st; |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
2938 |
// Write the stations |
0 | 2939 |
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
|
2940 |
SlSetArrayIndex(st->index); |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
2941 |
SlAutolength((AutolengthProc*)SaveLoad_STNS, st); |
0 | 2942 |
} |
2943 |
} |
|
2944 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1078
diff
changeset
|
2945 |
static void Load_STNS(void) |
0 | 2946 |
{ |
2947 |
int index; |
|
2948 |
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
|
2949 |
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
|
2950 |
|
0 | 2951 |
SaveLoad_STNS(st); |
2952 |
||
2953 |
// this means it's an oldstyle savegame without support for nonuniform stations |
|
2639 | 2954 |
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
|
2955 |
uint w = GB(st->trainst_w, 4, 4); |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
2956 |
uint h = GB(st->trainst_w, 0, 4); |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
2957 |
|
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2958 |
if (GetRailStationAxis(st->train_tile) == AXIS_Y) uintswap(w, h); |
0 | 2959 |
st->trainst_w = w; |
2960 |
st->trainst_h = h; |
|
2961 |
} |
|
2962 |
} |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
2963 |
|
1472
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
2964 |
/* 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
|
2965 |
if (_station_tick_ctr > GetMaxStationIndex()) _station_tick_ctr = 0; |
0 | 2966 |
} |
2967 |
||
2549 | 2968 |
static void Save_ROADSTOP(void) |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2969 |
{ |
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
2970 |
RoadStop *rs; |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
2971 |
|
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
2972 |
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
|
2973 |
SlSetArrayIndex(rs->index); |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
2974 |
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
|
2975 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2976 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2977 |
|
2549 | 2978 |
static void Load_ROADSTOP(void) |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2979 |
{ |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2980 |
int index; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2981 |
|
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
2982 |
while ((index = SlIterateArray()) != -1) { |
5967 | 2983 |
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
|
2984 |
|
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
2985 |
SlObject(rs, _roadstop_desc); |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
2986 |
} |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2987 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2988 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
2989 |
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
|
2990 |
{ '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
|
2991 |
{ 'ROAD', Save_ROADSTOP, Load_ROADSTOP, CH_ARRAY | CH_LAST}, |
0 | 2992 |
}; |
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
|
2993 |
|
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
|
2994 |