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