author | bjarni |
Mon, 30 Jan 2006 19:31:02 +0000 | |
changeset 2937 | c6b63d147210 |
parent 2916 | 8f1aa489701f |
child 2951 | 2db3adee7736 |
child 9944 | 4f027626dbf6 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
2213
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
3 |
/** @file station_cmd.c |
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
4 |
*/ |
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
5 |
|
0 | 6 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1881
diff
changeset
|
7 |
#include "openttd.h" |
1299
0a6510cc889b
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1295
diff
changeset
|
8 |
#include "debug.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2148
diff
changeset
|
9 |
#include "functions.h" |
1363
01d3de5d8039
(svn r1867) Include tables/sprites.h only in files which need it
tron
parents:
1335
diff
changeset
|
10 |
#include "table/sprites.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
500
diff
changeset
|
11 |
#include "table/strings.h" |
679
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
595
diff
changeset
|
12 |
#include "map.h" |
1209
a1ac96655b79
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1190
diff
changeset
|
13 |
#include "tile.h" |
0 | 14 |
#include "station.h" |
15 |
#include "gfx.h" |
|
16 |
#include "window.h" |
|
17 |
#include "viewport.h" |
|
18 |
#include "command.h" |
|
19 |
#include "town.h" |
|
20 |
#include "vehicle.h" |
|
21 |
#include "news.h" |
|
22 |
#include "saveload.h" |
|
23 |
#include "economy.h" |
|
24 |
#include "player.h" |
|
25 |
#include "airport.h" |
|
405
6830ae7a0d5d
(svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents:
403
diff
changeset
|
26 |
#include "sprite.h" |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
27 |
#include "depot.h" |
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2671
diff
changeset
|
28 |
#include "train.h" |
0 | 29 |
|
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
30 |
enum { |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
31 |
/* Max stations: 64000 (64 * 1000) */ |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
32 |
STATION_POOL_BLOCK_SIZE_BITS = 6, /* In bits, so (1 << 6) == 64 */ |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
33 |
STATION_POOL_MAX_BLOCKS = 1000, |
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
34 |
|
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
35 |
/* Max roadstops: 64000 (32 * 2000) */ |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
36 |
ROADSTOP_POOL_BLOCK_SIZE_BITS = 5, /* In bits, so (1 << 5) == 32 */ |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
37 |
ROADSTOP_POOL_MAX_BLOCKS = 2000, |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
38 |
}; |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
39 |
|
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
40 |
/** |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
41 |
* Called if a new block is added to the station-pool |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
42 |
*/ |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
43 |
static void StationPoolNewBlock(uint start_item) |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
44 |
{ |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
45 |
Station *st; |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
46 |
|
2639 | 47 |
FOR_ALL_STATIONS_FROM(st, start_item) st->index = start_item++; |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
48 |
} |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
49 |
|
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
50 |
/** |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
51 |
* Called if a new block is added to the roadstop-pool |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
52 |
*/ |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
53 |
static void RoadStopPoolNewBlock(uint start_item) |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
54 |
{ |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
55 |
RoadStop *rs; |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
56 |
|
2639 | 57 |
FOR_ALL_ROADSTOPS_FROM(rs, start_item) rs->index = start_item++; |
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
58 |
} |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
59 |
|
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
60 |
/* Initialize the station-pool and roadstop-pool */ |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
61 |
MemoryPool _station_pool = { "Stations", STATION_POOL_MAX_BLOCKS, STATION_POOL_BLOCK_SIZE_BITS, sizeof(Station), &StationPoolNewBlock, 0, 0, NULL }; |
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
62 |
MemoryPool _roadstop_pool = { "RoadStop", ROADSTOP_POOL_MAX_BLOCKS, ROADSTOP_POOL_BLOCK_SIZE_BITS, sizeof(RoadStop), &RoadStopPoolNewBlock, 0, 0, NULL }; |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
63 |
|
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
64 |
|
0 | 65 |
// FIXME -- need to be embedded into Airport variable. Is dynamically |
66 |
// deducteable from graphics-tile array, so will not be needed |
|
1417
fd04b8a2eefc
(svn r1921) -Fix: Out of bounds array access which caused oil rigs to accept other cargo types besides passengers and mail
tron
parents:
1368
diff
changeset
|
67 |
const byte _airport_size_x[] = {4, 6, 1, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; |
fd04b8a2eefc
(svn r1921) -Fix: Out of bounds array access which caused oil rigs to accept other cargo types besides passengers and mail
tron
parents:
1368
diff
changeset
|
68 |
const byte _airport_size_y[] = {3, 6, 1, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; |
0 | 69 |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
70 |
void ShowAircraftDepotWindow(TileIndex tile); |
0 | 71 |
extern void UpdateAirplanesOnNewStation(Station *st); |
72 |
||
2549 | 73 |
static void MarkStationDirty(const Station* st) |
0 | 74 |
{ |
75 |
if (st->sign.width_1 != 0) { |
|
76 |
InvalidateWindowWidget(WC_STATION_VIEW, st->index, 1); |
|
77 |
||
78 |
MarkAllViewportsDirty( |
|
79 |
st->sign.left - 6, |
|
80 |
st->sign.top, |
|
81 |
st->sign.left + (st->sign.width_1 << 2) + 12, |
|
82 |
st->sign.top + 48); |
|
83 |
} |
|
84 |
} |
|
85 |
||
1551
eb05e6a90e67
(svn r2055) -CodeChange: Begun introducting StationID
celestar
parents:
1527
diff
changeset
|
86 |
static void InitializeRoadStop(RoadStop *road_stop, RoadStop *previous, TileIndex tile, StationID index) |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
87 |
{ |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
88 |
road_stop->xy = tile; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
89 |
road_stop->used = true; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
90 |
road_stop->status = 3; //stop is free |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
91 |
road_stop->slot[0] = road_stop->slot[1] = INVALID_SLOT; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
92 |
road_stop->next = NULL; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
93 |
road_stop->prev = previous; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
94 |
road_stop->station = index; |
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 |
|
2639 | 97 |
RoadStop* GetPrimaryRoadStop(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
|
98 |
{ |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
99 |
switch (type) { |
2631
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
100 |
case RS_BUS: return 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
|
101 |
case RS_TRUCK: return st->truck_stops; |
2631
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
102 |
default: NOT_REACHED(); |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
103 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
104 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
105 |
return NULL; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
106 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
107 |
|
2639 | 108 |
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
|
109 |
{ |
2639 | 110 |
const Station* st = GetStation(_m[tile].m2); |
111 |
RoadStop* rs; |
|
112 |
||
113 |
for (rs = GetPrimaryRoadStop(st, type); rs->xy != tile; rs = rs->next) { |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
114 |
assert(rs->next != NULL); |
2639 | 115 |
} |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
116 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
117 |
return rs; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
118 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
119 |
|
2817 | 120 |
static uint GetNumRoadStops(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
|
121 |
{ |
2549 | 122 |
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
|
123 |
const RoadStop *rs; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
124 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
125 |
assert(st != NULL); |
2549 | 126 |
for (rs = GetPrimaryRoadStop(st, type); rs != NULL; rs = rs->next) num++; |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
127 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
128 |
return num; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
129 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
130 |
|
2549 | 131 |
RoadStop *AllocateRoadStop(void) |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
132 |
{ |
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
133 |
RoadStop *rs; |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
134 |
|
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
135 |
FOR_ALL_ROADSTOPS(rs) { |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
136 |
if (!rs->used) { |
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
137 |
uint index = rs->index; |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
138 |
|
2549 | 139 |
memset(rs, 0, sizeof(*rs)); |
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
140 |
rs->index = index; |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
141 |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
142 |
return rs; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
143 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
144 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
145 |
|
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
146 |
/* Check if we can add a block to the pool */ |
2639 | 147 |
if (AddBlockToPool(&_roadstop_pool)) return AllocateRoadStop(); |
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
148 |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
149 |
return NULL; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
150 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
151 |
|
703
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
152 |
/* Calculate the radius of the station. Basicly it is the biggest |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
153 |
radius that is available within the station */ |
2643 | 154 |
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
|
155 |
{ |
2643 | 156 |
uint ret = 0; |
703
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
157 |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
158 |
if (st->bus_stops != NULL) ret = max(ret, CA_BUS); |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
159 |
if (st->truck_stops != NULL) ret = max(ret, CA_TRUCK); |
703
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
160 |
if (st->train_tile) ret = max(ret, CA_TRAIN); |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
161 |
if (st->dock_tile) ret = max(ret, CA_DOCK); |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
162 |
|
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
163 |
if (st->airport_tile) { |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
164 |
switch (st->airport_type) { |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
165 |
case AT_OILRIG: ret = max(ret, CA_AIR_OILPAD); break; |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
166 |
case AT_SMALL: ret = max(ret, CA_AIR_SMALL); break; |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
167 |
case AT_HELIPORT: ret = max(ret, CA_AIR_HELIPORT); break; |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
168 |
case AT_LARGE: ret = max(ret, CA_AIR_LARGE); break; |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
169 |
case AT_METROPOLITAN: ret = max(ret, CA_AIR_METRO); break; |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
170 |
case AT_INTERNATIONAL: ret = max(ret, CA_AIR_INTER); break; |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
171 |
} |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
172 |
} |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
173 |
|
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
174 |
return ret; |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
175 |
} |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
176 |
|
0 | 177 |
#define CHECK_STATIONS_ERR ((Station*)-1) |
178 |
||
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
|
179 |
static Station* GetStationAround(TileIndex tile, int w, int h, StationID closest_station) |
0 | 180 |
{ |
181 |
// check around to see if there's any stations there |
|
1981 | 182 |
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
|
183 |
if (IsTileType(tile_cur, MP_STATION)) { |
2498
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
184 |
StationID t = _m[tile_cur].m2; |
28
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
185 |
{ |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
186 |
Station *st = GetStation(t); |
28
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
187 |
// you cannot take control of an oilrig!! |
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
188 |
if (st->airport_type == AT_OILRIG && st->facilities == (FACIL_AIRPORT|FACIL_DOCK)) |
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
189 |
continue; |
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
190 |
} |
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
191 |
|
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
|
192 |
if (closest_station == INVALID_STATION) { |
0 | 193 |
closest_station = t; |
194 |
} else if (closest_station != t) { |
|
195 |
_error_message = STR_3006_ADJOINS_MORE_THAN_ONE_EXISTING; |
|
196 |
return CHECK_STATIONS_ERR; |
|
197 |
} |
|
198 |
} |
|
1981 | 199 |
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
|
200 |
return (closest_station == INVALID_STATION) ? NULL : GetStation(closest_station); |
0 | 201 |
} |
202 |
||
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1012
diff
changeset
|
203 |
TileIndex GetStationTileForVehicle(const Vehicle *v, const Station *st) |
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
43
diff
changeset
|
204 |
{ |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
43
diff
changeset
|
205 |
switch (v->type) { |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
43
diff
changeset
|
206 |
case VEH_Train: return st->train_tile; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
43
diff
changeset
|
207 |
case VEH_Aircraft: return st->airport_tile; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
43
diff
changeset
|
208 |
case VEH_Ship: return st->dock_tile; |
1231
64cc1f5c1c82
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1217
diff
changeset
|
209 |
case VEH_Road: |
64cc1f5c1c82
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1217
diff
changeset
|
210 |
if (v->cargo_type == CT_PASSENGERS) { |
2549 | 211 |
return (st->bus_stops != NULL) ? st->bus_stops->xy : 0; |
1231
64cc1f5c1c82
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1217
diff
changeset
|
212 |
} else { |
2549 | 213 |
return (st->truck_stops != NULL) ? st->truck_stops->xy : 0; |
1231
64cc1f5c1c82
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1217
diff
changeset
|
214 |
} |
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
43
diff
changeset
|
215 |
default: |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
43
diff
changeset
|
216 |
assert(false); |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
43
diff
changeset
|
217 |
return 0; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
43
diff
changeset
|
218 |
} |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
43
diff
changeset
|
219 |
} |
0 | 220 |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
221 |
static bool CheckStationSpreadOut(Station *st, TileIndex tile, int w, int h) |
0 | 222 |
{ |
1551
eb05e6a90e67
(svn r2055) -CodeChange: Begun introducting StationID
celestar
parents:
1527
diff
changeset
|
223 |
StationID station_index = st->index; |
0 | 224 |
uint i; |
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
|
225 |
uint x1 = 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
|
226 |
uint y1 = TileY(tile); |
0 | 227 |
uint x2 = x1 + w - 1; |
228 |
uint y2 = y1 + h - 1; |
|
229 |
uint t; |
|
230 |
||
863
8d09f9331a80
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
856
diff
changeset
|
231 |
for (i = 0; i != MapSize(); i++) { |
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
|
232 |
if (IsTileType(i, MP_STATION) && _m[i].m2 == station_index) { |
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
|
233 |
t = TileX(i); |
0 | 234 |
if (t < x1) x1 = t; |
235 |
if (t > x2) x2 = t; |
|
236 |
||
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
|
237 |
t = TileY(i); |
0 | 238 |
if (t < y1) y1 = t; |
239 |
if (t > y2) y2 = t; |
|
240 |
} |
|
241 |
} |
|
242 |
||
2549 | 243 |
if (y2 - y1 >= _patches.station_spread || x2 - x1 >= _patches.station_spread) { |
0 | 244 |
_error_message = STR_306C_STATION_TOO_SPREAD_OUT; |
245 |
return false; |
|
246 |
} |
|
247 |
||
248 |
return true; |
|
249 |
} |
|
250 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1078
diff
changeset
|
251 |
static Station *AllocateStation(void) |
0 | 252 |
{ |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
253 |
Station *st = NULL; |
0 | 254 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
255 |
FOR_ALL_STATIONS(st) { |
0 | 256 |
if (st->xy == 0) { |
1551
eb05e6a90e67
(svn r2055) -CodeChange: Begun introducting StationID
celestar
parents:
1527
diff
changeset
|
257 |
StationID index = st->index; |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
258 |
|
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
259 |
memset(st, 0, sizeof(Station)); |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
260 |
st->index = index; |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
261 |
|
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
262 |
return st; |
0 | 263 |
} |
264 |
} |
|
265 |
||
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
266 |
/* Check if we can add a block to the pool */ |
2639 | 267 |
if (AddBlockToPool(&_station_pool)) return AllocateStation(); |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
268 |
|
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
269 |
_error_message = STR_3008_TOO_MANY_STATIONS_LOADING; |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
270 |
return NULL; |
0 | 271 |
} |
272 |
||
273 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
274 |
static int CountMapSquareAround(TileIndex tile, byte type, byte min, byte max) |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
275 |
{ |
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
276 |
static const TileIndexDiffC _count_square_table[] = { |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
277 |
{-3, -3}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
278 |
{-6, 1}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
279 |
{-6, 1}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
280 |
{-6, 1}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
281 |
{-6, 1}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
282 |
{-6, 1}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
283 |
{-6, 1}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
284 |
}; |
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
285 |
const TileIndexDiffC *p; |
0 | 286 |
int num = 0; |
287 |
||
847
e0d8d5ef95b9
(svn r1328) Turn loop with explicit terminator element into loop using endof()
tron
parents:
817
diff
changeset
|
288 |
for (p = _count_square_table; p != endof(_count_square_table); ++p) { |
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
289 |
tile = TILE_MASK(tile + ToTileIndexDiff(*p)); |
0 | 290 |
|
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
|
291 |
if (IsTileType(tile, type) && _m[tile].m5 >= min && _m[tile].m5 <= max) |
0 | 292 |
num++; |
293 |
} |
|
294 |
||
295 |
return num; |
|
296 |
} |
|
297 |
||
298 |
#define M(x) ((x) - STR_SV_STNAME) |
|
299 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
300 |
static bool GenerateStationName(Station *st, TileIndex tile, int flag) |
0 | 301 |
{ |
302 |
static const uint32 _gen_station_name_bits[] = { |
|
1454 | 303 |
0, /* 0 */ |
304 |
1 << M(STR_SV_STNAME_AIRPORT), /* 1 */ |
|
305 |
1 << M(STR_SV_STNAME_OILFIELD), /* 2 */ |
|
306 |
1 << M(STR_SV_STNAME_DOCKS), /* 3 */ |
|
307 |
0x1FF << M(STR_SV_STNAME_BUOY_1), /* 4 */ |
|
308 |
1 << M(STR_SV_STNAME_HELIPORT), /* 5 */ |
|
0 | 309 |
}; |
310 |
||
311 |
Town *t = st->town; |
|
312 |
uint32 free_names = (uint32)-1; |
|
313 |
int found; |
|
314 |
uint z,z2; |
|
315 |
unsigned long tmp; |
|
316 |
||
317 |
{ |
|
318 |
Station *s; |
|
319 |
||
320 |
FOR_ALL_STATIONS(s) { |
|
321 |
if (s != st && s->xy != 0 && s->town==t) { |
|
322 |
uint str = M(s->string_id); |
|
323 |
if (str <= 0x20) { |
|
324 |
if (str == M(STR_SV_STNAME_FOREST)) |
|
325 |
str = M(STR_SV_STNAME_WOODS); |
|
326 |
CLRBIT(free_names, str); |
|
327 |
} |
|
328 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
329 |
} |
0 | 330 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
331 |
|
0 | 332 |
/* check default names */ |
333 |
tmp = free_names & _gen_station_name_bits[flag]; |
|
334 |
if (tmp != 0) { |
|
335 |
found = FindFirstBit(tmp); |
|
336 |
goto done; |
|
337 |
} |
|
338 |
||
339 |
/* check mine? */ |
|
340 |
if (HASBIT(free_names, M(STR_SV_STNAME_MINES))) { |
|
341 |
if (CountMapSquareAround(tile, MP_INDUSTRY, 0, 6) >= 2 || |
|
1472
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
342 |
CountMapSquareAround(tile, MP_INDUSTRY, 0x64, 0x73) >= 2 || |
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
343 |
CountMapSquareAround(tile, MP_INDUSTRY, 0x2F, 0x33) >= 2 || |
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
344 |
CountMapSquareAround(tile, MP_INDUSTRY, 0x48, 0x58) >= 2 || |
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
345 |
CountMapSquareAround(tile, MP_INDUSTRY, 0x5B, 0x63) >= 2) { |
1454 | 346 |
found = M(STR_SV_STNAME_MINES); |
347 |
goto done; |
|
348 |
} |
|
0 | 349 |
} |
350 |
||
351 |
/* check close enough to town to get central as name? */ |
|
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1239
diff
changeset
|
352 |
if (DistanceMax(tile,t->xy) < 8) { |
0 | 353 |
found = M(STR_SV_STNAME); |
354 |
if (HASBIT(free_names, M(STR_SV_STNAME))) goto done; |
|
355 |
||
356 |
found = M(STR_SV_STNAME_CENTRAL); |
|
357 |
if (HASBIT(free_names, M(STR_SV_STNAME_CENTRAL))) goto done; |
|
358 |
} |
|
359 |
||
360 |
/* Check lakeside */ |
|
1472
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
361 |
if (HASBIT(free_names, M(STR_SV_STNAME_LAKESIDE)) && |
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
362 |
DistanceFromEdge(tile) < 20 && |
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
363 |
CountMapSquareAround(tile, MP_WATER, 0, 0) >= 5) { |
1454 | 364 |
found = M(STR_SV_STNAME_LAKESIDE); |
365 |
goto done; |
|
366 |
} |
|
0 | 367 |
|
368 |
/* Check woods */ |
|
1472
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
369 |
if (HASBIT(free_names, M(STR_SV_STNAME_WOODS)) && ( |
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
370 |
CountMapSquareAround(tile, MP_TREES, 0, 255) >= 8 || |
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
371 |
CountMapSquareAround(tile, MP_INDUSTRY, 0x10, 0x11) >= 2) |
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
372 |
) { |
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
373 |
found = _opt.landscape == LT_DESERT ? |
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
374 |
M(STR_SV_STNAME_FOREST) : M(STR_SV_STNAME_WOODS); |
1454 | 375 |
goto done; |
0 | 376 |
} |
377 |
||
378 |
/* check elevation compared to town */ |
|
379 |
z = GetTileZ(tile); |
|
380 |
z2 = GetTileZ(t->xy); |
|
381 |
if (z < z2) { |
|
382 |
found = M(STR_SV_STNAME_VALLEY); |
|
383 |
if (HASBIT(free_names, M(STR_SV_STNAME_VALLEY))) goto done; |
|
384 |
} else if (z > z2) { |
|
385 |
found = M(STR_SV_STNAME_HEIGHTS); |
|
386 |
if (HASBIT(free_names, M(STR_SV_STNAME_HEIGHTS))) goto done; |
|
387 |
} |
|
388 |
||
389 |
/* check direction compared to town */ |
|
390 |
{ |
|
391 |
static const int8 _direction_and_table[] = { |
|
392 |
~( (1<<M(STR_SV_STNAME_WEST)) | (1<<M(STR_SV_STNAME_EAST)) | (1<<M(STR_SV_STNAME_NORTH)) ), |
|
393 |
~( (1<<M(STR_SV_STNAME_SOUTH)) | (1<<M(STR_SV_STNAME_WEST)) | (1<<M(STR_SV_STNAME_NORTH)) ), |
|
394 |
~( (1<<M(STR_SV_STNAME_SOUTH)) | (1<<M(STR_SV_STNAME_EAST)) | (1<<M(STR_SV_STNAME_NORTH)) ), |
|
395 |
~( (1<<M(STR_SV_STNAME_SOUTH)) | (1<<M(STR_SV_STNAME_WEST)) | (1<<M(STR_SV_STNAME_EAST)) ), |
|
396 |
}; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
397 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
398 |
free_names &= _direction_and_table[ |
926
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
399 |
(TileX(tile) < TileX(t->xy)) + |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
400 |
(TileY(tile) < TileY(t->xy)) * 2]; |
0 | 401 |
} |
402 |
||
403 |
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)); |
|
404 |
if (tmp == 0) { |
|
405 |
_error_message = STR_3007_TOO_MANY_STATIONS_LOADING; |
|
406 |
return false; |
|
407 |
} |
|
408 |
found = FindFirstBit(tmp); |
|
409 |
||
410 |
done: |
|
411 |
st->string_id = found + STR_SV_STNAME; |
|
412 |
return true; |
|
413 |
} |
|
414 |
#undef M |
|
415 |
||
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
|
416 |
static Station* GetClosestStationFromTile(TileIndex tile, uint threshold, PlayerID owner) |
0 | 417 |
{ |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
418 |
Station* best_station = NULL; |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
419 |
Station* st; |
0 | 420 |
|
421 |
FOR_ALL_STATIONS(st) { |
|
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
422 |
if (st->xy != 0 && (owner == OWNER_SPECTATOR || st->owner == owner)) { |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
423 |
uint cur_dist = DistanceManhattan(tile, st->xy); |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
424 |
|
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
425 |
if (cur_dist < threshold) { |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
426 |
threshold = cur_dist; |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
427 |
best_station = st; |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
428 |
} |
0 | 429 |
} |
430 |
} |
|
431 |
||
432 |
return best_station; |
|
433 |
} |
|
434 |
||
435 |
static void StationInitialize(Station *st, TileIndex tile) |
|
436 |
{ |
|
437 |
GoodsEntry *ge; |
|
438 |
||
439 |
st->xy = tile; |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
440 |
st->airport_tile = st->dock_tile = st->train_tile = 0; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
441 |
st->bus_stops = st->truck_stops = NULL; |
0 | 442 |
st->had_vehicle_of_type = 0; |
443 |
st->time_since_load = 255; |
|
444 |
st->time_since_unload = 255; |
|
445 |
st->delete_ctr = 0; |
|
446 |
st->facilities = 0; |
|
447 |
||
448 |
st->last_vehicle = INVALID_VEHICLE; |
|
449 |
||
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
450 |
for (ge = st->goods; ge != endof(st->goods); ge++) { |
0 | 451 |
ge->waiting_acceptance = 0; |
452 |
ge->days_since_pickup = 0; |
|
1266
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1265
diff
changeset
|
453 |
ge->enroute_from = INVALID_STATION; |
0 | 454 |
ge->rating = 175; |
455 |
ge->last_speed = 0; |
|
456 |
ge->last_age = 0xFF; |
|
1935
f43f062c9498
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1902
diff
changeset
|
457 |
ge->feeder_profit = 0; |
0 | 458 |
} |
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
459 |
|
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
460 |
_global_station_sort_dirty = true; // build a new station |
0 | 461 |
} |
462 |
||
463 |
// Update the virtual coords needed to draw the station sign. |
|
464 |
// st = Station to update for. |
|
465 |
static void UpdateStationVirtCoord(Station *st) |
|
466 |
{ |
|
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
|
467 |
Point pt = RemapCoords2(TileX(st->xy) * 16, TileY(st->xy) * 16); |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
468 |
|
0 | 469 |
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
|
470 |
if (st->facilities & FACIL_AIRPORT && st->airport_type == AT_OILRIG) pt.y -= 16; |
0 | 471 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
472 |
SetDParam(0, st->index); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
473 |
SetDParam(1, st->facilities); |
0 | 474 |
UpdateViewportSignPos(&st->sign, pt.x, pt.y, STR_305C_0); |
475 |
} |
|
476 |
||
477 |
// Update the virtual coords needed to draw the station sign for all stations. |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1078
diff
changeset
|
478 |
void UpdateAllStationVirtCoord(void) |
0 | 479 |
{ |
2639 | 480 |
Station* st; |
481 |
||
0 | 482 |
FOR_ALL_STATIONS(st) { |
2639 | 483 |
if (st->xy != 0) UpdateStationVirtCoord(st); |
0 | 484 |
} |
485 |
} |
|
486 |
||
487 |
// Update the station virt coords while making the modified parts dirty. |
|
488 |
static void UpdateStationVirtCoordDirty(Station *st) |
|
489 |
{ |
|
490 |
MarkStationDirty(st); |
|
491 |
UpdateStationVirtCoord(st); |
|
492 |
MarkStationDirty(st); |
|
493 |
} |
|
494 |
||
495 |
// Get a mask of the cargo types that the station accepts. |
|
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
496 |
static uint GetAcceptanceMask(const Station *st) |
0 | 497 |
{ |
498 |
uint mask = 0; |
|
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
499 |
uint i; |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
500 |
|
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
501 |
for (i = 0; i != NUM_CARGO; i++) { |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
502 |
if (st->goods[i].waiting_acceptance & 0x8000) mask |= 1 << i; |
0 | 503 |
} |
504 |
return mask; |
|
505 |
} |
|
506 |
||
507 |
// Items contains the two cargo names that are to be accepted or rejected. |
|
508 |
// msg is the string id of the message to display. |
|
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
509 |
static void ShowRejectOrAcceptNews(const Station *st, uint32 items, StringID msg) |
0 | 510 |
{ |
511 |
if (items) { |
|
2549 | 512 |
SetDParam(2, GB(items, 16, 16)); |
513 |
SetDParam(1, GB(items, 0, 16)); |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
514 |
SetDParam(0, st->index); |
0 | 515 |
AddNewsItem(msg + ((items >> 16)?1:0), NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_TILE, NT_ACCEPTANCE, 0), st->xy, 0); |
516 |
} |
|
517 |
} |
|
518 |
||
519 |
// Get a list of the cargo types being produced around the tile. |
|
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
520 |
void GetProductionAroundTiles(AcceptedCargo produced, TileIndex tile, |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
521 |
int w, int h, int rad) |
0 | 522 |
{ |
523 |
int x,y; |
|
524 |
int x1,y1,x2,y2; |
|
525 |
int xc,yc; |
|
526 |
||
2133 | 527 |
memset(produced, 0, sizeof(AcceptedCargo)); |
0 | 528 |
|
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
|
529 |
x = TileX(tile); |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
530 |
y = TileY(tile); |
0 | 531 |
|
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
532 |
// expand the region by rad tiles on each side |
0 | 533 |
// while making sure that we remain inside the board. |
856
07dc27d0503e
(svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents:
847
diff
changeset
|
534 |
x2 = min(x + w + rad, MapSizeX()); |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
535 |
x1 = max(x - rad, 0); |
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
536 |
|
856
07dc27d0503e
(svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents:
847
diff
changeset
|
537 |
y2 = min(y + h + rad, MapSizeY()); |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
538 |
y1 = max(y - rad, 0); |
0 | 539 |
|
540 |
assert(x1 < x2); |
|
541 |
assert(y1 < y2); |
|
542 |
assert(w > 0); |
|
543 |
assert(h > 0); |
|
544 |
||
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
545 |
for (yc = y1; yc != y2; yc++) { |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
546 |
for (xc = x1; xc != x2; xc++) { |
0 | 547 |
if (!(IS_INSIDE_1D(xc, x, w) && IS_INSIDE_1D(yc, y, h))) { |
548 |
GetProducedCargoProc *gpc; |
|
1981 | 549 |
TileIndex tile = TileXY(xc, yc); |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
550 |
|
1214
33e07bbb7779
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1209
diff
changeset
|
551 |
gpc = _tile_type_procs[GetTileType(tile)]->get_produced_cargo_proc; |
0 | 552 |
if (gpc != NULL) { |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
553 |
byte cargos[2] = { CT_INVALID, CT_INVALID }; |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
554 |
|
0 | 555 |
gpc(tile, cargos); |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
556 |
if (cargos[0] != CT_INVALID) { |
0 | 557 |
produced[cargos[0]]++; |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
558 |
if (cargos[1] != CT_INVALID) { |
0 | 559 |
produced[cargos[1]]++; |
560 |
} |
|
561 |
} |
|
562 |
} |
|
563 |
} |
|
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
564 |
} |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
565 |
} |
0 | 566 |
} |
567 |
||
568 |
// Get a list of the cargo types that are accepted around the tile. |
|
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
569 |
void GetAcceptanceAroundTiles(AcceptedCargo accepts, TileIndex tile, |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
570 |
int w, int h, int rad) |
0 | 571 |
{ |
572 |
int x,y; |
|
573 |
int x1,y1,x2,y2; |
|
574 |
int xc,yc; |
|
473
0da86c59e3ae
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
457
diff
changeset
|
575 |
|
0da86c59e3ae
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
457
diff
changeset
|
576 |
memset(accepts, 0, sizeof(AcceptedCargo)); |
0 | 577 |
|
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
|
578 |
x = TileX(tile); |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
579 |
y = TileY(tile); |
0 | 580 |
|
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
581 |
// expand the region by rad tiles on each side |
0 | 582 |
// while making sure that we remain inside the board. |
856
07dc27d0503e
(svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents:
847
diff
changeset
|
583 |
x2 = min(x + w + rad, MapSizeX()); |
07dc27d0503e
(svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents:
847
diff
changeset
|
584 |
y2 = min(y + h + rad, MapSizeY()); |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
585 |
x1 = max(x - rad, 0); |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
586 |
y1 = max(y - rad, 0); |
0 | 587 |
|
588 |
assert(x1 < x2); |
|
589 |
assert(y1 < y2); |
|
590 |
assert(w > 0); |
|
591 |
assert(h > 0); |
|
592 |
||
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
593 |
for (yc = y1; yc != y2; yc++) { |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
594 |
for (xc = x1; xc != x2; xc++) { |
1981 | 595 |
TileIndex tile = TileXY(xc, yc); |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
596 |
|
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
|
597 |
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
|
598 |
AcceptedCargo ac; |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
599 |
uint i; |
473
0da86c59e3ae
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
457
diff
changeset
|
600 |
|
0da86c59e3ae
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
457
diff
changeset
|
601 |
GetAcceptedCargo(tile, ac); |
2639 | 602 |
for (i = 0; i < lengthof(ac); ++i) accepts[i] += ac[i]; |
0 | 603 |
} |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
604 |
} |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
605 |
} |
0 | 606 |
} |
607 |
||
2793
d613eb566917
(svn r3341) -Codechange: make mingw32 happy, and renamed Rectangle, because it already exists on that platform
truelight
parents:
2767
diff
changeset
|
608 |
typedef struct ottd_Rectangle { |
1423
50abec7ebe37
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
609 |
uint min_x; |
50abec7ebe37
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
610 |
uint min_y; |
50abec7ebe37
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
611 |
uint max_x; |
50abec7ebe37
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
612 |
uint max_y; |
2793
d613eb566917
(svn r3341) -Codechange: make mingw32 happy, and renamed Rectangle, because it already exists on that platform
truelight
parents:
2767
diff
changeset
|
613 |
} ottd_Rectangle; |
d613eb566917
(svn r3341) -Codechange: make mingw32 happy, and renamed Rectangle, because it already exists on that platform
truelight
parents:
2767
diff
changeset
|
614 |
|
d613eb566917
(svn r3341) -Codechange: make mingw32 happy, and renamed Rectangle, because it already exists on that platform
truelight
parents:
2767
diff
changeset
|
615 |
static void MergePoint(ottd_Rectangle* rect, TileIndex tile) |
1423
50abec7ebe37
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
616 |
{ |
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
|
617 |
uint x = TileX(tile); |
50abec7ebe37
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
618 |
uint y = TileY(tile); |
50abec7ebe37
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
619 |
|
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
|
620 |
if (rect->min_x > x) rect->min_x = x; |
50abec7ebe37
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
621 |
if (rect->min_y > y) rect->min_y = y; |
50abec7ebe37
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
622 |
if (rect->max_x < x) rect->max_x = x; |
50abec7ebe37
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
623 |
if (rect->max_y < y) rect->max_y = y; |
50abec7ebe37
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
624 |
} |
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
|
625 |
|
0 | 626 |
// Update the acceptance for a station. |
627 |
// show_msg controls whether to display a message that acceptance was changed. |
|
628 |
static void UpdateStationAcceptance(Station *st, bool show_msg) |
|
629 |
{ |
|
630 |
uint old_acc, new_acc; |
|
1423
50abec7ebe37
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
631 |
const RoadStop *cur_rs; |
0 | 632 |
int i; |
2793
d613eb566917
(svn r3341) -Codechange: make mingw32 happy, and renamed Rectangle, because it already exists on that platform
truelight
parents:
2767
diff
changeset
|
633 |
ottd_Rectangle rect; |
1423
50abec7ebe37
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
634 |
int rad; |
50abec7ebe37
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
635 |
AcceptedCargo accepts; |
0 | 636 |
|
1507
2d09b13f049f
(svn r2011) - Fix: [ 1162209 ] Fix OS/2 build (orudge) #2
darkvater
parents:
1477
diff
changeset
|
637 |
rect.min_x = MapSizeX(); |
2d09b13f049f
(svn r2011) - Fix: [ 1162209 ] Fix OS/2 build (orudge) #2
darkvater
parents:
1477
diff
changeset
|
638 |
rect.min_y = MapSizeY(); |
2d09b13f049f
(svn r2011) - Fix: [ 1162209 ] Fix OS/2 build (orudge) #2
darkvater
parents:
1477
diff
changeset
|
639 |
rect.max_x = rect.max_y = 0; |
0 | 640 |
// Don't update acceptance for a buoy |
2639 | 641 |
if (IsBuoy(st)) return; |
0 | 642 |
|
643 |
/* old accepted goods types */ |
|
644 |
old_acc = GetAcceptanceMask(st); |
|
645 |
||
646 |
// Put all the tiles that span an area in the table. |
|
647 |
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
|
648 |
MergePoint(&rect, st->train_tile); |
50abec7ebe37
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
649 |
MergePoint(&rect, |
1981 | 650 |
st->train_tile + TileDiffXY(st->trainst_w - 1, st->trainst_h - 1) |
1423
50abec7ebe37
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
651 |
); |
0 | 652 |
} |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
653 |
|
0 | 654 |
if (st->airport_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
|
655 |
MergePoint(&rect, st->airport_tile); |
50abec7ebe37
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
656 |
MergePoint(&rect, |
1981 | 657 |
st->airport_tile + TileDiffXY( |
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
|
658 |
_airport_size_x[st->airport_type] - 1, |
50abec7ebe37
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
659 |
_airport_size_y[st->airport_type] - 1 |
50abec7ebe37
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
660 |
) |
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
|
661 |
); |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
662 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
663 |
|
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
|
664 |
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
|
665 |
|
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
|
666 |
for (cur_rs = st->bus_stops; cur_rs != NULL; cur_rs = cur_rs->next) { |
50abec7ebe37
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
667 |
MergePoint(&rect, cur_rs->xy); |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
668 |
} |
0 | 669 |
|
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
|
670 |
for (cur_rs = st->truck_stops; cur_rs != NULL; cur_rs = cur_rs->next) { |
50abec7ebe37
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
671 |
MergePoint(&rect, cur_rs->xy); |
0 | 672 |
} |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
673 |
|
2631
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
674 |
rad = (_patches.modified_catchment) ? FindCatchmentRadius(st) : 4; |
0 | 675 |
|
676 |
// And retrieve the acceptance. |
|
1423
50abec7ebe37
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
677 |
if (rect.max_x >= rect.min_x) { |
50abec7ebe37
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
678 |
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
|
679 |
accepts, |
1981 | 680 |
TileXY(rect.min_x, rect.min_y), |
1423
50abec7ebe37
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
681 |
rect.max_x - rect.min_x + 1, |
50abec7ebe37
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
682 |
rect.max_y - rect.min_y + 1, |
50abec7ebe37
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
683 |
rad |
50abec7ebe37
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
684 |
); |
0 | 685 |
} else { |
686 |
memset(accepts, 0, sizeof(accepts)); |
|
687 |
} |
|
688 |
||
689 |
// Adjust in case our station only accepts fewer kinds of goods |
|
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
690 |
for (i = 0; i != NUM_CARGO; i++) { |
0 | 691 |
uint amt = min(accepts[i], 15); |
692 |
||
693 |
// Make sure the station can accept the goods type. |
|
694 |
if ((i != CT_PASSENGERS && !(st->facilities & (byte)~FACIL_BUS_STOP)) || |
|
695 |
(i == CT_PASSENGERS && !(st->facilities & (byte)~FACIL_TRUCK_STOP))) |
|
696 |
amt = 0; |
|
697 |
||
2504
7c27fc230cda
(svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents:
2502
diff
changeset
|
698 |
SB(st->goods[i].waiting_acceptance, 12, 4, amt); |
0 | 699 |
} |
700 |
||
701 |
// Only show a message in case the acceptance was actually changed. |
|
702 |
new_acc = GetAcceptanceMask(st); |
|
703 |
if (old_acc == new_acc) |
|
704 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
705 |
|
0 | 706 |
// show a message to report that the acceptance was changed? |
707 |
if (show_msg && st->owner == _local_player && st->facilities) { |
|
708 |
uint32 accept=0, reject=0; /* these contain two string ids each */ |
|
709 |
const StringID *str = _cargoc.names_s; |
|
710 |
||
711 |
do { |
|
712 |
if (new_acc & 1) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
713 |
if (!(old_acc & 1)) accept = (accept << 16) | *str; |
0 | 714 |
} else { |
715 |
if (old_acc & 1) reject = (reject << 16) | *str; |
|
716 |
} |
|
717 |
} while (str++,(new_acc>>=1) != (old_acc>>=1)); |
|
718 |
||
719 |
ShowRejectOrAcceptNews(st, accept, STR_3040_NOW_ACCEPTS); |
|
720 |
ShowRejectOrAcceptNews(st, reject, STR_303E_NO_LONGER_ACCEPTS); |
|
721 |
} |
|
722 |
||
723 |
// redraw the station view since acceptance changed |
|
724 |
InvalidateWindowWidget(WC_STATION_VIEW, st->index, 4); |
|
725 |
} |
|
726 |
||
727 |
// This is called right after a station was deleted. |
|
728 |
// It checks if the whole station is free of substations, and if so, the station will be |
|
729 |
// deleted after a little while. |
|
2639 | 730 |
static void DeleteStationIfEmpty(Station* st) |
731 |
{ |
|
0 | 732 |
if (st->facilities == 0) { |
733 |
st->delete_ctr = 0; |
|
28
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
734 |
InvalidateWindow(WC_STATION_LIST, st->owner); |
27
87c8058a69b5
(svn r28) -Fix removing station merged with oilrig, will reset oilrigs ownership
darkvater
parents:
22
diff
changeset
|
735 |
} |
0 | 736 |
} |
737 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
738 |
static int32 ClearTile_Station(TileIndex tile, byte flags); |
977
bcafa4f6550a
(svn r1472) -Fix: correct error message for when trying to build a railroad station over a bus/truck/etc-station.
darkvater
parents:
972
diff
changeset
|
739 |
|
0 | 740 |
// Tries to clear the given area. Returns the cost in case of success. |
741 |
// Or an error code if it failed. |
|
2498
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
742 |
int32 CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invalid_dirs, StationID* station) |
0 | 743 |
{ |
744 |
int32 cost = 0, ret; |
|
745 |
||
746 |
uint tileh; |
|
1335
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1328
diff
changeset
|
747 |
uint z; |
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1328
diff
changeset
|
748 |
int allowed_z = -1; |
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1328
diff
changeset
|
749 |
int flat_z; |
0 | 750 |
|
751 |
BEGIN_TILE_LOOP(tile_cur, w, h, tile) |
|
2639 | 752 |
if (!EnsureNoVehicle(tile_cur)) return CMD_ERROR; |
0 | 753 |
|
754 |
tileh = GetTileSlope(tile_cur, &z); |
|
755 |
||
2085
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
756 |
/* Prohibit building if |
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
757 |
1) The tile is "steep" (i.e. stretches two height levels) |
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
758 |
-OR- |
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
759 |
2) The tile is non-flat if |
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
760 |
a) the player building is an "old-school" AI |
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
761 |
-OR- |
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
762 |
b) the build_on_slopes switch is disabled |
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
763 |
*/ |
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
764 |
if (IsSteepTileh(tileh) || |
2639 | 765 |
((_is_old_ai_player || !_patches.build_on_slopes) && tileh != 0)) { |
0 | 766 |
_error_message = STR_0007_FLAT_LAND_REQUIRED; |
767 |
return CMD_ERROR; |
|
768 |
} |
|
769 |
||
770 |
flat_z = z; |
|
771 |
if (tileh) { |
|
772 |
// need to check so the entrance to the station is not pointing at a slope. |
|
773 |
if ((invalid_dirs&1 && !(tileh & 0xC) && (uint)w_cur == w) || |
|
774 |
(invalid_dirs&2 && !(tileh & 6) && h_cur == 1) || |
|
775 |
(invalid_dirs&4 && !(tileh & 3) && w_cur == 1) || |
|
776 |
(invalid_dirs&8 && !(tileh & 9) && (uint)h_cur == h)) { |
|
777 |
_error_message = STR_0007_FLAT_LAND_REQUIRED; |
|
778 |
return CMD_ERROR; |
|
779 |
} |
|
780 |
cost += _price.terraform; |
|
781 |
flat_z += 8; |
|
782 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
783 |
|
0 | 784 |
// get corresponding flat level and make sure that all parts of the station have the same level. |
785 |
if (allowed_z == -1) { |
|
786 |
// first tile |
|
787 |
allowed_z = flat_z; |
|
788 |
} else if (allowed_z != flat_z) { |
|
789 |
_error_message = STR_0007_FLAT_LAND_REQUIRED; |
|
790 |
return CMD_ERROR; |
|
791 |
} |
|
792 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
793 |
// if station is set, then we have special handling to allow building on top of already existing stations. |
2498
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
794 |
// so station points to INVALID_STATION if we can build on any station. or it points to a station if we're only allowed to build |
0 | 795 |
// 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
|
796 |
if (station != NULL && IsTileType(tile_cur, MP_STATION)) { |
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
|
797 |
if (_m[tile_cur].m5 >= 8) { |
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
|
798 |
_error_message = ClearTile_Station(tile_cur, DC_AUTO); // get error message |
0 | 799 |
return CMD_ERROR; |
800 |
} else { |
|
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
|
801 |
StationID st = _m[tile_cur].m2; |
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
802 |
if (*station == INVALID_STATION) { |
0 | 803 |
*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
|
804 |
} else if (*station != st) { |
0 | 805 |
_error_message = STR_3006_ADJOINS_MORE_THAN_ONE_EXISTING; |
806 |
return CMD_ERROR; |
|
807 |
} |
|
808 |
} |
|
809 |
} else { |
|
810 |
ret = DoCommandByTile(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
2737
f16e0a808897
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2690
diff
changeset
|
811 |
if (CmdFailed(ret)) return CMD_ERROR; |
0 | 812 |
cost += ret; |
813 |
} |
|
814 |
END_TILE_LOOP(tile_cur, w, h, tile) |
|
815 |
||
816 |
return cost; |
|
817 |
} |
|
818 |
||
819 |
static bool CanExpandRailroadStation(Station *st, uint *fin, int direction) |
|
820 |
{ |
|
821 |
uint curw = st->trainst_w, curh = st->trainst_h; |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
822 |
TileIndex tile = fin[0]; |
0 | 823 |
uint w = fin[1]; |
824 |
uint h = fin[2]; |
|
825 |
||
826 |
if (_patches.nonuniform_stations) { |
|
827 |
// 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
|
828 |
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
|
829 |
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
|
830 |
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
|
831 |
curh = max(TileY(st->train_tile) + curh, TileY(tile) + h) - y; |
1981 | 832 |
tile = TileXY(x, y); |
0 | 833 |
} else { |
834 |
// check so the direction is the same |
|
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
|
835 |
if ((_m[st->train_tile].m5 & 1) != direction) { |
1189
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
836 |
_error_message = STR_306D_NONUNIFORM_STATIONS_DISALLOWED; |
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
837 |
return false; |
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
838 |
} |
0 | 839 |
|
840 |
// check if the new station adjoins the old station in either direction |
|
1981 | 841 |
if (curw == w && st->train_tile == tile + TileDiffXY(0, h)) { |
0 | 842 |
// above |
843 |
curh += h; |
|
1981 | 844 |
} else if (curw == w && st->train_tile == tile - TileDiffXY(0, curh)) { |
0 | 845 |
// below |
1981 | 846 |
tile -= TileDiffXY(0, curh); |
0 | 847 |
curh += h; |
1981 | 848 |
} else if (curh == h && st->train_tile == tile + TileDiffXY(w, 0)) { |
0 | 849 |
// to the left |
850 |
curw += w; |
|
1981 | 851 |
} else if (curh == h && st->train_tile == tile - TileDiffXY(curw, 0)) { |
0 | 852 |
// to the right |
1981 | 853 |
tile -= TileDiffXY(curw, 0); |
0 | 854 |
curw += w; |
1189
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
855 |
} else { |
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
856 |
_error_message = STR_306D_NONUNIFORM_STATIONS_DISALLOWED; |
0 | 857 |
return false; |
1189
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
858 |
} |
0 | 859 |
} |
860 |
// make sure the final size is not too big. |
|
1189
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
861 |
if (curw > _patches.station_spread || curh > _patches.station_spread) { |
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
862 |
_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
|
863 |
return false; |
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
864 |
} |
0 | 865 |
|
866 |
// now tile contains the new value for st->train_tile |
|
867 |
// curw, curh contain the new value for width and height |
|
868 |
fin[0] = tile; |
|
869 |
fin[1] = curw; |
|
870 |
fin[2] = curh; |
|
871 |
return true; |
|
872 |
} |
|
873 |
||
536 | 874 |
static inline byte *CreateSingle(byte *layout, int n) |
0 | 875 |
{ |
876 |
int i = n; |
|
877 |
do *layout++ = 0; while (--i); |
|
878 |
layout[((n-1) >> 1)-n] = 2; |
|
879 |
return layout; |
|
880 |
} |
|
881 |
||
536 | 882 |
static inline byte *CreateMulti(byte *layout, int n, byte b) |
0 | 883 |
{ |
884 |
int i = n; |
|
885 |
do *layout++ = b; while (--i); |
|
886 |
if (n > 4) { |
|
887 |
layout[0-n] = 0; |
|
888 |
layout[n-1-n] = 0; |
|
889 |
} |
|
890 |
return layout; |
|
891 |
} |
|
892 |
||
2624
47d7768c6dca
(svn r3166) Constify read-only accesses of custom stations
peter1138
parents:
2617
diff
changeset
|
893 |
static void GetStationLayout(byte *layout, int numtracks, int plat_len, const StationSpec *spec) |
0 | 894 |
{ |
1472
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
895 |
if (spec != NULL && spec->lengths >= plat_len && |
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
896 |
spec->platforms[plat_len - 1] >= numtracks && |
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
897 |
spec->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
|
898 |
/* Custom layout defined, follow it. */ |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
899 |
memcpy(layout, spec->layouts[plat_len - 1][numtracks - 1], |
1472
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
900 |
plat_len * numtracks); |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
901 |
return; |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
902 |
} |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
903 |
|
0 | 904 |
if (plat_len == 1) { |
905 |
CreateSingle(layout, numtracks); |
|
906 |
} else { |
|
2639 | 907 |
if (numtracks & 1) layout = CreateSingle(layout, plat_len); |
908 |
numtracks >>= 1; |
|
0 | 909 |
|
910 |
while (--numtracks >= 0) { |
|
911 |
layout = CreateMulti(layout, plat_len, 4); |
|
912 |
layout = CreateMulti(layout, plat_len, 6); |
|
913 |
} |
|
914 |
} |
|
915 |
} |
|
916 |
||
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
|
917 |
/** Build railroad station |
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
|
918 |
* @param x,y starting position of station dragging/placement |
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1774
diff
changeset
|
919 |
* @param p1 various bitstuffed elements |
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1774
diff
changeset
|
920 |
* - p1 = (bit 0) - orientation (p1 & 1) |
2140
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2133
diff
changeset
|
921 |
* - 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
|
922 |
* - p1 = (bit 16-23) - platform length |
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1774
diff
changeset
|
923 |
* @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
|
924 |
* - p2 = (bit 0- 3) - railtype (p2 & 0xF) |
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
|
925 |
* - p2 = (bit 4) - set for custom station (p2 & 0x10) |
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
|
926 |
* - p2 = (bit 8-..) - custom station id (p2 >> 8) |
0 | 927 |
*/ |
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
|
928 |
int32 CmdBuildRailroadStation(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
0 | 929 |
{ |
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
|
930 |
Station *st; |
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1774
diff
changeset
|
931 |
TileIndex tile_org; |
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
|
932 |
int w_org, h_org; |
0 | 933 |
int32 cost, ret; |
2498
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
934 |
StationID est; |
0 | 935 |
int plat_len, numtracks; |
936 |
int direction; |
|
937 |
uint finalvalues[3]; |
|
938 |
||
939 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
940 |
||
1980
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
941 |
tile_org = TileVirtXY(x, y); |
0 | 942 |
|
943 |
/* 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
|
944 |
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile_org)) return CMD_ERROR; |
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1774
diff
changeset
|
945 |
if (!ValParamRailtype(p2 & 0xF)) return CMD_ERROR; |
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1774
diff
changeset
|
946 |
|
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
|
947 |
/* unpack parameters */ |
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
|
948 |
direction = p1 & 1; |
2140
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2133
diff
changeset
|
949 |
numtracks = GB(p1, 8, 8); |
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2133
diff
changeset
|
950 |
plat_len = GB(p1, 16, 8); |
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1774
diff
changeset
|
951 |
/* w = length, h = num_tracks */ |
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
|
952 |
if (direction) { |
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
|
953 |
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
|
954 |
w_org = numtracks; |
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
|
955 |
} else { |
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
|
956 |
w_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
|
957 |
h_org = numtracks; |
0 | 958 |
} |
959 |
||
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
|
960 |
if (h_org > _patches.station_spread || w_org > _patches.station_spread) return CMD_ERROR; |
92e08797c84b
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
961 |
|
0 | 962 |
// these values are those that will be stored in train_tile and station_platforms |
963 |
finalvalues[0] = tile_org; |
|
964 |
finalvalues[1] = w_org; |
|
965 |
finalvalues[2] = h_org; |
|
966 |
||
967 |
// Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station) |
|
2498
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
968 |
est = INVALID_STATION; |
313
6660bb7b38f1
(svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents:
243
diff
changeset
|
969 |
// If DC_EXEC is in flag, do not want to pass it to CheckFlatLandBelow, because of a nice bug |
6660bb7b38f1
(svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents:
243
diff
changeset
|
970 |
// for detail info, see: https://sourceforge.net/tracker/index.php?func=detail&aid=1029064&group_id=103924&atid=636365 |
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
|
971 |
if (CmdFailed(ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags&~DC_EXEC, 5 << direction, _patches.nonuniform_stations ? &est : NULL))) return CMD_ERROR; |
0 | 972 |
cost = ret + (numtracks * _price.train_station_track + _price.train_station_length) * plat_len; |
973 |
||
974 |
// Make sure there are no similar stations around us. |
|
975 |
st = GetStationAround(tile_org, w_org, h_org, est); |
|
976 |
if (st == CHECK_STATIONS_ERR) return CMD_ERROR; |
|
977 |
||
978 |
// See if there is a deleted station close to us. |
|
979 |
if (st == NULL) { |
|
980 |
st = GetClosestStationFromTile(tile_org, 8, _current_player); |
|
981 |
if (st != NULL && st->facilities) st = NULL; |
|
982 |
} |
|
983 |
||
984 |
if (st != NULL) { |
|
985 |
// Reuse an existing station. |
|
986 |
if (st->owner != OWNER_NONE && st->owner != _current_player) |
|
987 |
return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION); |
|
988 |
||
989 |
if (st->train_tile != 0) { |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
71
diff
changeset
|
990 |
// check if we want to expanding an already existing station? |
2422
914a12dee832
(svn r2948) -Fix: the old AI needs a special flag that triggers all kind of special
truelight
parents:
2395
diff
changeset
|
991 |
if (_is_old_ai_player || !_patches.join_stations) |
0 | 992 |
return_cmd_error(STR_3005_TOO_CLOSE_TO_ANOTHER_RAILROAD); |
1189
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
993 |
if (!CanExpandRailroadStation(st, finalvalues, direction)) |
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
994 |
return CMD_ERROR; |
0 | 995 |
} |
996 |
||
1189
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
997 |
//XXX can't we pack this in the "else" part of the if above? |
2639 | 998 |
if (!CheckStationSpreadOut(st, tile_org, w_org, h_org)) return CMD_ERROR; |
0 | 999 |
} else { |
1000 |
// Create a new station |
|
1001 |
st = AllocateStation(); |
|
2639 | 1002 |
if (st == NULL) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1003 |
|
0 | 1004 |
st->town = ClosestTownFromTile(tile_org, (uint)-1); |
2639 | 1005 |
if (_current_player < MAX_PLAYERS && flags & DC_EXEC) |
0 | 1006 |
SETBIT(st->town->have_ratings, _current_player); |
1007 |
||
2639 | 1008 |
if (!GenerateStationName(st, tile_org, 0)) return CMD_ERROR; |
1009 |
||
1010 |
if (flags & DC_EXEC) StationInitialize(st, tile_org); |
|
0 | 1011 |
} |
1012 |
||
1013 |
if (flags & DC_EXEC) { |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1014 |
TileIndexDiff tile_delta; |
0 | 1015 |
byte *layout_ptr; |
1551
eb05e6a90e67
(svn r2055) -CodeChange: Begun introducting StationID
celestar
parents:
1527
diff
changeset
|
1016 |
StationID station_index = st->index; |
2624
47d7768c6dca
(svn r3166) Constify read-only accesses of custom stations
peter1138
parents:
2617
diff
changeset
|
1017 |
const StationSpec *statspec; |
2824
a7a9d3239884
(svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents:
2817
diff
changeset
|
1018 |
Track track; |
0 | 1019 |
|
313
6660bb7b38f1
(svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents:
243
diff
changeset
|
1020 |
// Now really clear the land below the station |
6660bb7b38f1
(svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents:
243
diff
changeset
|
1021 |
// It should never return CMD_ERROR.. but you never know ;) |
6660bb7b38f1
(svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents:
243
diff
changeset
|
1022 |
// (a bit strange function name for it, but it really does clear the land, when DC_EXEC is in flags) |
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
|
1023 |
if (CmdFailed(CheckFlatLandBelow(tile_org, w_org, h_org, flags, 5 << direction, _patches.nonuniform_stations ? &est : NULL))) return CMD_ERROR; |
313
6660bb7b38f1
(svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents:
243
diff
changeset
|
1024 |
|
0 | 1025 |
st->train_tile = finalvalues[0]; |
1026 |
if (!st->facilities) st->xy = finalvalues[0]; |
|
1027 |
st->facilities |= FACIL_TRAIN; |
|
1028 |
st->owner = _current_player; |
|
1029 |
||
1030 |
st->trainst_w = finalvalues[1]; |
|
1031 |
st->trainst_h = finalvalues[2]; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1032 |
|
71
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
65
diff
changeset
|
1033 |
st->build_date = _date; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1034 |
|
1981 | 1035 |
tile_delta = direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
2824
a7a9d3239884
(svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents:
2817
diff
changeset
|
1036 |
track = direction ? TRACK_DIAG2 : TRACK_DIAG1; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1037 |
|
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1038 |
statspec = (p2 & 0x10) != 0 ? GetCustomStation(STAT_CLASS_DFLT, p2 >> 8) : NULL; |
0 | 1039 |
layout_ptr = alloca(numtracks * plat_len); |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1040 |
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
|
1041 |
|
0 | 1042 |
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
|
1043 |
TileIndex tile = tile_org; |
0 | 1044 |
int w = plat_len; |
1045 |
do { |
|
1046 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1047 |
ModifyTile(tile, |
0 | 1048 |
MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT | |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1049 |
MP_MAP2 | MP_MAP5 | MP_MAP3LO | MP_MAP3HI, |
0 | 1050 |
station_index, /* map2 parameter */ |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1051 |
p2 & 0xFF, /* map3lo parameter */ |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1052 |
p2 >> 8, /* map3hi parameter */ |
0 | 1053 |
(*layout_ptr++) + direction /* map5 parameter */ |
1054 |
); |
|
1055 |
||
1056 |
tile += tile_delta; |
|
1057 |
} while (--w); |
|
2824
a7a9d3239884
(svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents:
2817
diff
changeset
|
1058 |
SetSignalsOnBothDir(tile_org, track); |
1981 | 1059 |
tile_org += tile_delta ^ TileDiffXY(1, 1); // perpendicular to tile_delta |
0 | 1060 |
} while (--numtracks); |
1061 |
||
1062 |
UpdateStationVirtCoordDirty(st); |
|
1063 |
UpdateStationAcceptance(st, false); |
|
1064 |
InvalidateWindow(WC_STATION_LIST, st->owner); |
|
1065 |
} |
|
1066 |
||
1067 |
return cost; |
|
1068 |
} |
|
1069 |
||
2805
b6098e7ca457
(svn r3353) Simplify the automatic length adjustment algorithm for replacing trains: Use the length of the train before the replacement as reference length
tron
parents:
2793
diff
changeset
|
1070 |
static bool TileBelongsToRailStation(const Station *st, TileIndex tile) |
b6098e7ca457
(svn r3353) Simplify the automatic length adjustment algorithm for replacing trains: Use the length of the train before the replacement as reference length
tron
parents:
2793
diff
changeset
|
1071 |
{ |
b6098e7ca457
(svn r3353) Simplify the automatic length adjustment algorithm for replacing trains: Use the length of the train before the replacement as reference length
tron
parents:
2793
diff
changeset
|
1072 |
return IsTileType(tile, MP_STATION) && _m[tile].m2 == st->index && _m[tile].m5 < 8; |
b6098e7ca457
(svn r3353) Simplify the automatic length adjustment algorithm for replacing trains: Use the length of the train before the replacement as reference length
tron
parents:
2793
diff
changeset
|
1073 |
} |
b6098e7ca457
(svn r3353) Simplify the automatic length adjustment algorithm for replacing trains: Use the length of the train before the replacement as reference length
tron
parents:
2793
diff
changeset
|
1074 |
|
0 | 1075 |
static void MakeRailwayStationAreaSmaller(Station *st) |
1076 |
{ |
|
1077 |
uint w = st->trainst_w; |
|
1078 |
uint h = st->trainst_h; |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1079 |
TileIndex tile = st->train_tile; |
0 | 1080 |
uint i; |
1081 |
||
1082 |
restart: |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1083 |
|
0 | 1084 |
// too small? |
1085 |
if (w != 0 && h != 0) { |
|
1086 |
// check the left side, x = constant, y changes |
|
1981 | 1087 |
for (i = 0; !TileBelongsToRailStation(st, tile + TileDiffXY(0, i));) { |
0 | 1088 |
// the left side is unused? |
1981 | 1089 |
if (++i == h) { |
1090 |
tile += TileDiffXY(1, 0); |
|
1091 |
w--; |
|
1092 |
goto restart; |
|
1093 |
} |
|
1094 |
} |
|
0 | 1095 |
|
1096 |
// check the right side, x = constant, y changes |
|
1981 | 1097 |
for (i = 0; !TileBelongsToRailStation(st, tile + TileDiffXY(w - 1, i));) { |
0 | 1098 |
// the right side is unused? |
1981 | 1099 |
if (++i == h) { |
1100 |
w--; |
|
1101 |
goto restart; |
|
1102 |
} |
|
1103 |
} |
|
0 | 1104 |
|
1105 |
// check the upper side, y = constant, x changes |
|
1981 | 1106 |
for (i = 0; !TileBelongsToRailStation(st, tile + TileDiffXY(i, 0));) { |
0 | 1107 |
// the left side is unused? |
1981 | 1108 |
if (++i == w) { |
1109 |
tile += TileDiffXY(0, 1); |
|
1110 |
h--; |
|
1111 |
goto restart; |
|
1112 |
} |
|
1113 |
} |
|
0 | 1114 |
|
1115 |
// check the lower side, y = constant, x changes |
|
1981 | 1116 |
for (i = 0; !TileBelongsToRailStation(st, tile + TileDiffXY(i, h - 1));) { |
0 | 1117 |
// the left side is unused? |
1981 | 1118 |
if (++i == w) { |
1119 |
h--; |
|
1120 |
goto restart; |
|
1121 |
} |
|
1122 |
} |
|
0 | 1123 |
} else { |
1124 |
tile = 0; |
|
1125 |
} |
|
1126 |
||
1127 |
st->trainst_w = w; |
|
1128 |
st->trainst_h = h; |
|
1129 |
st->train_tile = tile; |
|
1130 |
} |
|
1131 |
||
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1132 |
/** Remove a single tile from a railroad station. |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1133 |
* This allows for custom-built station with holes and weird layouts |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1134 |
* @param x,y tile coordinates to remove |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1135 |
* @param p1 unused |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1136 |
* @param p2 unused |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1137 |
*/ |
0 | 1138 |
int32 CmdRemoveFromRailroadStation(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
1139 |
{ |
|
1980
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
1140 |
TileIndex tile = TileVirtXY(x, y); |
0 | 1141 |
Station *st; |
1142 |
||
889
7f8630bfea41
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
863
diff
changeset
|
1143 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
7f8630bfea41
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
863
diff
changeset
|
1144 |
|
0 | 1145 |
// make sure the specified tile belongs to the current player, and that it is a railroad station. |
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
|
1146 |
if (!IsTileType(tile, MP_STATION) || _m[tile].m5 >= 8 || !_patches.nonuniform_stations) return CMD_ERROR; |
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
|
1147 |
st = GetStation(_m[tile].m2); |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
123
diff
changeset
|
1148 |
if (_current_player != OWNER_WATER && (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile))) return CMD_ERROR; |
0 | 1149 |
|
1150 |
// if we reached here, it means we can actually delete it. do that. |
|
1151 |
if (flags & DC_EXEC) { |
|
2824
a7a9d3239884
(svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents:
2817
diff
changeset
|
1152 |
Track track = HASBIT(_m[tile].m5, 0) ? TRACK_DIAG2 : TRACK_DIAG1; |
0 | 1153 |
DoClearSquare(tile); |
2824
a7a9d3239884
(svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents:
2817
diff
changeset
|
1154 |
SetSignalsOnBothDir(tile, track); |
0 | 1155 |
// now we need to make the "spanned" area of the railway station smaller if we deleted something at the edges. |
1156 |
// we also need to adjust train_tile. |
|
1157 |
MakeRailwayStationAreaSmaller(st); |
|
1158 |
||
1159 |
// if we deleted the whole station, delete the train facility. |
|
1160 |
if (st->train_tile == 0) { |
|
1161 |
st->facilities &= ~FACIL_TRAIN; |
|
1162 |
UpdateStationVirtCoordDirty(st); |
|
1163 |
DeleteStationIfEmpty(st); |
|
1164 |
} |
|
1165 |
} |
|
1166 |
return _price.remove_rail_station; |
|
1167 |
} |
|
1168 |
||
1169 |
// determine the number of platforms for the station |
|
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2427
diff
changeset
|
1170 |
uint GetStationPlatforms(const Station *st, TileIndex tile) |
0 | 1171 |
{ |
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
|
1172 |
TileIndex t; |
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
1173 |
TileIndexDiff delta; |
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
1174 |
int dir; |
2639 | 1175 |
uint len; |
0 | 1176 |
assert(TileBelongsToRailStation(st, tile)); |
1177 |
||
1178 |
len = 0; |
|
2639 | 1179 |
dir = _m[tile].m5 & 1; |
1981 | 1180 |
delta = dir ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
0 | 1181 |
|
1182 |
// find starting tile.. |
|
1183 |
t = tile; |
|
2639 | 1184 |
do { |
1185 |
t -= delta; |
|
1186 |
len++; |
|
1187 |
} while (TileBelongsToRailStation(st, t) && (_m[t].m5 & 1) == dir); |
|
0 | 1188 |
|
1189 |
// find ending tile |
|
1190 |
t = tile; |
|
2639 | 1191 |
do { |
1192 |
t += delta; |
|
1193 |
len++; |
|
1194 |
} while (TileBelongsToRailStation(st, t) && (_m[t].m5 & 1) == dir); |
|
0 | 1195 |
|
1196 |
return len - 1; |
|
1197 |
} |
|
1198 |
||
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
|
1199 |
static const RealSpriteGroup *ResolveStationSpriteGroup(const SpriteGroup *spg, const Station *st) |
413
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1200 |
{ |
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
|
1201 |
switch (spg->type) { |
413
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1202 |
case SGT_REAL: |
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
|
1203 |
return &spg->g.real; |
413
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1204 |
|
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1205 |
case SGT_DETERMINISTIC: { |
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
|
1206 |
const DeterministicSpriteGroup *dsg = &spg->g.determ; |
1477 | 1207 |
SpriteGroup *target; |
413
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1208 |
int value = -1; |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1209 |
|
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1210 |
if ((dsg->variable >> 6) == 0) { |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1211 |
/* General property */ |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1212 |
value = GetDeterministicSpriteValue(dsg->variable); |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1213 |
|
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1214 |
} else { |
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
|
1215 |
if (st == NULL) { |
433
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1216 |
/* We are in a build dialog of something, |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1217 |
* and we are checking for something undefined. |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1218 |
* That means we should get the first target |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1219 |
* (NOT the default one). */ |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1220 |
if (dsg->num_ranges > 0) { |
2488
cbe3d6b60c27
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2469
diff
changeset
|
1221 |
target = dsg->ranges[0].group; |
433
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1222 |
} else { |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1223 |
target = dsg->default_group; |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1224 |
} |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1225 |
return ResolveStationSpriteGroup(target, NULL); |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1226 |
} |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
1227 |
|
413
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1228 |
/* Station-specific property. */ |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1229 |
if (dsg->var_scope == VSG_SCOPE_PARENT) { |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1230 |
/* TODO: Town structure. */ |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1231 |
|
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1232 |
} else /* VSG_SELF */ { |
1472
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
1233 |
if (dsg->variable == 0x40 || dsg->variable == 0x41) { |
413
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1234 |
/* FIXME: This is ad hoc only |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1235 |
* for waypoints. */ |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1236 |
value = 0x01010000; |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1237 |
} else { |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1238 |
/* TODO: Only small fraction done. */ |
426
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
413
diff
changeset
|
1239 |
// TTDPatch runs on little-endian arch; |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
413
diff
changeset
|
1240 |
// Variable is 0x70 + offset in the TTD's station structure |
413
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1241 |
switch (dsg->variable - 0x70) { |
2631
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1242 |
case 0x80: value = st->facilities; break; |
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1243 |
case 0x81: value = st->airport_type; break; |
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1244 |
case 0x82: value = st->truck_stops->status; break; |
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1245 |
case 0x83: value = st->bus_stops->status; break; |
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1246 |
case 0x86: value = st->airport_flags & 0xFFFF; break; |
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1247 |
case 0x87: value = st->airport_flags & 0xFF; break; |
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1248 |
case 0x8A: value = st->build_date; break; |
413
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1249 |
} |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1250 |
} |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1251 |
} |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1252 |
} |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1253 |
|
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1254 |
target = value != -1 ? EvalDeterministicSpriteGroup(dsg, value) : dsg->default_group; |
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
|
1255 |
return ResolveStationSpriteGroup(target, st); |
413
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1256 |
} |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1257 |
|
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1258 |
default: |
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
438
diff
changeset
|
1259 |
case SGT_RANDOMIZED: |
413
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1260 |
error("I don't know how to handle random spritegroups yet!"); |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1261 |
return NULL; |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1262 |
} |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1263 |
} |
36afcda97345
(svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents:
408
diff
changeset
|
1264 |
|
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
|
1265 |
uint32 GetCustomStationRelocation(const StationSpec *spec, const Station *st, byte ctype) |
403
bfb365c74e80
(svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents:
400
diff
changeset
|
1266 |
{ |
2488
cbe3d6b60c27
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2469
diff
changeset
|
1267 |
const RealSpriteGroup *rsg = ResolveStationSpriteGroup(spec->spritegroup[ctype], st); |
408
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
1268 |
|
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
1269 |
if (rsg->sprites_per_set != 0) { |
2489
88827d8ae517
(svn r3015) -NewGRF: Add a new sprite group result type, and support loading of callbacks results within random and "real" groups. (Not fully supported yet.)
peter1138
parents:
2488
diff
changeset
|
1270 |
if (rsg->loading_count != 0) return rsg->loading[0]->g.result.result; |
88827d8ae517
(svn r3015) -NewGRF: Add a new sprite group result type, and support loading of callbacks results within random and "real" groups. (Not fully supported yet.)
peter1138
parents:
2488
diff
changeset
|
1271 |
|
88827d8ae517
(svn r3015) -NewGRF: Add a new sprite group result type, and support loading of callbacks results within random and "real" groups. (Not fully supported yet.)
peter1138
parents:
2488
diff
changeset
|
1272 |
if (rsg->loaded_count != 0) return rsg->loaded[0]->g.result.result; |
403
bfb365c74e80
(svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents:
400
diff
changeset
|
1273 |
} |
408
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
1274 |
|
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
1275 |
error("Custom station 0x%08x::0x%02x has no sprites associated.", |
1472
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
1276 |
spec->grfid, spec->localidx); |
452
520e4ed6945d
(svn r662) [newgrf] Moved grfspecial.c to newgrf.c/newgrf.h
dominik
parents:
449
diff
changeset
|
1277 |
/* This is what gets subscribed of dtss->image in newgrf.c, |
408
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
1278 |
* so it's probably kinda "default offset". Try to use it as |
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
1279 |
* emergency measure. */ |
2517
b90693227193
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2504
diff
changeset
|
1280 |
return SPR_RAIL_PLATFORM_Y_FRONT; |
389
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
384
diff
changeset
|
1281 |
} |
2d394eeba5e5
(svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents:
384
diff
changeset
|
1282 |
|
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
123
diff
changeset
|
1283 |
static int32 RemoveRailroadStation(Station *st, TileIndex tile, uint32 flags) |
0 | 1284 |
{ |
1285 |
int w,h; |
|
1286 |
int32 cost; |
|
1287 |
||
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
123
diff
changeset
|
1288 |
/* if there is flooding and non-uniform stations are enabled, remove platforms tile by tile */ |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
123
diff
changeset
|
1289 |
if (_current_player == OWNER_WATER && _patches.nonuniform_stations) |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
123
diff
changeset
|
1290 |
return DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_REMOVE_FROM_RAILROAD_STATION); |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
123
diff
changeset
|
1291 |
|
0 | 1292 |
/* Current player owns the station? */ |
1293 |
if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) |
|
1294 |
return CMD_ERROR; |
|
1295 |
||
1296 |
/* determine width and height of platforms */ |
|
1297 |
tile = st->train_tile; |
|
1298 |
w = st->trainst_w; |
|
1299 |
h = st->trainst_h; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1300 |
|
0 | 1301 |
assert(w != 0 && h != 0); |
1302 |
||
1303 |
/* cost is area * constant */ |
|
1304 |
cost = w*h*_price.remove_rail_station; |
|
1305 |
||
1306 |
/* clear all areas of the station */ |
|
1307 |
do { |
|
1308 |
int w_bak = w; |
|
1309 |
do { |
|
1310 |
// for nonuniform stations, only remove tiles that are actually train station tiles |
|
1311 |
if (TileBelongsToRailStation(st, tile)) { |
|
1312 |
if (!EnsureNoVehicle(tile)) |
|
1313 |
return CMD_ERROR; |
|
2824
a7a9d3239884
(svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents:
2817
diff
changeset
|
1314 |
if (flags & DC_EXEC) { |
a7a9d3239884
(svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents:
2817
diff
changeset
|
1315 |
Track track = HASBIT(_m[tile].m5, 0) ? TRACK_DIAG2 : TRACK_DIAG1; |
0 | 1316 |
DoClearSquare(tile); |
2824
a7a9d3239884
(svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents:
2817
diff
changeset
|
1317 |
SetSignalsOnBothDir(tile, track); |
a7a9d3239884
(svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents:
2817
diff
changeset
|
1318 |
} |
0 | 1319 |
} |
1981 | 1320 |
tile += TileDiffXY(1, 0); |
0 | 1321 |
} while (--w); |
1322 |
w = w_bak; |
|
1981 | 1323 |
tile += TileDiffXY(-w, 1); |
0 | 1324 |
} while (--h); |
1325 |
||
1326 |
if (flags & DC_EXEC) { |
|
1327 |
st->train_tile = 0; |
|
1328 |
st->facilities &= ~FACIL_TRAIN; |
|
1329 |
||
1330 |
UpdateStationVirtCoordDirty(st); |
|
1331 |
DeleteStationIfEmpty(st); |
|
1332 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1333 |
|
0 | 1334 |
return cost; |
1335 |
} |
|
1336 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1337 |
int32 DoConvertStationRail(TileIndex tile, uint totype, bool exec) |
0 | 1338 |
{ |
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
|
1339 |
const Station *st = GetStation(_m[tile].m2); |
0 | 1340 |
if (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile)) return CMD_ERROR; |
1341 |
||
1342 |
// tile is not a railroad station? |
|
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
|
1343 |
if (_m[tile].m5 >= 8) return CMD_ERROR; |
0 | 1344 |
|
1345 |
// tile is already of requested type? |
|
2493
d834d0c1502a
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2489
diff
changeset
|
1346 |
if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR; |
0 | 1347 |
|
1348 |
if (exec) { |
|
1349 |
// change type. |
|
2493
d834d0c1502a
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2489
diff
changeset
|
1350 |
SB(_m[tile].m3, 0, 4, totype); |
0 | 1351 |
MarkTileDirtyByTile(tile); |
1352 |
} |
|
1353 |
||
1354 |
return _price.build_rail >> 1; |
|
1355 |
} |
|
1356 |
||
2752 | 1357 |
static void FindRoadStationSpot(bool truck_station, Station* st, RoadStop*** currstop, RoadStop** prev) |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1358 |
{ |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1359 |
RoadStop **primary_stop; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1360 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1361 |
primary_stop = (truck_station) ? &st->truck_stops : &st->bus_stops; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1362 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1363 |
if (*primary_stop == NULL) { |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1364 |
//we have no station of the type yet, so write a "primary station" |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1365 |
//(the one at st->foo_stops) |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1366 |
*currstop = primary_stop; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1367 |
} else { |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1368 |
//there are stops already, so append to the end of the list |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1369 |
*prev = *primary_stop; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1370 |
*currstop = &(*primary_stop)->next; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1371 |
while (**currstop != NULL) { |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1372 |
*prev = (*prev)->next; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1373 |
*currstop = &(**currstop)->next; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1374 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1375 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1376 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1377 |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1378 |
/** Build a bus station |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1379 |
* @param x,y coordinates to build bus station at |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1380 |
* @param p1 busstop entrance direction (0 through 3), where 0 is NW, 1 is NE, etc. |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1381 |
* @param p2 0 for Bus stops, 1 for truck stops |
0 | 1382 |
*/ |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1383 |
int32 CmdBuildRoadStop(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
0 | 1384 |
{ |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1385 |
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
|
1386 |
RoadStop *road_stop; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1387 |
RoadStop **currstop; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1388 |
RoadStop *prev = NULL; |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1389 |
TileIndex tile; |
0 | 1390 |
int32 cost; |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1391 |
bool type = !!p2; |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1392 |
|
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1393 |
/* Saveguard the parameters */ |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1394 |
if (p1 > 3) return CMD_ERROR; |
0 | 1395 |
|
1396 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
1397 |
||
1980
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
1398 |
tile = TileVirtXY(x, y); |
0 | 1399 |
|
1400 |
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) |
|
1401 |
return CMD_ERROR; |
|
1402 |
||
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1403 |
cost = CheckFlatLandBelow(tile, 1, 1, flags, 1 << p1, NULL); |
2737
f16e0a808897
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2690
diff
changeset
|
1404 |
if (CmdFailed(cost)) return CMD_ERROR; |
0 | 1405 |
|
1406 |
st = GetStationAround(tile, 1, 1, -1); |
|
2639 | 1407 |
if (st == CHECK_STATIONS_ERR) return CMD_ERROR; |
0 | 1408 |
|
1409 |
/* Find a station close to us */ |
|
1410 |
if (st == NULL) { |
|
1411 |
st = GetClosestStationFromTile(tile, 8, _current_player); |
|
2639 | 1412 |
if (st != NULL && st->facilities) st = NULL; |
0 | 1413 |
} |
1414 |
||
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1415 |
//give us a road stop in the list, and check if something went wrong |
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
1416 |
road_stop = AllocateRoadStop(); |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1417 |
if (road_stop == NULL) |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1418 |
return_cmd_error( (type) ? STR_3008B_TOO_MANY_TRUCK_STOPS : STR_3008A_TOO_MANY_BUS_STOPS); |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1419 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1420 |
if ( st != NULL && (GetNumRoadStops(st, RS_BUS) + GetNumRoadStops(st, RS_TRUCK) >= ROAD_STOP_LIMIT)) |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1421 |
return_cmd_error( (type) ? STR_3008B_TOO_MANY_TRUCK_STOPS : STR_3008A_TOO_MANY_BUS_STOPS); |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1422 |
|
0 | 1423 |
if (st != NULL) { |
1424 |
if (st->owner != OWNER_NONE && st->owner != _current_player) |
|
1425 |
return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1426 |
|
0 | 1427 |
if (!CheckStationSpreadOut(st, tile, 1, 1)) |
1428 |
return CMD_ERROR; |
|
1429 |
||
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1430 |
FindRoadStationSpot(type, st, &currstop, &prev); |
0 | 1431 |
} else { |
1432 |
Town *t; |
|
1433 |
||
1434 |
st = AllocateStation(); |
|
2639 | 1435 |
if (st == NULL) return CMD_ERROR; |
0 | 1436 |
|
1437 |
st->town = t = ClosestTownFromTile(tile, (uint)-1); |
|
1438 |
||
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1439 |
FindRoadStationSpot(type, st, &currstop, &prev); |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1440 |
|
0 | 1441 |
if (_current_player < MAX_PLAYERS && flags&DC_EXEC) |
1442 |
SETBIT(t->have_ratings, _current_player); |
|
1443 |
||
1444 |
st->sign.width_1 = 0; |
|
1445 |
||
2639 | 1446 |
if (!GenerateStationName(st, tile, 0)) return CMD_ERROR; |
1447 |
||
1448 |
if (flags & DC_EXEC) StationInitialize(st, tile); |
|
0 | 1449 |
} |
1450 |
||
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1451 |
cost += (type) ? _price.build_truck_station : _price.build_bus_station; |
0 | 1452 |
|
1453 |
if (flags & DC_EXEC) { |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1454 |
//point to the correct item in the _busstops or _truckstops array |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1455 |
*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
|
1456 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1457 |
//initialize an empty station |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1458 |
InitializeRoadStop(road_stop, prev, tile, st->index); |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1459 |
(*currstop)->type = type; |
0 | 1460 |
if (!st->facilities) st->xy = tile; |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1461 |
st->facilities |= (type) ? FACIL_TRUCK_STOP : FACIL_BUS_STOP; |
0 | 1462 |
st->owner = _current_player; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1463 |
|
71
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
65
diff
changeset
|
1464 |
st->build_date = _date; |
0 | 1465 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1466 |
ModifyTile(tile, |
0 | 1467 |
MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT | |
1468 |
MP_MAP2 | MP_MAP5 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1469 |
st->index, /* map2 parameter */ |
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
|
1470 |
/* XXX - Truck stops have 0x43 _m[].m5 value + direction |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1471 |
* XXX - Bus stops have a _map5 value of 0x47 + direction */ |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1472 |
((type) ? 0x43 : 0x47) + p1 /* map5 parameter */ |
0 | 1473 |
); |
1474 |
||
1475 |
UpdateStationVirtCoordDirty(st); |
|
1476 |
UpdateStationAcceptance(st, false); |
|
1477 |
InvalidateWindow(WC_STATION_LIST, st->owner); |
|
1478 |
} |
|
1479 |
return cost; |
|
1480 |
} |
|
1481 |
||
1482 |
// Remove a bus station |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1483 |
static int32 RemoveRoadStop(Station *st, uint32 flags, TileIndex tile) |
0 | 1484 |
{ |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1485 |
RoadStop **primary_stop; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1486 |
RoadStop *cur_stop; |
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
|
1487 |
bool is_truck = _m[tile].m5 < 0x47; |
0 | 1488 |
|
1489 |
if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) |
|
1490 |
return CMD_ERROR; |
|
1491 |
||
2639 | 1492 |
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
|
1493 |
primary_stop = &st->truck_stops; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1494 |
cur_stop = GetRoadStopByTile(tile, RS_TRUCK); |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1495 |
} else { |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1496 |
primary_stop = &st->bus_stops; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1497 |
cur_stop = GetRoadStopByTile(tile, RS_BUS); |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1498 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1499 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1500 |
assert(cur_stop != NULL); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1501 |
|
0 | 1502 |
if (!EnsureNoVehicle(tile)) |
1503 |
return CMD_ERROR; |
|
1504 |
||
1505 |
if (flags & DC_EXEC) { |
|
2639 | 1506 |
uint i; |
0 | 1507 |
DoClearSquare(tile); |
1508 |
||
1706
70c2d2ad472a
(svn r2210) - Fix: When a road-station is deleted, also delete the assigned slots of all vehicles headed to that station. This fixes an assertion, thanks go to Tron for finding the cause.
Darkvater
parents:
1685
diff
changeset
|
1509 |
/* Clear all vehicles destined for this station */ |
70c2d2ad472a
(svn r2210) - Fix: When a road-station is deleted, also delete the assigned slots of all vehicles headed to that station. This fixes an assertion, thanks go to Tron for finding the cause.
Darkvater
parents:
1685
diff
changeset
|
1510 |
for (i = 0; i != NUM_SLOTS; i++) { |
70c2d2ad472a
(svn r2210) - Fix: When a road-station is deleted, also delete the assigned slots of all vehicles headed to that station. This fixes an assertion, thanks go to Tron for finding the cause.
Darkvater
parents:
1685
diff
changeset
|
1511 |
if (cur_stop->slot[i] != INVALID_SLOT) { |
70c2d2ad472a
(svn r2210) - Fix: When a road-station is deleted, also delete the assigned slots of all vehicles headed to that station. This fixes an assertion, thanks go to Tron for finding the cause.
Darkvater
parents:
1685
diff
changeset
|
1512 |
Vehicle *v = GetVehicle(cur_stop->slot[i]); |
70c2d2ad472a
(svn r2210) - Fix: When a road-station is deleted, also delete the assigned slots of all vehicles headed to that station. This fixes an assertion, thanks go to Tron for finding the cause.
Darkvater
parents:
1685
diff
changeset
|
1513 |
ClearSlot(v, v->u.road.slot); |
70c2d2ad472a
(svn r2210) - Fix: When a road-station is deleted, also delete the assigned slots of all vehicles headed to that station. This fixes an assertion, thanks go to Tron for finding the cause.
Darkvater
parents:
1685
diff
changeset
|
1514 |
} |
70c2d2ad472a
(svn r2210) - Fix: When a road-station is deleted, also delete the assigned slots of all vehicles headed to that station. This fixes an assertion, thanks go to Tron for finding the cause.
Darkvater
parents:
1685
diff
changeset
|
1515 |
} |
70c2d2ad472a
(svn r2210) - Fix: When a road-station is deleted, also delete the assigned slots of all vehicles headed to that station. This fixes an assertion, thanks go to Tron for finding the cause.
Darkvater
parents:
1685
diff
changeset
|
1516 |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1517 |
cur_stop->used = false; |
2639 | 1518 |
if (cur_stop->prev != NULL) cur_stop->prev->next = cur_stop->next; |
1519 |
if (cur_stop->next != NULL) cur_stop->next->prev = cur_stop->prev; |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1520 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1521 |
//we only had one stop left |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1522 |
if (cur_stop->next == NULL && cur_stop->prev == NULL) { |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1523 |
//so we remove ALL stops |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1524 |
*primary_stop = NULL; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1525 |
st->facilities &= (is_truck) ? ~FACIL_TRUCK_STOP : ~FACIL_BUS_STOP; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1526 |
} else if (cur_stop == *primary_stop) { |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1527 |
//removed the first stop in the list |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1528 |
//need to set the primary element to the next stop |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1529 |
*primary_stop = (*primary_stop)->next; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1530 |
} |
0 | 1531 |
|
1532 |
UpdateStationVirtCoordDirty(st); |
|
1533 |
DeleteStationIfEmpty(st); |
|
1534 |
} |
|
1535 |
||
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1536 |
return (is_truck) ? _price.remove_truck_station : _price.remove_bus_station; |
0 | 1537 |
} |
1538 |
||
1539 |
||
1540 |
||
1541 |
// FIXME -- need to move to its corresponding Airport variable |
|
1542 |
// Country Airfield (small) |
|
1543 |
static const byte _airport_map5_tiles_country[] = { |
|
1544 |
54, 53, 52, 65, |
|
1545 |
58, 57, 56, 55, |
|
1546 |
64, 63, 63, 62 |
|
1547 |
}; |
|
1548 |
||
1549 |
// City Airport (large) |
|
1550 |
static const byte _airport_map5_tiles_town[] = { |
|
2549 | 1551 |
31, 9, 33, 9, 9, 32, |
1552 |
27, 36, 29, 34, 8, 10, |
|
0 | 1553 |
30, 11, 35, 13, 20, 21, |
1554 |
51, 12, 14, 17, 19, 28, |
|
1555 |
38, 13, 15, 16, 18, 39, |
|
1556 |
26, 22, 23, 24, 25, 26 |
|
1557 |
}; |
|
1558 |
||
1559 |
// Metropolitain Airport (large) - 2 runways |
|
1560 |
static const byte _airport_map5_tiles_metropolitan[] = { |
|
2549 | 1561 |
31, 9, 33, 9, 9, 32, |
1562 |
27, 36, 29, 34, 8, 10, |
|
1563 |
30, 11, 35, 13, 20, 21, |
|
1564 |
102, 8, 8, 8, 8, 28, |
|
1565 |
83, 84, 84, 84, 84, 83, |
|
1566 |
26, 23, 23, 23, 23, 26 |
|
0 | 1567 |
}; |
1568 |
||
1569 |
// International Airport (large) - 2 runways |
|
1570 |
static const byte _airport_map5_tiles_international[] = { |
|
2549 | 1571 |
88, 89, 89, 89, 89, 89, 88, |
1572 |
51, 8, 8, 8, 8, 8, 32, |
|
1573 |
30, 8, 11, 27, 11, 8, 10, |
|
0 | 1574 |
32, 8, 11, 27, 11, 8, 114, |
1575 |
87, 8, 11, 85, 11, 8, 114, |
|
2549 | 1576 |
87, 8, 8, 8, 8, 8, 90, |
1577 |
26, 23, 23, 23, 23, 23, 26 |
|
0 | 1578 |
}; |
1579 |
||
1580 |
// Heliport |
|
1581 |
static const byte _airport_map5_tiles_heliport[] = { |
|
1582 |
66, |
|
1583 |
}; |
|
1584 |
||
1585 |
static const byte * const _airport_map5_tiles[] = { |
|
1586 |
_airport_map5_tiles_country, // Country Airfield (small) |
|
1587 |
_airport_map5_tiles_town, // City Airport (large) |
|
1588 |
_airport_map5_tiles_heliport, // Heliport |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1589 |
_airport_map5_tiles_metropolitan, // Metropolitain Airport (large) |
0 | 1590 |
_airport_map5_tiles_international, // International Airport (xlarge) |
1591 |
}; |
|
1592 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1593 |
/** Place an Airport. |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1594 |
* @param x,y tile coordinates where airport will be built |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1595 |
* @param p1 airport type, @see airport.h |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1596 |
* @param p2 unused |
0 | 1597 |
*/ |
1598 |
int32 CmdBuildAirport(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
1599 |
{ |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1600 |
TileIndex tile; |
0 | 1601 |
Town *t; |
1602 |
Station *st; |
|
1603 |
int32 cost; |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1604 |
int w, h; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1605 |
bool airport_upgrade = true; |
0 | 1606 |
|
1607 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
1608 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1609 |
/* Check if a valid, buildable airport was chosen for construction */ |
1876
95c95857ec7b
(svn r2382) - Fix: Check the airport type when building an airport
Darkvater
parents:
1840
diff
changeset
|
1610 |
if (p1 > lengthof(_airport_map5_tiles) || !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
|
1611 |
|
1980
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
1612 |
tile = TileVirtXY(x, y); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1613 |
|
0 | 1614 |
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) |
1615 |
return CMD_ERROR; |
|
1616 |
||
1617 |
t = ClosestTownFromTile(tile, (uint)-1); |
|
1618 |
||
1619 |
/* Check if local auth refuses a new airport */ |
|
1620 |
{ |
|
1621 |
uint num = 0; |
|
1622 |
FOR_ALL_STATIONS(st) { |
|
1623 |
if (st->xy != 0 && st->town == t && st->facilities&FACIL_AIRPORT && st->airport_type != AT_OILRIG) |
|
1624 |
num++; |
|
1625 |
} |
|
1626 |
if (num >= 2) { |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1627 |
SetDParam(0, t->index); |
0 | 1628 |
return_cmd_error(STR_2035_LOCAL_AUTHORITY_REFUSES); |
1629 |
} |
|
1630 |
} |
|
1631 |
||
1632 |
w = _airport_size_x[p1]; |
|
1633 |
h = _airport_size_y[p1]; |
|
1634 |
||
1635 |
cost = CheckFlatLandBelow(tile, w, h, flags, 0, NULL); |
|
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
|
1636 |
if (CmdFailed(cost)) return CMD_ERROR; |
0 | 1637 |
|
1638 |
st = GetStationAround(tile, w, h, -1); |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1639 |
if (st == CHECK_STATIONS_ERR) return CMD_ERROR; |
0 | 1640 |
|
1641 |
/* Find a station close to us */ |
|
1642 |
if (st == NULL) { |
|
1643 |
st = GetClosestStationFromTile(tile, 8, _current_player); |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1644 |
if (st != NULL && st->facilities) st = NULL; |
0 | 1645 |
} |
1646 |
||
1647 |
if (st != NULL) { |
|
1648 |
if (st->owner != OWNER_NONE && st->owner != _current_player) |
|
1649 |
return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1650 |
|
0 | 1651 |
if (!CheckStationSpreadOut(st, tile, 1, 1)) |
1652 |
return CMD_ERROR; |
|
1653 |
||
1654 |
if (st->airport_tile != 0) |
|
1655 |
return_cmd_error(STR_300D_TOO_CLOSE_TO_ANOTHER_AIRPORT); |
|
1656 |
} else { |
|
1657 |
airport_upgrade = false; |
|
1658 |
||
1659 |
st = AllocateStation(); |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1660 |
if (st == NULL) return CMD_ERROR; |
0 | 1661 |
|
1265
0430e635b116
(svn r1769) Don't compute the same value twice, remove one function call
tron
parents:
1247
diff
changeset
|
1662 |
st->town = t; |
0 | 1663 |
|
2639 | 1664 |
if (_current_player < MAX_PLAYERS && flags & DC_EXEC) |
0 | 1665 |
SETBIT(t->have_ratings, _current_player); |
1666 |
||
1667 |
st->sign.width_1 = 0; |
|
1668 |
||
1669 |
// if airport type equals Heliport then generate |
|
1670 |
// type 5 name, which is heliport, otherwise airport names (1) |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1671 |
if (!GenerateStationName(st, tile, (p1 == AT_HELIPORT) ? 5 : 1)) |
0 | 1672 |
return CMD_ERROR; |
1673 |
||
1674 |
if (flags & DC_EXEC) |
|
1675 |
StationInitialize(st, tile); |
|
1676 |
} |
|
1677 |
||
1678 |
cost += _price.build_airport * w * h; |
|
1679 |
||
1680 |
if (flags & DC_EXEC) { |
|
701 | 1681 |
const AirportFTAClass *afc = GetAirport(p1); |
1682 |
||
0 | 1683 |
st->owner = _current_player; |
2425
99e1e8430a28
(svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents:
2422
diff
changeset
|
1684 |
if (IsLocalPlayer() && afc->nof_depots != 0) |
99e1e8430a28
(svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents:
2422
diff
changeset
|
1685 |
_last_built_aircraft_depot_tile = tile + ToTileIndexDiff(afc->airport_depots[0]); |
0 | 1686 |
|
1687 |
st->airport_tile = tile; |
|
1688 |
if (!st->facilities) st->xy = tile; |
|
1689 |
st->facilities |= FACIL_AIRPORT; |
|
1690 |
st->airport_type = (byte)p1; |
|
1691 |
st->airport_flags = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1692 |
|
71
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
65
diff
changeset
|
1693 |
st->build_date = _date; |
0 | 1694 |
|
2639 | 1695 |
/* if airport was demolished while planes were en-route to it, the |
1696 |
* positions can no longer be the same (v->u.air.pos), since different |
|
1697 |
* airports have different indexes. So update all planes en-route to this |
|
1698 |
* airport. Only update if |
|
1699 |
* 1. airport is upgraded |
|
1700 |
* 2. airport is added to existing station (unfortunately unavoideable) |
|
1701 |
*/ |
|
2549 | 1702 |
if (airport_upgrade) UpdateAirplanesOnNewStation(st); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1703 |
|
0 | 1704 |
{ |
1705 |
const byte *b = _airport_map5_tiles[p1]; |
|
2549 | 1706 |
|
1707 |
BEGIN_TILE_LOOP(tile_cur,w,h,tile) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1708 |
ModifyTile(tile_cur, |
0 | 1709 |
MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT | |
1710 |
MP_MAP2 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR | MP_MAP5, |
|
1711 |
st->index, *b++); |
|
2549 | 1712 |
} END_TILE_LOOP(tile_cur,w,h,tile) |
0 | 1713 |
} |
1714 |
||
1715 |
UpdateStationVirtCoordDirty(st); |
|
1716 |
UpdateStationAcceptance(st, false); |
|
1717 |
InvalidateWindow(WC_STATION_LIST, st->owner); |
|
1718 |
} |
|
1719 |
||
1720 |
return cost; |
|
1721 |
} |
|
1722 |
||
1723 |
static int32 RemoveAirport(Station *st, uint32 flags) |
|
1724 |
{ |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1725 |
TileIndex tile; |
0 | 1726 |
int w,h; |
1727 |
int32 cost; |
|
1728 |
||
1729 |
if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) |
|
1730 |
return CMD_ERROR; |
|
1731 |
||
1732 |
tile = st->airport_tile; |
|
1733 |
||
1734 |
w = _airport_size_x[st->airport_type]; |
|
1735 |
h = _airport_size_y[st->airport_type]; |
|
1736 |
||
1737 |
cost = w * h * _price.remove_airport; |
|
1738 |
||
1739 |
{ |
|
1740 |
BEGIN_TILE_LOOP(tile_cur,w,h,tile) |
|
1741 |
if (!EnsureNoVehicle(tile_cur)) |
|
1742 |
return CMD_ERROR; |
|
1743 |
||
1744 |
if (flags & DC_EXEC) { |
|
1745 |
DeleteAnimatedTile(tile_cur); |
|
1746 |
DoClearSquare(tile_cur); |
|
1747 |
} |
|
1748 |
END_TILE_LOOP(tile_cur, w,h,tile) |
|
1749 |
} |
|
1750 |
||
1751 |
if (flags & DC_EXEC) { |
|
700 | 1752 |
const AirportFTAClass *afc = GetAirport(st->airport_type); |
1753 |
uint i; |
|
1754 |
||
1755 |
for (i = 0; i < afc->nof_depots; ++i) |
|
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1756 |
DeleteWindowById(WC_VEHICLE_DEPOT, tile + ToTileIndexDiff(afc->airport_depots[i])); |
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
|
1757 |
|
0 | 1758 |
st->airport_tile = 0; |
1759 |
st->facilities &= ~FACIL_AIRPORT; |
|
1760 |
||
1761 |
UpdateStationVirtCoordDirty(st); |
|
1762 |
DeleteStationIfEmpty(st); |
|
1763 |
} |
|
1764 |
||
1765 |
return cost; |
|
1766 |
} |
|
1767 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1768 |
/** Build a buoy. |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1769 |
* @param x,y tile coordinates of bouy construction |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1770 |
* @param p1 unused |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1771 |
* @param p2 unused |
0 | 1772 |
*/ |
1773 |
int32 CmdBuildBuoy(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
1774 |
{ |
|
1775 |
TileInfo ti; |
|
1776 |
Station *st; |
|
1777 |
||
1778 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
1779 |
||
1780 |
FindLandscapeHeight(&ti, x, y); |
|
1781 |
||
1782 |
if (ti.type != MP_WATER || ti.tileh != 0 || ti.map5 != 0 || ti.tile == 0) |
|
1783 |
return_cmd_error(STR_304B_SITE_UNSUITABLE); |
|
1784 |
||
1785 |
st = AllocateStation(); |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1786 |
if (st == NULL) return CMD_ERROR; |
0 | 1787 |
|
1788 |
st->town = ClosestTownFromTile(ti.tile, (uint)-1); |
|
1789 |
st->sign.width_1 = 0; |
|
1790 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1791 |
if (!GenerateStationName(st, ti.tile, 4)) return CMD_ERROR; |
0 | 1792 |
|
1793 |
if (flags & DC_EXEC) { |
|
1794 |
StationInitialize(st, ti.tile); |
|
1795 |
st->dock_tile = ti.tile; |
|
1796 |
st->facilities |= FACIL_DOCK; |
|
1751
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1706
diff
changeset
|
1797 |
/* 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
|
1798 |
* braindead.. */ |
0 | 1799 |
st->had_vehicle_of_type |= HVOT_BUOY; |
1800 |
st->owner = OWNER_NONE; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1801 |
|
71
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
65
diff
changeset
|
1802 |
st->build_date = _date; |
0 | 1803 |
|
1804 |
ModifyTile(ti.tile, |
|
1805 |
MP_SETTYPE(MP_STATION) | |
|
1806 |
MP_MAP2 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR | MP_MAPOWNER | MP_MAP5, |
|
1807 |
st->index, /* map2 */ |
|
1808 |
OWNER_NONE, /* map_owner */ |
|
1809 |
0x52 /* map5 */ |
|
1810 |
); |
|
1811 |
||
1812 |
UpdateStationVirtCoordDirty(st); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1813 |
|
0 | 1814 |
UpdateStationAcceptance(st, false); |
1815 |
InvalidateWindow(WC_STATION_LIST, st->owner); |
|
1816 |
} |
|
1817 |
||
1818 |
return _price.build_dock; |
|
1819 |
} |
|
1820 |
||
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
|
1821 |
/* Checks if any ship is servicing the buoy specified. Returns yes or no */ |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1822 |
static bool CheckShipsOnBuoy(Station *st) |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1823 |
{ |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1824 |
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
|
1825 |
FOR_ALL_VEHICLES(v) { |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1826 |
if (v->type == VEH_Ship) { |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1827 |
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
|
1828 |
FOR_VEHICLE_ORDERS(v, 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
|
1829 |
if (order->type == OT_GOTO_STATION && order->station == st->index) { |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1830 |
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
|
1831 |
} |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1832 |
} |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1833 |
} |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1834 |
} |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1835 |
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
|
1836 |
} |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1837 |
|
0 | 1838 |
static int32 RemoveBuoy(Station *st, uint32 flags) |
1839 |
{ |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1840 |
TileIndex tile; |
0 | 1841 |
|
1842 |
if (_current_player >= MAX_PLAYERS) { |
|
1843 |
/* XXX: strange stuff */ |
|
1844 |
return_cmd_error(INVALID_STRING_ID); |
|
1845 |
} |
|
1846 |
||
1847 |
tile = st->dock_tile; |
|
1848 |
||
2639 | 1849 |
if (CheckShipsOnBuoy(st)) return_cmd_error(STR_BUOY_IS_IN_USE); |
1850 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
|
0 | 1851 |
|
1852 |
if (flags & DC_EXEC) { |
|
1853 |
st->dock_tile = 0; |
|
1751
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1706
diff
changeset
|
1854 |
/* 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
|
1855 |
* braindead.. */ |
0 | 1856 |
st->facilities &= ~FACIL_DOCK; |
1857 |
st->had_vehicle_of_type &= ~HVOT_BUOY; |
|
1858 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1859 |
ModifyTile(tile, |
0 | 1860 |
MP_SETTYPE(MP_WATER) | |
1861 |
MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR, |
|
1862 |
OWNER_WATER, /* map_owner */ |
|
1863 |
0 /* map5 */ |
|
1864 |
); |
|
1865 |
||
1866 |
UpdateStationVirtCoordDirty(st); |
|
1867 |
DeleteStationIfEmpty(st); |
|
1868 |
} |
|
1869 |
||
1870 |
return _price.remove_truck_station; |
|
1871 |
} |
|
1872 |
||
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1873 |
static const TileIndexDiffC _dock_tileoffs_chkaround[] = { |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1874 |
{-1, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1875 |
{ 0, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1876 |
{ 0, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1877 |
{ 0, -1} |
0 | 1878 |
}; |
1879 |
static const byte _dock_w_chk[4] = { 2,1,2,1 }; |
|
1880 |
static const byte _dock_h_chk[4] = { 1,2,1,2 }; |
|
1881 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1882 |
/** Build a dock/haven. |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1883 |
* @param x,y tile coordinates where dock will be built |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1884 |
* @param p1 unused |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1885 |
* @param p2 unused |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1886 |
*/ |
0 | 1887 |
int32 CmdBuildDock(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
1888 |
{ |
|
1889 |
TileInfo ti; |
|
1890 |
int direction; |
|
1891 |
int32 cost; |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1892 |
TileIndex tile, tile_cur; |
0 | 1893 |
Station *st; |
1894 |
||
1895 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
1896 |
||
1897 |
FindLandscapeHeight(&ti, x, y); |
|
1898 |
||
1899 |
if ((direction=0,ti.tileh) != 3 && |
|
1900 |
(direction++,ti.tileh) != 9 && |
|
1901 |
(direction++,ti.tileh) != 12 && |
|
1902 |
(direction++,ti.tileh) != 6) |
|
1903 |
return_cmd_error(STR_304B_SITE_UNSUITABLE); |
|
1904 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1905 |
if (!EnsureNoVehicle(ti.tile)) return CMD_ERROR; |
0 | 1906 |
|
1907 |
cost = DoCommandByTile(ti.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1908 |
if (CmdFailed(cost)) return CMD_ERROR; |
0 | 1909 |
|
900 | 1910 |
tile_cur = (tile=ti.tile) + TileOffsByDir(direction); |
0 | 1911 |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1912 |
if (!EnsureNoVehicle(tile_cur)) return CMD_ERROR; |
0 | 1913 |
|
1914 |
FindLandscapeHeightByTile(&ti, tile_cur); |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1915 |
if (ti.tileh != 0 || ti.type != MP_WATER) return_cmd_error(STR_304B_SITE_UNSUITABLE); |
0 | 1916 |
|
1917 |
cost = DoCommandByTile(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1918 |
if (CmdFailed(cost)) return CMD_ERROR; |
0 | 1919 |
|
900 | 1920 |
tile_cur = tile_cur + TileOffsByDir(direction); |
0 | 1921 |
FindLandscapeHeightByTile(&ti, tile_cur); |
1922 |
if (ti.tileh != 0 || ti.type != MP_WATER) |
|
1923 |
return_cmd_error(STR_304B_SITE_UNSUITABLE); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1924 |
|
0 | 1925 |
/* middle */ |
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1926 |
st = GetStationAround( |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1927 |
tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]), |
0 | 1928 |
_dock_w_chk[direction], _dock_h_chk[direction], -1); |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1929 |
if (st == CHECK_STATIONS_ERR) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1930 |
|
0 | 1931 |
/* Find a station close to us */ |
1932 |
if (st == NULL) { |
|
1933 |
st = GetClosestStationFromTile(tile, 8, _current_player); |
|
1934 |
if (st!=NULL && st->facilities) st = NULL; |
|
1935 |
} |
|
1936 |
||
1937 |
if (st != NULL) { |
|
1938 |
if (st->owner != OWNER_NONE && st->owner != _current_player) |
|
1939 |
return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1940 |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1941 |
if (!CheckStationSpreadOut(st, tile, 1, 1)) return CMD_ERROR; |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1942 |
|
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1943 |
if (st->dock_tile != 0) return_cmd_error(STR_304C_TOO_CLOSE_TO_ANOTHER_DOCK); |
0 | 1944 |
} else { |
1945 |
Town *t; |
|
1946 |
||
1947 |
st = AllocateStation(); |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1948 |
if (st == NULL) return CMD_ERROR; |
0 | 1949 |
|
1950 |
st->town = t = ClosestTownFromTile(tile, (uint)-1); |
|
1951 |
||
1952 |
if (_current_player < MAX_PLAYERS && flags&DC_EXEC) |
|
1953 |
SETBIT(t->have_ratings, _current_player); |
|
1954 |
||
1955 |
st->sign.width_1 = 0; |
|
1956 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1957 |
if (!GenerateStationName(st, tile, 3)) return CMD_ERROR; |
0 | 1958 |
|
2639 | 1959 |
if (flags & DC_EXEC) StationInitialize(st, tile); |
0 | 1960 |
} |
1961 |
||
1962 |
if (flags & DC_EXEC) { |
|
1963 |
st->dock_tile = tile; |
|
1964 |
if (!st->facilities) st->xy = tile; |
|
1965 |
st->facilities |= FACIL_DOCK; |
|
1966 |
st->owner = _current_player; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1967 |
|
71
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
65
diff
changeset
|
1968 |
st->build_date = _date; |
0 | 1969 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1970 |
ModifyTile(tile, |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1971 |
MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT | |
0 | 1972 |
MP_MAP2 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR | |
1973 |
MP_MAP5, |
|
1974 |
st->index, |
|
1975 |
direction + 0x4C); |
|
1976 |
||
900 | 1977 |
ModifyTile(tile + TileOffsByDir(direction), |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1978 |
MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT | |
0 | 1979 |
MP_MAP2 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR | |
1980 |
MP_MAP5, |
|
1981 |
st->index, |
|
1982 |
(direction&1) + 0x50); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1983 |
|
0 | 1984 |
UpdateStationVirtCoordDirty(st); |
1985 |
UpdateStationAcceptance(st, false); |
|
1986 |
InvalidateWindow(WC_STATION_LIST, st->owner); |
|
1987 |
} |
|
1988 |
return _price.build_dock; |
|
1989 |
} |
|
1990 |
||
1991 |
static int32 RemoveDock(Station *st, uint32 flags) |
|
1992 |
{ |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1993 |
TileIndex tile1; |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1994 |
TileIndex tile2; |
0 | 1995 |
|
2639 | 1996 |
if (!CheckOwnership(st->owner)) return CMD_ERROR; |
0 | 1997 |
|
1998 |
tile1 = st->dock_tile; |
|
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
|
1999 |
tile2 = tile1 + TileOffsByDir(_m[tile1].m5 - 0x4C); |
0 | 2000 |
|
2639 | 2001 |
if (!EnsureNoVehicle(tile1)) return CMD_ERROR; |
2002 |
if (!EnsureNoVehicle(tile2)) return CMD_ERROR; |
|
0 | 2003 |
|
2004 |
if (flags & DC_EXEC) { |
|
2005 |
DoClearSquare(tile1); |
|
2006 |
||
2007 |
// convert the water tile to water. |
|
2008 |
ModifyTile(tile2, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, OWNER_WATER, 0); |
|
2009 |
||
2010 |
st->dock_tile = 0; |
|
2011 |
st->facilities &= ~FACIL_DOCK; |
|
2012 |
||
2013 |
UpdateStationVirtCoordDirty(st); |
|
2014 |
DeleteStationIfEmpty(st); |
|
2015 |
} |
|
2016 |
||
2017 |
return _price.remove_dock; |
|
2018 |
} |
|
2019 |
||
2020 |
#include "table/station_land.h" |
|
2021 |
||
2022 |
||
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2023 |
extern uint16 _custom_sprites_base; |
0 | 2024 |
|
2025 |
static void DrawTile_Station(TileInfo *ti) |
|
2026 |
{ |
|
2027 |
uint32 image_or_modificator; |
|
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2028 |
uint32 image; |
0 | 2029 |
const DrawTileSeqStruct *dtss; |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2030 |
const DrawTileSprites *t = NULL; |
2520
75eb66d6e371
(svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents:
2517
diff
changeset
|
2031 |
RailType railtype = GB(_m[ti->tile].m3, 0, 4); |
2254
72f8883ff3ac
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2213
diff
changeset
|
2032 |
const RailtypeInfo *rti = GetRailTypeInfo(railtype); |
72f8883ff3ac
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2213
diff
changeset
|
2033 |
SpriteID offset; |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2034 |
uint32 relocation = 0; |
0 | 2035 |
|
2036 |
{ |
|
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
|
2037 |
PlayerID owner = GetTileOwner(ti->tile); |
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
2038 |
image_or_modificator = PALETTE_TO_GREY; /* NOTE: possible bug in ttd here? */ |
2639 | 2039 |
if (owner < MAX_PLAYERS) image_or_modificator = PLAYER_SPRITE_COLOR(owner); |
0 | 2040 |
} |
2041 |
||
2042 |
// don't show foundation for docks (docks are between 76 (0x4C) and 81 (0x51)) |
|
2043 |
if (ti->tileh != 0 && (ti->map5 < 0x4C || ti->map5 > 0x51)) |
|
2044 |
DrawFoundation(ti, ti->tileh); |
|
2045 |
||
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
|
2046 |
if (_m[ti->tile].m3 & 0x10) { |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2047 |
// look for customization |
2624
47d7768c6dca
(svn r3166) Constify read-only accesses of custom stations
peter1138
parents:
2617
diff
changeset
|
2048 |
const StationSpec *statspec = GetCustomStation(STAT_CLASS_DFLT, _m[ti->tile].m4); |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2049 |
|
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2050 |
//debug("Cust-o-mized %p", statspec); |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2051 |
|
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2052 |
if (statspec != NULL) { |
2630 | 2053 |
const Station* st = GetStation(_m[ti->tile].m2); |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2054 |
|
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2055 |
relocation = GetCustomStationRelocation(statspec, st, 0); |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2056 |
//debug("Relocation %d", relocation); |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2057 |
t = &statspec->renderdata[ti->map5]; |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2058 |
} |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2059 |
} |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2060 |
|
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2061 |
if (t == NULL) t = &_station_display_datas[ti->map5]; |
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
|
2062 |
|
bf1303e754ff
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
2063 |
image = t->ground_sprite; |
2639 | 2064 |
if (image & PALETTE_MODIFIER_COLOR) image |= image_or_modificator; |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2065 |
|
2008
c9d6585c96c8
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1981
diff
changeset
|
2066 |
// For custom sprites, there's no railtype-based pitching. |
2254
72f8883ff3ac
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2213
diff
changeset
|
2067 |
offset = (image & SPRITE_MASK) < _custom_sprites_base ? rti->total_offset : railtype; |
72f8883ff3ac
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2213
diff
changeset
|
2068 |
image += offset; |
2008
c9d6585c96c8
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1981
diff
changeset
|
2069 |
|
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2070 |
// station_land array has been increased from 82 elements to 114 |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2071 |
// but this is something else. If AI builds station with 114 it looks all weird |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2072 |
DrawGroundSprite(image); |
0 | 2073 |
|
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
|
2074 |
foreach_draw_tile_seq(dtss, t->seq) { |
2008
c9d6585c96c8
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1981
diff
changeset
|
2075 |
image = dtss->image + relocation; |
2254
72f8883ff3ac
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2213
diff
changeset
|
2076 |
image += offset; |
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
|
2077 |
if (_display_opt & DO_TRANS_BUILDINGS) { |
2148
47ba4a1b1c3b
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
2078 |
MAKE_TRANSPARENT(image); |
497
2d6d31173813
(svn r787) Invert the sense of the DO_TRANS_BUILDINGS flag to be consistent with its own name and all other DO_* flags.
tron
parents:
494
diff
changeset
|
2079 |
} else { |
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
2080 |
if (image & PALETTE_MODIFIER_COLOR) image |= image_or_modificator; |
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
|
2081 |
} |
bf1303e754ff
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
2082 |
|
0 | 2083 |
if ((byte)dtss->delta_z != 0x80) { |
2084 |
AddSortableSpriteToDraw(image, ti->x + dtss->delta_x, ti->y + dtss->delta_y, dtss->width, dtss->height, dtss->unk, ti->z + dtss->delta_z); |
|
2085 |
} else { |
|
2086 |
AddChildSpriteScreen(image, dtss->delta_x, dtss->delta_y); |
|
2087 |
} |
|
2088 |
} |
|
2089 |
} |
|
2090 |
||
2520
75eb66d6e371
(svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents:
2517
diff
changeset
|
2091 |
void StationPickerDrawSprite(int x, int y, RailType railtype, int image) |
0 | 2092 |
{ |
2093 |
uint32 ormod, img; |
|
2094 |
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
|
2095 |
const DrawTileSprites *t; |
2254
72f8883ff3ac
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2213
diff
changeset
|
2096 |
const RailtypeInfo *rti = GetRailTypeInfo(railtype); |
0 | 2097 |
|
2098 |
ormod = PLAYER_SPRITE_COLOR(_local_player); |
|
2099 |
||
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
|
2100 |
t = &_station_display_datas[image]; |
bf1303e754ff
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
2101 |
|
bf1303e754ff
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
2102 |
img = t->ground_sprite; |
2639 | 2103 |
if (img & PALETTE_MODIFIER_COLOR) img |= ormod; |
2254
72f8883ff3ac
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2213
diff
changeset
|
2104 |
DrawSprite(img + rti->total_offset, x, y); |
0 | 2105 |
|
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
|
2106 |
foreach_draw_tile_seq(dtss, t->seq) { |
0 | 2107 |
Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z); |
2254
72f8883ff3ac
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2213
diff
changeset
|
2108 |
DrawSprite((dtss->image | ormod) + rti->total_offset, x + pt.x, y + pt.y); |
0 | 2109 |
} |
2110 |
} |
|
2111 |
||
2537 | 2112 |
static uint GetSlopeZ_Station(const TileInfo* ti) |
0 | 2113 |
{ |
2549 | 2114 |
return (ti->tileh != 0) ? ti->z + 8 : ti->z; |
0 | 2115 |
} |
2116 |
||
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
|
2117 |
static uint GetSlopeTileh_Station(const TileInfo *ti) |
39 | 2118 |
{ |
2119 |
return 0; |
|
2120 |
} |
|
2121 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2122 |
static void GetAcceptedCargo_Station(TileIndex tile, AcceptedCargo ac) |
0 | 2123 |
{ |
2124 |
/* not used */ |
|
2125 |
} |
|
2126 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2127 |
static void GetTileDesc_Station(TileIndex tile, TileDesc *td) |
0 | 2128 |
{ |
2129 |
byte m5; |
|
2130 |
StringID str; |
|
2131 |
||
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
|
2132 |
td->owner = GetTileOwner(tile); |
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
|
2133 |
td->build_date = GetStation(_m[tile].m2)->build_date; |
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
|
2134 |
|
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
|
2135 |
m5 = _m[tile].m5; |
0 | 2136 |
(str=STR_305E_RAILROAD_STATION, m5 < 8) || |
2137 |
(str=STR_305F_AIRCRAFT_HANGAR, m5==32 || m5==45) || // hangars |
|
2138 |
(str=STR_3060_AIRPORT, m5 < 0x43 || (m5 >= 83 && m5 <= 114)) || |
|
2139 |
(str=STR_3061_TRUCK_LOADING_AREA, m5 < 0x47) || |
|
2140 |
(str=STR_3062_BUS_STATION, m5 < 0x4B) || |
|
2141 |
(str=STR_4807_OIL_RIG, m5 == 0x4B) || |
|
2142 |
(str=STR_3063_SHIP_DOCK, m5 != 0x52) || |
|
2143 |
(str=STR_3069_BUOY, true); |
|
2144 |
td->str = str; |
|
2145 |
} |
|
2146 |
||
2147 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2148 |
static uint32 GetTileTrackStatus_Station(TileIndex tile, TransportType mode) |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2149 |
{ |
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
|
2150 |
uint i = _m[tile].m5; |
0 | 2151 |
uint j = 0; |
2152 |
||
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
|
2153 |
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
|
2154 |
case TRANSPORT_RAIL: |
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
|
2155 |
if (i < 8) { |
2630 | 2156 |
static const byte tile_track_status_rail[] = { 1, 2, 1, 2, 1, 2, 1, 2 }; |
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
|
2157 |
j = tile_track_status_rail[i]; |
6020f9143b17
(svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents:
1024
diff
changeset
|
2158 |
} |
6020f9143b17
(svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents:
1024
diff
changeset
|
2159 |
j += (j << 8); |
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
|
2160 |
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
|
2161 |
|
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
|
2162 |
case TRANSPORT_WATER: |
6020f9143b17
(svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents:
1024
diff
changeset
|
2163 |
// buoy is coded as a station, it is always on open water |
6020f9143b17
(svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents:
1024
diff
changeset
|
2164 |
// (0x3F, all tracks available) |
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
|
2165 |
if (i == 0x52) j = 0x3F; |
6020f9143b17
(svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents:
1024
diff
changeset
|
2166 |
j += (j << 8); |
6020f9143b17
(svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents:
1024
diff
changeset
|
2167 |
break; |
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
|
2168 |
|
6020f9143b17
(svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents:
1024
diff
changeset
|
2169 |
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
|
2170 |
break; |
0 | 2171 |
} |
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
|
2172 |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
2173 |
return j; |
0 | 2174 |
} |
2175 |
||
2660 | 2176 |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2177 |
static void TileLoop_Station(TileIndex tile) |
0 | 2178 |
{ |
2660 | 2179 |
// FIXME -- GetTileTrackStatus_Station -> animated stationtiles |
2180 |
// hardcoded.....not good |
|
2181 |
switch (_m[tile].m5) { |
|
2182 |
case 0x27: // large big airport |
|
2183 |
case 0x3A: // flag small airport |
|
2184 |
case 0x5A: // radar international airport |
|
2185 |
case 0x66: // radar metropolitan airport |
|
2186 |
AddAnimatedTile(tile); |
|
2187 |
break; |
|
2188 |
||
2189 |
case 0x4B: // oilrig (station part) |
|
2190 |
case 0x52: // bouy |
|
2191 |
TileLoop_Water(tile); |
|
2192 |
break; |
|
2193 |
||
2194 |
default: break; |
|
2195 |
} |
|
0 | 2196 |
} |
2197 |
||
2198 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2199 |
static void AnimateTile_Station(TileIndex tile) |
0 | 2200 |
{ |
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
|
2201 |
byte m5 = _m[tile].m5; |
0 | 2202 |
//FIXME -- AnimateTile_Station -> not nice code, lots of things double |
2203 |
// again hardcoded...was a quick hack |
|
2204 |
||
2205 |
// turning radar / windsack on airport |
|
2206 |
if (m5 >= 39 && m5 <= 50) { // turning radar (39 - 50) |
|
2207 |
if (_tick_counter & 3) |
|
2208 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2209 |
|
0 | 2210 |
if (++m5 == 50+1) |
2211 |
m5 = 39; |
|
2212 |
||
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
|
2213 |
_m[tile].m5 = m5; |
0 | 2214 |
MarkTileDirtyByTile(tile); |
2215 |
//added - begin |
|
2216 |
} else if (m5 >= 90 && m5 <= 113) { // turning radar with ground under it (different fences) (90 - 101 | 102 - 113) |
|
2217 |
if (_tick_counter & 3) |
|
2218 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2219 |
|
0 | 2220 |
m5++; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2221 |
|
0 | 2222 |
if (m5 == 101+1) {m5 = 90;} // radar with fences in south |
2223 |
else if (m5 == 113+1) {m5 = 102;} // radar with fences in north |
|
2224 |
||
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
|
2225 |
_m[tile].m5 = m5; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2226 |
MarkTileDirtyByTile(tile); |
0 | 2227 |
//added - end |
2228 |
} else if (m5 >= 0x3A && m5 <= 0x3D) { // windsack (58 - 61) |
|
2229 |
if (_tick_counter & 1) |
|
2230 |
return; |
|
2231 |
||
2232 |
if (++m5 == 0x3D+1) |
|
2233 |
m5 = 0x3A; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2234 |
|
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
|
2235 |
_m[tile].m5 = m5; |
0 | 2236 |
MarkTileDirtyByTile(tile); |
2237 |
} |
|
2238 |
} |
|
2239 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2240 |
static void ClickTile_Station(TileIndex tile) |
0 | 2241 |
{ |
2242 |
// 0x20 - hangar large airport (32) |
|
2243 |
// 0x41 - hangar small airport (65) |
|
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
|
2244 |
if (_m[tile].m5 == 32 || _m[tile].m5 == 65) { |
0 | 2245 |
ShowAircraftDepotWindow(tile); |
2246 |
} else { |
|
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
|
2247 |
ShowStationViewWindow(_m[tile].m2); |
0 | 2248 |
} |
2249 |
} |
|
2250 |
||
2251 |
static const byte _enter_station_speedtable[12] = { |
|
2252 |
215, 195, 175, 155, 135, 115, 95, 75, 55, 35, 15, 0 |
|
2253 |
}; |
|
2254 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2255 |
static uint32 VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y) |
0 | 2256 |
{ |
1551
eb05e6a90e67
(svn r2055) -CodeChange: Begun introducting StationID
celestar
parents:
1527
diff
changeset
|
2257 |
StationID station_id; |
0 | 2258 |
byte dir; |
2259 |
||
2260 |
if (v->type == VEH_Train) { |
|
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2671
diff
changeset
|
2261 |
if (IS_BYTE_INSIDE(_m[tile].m5, 0, 8) && IsFrontEngine(v) && |
1685
b9cfe79393c0
(svn r2189) Introduce and use IsCompatibleTrainStationTile()
tron
parents:
1672
diff
changeset
|
2262 |
!IsCompatibleTrainStationTile(tile + TileOffsByDir(v->direction >> 1), tile)) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2263 |
|
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
|
2264 |
station_id = _m[tile].m2; |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
2265 |
if ((!(v->current_order.flags & OF_NON_STOP) && !_patches.new_nonstop) || |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
2266 |
(v->current_order.type == OT_GOTO_STATION && v->current_order.station == station_id)) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
2267 |
if (!(_patches.new_nonstop && v->current_order.flags & OF_NON_STOP) && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
2268 |
v->current_order.type != OT_LEAVESTATION && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
2269 |
v->last_station_visited != station_id) { |
0 | 2270 |
x &= 0xF; |
2271 |
y &= 0xF; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2272 |
|
0 | 2273 |
dir = v->direction & 6; |
2274 |
if (dir & 2) intswap(x,y); |
|
2275 |
if (y == 8) { |
|
2639 | 2276 |
if (dir != 2 && dir != 4) x = ~x & 0xF; |
0 | 2277 |
if (x == 12) return 2 | (station_id << 8); /* enter station */ |
2278 |
if (x < 12) { |
|
2639 | 2279 |
uint16 spd; |
2280 |
||
0 | 2281 |
v->vehstatus |= VS_TRAIN_SLOWING; |
2282 |
spd = _enter_station_speedtable[x]; |
|
2639 | 2283 |
if (spd < v->cur_speed) v->cur_speed = spd; |
0 | 2284 |
} |
2285 |
} |
|
2286 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2287 |
} |
0 | 2288 |
} |
2289 |
} else if (v->type == VEH_Road) { |
|
2671
457c6cdbf9e7
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2660
diff
changeset
|
2290 |
if (v->u.road.state < 16 && !HASBIT(v->u.road.state, 2) && v->u.road.frame == 0) { |
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
|
2291 |
if (IS_BYTE_INSIDE(_m[tile].m5, 0x43, 0x4B)) { |
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
|
2292 |
/* 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
|
2293 |
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
|
2294 |
|
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
|
2295 |
/* rs->status bits 0 and 1 describe current the two parking spots. |
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
|
2296 |
* 0 means occupied, 1 means free. */ |
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
|
2297 |
|
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
|
2298 |
// Check if station is busy or if there are no free bays. |
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
|
2299 |
if (HASBIT(rs->status, 7) || GB(rs->status, 0, 2) == 0) |
0 | 2300 |
return 8; |
2301 |
||
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
|
2302 |
v->u.road.state += 32; |
457c6cdbf9e7
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2660
diff
changeset
|
2303 |
|
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
|
2304 |
// if the first bay is free, allocate that, else the second bay must be free. |
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
|
2305 |
if (HASBIT(rs->status, 0)) { |
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
|
2306 |
CLRBIT(rs->status, 0); |
0 | 2307 |
} else { |
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
|
2308 |
CLRBIT(rs->status, 1); |
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
|
2309 |
v->u.road.state += 2; |
0 | 2310 |
} |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2311 |
|
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
|
2312 |
// mark the station as busy |
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
|
2313 |
SETBIT(rs->status, 7); |
0 | 2314 |
} |
2315 |
} |
|
2316 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2317 |
|
0 | 2318 |
return 0; |
2319 |
} |
|
2320 |
||
2213
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
2321 |
/** Removes a station from the list. |
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
2322 |
* This is done by setting the .xy property to 0, |
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
2323 |
* and doing some maintenance, especially clearing vehicle orders. |
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
2324 |
* Aircraft-Hangar orders need special treatment here, as the hangars are |
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
2325 |
* actually part of a station (tiletype is STATION), but the order type |
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
2326 |
* is OT_GOTO_DEPOT. |
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
2327 |
* @param st Station to be deleted |
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
2328 |
*/ |
0 | 2329 |
static void DeleteStation(Station *st) |
2330 |
{ |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
2331 |
Order order; |
1551
eb05e6a90e67
(svn r2055) -CodeChange: Begun introducting StationID
celestar
parents:
1527
diff
changeset
|
2332 |
StationID index; |
2213
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
2333 |
Vehicle *v; |
0 | 2334 |
st->xy = 0; |
2335 |
||
2336 |
DeleteName(st->string_id); |
|
2337 |
MarkStationDirty(st); |
|
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
2338 |
_global_station_sort_dirty = true; // delete station, remove sign |
65
f9f866bc609c
(svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents:
59
diff
changeset
|
2339 |
InvalidateWindowClasses(WC_STATION_LIST); |
0 | 2340 |
|
2341 |
index = st->index; |
|
2342 |
DeleteWindowById(WC_STATION_VIEW, index); |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1012
diff
changeset
|
2343 |
|
2213
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
2344 |
//Now delete all orders that go to the station |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
2345 |
order.type = OT_GOTO_STATION; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
2346 |
order.station = index; |
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1012
diff
changeset
|
2347 |
DeleteDestinationFromVehicleOrder(order); |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1012
diff
changeset
|
2348 |
|
2213
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
2349 |
//And do the same with aircraft that have the station as a hangar-stop |
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
2350 |
FOR_ALL_VEHICLES(v) { |
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
2351 |
bool invalidate = false; |
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
2352 |
if (v->type == VEH_Aircraft) { |
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
2353 |
Order *order; |
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
2354 |
FOR_VEHICLE_ORDERS(v, order) { |
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
2355 |
if (order->type == OT_GOTO_DEPOT && order->station == index) { |
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
2356 |
order->type = OT_DUMMY; |
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
2357 |
order->flags = 0; |
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
2358 |
invalidate = true; |
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
2359 |
} |
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
2360 |
} |
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
2361 |
} |
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
2362 |
//Orders for the vehicle have been changed, invalidate the window |
2639 | 2363 |
if (invalidate) InvalidateWindow(WC_VEHICLE_ORDERS, v->index); |
2213
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
2364 |
} |
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
2365 |
|
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
2366 |
//Subsidies need removal as well |
0 | 2367 |
DeleteSubsidyWithStation(index); |
2368 |
} |
|
2369 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1078
diff
changeset
|
2370 |
void DeleteAllPlayerStations(void) |
0 | 2371 |
{ |
2372 |
Station *st; |
|
2373 |
||
2374 |
FOR_ALL_STATIONS(st) { |
|
2639 | 2375 |
if (st->xy != 0 && st->owner < MAX_PLAYERS) DeleteStation(st); |
0 | 2376 |
} |
2377 |
} |
|
2378 |
||
1664
000099fbae6e
(svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents:
1593
diff
changeset
|
2379 |
static void CheckOrphanedSlots(const Station *st, RoadStopType rst) |
000099fbae6e
(svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents:
1593
diff
changeset
|
2380 |
{ |
000099fbae6e
(svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents:
1593
diff
changeset
|
2381 |
RoadStop *rs; |
000099fbae6e
(svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents:
1593
diff
changeset
|
2382 |
int k; |
000099fbae6e
(svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents:
1593
diff
changeset
|
2383 |
|
000099fbae6e
(svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents:
1593
diff
changeset
|
2384 |
for (rs = GetPrimaryRoadStop(st, rst); rs != NULL; rs = rs->next) { |
000099fbae6e
(svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents:
1593
diff
changeset
|
2385 |
for (k = 0; k < NUM_SLOTS; k++) { |
000099fbae6e
(svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents:
1593
diff
changeset
|
2386 |
if (rs->slot[k] != INVALID_SLOT) { |
1672 | 2387 |
const Vehicle *v = GetVehicle(rs->slot[k]); |
2388 |
||
2389 |
if (v->type != VEH_Road || v->u.road.slot != rs) { |
|
2390 |
DEBUG(ms, 0) ( |
|
2391 |
"Multistop: Orphaned %s slot at 0x%X of station %d (don't panic)", |
|
2392 |
(rst == RS_BUS) ? "bus" : "truck", rs->xy, st->index); |
|
1664
000099fbae6e
(svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents:
1593
diff
changeset
|
2393 |
rs->slot[k] = INVALID_SLOT; |
000099fbae6e
(svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents:
1593
diff
changeset
|
2394 |
} |
000099fbae6e
(svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents:
1593
diff
changeset
|
2395 |
} |
000099fbae6e
(svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents:
1593
diff
changeset
|
2396 |
} |
000099fbae6e
(svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents:
1593
diff
changeset
|
2397 |
} |
000099fbae6e
(svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents:
1593
diff
changeset
|
2398 |
} |
000099fbae6e
(svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents:
1593
diff
changeset
|
2399 |
|
0 | 2400 |
/* this function is called for one station each tick */ |
2401 |
static void StationHandleBigTick(Station *st) |
|
2402 |
{ |
|
2403 |
UpdateStationAcceptance(st, true); |
|
2404 |
||
2639 | 2405 |
if (st->facilities == 0 && ++st->delete_ctr >= 8) DeleteStation(st); |
1239
6e61c510580e
(svn r1743) -Fix: Multistop: Added some debug output and made sure that orphaned slots are cleared.
celestar
parents:
1231
diff
changeset
|
2406 |
|
1664
000099fbae6e
(svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents:
1593
diff
changeset
|
2407 |
// Here we saveguard against orphaned slots |
000099fbae6e
(svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents:
1593
diff
changeset
|
2408 |
CheckOrphanedSlots(st, RS_BUS); |
000099fbae6e
(svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents:
1593
diff
changeset
|
2409 |
CheckOrphanedSlots(st, RS_TRUCK); |
0 | 2410 |
} |
2411 |
||
500
ef288590e096
(svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents:
497
diff
changeset
|
2412 |
static inline void byte_inc_sat(byte *p) { byte b = *p + 1; if (b != 0) *p = b; } |
0 | 2413 |
|
2414 |
static void UpdateStationRating(Station *st) |
|
2415 |
{ |
|
2416 |
GoodsEntry *ge; |
|
1551
eb05e6a90e67
(svn r2055) -CodeChange: Begun introducting StationID
celestar
parents:
1527
diff
changeset
|
2417 |
int rating; |
eb05e6a90e67
(svn r2055) -CodeChange: Begun introducting StationID
celestar
parents:
1527
diff
changeset
|
2418 |
StationID index; |
0 | 2419 |
int waiting; |
2420 |
bool waiting_changed = false; |
|
2421 |
||
2422 |
byte_inc_sat(&st->time_since_load); |
|
2423 |
byte_inc_sat(&st->time_since_unload); |
|
2424 |
||
2425 |
ge = st->goods; |
|
2426 |
do { |
|
1266
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1265
diff
changeset
|
2427 |
if (ge->enroute_from != INVALID_STATION) { |
0 | 2428 |
byte_inc_sat(&ge->enroute_time); |
2429 |
byte_inc_sat(&ge->days_since_pickup); |
|
2430 |
||
2431 |
rating = 0; |
|
2432 |
||
2433 |
{ |
|
2434 |
int b = ge->last_speed; |
|
2435 |
if ((b-=85) >= 0) |
|
2436 |
rating += b >> 2; |
|
2437 |
} |
|
2438 |
||
2439 |
{ |
|
2440 |
byte age = ge->last_age; |
|
2441 |
(age >= 3) || |
|
2442 |
(rating += 10, age >= 2) || |
|
2443 |
(rating += 10, age >= 1) || |
|
2444 |
(rating += 13, true); |
|
2445 |
} |
|
2446 |
||
1457
6a8ca2f51a8b
(svn r1961) - Fix: [ 1158618 ] Segmentation fault when loading savegame, out of bounds array check.
Darkvater
parents:
1454
diff
changeset
|
2447 |
if (st->owner < MAX_PLAYERS && HASBIT(st->town->statues, st->owner)) |
0 | 2448 |
rating += 26; |
2449 |
||
2450 |
{ |
|
2451 |
byte days = ge->days_since_pickup; |
|
2452 |
if (st->last_vehicle != INVALID_VEHICLE && |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
2453 |
GetVehicle(st->last_vehicle)->type == VEH_Ship) |
0 | 2454 |
days >>= 2; |
2455 |
(days > 21) || |
|
2456 |
(rating += 25, days > 12) || |
|
2457 |
(rating += 25, days > 6) || |
|
2458 |
(rating += 45, days > 3) || |
|
2459 |
(rating += 35, true); |
|
2460 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2461 |
|
0 | 2462 |
{ |
2504
7c27fc230cda
(svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents:
2502
diff
changeset
|
2463 |
waiting = GB(ge->waiting_acceptance, 0, 12); |
0 | 2464 |
(rating -= 90, waiting > 1500) || |
2465 |
(rating += 55, waiting > 1000) || |
|
2466 |
(rating += 35, waiting > 600) || |
|
2467 |
(rating += 10, waiting > 300) || |
|
2468 |
(rating += 20, waiting > 100) || |
|
2469 |
(rating += 10, true); |
|
2470 |
} |
|
2471 |
||
2472 |
{ |
|
2473 |
int or = ge->rating; // old rating |
|
2474 |
||
2475 |
// only modify rating in steps of -2, -1, 0, 1 or 2 |
|
2476 |
ge->rating = rating = or + clamp(clamp(rating, 0, 255) - or, -2, 2); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2477 |
|
0 | 2478 |
// if rating is <= 64 and more than 200 items waiting, remove some random amount of goods from the station |
2479 |
if (rating <= 64 && waiting >= 200) { |
|
2480 |
int dec = Random() & 0x1F; |
|
2481 |
if (waiting < 400) dec &= 7; |
|
2482 |
waiting -= dec + 1; |
|
2483 |
waiting_changed = true; |
|
2484 |
} |
|
2485 |
||
2486 |
// if rating is <= 127 and there are any items waiting, maybe remove some goods. |
|
2487 |
if (rating <= 127 && waiting != 0) { |
|
2488 |
uint32 r = Random(); |
|
2489 |
if ( (uint)rating <= (r & 0x7F) ) { |
|
2490 |
waiting = max(waiting - ((r >> 8)&3) - 1, 0); |
|
2491 |
waiting_changed = true; |
|
2492 |
} |
|
2493 |
} |
|
2494 |
||
2504
7c27fc230cda
(svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents:
2502
diff
changeset
|
2495 |
if (waiting_changed) SB(ge->waiting_acceptance, 0, 12, waiting); |
0 | 2496 |
} |
2497 |
} |
|
2498 |
} while (++ge != endof(st->goods)); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2499 |
|
0 | 2500 |
index = st->index; |
2501 |
||
2502 |
if (waiting_changed) |
|
2503 |
InvalidateWindow(WC_STATION_VIEW, index); |
|
2504 |
else |
|
2505 |
InvalidateWindowWidget(WC_STATION_VIEW, index, 5); |
|
2506 |
} |
|
2507 |
||
2508 |
/* called for every station each tick */ |
|
2509 |
static void StationHandleSmallTick(Station *st) |
|
2510 |
{ |
|
2511 |
byte b; |
|
2512 |
||
2639 | 2513 |
if (st->facilities == 0) return; |
0 | 2514 |
|
2515 |
b = st->delete_ctr + 1; |
|
2516 |
if (b >= 185) b = 0; |
|
2517 |
st->delete_ctr = b; |
|
2518 |
||
2639 | 2519 |
if (b == 0) UpdateStationRating(st); |
0 | 2520 |
} |
2521 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1078
diff
changeset
|
2522 |
void OnTick_Station(void) |
0 | 2523 |
{ |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
2524 |
uint i; |
0 | 2525 |
Station *st; |
2526 |
||
2639 | 2527 |
if (_game_mode == GM_EDITOR) return; |
0 | 2528 |
|
2529 |
i = _station_tick_ctr; |
|
2639 | 2530 |
if (++_station_tick_ctr == GetStationPoolSize()) _station_tick_ctr = 0; |
0 | 2531 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
2532 |
st = GetStation(i); |
2639 | 2533 |
if (st->xy != 0) StationHandleBigTick(st); |
0 | 2534 |
|
2535 |
FOR_ALL_STATIONS(st) { |
|
2640 | 2536 |
if (st->xy != 0) StationHandleSmallTick(st); |
0 | 2537 |
} |
2538 |
} |
|
2539 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1078
diff
changeset
|
2540 |
void StationMonthlyLoop(void) |
0 | 2541 |
{ |
2542 |
} |
|
2543 |
||
2544 |
||
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
|
2545 |
void ModifyStationRatingAround(TileIndex tile, PlayerID owner, int amount, uint radius) |
0 | 2546 |
{ |
2547 |
Station *st; |
|
2548 |
||
2549 |
FOR_ALL_STATIONS(st) { |
|
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1239
diff
changeset
|
2550 |
if (st->xy != 0 && st->owner == owner && |
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1239
diff
changeset
|
2551 |
DistanceManhattan(tile, st->xy) <= radius) { |
2549 | 2552 |
uint i; |
2553 |
||
2554 |
for (i = 0; i != NUM_CARGO; i++) { |
|
2555 |
GoodsEntry* ge = &st->goods[i]; |
|
2556 |
||
1266
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1265
diff
changeset
|
2557 |
if (ge->enroute_from != INVALID_STATION) { |
0 | 2558 |
ge->rating = clamp(ge->rating + amount, 0, 255); |
2559 |
} |
|
2560 |
} |
|
2561 |
} |
|
2562 |
} |
|
2563 |
} |
|
2564 |
||
2565 |
static void UpdateStationWaiting(Station *st, int type, uint amount) |
|
2566 |
{ |
|
2504
7c27fc230cda
(svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents:
2502
diff
changeset
|
2567 |
SB(st->goods[type].waiting_acceptance, 0, 12, |
7c27fc230cda
(svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents:
2502
diff
changeset
|
2568 |
min(0xFFF, GB(st->goods[type].waiting_acceptance, 0, 12) + amount) |
7c27fc230cda
(svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents:
2502
diff
changeset
|
2569 |
); |
0 | 2570 |
|
2571 |
st->goods[type].enroute_time = 0; |
|
2572 |
st->goods[type].enroute_from = st->index; |
|
2573 |
InvalidateWindow(WC_STATION_VIEW, st->index); |
|
2574 |
} |
|
2575 |
||
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
|
2576 |
/** Rename a station |
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
|
2577 |
* @param x,y 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
|
2578 |
* @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
|
2579 |
* @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
|
2580 |
*/ |
0 | 2581 |
int32 CmdRenameStation(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
2582 |
{ |
|
2639 | 2583 |
StringID str; |
0 | 2584 |
Station *st; |
2585 |
||
1840
c181d5cb4ffe
(svn r2345) - Fix: Don't allow stuff to be renamed to nothing if we don't support it. Only valid ones are signs (delete) and waypoints (rename to default).
Darkvater
parents:
1820
diff
changeset
|
2586 |
if (!IsStationIndex(p1) || _cmd_text[0] == '\0') return CMD_ERROR; |
1774
0fc4a31265c2
(svn r2278) When renaming a station, check if the station exists and belongs to the correct player
tron
parents:
1751
diff
changeset
|
2587 |
st = GetStation(p1); |
0fc4a31265c2
(svn r2278) When renaming a station, check if the station exists and belongs to the correct player
tron
parents:
1751
diff
changeset
|
2588 |
|
0fc4a31265c2
(svn r2278) When renaming a station, check if the station exists and belongs to the correct player
tron
parents:
1751
diff
changeset
|
2589 |
if (!IsValidStation(st) || !CheckOwnership(st->owner)) return CMD_ERROR; |
0fc4a31265c2
(svn r2278) When renaming a station, check if the station exists and belongs to the correct player
tron
parents:
1751
diff
changeset
|
2590 |
|
1820
9b6458526480
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1786
diff
changeset
|
2591 |
str = AllocateNameUnique(_cmd_text, 6); |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1784
diff
changeset
|
2592 |
if (str == 0) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2593 |
|
0 | 2594 |
if (flags & DC_EXEC) { |
2639 | 2595 |
StringID old_str = st->string_id; |
2596 |
||
0 | 2597 |
st->string_id = str; |
2598 |
UpdateStationVirtCoord(st); |
|
2599 |
DeleteName(old_str); |
|
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
2600 |
_station_sort_dirty[st->owner] = true; // rename a station |
0 | 2601 |
MarkWholeScreenDirty(); |
2602 |
} else { |
|
2603 |
DeleteName(str); |
|
2604 |
} |
|
2605 |
||
2606 |
return 0; |
|
2607 |
} |
|
2608 |
||
2609 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2610 |
uint MoveGoodsToStation(TileIndex tile, int w, int h, int type, uint amount) |
0 | 2611 |
{ |
2612 |
Station *around_ptr[8]; |
|
1551
eb05e6a90e67
(svn r2055) -CodeChange: Begun introducting StationID
celestar
parents:
1527
diff
changeset
|
2613 |
StationID around[8]; |
eb05e6a90e67
(svn r2055) -CodeChange: Begun introducting StationID
celestar
parents:
1527
diff
changeset
|
2614 |
StationID st_index; |
0 | 2615 |
int i; |
2616 |
Station *st; |
|
2617 |
uint moved; |
|
2618 |
uint best_rating, best_rating2; |
|
2619 |
Station *st1, *st2; |
|
2620 |
int t; |
|
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2621 |
int rad=0; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2622 |
int w_prod=0, h_prod=0; //width and height of the "producer" of the cargo |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2623 |
int x_min_prod, x_max_prod; //min and max coordinates of the producer |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2624 |
int y_min_prod, y_max_prod; //relative |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2625 |
int x_dist, y_dist; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2626 |
int max_rad; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2627 |
|
0 | 2628 |
|
2629 |
memset(around, 0xff, sizeof(around)); |
|
2630 |
||
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2631 |
if (_patches.modified_catchment) { |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2632 |
w_prod = w; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2633 |
h_prod = h; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2634 |
w += 16; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2635 |
h += 16; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2636 |
max_rad = 8; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2637 |
} else { |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2638 |
w += 8; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2639 |
h += 8; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2640 |
max_rad = 4; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2641 |
} |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2642 |
|
1981 | 2643 |
BEGIN_TILE_LOOP(cur_tile, w, h, tile - TileDiffXY(max_rad, max_rad)) |
0 | 2644 |
cur_tile = TILE_MASK(cur_tile); |
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
|
2645 |
if (IsTileType(cur_tile, MP_STATION)) { |
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
|
2646 |
st_index = _m[cur_tile].m2; |
2639 | 2647 |
for (i = 0; i != 8; i++) { |
1527
3d204567b05b
(svn r2031) -Fix: Station #256 now gets cargo delivered as well
celestar
parents:
1507
diff
changeset
|
2648 |
if (around[i] == INVALID_STATION) { |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
2649 |
st = GetStation(st_index); |
1751
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1706
diff
changeset
|
2650 |
if (!IsBuoy(st) && |
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
84
diff
changeset
|
2651 |
( !st->town->exclusive_counter || (st->town->exclusivity == st->owner) ) && // check exclusive transport rights |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2652 |
st->goods[type].rating != 0 && |
0 | 2653 |
(!_patches.selectgoods || st->goods[type].last_speed) && // if last_speed is 0, no vehicle has been there. |
22 | 2654 |
((st->facilities & (byte)~FACIL_BUS_STOP)!=0 || type==CT_PASSENGERS) && // if we have other fac. than a bus stop, or the cargo is passengers |
2655 |
((st->facilities & (byte)~FACIL_TRUCK_STOP)!=0 || type!=CT_PASSENGERS)) { // if we have other fac. than a cargo bay or the cargo is not passengers |
|
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2656 |
if (_patches.modified_catchment) { |
703
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
2657 |
rad = FindCatchmentRadius(st); |
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2658 |
x_min_prod = y_min_prod = 9; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2659 |
x_max_prod = 8 + w_prod; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2660 |
y_max_prod = 8 + h_prod; |
703
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
2661 |
|
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2662 |
x_dist = min(w_cur - x_min_prod, x_max_prod - w_cur); |
703
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
2663 |
|
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2664 |
if (w_cur < x_min_prod) { |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2665 |
x_dist = x_min_prod - w_cur; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2666 |
} else { //save cycles |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2667 |
if (w_cur > x_max_prod) x_dist = w_cur - x_max_prod; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2668 |
} |
703
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
2669 |
|
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2670 |
y_dist = min(h_cur - y_min_prod, y_max_prod - h_cur); |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2671 |
if (h_cur < y_min_prod) { |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2672 |
y_dist = y_min_prod - h_cur; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2673 |
} else { |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2674 |
if (h_cur > y_max_prod) y_dist = h_cur - y_max_prod; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2675 |
} |
703
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
2676 |
|
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2677 |
} else { |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2678 |
x_dist = y_dist = 0; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2679 |
} |
703
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
2680 |
|
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2681 |
if ( !(x_dist > rad) && !(y_dist > rad) ) { |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2682 |
|
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2683 |
around[i] = st_index; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2684 |
around_ptr[i] = st; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2685 |
} |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2686 |
} |
0 | 2687 |
break; |
2688 |
} else if (around[i] == st_index) |
|
2689 |
break; |
|
2690 |
} |
|
2691 |
} |
|
1981 | 2692 |
END_TILE_LOOP(cur_tile, w, h, tile - TileDiffXY(max_rad, max_rad)) |
0 | 2693 |
|
2694 |
/* no stations around at all? */ |
|
1527
3d204567b05b
(svn r2031) -Fix: Station #256 now gets cargo delivered as well
celestar
parents:
1507
diff
changeset
|
2695 |
if (around[0] == INVALID_STATION) |
0 | 2696 |
return 0; |
2697 |
||
1527
3d204567b05b
(svn r2031) -Fix: Station #256 now gets cargo delivered as well
celestar
parents:
1507
diff
changeset
|
2698 |
if (around[1] == INVALID_STATION) { |
0 | 2699 |
/* only one station around */ |
2700 |
moved = (amount * around_ptr[0]->goods[type].rating >> 8) + 1; |
|
2701 |
UpdateStationWaiting(around_ptr[0], type, moved); |
|
2702 |
return moved; |
|
2703 |
} |
|
2704 |
||
2705 |
/* several stations around, find the two with the highest rating */ |
|
2706 |
st2 = st1 = NULL; |
|
2707 |
best_rating = best_rating2 = 0; |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2708 |
|
1527
3d204567b05b
(svn r2031) -Fix: Station #256 now gets cargo delivered as well
celestar
parents:
1507
diff
changeset
|
2709 |
for( i = 0; i != 8 && around[i] != INVALID_STATION; i++) { |
0 | 2710 |
if (around_ptr[i]->goods[type].rating >= best_rating) { |
2711 |
best_rating2 = best_rating; |
|
2712 |
st2 = st1; |
|
2713 |
||
2714 |
best_rating = around_ptr[i]->goods[type].rating; |
|
2715 |
st1 = around_ptr[i]; |
|
2716 |
} else if (around_ptr[i]->goods[type].rating >= best_rating2) { |
|
2717 |
best_rating2 = around_ptr[i]->goods[type].rating; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2718 |
st2 = around_ptr[i]; |
0 | 2719 |
} |
2720 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2721 |
|
0 | 2722 |
assert(st1 != NULL); |
2723 |
assert(st2 != NULL); |
|
2724 |
assert(best_rating != 0 || best_rating2 != 0); |
|
2725 |
||
2726 |
/* the 2nd highest one gets a penalty */ |
|
2727 |
best_rating2 >>= 1; |
|
2728 |
||
2729 |
/* amount given to station 1 */ |
|
2730 |
t = (best_rating * (amount + 1)) / (best_rating + best_rating2); |
|
2731 |
||
2732 |
moved = 0; |
|
2733 |
if (t != 0) { |
|
2734 |
moved = (t * best_rating >> 8) + 1; |
|
2735 |
amount -= t; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2736 |
UpdateStationWaiting(st1, type, moved); |
0 | 2737 |
} |
2738 |
||
2739 |
if (amount != 0) { |
|
2740 |
moved += (amount = (amount * best_rating2 >> 8) + 1); |
|
2741 |
UpdateStationWaiting(st2, type, amount); |
|
2742 |
} |
|
2743 |
||
2744 |
return moved; |
|
2745 |
} |
|
2746 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2747 |
void BuildOilRig(TileIndex tile) |
0 | 2748 |
{ |
2639 | 2749 |
uint j; |
2427
b7a0ad02af26
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2750 |
Station *st = AllocateStation(); |
b7a0ad02af26
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2751 |
|
b7a0ad02af26
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2752 |
if (st == 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
|
2753 |
DEBUG(misc, 0) ("Couldn't allocate station for oilrig at %#X, reverting to oilrig only...", 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
|
2754 |
return; |
0 | 2755 |
} |
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
|
2756 |
if (!GenerateStationName(st, tile, 2)) { |
b7a0ad02af26
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2757 |
DEBUG(misc, 0) ("Couldn't allocate station-name for oilrig at %#X, reverting to oilrig only...", 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
|
2758 |
return; |
b7a0ad02af26
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2759 |
} |
b7a0ad02af26
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2760 |
|
b7a0ad02af26
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2761 |
st->town = ClosestTownFromTile(tile, (uint)-1); |
b7a0ad02af26
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2762 |
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
|
2763 |
|
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
|
2764 |
SetTileType(tile, MP_STATION); |
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
|
2765 |
SetTileOwner(tile, OWNER_NONE); |
2639 | 2766 |
_m[tile].m2 = 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
|
2767 |
_m[tile].m3 = 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
|
2768 |
_m[tile].m4 = 0; |
2639 | 2769 |
_m[tile].m5 = 0x4B; |
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
|
2770 |
|
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
|
2771 |
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
|
2772 |
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
|
2773 |
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
|
2774 |
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
|
2775 |
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
|
2776 |
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
|
2777 |
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
|
2778 |
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
|
2779 |
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
|
2780 |
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
|
2781 |
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
|
2782 |
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
|
2783 |
st->delete_ctr = 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
|
2784 |
st->last_vehicle = INVALID_VEHICLE; |
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
|
2785 |
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
|
2786 |
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
|
2787 |
|
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
|
2788 |
for (j = 0; j != NUM_CARGO; j++) { |
b7a0ad02af26
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2789 |
st->goods[j].waiting_acceptance = 0; |
b7a0ad02af26
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2790 |
st->goods[j].days_since_pickup = 0; |
b7a0ad02af26
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2791 |
st->goods[j].enroute_from = INVALID_STATION; |
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
|
2792 |
st->goods[j].rating = 175; |
b7a0ad02af26
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2793 |
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
|
2794 |
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
|
2795 |
} |
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
|
2796 |
|
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
|
2797 |
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
|
2798 |
UpdateStationAcceptance(st, false); |
0 | 2799 |
} |
2800 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2801 |
void DeleteOilRig(TileIndex tile) |
0 | 2802 |
{ |
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
|
2803 |
Station *st = GetStation(_m[tile].m2); |
0 | 2804 |
|
2805 |
DoClearSquare(tile); |
|
2806 |
||
2807 |
st->dock_tile = 0; |
|
2808 |
st->airport_tile = 0; |
|
2809 |
st->facilities &= ~(FACIL_AIRPORT | FACIL_DOCK); |
|
2810 |
st->airport_flags = 0; |
|
2811 |
UpdateStationVirtCoordDirty(st); |
|
2812 |
DeleteStation(st); |
|
2813 |
} |
|
2814 |
||
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
|
2815 |
static void ChangeTileOwner_Station(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 2816 |
{ |
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
|
2817 |
if (!IsTileOwner(tile, old_player)) return; |
0 | 2818 |
|
2502 | 2819 |
if (new_player != OWNER_SPECTATOR) { |
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
|
2820 |
Station *st = GetStation(_m[tile].m2); |
1902 | 2821 |
SetTileOwner(tile, new_player); |
0 | 2822 |
st->owner = new_player; |
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
2823 |
_global_station_sort_dirty = true; // transfer ownership of station to another player |
65
f9f866bc609c
(svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents:
59
diff
changeset
|
2824 |
InvalidateWindowClasses(WC_STATION_LIST); |
0 | 2825 |
} else { |
2826 |
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
2827 |
} |
|
2828 |
} |
|
2829 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2830 |
static int32 ClearTile_Station(TileIndex tile, byte flags) |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2831 |
{ |
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
|
2832 |
byte m5 = _m[tile].m5; |
0 | 2833 |
Station *st; |
2834 |
||
2835 |
if (flags & DC_AUTO) { |
|
2836 |
if (m5 < 8) return_cmd_error(STR_300B_MUST_DEMOLISH_RAILROAD); |
|
2837 |
if (m5 < 0x43 || (m5 >= 83 && m5 <= 114)) return_cmd_error(STR_300E_MUST_DEMOLISH_AIRPORT_FIRST); |
|
2838 |
if (m5 < 0x47) return_cmd_error(STR_3047_MUST_DEMOLISH_TRUCK_STATION); |
|
2839 |
if (m5 < 0x4B) return_cmd_error(STR_3046_MUST_DEMOLISH_BUS_STATION); |
|
2840 |
if (m5 == 0x52) return_cmd_error(STR_306A_BUOY_IN_THE_WAY); |
|
2841 |
if (m5 != 0x4B && m5 < 0x53) return_cmd_error(STR_304D_MUST_DEMOLISH_DOCK_FIRST); |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
2842 |
SetDParam(0, STR_4807_OIL_RIG); |
0 | 2843 |
return_cmd_error(STR_4800_IN_THE_WAY); |
2844 |
} |
|
2845 |
||
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
|
2846 |
st = GetStation(_m[tile].m2); |
0 | 2847 |
|
2639 | 2848 |
if (m5 < 8) return RemoveRailroadStation(st, tile, flags); |
0 | 2849 |
// original airports < 67, new airports between 83 - 114 |
2639 | 2850 |
if (m5 < 0x43 || (m5 >= 83 && m5 <= 114)) return RemoveAirport(st, flags); |
2851 |
if (m5 < 0x4B) return RemoveRoadStop(st, flags, tile); |
|
2852 |
if (m5 == 0x52) return RemoveBuoy(st, flags); |
|
2853 |
if (m5 != 0x4B && m5 < 0x53) return RemoveDock(st, flags); |
|
0 | 2854 |
|
2855 |
return CMD_ERROR; |
|
2856 |
} |
|
2857 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1078
diff
changeset
|
2858 |
void InitializeStations(void) |
0 | 2859 |
{ |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
2860 |
/* Clean the station pool and create 1 block in it */ |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
2861 |
CleanPool(&_station_pool); |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
2862 |
AddBlockToPool(&_station_pool); |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
2863 |
|
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
2864 |
/* Clean the roadstop pool and create 1 block in it */ |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
2865 |
CleanPool(&_roadstop_pool); |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
2866 |
AddBlockToPool(&_roadstop_pool); |
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
2867 |
|
0 | 2868 |
_station_tick_ctr = 0; |
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
2869 |
|
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
2870 |
// set stations to be sorted on load of savegame |
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
2871 |
memset(_station_sort_dirty, true, sizeof(_station_sort_dirty)); |
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
2872 |
_global_station_sort_dirty = true; // load of savegame |
0 | 2873 |
} |
2874 |
||
2875 |
||
2876 |
const TileTypeProcs _tile_type_station_procs = { |
|
2877 |
DrawTile_Station, /* draw_tile_proc */ |
|
2878 |
GetSlopeZ_Station, /* get_slope_z_proc */ |
|
2879 |
ClearTile_Station, /* clear_tile_proc */ |
|
2880 |
GetAcceptedCargo_Station, /* get_accepted_cargo_proc */ |
|
2881 |
GetTileDesc_Station, /* get_tile_desc_proc */ |
|
2882 |
GetTileTrackStatus_Station, /* get_tile_track_status_proc */ |
|
2883 |
ClickTile_Station, /* click_tile_proc */ |
|
2884 |
AnimateTile_Station, /* animate_tile_proc */ |
|
2885 |
TileLoop_Station, /* tile_loop_clear */ |
|
2886 |
ChangeTileOwner_Station, /* change_tile_owner_clear */ |
|
2887 |
NULL, /* get_produced_cargo_proc */ |
|
2888 |
VehicleEnter_Station, /* vehicle_enter_tile_proc */ |
|
2889 |
NULL, /* vehicle_leave_tile_proc */ |
|
39 | 2890 |
GetSlopeTileh_Station, /* get_slope_tileh_proc */ |
0 | 2891 |
}; |
2892 |
||
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
|
2893 |
static const SaveLoad _roadstop_desc[] = { |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2894 |
SLE_VAR(RoadStop,xy, SLE_UINT32), |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2895 |
SLE_VAR(RoadStop,used, SLE_UINT8), |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2896 |
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
|
2897 |
/* Index was saved in some versions, but this is not needed */ |
dee20e32bffe
(svn r1789) -Fix: there is no need to save the index, it is done for us
truelight
parents:
1284
diff
changeset
|
2898 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U32 | SLE_VAR_NULL, 1, 0, 8), |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2899 |
SLE_VAR(RoadStop,station, SLE_UINT16), |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2900 |
SLE_VAR(RoadStop,type, SLE_UINT8), |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2901 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2902 |
SLE_REF(RoadStop,next, REF_ROADSTOPS), |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2903 |
SLE_REF(RoadStop,prev, REF_ROADSTOPS), |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2904 |
|
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
2905 |
SLE_ARR(RoadStop,slot, SLE_UINT16, NUM_SLOTS), |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2906 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2907 |
SLE_END() |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2908 |
}; |
0 | 2909 |
|
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
|
2910 |
static const SaveLoad _station_desc[] = { |
1174
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1093
diff
changeset
|
2911 |
SLE_CONDVAR(Station, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1093
diff
changeset
|
2912 |
SLE_CONDVAR(Station, xy, SLE_UINT32, 6, 255), |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2913 |
SLE_CONDVAR(Station, bus_tile_obsolete, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2914 |
SLE_CONDVAR(Station, lorry_tile_obsolete, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
1174
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1093
diff
changeset
|
2915 |
SLE_CONDVAR(Station, train_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1093
diff
changeset
|
2916 |
SLE_CONDVAR(Station, train_tile, SLE_UINT32, 6, 255), |
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1093
diff
changeset
|
2917 |
SLE_CONDVAR(Station, airport_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1093
diff
changeset
|
2918 |
SLE_CONDVAR(Station, airport_tile, SLE_UINT32, 6, 255), |
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1093
diff
changeset
|
2919 |
SLE_CONDVAR(Station, dock_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1093
diff
changeset
|
2920 |
SLE_CONDVAR(Station, dock_tile, SLE_UINT32, 6, 255), |
0 | 2921 |
SLE_REF(Station,town, REF_TOWN), |
2922 |
SLE_VAR(Station,trainst_w, SLE_UINT8), |
|
2923 |
SLE_CONDVAR(Station,trainst_h, SLE_UINT8, 2, 255), |
|
2924 |
||
2925 |
// alpha_order was stored here in savegame format 0 - 3 |
|
2926 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U8 | SLE_VAR_NULL, 1, 0, 3), |
|
2927 |
||
2928 |
SLE_VAR(Station,string_id, SLE_STRINGID), |
|
2929 |
SLE_VAR(Station,had_vehicle_of_type,SLE_UINT16), |
|
2930 |
||
2931 |
SLE_VAR(Station,time_since_load, SLE_UINT8), |
|
2932 |
SLE_VAR(Station,time_since_unload, SLE_UINT8), |
|
2933 |
SLE_VAR(Station,delete_ctr, SLE_UINT8), |
|
2934 |
SLE_VAR(Station,owner, SLE_UINT8), |
|
2935 |
SLE_VAR(Station,facilities, SLE_UINT8), |
|
2936 |
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
|
2937 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2938 |
// truck/bus_stop_status was stored here in savegame format 0 - 6 |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2939 |
SLE_CONDVAR(Station,truck_stop_status_obsolete, SLE_UINT8, 0, 5), |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2940 |
SLE_CONDVAR(Station,bus_stop_status_obsolete, SLE_UINT8, 0, 5), |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2941 |
|
123
d550772c61e6
(svn r124) Prepared code for removal of block_months variable in next major savegame version
dominik
parents:
121
diff
changeset
|
2942 |
// blocked_months was stored here in savegame format 0 - 4.0 |
d550772c61e6
(svn r124) Prepared code for removal of block_months variable in next major savegame version
dominik
parents:
121
diff
changeset
|
2943 |
SLE_CONDVAR(Station,blocked_months_obsolete, SLE_UINT8, 0, 4), |
0 | 2944 |
|
2945 |
SLE_CONDVAR(Station,airport_flags, SLE_VAR_U32 | SLE_FILE_U16, 0, 2), |
|
2946 |
SLE_CONDVAR(Station,airport_flags, SLE_UINT32, 3, 255), |
|
2947 |
||
2948 |
SLE_VAR(Station,last_vehicle, SLE_UINT16), |
|
2949 |
||
2950 |
SLE_CONDVAR(Station,class_id, SLE_UINT8, 3, 255), |
|
2951 |
SLE_CONDVAR(Station,stat_id, SLE_UINT8, 3, 255), |
|
2952 |
SLE_CONDVAR(Station,build_date, SLE_UINT16, 3, 255), |
|
2953 |
||
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2954 |
SLE_CONDREF(Station,bus_stops, REF_ROADSTOPS, 6, 255), |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2955 |
SLE_CONDREF(Station,truck_stops, REF_ROADSTOPS, 6, 255), |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2956 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2957 |
// reserve extra space in savegame here. (currently 28 bytes) |
0 | 2958 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U8 | SLE_VAR_NULL, 32, 2, 255), |
2959 |
||
2960 |
SLE_END() |
|
2961 |
}; |
|
2962 |
||
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
|
2963 |
static const SaveLoad _goods_desc[] = { |
0 | 2964 |
SLE_VAR(GoodsEntry,waiting_acceptance,SLE_UINT16), |
2965 |
SLE_VAR(GoodsEntry,days_since_pickup, SLE_UINT8), |
|
2966 |
SLE_VAR(GoodsEntry,rating, SLE_UINT8), |
|
1266
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1265
diff
changeset
|
2967 |
SLE_CONDVAR(GoodsEntry,enroute_from, SLE_FILE_U8 | SLE_VAR_U16, 0, 6), |
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1265
diff
changeset
|
2968 |
SLE_CONDVAR(GoodsEntry,enroute_from, SLE_UINT16, 7, 255), |
0 | 2969 |
SLE_VAR(GoodsEntry,enroute_time, SLE_UINT8), |
2970 |
SLE_VAR(GoodsEntry,last_speed, SLE_UINT8), |
|
2971 |
SLE_VAR(GoodsEntry,last_age, SLE_UINT8), |
|
1935
f43f062c9498
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1902
diff
changeset
|
2972 |
SLE_CONDVAR(GoodsEntry,feeder_profit, SLE_INT32, 14, 255), |
0 | 2973 |
|
2974 |
SLE_END() |
|
2975 |
}; |
|
2976 |
||
2977 |
||
2978 |
static void SaveLoad_STNS(Station *st) |
|
2979 |
{ |
|
2980 |
int i; |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2981 |
|
0 | 2982 |
SlObject(st, _station_desc); |
1266
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1265
diff
changeset
|
2983 |
for (i = 0; i != NUM_CARGO; i++) { |
0 | 2984 |
SlObject(&st->goods[i], _goods_desc); |
1266
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1265
diff
changeset
|
2985 |
|
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1265
diff
changeset
|
2986 |
/* In older versions, enroute_from had 0xFF as INVALID_STATION, is now 0xFFFF */ |
2685
00111d5ca47f
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2676
diff
changeset
|
2987 |
if (CheckSavegameVersion(7) && st->goods[i].enroute_from == 0xFF) { |
2469
1bfbb0dc0b75
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2436
diff
changeset
|
2988 |
st->goods[i].enroute_from = INVALID_STATION; |
2639 | 2989 |
} |
1266
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1265
diff
changeset
|
2990 |
} |
0 | 2991 |
} |
2992 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1078
diff
changeset
|
2993 |
static void Save_STNS(void) |
0 | 2994 |
{ |
2995 |
Station *st; |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
2996 |
// Write the stations |
0 | 2997 |
FOR_ALL_STATIONS(st) { |
2998 |
if (st->xy != 0) { |
|
2999 |
SlSetArrayIndex(st->index); |
|
3000 |
SlAutolength((AutolengthProc*)SaveLoad_STNS, st); |
|
3001 |
} |
|
3002 |
} |
|
3003 |
} |
|
3004 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1078
diff
changeset
|
3005 |
static void Load_STNS(void) |
0 | 3006 |
{ |
3007 |
int index; |
|
3008 |
while ((index = SlIterateArray()) != -1) { |
|
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
3009 |
Station *st; |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
3010 |
|
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
3011 |
if (!AddBlockIfNeeded(&_station_pool, index)) |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
3012 |
error("Stations: failed loading savegame: too many stations"); |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
3013 |
|
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
3014 |
st = GetStation(index); |
0 | 3015 |
SaveLoad_STNS(st); |
3016 |
||
3017 |
// this means it's an oldstyle savegame without support for nonuniform stations |
|
2639 | 3018 |
if (st->train_tile != 0 && st->trainst_h == 0) { |
2642 | 3019 |
int w = GB(st->trainst_w, 4, 4); |
3020 |
int h = GB(st->trainst_w, 0, 4); |
|
2639 | 3021 |
|
3022 |
if (_m[st->train_tile].m5 & 1) intswap(w, h); |
|
0 | 3023 |
st->trainst_w = w; |
3024 |
st->trainst_h = h; |
|
3025 |
} |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3026 |
|
2685
00111d5ca47f
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2676
diff
changeset
|
3027 |
/* In older versions, we had just 1 tile for a bus/lorry, now we have more.. |
00111d5ca47f
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2676
diff
changeset
|
3028 |
* convert, if needed */ |
00111d5ca47f
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2676
diff
changeset
|
3029 |
if (CheckSavegameVersion(6)) { |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3030 |
if (st->bus_tile_obsolete != 0) { |
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3031 |
st->bus_stops = AllocateRoadStop(); |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3032 |
if (st->bus_stops == NULL) |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3033 |
error("Station: too many busstations in savegame"); |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3034 |
|
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3035 |
InitializeRoadStop(st->bus_stops, NULL, st->bus_tile_obsolete, st->index); |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3036 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3037 |
if (st->lorry_tile_obsolete != 0) { |
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3038 |
st->truck_stops = AllocateRoadStop(); |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3039 |
if (st->truck_stops == NULL) |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3040 |
error("Station: too many truckstations in savegame"); |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3041 |
|
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3042 |
InitializeRoadStop(st->truck_stops, NULL, st->lorry_tile_obsolete, st->index); |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3043 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3044 |
} |
0 | 3045 |
} |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
3046 |
|
1472
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
3047 |
/* This is to ensure all pointers are within the limits of _stations_size */ |
2639 | 3048 |
if (_station_tick_ctr > GetStationPoolSize()) _station_tick_ctr = 0; |
0 | 3049 |
} |
3050 |
||
2549 | 3051 |
static void Save_ROADSTOP(void) |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3052 |
{ |
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3053 |
RoadStop *rs; |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3054 |
|
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3055 |
FOR_ALL_ROADSTOPS(rs) { |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3056 |
if (rs->used) { |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3057 |
SlSetArrayIndex(rs->index); |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3058 |
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
|
3059 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3060 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3061 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3062 |
|
2549 | 3063 |
static void Load_ROADSTOP(void) |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3064 |
{ |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3065 |
int index; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3066 |
|
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3067 |
while ((index = SlIterateArray()) != -1) { |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3068 |
RoadStop *rs; |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3069 |
|
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3070 |
if (!AddBlockIfNeeded(&_roadstop_pool, index)) |
1314
d6a253cf92c3
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1313
diff
changeset
|
3071 |
error("RoadStops: failed loading savegame: too many RoadStops"); |
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3072 |
|
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3073 |
rs = GetRoadStop(index); |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3074 |
SlObject(rs, _roadstop_desc); |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3075 |
} |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3076 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3077 |
|
0 | 3078 |
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
|
3079 |
{ '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
|
3080 |
{ 'ROAD', Save_ROADSTOP, Load_ROADSTOP, CH_ARRAY | CH_LAST}, |
0 | 3081 |
}; |