author | truebrain |
Thu, 12 Jun 2008 21:07:25 +0000 | |
branch | noai |
changeset 10943 | 5f5a5dd407d8 |
parent 10920 | e33442a2b239 |
child 11044 | 097ea3e7ec56 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
3 |
/** @file station_cmd.cpp Handling of station tiles. */ |
2213
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1881
diff
changeset
|
6 |
#include "openttd.h" |
6413 | 7 |
#include "aircraft.h" |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5568
diff
changeset
|
8 |
#include "bridge_map.h" |
6460 | 9 |
#include "cmd_helper.h" |
1299
0a6510cc889b
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1295
diff
changeset
|
10 |
#include "debug.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
11 |
#include "tile_cmd.h" |
9599 | 12 |
#include "landscape.h" |
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
13 |
#include "station_map.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
14 |
#include "viewport_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
15 |
#include "command_func.h" |
0 | 16 |
#include "town.h" |
9826
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9800
diff
changeset
|
17 |
#include "news_func.h" |
0 | 18 |
#include "saveload.h" |
19 |
#include "airport.h" |
|
405
6830ae7a0d5d
(svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents:
403
diff
changeset
|
20 |
#include "sprite.h" |
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2671
diff
changeset
|
21 |
#include "train.h" |
9627 | 22 |
#include "roadveh.h" |
3111
1edf71aa942e
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3102
diff
changeset
|
23 |
#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
|
24 |
#include "industry_map.h" |
3754
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
25 |
#include "newgrf_callbacks.h" |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
26 |
#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
|
27 |
#include "yapf/yapf.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
28 |
#include "road_type.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
29 |
#include "road_internal.h" /* For drawing catenary/checking road removal */ |
6417
26acff62d001
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents:
6413
diff
changeset
|
30 |
#include "cargotype.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
31 |
#include "variables.h" |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
32 |
#include "autoslope.h" |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
33 |
#include "transparency.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
34 |
#include "water.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
35 |
#include "station_gui.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
36 |
#include "strings_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
37 |
#include "functions.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
38 |
#include "window_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
39 |
#include "date_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
40 |
#include "vehicle_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
41 |
#include "string_func.h" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
42 |
#include "signal_func.h" |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
43 |
#include "oldpool_func.h" |
10294 | 44 |
#include "animated_tile_func.h" |
10513
33cb70ff2f5d
(svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents:
10455
diff
changeset
|
45 |
#include "elrail_func.h" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
46 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
47 |
#include "table/sprites.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
48 |
#include "table/strings.h" |
5917
e0d30aba24a3
(svn r8126) -Fix (r8125): missing #include fixes compilation error on g++ (still some warnings, working on it)
KUDr
parents:
5916
diff
changeset
|
49 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
50 |
DEFINE_OLD_POOL_GENERIC(Station, Station) |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
51 |
DEFINE_OLD_POOL_GENERIC(RoadStop, RoadStop) |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
52 |
|
3587 | 53 |
|
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
54 |
/** |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
55 |
* Check whether the given tile is a hangar. |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
56 |
* @param t the tile to of whether it is a hangar. |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
57 |
* @pre IsTileType(t, MP_STATION) |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
58 |
* @return true if and only if the tile is a hangar. |
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
59 |
*/ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
60 |
bool IsHangar(TileIndex t) |
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
61 |
{ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
62 |
assert(IsTileType(t, MP_STATION)); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
63 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
64 |
const Station *st = GetStationByTile(t); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
65 |
const AirportFTAClass *apc = st->Airport(); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
66 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
67 |
for (uint i = 0; i < apc->nof_depots; i++) { |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
68 |
if (st->airport_tile + ToTileIndexDiff(apc->airport_depots[i]) == t) return true; |
5969 | 69 |
} |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
70 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
71 |
return false; |
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
72 |
} |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
73 |
|
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
74 |
RoadStop *GetRoadStopByTile(TileIndex tile, RoadStopType type) |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
75 |
{ |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
76 |
const Station *st = GetStationByTile(tile); |
6395 | 77 |
|
78 |
for (RoadStop *rs = st->GetPrimaryRoadStop(type);; rs = rs->next) { |
|
79 |
if (rs->xy == tile) return rs; |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
80 |
assert(rs->next != NULL); |
2639 | 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 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
83 |
|
6164 | 84 |
|
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
85 |
static uint GetNumRoadStopsInStation(const Station *st, RoadStopType type) |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
86 |
{ |
2549 | 87 |
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
|
88 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
89 |
assert(st != NULL); |
6395 | 90 |
for (const RoadStop *rs = st->GetPrimaryRoadStop(type); rs != NULL; rs = rs->next) { |
91 |
num++; |
|
92 |
} |
|
1217
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 |
return num; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
95 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
96 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
97 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
98 |
/** Calculate the radius of the station. Basicly it is the biggest |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
99 |
* radius that is available within the station |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
100 |
* @param st Station to query |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
101 |
* @return the so calculated radius |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
102 |
*/ |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
103 |
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
|
104 |
{ |
6367 | 105 |
uint ret = CA_NONE; |
106 |
||
107 |
if (st->bus_stops != NULL) ret = max<uint>(ret, CA_BUS); |
|
108 |
if (st->truck_stops != NULL) ret = max<uint>(ret, CA_TRUCK); |
|
109 |
if (st->train_tile != 0) ret = max<uint>(ret, CA_TRAIN); |
|
110 |
if (st->dock_tile != 0) ret = max<uint>(ret, CA_DOCK); |
|
111 |
if (st->airport_tile) ret = max<uint>(ret, st->Airport()->catchment); |
|
703
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
112 |
|
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
113 |
return ret; |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
114 |
} |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
115 |
|
0 | 116 |
#define CHECK_STATIONS_ERR ((Station*)-1) |
117 |
||
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
118 |
static Station *GetStationAround(TileIndex tile, int w, int h, StationID closest_station) |
0 | 119 |
{ |
9574 | 120 |
/* check around to see if there's any stations there */ |
1981 | 121 |
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
|
122 |
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
|
123 |
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
|
124 |
|
2498
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
125 |
if (closest_station == INVALID_STATION) { |
0 | 126 |
closest_station = t; |
127 |
} else if (closest_station != t) { |
|
128 |
_error_message = STR_3006_ADJOINS_MORE_THAN_ONE_EXISTING; |
|
129 |
return CHECK_STATIONS_ERR; |
|
130 |
} |
|
131 |
} |
|
1981 | 132 |
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
|
133 |
return (closest_station == INVALID_STATION) ? NULL : GetStation(closest_station); |
0 | 134 |
} |
135 |
||
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
136 |
/** |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
137 |
* Function to check whether the given tile matches some criterion. |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
138 |
* @param tile the tile to check |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
139 |
* @return true if it matches, false otherwise |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
140 |
*/ |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
141 |
typedef bool (*CMSAMatcher)(TileIndex tile); |
0 | 142 |
|
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
|
143 |
/** |
b14c49efef1e
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
144 |
* 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
|
145 |
* @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
|
146 |
* @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
|
147 |
* @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
|
148 |
* in all other cases this parameter is ignored |
6527
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6524
diff
changeset
|
149 |
* @return the result the noumber of matching tiles around |
3515
b14c49efef1e
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
150 |
*/ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
151 |
static int CountMapSquareAround(TileIndex tile, CMSAMatcher cmp) |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
152 |
{ |
0 | 153 |
int num = 0; |
154 |
||
6395 | 155 |
for (int dx = -3; dx <= 3; dx++) { |
156 |
for (int dy = -3; dy <= 3; dy++) { |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
157 |
if (cmp(TILE_MASK(tile + TileDiffXY(dx, dy)))) num++; |
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
|
158 |
} |
0 | 159 |
} |
160 |
||
161 |
return num; |
|
162 |
} |
|
163 |
||
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
164 |
/** |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
165 |
* Check whether the tile is a mine. |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
166 |
* @param tile the tile to investigate. |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
167 |
* @return true if and only if the tile is a mine |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
168 |
*/ |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
169 |
static bool CMSAMine(TileIndex tile) |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
170 |
{ |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
171 |
/* No industry */ |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
172 |
if (!IsTileType(tile, MP_INDUSTRY)) return false; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
173 |
|
9704 | 174 |
const Industry *ind = GetIndustryByTile(tile); |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
175 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
176 |
/* No extractive industry */ |
9704 | 177 |
if ((GetIndustrySpec(ind->type)->life_type & INDUSTRYLIFE_EXTRACTIVE) == 0) return false; |
178 |
||
179 |
for (uint i = 0; i < lengthof(ind->produced_cargo); i++) { |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
180 |
/* The industry extracts something non-liquid, i.e. no oil or plastic, so it is a mine */ |
9704 | 181 |
if (ind->produced_cargo[i] != CT_INVALID && (GetCargo(ind->produced_cargo[i])->classes & CC_LIQUID) == 0) return true; |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
182 |
} |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
183 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
184 |
return false; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
185 |
} |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
186 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
187 |
/** |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
188 |
* Check whether the tile is water. |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
189 |
* @param tile the tile to investigate. |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
190 |
* @return true if and only if the tile is a mine |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
191 |
*/ |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
192 |
static bool CMSAWater(TileIndex tile) |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
193 |
{ |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
194 |
return IsTileType(tile, MP_WATER) && IsWater(tile); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
195 |
} |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
196 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
197 |
/** |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
198 |
* Check whether the tile is a tree. |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
199 |
* @param tile the tile to investigate. |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
200 |
* @return true if and only if the tile is a mine |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
201 |
*/ |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
202 |
static bool CMSATree(TileIndex tile) |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
203 |
{ |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
204 |
return IsTileType(tile, MP_TREES); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
205 |
} |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
206 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
207 |
/** |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
208 |
* Check whether the tile is a forest. |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
209 |
* @param tile the tile to investigate. |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
210 |
* @return true if and only if the tile is a mine |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
211 |
*/ |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
212 |
static bool CMSAForest(TileIndex tile) |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
213 |
{ |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
214 |
/* No industry */ |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
215 |
if (!IsTileType(tile, MP_INDUSTRY)) return false; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
216 |
|
9704 | 217 |
const Industry *ind = GetIndustryByTile(tile); |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
218 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
219 |
/* No extractive industry */ |
9704 | 220 |
if ((GetIndustrySpec(ind->type)->life_type & INDUSTRYLIFE_ORGANIC) == 0) return false; |
221 |
||
222 |
for (uint i = 0; i < lengthof(ind->produced_cargo); i++) { |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
223 |
/* The industry produces wood. */ |
9704 | 224 |
if (ind->produced_cargo[i] != CT_INVALID && GetCargo(ind->produced_cargo[i])->label == 'WOOD') return true; |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
225 |
} |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
226 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
227 |
return false; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
228 |
} |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
229 |
|
0 | 230 |
#define M(x) ((x) - STR_SV_STNAME) |
231 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
232 |
enum StationNaming { |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
233 |
STATIONNAMING_RAIL = 0, |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
234 |
STATIONNAMING_ROAD = 0, |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
235 |
STATIONNAMING_AIRPORT, |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
236 |
STATIONNAMING_OILRIG, |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
237 |
STATIONNAMING_DOCK, |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
238 |
STATIONNAMING_BUOY, |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
239 |
STATIONNAMING_HELIPORT, |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
240 |
}; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
241 |
|
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
242 |
static StringID GenerateStationName(Station *st, TileIndex tile, int flag) |
0 | 243 |
{ |
244 |
static const uint32 _gen_station_name_bits[] = { |
|
1454 | 245 |
0, /* 0 */ |
246 |
1 << M(STR_SV_STNAME_AIRPORT), /* 1 */ |
|
247 |
1 << M(STR_SV_STNAME_OILFIELD), /* 2 */ |
|
248 |
1 << M(STR_SV_STNAME_DOCKS), /* 3 */ |
|
249 |
0x1FF << M(STR_SV_STNAME_BUOY_1), /* 4 */ |
|
250 |
1 << M(STR_SV_STNAME_HELIPORT), /* 5 */ |
|
0 | 251 |
}; |
252 |
||
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
253 |
const Town *t = st->town; |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
254 |
uint32 free_names = UINT32_MAX; |
0 | 255 |
|
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
256 |
const Station *s; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
257 |
FOR_ALL_STATIONS(s) { |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
258 |
if (s != st && s->town == t) { |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
259 |
uint str = M(s->string_id); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
260 |
if (str <= 0x20) { |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
261 |
if (str == M(STR_SV_STNAME_FOREST)) { |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
262 |
str = M(STR_SV_STNAME_WOODS); |
0 | 263 |
} |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
264 |
ClrBit(free_names, str); |
0 | 265 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
266 |
} |
0 | 267 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
268 |
|
0 | 269 |
/* check default names */ |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
270 |
uint32 tmp = free_names & _gen_station_name_bits[flag]; |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
271 |
if (tmp != 0) return STR_SV_STNAME + FindFirstBit(tmp); |
0 | 272 |
|
273 |
/* check mine? */ |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
274 |
if (HasBit(free_names, M(STR_SV_STNAME_MINES))) { |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
275 |
if (CountMapSquareAround(tile, CMSAMine) >= 2) { |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
276 |
return STR_SV_STNAME_MINES; |
1454 | 277 |
} |
0 | 278 |
} |
279 |
||
280 |
/* check close enough to town to get central as name? */ |
|
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
281 |
if (DistanceMax(tile, t->xy) < 8) { |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
282 |
if (HasBit(free_names, M(STR_SV_STNAME))) return STR_SV_STNAME; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
283 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
284 |
if (HasBit(free_names, M(STR_SV_STNAME_CENTRAL))) return STR_SV_STNAME_CENTRAL; |
0 | 285 |
} |
286 |
||
287 |
/* Check lakeside */ |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
288 |
if (HasBit(free_names, M(STR_SV_STNAME_LAKESIDE)) && |
1472
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
289 |
DistanceFromEdge(tile) < 20 && |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
290 |
CountMapSquareAround(tile, CMSAWater) >= 5) { |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
291 |
return STR_SV_STNAME_LAKESIDE; |
1454 | 292 |
} |
0 | 293 |
|
294 |
/* Check woods */ |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
295 |
if (HasBit(free_names, M(STR_SV_STNAME_WOODS)) && ( |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
296 |
CountMapSquareAround(tile, CMSATree) >= 8 || |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
297 |
CountMapSquareAround(tile, CMSAForest) >= 2) |
1472
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
298 |
) { |
10776 | 299 |
return _settings_game.game_creation.landscape == LT_TROPIC ? STR_SV_STNAME_FOREST : STR_SV_STNAME_WOODS; |
0 | 300 |
} |
301 |
||
302 |
/* check elevation compared to town */ |
|
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
303 |
uint z = GetTileZ(tile); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
304 |
uint z2 = GetTileZ(t->xy); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
305 |
if (z < z2) { |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
306 |
if (HasBit(free_names, M(STR_SV_STNAME_VALLEY))) return STR_SV_STNAME_VALLEY; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
307 |
} else if (z > z2) { |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
308 |
if (HasBit(free_names, M(STR_SV_STNAME_HEIGHTS))) return STR_SV_STNAME_HEIGHTS; |
0 | 309 |
} |
310 |
||
311 |
/* check direction compared to town */ |
|
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
312 |
static const int8 _direction_and_table[] = { |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
313 |
~( (1 << M(STR_SV_STNAME_WEST)) | (1 << M(STR_SV_STNAME_EAST)) | (1 << M(STR_SV_STNAME_NORTH)) ), |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
314 |
~( (1 << M(STR_SV_STNAME_SOUTH)) | (1 << M(STR_SV_STNAME_WEST)) | (1 << M(STR_SV_STNAME_NORTH)) ), |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
315 |
~( (1 << M(STR_SV_STNAME_SOUTH)) | (1 << M(STR_SV_STNAME_EAST)) | (1 << M(STR_SV_STNAME_NORTH)) ), |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
316 |
~( (1 << M(STR_SV_STNAME_SOUTH)) | (1 << M(STR_SV_STNAME_WEST)) | (1 << M(STR_SV_STNAME_EAST)) ), |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
317 |
}; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
318 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
319 |
free_names &= _direction_and_table[ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
320 |
(TileX(tile) < TileX(t->xy)) + |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
321 |
(TileY(tile) < TileY(t->xy)) * 2]; |
0 | 322 |
|
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
323 |
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)); |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
324 |
return (tmp == 0) ? STR_SV_STNAME_FALLBACK : (STR_SV_STNAME + FindFirstBit(tmp)); |
0 | 325 |
} |
326 |
#undef M |
|
327 |
||
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
328 |
static Station *GetClosestStationFromTile(TileIndex tile) |
0 | 329 |
{ |
6378 | 330 |
uint threshold = 8; |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
331 |
Station *best_station = NULL; |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
332 |
Station *st; |
0 | 333 |
|
334 |
FOR_ALL_STATIONS(st) { |
|
6378 | 335 |
if (st->facilities == 0 && st->owner == _current_player) { |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
336 |
uint cur_dist = DistanceManhattan(tile, st->xy); |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
337 |
|
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
338 |
if (cur_dist < threshold) { |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
339 |
threshold = cur_dist; |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
340 |
best_station = st; |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
341 |
} |
0 | 342 |
} |
343 |
} |
|
344 |
||
345 |
return best_station; |
|
346 |
} |
|
347 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
348 |
/** Update the virtual coords needed to draw the station sign. |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
349 |
* @param st Station to update for. |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
350 |
*/ |
0 | 351 |
static void UpdateStationVirtCoord(Station *st) |
352 |
{ |
|
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
|
353 |
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
|
354 |
|
0 | 355 |
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
|
356 |
if (st->facilities & FACIL_AIRPORT && st->airport_type == AT_OILRIG) pt.y -= 16; |
0 | 357 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
358 |
SetDParam(0, st->index); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
359 |
SetDParam(1, st->facilities); |
0 | 360 |
UpdateViewportSignPos(&st->sign, pt.x, pt.y, STR_305C_0); |
361 |
} |
|
362 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
363 |
/** Update the virtual coords needed to draw the station sign for all stations. */ |
6573 | 364 |
void UpdateAllStationVirtCoord() |
0 | 365 |
{ |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
366 |
Station *st; |
2639 | 367 |
|
0 | 368 |
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
|
369 |
UpdateStationVirtCoord(st); |
0 | 370 |
} |
371 |
} |
|
372 |
||
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
373 |
/** |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
374 |
* Update the station virt coords while making the modified parts dirty. |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
375 |
* |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
376 |
* This function updates the virt coords and mark the modified parts as dirty |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
377 |
* |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
378 |
* @param st The station to update the virt coords |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
379 |
* @ingroup dirty |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
380 |
*/ |
0 | 381 |
static void UpdateStationVirtCoordDirty(Station *st) |
382 |
{ |
|
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
|
383 |
st->MarkDirty(); |
0 | 384 |
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
|
385 |
st->MarkDirty(); |
0 | 386 |
} |
387 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
388 |
/** Get a mask of the cargo types that the station accepts. |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
389 |
* @param st Station to query |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
390 |
* @return the expected mask |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
391 |
*/ |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
392 |
static uint GetAcceptanceMask(const Station *st) |
0 | 393 |
{ |
394 |
uint mask = 0; |
|
6395 | 395 |
|
9505 | 396 |
for (CargoID i = 0; i < NUM_CARGO; i++) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
397 |
if (HasBit(st->goods[i].acceptance_pickup, GoodsEntry::ACCEPTANCE)) mask |= 1 << i; |
0 | 398 |
} |
399 |
return mask; |
|
400 |
} |
|
401 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
402 |
/** Items contains the two cargo names that are to be accepted or rejected. |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
403 |
* msg is the string id of the message to display. |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
404 |
*/ |
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
|
405 |
static void ShowRejectOrAcceptNews(const Station *st, uint num_items, CargoID *cargo, StringID msg) |
0 | 406 |
{ |
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
|
407 |
for (uint i = 0; i < num_items; i++) { |
6417
26acff62d001
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents:
6413
diff
changeset
|
408 |
SetDParam(i + 1, GetCargo(cargo[i])->name); |
0 | 409 |
} |
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
|
410 |
|
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
|
411 |
SetDParam(0, st->index); |
10645 | 412 |
AddNewsItem(msg, NS_ACCEPTANCE, st->xy, 0); |
0 | 413 |
} |
414 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
415 |
/** |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
416 |
* Get a list of the cargo types being produced around the tile (in a rectangle). |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
417 |
* @param produced: Destination array of produced cargo |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
418 |
* @param tile: Center of the search area |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
419 |
* @param w: Width of the center |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
420 |
* @param h: Height of the center |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
421 |
* @param rad: Radius of the search area |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
422 |
*/ |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
423 |
void GetProductionAroundTiles(AcceptedCargo produced, TileIndex tile, |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
424 |
int w, int h, int rad) |
0 | 425 |
{ |
2133 | 426 |
memset(produced, 0, sizeof(AcceptedCargo)); |
0 | 427 |
|
6395 | 428 |
int x = TileX(tile); |
429 |
int y = TileY(tile); |
|
0 | 430 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
431 |
/* expand the region by rad tiles on each side |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
432 |
* while making sure that we remain inside the board. */ |
6395 | 433 |
int x2 = min(x + w + rad, MapSizeX()); |
434 |
int x1 = max(x - rad, 0); |
|
435 |
||
436 |
int y2 = min(y + h + rad, MapSizeY()); |
|
437 |
int y1 = max(y - rad, 0); |
|
0 | 438 |
|
439 |
assert(x1 < x2); |
|
440 |
assert(y1 < y2); |
|
441 |
assert(w > 0); |
|
442 |
assert(h > 0); |
|
443 |
||
6395 | 444 |
for (int yc = y1; yc != y2; yc++) { |
445 |
for (int xc = x1; xc != x2; xc++) { |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
446 |
TileIndex tile = TileXY(xc, yc); |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
447 |
|
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
448 |
if (!IsTileType(tile, MP_STATION)) { |
6395 | 449 |
GetProducedCargoProc *gpc = _tile_type_procs[GetTileType(tile)]->get_produced_cargo_proc; |
0 | 450 |
if (gpc != NULL) { |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
451 |
CargoID cargos[256]; // Required for CBID_HOUSE_PRODUCE_CARGO. |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
452 |
memset(cargos, CT_INVALID, 256); |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
453 |
|
0 | 454 |
gpc(tile, cargos); |
9800 | 455 |
for (uint i = 0; i < lengthof(cargos); ++i) { |
456 |
if (cargos[i] != CT_INVALID) produced[cargos[i]]++; |
|
0 | 457 |
} |
458 |
} |
|
459 |
} |
|
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
460 |
} |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
461 |
} |
0 | 462 |
} |
463 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
464 |
/** |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
465 |
* Get a list of the cargo types that are accepted around the tile. |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
466 |
* @param accepts: Destination array of accepted cargo |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
467 |
* @param tile: Center of the search area |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
468 |
* @param w: Width of the center |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
469 |
* @param h: Height of the center |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
470 |
* @param rad: Radius of the rectangular search area |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
471 |
*/ |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
472 |
void GetAcceptanceAroundTiles(AcceptedCargo accepts, TileIndex tile, |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
473 |
int w, int h, int rad) |
0 | 474 |
{ |
473
0da86c59e3ae
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
457
diff
changeset
|
475 |
memset(accepts, 0, sizeof(AcceptedCargo)); |
0 | 476 |
|
6395 | 477 |
int x = TileX(tile); |
478 |
int y = TileY(tile); |
|
0 | 479 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
480 |
/* expand the region by rad tiles on each side |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
481 |
* while making sure that we remain inside the board. */ |
6395 | 482 |
int x2 = min(x + w + rad, MapSizeX()); |
483 |
int y2 = min(y + h + rad, MapSizeY()); |
|
484 |
int x1 = max(x - rad, 0); |
|
485 |
int y1 = max(y - rad, 0); |
|
0 | 486 |
|
487 |
assert(x1 < x2); |
|
488 |
assert(y1 < y2); |
|
489 |
assert(w > 0); |
|
490 |
assert(h > 0); |
|
491 |
||
6395 | 492 |
for (int yc = y1; yc != y2; yc++) { |
493 |
for (int xc = x1; xc != x2; xc++) { |
|
1981 | 494 |
TileIndex tile = TileXY(xc, yc); |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
495 |
|
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
|
496 |
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
|
497 |
AcceptedCargo ac; |
0da86c59e3ae
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
457
diff
changeset
|
498 |
|
0da86c59e3ae
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
457
diff
changeset
|
499 |
GetAcceptedCargo(tile, ac); |
6395 | 500 |
for (uint i = 0; i < lengthof(ac); ++i) accepts[i] += ac[i]; |
0 | 501 |
} |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
502 |
} |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
503 |
} |
0 | 504 |
} |
505 |
||
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
506 |
static inline void MergePoint(Rect *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
|
507 |
{ |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
508 |
int x = TileX(tile); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
509 |
int y = TileY(tile); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
510 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
511 |
if (rect->left > x) rect->left = x; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
512 |
if (rect->bottom > y) rect->bottom = y; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
513 |
if (rect->right < x) rect->right = x; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
514 |
if (rect->top < y) rect->top = 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
|
515 |
} |
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 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
517 |
/** Update the acceptance for a station. |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
518 |
* @param st Station to update |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
519 |
* @param show_msg controls whether to display a message that acceptance was changed. |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
520 |
*/ |
0 | 521 |
static void UpdateStationAcceptance(Station *st, bool show_msg) |
522 |
{ |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
523 |
/* Don't update acceptance for a buoy */ |
6395 | 524 |
if (st->IsBuoy()) return; |
525 |
||
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
526 |
Rect rect; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
527 |
rect.left = MapSizeX(); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
528 |
rect.bottom = MapSizeY(); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
529 |
rect.right = 0; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
530 |
rect.top = 0; |
0 | 531 |
|
532 |
/* old accepted goods types */ |
|
6395 | 533 |
uint old_acc = GetAcceptanceMask(st); |
0 | 534 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
535 |
/* Put all the tiles that span an area in the table. */ |
0 | 536 |
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
|
537 |
MergePoint(&rect, st->train_tile); |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
538 |
MergePoint(&rect, st->train_tile + TileDiffXY(st->trainst_w - 1, st->trainst_h - 1)); |
0 | 539 |
} |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
540 |
|
0 | 541 |
if (st->airport_tile != 0) { |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
542 |
const AirportFTAClass *afc = st->Airport(); |
3876
c0d426e78b56
(svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents:
3873
diff
changeset
|
543 |
|
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
|
544 |
MergePoint(&rect, st->airport_tile); |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
545 |
MergePoint(&rect, st->airport_tile + TileDiffXY(afc->size_x - 1, afc->size_y - 1)); |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
546 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
547 |
|
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
|
548 |
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
|
549 |
|
6395 | 550 |
for (const RoadStop *rs = st->bus_stops; rs != NULL; rs = rs->next) { |
551 |
MergePoint(&rect, rs->xy); |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
552 |
} |
0 | 553 |
|
6395 | 554 |
for (const RoadStop *rs = st->truck_stops; rs != NULL; rs = rs->next) { |
555 |
MergePoint(&rect, rs->xy); |
|
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 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
558 |
/* And retrieve the acceptance. */ |
6395 | 559 |
AcceptedCargo accepts; |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
560 |
if (rect.right >= rect.left) { |
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 |
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
|
562 |
accepts, |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
563 |
TileXY(rect.left, rect.bottom), |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
564 |
rect.right - rect.left + 1, |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
565 |
rect.top - rect.bottom + 1, |
10776 | 566 |
_settings_game.station.modified_catchment ? FindCatchmentRadius(st) : (uint)CA_UNMODIFIED |
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 |
); |
0 | 568 |
} else { |
569 |
memset(accepts, 0, sizeof(accepts)); |
|
570 |
} |
|
571 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
572 |
/* Adjust in case our station only accepts fewer kinds of goods */ |
9505 | 573 |
for (CargoID i = 0; i < NUM_CARGO; i++) { |
0 | 574 |
uint amt = min(accepts[i], 15); |
575 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
576 |
/* Make sure the station can accept the goods type. */ |
9476 | 577 |
bool is_passengers = IsCargoInClass(i, CC_PASSENGERS); |
578 |
if ((!is_passengers && !(st->facilities & (byte)~FACIL_BUS_STOP)) || |
|
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
579 |
(is_passengers && !(st->facilities & (byte)~FACIL_TRUCK_STOP))) { |
0 | 580 |
amt = 0; |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
581 |
} |
0 | 582 |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
583 |
SB(st->goods[i].acceptance_pickup, GoodsEntry::ACCEPTANCE, 1, amt >= 8); |
0 | 584 |
} |
585 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
586 |
/* Only show a message in case the acceptance was actually changed. */ |
6395 | 587 |
uint new_acc = GetAcceptanceMask(st); |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
588 |
if (old_acc == new_acc) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
589 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
590 |
/* show a message to report that the acceptance was changed? */ |
0 | 591 |
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
|
592 |
/* 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
|
593 |
* 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
|
594 |
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
|
595 |
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
|
596 |
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
|
597 |
}; |
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
|
598 |
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
|
599 |
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
|
600 |
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
|
601 |
}; |
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
|
602 |
|
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
|
603 |
/* 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
|
604 |
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
|
605 |
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
|
606 |
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
|
607 |
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
|
608 |
|
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
|
609 |
/* 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
|
610 |
for (CargoID i = 0; i < NUM_CARGO; i++) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
611 |
if (HasBit(new_acc, i)) { |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
612 |
if (!HasBit(old_acc, i) && num_acc < lengthof(accepts)) { |
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
|
613 |
/* 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
|
614 |
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
|
615 |
} |
0 | 616 |
} else { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
617 |
if (HasBit(old_acc, i) && num_rej < lengthof(rejects)) { |
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
|
618 |
/* 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
|
619 |
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
|
620 |
} |
0 | 621 |
} |
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
|
622 |
} |
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 |
|
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 |
/* 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
|
625 |
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
|
626 |
if (num_rej > 0) ShowRejectOrAcceptNews(st, num_rej, rejects, reject_msg[num_rej - 1]); |
0 | 627 |
} |
628 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
629 |
/* redraw the station view since acceptance changed */ |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
630 |
InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_ACCEPTLIST); |
0 | 631 |
} |
632 |
||
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
|
633 |
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
|
634 |
{ |
6395 | 635 |
const StationRect *r = &st->rect; |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
636 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
637 |
if (r->IsEmpty()) return; /* no tiles belong to this station */ |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
638 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
639 |
/* clamp sign coord to be inside the station rect */ |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
640 |
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
|
641 |
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
|
642 |
} |
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
|
643 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
644 |
/** This is called right after a station was deleted. |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
645 |
* It checks if the whole station is free of substations, and if so, the station will be |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
646 |
* deleted after a little while. |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
647 |
* @param st Station |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
648 |
*/ |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
649 |
static void DeleteStationIfEmpty(Station *st) |
2639 | 650 |
{ |
0 | 651 |
if (st->facilities == 0) { |
652 |
st->delete_ctr = 0; |
|
10645 | 653 |
InvalidateWindowData(WC_STATION_LIST, st->owner, 0); |
27
87c8058a69b5
(svn r28) -Fix removing station merged with oilrig, will reset oilrigs ownership
darkvater
parents:
22
diff
changeset
|
654 |
} |
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
|
655 |
/* 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
|
656 |
UpdateStationSignCoord(st); |
0 | 657 |
} |
658 |
||
9629 | 659 |
static CommandCost ClearTile_Station(TileIndex tile, byte flags); |
977
bcafa4f6550a
(svn r1472) -Fix: correct error message for when trying to build a railroad station over a bus/truck/etc-station.
darkvater
parents:
972
diff
changeset
|
660 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
661 |
/** Tries to clear the given area. |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
662 |
* @param tile TileIndex to start check |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
663 |
* @param w width of search area |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
664 |
* @param h height of search area |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
665 |
* @param flags operation to perform |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
666 |
* @param invalid_dirs prohibited directions (set of DiagDirections) |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
667 |
* @param station StationID to be queried and returned if available |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
668 |
* @param check_clear if clearing tile should be performed (in wich case, cost will be added) |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
669 |
* @return the cost in case of success, or an error code if it failed. |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
670 |
*/ |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
671 |
CommandCost CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invalid_dirs, StationID *station, bool check_clear = true) |
0 | 672 |
{ |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
673 |
CommandCost cost(EXPENSES_CONSTRUCTION); |
1335
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1328
diff
changeset
|
674 |
int allowed_z = -1; |
6395 | 675 |
|
676 |
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
|
677 |
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
|
678 |
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
|
679 |
} |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5568
diff
changeset
|
680 |
|
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
681 |
if (!EnsureNoVehicleOnGround(tile_cur)) return CMD_ERROR; |
0 | 682 |
|
6395 | 683 |
uint z; |
684 |
Slope tileh = GetTileSlope(tile_cur, &z); |
|
0 | 685 |
|
2085
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
686 |
/* Prohibit building if |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
687 |
* 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
|
688 |
* -OR- |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
689 |
* 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
|
690 |
* 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
|
691 |
* -OR- |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
692 |
* 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
|
693 |
*/ |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
694 |
if (IsSteepSlope(tileh) || |
10776 | 695 |
((!_settings_game.construction.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
|
696 |
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
0 | 697 |
} |
698 |
||
6395 | 699 |
int flat_z = z; |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
700 |
if (tileh != SLOPE_FLAT) { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
701 |
/* need to check so the entrance to the station is not pointing at a slope. |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
702 |
* This must be valid for all station tiles, as the user can remove single station tiles. */ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
703 |
if ((HasBit(invalid_dirs, DIAGDIR_NE) && !(tileh & SLOPE_NE)) || |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
704 |
(HasBit(invalid_dirs, DIAGDIR_SE) && !(tileh & SLOPE_SE)) || |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
705 |
(HasBit(invalid_dirs, DIAGDIR_SW) && !(tileh & SLOPE_SW)) || |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
706 |
(HasBit(invalid_dirs, DIAGDIR_NW) && !(tileh & SLOPE_NW))) { |
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
|
707 |
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
0 | 708 |
} |
9629 | 709 |
cost.AddCost(_price.terraform); |
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
710 |
flat_z += TILE_HEIGHT; |
0 | 711 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
712 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
713 |
/* get corresponding flat level and make sure that all parts of the station have the same level. */ |
0 | 714 |
if (allowed_z == -1) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
715 |
/* first tile */ |
0 | 716 |
allowed_z = flat_z; |
717 |
} 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
|
718 |
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
0 | 719 |
} |
720 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
721 |
/* if station is set, then we have special handling to allow building on top of already existing stations. |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
722 |
* so station points to INVALID_STATION if we can build on any station. |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
723 |
* Or it points to a station if we're only allowed to build 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
|
724 |
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
|
725 |
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
|
726 |
return ClearTile_Station(tile_cur, DC_AUTO); // get error message |
0 | 727 |
} 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
|
728 |
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
|
729 |
if (*station == INVALID_STATION) { |
0 | 730 |
*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
|
731 |
} 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
|
732 |
return_cmd_error(STR_3006_ADJOINS_MORE_THAN_ONE_EXISTING); |
0 | 733 |
} |
734 |
} |
|
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
735 |
} else if (check_clear) { |
9629 | 736 |
CommandCost 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
|
737 |
if (CmdFailed(ret)) return ret; |
9629 | 738 |
cost.AddCost(ret); |
0 | 739 |
} |
6395 | 740 |
} END_TILE_LOOP(tile_cur, w, h, tile) |
0 | 741 |
|
742 |
return cost; |
|
743 |
} |
|
744 |
||
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
745 |
static bool CanExpandRailroadStation(const Station *st, uint *fin, Axis axis) |
0 | 746 |
{ |
6395 | 747 |
uint curw = st->trainst_w; |
748 |
uint curh = st->trainst_h; |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
749 |
TileIndex tile = fin[0]; |
0 | 750 |
uint w = fin[1]; |
751 |
uint h = fin[2]; |
|
752 |
||
10776 | 753 |
if (_settings_game.station.nonuniform_stations) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
754 |
/* 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
|
755 |
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
|
756 |
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
|
757 |
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
|
758 |
curh = max(TileY(st->train_tile) + curh, TileY(tile) + h) - y; |
1981 | 759 |
tile = TileXY(x, y); |
0 | 760 |
} else { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
761 |
/* do not allow modifying non-uniform stations, |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
762 |
* the uniform-stations code wouldn't handle it well */ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
763 |
BEGIN_TILE_LOOP(t, st->trainst_w, st->trainst_h, st->train_tile) |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
764 |
if (!st->TileBelongsToRailStation(t)) { // there may be adjoined station |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
765 |
_error_message = STR_NONUNIFORM_STATIONS_DISALLOWED; |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
766 |
return false; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
767 |
} |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
768 |
END_TILE_LOOP(t, st->trainst_w, st->trainst_h, st->train_tile) |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
769 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
770 |
/* 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
|
771 |
if (GetRailStationAxis(st->train_tile) != axis) { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
772 |
_error_message = STR_NONUNIFORM_STATIONS_DISALLOWED; |
1189
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
773 |
return false; |
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
774 |
} |
0 | 775 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
776 |
/* check if the new station adjoins the old station in either direction */ |
1981 | 777 |
if (curw == w && st->train_tile == tile + TileDiffXY(0, h)) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
778 |
/* above */ |
0 | 779 |
curh += h; |
1981 | 780 |
} else if (curw == w && st->train_tile == tile - TileDiffXY(0, curh)) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
781 |
/* below */ |
1981 | 782 |
tile -= TileDiffXY(0, curh); |
0 | 783 |
curh += h; |
1981 | 784 |
} else if (curh == h && st->train_tile == tile + TileDiffXY(w, 0)) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
785 |
/* to the left */ |
0 | 786 |
curw += w; |
1981 | 787 |
} else if (curh == h && st->train_tile == tile - TileDiffXY(curw, 0)) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
788 |
/* to the right */ |
1981 | 789 |
tile -= TileDiffXY(curw, 0); |
0 | 790 |
curw += w; |
1189
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
791 |
} else { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
792 |
_error_message = STR_NONUNIFORM_STATIONS_DISALLOWED; |
0 | 793 |
return false; |
1189
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
794 |
} |
0 | 795 |
} |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
796 |
/* make sure the final size is not too big. */ |
10776 | 797 |
if (curw > _settings_game.station.station_spread || curh > _settings_game.station.station_spread) { |
1189
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
798 |
_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
|
799 |
return false; |
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
800 |
} |
0 | 801 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
802 |
/* now tile contains the new value for st->train_tile |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
803 |
* curw, curh contain the new value for width and height */ |
0 | 804 |
fin[0] = tile; |
805 |
fin[1] = curw; |
|
806 |
fin[2] = curh; |
|
807 |
return true; |
|
808 |
} |
|
809 |
||
536 | 810 |
static inline byte *CreateSingle(byte *layout, int n) |
0 | 811 |
{ |
812 |
int i = n; |
|
813 |
do *layout++ = 0; while (--i); |
|
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
814 |
layout[((n - 1) >> 1) - n] = 2; |
0 | 815 |
return layout; |
816 |
} |
|
817 |
||
536 | 818 |
static inline byte *CreateMulti(byte *layout, int n, byte b) |
0 | 819 |
{ |
820 |
int i = n; |
|
821 |
do *layout++ = b; while (--i); |
|
822 |
if (n > 4) { |
|
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
823 |
layout[0 - n] = 0; |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
824 |
layout[n - 1 - n] = 0; |
0 | 825 |
} |
826 |
return layout; |
|
827 |
} |
|
828 |
||
3676
48444d881fbe
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3657
diff
changeset
|
829 |
static void GetStationLayout(byte *layout, int numtracks, int plat_len, const StationSpec *statspec) |
0 | 830 |
{ |
3676
48444d881fbe
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3657
diff
changeset
|
831 |
if (statspec != NULL && statspec->lengths >= plat_len && |
48444d881fbe
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3657
diff
changeset
|
832 |
statspec->platforms[plat_len - 1] >= numtracks && |
48444d881fbe
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3657
diff
changeset
|
833 |
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
|
834 |
/* Custom layout defined, follow it. */ |
3676
48444d881fbe
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3657
diff
changeset
|
835 |
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
|
836 |
plat_len * numtracks); |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
837 |
return; |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
838 |
} |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
839 |
|
0 | 840 |
if (plat_len == 1) { |
841 |
CreateSingle(layout, numtracks); |
|
842 |
} else { |
|
2639 | 843 |
if (numtracks & 1) layout = CreateSingle(layout, plat_len); |
844 |
numtracks >>= 1; |
|
0 | 845 |
|
846 |
while (--numtracks >= 0) { |
|
847 |
layout = CreateMulti(layout, plat_len, 4); |
|
848 |
layout = CreateMulti(layout, plat_len, 6); |
|
849 |
} |
|
850 |
} |
|
851 |
} |
|
852 |
||
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
|
853 |
/** 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
|
854 |
* @param tile_org starting position of station dragging/placement |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
855 |
* @param flags operation to perform |
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1774
diff
changeset
|
856 |
* @param p1 various bitstuffed elements |
6460 | 857 |
* - p1 = (bit 0) - orientation (Axis) |
2140
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2133
diff
changeset
|
858 |
* - 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
|
859 |
* - p1 = (bit 16-23) - platform length |
9624 | 860 |
* - p1 = (bit 24) - allow stations directly adjacent to other stations. |
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1774
diff
changeset
|
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 |
*/ |
9629 | 866 |
CommandCost CmdBuildRailroadStation(TileIndex tile_org, uint32 flags, uint32 p1, uint32 p2) |
0 | 867 |
{ |
868 |
/* 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
|
869 |
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile_org)) return CMD_ERROR; |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
870 |
if (!ValParamRailtype((RailType)(p2 & 0xF))) return CMD_ERROR; |
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
|
871 |
|
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
|
872 |
/* unpack parameters */ |
6460 | 873 |
Axis axis = Extract<Axis, 0>(p1); |
6395 | 874 |
uint numtracks = GB(p1, 8, 8); |
875 |
uint plat_len = GB(p1, 16, 8); |
|
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
876 |
|
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
877 |
int w_org, h_org; |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
878 |
if (axis == AXIS_X) { |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
879 |
w_org = plat_len; |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
880 |
h_org = numtracks; |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
881 |
} 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
|
882 |
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
|
883 |
w_org = numtracks; |
0 | 884 |
} |
885 |
||
10776 | 886 |
if (h_org > _settings_game.station.station_spread || w_org > _settings_game.station.station_spread) return CMD_ERROR; |
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
|
887 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
888 |
/* these values are those that will be stored in train_tile and station_platforms */ |
6395 | 889 |
uint finalvalues[3]; |
0 | 890 |
finalvalues[0] = tile_org; |
891 |
finalvalues[1] = w_org; |
|
892 |
finalvalues[2] = h_org; |
|
893 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
894 |
/* Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station) */ |
6395 | 895 |
StationID est = INVALID_STATION; |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
896 |
/* If DC_EXEC is in flag, do not want to pass it to CheckFlatLandBelow, because of a nice bug |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
897 |
* for detail info, see: |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
898 |
* https://sourceforge.net/tracker/index.php?func=detail&aid=1029064&group_id=103924&atid=636365 */ |
10776 | 899 |
CommandCost ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags & ~DC_EXEC, 5 << axis, _settings_game.station.nonuniform_stations ? &est : NULL); |
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
|
900 |
if (CmdFailed(ret)) return ret; |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
901 |
CommandCost cost(EXPENSES_CONSTRUCTION, ret.GetCost() + (numtracks * _price.train_station_track + _price.train_station_length) * plat_len); |
0 | 902 |
|
9624 | 903 |
Station *st = NULL; |
904 |
bool check_surrounding = true; |
|
905 |
||
10776 | 906 |
if (_settings_game.station.adjacent_stations) { |
9624 | 907 |
if (est != INVALID_STATION) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
908 |
if (HasBit(p1, 24)) { |
9624 | 909 |
/* You can't build an adjacent station over the top of one that |
910 |
* already exists. */ |
|
911 |
return_cmd_error(STR_MUST_REMOVE_RAILWAY_STATION_FIRST); |
|
912 |
} else { |
|
913 |
/* Extend the current station, and don't check whether it will |
|
914 |
* be near any other stations. */ |
|
915 |
st = GetStation(est); |
|
916 |
check_surrounding = false; |
|
917 |
} |
|
918 |
} else { |
|
919 |
/* There's no station here. Don't check the tiles surrounding this |
|
920 |
* one if the player wanted to build an adjacent station. */ |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
921 |
if (HasBit(p1, 24)) check_surrounding = false; |
9624 | 922 |
} |
923 |
} |
|
924 |
||
925 |
if (check_surrounding) { |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
926 |
/* Make sure there are no similar stations around us. */ |
9624 | 927 |
st = GetStationAround(tile_org, w_org, h_org, est); |
928 |
if (st == CHECK_STATIONS_ERR) return CMD_ERROR; |
|
929 |
} |
|
0 | 930 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
931 |
/* See if there is a deleted station close to us. */ |
6378 | 932 |
if (st == NULL) st = GetClosestStationFromTile(tile_org); |
0 | 933 |
|
934 |
if (st != NULL) { |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
935 |
/* Reuse an existing station. */ |
6390 | 936 |
if (st->owner != _current_player) |
0 | 937 |
return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION); |
938 |
||
939 |
if (st->train_tile != 0) { |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
940 |
/* check if we want to expanding an already existing station? */ |
10776 | 941 |
if (!_settings_game.station.join_stations) |
0 | 942 |
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
|
943 |
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
|
944 |
return CMD_ERROR; |
0 | 945 |
} |
946 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
947 |
/* 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
|
948 |
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
|
949 |
} 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
|
950 |
/* allocate and initialize new station */ |
10355
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
951 |
if (!Station::CanAllocateItem()) return_cmd_error(STR_3008_TOO_MANY_STATIONS_LOADING); |
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
952 |
|
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
953 |
if (flags & DC_EXEC) { |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
954 |
st = new Station(tile_org); |
10355
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
955 |
|
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
956 |
st->town = ClosestTownFromTile(tile_org, UINT_MAX); |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
957 |
st->string_id = GenerateStationName(st, tile_org, STATIONNAMING_RAIL); |
10355
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
958 |
|
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
959 |
if (IsValidPlayer(_current_player)) { |
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
960 |
SetBit(st->town->have_ratings, _current_player); |
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
961 |
} |
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
|
962 |
} |
0 | 963 |
} |
964 |
||
3587 | 965 |
/* Check if the given station class is valid */ |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
966 |
if (GB(p2, 8, 8) >= GetNumStationClasses()) return CMD_ERROR; |
3587 | 967 |
|
968 |
/* Check if we can allocate a custom stationspec to this station */ |
|
6395 | 969 |
const StationSpec *statspec = GetCustomStationSpec((StationClassID)GB(p2, 8, 8), GB(p2, 16, 8)); |
970 |
int specindex = AllocateSpecToStation(statspec, st, flags & DC_EXEC); |
|
3587 | 971 |
if (specindex == -1) return CMD_ERROR; |
972 |
||
3754
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
973 |
if (statspec != NULL) { |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
974 |
/* Perform NewStation checks */ |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
975 |
|
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
976 |
/* Check if the station size is permitted */ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
977 |
if (HasBit(statspec->disallowed_platforms, numtracks - 1) || HasBit(statspec->disallowed_lengths, plat_len - 1)) { |
3754
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
978 |
return CMD_ERROR; |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
979 |
} |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
980 |
|
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
981 |
/* Check if the station is buildable */ |
10294 | 982 |
if (HasBit(statspec->callbackmask, CBM_STATION_AVAIL) && GB(GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE), 0, 8) == 0) { |
3754
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
983 |
return CMD_ERROR; |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
984 |
} |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
985 |
} |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
986 |
|
0 | 987 |
if (flags & DC_EXEC) { |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
988 |
TileIndexDiff tile_delta; |
0 | 989 |
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
|
990 |
byte numtracks_orig; |
2824
a7a9d3239884
(svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents:
2817
diff
changeset
|
991 |
Track track; |
0 | 992 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
993 |
/* Now really clear the land below the station |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
994 |
* It should never return CMD_ERROR.. but you never know ;) |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
995 |
* (a bit strange function name for it, but it really does clear the land, when DC_EXEC is in flags) */ |
10776 | 996 |
ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags, 5 << axis, _settings_game.station.nonuniform_stations ? &est : NULL); |
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
|
997 |
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
|
998 |
|
0 | 999 |
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
|
1000 |
st->AddFacility(FACIL_TRAIN, finalvalues[0]); |
0 | 1001 |
|
1002 |
st->trainst_w = finalvalues[1]; |
|
1003 |
st->trainst_h = finalvalues[2]; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1004 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1005 |
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
|
1006 |
|
10294 | 1007 |
if (statspec != NULL) { |
1008 |
/* Include this station spec's animation trigger bitmask |
|
1009 |
* in the station's cached copy. */ |
|
1010 |
st->cached_anim_triggers |= statspec->anim_triggers; |
|
1011 |
} |
|
1012 |
||
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
1013 |
tile_delta = (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); |
4158 | 1014 |
track = AxisToTrack(axis); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1015 |
|
10920 | 1016 |
layout_ptr = AllocaM(byte, numtracks * plat_len); |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1017 |
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
|
1018 |
|
3769
2fd087fd336f
(svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents:
3766
diff
changeset
|
1019 |
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
|
1020 |
|
0 | 1021 |
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
|
1022 |
TileIndex tile = tile_org; |
0 | 1023 |
int w = plat_len; |
1024 |
do { |
|
3769
2fd087fd336f
(svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents:
3766
diff
changeset
|
1025 |
byte layout = *layout_ptr++; |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1026 |
MakeRailStation(tile, st->owner, st->index, axis, layout & ~1, (RailType)GB(p2, 0, 4)); |
3587 | 1027 |
SetCustomStationSpecIndex(tile, specindex); |
3742
8528d7737361
(svn r4724) - Newstations: Add per-tile random data for station tiles.
peter1138
parents:
3741
diff
changeset
|
1028 |
SetStationTileRandomBits(tile, GB(Random(), 0, 4)); |
10294 | 1029 |
SetStationAnimationFrame(tile, 0); |
0 | 1030 |
|
3754
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
1031 |
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
|
1032 |
/* 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
|
1033 |
uint32 platinfo = GetPlatformInfo(AXIS_X, 0, plat_len, numtracks_orig, plat_len - w, numtracks_orig - numtracks, false); |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1034 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1035 |
/* As the station is not yet completely finished, the station does not yet exist. */ |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1036 |
uint16 callback = GetStationCallback(CBID_STATION_TILE_LAYOUT, platinfo, 0, statspec, NULL, tile); |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1037 |
if (callback != CALLBACK_FAILED && callback < 8) SetStationGfx(tile, (callback & ~1) + axis); |
10294 | 1038 |
|
1039 |
/* Trigger station animation -- after building? */ |
|
1040 |
StationAnimationTrigger(st, tile, STAT_ANIM_BUILT); |
|
3754
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
1041 |
} |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
1042 |
|
0 | 1043 |
tile += tile_delta; |
1044 |
} while (--w); |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1045 |
AddTrackToSignalBuffer(tile_org, track, _current_player); |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
1046 |
YapfNotifyTrackLayoutChange(tile_org, track); |
1981 | 1047 |
tile_org += tile_delta ^ TileDiffXY(1, 1); // perpendicular to tile_delta |
0 | 1048 |
} while (--numtracks); |
1049 |
||
9626 | 1050 |
st->MarkTilesDirty(false); |
0 | 1051 |
UpdateStationVirtCoordDirty(st); |
1052 |
UpdateStationAcceptance(st, false); |
|
10645 | 1053 |
InvalidateWindowData(WC_STATION_LIST, st->owner, 0); |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1054 |
InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_TRAINS); |
0 | 1055 |
} |
1056 |
||
1057 |
return cost; |
|
1058 |
} |
|
1059 |
||
1060 |
static void MakeRailwayStationAreaSmaller(Station *st) |
|
1061 |
{ |
|
1062 |
uint w = st->trainst_w; |
|
1063 |
uint h = st->trainst_h; |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1064 |
TileIndex tile = st->train_tile; |
0 | 1065 |
|
1066 |
restart: |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1067 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1068 |
/* too small? */ |
0 | 1069 |
if (w != 0 && h != 0) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1070 |
/* check the left side, x = constant, y changes */ |
6395 | 1071 |
for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(0, i));) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1072 |
/* the left side is unused? */ |
1981 | 1073 |
if (++i == h) { |
1074 |
tile += TileDiffXY(1, 0); |
|
1075 |
w--; |
|
1076 |
goto restart; |
|
1077 |
} |
|
1078 |
} |
|
0 | 1079 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1080 |
/* check the right side, x = constant, y changes */ |
6395 | 1081 |
for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(w - 1, i));) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1082 |
/* the right side is unused? */ |
1981 | 1083 |
if (++i == h) { |
1084 |
w--; |
|
1085 |
goto restart; |
|
1086 |
} |
|
1087 |
} |
|
0 | 1088 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1089 |
/* check the upper side, y = constant, x changes */ |
6395 | 1090 |
for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(i, 0));) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1091 |
/* the left side is unused? */ |
1981 | 1092 |
if (++i == w) { |
1093 |
tile += TileDiffXY(0, 1); |
|
1094 |
h--; |
|
1095 |
goto restart; |
|
1096 |
} |
|
1097 |
} |
|
0 | 1098 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1099 |
/* check the lower side, y = constant, x changes */ |
6395 | 1100 |
for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(i, h - 1));) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1101 |
/* the left side is unused? */ |
1981 | 1102 |
if (++i == w) { |
1103 |
h--; |
|
1104 |
goto restart; |
|
1105 |
} |
|
1106 |
} |
|
0 | 1107 |
} else { |
1108 |
tile = 0; |
|
1109 |
} |
|
1110 |
||
1111 |
st->trainst_w = w; |
|
1112 |
st->trainst_h = h; |
|
1113 |
st->train_tile = tile; |
|
1114 |
} |
|
1115 |
||
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1116 |
/** Remove a single tile from a railroad station. |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1117 |
* 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
|
1118 |
* @param tile tile of station piece to remove |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1119 |
* @param flags operation to perform |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1120 |
* @param p1 start_tile |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1121 |
* @param p2 unused |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1122 |
*/ |
9629 | 1123 |
CommandCost CmdRemoveFromRailroadStation(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1124 |
{ |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1125 |
TileIndex start = p1 == 0 ? tile : p1; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1126 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1127 |
/* Count of the number of tiles removed */ |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1128 |
int quantity = 0; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1129 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1130 |
if (tile >= MapSize() || start >= MapSize()) return CMD_ERROR; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1131 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1132 |
/* make sure sx,sy are smaller than ex,ey */ |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1133 |
int ex = TileX(tile); |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1134 |
int ey = TileY(tile); |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1135 |
int sx = TileX(start); |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1136 |
int sy = TileY(start); |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1137 |
if (ex < sx) Swap(ex, sx); |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1138 |
if (ey < sy) Swap(ey, sy); |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1139 |
tile = TileXY(sx, sy); |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1140 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1141 |
int size_x = ex - sx + 1; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1142 |
int size_y = ey - sy + 1; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1143 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1144 |
/* Do the action for every tile into the area */ |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1145 |
BEGIN_TILE_LOOP(tile2, size_x, size_y, tile) { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1146 |
/* Make sure the specified tile is a railroad station */ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1147 |
if (!IsTileType(tile2, MP_STATION) || !IsRailwayStation(tile2)) { |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1148 |
continue; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1149 |
} |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1150 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1151 |
/* If there is a vehicle on ground, do not allow to remove (flood) the tile */ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1152 |
if (!EnsureNoVehicleOnGround(tile2)) { |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1153 |
continue; |
0 | 1154 |
} |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1155 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1156 |
/* Check ownership of station */ |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1157 |
Station *st = GetStationByTile(tile2); |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1158 |
if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) { |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1159 |
continue; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1160 |
} |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1161 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1162 |
/* Do not allow removing from stations if non-uniform stations are not enabled |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1163 |
* The check must be here to give correct error message |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
1164 |
*/ |
10776 | 1165 |
if (!_settings_game.station.nonuniform_stations) return_cmd_error(STR_NONUNIFORM_STATIONS_DISALLOWED); |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1166 |
|
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1167 |
/* If we reached here, the tile is valid so increase the quantity of tiles we will remove */ |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1168 |
quantity++; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1169 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1170 |
if (flags & DC_EXEC) { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1171 |
/* read variables before the station tile is removed */ |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1172 |
uint specindex = GetCustomStationSpecIndex(tile2); |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1173 |
Track track = GetRailStationTrack(tile2); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1174 |
Owner owner = GetTileOwner(tile2); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1175 |
|
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1176 |
DoClearSquare(tile2); |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1177 |
st->rect.AfterRemoveTile(st, tile2); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1178 |
AddTrackToSignalBuffer(tile2, track, owner); |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1179 |
YapfNotifyTrackLayoutChange(tile2, track); |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1180 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1181 |
DeallocateSpecFromStation(st, specindex); |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1182 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1183 |
/* now we need to make the "spanned" area of the railway station smaller |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1184 |
* if we deleted something at the edges. |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1185 |
* we also need to adjust train_tile. */ |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1186 |
MakeRailwayStationAreaSmaller(st); |
9626 | 1187 |
st->MarkTilesDirty(false); |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1188 |
UpdateStationSignCoord(st); |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1189 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1190 |
/* if we deleted the whole station, delete the train facility. */ |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1191 |
if (st->train_tile == 0) { |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1192 |
st->facilities &= ~FACIL_TRAIN; |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1193 |
InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_TRAINS); |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1194 |
UpdateStationVirtCoordDirty(st); |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1195 |
DeleteStationIfEmpty(st); |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1196 |
} |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1197 |
} |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1198 |
} END_TILE_LOOP(tile2, size_x, size_y, tile) |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1199 |
|
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1200 |
/* If we've not removed any tiles, give an error */ |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1201 |
if (quantity == 0) return CMD_ERROR; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
1202 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1203 |
return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_rail_station * quantity); |
0 | 1204 |
} |
1205 |
||
3928
791f04fb29ad
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1206 |
|
9629 | 1207 |
static CommandCost RemoveRailroadStation(Station *st, TileIndex tile, uint32 flags) |
0 | 1208 |
{ |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
123
diff
changeset
|
1209 |
/* if there is flooding and non-uniform stations are enabled, remove platforms tile by tile */ |
10776 | 1210 |
if (_current_player == OWNER_WATER && _settings_game.station.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
|
1211 |
return DoCommand(tile, 0, 0, DC_EXEC, CMD_REMOVE_FROM_RAILROAD_STATION); |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
1212 |
} |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
123
diff
changeset
|
1213 |
|
0 | 1214 |
/* Current player owns the station? */ |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
1215 |
if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) return CMD_ERROR; |
0 | 1216 |
|
1217 |
/* determine width and height of platforms */ |
|
1218 |
tile = st->train_tile; |
|
6395 | 1219 |
int w = st->trainst_w; |
1220 |
int h = st->trainst_h; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1221 |
|
0 | 1222 |
assert(w != 0 && h != 0); |
1223 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1224 |
CommandCost cost(EXPENSES_CONSTRUCTION); |
0 | 1225 |
/* clear all areas of the station */ |
1226 |
do { |
|
1227 |
int w_bak = w; |
|
1228 |
do { |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1229 |
/* 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
|
1230 |
if (st->TileBelongsToRailStation(tile)) { |
9718
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
1231 |
if (!EnsureNoVehicleOnGround(tile)) |
0 | 1232 |
return CMD_ERROR; |
9629 | 1233 |
cost.AddCost(_price.remove_rail_station); |
2824
a7a9d3239884
(svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents:
2817
diff
changeset
|
1234 |
if (flags & DC_EXEC) { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1235 |
/* read variables before the station tile is removed */ |
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1236 |
Track track = GetRailStationTrack(tile); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1237 |
Owner owner = GetTileOwner(tile); // _current_player can be OWNER_WATER |
0 | 1238 |
DoClearSquare(tile); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1239 |
AddTrackToSignalBuffer(tile, track, owner); |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
1240 |
YapfNotifyTrackLayoutChange(tile, track); |
2824
a7a9d3239884
(svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents:
2817
diff
changeset
|
1241 |
} |
0 | 1242 |
} |
1981 | 1243 |
tile += TileDiffXY(1, 0); |
0 | 1244 |
} while (--w); |
1245 |
w = w_bak; |
|
1981 | 1246 |
tile += TileDiffXY(-w, 1); |
0 | 1247 |
} while (--h); |
1248 |
||
1249 |
if (flags & DC_EXEC) { |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1250 |
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
|
1251 |
|
0 | 1252 |
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
|
1253 |
st->trainst_w = st->trainst_h = 0; |
0 | 1254 |
st->facilities &= ~FACIL_TRAIN; |
1255 |
||
3587 | 1256 |
free(st->speclist); |
1257 |
st->num_specs = 0; |
|
1258 |
st->speclist = NULL; |
|
10294 | 1259 |
st->cached_anim_triggers = 0; |
3587 | 1260 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1261 |
InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_TRAINS); |
0 | 1262 |
UpdateStationVirtCoordDirty(st); |
1263 |
DeleteStationIfEmpty(st); |
|
1264 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1265 |
|
0 | 1266 |
return cost; |
1267 |
} |
|
1268 |
||
9517 | 1269 |
/** |
9837
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9826
diff
changeset
|
1270 |
* @param truck_station Determines whether a stop is ROADSTOP_BUS or ROADSTOP_TRUCK |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1271 |
* @param st The Station to do the whole procedure for |
6157 | 1272 |
* @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
|
1273 |
*/ |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
1274 |
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
|
1275 |
{ |
3691
7e1ad0718ed8
(svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents:
3687
diff
changeset
|
1276 |
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
|
1277 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1278 |
if (*primary_stop == NULL) { |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1279 |
/* we have no roadstop of the type yet, so write a "primary stop" */ |
6157 | 1280 |
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
|
1281 |
} else { |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1282 |
/* there are stops already, so append to the end of the list */ |
6157 | 1283 |
RoadStop *stop = *primary_stop; |
1284 |
while (stop->next != NULL) stop = stop->next; |
|
1285 |
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
|
1286 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1287 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1288 |
|
3691
7e1ad0718ed8
(svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents:
3687
diff
changeset
|
1289 |
/** 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
|
1290 |
* @param tile tile to build the stop at |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1291 |
* @param flags operation to perform |
3333 | 1292 |
* @param p1 entrance direction (DiagDirection) |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1293 |
* @param p2 bit 0: 0 for Bus stops, 1 for truck stops |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1294 |
* bit 1: 0 for normal, 1 for drive-through |
9624 | 1295 |
* bit 2..4: the roadtypes |
1296 |
* bit 5: allow stations directly adjacent to other stations. |
|
0 | 1297 |
*/ |
9629 | 1298 |
CommandCost CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1299 |
{ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1300 |
bool type = HasBit(p2, 0); |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1301 |
bool is_drive_through = HasBit(p2, 1); |
9732 | 1302 |
bool build_over_road = is_drive_through && IsNormalRoadTile(tile); |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1303 |
bool town_owned_road = false; |
9624 | 1304 |
RoadTypes rts = (RoadTypes)GB(p2, 2, 3); |
1305 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1306 |
if (!AreValidRoadTypes(rts) || !HasRoadTypesAvail(_current_player, rts)) return CMD_ERROR; |
9624 | 1307 |
|
1308 |
/* Trams only have drive through stops */ |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1309 |
if (!is_drive_through && HasBit(rts, ROADTYPE_TRAM)) return CMD_ERROR; |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
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; |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1313 |
/* If it is a drive-through stop check for valid axis */ |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1314 |
if (is_drive_through && !IsValidAxis((Axis)p1)) return CMD_ERROR; |
6344
c5c1b17c8925
(svn r8741) -Fix (r8735): make the saveguards of CmdBuildRoadStop more robust and add roadstops.grf to the list of required grfs.
rubidium
parents:
6338
diff
changeset
|
1315 |
/* Road bits in the wrong direction */ |
9624 | 1316 |
if (build_over_road && (GetAllRoadBits(tile) & ((Axis)p1 == AXIS_X ? ROAD_Y : ROAD_X)) != 0) return_cmd_error(STR_DRIVE_THROUGH_ERROR_DIRECTION); |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1317 |
|
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1318 |
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) return CMD_ERROR; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1319 |
|
6344
c5c1b17c8925
(svn r8741) -Fix (r8735): make the saveguards of CmdBuildRoadStop more robust and add roadstops.grf to the list of required grfs.
rubidium
parents:
6338
diff
changeset
|
1320 |
/* Not allowed to build over this road */ |
9574 | 1321 |
if (build_over_road) { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1322 |
RoadTypes cur_rts = GetRoadTypes(tile); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1323 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1324 |
/* there is a road, check if we can build road+tram stop over it */ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1325 |
if (HasBit(cur_rts, ROADTYPE_ROAD)) { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1326 |
Owner road_owner = GetRoadOwner(tile, ROADTYPE_ROAD); |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1327 |
if (road_owner == OWNER_TOWN) { |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1328 |
town_owned_road = true; |
10776 | 1329 |
if (!_settings_game.construction.road_stop_on_town_road) return_cmd_error(STR_DRIVE_THROUGH_ERROR_ON_TOWN_ROAD); |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1330 |
} else { |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1331 |
if (road_owner != OWNER_NONE && !CheckOwnership(road_owner)) return CMD_ERROR; |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1332 |
} |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1333 |
} |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1334 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1335 |
/* there is a tram, check if we can build road+tram stop over it */ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1336 |
if (HasBit(cur_rts, ROADTYPE_TRAM)) { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1337 |
Owner tram_owner = GetRoadOwner(tile, ROADTYPE_TRAM); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1338 |
if (tram_owner != OWNER_NONE && !CheckOwnership(tram_owner)) return CMD_ERROR; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1339 |
} |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1340 |
|
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1341 |
/* Don't allow building the roadstop when vehicles are already driving on it */ |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1342 |
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1343 |
|
9624 | 1344 |
/* Do not remove roadtypes! */ |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1345 |
rts |= cur_rts; |
9574 | 1346 |
} |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
1347 |
|
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
1348 |
CommandCost cost = CheckFlatLandBelow(tile, 1, 1, flags, is_drive_through ? 5 << p1 : 1 << p1, NULL, !build_over_road); |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1349 |
if (CmdFailed(cost)) return cost; |
6395 | 1350 |
|
9624 | 1351 |
Station *st = NULL; |
1352 |
||
10776 | 1353 |
if (!_settings_game.station.adjacent_stations || !HasBit(p2, 5)) { |
9624 | 1354 |
st = GetStationAround(tile, 1, 1, INVALID_STATION); |
1355 |
if (st == CHECK_STATIONS_ERR) return CMD_ERROR; |
|
1356 |
} |
|
0 | 1357 |
|
1358 |
/* Find a station close to us */ |
|
6378 | 1359 |
if (st == NULL) st = GetClosestStationFromTile(tile); |
0 | 1360 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1361 |
/* give us a road stop in the list, and check if something went wrong */ |
10355
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1362 |
if (!RoadStop::CanAllocateItem()) return_cmd_error(type ? STR_TOO_MANY_TRUCK_STOPS : STR_TOO_MANY_BUS_STOPS); |
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
|
1363 |
|
2989 | 1364 |
if (st != NULL && |
9837
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9826
diff
changeset
|
1365 |
GetNumRoadStopsInStation(st, ROADSTOP_BUS) + GetNumRoadStopsInStation(st, ROADSTOP_TRUCK) >= RoadStop::LIMIT) { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1366 |
return_cmd_error(type ? STR_TOO_MANY_TRUCK_STOPS : STR_TOO_MANY_BUS_STOPS); |
2951 | 1367 |
} |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1368 |
|
0 | 1369 |
if (st != NULL) { |
6390 | 1370 |
if (st->owner != _current_player) { |
0 | 1371 |
return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION); |
2951 | 1372 |
} |
1373 |
||
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1374 |
if (!st->rect.BeforeAddTile(tile, StationRect::ADD_TEST)) return CMD_ERROR; |
0 | 1375 |
} 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
|
1376 |
/* allocate and initialize new station */ |
10355
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1377 |
if (!Station::CanAllocateItem()) return_cmd_error(STR_3008_TOO_MANY_STATIONS_LOADING); |
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1378 |
|
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1379 |
if (flags & DC_EXEC) { |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
1380 |
st = new Station(tile); |
10355
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1381 |
|
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1382 |
st->town = ClosestTownFromTile(tile, UINT_MAX); |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
1383 |
st->string_id = GenerateStationName(st, tile, STATIONNAMING_ROAD); |
10355
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1384 |
|
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1385 |
if (IsValidPlayer(_current_player)) { |
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1386 |
SetBit(st->town->have_ratings, _current_player); |
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1387 |
} |
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1388 |
st->sign.width_1 = 0; |
2951 | 1389 |
} |
0 | 1390 |
} |
1391 |
||
9629 | 1392 |
cost.AddCost((type) ? _price.build_truck_station : _price.build_bus_station); |
0 | 1393 |
|
1394 |
if (flags & DC_EXEC) { |
|
10355
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1395 |
RoadStop *road_stop = new RoadStop(tile); |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1396 |
/* Insert into linked list of RoadStops */ |
6157 | 1397 |
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
|
1398 |
*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
|
1399 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1400 |
/*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
|
1401 |
st->AddFacility((type) ? FACIL_TRUCK_STOP : FACIL_BUS_STOP, tile); |
0 | 1402 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1403 |
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
|
1404 |
|
9837
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9826
diff
changeset
|
1405 |
RoadStopType rs_type = type ? ROADSTOP_TRUCK : ROADSTOP_BUS; |
6424 | 1406 |
if (is_drive_through) { |
9624 | 1407 |
MakeDriveThroughRoadStop(tile, st->owner, st->index, rs_type, rts, (Axis)p1, town_owned_road); |
6424 | 1408 |
} else { |
9624 | 1409 |
MakeRoadStop(tile, st->owner, st->index, rs_type, rts, (DiagDirection)p1); |
6424 | 1410 |
} |
0 | 1411 |
|
1412 |
UpdateStationVirtCoordDirty(st); |
|
1413 |
UpdateStationAcceptance(st, false); |
|
10645 | 1414 |
InvalidateWindowData(WC_STATION_LIST, st->owner, 0); |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1415 |
InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_ROADVEHS); |
0 | 1416 |
} |
1417 |
return cost; |
|
1418 |
} |
|
1419 |
||
9732 | 1420 |
|
1421 |
static void *ClearRoadStopStatusEnum(Vehicle *v, void *) |
|
1422 |
{ |
|
1423 |
if (v->type == VEH_ROAD) ClrBit(v->u.road.state, RVS_IN_DT_ROAD_STOP); |
|
1424 |
||
1425 |
return NULL; |
|
1426 |
} |
|
1427 |
||
1428 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1429 |
/** Remove a bus station |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1430 |
* @param st Station to remove |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1431 |
* @param flags operation to perform |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1432 |
* @param tile TileIndex been queried |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1433 |
* @return cost or failure of operation |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1434 |
*/ |
9629 | 1435 |
static CommandCost RemoveRoadStop(Station *st, uint32 flags, TileIndex tile) |
0 | 1436 |
{ |
2951 | 1437 |
if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) { |
0 | 1438 |
return CMD_ERROR; |
2951 | 1439 |
} |
0 | 1440 |
|
6395 | 1441 |
bool is_truck = IsTruckStop(tile); |
1442 |
||
1443 |
RoadStop **primary_stop; |
|
1444 |
RoadStop *cur_stop; |
|
2639 | 1445 |
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
|
1446 |
primary_stop = &st->truck_stops; |
9837
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9826
diff
changeset
|
1447 |
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
|
1448 |
} else { |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1449 |
primary_stop = &st->bus_stops; |
9837
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9826
diff
changeset
|
1450 |
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
|
1451 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1452 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1453 |
assert(cur_stop != NULL); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1454 |
|
9732 | 1455 |
/* don't do the check for drive-through road stops when company bankrupts */ |
1456 |
if (IsDriveThroughStopTile(tile) && (flags & DC_BANKRUPT)) { |
|
1457 |
/* remove the 'going through road stop' status from all vehicles on that tile */ |
|
1458 |
if (flags & DC_EXEC) VehicleFromPos(tile, NULL, &ClearRoadStopStatusEnum); |
|
1459 |
} else { |
|
1460 |
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; |
|
1461 |
} |
|
0 | 1462 |
|
1463 |
if (flags & DC_EXEC) { |
|
6118 | 1464 |
if (*primary_stop == cur_stop) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1465 |
/* removed the first stop in the list */ |
6118 | 1466 |
*primary_stop = cur_stop->next; |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1467 |
/* removed the only stop? */ |
6118 | 1468 |
if (*primary_stop == NULL) { |
1469 |
st->facilities &= (is_truck ? ~FACIL_TRUCK_STOP : ~FACIL_BUS_STOP); |
|
1470 |
} |
|
1471 |
} else { |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1472 |
/* tell the predecessor in the list to skip this stop */ |
6118 | 1473 |
RoadStop *pred = *primary_stop; |
1474 |
while (pred->next != cur_stop) pred = pred->next; |
|
1475 |
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
|
1476 |
} |
0 | 1477 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1478 |
InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_ROADVEHS); |
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
|
1479 |
delete cur_stop; |
4398
e889842a75a1
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
1480 |
DoClearSquare(tile); |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1481 |
st->rect.AfterRemoveTile(st, tile); |
4398
e889842a75a1
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
1482 |
|
0 | 1483 |
UpdateStationVirtCoordDirty(st); |
1484 |
DeleteStationIfEmpty(st); |
|
1485 |
} |
|
1486 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1487 |
return CommandCost(EXPENSES_CONSTRUCTION, (is_truck) ? _price.remove_truck_station : _price.remove_bus_station); |
0 | 1488 |
} |
1489 |
||
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1490 |
/** Remove a bus or truck stop |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1491 |
* @param tile tile to remove the stop from |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1492 |
* @param flags operation to perform |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1493 |
* @param p1 not used |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1494 |
* @param p2 bit 0: 0 for Bus stops, 1 for truck stops |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1495 |
*/ |
9629 | 1496 |
CommandCost CmdRemoveRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1497 |
{ |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1498 |
/* Make sure the specified tile is a road stop of the correct type */ |
10915
21ea526fd075
(svn r13467) [NoAI] -Fix [OpenTTD Core]: make CmdRemoveRoadStop use p2 as documented (only look at bit 0, not at the complete value)
truebrain
parents:
10776
diff
changeset
|
1499 |
if (!IsTileType(tile, MP_STATION) || !IsRoadStop(tile) || (uint32)GetRoadStopType(tile) != GB(p2, 0, 1)) return CMD_ERROR; |
6395 | 1500 |
Station *st = GetStationByTile(tile); |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1501 |
/* Save the stop info before it is removed */ |
6395 | 1502 |
bool is_drive_through = IsDriveThroughStopTile(tile); |
9624 | 1503 |
RoadTypes rts = GetRoadTypes(tile); |
1504 |
RoadBits road_bits = IsDriveThroughStopTile(tile) ? |
|
1505 |
((GetRoadStopDir(tile) == DIAGDIR_NE) ? ROAD_X : ROAD_Y) : |
|
1506 |
DiagDirToRoadBits(GetRoadStopDir(tile)); |
|
6395 | 1507 |
bool is_towns_road = is_drive_through && GetStopBuiltOnTownRoad(tile); |
1508 |
||
9629 | 1509 |
CommandCost ret = RemoveRoadStop(st, flags, tile); |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1510 |
|
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1511 |
/* If the stop was a drive-through stop replace the road */ |
9629 | 1512 |
if ((flags & DC_EXEC) && CmdSucceeded(ret) && is_drive_through) { |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1513 |
/* Rebuild the drive throuhg road stop. As a road stop can only be |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1514 |
* removed by the owner of the roadstop, _current_player is the |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1515 |
* owner of the road stop. */ |
10355
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1516 |
MakeRoadNormal(tile, road_bits, rts, is_towns_road ? ClosestTownFromTile(tile, UINT_MAX)->index : 0, |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1517 |
is_towns_road ? OWNER_TOWN : _current_player, _current_player, _current_player); |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1518 |
} |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1519 |
|
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1520 |
return ret; |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1521 |
} |
0 | 1522 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1523 |
/* FIXME -- need to move to its corresponding Airport variable*/ |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1524 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1525 |
/* Country Airfield (small) */ |
3429
12d01022976a
(svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents:
3422
diff
changeset
|
1526 |
static const byte _airport_sections_country[] = { |
0 | 1527 |
54, 53, 52, 65, |
1528 |
58, 57, 56, 55, |
|
1529 |
64, 63, 63, 62 |
|
1530 |
}; |
|
1531 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1532 |
/* City Airport (large) */ |
3429
12d01022976a
(svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents:
3422
diff
changeset
|
1533 |
static const byte _airport_sections_town[] = { |
2549 | 1534 |
31, 9, 33, 9, 9, 32, |
1535 |
27, 36, 29, 34, 8, 10, |
|
0 | 1536 |
30, 11, 35, 13, 20, 21, |
1537 |
51, 12, 14, 17, 19, 28, |
|
1538 |
38, 13, 15, 16, 18, 39, |
|
1539 |
26, 22, 23, 24, 25, 26 |
|
1540 |
}; |
|
1541 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1542 |
/* Metropolitain Airport (large) - 2 runways */ |
3429
12d01022976a
(svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents:
3422
diff
changeset
|
1543 |
static const byte _airport_sections_metropolitan[] = { |
2549 | 1544 |
31, 9, 33, 9, 9, 32, |
1545 |
27, 36, 29, 34, 8, 10, |
|
1546 |
30, 11, 35, 13, 20, 21, |
|
1547 |
102, 8, 8, 8, 8, 28, |
|
1548 |
83, 84, 84, 84, 84, 83, |
|
1549 |
26, 23, 23, 23, 23, 26 |
|
0 | 1550 |
}; |
1551 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1552 |
/* International Airport (large) - 2 runways */ |
3429
12d01022976a
(svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents:
3422
diff
changeset
|
1553 |
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
|
1554 |
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
|
1555 |
51, 8, 8, 8, 8, 8, 32, |
2549 | 1556 |
30, 8, 11, 27, 11, 8, 10, |
0 | 1557 |
32, 8, 11, 27, 11, 8, 114, |
1558 |
87, 8, 11, 85, 11, 8, 114, |
|
2549 | 1559 |
87, 8, 8, 8, 8, 8, 90, |
1560 |
26, 23, 23, 23, 23, 23, 26 |
|
0 | 1561 |
}; |
1562 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1563 |
/* Intercontinental Airport (vlarge) - 4 runways */ |
4059
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1564 |
static const byte _airport_sections_intercontinental[] = { |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
1565 |
102, 120, 89, 89, 89, 89, 89, 89, 118, |
6593
97097178e0fc
(svn r9076) -Fix [FS#529]: the intercontinental airport used 'T-junction' runway sprites when there is no exit in the middle of the runway as in the city airport (skidd13).
rubidium
parents:
6587
diff
changeset
|
1566 |
120, 23, 23, 23, 23, 23, 23, 119, 117, |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
1567 |
87, 54, 87, 8, 8, 8, 8, 51, 117, |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
1568 |
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
|
1569 |
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
|
1570 |
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
|
1571 |
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
|
1572 |
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
|
1573 |
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
|
1574 |
87, 120, 89, 89, 89, 89, 89, 89, 119, |
6593
97097178e0fc
(svn r9076) -Fix [FS#529]: the intercontinental airport used 'T-junction' runway sprites when there is no exit in the middle of the runway as in the city airport (skidd13).
rubidium
parents:
6587
diff
changeset
|
1575 |
121, 23, 23, 23, 23, 23, 23, 119, 37 |
4059
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1576 |
}; |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1577 |
|
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1578 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1579 |
/* Commuter Airfield (small) */ |
4059
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1580 |
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
|
1581 |
85, 30, 115, 115, 32, |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1582 |
87, 8, 8, 8, 10, |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1583 |
87, 11, 11, 11, 10, |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1584 |
26, 23, 23, 23, 26 |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1585 |
}; |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1586 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1587 |
/* Heliport */ |
3429
12d01022976a
(svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents:
3422
diff
changeset
|
1588 |
static const byte _airport_sections_heliport[] = { |
0 | 1589 |
66, |
1590 |
}; |
|
1591 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1592 |
/* Helidepot */ |
4059
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1593 |
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
|
1594 |
124, 32, |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1595 |
122, 123 |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1596 |
}; |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1597 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1598 |
/* Helistation */ |
4059
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1599 |
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
|
1600 |
32, 134, 159, 158, |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1601 |
161, 142, 142, 157 |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1602 |
}; |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1603 |
|
3471
c31dc50d54fb
(svn r4316) -Codechange: finished r4257 (forgot one variable there)
celestar
parents:
3435
diff
changeset
|
1604 |
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
|
1605 |
_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
|
1606 |
_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
|
1607 |
_airport_sections_heliport, // Heliport |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1608 |
_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
|
1609 |
_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
|
1610 |
_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
|
1611 |
_airport_sections_helidepot, // Helidepot |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1612 |
_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
|
1613 |
_airport_sections_helistation // Helistation |
0 | 1614 |
}; |
1615 |
||
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1616 |
/** Recalculate the noise generated by the airports of each town */ |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1617 |
void UpdateAirportsNoise() |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1618 |
{ |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1619 |
Town *t; |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1620 |
const Station *st; |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1621 |
|
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1622 |
FOR_ALL_TOWNS(t) t->noise_reached = 0; |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1623 |
|
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1624 |
FOR_ALL_STATIONS(st) { |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1625 |
if (IsAirport(st->xy)) { |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1626 |
st->town->noise_reached += GetAirportNoiseLevelForTown(GetAirport(st->airport_type), st->town->xy, st->xy); |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1627 |
} |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1628 |
} |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1629 |
} |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1630 |
|
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1631 |
/** Get a possible noise reduction factor based on distance from town center. |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1632 |
* The further you get, the less noise you generate. |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1633 |
* So all those folks at city council can now happily slee... work in their offices |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1634 |
* @param afc AirportFTAClass pointer of the class being proposed |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1635 |
* @param town_tile TileIndex of town's center, the one who will receive the airport's candidature |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1636 |
* @param tile TileIndex where the new airport might be built |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1637 |
* @return the noise that will be generated, according to distance |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1638 |
*/ |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1639 |
uint8 GetAirportNoiseLevelForTown(const AirportFTAClass *afc, TileIndex town_tile, TileIndex tile) |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1640 |
{ |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1641 |
struct TileIndexDistance { |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1642 |
TileIndex index; |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1643 |
uint distance; |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1644 |
}; |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1645 |
|
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1646 |
uint distance; |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1647 |
|
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1648 |
/* 0 cannot be accounted, and 1 is the lowest that can be reduced from town. |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1649 |
* So no need to go any further*/ |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1650 |
if (afc->noise_level < 2) return afc->noise_level; |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1651 |
|
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1652 |
/* Find the airport-to-be's closest corner to the town */ |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1653 |
if (afc->size_x == 1 && afc->size_y == 1) { |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1654 |
distance = DistanceManhattan(town_tile, tile); // ont tile, one corner, it's THE corner |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1655 |
} else { |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1656 |
/* calculate manhattan distance to town of each side of the airport */ |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1657 |
TileIndexDistance dist[4]; ///< Array that will contain all 4 corners in TileIndex and distance |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1658 |
uint min_tile = UINT_MAX; ///< Sentinel value |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1659 |
uint min_indice = 4; |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1660 |
|
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1661 |
/* Based on the size of the airport, establish location of each corner*/ |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1662 |
dist[0].index = tile; // north tile |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1663 |
dist[1].index = TileAddWrap(tile, afc->size_x - 1, afc->size_y - 1); // south tile |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1664 |
dist[2].index = TileAddWrap(tile, afc->size_x - 1, 0); // west tile |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1665 |
dist[3].index = TileAddWrap(tile, 0, afc->size_y - 1); //east tile |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1666 |
|
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1667 |
/* now, go and find the smallest one, thus the closest to town */ |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1668 |
for (uint i = 0; i < 4; i++) { |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1669 |
dist[i].distance = DistanceManhattan(town_tile, dist[i].index); |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1670 |
|
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1671 |
if (dist[i].distance < min_tile) { |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1672 |
min_tile = dist[i].distance; // here's a new candidate |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1673 |
min_indice = i; |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1674 |
} |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1675 |
} |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1676 |
|
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1677 |
distance = dist[min_indice].distance; |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1678 |
} |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1679 |
|
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1680 |
/* The steps for measuring noise reduction are based on the "magical" (and arbitrary) 8 base distance |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1681 |
* adding the town_council_tolerance 4 times, as a way to graduate, depending of the tolerance. |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1682 |
* Basically, it says that the less tolerant a town is, the bigger the distance before |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1683 |
* an actual decrease can be granted */ |
10776 | 1684 |
uint8 town_tolerance_distance = 8 + (_settings_game.difficulty.town_council_tolerance * 4); |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1685 |
|
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1686 |
/* now, we want to have the distance segmented using the distance judged bareable by town |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1687 |
* This will give us the coefficient of reduction the distance provides. */ |
10776 | 1688 |
uint noise_reduction = distance / town_tolerance_distance; |
1689 |
||
1690 |
/* If the noise reduction equals the airport noise itself, don't give it for free. |
|
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1691 |
* Otherwise, simply reduce the airport's level. */ |
10776 | 1692 |
return noise_reduction >= afc->noise_level ? 1 : afc->noise_level - noise_reduction; |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1693 |
} |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1694 |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1695 |
/** 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
|
1696 |
* @param tile tile where airport will be built |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1697 |
* @param flags operation to perform |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1698 |
* @param p1 airport type, @see airport.h |
9624 | 1699 |
* @param p2 (bit 0) - allow airports directly adjacent to other airports. |
0 | 1700 |
*/ |
9629 | 1701 |
CommandCost CmdBuildAirport(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1702 |
{ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1703 |
bool airport_upgrade = true; |
0 | 1704 |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1705 |
/* Check if a valid, buildable airport was chosen for construction */ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1706 |
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
|
1707 |
|
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
1708 |
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) { |
0 | 1709 |
return CMD_ERROR; |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
1710 |
} |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
1711 |
|
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
1712 |
Town *t = ClosestTownFromTile(tile, UINT_MAX); |
6395 | 1713 |
const AirportFTAClass *afc = GetAirport(p1); |
1714 |
int w = afc->size_x; |
|
1715 |
int h = afc->size_y; |
|
9624 | 1716 |
Station *st = NULL; |
1717 |
||
10776 | 1718 |
if (w > _settings_game.station.station_spread || h > _settings_game.station.station_spread) { |
5764
483bcb05ccf3
(svn r7810) -Fix: FS#504 Building airport whose size exceeds max station spread-out caused assert. (Zuu)
KUDr
parents:
5726
diff
changeset
|
1719 |
_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
|
1720 |
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
|
1721 |
} |
483bcb05ccf3
(svn r7810) -Fix: FS#504 Building airport whose size exceeds max station spread-out caused assert. (Zuu)
KUDr
parents:
5726
diff
changeset
|
1722 |
|
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
1723 |
CommandCost cost = CheckFlatLandBelow(tile, w, h, flags, 0, NULL); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
1724 |
if (CmdFailed(cost)) return cost; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
1725 |
|
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1726 |
/* Go get the final noise level, that is base noise minus factor from distance to town center */ |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1727 |
uint newnoise_level = GetAirportNoiseLevelForTown(afc, t->xy, tile); |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1728 |
|
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1729 |
/* Check if local auth would allow a new airport */ |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1730 |
bool authority_refused; |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1731 |
|
10776 | 1732 |
if (_settings_game.economy.station_noise_level) { |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1733 |
/* do not allow to build a new airport if this raise the town noise over the maximum allowed by town */ |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1734 |
authority_refused = (t->noise_reached + newnoise_level) > t->MaxTownNoise(); |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1735 |
} else { |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1736 |
uint num = 0; |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1737 |
const Station *st; |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1738 |
FOR_ALL_STATIONS(st) { |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1739 |
if (st->town == t && st->facilities & FACIL_AIRPORT && st->airport_type != AT_OILRIG) num++; |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1740 |
} |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1741 |
authority_refused = (num >= 2); |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
1742 |
} |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1743 |
|
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1744 |
if (authority_refused) { |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
1745 |
SetDParam(0, t->index); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
1746 |
return_cmd_error(STR_2035_LOCAL_AUTHORITY_REFUSES); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
1747 |
} |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
1748 |
|
10776 | 1749 |
if (!_settings_game.station.adjacent_stations || !HasBit(p2, 0)) { |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
1750 |
st = GetStationAround(tile, w, h, INVALID_STATION); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
1751 |
if (st == CHECK_STATIONS_ERR) return CMD_ERROR; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
1752 |
} else { |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
1753 |
st = NULL; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
1754 |
} |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
1755 |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
1756 |
/* Find a station close to us */ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
1757 |
if (st == NULL) st = GetClosestStationFromTile(tile); |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
1758 |
|
0 | 1759 |
if (st != NULL) { |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
1760 |
if (st->owner != _current_player) { |
0 | 1761 |
return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION); |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
1762 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1763 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1764 |
if (!st->rect.BeforeAddRect(tile, w, h, StationRect::ADD_TEST)) return CMD_ERROR; |
0 | 1765 |
|
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
1766 |
if (st->airport_tile != 0) { |
0 | 1767 |
return_cmd_error(STR_300D_TOO_CLOSE_TO_ANOTHER_AIRPORT); |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
1768 |
} |
0 | 1769 |
} else { |
1770 |
airport_upgrade = false; |
|
1771 |
||
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
|
1772 |
/* allocate and initialize new station */ |
10355
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1773 |
if (!Station::CanAllocateItem()) return_cmd_error(STR_3008_TOO_MANY_STATIONS_LOADING); |
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1774 |
|
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1775 |
if (flags & DC_EXEC) { |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
1776 |
st = new Station(tile); |
10355
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1777 |
|
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1778 |
st->town = t; |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
1779 |
st->string_id = GenerateStationName(st, tile, !(afc->flags & AirportFTAClass::AIRPLANES) ? STATIONNAMING_HELIPORT : STATIONNAMING_AIRPORT); |
10355
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1780 |
|
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1781 |
if (IsValidPlayer(_current_player)) { |
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1782 |
SetBit(st->town->have_ratings, _current_player); |
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1783 |
} |
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1784 |
st->sign.width_1 = 0; |
6375 | 1785 |
} |
0 | 1786 |
} |
1787 |
||
9629 | 1788 |
cost.AddCost(_price.build_airport * w * h); |
0 | 1789 |
|
1790 |
if (flags & DC_EXEC) { |
|
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1791 |
/* Always add the noise, so there will be no need to recalculate when option toggles */ |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1792 |
st->town->noise_reached += newnoise_level; |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1793 |
|
0 | 1794 |
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
|
1795 |
st->AddFacility(FACIL_AIRPORT, tile); |
0 | 1796 |
st->airport_type = (byte)p1; |
1797 |
st->airport_flags = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1798 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1799 |
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
|
1800 |
|
2639 | 1801 |
/* if airport was demolished while planes were en-route to it, the |
1802 |
* positions can no longer be the same (v->u.air.pos), since different |
|
1803 |
* airports have different indexes. So update all planes en-route to this |
|
1804 |
* airport. Only update if |
|
1805 |
* 1. airport is upgraded |
|
1806 |
* 2. airport is added to existing station (unfortunately unavoideable) |
|
1807 |
*/ |
|
2549 | 1808 |
if (airport_upgrade) UpdateAirplanesOnNewStation(st); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1809 |
|
0 | 1810 |
{ |
3471
c31dc50d54fb
(svn r4316) -Codechange: finished r4257 (forgot one variable there)
celestar
parents:
3435
diff
changeset
|
1811 |
const byte *b = _airport_sections[p1]; |
2549 | 1812 |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1813 |
BEGIN_TILE_LOOP(tile_cur, w, h, tile) { |
9686
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
1814 |
MakeAirport(tile_cur, st->owner, st->index, *b - ((*b < 67) ? 8 : 24)); |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
1815 |
b++; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1816 |
} END_TILE_LOOP(tile_cur, w, h, tile) |
0 | 1817 |
} |
1818 |
||
1819 |
UpdateStationVirtCoordDirty(st); |
|
1820 |
UpdateStationAcceptance(st, false); |
|
10645 | 1821 |
InvalidateWindowData(WC_STATION_LIST, st->owner, 0); |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1822 |
InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_PLANES); |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1823 |
|
10776 | 1824 |
if (_settings_game.economy.station_noise_level) { |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1825 |
InvalidateWindow(WC_TOWN_VIEW, st->town->index); |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1826 |
} |
0 | 1827 |
} |
1828 |
||
1829 |
return cost; |
|
1830 |
} |
|
1831 |
||
9629 | 1832 |
static CommandCost RemoveAirport(Station *st, uint32 flags) |
0 | 1833 |
{ |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
1834 |
if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) { |
0 | 1835 |
return CMD_ERROR; |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
1836 |
} |
0 | 1837 |
|
6395 | 1838 |
TileIndex tile = st->airport_tile; |
0 | 1839 |
|
6358 | 1840 |
const AirportFTAClass *afc = st->Airport(); |
6395 | 1841 |
int w = afc->size_x; |
1842 |
int h = afc->size_y; |
|
1843 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1844 |
CommandCost cost(EXPENSES_CONSTRUCTION, w * h * _price.remove_airport); |
0 | 1845 |
|
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
1846 |
const Vehicle *v; |
9574 | 1847 |
FOR_ALL_VEHICLES(v) { |
1848 |
if (!(v->type == VEH_AIRCRAFT && IsNormalAircraft(v))) continue; |
|
1849 |
||
1850 |
if (v->u.air.targetairport == st->index && v->u.air.state != FLYING) return CMD_ERROR; |
|
1851 |
} |
|
1852 |
||
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1853 |
BEGIN_TILE_LOOP(tile_cur, w, h, tile) { |
9704 | 1854 |
if (!EnsureNoVehicleOnGround(tile_cur)) return CMD_ERROR; |
0 | 1855 |
|
1856 |
if (flags & DC_EXEC) { |
|
1857 |
DeleteAnimatedTile(tile_cur); |
|
1858 |
DoClearSquare(tile_cur); |
|
1859 |
} |
|
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1860 |
} END_TILE_LOOP(tile_cur, w, h, tile) |
0 | 1861 |
|
1862 |
if (flags & DC_EXEC) { |
|
6395 | 1863 |
for (uint i = 0; i < afc->nof_depots; ++i) { |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1864 |
DeleteWindowById( |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1865 |
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
|
1866 |
); |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1867 |
} |
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
|
1868 |
|
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1869 |
/* Go get the final noise level, that is base noise minus factor from distance to town center. |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1870 |
* And as for construction, always remove it, even if the patch is not set, in order to avoid the |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1871 |
* need of recalculation */ |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1872 |
st->town->noise_reached -= GetAirportNoiseLevelForTown(afc, st->town->xy, tile); |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1873 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1874 |
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
|
1875 |
|
0 | 1876 |
st->airport_tile = 0; |
1877 |
st->facilities &= ~FACIL_AIRPORT; |
|
1878 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1879 |
InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_PLANES); |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1880 |
|
10776 | 1881 |
if (_settings_game.economy.station_noise_level) { |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1882 |
InvalidateWindow(WC_TOWN_VIEW, st->town->index); |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1883 |
} |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1884 |
|
0 | 1885 |
UpdateStationVirtCoordDirty(st); |
1886 |
DeleteStationIfEmpty(st); |
|
1887 |
} |
|
1888 |
||
1889 |
return cost; |
|
1890 |
} |
|
1891 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1892 |
/** 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
|
1893 |
* @param tile tile where to place the bouy |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1894 |
* @param flags operation to perform |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1895 |
* @param p1 unused |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1896 |
* @param p2 unused |
0 | 1897 |
*/ |
9629 | 1898 |
CommandCost CmdBuildBuoy(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1899 |
{ |
9718
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
1900 |
if (!IsWaterTile(tile) || tile == 0) return_cmd_error(STR_304B_SITE_UNSUITABLE); |
9403 | 1901 |
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); |
0 | 1902 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1903 |
if (GetTileSlope(tile, NULL) != SLOPE_FLAT) return_cmd_error(STR_304B_SITE_UNSUITABLE); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1904 |
|
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 */ |
10355
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1906 |
if (!Station::CanAllocateItem()) return_cmd_error(STR_3008_TOO_MANY_STATIONS_LOADING); |
0 | 1907 |
|
1908 |
if (flags & DC_EXEC) { |
|
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
1909 |
Station *st = new Station(tile); |
10355
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1910 |
|
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1911 |
st->town = ClosestTownFromTile(tile, UINT_MAX); |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
1912 |
st->string_id = GenerateStationName(st, tile, STATIONNAMING_BUOY); |
10355
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1913 |
|
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1914 |
if (IsValidPlayer(_current_player)) { |
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1915 |
SetBit(st->town->have_ratings, _current_player); |
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1916 |
} |
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
1917 |
st->sign.width_1 = 0; |
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
|
1918 |
st->dock_tile = tile; |
0 | 1919 |
st->facilities |= FACIL_DOCK; |
1751
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1706
diff
changeset
|
1920 |
/* 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
|
1921 |
* braindead.. */ |
0 | 1922 |
st->had_vehicle_of_type |= HVOT_BUOY; |
1923 |
st->owner = OWNER_NONE; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1924 |
|
71
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
65
diff
changeset
|
1925 |
st->build_date = _date; |
0 | 1926 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1927 |
MakeBuoy(tile, st->index, GetWaterClass(tile)); |
0 | 1928 |
|
1929 |
UpdateStationVirtCoordDirty(st); |
|
1930 |
UpdateStationAcceptance(st, false); |
|
10645 | 1931 |
InvalidateWindowData(WC_STATION_LIST, st->owner, 0); |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1932 |
InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_SHIPS); |
0 | 1933 |
} |
1934 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1935 |
return CommandCost(EXPENSES_CONSTRUCTION, _price.build_dock); |
0 | 1936 |
} |
1937 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1938 |
/** |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1939 |
* Tests whether the player's vehicles have this station in orders |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1940 |
* When player == INVALID_PLAYER, then check all vehicles |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1941 |
* @param station station ID |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1942 |
* @param player player ID, INVALID_PLAYER to disable the check |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1943 |
*/ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1944 |
bool HasStationInUse(StationID station, PlayerID player) |
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
|
1945 |
{ |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1946 |
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
|
1947 |
FOR_ALL_VEHICLES(v) { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1948 |
if (player == INVALID_PLAYER || v->owner == player) { |
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
|
1949 |
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
|
1950 |
FOR_VEHICLE_ORDERS(v, order) { |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
1951 |
if (order->IsType(OT_GOTO_STATION) && order->GetDestination() == station) { |
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
|
1952 |
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
|
1953 |
} |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1954 |
} |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1955 |
} |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1956 |
} |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1957 |
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
|
1958 |
} |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1959 |
|
9629 | 1960 |
static CommandCost RemoveBuoy(Station *st, uint32 flags) |
0 | 1961 |
{ |
4850
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4848
diff
changeset
|
1962 |
/* XXX: strange stuff */ |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
1963 |
if (!IsValidPlayer(_current_player)) return_cmd_error(INVALID_STRING_ID); |
0 | 1964 |
|
6395 | 1965 |
TileIndex tile = st->dock_tile; |
0 | 1966 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1967 |
if (HasStationInUse(st->index, INVALID_PLAYER)) return_cmd_error(STR_BUOY_IS_IN_USE); |
9732 | 1968 |
/* remove the buoy if there is a ship on tile when company goes bankrupt... */ |
1969 |
if (!(flags & DC_BANKRUPT) && !EnsureNoVehicleOnGround(tile)) return CMD_ERROR; |
|
0 | 1970 |
|
1971 |
if (flags & DC_EXEC) { |
|
1972 |
st->dock_tile = 0; |
|
1751
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1706
diff
changeset
|
1973 |
/* 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
|
1974 |
* braindead.. */ |
0 | 1975 |
st->facilities &= ~FACIL_DOCK; |
1976 |
st->had_vehicle_of_type &= ~HVOT_BUOY; |
|
1977 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1978 |
InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_SHIPS); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1979 |
|
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
|
1980 |
/* 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
|
1981 |
* 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
|
1982 |
* remove it and flood the land (if the canal edge is at level 0) */ |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1983 |
MakeWaterKeepingClass(tile, GetTileOwner(tile)); |
3111
1edf71aa942e
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3102
diff
changeset
|
1984 |
MarkTileDirtyByTile(tile); |
0 | 1985 |
|
1986 |
UpdateStationVirtCoordDirty(st); |
|
1987 |
DeleteStationIfEmpty(st); |
|
1988 |
} |
|
1989 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1990 |
return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_truck_station); |
0 | 1991 |
} |
1992 |
||
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1993 |
static const TileIndexDiffC _dock_tileoffs_chkaround[] = { |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1994 |
{-1, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1995 |
{ 0, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1996 |
{ 0, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1997 |
{ 0, -1} |
0 | 1998 |
}; |
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
|
1999 |
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
|
2000 |
static const byte _dock_h_chk[4] = { 1, 2, 1, 2 }; |
0 | 2001 |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
2002 |
/** 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
|
2003 |
* @param tile tile where dock will be built |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2004 |
* @param flags operation to perform |
9624 | 2005 |
* @param p1 (bit 0) - allow docks directly adjacent to other docks. |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
2006 |
* @param p2 unused |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
2007 |
*/ |
9629 | 2008 |
CommandCost CmdBuildDock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 2009 |
{ |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2010 |
DiagDirection direction = GetInclinedSlopeDirection(GetTileSlope(tile, NULL)); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2011 |
if (direction == INVALID_DIAGDIR) return_cmd_error(STR_304B_SITE_UNSUITABLE); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2012 |
direction = ReverseDiagDir(direction); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2013 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2014 |
/* Docks cannot be placed on rapids */ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2015 |
if (IsWaterTile(tile)) 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
|
2016 |
|
4619
fc11bc6a7fe7
(svn r6477) - Fix a loop-hole that allowed docks to be built regardless of town authority rating.
peter1138
parents:
4559
diff
changeset
|
2017 |
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
|
2018 |
|
9403 | 2019 |
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); |
2020 |
||
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
2021 |
if (CmdFailed(DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR))) return CMD_ERROR; |
0 | 2022 |
|
6395 | 2023 |
TileIndex tile_cur = tile + TileOffsByDiagDir(direction); |
0 | 2024 |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
2025 |
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
|
2026 |
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
|
2027 |
} |
0 | 2028 |
|
9403 | 2029 |
if (MayHaveBridgeAbove(tile_cur) && IsBridgeAbove(tile_cur)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); |
2030 |
||
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2031 |
/* Get the water class of the water tile before it is cleared.*/ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2032 |
WaterClass wc = GetWaterClass(tile_cur); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2033 |
|
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
2034 |
if (CmdFailed(DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR))) return CMD_ERROR; |
0 | 2035 |
|
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
2036 |
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
|
2037 |
if (!IsTileType(tile_cur, MP_WATER) || GetTileSlope(tile_cur, NULL) != SLOPE_FLAT) { |
0 | 2038 |
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
|
2039 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2040 |
|
0 | 2041 |
/* middle */ |
9624 | 2042 |
Station *st = NULL; |
2043 |
||
10776 | 2044 |
if (!_settings_game.station.adjacent_stations || !HasBit(p1, 0)) { |
9624 | 2045 |
st = GetStationAround( |
2046 |
tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]), |
|
2047 |
_dock_w_chk[direction], _dock_h_chk[direction], INVALID_STATION); |
|
2048 |
if (st == CHECK_STATIONS_ERR) return CMD_ERROR; |
|
2049 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2050 |
|
0 | 2051 |
/* Find a station close to us */ |
6378 | 2052 |
if (st == NULL) st = GetClosestStationFromTile(tile); |
0 | 2053 |
|
2054 |
if (st != NULL) { |
|
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
2055 |
if (st->owner != _current_player) { |
0 | 2056 |
return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION); |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
2057 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2058 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
2059 |
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
|
2060 |
|
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
2061 |
if (st->dock_tile != 0) return_cmd_error(STR_304C_TOO_CLOSE_TO_ANOTHER_DOCK); |
0 | 2062 |
} 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
|
2063 |
/* allocate and initialize new station */ |
10355
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
2064 |
/* allocate and initialize new station */ |
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
2065 |
if (!Station::CanAllocateItem()) return_cmd_error(STR_3008_TOO_MANY_STATIONS_LOADING); |
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
2066 |
|
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
2067 |
if (flags & DC_EXEC) { |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
2068 |
st = new Station(tile); |
10355
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
2069 |
|
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
2070 |
st->town = ClosestTownFromTile(tile, UINT_MAX); |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
2071 |
st->string_id = GenerateStationName(st, tile, STATIONNAMING_DOCK); |
10355
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
2072 |
|
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
2073 |
if (IsValidPlayer(_current_player)) { |
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
2074 |
SetBit(st->town->have_ratings, _current_player); |
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
2075 |
} |
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
|
2076 |
} |
0 | 2077 |
} |
2078 |
||
2079 |
if (flags & DC_EXEC) { |
|
2080 |
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
|
2081 |
st->AddFacility(FACIL_DOCK, tile); |
0 | 2082 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
2083 |
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
|
2084 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2085 |
MakeDock(tile, st->owner, st->index, direction, wc); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2086 |
|
0 | 2087 |
UpdateStationVirtCoordDirty(st); |
2088 |
UpdateStationAcceptance(st, false); |
|
10645 | 2089 |
InvalidateWindowData(WC_STATION_LIST, st->owner, 0); |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2090 |
InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_SHIPS); |
0 | 2091 |
} |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
2092 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2093 |
return CommandCost(EXPENSES_CONSTRUCTION, _price.build_dock); |
0 | 2094 |
} |
2095 |
||
9629 | 2096 |
static CommandCost RemoveDock(Station *st, uint32 flags) |
0 | 2097 |
{ |
2639 | 2098 |
if (!CheckOwnership(st->owner)) return CMD_ERROR; |
0 | 2099 |
|
6395 | 2100 |
TileIndex tile1 = st->dock_tile; |
2101 |
TileIndex tile2 = tile1 + TileOffsByDiagDir(GetDockDirection(tile1)); |
|
0 | 2102 |
|
9718
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
2103 |
if (!EnsureNoVehicleOnGround(tile1)) return CMD_ERROR; |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
2104 |
if (!EnsureNoVehicleOnGround(tile2)) return CMD_ERROR; |
0 | 2105 |
|
2106 |
if (flags & DC_EXEC) { |
|
2107 |
DoClearSquare(tile1); |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2108 |
MakeWaterKeepingClass(tile2, st->owner); |
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
|
2109 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
2110 |
st->rect.AfterRemoveTile(st, tile1); |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
2111 |
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
|
2112 |
|
3111
1edf71aa942e
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3102
diff
changeset
|
2113 |
MarkTileDirtyByTile(tile2); |
0 | 2114 |
|
2115 |
st->dock_tile = 0; |
|
2116 |
st->facilities &= ~FACIL_DOCK; |
|
2117 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2118 |
InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_SHIPS); |
0 | 2119 |
UpdateStationVirtCoordDirty(st); |
2120 |
DeleteStationIfEmpty(st); |
|
2121 |
} |
|
2122 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2123 |
return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_dock); |
0 | 2124 |
} |
2125 |
||
2126 |
#include "table/station_land.h" |
|
2127 |
||
9686
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2128 |
const DrawTileSprites *GetStationTileLayout(StationType st, byte gfx) |
3763
460bbb4a8154
(svn r4754) - Newstations: expose default station display data via a function so we can use it (rarely) in other places.
peter1138
parents:
3754
diff
changeset
|
2129 |
{ |
9686
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2130 |
return &_station_display_datas[st][gfx]; |
3763
460bbb4a8154
(svn r4754) - Newstations: expose default station display data via a function so we can use it (rarely) in other places.
peter1138
parents:
3754
diff
changeset
|
2131 |
} |
0 | 2132 |
|
2133 |
static void DrawTile_Station(TileInfo *ti) |
|
2134 |
{ |
|
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2135 |
const DrawTileSprites *t = NULL; |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
2136 |
RoadTypes roadtypes; |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2137 |
int32 total_offset; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2138 |
int32 custom_ground_offset; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2139 |
|
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
2140 |
if (IsRailwayStation(ti->tile)) { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2141 |
const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile)); |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
2142 |
roadtypes = ROADTYPES_NONE; |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2143 |
total_offset = rti->total_offset; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2144 |
custom_ground_offset = rti->custom_ground_offset; |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
2145 |
} else { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2146 |
roadtypes = IsRoadStop(ti->tile) ? GetRoadTypes(ti->tile) : ROADTYPES_NONE; |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2147 |
total_offset = 0; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2148 |
custom_ground_offset = 0; |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
2149 |
} |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2150 |
uint32 relocation = 0; |
3775
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2151 |
const Station *st = NULL; |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2152 |
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
|
2153 |
PlayerID owner = GetTileOwner(ti->tile); |
6395 | 2154 |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
2155 |
SpriteID palette; |
4850
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4848
diff
changeset
|
2156 |
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
|
2157 |
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
|
2158 |
} else { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2159 |
/* Some stations are not owner by a player, namely oil rigs */ |
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
|
2160 |
palette = PALETTE_TO_GREY; |
0 | 2161 |
} |
2162 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2163 |
/* 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
|
2164 |
if (ti->tileh != SLOPE_FLAT && !IsDock(ti->tile)) |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
2165 |
DrawFoundation(ti, FOUNDATION_LEVELED); |
0 | 2166 |
|
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
|
2167 |
if (IsCustomStationSpecIndex(ti->tile)) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2168 |
/* look for customization */ |
3775
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2169 |
st = GetStationByTile(ti->tile); |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2170 |
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
|
2171 |
|
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2172 |
if (statspec != NULL) { |
3576
007e6b163bf5
(svn r4462) - Newstations: ensure the chosen tile layout is available from a custom station
peter1138
parents:
3574
diff
changeset
|
2173 |
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
|
2174 |
|
3751
785501c18d0d
(svn r4739) - Newstations: remove cargo type parameter of GetCustomStationRelocation() as we can determine it internally
peter1138
parents:
3742
diff
changeset
|
2175 |
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
|
2176 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2177 |
if (HasBit(statspec->callbackmask, CBM_STATION_SPRITE_LAYOUT)) { |
3754
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
2178 |
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
|
2179 |
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
|
2180 |
} |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
2181 |
|
3576
007e6b163bf5
(svn r4462) - Newstations: ensure the chosen tile layout is available from a custom station
peter1138
parents:
3574
diff
changeset
|
2182 |
/* 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
|
2183 |
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
|
2184 |
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
|
2185 |
} |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2186 |
} |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2187 |
} |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2188 |
|
9686
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2189 |
if (t == NULL || t->seq == NULL) t = &_station_display_datas[GetStationType(ti->tile)][GetStationGfx(ti->tile)]; |
384
bf1303e754ff
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
2190 |
|
9732 | 2191 |
|
2192 |
if (IsBuoy(ti->tile) || IsDock(ti->tile)) { |
|
2193 |
if (ti->tileh == SLOPE_FLAT) { |
|
2194 |
DrawWaterClassGround(ti); |
|
2195 |
} else { |
|
2196 |
assert(IsDock(ti->tile)); |
|
2197 |
TileIndex water_tile = ti->tile + TileOffsByDiagDir(GetDockDirection(ti->tile)); |
|
2198 |
WaterClass wc = GetWaterClass(water_tile); |
|
2199 |
if (wc == WATER_CLASS_SEA) { |
|
2200 |
DrawShoreTile(ti->tileh); |
|
2201 |
} else { |
|
2202 |
DrawClearLandTile(ti, 3); |
|
2203 |
} |
|
2204 |
} |
|
3775
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2205 |
} else { |
9732 | 2206 |
SpriteID image = t->ground.sprite; |
2207 |
if (HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) { |
|
2208 |
image += GetCustomStationGroundRelocation(statspec, st, ti->tile); |
|
2209 |
image += custom_ground_offset; |
|
2210 |
} else { |
|
2211 |
image += total_offset; |
|
2212 |
} |
|
2213 |
DrawGroundSprite(image, HasBit(image, PALETTE_MODIFIER_COLOR) ? palette : PAL_NONE); |
|
3775
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2214 |
} |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2215 |
|
10513
33cb70ff2f5d
(svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents:
10455
diff
changeset
|
2216 |
if (IsRailwayStation(ti->tile) && HasCatenaryDrawn(GetRailType(ti->tile)) && 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
|
2217 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2218 |
if (HasBit(roadtypes, ROADTYPE_TRAM)) { |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
2219 |
Axis axis = GetRoadStopDir(ti->tile) == DIAGDIR_NE ? AXIS_X : AXIS_Y; |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2220 |
DrawGroundSprite((HasBit(roadtypes, ROADTYPE_ROAD) ? SPR_TRAMWAY_OVERLAY : SPR_TRAMWAY_TRAM) + (axis ^ 1), PAL_NONE); |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
2221 |
DrawTramCatenary(ti, axis == AXIS_X ? ROAD_X : ROAD_Y); |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
2222 |
} |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
2223 |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2224 |
/* End now if buildings are invisible */ |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2225 |
if (IsInvisibilitySet(TO_BUILDINGS)) return; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2226 |
|
6395 | 2227 |
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
|
2228 |
foreach_draw_tile_seq(dtss, t->seq) { |
9732 | 2229 |
SpriteID image = dtss->image.sprite; |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2230 |
if (relocation == 0 || HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2231 |
image += total_offset; |
3775
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2232 |
} else { |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2233 |
image += relocation; |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2234 |
} |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2235 |
|
6395 | 2236 |
SpriteID pal; |
10181
54df587fef5d
(svn r12712) [NoAI] -Sync with trunk r12672:12711.
rubidium
parents:
10142
diff
changeset
|
2237 |
if (HasBit(image, PALETTE_MODIFIER_TRANSPARENT) || HasBit(image, PALETTE_MODIFIER_COLOR)) { |
54df587fef5d
(svn r12712) [NoAI] -Sync with trunk r12672:12711.
rubidium
parents:
10142
diff
changeset
|
2238 |
if (dtss->image.pal > 0) { |
54df587fef5d
(svn r12712) [NoAI] -Sync with trunk r12672:12711.
rubidium
parents:
10142
diff
changeset
|
2239 |
pal = dtss->image.pal; |
54df587fef5d
(svn r12712) [NoAI] -Sync with trunk r12672:12711.
rubidium
parents:
10142
diff
changeset
|
2240 |
} else { |
54df587fef5d
(svn r12712) [NoAI] -Sync with trunk r12672:12711.
rubidium
parents:
10142
diff
changeset
|
2241 |
pal = palette; |
54df587fef5d
(svn r12712) [NoAI] -Sync with trunk r12672:12711.
rubidium
parents:
10142
diff
changeset
|
2242 |
} |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
2243 |
} else { |
10181
54df587fef5d
(svn r12712) [NoAI] -Sync with trunk r12672:12711.
rubidium
parents:
10142
diff
changeset
|
2244 |
pal = PAL_NONE; |
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
|
2245 |
} |
bf1303e754ff
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
2246 |
|
0 | 2247 |
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
|
2248 |
AddSortableSpriteToDraw( |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
2249 |
image, pal, |
4230
cd86b1c47f33
(svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents:
4227
diff
changeset
|
2250 |
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
|
2251 |
dtss->size_x, dtss->size_y, |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
2252 |
dtss->size_z, ti->z + dtss->delta_z, |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2253 |
!HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(TO_BUILDINGS) |
4230
cd86b1c47f33
(svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents:
4227
diff
changeset
|
2254 |
); |
0 | 2255 |
} else { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2256 |
AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y, IsTransparencySet(TO_BUILDINGS)); |
0 | 2257 |
} |
2258 |
} |
|
2259 |
} |
|
2260 |
||
9686
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2261 |
void StationPickerDrawSprite(int x, int y, StationType st, RailType railtype, RoadType roadtype, int image) |
0 | 2262 |
{ |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2263 |
int32 total_offset = 0; |
6395 | 2264 |
SpriteID pal = PLAYER_SPRITE_COLOR(_local_player); |
9686
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2265 |
const DrawTileSprites *t = &_station_display_datas[st][image]; |
6395 | 2266 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2267 |
if (railtype != INVALID_RAILTYPE) { |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2268 |
const RailtypeInfo *rti = GetRailTypeInfo(railtype); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2269 |
total_offset = rti->total_offset; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2270 |
} |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2271 |
|
9732 | 2272 |
SpriteID img = t->ground.sprite; |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2273 |
DrawSprite(img + total_offset, HasBit(img, PALETTE_MODIFIER_COLOR) ? pal : PAL_NONE, x, y); |
0 | 2274 |
|
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
2275 |
if (roadtype == ROADTYPE_TRAM) { |
9732 | 2276 |
DrawSprite(SPR_TRAMWAY_TRAM + (t->ground.sprite == SPR_ROAD_PAVED_STRAIGHT_X ? 1 : 0), PAL_NONE, x, y); |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
2277 |
} |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
2278 |
|
6395 | 2279 |
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
|
2280 |
foreach_draw_tile_seq(dtss, t->seq) { |
0 | 2281 |
Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z); |
9732 | 2282 |
DrawSprite(dtss->image.sprite + total_offset, pal, x + pt.x, y + pt.y); |
0 | 2283 |
} |
2284 |
} |
|
2285 |
||
4231
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4230
diff
changeset
|
2286 |
static uint GetSlopeZ_Station(TileIndex tile, uint x, uint y) |
0 | 2287 |
{ |
4231
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4230
diff
changeset
|
2288 |
return GetTileMaxZ(tile); |
0 | 2289 |
} |
2290 |
||
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
2291 |
static Foundation GetFoundation_Station(TileIndex tile, Slope tileh) |
39 | 2292 |
{ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
2293 |
return FlatteningFoundation(tileh); |
39 | 2294 |
} |
2295 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2296 |
static void GetAcceptedCargo_Station(TileIndex tile, AcceptedCargo ac) |
0 | 2297 |
{ |
2298 |
/* not used */ |
|
2299 |
} |
|
2300 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2301 |
static void GetTileDesc_Station(TileIndex tile, TileDesc *td) |
0 | 2302 |
{ |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
2303 |
td->owner[0] = GetTileOwner(tile); |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
2304 |
if (IsDriveThroughStopTile(tile) && HasTileRoadType(tile, ROADTYPE_ROAD) && GetStopBuiltOnTownRoad(tile)) { |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
2305 |
/* Display a second owner */ |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
2306 |
td->owner_type[1] = STR_ROAD_OWNER; |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
2307 |
td->owner[1] = OWNER_TOWN; |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
2308 |
} |
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
2309 |
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
|
2310 |
|
6395 | 2311 |
StringID str; |
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2312 |
switch (GetStationType(tile)) { |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2313 |
default: NOT_REACHED(); |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2314 |
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
|
2315 |
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
|
2316 |
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
|
2317 |
break; |
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2318 |
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
|
2319 |
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
|
2320 |
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
|
2321 |
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
|
2322 |
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
|
2323 |
} |
0 | 2324 |
td->str = str; |
2325 |
} |
|
2326 |
||
2327 |
||
9732 | 2328 |
static TrackStatus GetTileTrackStatus_Station(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side) |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2329 |
{ |
9732 | 2330 |
TrackBits trackbits = TRACK_BIT_NONE; |
2331 |
||
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
|
2332 |
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
|
2333 |
case TRANSPORT_RAIL: |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
2334 |
if (IsRailwayStation(tile) && !IsStationTileBlocked(tile)) { |
9732 | 2335 |
trackbits = TrackToTrackBits(GetRailStationTrack(tile)); |
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
|
2336 |
} |
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
|
2337 |
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
|
2338 |
|
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
|
2339 |
case TRANSPORT_WATER: |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2340 |
/* 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
|
2341 |
if (IsBuoy(tile)) { |
9732 | 2342 |
trackbits = TRACK_BIT_ALL; |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2343 |
/* remove tracks that connect NE map edge */ |
9732 | 2344 |
if (TileX(tile) == 0) trackbits &= ~(TRACK_BIT_X | TRACK_BIT_UPPER | TRACK_BIT_RIGHT); |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2345 |
/* remove tracks that connect NW map edge */ |
9732 | 2346 |
if (TileY(tile) == 0) trackbits &= ~(TRACK_BIT_Y | TRACK_BIT_LEFT | TRACK_BIT_UPPER); |
6165
4da5ead702ad
(svn r8540) -Fix[YAPF]: Assert when buoy is placed on NE or NW map edge (Dan)
KUDr
parents:
6164
diff
changeset
|
2347 |
} |
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
|
2348 |
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
|
2349 |
|
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
2350 |
case TRANSPORT_ROAD: |
9732 | 2351 |
if ((GetRoadTypes(tile) & sub_mode) != 0 && IsRoadStop(tile)) { |
2352 |
DiagDirection dir = GetRoadStopDir(tile); |
|
2353 |
Axis axis = DiagDirToAxis(dir); |
|
2354 |
||
2355 |
if (side != INVALID_DIAGDIR) { |
|
2356 |
if (axis != DiagDirToAxis(side) || (IsStandardRoadStopTile(tile) && dir != side)) break; |
|
2357 |
} |
|
2358 |
||
2359 |
trackbits = AxisToTrackBits(axis); |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
2360 |
} |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
2361 |
break; |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
2362 |
|
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
|
2363 |
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
|
2364 |
break; |
0 | 2365 |
} |
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
|
2366 |
|
9732 | 2367 |
return CombineTrackStatus(TrackBitsToTrackdirBits(trackbits), TRACKDIR_BIT_NONE); |
0 | 2368 |
} |
2369 |
||
2660 | 2370 |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2371 |
static void TileLoop_Station(TileIndex tile) |
0 | 2372 |
{ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2373 |
/* FIXME -- GetTileTrackStatus_Station -> animated stationtiles |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2374 |
* hardcoded.....not good */ |
9686
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2375 |
switch (GetStationType(tile)) { |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2376 |
case STATION_AIRPORT: |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2377 |
switch (GetStationGfx(tile)) { |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2378 |
case GFX_RADAR_LARGE_FIRST: |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2379 |
case GFX_WINDSACK_FIRST : // for small airport |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2380 |
case GFX_RADAR_INTERNATIONAL_FIRST: |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2381 |
case GFX_RADAR_METROPOLITAN_FIRST: |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2382 |
case GFX_RADAR_DISTRICTWE_FIRST: // radar district W-E airport |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2383 |
case GFX_WINDSACK_INTERCON_FIRST : // for intercontinental airport |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2384 |
AddAnimatedTile(tile); |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2385 |
break; |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2386 |
} |
2660 | 2387 |
break; |
2388 |
||
9732 | 2389 |
case STATION_DOCK: |
2390 |
if (GetTileSlope(tile, NULL) != SLOPE_FLAT) break; // only handle water part |
|
2391 |
/* FALL THROUGH */ |
|
9686
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2392 |
case STATION_OILRIG: //(station part) |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2393 |
case STATION_BUOY: |
2660 | 2394 |
TileLoop_Water(tile); |
2395 |
break; |
|
2396 |
||
2397 |
default: break; |
|
2398 |
} |
|
0 | 2399 |
} |
2400 |
||
2401 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2402 |
static void AnimateTile_Station(TileIndex tile) |
0 | 2403 |
{ |
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
2404 |
struct AnimData { |
4467
dede0d254ffb
(svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents:
4434
diff
changeset
|
2405 |
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
|
2406 |
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
|
2407 |
byte delay; |
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
2408 |
}; |
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
|
2409 |
|
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
|
2410 |
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
|
2411 |
{ 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
|
2412 |
{ 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
|
2413 |
{ 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
|
2414 |
{ 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
|
2415 |
{ 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
|
2416 |
{ 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
|
2417 |
}; |
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
|
2418 |
|
10294 | 2419 |
if (IsRailwayStation(tile)) { |
2420 |
AnimateStationTile(tile); |
|
2421 |
return; |
|
2422 |
} |
|
2423 |
||
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
|
2424 |
StationGfx gfx = GetStationGfx(tile); |
6395 | 2425 |
|
2426 |
for (const AnimData *i = data; i != endof(data); i++) { |
|
4467
dede0d254ffb
(svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents:
4434
diff
changeset
|
2427 |
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
|
2428 |
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
|
2429 |
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
|
2430 |
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
|
2431 |
} |
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
|
2432 |
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
|
2433 |
} |
0 | 2434 |
} |
2435 |
} |
|
2436 |
||
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
2437 |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2438 |
static void ClickTile_Station(TileIndex tile) |
0 | 2439 |
{ |
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2440 |
if (IsHangar(tile)) { |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2441 |
ShowDepotWindow(tile, VEH_AIRCRAFT); |
0 | 2442 |
} 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
|
2443 |
ShowStationViewWindow(GetStationIndex(tile)); |
0 | 2444 |
} |
2445 |
} |
|
2446 |
||
2447 |
static const byte _enter_station_speedtable[12] = { |
|
2448 |
215, 195, 175, 155, 135, 115, 95, 75, 55, 35, 15, 0 |
|
2449 |
}; |
|
2450 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2451 |
static VehicleEnterTileStatus VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y) |
0 | 2452 |
{ |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2453 |
StationID station_id = GetStationIndex(tile); |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2454 |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2455 |
if (v->type == VEH_TRAIN) { |
10181
54df587fef5d
(svn r12712) [NoAI] -Sync with trunk r12672:12711.
rubidium
parents:
10142
diff
changeset
|
2456 |
if (!v->current_order.ShouldStopAtStation(v, station_id)) return VETSB_CONTINUE; |
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2457 |
if (IsRailwayStation(tile) && IsFrontEngine(v) && |
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
2458 |
!IsCompatibleTrainStationTile(tile + TileOffsByDiagDir(DirToDiagDir(v->direction)), tile)) { |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2459 |
DiagDirection dir = DirToDiagDir(v->direction); |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2460 |
|
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2461 |
x &= 0xF; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2462 |
y &= 0xF; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2463 |
|
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2464 |
if (DiagDirToAxis(dir) != AXIS_X) Swap(x, y); |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2465 |
if (y == TILE_SIZE / 2) { |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2466 |
if (dir != DIAGDIR_SE && dir != DIAGDIR_SW) x = TILE_SIZE - 1 - x; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2467 |
if (x == 12) return VETSB_ENTERED_STATION | (VehicleEnterTileStatus)(station_id << VETS_STATION_ID_OFFSET); /* enter station */ |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2468 |
if (x < 12) { |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2469 |
uint16 spd; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2470 |
|
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2471 |
v->vehstatus |= VS_TRAIN_SLOWING; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2472 |
spd = _enter_station_speedtable[x]; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2473 |
if (spd < v->cur_speed) v->cur_speed = spd; |
0 | 2474 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2475 |
} |
0 | 2476 |
} |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2477 |
} else if (v->type == VEH_ROAD) { |
6402
d8d29aef051f
(svn r8809) -Fix (r8715): accidentally removed a part of an expression.
rubidium
parents:
6396
diff
changeset
|
2478 |
if (v->u.road.state < RVSB_IN_ROAD_STOP && !IsReversingRoadTrackdir((Trackdir)v->u.road.state) && v->u.road.frame == 0) { |
9627 | 2479 |
if (IsRoadStop(tile) && IsRoadVehFront(v)) { |
2671
457c6cdbf9e7
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2660
diff
changeset
|
2480 |
/* 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
|
2481 |
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
|
2482 |
|
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2483 |
if (IsDriveThroughStopTile(tile)) { |
10181
54df587fef5d
(svn r12712) [NoAI] -Sync with trunk r12672:12711.
rubidium
parents:
10142
diff
changeset
|
2484 |
if (!v->current_order.ShouldStopAtStation(v, station_id)) return VETSB_CONTINUE; |
54df587fef5d
(svn r12712) [NoAI] -Sync with trunk r12672:12711.
rubidium
parents:
10142
diff
changeset
|
2485 |
|
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2486 |
/* Vehicles entering a drive-through stop from the 'normal' side use first bay (bay 0). */ |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2487 |
byte side = ((DirToDiagDir(v->direction) == ReverseDiagDir(GetRoadStopDir(tile))) == (v->u.road.overtaking == 0)) ? 0 : 1; |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2488 |
|
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2489 |
if (!rs->IsFreeBay(side)) return VETSB_CANNOT_ENTER; |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2490 |
|
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2491 |
/* Check if the vehicle is stopping at this road stop */ |
9837
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9826
diff
changeset
|
2492 |
if (GetRoadStopType(tile) == (IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? ROADSTOP_BUS : ROADSTOP_TRUCK) && |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
2493 |
v->current_order.GetDestination() == GetStationIndex(tile)) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2494 |
SetBit(v->u.road.state, RVS_IS_STOPPING); |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2495 |
rs->AllocateDriveThroughBay(side); |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2496 |
} |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2497 |
|
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2498 |
/* Indicate if vehicle is using second bay. */ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2499 |
if (side == 1) SetBit(v->u.road.state, RVS_USING_SECOND_BAY); |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2500 |
/* Indicate a drive-through stop */ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2501 |
SetBit(v->u.road.state, RVS_IN_DT_ROAD_STOP); |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2502 |
return VETSB_CONTINUE; |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2503 |
} |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2504 |
|
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2505 |
/* For normal (non drive-through) road stops */ |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2506 |
/* Check if station is busy or if there are no free bays or whether it is a articulated vehicle. */ |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2507 |
if (rs->IsEntranceBusy() || !rs->HasFreeBay() || RoadVehHasArticPart(v)) return VETSB_CANNOT_ENTER; |
0 | 2508 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2509 |
SetBit(v->u.road.state, RVS_IN_ROAD_STOP); |
2671
457c6cdbf9e7
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2660
diff
changeset
|
2510 |
|
6316
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6214
diff
changeset
|
2511 |
/* 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
|
2512 |
uint bay_nr = rs->AllocateBay(); |
6326
c904c7ea1c8d
(svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents:
6324
diff
changeset
|
2513 |
SB(v->u.road.state, RVS_USING_SECOND_BAY, 1, bay_nr); |
6316
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6214
diff
changeset
|
2514 |
|
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6214
diff
changeset
|
2515 |
/* Mark the station entrace as busy */ |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6214
diff
changeset
|
2516 |
rs->SetEntranceBusy(true); |
0 | 2517 |
} |
2518 |
} |
|
2519 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2520 |
|
6317
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6316
diff
changeset
|
2521 |
return VETSB_CONTINUE; |
0 | 2522 |
} |
2523 |
||
2524 |
/* this function is called for one station each tick */ |
|
2525 |
static void StationHandleBigTick(Station *st) |
|
2526 |
{ |
|
2527 |
UpdateStationAcceptance(st, true); |
|
2528 |
||
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
|
2529 |
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
|
2530 |
|
0 | 2531 |
} |
2532 |
||
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
2533 |
static inline void byte_inc_sat(byte *p) |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
2534 |
{ |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
2535 |
byte b = *p + 1; |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
2536 |
if (b != 0) *p = b; |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
2537 |
} |
0 | 2538 |
|
2539 |
static void UpdateStationRating(Station *st) |
|
2540 |
{ |
|
2541 |
bool waiting_changed = false; |
|
2542 |
||
2543 |
byte_inc_sat(&st->time_since_load); |
|
2544 |
byte_inc_sat(&st->time_since_unload); |
|
2545 |
||
6395 | 2546 |
GoodsEntry *ge = st->goods; |
0 | 2547 |
do { |
6587
bc0bd6259485
(svn r9070) -Fix [FS#404]: if bribe failed and you didn't pick up cargo yet, you wouldn't ever be able to do so for a given station
truelight
parents:
6585
diff
changeset
|
2548 |
/* Slowly increase the rating back to his original level in the case we |
bc0bd6259485
(svn r9070) -Fix [FS#404]: if bribe failed and you didn't pick up cargo yet, you wouldn't ever be able to do so for a given station
truelight
parents:
6585
diff
changeset
|
2549 |
* didn't deliver cargo yet to this station. This happens when a bribe |
bc0bd6259485
(svn r9070) -Fix [FS#404]: if bribe failed and you didn't pick up cargo yet, you wouldn't ever be able to do so for a given station
truelight
parents:
6585
diff
changeset
|
2550 |
* failed while you didn't moved that cargo yet to a station. */ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2551 |
if (!HasBit(ge->acceptance_pickup, GoodsEntry::PICKUP) && ge->rating < INITIAL_STATION_RATING) { |
6587
bc0bd6259485
(svn r9070) -Fix [FS#404]: if bribe failed and you didn't pick up cargo yet, you wouldn't ever be able to do so for a given station
truelight
parents:
6585
diff
changeset
|
2552 |
ge->rating++; |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2553 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2554 |
|
6587
bc0bd6259485
(svn r9070) -Fix [FS#404]: if bribe failed and you didn't pick up cargo yet, you wouldn't ever be able to do so for a given station
truelight
parents:
6585
diff
changeset
|
2555 |
/* Only change the rating if we are moving this cargo */ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2556 |
if (HasBit(ge->acceptance_pickup, GoodsEntry::PICKUP)) { |
0 | 2557 |
byte_inc_sat(&ge->days_since_pickup); |
2558 |
||
6395 | 2559 |
int rating = 0; |
0 | 2560 |
|
2561 |
{ |
|
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
2562 |
int b = ge->last_speed - 85; |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
2563 |
if (b >= 0) |
0 | 2564 |
rating += b >> 2; |
2565 |
} |
|
2566 |
||
2567 |
{ |
|
2568 |
byte age = ge->last_age; |
|
2569 |
(age >= 3) || |
|
2570 |
(rating += 10, age >= 2) || |
|
2571 |
(rating += 10, age >= 1) || |
|
2572 |
(rating += 13, true); |
|
2573 |
} |
|
2574 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2575 |
if (IsValidPlayer(st->owner) && HasBit(st->town->statues, st->owner)) rating += 26; |
0 | 2576 |
|
2577 |
{ |
|
2578 |
byte days = ge->days_since_pickup; |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2579 |
if (st->last_vehicle_type == VEH_SHIP) days >>= 2; |
0 | 2580 |
(days > 21) || |
2581 |
(rating += 25, days > 12) || |
|
2582 |
(rating += 25, days > 6) || |
|
2583 |
(rating += 45, days > 3) || |
|
2584 |
(rating += 35, true); |
|
2585 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2586 |
|
9629 | 2587 |
uint waiting = ge->cargo.Count(); |
6395 | 2588 |
(rating -= 90, waiting > 1500) || |
2589 |
(rating += 55, waiting > 1000) || |
|
2590 |
(rating += 35, waiting > 600) || |
|
2591 |
(rating += 10, waiting > 300) || |
|
2592 |
(rating += 20, waiting > 100) || |
|
2593 |
(rating += 10, true); |
|
0 | 2594 |
|
2595 |
{ |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
2596 |
int or_ = ge->rating; // old rating |
0 | 2597 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2598 |
/* only modify rating in steps of -2, -1, 0, 1 or 2 */ |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2599 |
ge->rating = rating = or_ + Clamp(Clamp(rating, 0, 255) - or_, -2, 2); |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2600 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2601 |
/* if rating is <= 64 and more than 200 items waiting, |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2602 |
* remove some random amount of goods from the station */ |
0 | 2603 |
if (rating <= 64 && waiting >= 200) { |
2604 |
int dec = Random() & 0x1F; |
|
2605 |
if (waiting < 400) dec &= 7; |
|
2606 |
waiting -= dec + 1; |
|
2607 |
waiting_changed = true; |
|
2608 |
} |
|
2609 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2610 |
/* if rating is <= 127 and there are any items waiting, maybe remove some goods. */ |
0 | 2611 |
if (rating <= 127 && waiting != 0) { |
2612 |
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
|
2613 |
if (rating <= (int)GB(r, 0, 7)) { |
9629 | 2614 |
/* Need to have int, otherwise it will just overflow etc. */ |
2615 |
waiting = max((int)waiting - (int)GB(r, 8, 2) - 1, 0); |
|
0 | 2616 |
waiting_changed = true; |
2617 |
} |
|
2618 |
} |
|
2619 |
||
9686
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2620 |
/* At some point we really must cap the cargo. Previously this |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2621 |
* was a strict 4095, but now we'll have a less strict, but |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2622 |
* increasingly agressive truncation of the amount of cargo. */ |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2623 |
static const uint WAITING_CARGO_THRESHOLD = 1 << 12; |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2624 |
static const uint WAITING_CARGO_CUT_FACTOR = 1 << 6; |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2625 |
static const uint MAX_WAITING_CARGO = 1 << 15; |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2626 |
|
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2627 |
if (waiting > WAITING_CARGO_THRESHOLD) { |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2628 |
uint difference = waiting - WAITING_CARGO_THRESHOLD; |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2629 |
waiting -= (difference / WAITING_CARGO_CUT_FACTOR); |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2630 |
|
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2631 |
waiting = min(waiting, MAX_WAITING_CARGO); |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2632 |
waiting_changed = true; |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2633 |
} |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
2634 |
|
9629 | 2635 |
if (waiting_changed) ge->cargo.Truncate(waiting); |
0 | 2636 |
} |
2637 |
} |
|
2638 |
} while (++ge != endof(st->goods)); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2639 |
|
6395 | 2640 |
StationID index = st->index; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
2641 |
if (waiting_changed) { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2642 |
InvalidateWindow(WC_STATION_VIEW, index); // update whole window |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
2643 |
} else { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2644 |
InvalidateWindowWidget(WC_STATION_VIEW, index, SVW_RATINGLIST); // update only ratings list |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
2645 |
} |
0 | 2646 |
} |
2647 |
||
2648 |
/* called for every station each tick */ |
|
2649 |
static void StationHandleSmallTick(Station *st) |
|
2650 |
{ |
|
2639 | 2651 |
if (st->facilities == 0) return; |
0 | 2652 |
|
6395 | 2653 |
byte b = st->delete_ctr + 1; |
0 | 2654 |
if (b >= 185) b = 0; |
2655 |
st->delete_ctr = b; |
|
2656 |
||
2639 | 2657 |
if (b == 0) UpdateStationRating(st); |
0 | 2658 |
} |
2659 |
||
6573 | 2660 |
void OnTick_Station() |
0 | 2661 |
{ |
2639 | 2662 |
if (_game_mode == GM_EDITOR) return; |
0 | 2663 |
|
6395 | 2664 |
uint i = _station_tick_ctr; |
5247
c3eece01af11
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5220
diff
changeset
|
2665 |
if (++_station_tick_ctr > GetMaxStationIndex()) _station_tick_ctr = 0; |
0 | 2666 |
|
4352
8ddb01bc6075
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
2667 |
if (IsValidStationID(i)) StationHandleBigTick(GetStation(i)); |
0 | 2668 |
|
6395 | 2669 |
Station *st; |
10294 | 2670 |
FOR_ALL_STATIONS(st) { |
2671 |
StationHandleSmallTick(st); |
|
2672 |
||
2673 |
/* Run 250 tick interval trigger for station animation. |
|
2674 |
* Station index is included so that triggers are not all done |
|
2675 |
* at the same time. */ |
|
2676 |
if ((_tick_counter + st->index) % 250 == 0) { |
|
2677 |
StationAnimationTrigger(st, st->xy, STAT_ANIM_250_TICKS); |
|
2678 |
} |
|
2679 |
} |
|
0 | 2680 |
} |
2681 |
||
6573 | 2682 |
void StationMonthlyLoop() |
0 | 2683 |
{ |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
2684 |
/* not used */ |
0 | 2685 |
} |
2686 |
||
2687 |
||
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
|
2688 |
void ModifyStationRatingAround(TileIndex tile, PlayerID owner, int amount, uint radius) |
0 | 2689 |
{ |
2690 |
Station *st; |
|
2691 |
||
2692 |
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
|
2693 |
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
|
2694 |
DistanceManhattan(tile, st->xy) <= radius) { |
9505 | 2695 |
for (CargoID i = 0; i < NUM_CARGO; i++) { |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
2696 |
GoodsEntry *ge = &st->goods[i]; |
2549 | 2697 |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2698 |
if (ge->acceptance_pickup != 0) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2699 |
ge->rating = Clamp(ge->rating + amount, 0, 255); |
0 | 2700 |
} |
2701 |
} |
|
2702 |
} |
|
2703 |
} |
|
2704 |
} |
|
2705 |
||
9505 | 2706 |
static void UpdateStationWaiting(Station *st, CargoID type, uint amount) |
0 | 2707 |
{ |
9629 | 2708 |
st->goods[type].cargo.Append(new CargoPacket(st->index, amount)); |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2709 |
SetBit(st->goods[type].acceptance_pickup, GoodsEntry::PICKUP); |
9629 | 2710 |
|
10294 | 2711 |
StationAnimationTrigger(st, st->xy, STAT_ANIM_NEW_CARGO, type); |
2712 |
||
0 | 2713 |
InvalidateWindow(WC_STATION_VIEW, st->index); |
9626 | 2714 |
st->MarkTilesDirty(true); |
0 | 2715 |
} |
2716 |
||
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2717 |
static bool IsUniqueStationName(const char *name) |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2718 |
{ |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2719 |
const Station *st; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2720 |
char buf[512]; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2721 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2722 |
FOR_ALL_STATIONS(st) { |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2723 |
SetDParam(0, st->index); |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2724 |
GetString(buf, STR_STATION, lastof(buf)); |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2725 |
if (strcmp(buf, name) == 0) return false; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2726 |
} |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2727 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2728 |
return true; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2729 |
} |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2730 |
|
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
|
2731 |
/** 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
|
2732 |
* @param tile unused |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
2733 |
* @param flags operation to perform |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1784
diff
changeset
|
2734 |
* @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
|
2735 |
* @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
|
2736 |
*/ |
9629 | 2737 |
CommandCost CmdRenameStation(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 2738 |
{ |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2739 |
if (!IsValidStationID(p1) || StrEmpty(_cmd_text)) return CMD_ERROR; |
6395 | 2740 |
Station *st = GetStation(p1); |
1774
0fc4a31265c2
(svn r2278) When renaming a station, check if the station exists and belongs to the correct player
tron
parents:
1751
diff
changeset
|
2741 |
|
4352
8ddb01bc6075
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
2742 |
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
|
2743 |
|
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2744 |
if (!IsUniqueStationName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
2745 |
|
0 | 2746 |
if (flags & DC_EXEC) { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2747 |
free(st->name); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2748 |
st->name = strdup(_cmd_text); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
2749 |
|
0 | 2750 |
UpdateStationVirtCoord(st); |
10645 | 2751 |
InvalidateWindowData(WC_STATION_LIST, st->owner, 1); |
0 | 2752 |
MarkWholeScreenDirty(); |
2753 |
} |
|
2754 |
||
9629 | 2755 |
return CommandCost(); |
0 | 2756 |
} |
2757 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2758 |
/** |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
2759 |
* Find all (non-buoy) stations around an industry tile |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
2760 |
* |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
2761 |
* @param tile: Center tile to search from |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
2762 |
* @param w: Width of the center |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
2763 |
* @param h: Height of the center |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
2764 |
* |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
2765 |
* @return: Set of found stations |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
2766 |
*/ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2767 |
StationSet FindStationsAroundIndustryTile(TileIndex tile, int w, int h) |
0 | 2768 |
{ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2769 |
StationSet station_set; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2770 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2771 |
int w_prod; // width and height of the "producer" of the cargo |
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
|
2772 |
int h_prod; |
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2773 |
int max_rad; |
10776 | 2774 |
if (_settings_game.station.modified_catchment) { |
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2775 |
w_prod = w; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2776 |
h_prod = h; |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2777 |
w += 2 * MAX_CATCHMENT; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2778 |
h += 2 * MAX_CATCHMENT; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2779 |
max_rad = MAX_CATCHMENT; |
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2780 |
} 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
|
2781 |
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
|
2782 |
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
|
2783 |
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
|
2784 |
h += 8; |
9732 | 2785 |
max_rad = CA_UNMODIFIED; |
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2786 |
} |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2787 |
|
1981 | 2788 |
BEGIN_TILE_LOOP(cur_tile, w, h, tile - TileDiffXY(max_rad, max_rad)) |
0 | 2789 |
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
|
2790 |
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
|
2791 |
|
6395 | 2792 |
Station *st = GetStationByTile(cur_tile); |
2793 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2794 |
if (st->IsBuoy()) continue; // bouys don't accept cargo |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2795 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2796 |
|
10776 | 2797 |
if (_settings_game.station.modified_catchment) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2798 |
/* min and max coordinates of the producer relative */ |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2799 |
const int x_min_prod = max_rad + 1; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2800 |
const int x_max_prod = max_rad + w_prod; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2801 |
const int y_min_prod = max_rad + 1; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2802 |
const int y_max_prod = max_rad + h_prod; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2803 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2804 |
int rad = FindCatchmentRadius(st); |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2805 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2806 |
int x_dist = min(w_cur - x_min_prod, x_max_prod - w_cur); |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2807 |
if (w_cur < x_min_prod) { |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2808 |
x_dist = x_min_prod - w_cur; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2809 |
} else if (w_cur > x_max_prod) { |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2810 |
x_dist = w_cur - x_max_prod; |
0 | 2811 |
} |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2812 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2813 |
if (x_dist > rad) continue; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2814 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2815 |
int y_dist = min(h_cur - y_min_prod, y_max_prod - h_cur); |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2816 |
if (h_cur < y_min_prod) { |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2817 |
y_dist = y_min_prod - h_cur; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2818 |
} else if (h_cur > y_max_prod) { |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2819 |
y_dist = h_cur - y_max_prod; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2820 |
} |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2821 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2822 |
if (y_dist > rad) continue; |
0 | 2823 |
} |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2824 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2825 |
/* Insert the station in the set. This will fail if it has |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2826 |
* already been added. |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2827 |
*/ |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2828 |
station_set.insert(st); |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2829 |
|
1981 | 2830 |
END_TILE_LOOP(cur_tile, w, h, tile - TileDiffXY(max_rad, max_rad)) |
0 | 2831 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2832 |
return station_set; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2833 |
} |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2834 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2835 |
uint MoveGoodsToStation(TileIndex tile, int w, int h, CargoID type, uint amount) |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2836 |
{ |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
2837 |
Station *st1 = NULL; // Station with best rating |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
2838 |
Station *st2 = NULL; // Second best station |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
2839 |
uint best_rating1 = 0; // rating of st1 |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
2840 |
uint best_rating2 = 0; // rating of st2 |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2841 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2842 |
StationSet all_stations = FindStationsAroundIndustryTile(tile, w, h); |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2843 |
for (StationSet::iterator st_iter = all_stations.begin(); st_iter != all_stations.end(); ++st_iter) { |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2844 |
Station *st = *st_iter; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2845 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2846 |
/* Is the station reserved exclusively for somebody else? */ |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2847 |
if (st->town->exclusive_counter > 0 && st->town->exclusivity != st->owner) continue; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2848 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2849 |
if (st->goods[type].rating == 0) continue; // Lowest possible rating, better not to give cargo anymore |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2850 |
|
10776 | 2851 |
if (_settings_game.order.selectgoods && st->goods[type].last_speed == 0) continue; // Selectively servicing stations, and not this one |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2852 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2853 |
if (IsCargoInClass(type, CC_PASSENGERS)) { |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2854 |
if (st->facilities == FACIL_TRUCK_STOP) continue; // passengers are never served by just a truck stop |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2855 |
} else { |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2856 |
if (st->facilities == FACIL_BUS_STOP) continue; // non-passengers are never served by just a bus stop |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2857 |
} |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2858 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2859 |
/* This station can be used, add it to st1/st2 */ |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2860 |
if (st1 == NULL || st->goods[type].rating >= best_rating1) { |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2861 |
st2 = st1; best_rating2 = best_rating1; st1 = st; best_rating1 = st->goods[type].rating; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2862 |
} else if (st2 == NULL || st->goods[type].rating >= best_rating2) { |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2863 |
st2 = st; best_rating2 = st->goods[type].rating; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2864 |
} |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2865 |
} |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2866 |
|
0 | 2867 |
/* no stations around at all? */ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2868 |
if (st1 == NULL) return 0; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2869 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2870 |
if (st2 == NULL) { |
0 | 2871 |
/* only one station around */ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2872 |
uint moved = amount * best_rating1 / 256 + 1; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2873 |
UpdateStationWaiting(st1, type, moved); |
0 | 2874 |
return moved; |
2875 |
} |
|
2876 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2877 |
/* several stations around, the best two (highest rating) are in st1 and st2 */ |
0 | 2878 |
assert(st1 != NULL); |
2879 |
assert(st2 != NULL); |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2880 |
assert(best_rating1 != 0 || best_rating2 != 0); |
0 | 2881 |
|
2882 |
/* the 2nd highest one gets a penalty */ |
|
2883 |
best_rating2 >>= 1; |
|
2884 |
||
2885 |
/* amount given to station 1 */ |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2886 |
uint t = (best_rating1 * (amount + 1)) / (best_rating1 + best_rating2); |
6395 | 2887 |
|
2888 |
uint moved = 0; |
|
0 | 2889 |
if (t != 0) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2890 |
moved = t * best_rating1 / 256 + 1; |
0 | 2891 |
amount -= t; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2892 |
UpdateStationWaiting(st1, type, moved); |
0 | 2893 |
} |
2894 |
||
2895 |
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
|
2896 |
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
|
2897 |
moved += amount; |
0 | 2898 |
UpdateStationWaiting(st2, type, amount); |
2899 |
} |
|
2900 |
||
2901 |
return moved; |
|
2902 |
} |
|
2903 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2904 |
void BuildOilRig(TileIndex tile) |
0 | 2905 |
{ |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
2906 |
Station *st = new Station(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
|
2907 |
|
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
|
2908 |
if (st == NULL) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5550
diff
changeset
|
2909 |
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
|
2910 |
return; |
0 | 2911 |
} |
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
|
2912 |
|
10355
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
2913 |
st->town = ClosestTownFromTile(tile, UINT_MAX); |
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
|
2914 |
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
|
2915 |
|
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
2916 |
st->string_id = GenerateStationName(st, tile, STATIONNAMING_OILRIG); |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2917 |
|
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2918 |
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
|
2919 |
|
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
|
2920 |
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
|
2921 |
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
|
2922 |
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
|
2923 |
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
|
2924 |
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
|
2925 |
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
|
2926 |
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
|
2927 |
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
|
2928 |
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
|
2929 |
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
|
2930 |
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
|
2931 |
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
|
2932 |
st->delete_ctr = 0; |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2933 |
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
|
2934 |
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
|
2935 |
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
|
2936 |
|
9505 | 2937 |
for (CargoID j = 0; j < NUM_CARGO; j++) { |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2938 |
st->goods[j].acceptance_pickup = 0; |
9629 | 2939 |
st->goods[j].days_since_pickup = 255; |
6587
bc0bd6259485
(svn r9070) -Fix [FS#404]: if bribe failed and you didn't pick up cargo yet, you wouldn't ever be able to do so for a given station
truelight
parents:
6585
diff
changeset
|
2940 |
st->goods[j].rating = INITIAL_STATION_RATING; |
2427
b7a0ad02af26
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2941 |
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
|
2942 |
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
|
2943 |
} |
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
|
2944 |
|
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
|
2945 |
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
|
2946 |
UpdateStationAcceptance(st, false); |
0 | 2947 |
} |
2948 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2949 |
void DeleteOilRig(TileIndex tile) |
0 | 2950 |
{ |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
2951 |
Station *st = GetStationByTile(tile); |
0 | 2952 |
|
6138 | 2953 |
MakeWater(tile); |
0 | 2954 |
|
2955 |
st->dock_tile = 0; |
|
2956 |
st->airport_tile = 0; |
|
2957 |
st->facilities &= ~(FACIL_AIRPORT | FACIL_DOCK); |
|
2958 |
st->airport_flags = 0; |
|
2959 |
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
|
2960 |
if (st->facilities == 0) delete st; |
0 | 2961 |
} |
2962 |
||
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
|
2963 |
static void ChangeTileOwner_Station(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 2964 |
{ |
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
|
2965 |
if (!IsTileOwner(tile, old_player)) return; |
0 | 2966 |
|
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4638
diff
changeset
|
2967 |
if (new_player != PLAYER_SPECTATOR) { |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
2968 |
Station *st = GetStationByTile(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
|
2969 |
|
1902 | 2970 |
SetTileOwner(tile, new_player); |
9732 | 2971 |
if (!IsBuoy(tile)) st->owner = new_player; // do not set st->owner for buoys |
10645 | 2972 |
InvalidateWindowClassesData(WC_STATION_LIST, 0); |
0 | 2973 |
} else { |
9732 | 2974 |
if (IsDriveThroughStopTile(tile)) { |
2975 |
/* Remove the drive-through road stop */ |
|
9837
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9826
diff
changeset
|
2976 |
DoCommand(tile, 0, (GetStationType(tile) == STATION_TRUCK) ? ROADSTOP_TRUCK : ROADSTOP_BUS, DC_EXEC | DC_BANKRUPT, CMD_REMOVE_ROAD_STOP); |
9732 | 2977 |
assert(IsTileType(tile, MP_ROAD)); |
2978 |
/* Change owner of tile and all roadtypes */ |
|
2979 |
ChangeTileOwner(tile, old_player, new_player); |
|
6442
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2980 |
} else { |
9732 | 2981 |
DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR); |
2982 |
/* Set tile owner of water under (now removed) buoy and dock to OWNER_NONE. |
|
2983 |
* Update owner of buoy if it was not removed (was in orders). |
|
2984 |
* Do not update when owned by OWNER_WATER (sea and rivers). */ |
|
2985 |
if ((IsTileType(tile, MP_WATER) || IsBuoyTile(tile)) && IsTileOwner(tile, old_player)) SetTileOwner(tile, OWNER_NONE); |
|
6442
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2986 |
} |
0 | 2987 |
} |
2988 |
} |
|
2989 |
||
6442
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2990 |
/** |
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2991 |
* Check if a drive-through road stop tile can be cleared. |
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2992 |
* Road stops built on town-owned roads check the conditions |
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2993 |
* that would allow clearing of the original road. |
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2994 |
* @param tile road stop tile to check |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
2995 |
* @param flags command flags |
6442
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2996 |
* @return true if the road can be cleared |
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2997 |
*/ |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
2998 |
static bool CanRemoveRoadWithStop(TileIndex tile, uint32 flags) |
6442
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2999 |
{ |
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
3000 |
/* The road can always be cleared if it was not a town-owned road */ |
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
3001 |
if (!GetStopBuiltOnTownRoad(tile)) return true; |
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
3002 |
|
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
3003 |
return CheckAllowRemoveRoad(tile, GetAnyRoadBits(tile, ROADTYPE_ROAD), OWNER_TOWN, ROADTYPE_ROAD, flags); |
6442
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
3004 |
} |
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
3005 |
|
9629 | 3006 |
static CommandCost ClearTile_Station(TileIndex tile, byte flags) |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
3007 |
{ |
0 | 3008 |
if (flags & DC_AUTO) { |
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
3009 |
switch (GetStationType(tile)) { |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
3010 |
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
|
3011 |
case STATION_AIRPORT: return_cmd_error(STR_300E_MUST_DEMOLISH_AIRPORT_FIRST); |
9732 | 3012 |
case STATION_TRUCK: return_cmd_error(HasTileRoadType(tile, ROADTYPE_TRAM) ? STR_MUST_DEMOLISH_CARGO_TRAM_STATION : STR_3047_MUST_DEMOLISH_TRUCK_STATION); |
3013 |
case STATION_BUS: return_cmd_error(HasTileRoadType(tile, ROADTYPE_TRAM) ? STR_MUST_DEMOLISH_PASSENGER_TRAM_STATION : STR_3046_MUST_DEMOLISH_BUS_STATION); |
|
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
3014 |
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
|
3015 |
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
|
3016 |
case STATION_OILRIG: |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
3017 |
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
|
3018 |
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
|
3019 |
} |
0 | 3020 |
} |
3021 |
||
6395 | 3022 |
Station *st = GetStationByTile(tile); |
0 | 3023 |
|
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
3024 |
switch (GetStationType(tile)) { |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
3025 |
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
|
3026 |
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
|
3027 |
case STATION_TRUCK: |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
3028 |
if (IsDriveThroughStopTile(tile) && !CanRemoveRoadWithStop(tile, flags)) |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
3029 |
return_cmd_error(STR_3047_MUST_DEMOLISH_TRUCK_STATION); |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
3030 |
return RemoveRoadStop(st, flags, tile); |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
3031 |
case STATION_BUS: |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
3032 |
if (IsDriveThroughStopTile(tile) && !CanRemoveRoadWithStop(tile, flags)) |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
3033 |
return_cmd_error(STR_3046_MUST_DEMOLISH_BUS_STATION); |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
3034 |
return RemoveRoadStop(st, flags, tile); |
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
3035 |
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
|
3036 |
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
|
3037 |
default: break; |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
3038 |
} |
0 | 3039 |
|
3040 |
return CMD_ERROR; |
|
3041 |
} |
|
3042 |
||
6573 | 3043 |
void InitializeStations() |
0 | 3044 |
{ |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
3045 |
/* Clean the station pool and create 1 block in it */ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
3046 |
_Station_pool.CleanPool(); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
3047 |
_Station_pool.AddBlockToPool(); |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
3048 |
|
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3049 |
/* Clean the roadstop pool and create 1 block in it */ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
3050 |
_RoadStop_pool.CleanPool(); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
3051 |
_RoadStop_pool.AddBlockToPool(); |
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
3052 |
|
0 | 3053 |
_station_tick_ctr = 0; |
3054 |
} |
|
3055 |
||
3056 |
||
6573 | 3057 |
void AfterLoadStations() |
3765
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3058 |
{ |
6395 | 3059 |
/* Update the speclists of all stations to point to the currently loaded custom stations. */ |
3765
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3060 |
Station *st; |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3061 |
FOR_ALL_STATIONS(st) { |
6395 | 3062 |
for (uint i = 0; i < st->num_specs; i++) { |
3765
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3063 |
if (st->speclist[i].grfid == 0) continue; |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3064 |
|
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3065 |
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
|
3066 |
} |
9629 | 3067 |
|
3068 |
for (CargoID c = 0; c < NUM_CARGO; c++) st->goods[c].cargo.InvalidateCache(); |
|
10294 | 3069 |
|
3070 |
StationUpdateAnimTriggers(st); |
|
3765
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3071 |
} |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3072 |
} |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3073 |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3074 |
static CommandCost TerraformTile_Station(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new) |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3075 |
{ |
10776 | 3076 |
if (_settings_game.construction.build_on_slopes && AutoslopeEnabled()) { |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
3077 |
/* TODO: If you implement newgrf callback 149 'land slope check', you have to decide what to do with it here. |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
3078 |
* TTDP does not call it. |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
3079 |
*/ |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
3080 |
if (!IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) { |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
3081 |
switch (GetStationType(tile)) { |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
3082 |
case STATION_RAIL: { |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
3083 |
DiagDirection direction = AxisToDiagDir(GetRailStationAxis(tile)); |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
3084 |
if (!AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, direction)) break; |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
3085 |
if (!AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, ReverseDiagDir(direction))) break; |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
3086 |
return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform); |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
3087 |
} |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
3088 |
|
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
3089 |
case STATION_AIRPORT: |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
3090 |
return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform); |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
3091 |
|
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
3092 |
case STATION_TRUCK: |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
3093 |
case STATION_BUS: { |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
3094 |
DiagDirection direction = GetRoadStopDir(tile); |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
3095 |
if (!AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, direction)) break; |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
3096 |
if (IsDriveThroughStopTile(tile)) { |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
3097 |
if (!AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, ReverseDiagDir(direction))) break; |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
3098 |
} |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
3099 |
return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform); |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
3100 |
} |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
3101 |
|
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
3102 |
default: break; |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
3103 |
} |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
3104 |
} |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
3105 |
} |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3106 |
return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3107 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3108 |
|
3765
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3109 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
3110 |
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
|
3111 |
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
|
3112 |
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
|
3113 |
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
|
3114 |
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
|
3115 |
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
|
3116 |
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
|
3117 |
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
|
3118 |
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
|
3119 |
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
|
3120 |
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
|
3121 |
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
|
3122 |
VehicleEnter_Station, /* vehicle_enter_tile_proc */ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
3123 |
GetFoundation_Station, /* get_foundation_proc */ |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3124 |
TerraformTile_Station, /* terraform_tile_proc */ |
0 | 3125 |
}; |
3126 |
||
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
|
3127 |
static const SaveLoad _roadstop_desc[] = { |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
3128 |
SLE_VAR(RoadStop, xy, SLE_UINT32), |
5969 | 3129 |
SLE_CONDNULL(1, 0, 44), |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
3130 |
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
|
3131 |
/* 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
|
3132 |
SLE_CONDNULL(4, 0, 8), |
5967 | 3133 |
SLE_CONDNULL(2, 0, 44), |
3479
a4d992b5d24d
(svn r4324) Remove the unused road stop type attribute from struct RoadStop
tron
parents:
3478
diff
changeset
|
3134 |
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
|
3135 |
|
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
3136 |
SLE_REF(RoadStop, next, REF_ROADSTOPS), |
6118 | 3137 |
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
|
3138 |
|
3431 | 3139 |
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
|
3140 |
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
|
3141 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3142 |
SLE_END() |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3143 |
}; |
0 | 3144 |
|
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
|
3145 |
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
|
3146 |
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
|
3147 |
SLE_CONDVAR(Station, xy, SLE_UINT32, 6, SL_MAX_VERSION), |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
3148 |
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
|
3149 |
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
|
3150 |
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
|
3151 |
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
|
3152 |
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
|
3153 |
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
|
3154 |
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
|
3155 |
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
|
3156 |
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
|
3157 |
SLE_CONDVAR(Station, trainst_h, SLE_UINT8, 2, SL_MAX_VERSION), |
0 | 3158 |
|
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
3159 |
SLE_CONDNULL(1, 0, 3), ///< alpha_order |
0 | 3160 |
|
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
|
3161 |
SLE_VAR(Station, string_id, SLE_STRINGID), |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
3162 |
SLE_CONDSTR(Station, name, SLE_STR, 0, 84, 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
|
3163 |
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
|
3164 |
|
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
|
3165 |
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
|
3166 |
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
|
3167 |
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
|
3168 |
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
|
3169 |
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
|
3170 |
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
|
3171 |
|
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
3172 |
SLE_CONDNULL(2, 0, 5), ///< Truck/bus stop status |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
3173 |
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
|
3174 |
|
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
|
3175 |
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
|
3176 |
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
|
3177 |
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
|
3178 |
|
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
3179 |
SLE_CONDNULL(2, 0, 25), ///< 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
|
3180 |
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
|
3181 |
|
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10181
diff
changeset
|
3182 |
SLE_CONDNULL(2, 3, 25), ///< custom station class and id |
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
|
3183 |
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
|
3184 |
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
|
3185 |
|
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
|
3186 |
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
|
3187 |
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
|
3188 |
|
3687
109ec5cdb932
(svn r4612) - NewStations: add random bits (for graphic variation) to stations
peter1138
parents:
3682
diff
changeset
|
3189 |
/* 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
|
3190 |
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
|
3191 |
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
|
3192 |
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
|
3193 |
|
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
3194 |
SLE_CONDLST(Station, loading_vehicles, REF_VEHICLE, 57, SL_MAX_VERSION), |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
3195 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
3196 |
/* reserve extra space in savegame here. (currently 32 bytes) */ |
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
|
3197 |
SLE_CONDNULL(32, 2, SL_MAX_VERSION), |
0 | 3198 |
|
3199 |
SLE_END() |
|
3200 |
}; |
|
3201 |
||
9629 | 3202 |
static uint16 _waiting_acceptance; |
3203 |
static uint16 _cargo_source; |
|
3204 |
static uint32 _cargo_source_xy; |
|
3205 |
static uint16 _cargo_days; |
|
3206 |
static Money _cargo_feeder_share; |
|
3207 |
||
3765
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3208 |
static const SaveLoad _station_speclist_desc[] = { |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3209 |
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
|
3210 |
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
|
3211 |
|
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3212 |
SLE_END() |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3213 |
}; |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3214 |
|
0 | 3215 |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3216 |
void SaveLoad_STNS(Station *st) |
0 | 3217 |
{ |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3218 |
static const SaveLoad _goods_desc[] = { |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3219 |
SLEG_CONDVAR( _waiting_acceptance, SLE_UINT16, 0, 67), |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3220 |
SLE_CONDVAR(GoodsEntry, acceptance_pickup, SLE_UINT8, 68, SL_MAX_VERSION), |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3221 |
SLE_CONDNULL(2, 51, 67), |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3222 |
SLE_VAR(GoodsEntry, days_since_pickup, SLE_UINT8), |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3223 |
SLE_VAR(GoodsEntry, rating, SLE_UINT8), |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3224 |
SLEG_CONDVAR( _cargo_source, SLE_FILE_U8 | SLE_VAR_U16, 0, 6), |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3225 |
SLEG_CONDVAR( _cargo_source, SLE_UINT16, 7, 67), |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3226 |
SLEG_CONDVAR( _cargo_source_xy, SLE_UINT32, 44, 67), |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3227 |
SLEG_CONDVAR( _cargo_days, SLE_UINT8, 0, 67), |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3228 |
SLE_VAR(GoodsEntry, last_speed, SLE_UINT8), |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3229 |
SLE_VAR(GoodsEntry, last_age, SLE_UINT8), |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3230 |
SLEG_CONDVAR( _cargo_feeder_share, SLE_FILE_U32 | SLE_VAR_I64, 14, 64), |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3231 |
SLEG_CONDVAR( _cargo_feeder_share, SLE_INT64, 65, 67), |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3232 |
SLE_CONDLST(GoodsEntry, cargo.packets, REF_CARGO_PACKET, 68, SL_MAX_VERSION), |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3233 |
|
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3234 |
SLE_END() |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3235 |
}; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3236 |
|
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3237 |
|
0 | 3238 |
SlObject(st, _station_desc); |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
3239 |
|
9629 | 3240 |
_waiting_acceptance = 0; |
3241 |
||
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
3242 |
uint num_cargo = CheckSavegameVersion(55) ? 12 : NUM_CARGO; |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
3243 |
for (CargoID i = 0; i < num_cargo; i++) { |
9629 | 3244 |
GoodsEntry *ge = &st->goods[i]; |
3245 |
SlObject(ge, _goods_desc); |
|
3246 |
if (CheckSavegameVersion(68)) { |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
3247 |
SB(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE, 1, HasBit(_waiting_acceptance, 15)); |
9629 | 3248 |
if (GB(_waiting_acceptance, 0, 12) != 0) { |
3249 |
/* Don't construct the packet with station here, because that'll fail with old savegames */ |
|
3250 |
CargoPacket *cp = new CargoPacket(); |
|
3251 |
/* In old versions, enroute_from used 0xFF as INVALID_STATION */ |
|
3252 |
cp->source = (CheckSavegameVersion(7) && _cargo_source == 0xFF) ? INVALID_STATION : _cargo_source; |
|
3253 |
cp->count = GB(_waiting_acceptance, 0, 12); |
|
3254 |
cp->days_in_transit = _cargo_days; |
|
3255 |
cp->feeder_share = _cargo_feeder_share; |
|
3256 |
cp->source_xy = _cargo_source_xy; |
|
3257 |
cp->days_in_transit = _cargo_days; |
|
3258 |
cp->feeder_share = _cargo_feeder_share; |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
3259 |
SB(ge->acceptance_pickup, GoodsEntry::PICKUP, 1, 1); |
9629 | 3260 |
ge->cargo.Append(cp); |
3261 |
} |
|
3262 |
} |
|
1266
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1265
diff
changeset
|
3263 |
} |
3765
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3264 |
|
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3265 |
if (st->num_specs != 0) { |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3266 |
/* 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
|
3267 |
if (st->speclist == NULL) st->speclist = CallocT<StationSpecList>(st->num_specs); |
6395 | 3268 |
for (uint i = 0; i < st->num_specs; i++) { |
3269 |
SlObject(&st->speclist[i], _station_speclist_desc); |
|
3270 |
} |
|
3765
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3271 |
} |
0 | 3272 |
} |
3273 |
||
6573 | 3274 |
static void Save_STNS() |
0 | 3275 |
{ |
3276 |
Station *st; |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
3277 |
/* Write the stations */ |
0 | 3278 |
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
|
3279 |
SlSetArrayIndex(st->index); |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
3280 |
SlAutolength((AutolengthProc*)SaveLoad_STNS, st); |
0 | 3281 |
} |
3282 |
} |
|
3283 |
||
6573 | 3284 |
static void Load_STNS() |
0 | 3285 |
{ |
3286 |
int index; |
|
3287 |
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
|
3288 |
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
|
3289 |
|
0 | 3290 |
SaveLoad_STNS(st); |
3291 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
3292 |
/* this means it's an oldstyle savegame without support for nonuniform stations */ |
2639 | 3293 |
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
|
3294 |
uint w = GB(st->trainst_w, 4, 4); |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
3295 |
uint h = GB(st->trainst_w, 0, 4); |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
3296 |
|
6432 | 3297 |
if (GetRailStationAxis(st->train_tile) != AXIS_X) Swap(w, h); |
0 | 3298 |
st->trainst_w = w; |
3299 |
st->trainst_h = h; |
|
3300 |
} |
|
3301 |
} |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
3302 |
|
1472
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
3303 |
/* 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
|
3304 |
if (_station_tick_ctr > GetMaxStationIndex()) _station_tick_ctr = 0; |
0 | 3305 |
} |
3306 |
||
6573 | 3307 |
static void Save_ROADSTOP() |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3308 |
{ |
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3309 |
RoadStop *rs; |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3310 |
|
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3311 |
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
|
3312 |
SlSetArrayIndex(rs->index); |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
3313 |
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
|
3314 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3315 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3316 |
|
6573 | 3317 |
static void Load_ROADSTOP() |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3318 |
{ |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3319 |
int index; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3320 |
|
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3321 |
while ((index = SlIterateArray()) != -1) { |
5967 | 3322 |
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
|
3323 |
|
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3324 |
SlObject(rs, _roadstop_desc); |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3325 |
} |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3326 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3327 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
3328 |
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
|
3329 |
{ '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
|
3330 |
{ 'ROAD', Save_ROADSTOP, Load_ROADSTOP, CH_ARRAY | CH_LAST}, |
0 | 3331 |
}; |