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