author | belugas |
Fri, 23 Feb 2007 01:48:53 +0000 | |
changeset 6443 | b8f06d8eb7be |
parent 6338 | 0fb4f452873c |
child 6447 | 3b71e57fd22b |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6443
b8f06d8eb7be
(svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents:
6338
diff
changeset
|
3 |
/** @file station_cmd.cpp */ |
2213
cb78ae22fe58
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1881
diff
changeset
|
6 |
#include "openttd.h" |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5568
diff
changeset
|
7 |
#include "bridge_map.h" |
1299
0a6510cc889b
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1295
diff
changeset
|
8 |
#include "debug.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2148
diff
changeset
|
9 |
#include "functions.h" |
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
10 |
#include "station_map.h" |
1363
01d3de5d8039
(svn r1867) Include tables/sprites.h only in files which need it
tron
parents:
1335
diff
changeset
|
11 |
#include "table/sprites.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
500
diff
changeset
|
12 |
#include "table/strings.h" |
679
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
595
diff
changeset
|
13 |
#include "map.h" |
1209
a1ac96655b79
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1190
diff
changeset
|
14 |
#include "tile.h" |
0 | 15 |
#include "station.h" |
16 |
#include "gfx.h" |
|
17 |
#include "window.h" |
|
18 |
#include "viewport.h" |
|
19 |
#include "command.h" |
|
20 |
#include "town.h" |
|
21 |
#include "vehicle.h" |
|
22 |
#include "news.h" |
|
23 |
#include "saveload.h" |
|
24 |
#include "economy.h" |
|
25 |
#include "player.h" |
|
26 |
#include "airport.h" |
|
405
6830ae7a0d5d
(svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents:
403
diff
changeset
|
27 |
#include "sprite.h" |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
28 |
#include "depot.h" |
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2671
diff
changeset
|
29 |
#include "train.h" |
3111
1edf71aa942e
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3102
diff
changeset
|
30 |
#include "water_map.h" |
3515
b14c49efef1e
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
31 |
#include "industry_map.h" |
3754
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
32 |
#include "newgrf_callbacks.h" |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
33 |
#include "newgrf_station.h" |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
34 |
#include "yapf/yapf.h" |
4261
2ec8f5a9747b
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4231
diff
changeset
|
35 |
#include "date.h" |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
36 |
#include "helpers.hpp" |
0 | 37 |
|
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
38 |
Station::Station(TileIndex tile) |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
39 |
{ |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
40 |
DEBUG(station, cDebugCtorLevel, "I+%3d", index); |
5583
ed718fa4c69c
(svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents:
5573
diff
changeset
|
41 |
|
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
42 |
xy = tile; |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
43 |
airport_tile = dock_tile = train_tile = 0; |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
44 |
bus_stops = truck_stops = NULL; |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
45 |
had_vehicle_of_type = 0; |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
46 |
time_since_load = 255; |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
47 |
time_since_unload = 255; |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
48 |
delete_ctr = 0; |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
49 |
facilities = 0; |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
50 |
|
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
51 |
last_vehicle_type = VEH_Invalid; |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
52 |
|
5972
564f98b055d1
(svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents:
5969
diff
changeset
|
53 |
random_bits = 0; // Random() must be called when station is really built (DC_EXEC) |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
54 |
waiting_triggers = 0; |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
55 |
} |
5583
ed718fa4c69c
(svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents:
5573
diff
changeset
|
56 |
|
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
57 |
/** |
5929 | 58 |
* Clean up a station by clearing vehicle orders and invalidating windows. |
59 |
* Aircraft-Hangar orders need special treatment here, as the hangars are |
|
60 |
* actually part of a station (tiletype is STATION), but the order type |
|
61 |
* is OT_GOTO_DEPOT. |
|
62 |
* @param st Station to be deleted |
|
63 |
*/ |
|
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
64 |
Station::~Station() |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
65 |
{ |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
66 |
DEBUG(station, cDebugCtorLevel, "I-%3d", index); |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
67 |
|
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
68 |
DeleteName(string_id); |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
69 |
MarkDirty(); |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
70 |
RebuildStationLists(); |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
71 |
InvalidateWindowClasses(WC_STATION_LIST); |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
72 |
|
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
73 |
DeleteWindowById(WC_STATION_VIEW, index); |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
74 |
|
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
75 |
/* Now delete all orders that go to the station */ |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
76 |
RemoveOrderFromAllVehicles(OT_GOTO_STATION, index); |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
77 |
|
5929 | 78 |
/* Subsidies need removal as well */ |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
79 |
DeleteSubsidyWithStation(index); |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
80 |
|
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
81 |
free(speclist); |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
82 |
xy = 0; |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
83 |
} |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
84 |
|
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
85 |
void* Station::operator new(size_t size) |
3587 | 86 |
{ |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
87 |
Station *st = AllocateRaw(); |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
88 |
return st; |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
89 |
} |
3587 | 90 |
|
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
91 |
void* Station::operator new(size_t size, int st_idx) |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
92 |
{ |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
93 |
if (!AddBlockIfNeeded(&_Station_pool, st_idx)) |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
94 |
error("Stations: failed loading savegame: too many stations"); |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
95 |
|
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
96 |
Station *st = GetStation(st_idx); |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
97 |
return st; |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
98 |
} |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
99 |
|
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
100 |
void Station::operator delete(void *p) |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
101 |
{ |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
102 |
} |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
103 |
|
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
104 |
void Station::operator delete(void *p, int st_idx) |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
105 |
{ |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
106 |
} |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
107 |
|
5972
564f98b055d1
(svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents:
5969
diff
changeset
|
108 |
/** Called when new facility is built on the station. If it is the first facility |
564f98b055d1
(svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents:
5969
diff
changeset
|
109 |
* it initializes also 'xy' and 'random_bits' members */ |
564f98b055d1
(svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents:
5969
diff
changeset
|
110 |
void Station::AddFacility(byte new_facility_bit, TileIndex facil_xy) |
564f98b055d1
(svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents:
5969
diff
changeset
|
111 |
{ |
564f98b055d1
(svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents:
5969
diff
changeset
|
112 |
if (facilities == 0) { |
564f98b055d1
(svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents:
5969
diff
changeset
|
113 |
xy = facil_xy; |
564f98b055d1
(svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents:
5969
diff
changeset
|
114 |
random_bits = Random(); |
564f98b055d1
(svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents:
5969
diff
changeset
|
115 |
} |
564f98b055d1
(svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents:
5969
diff
changeset
|
116 |
facilities |= new_facility_bit; |
564f98b055d1
(svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents:
5969
diff
changeset
|
117 |
owner = _current_player; |
564f98b055d1
(svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents:
5969
diff
changeset
|
118 |
build_date = _date; |
564f98b055d1
(svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents:
5969
diff
changeset
|
119 |
} |
564f98b055d1
(svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents:
5969
diff
changeset
|
120 |
|
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
121 |
void Station::MarkDirty() const |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
122 |
{ |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
123 |
if (sign.width_1 != 0) { |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
124 |
InvalidateWindowWidget(WC_STATION_VIEW, index, 1); |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
125 |
|
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
126 |
MarkAllViewportsDirty( |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
127 |
sign.left - 6, |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
128 |
sign.top, |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
129 |
sign.left + (sign.width_1 << 2) + 12, |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
130 |
sign.top + 48); |
3587 | 131 |
} |
132 |
} |
|
133 |
||
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
134 |
void Station::MarkTilesDirty() const |
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
135 |
{ |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
136 |
TileIndex tile = train_tile; |
4910
ed97a9239b11
(svn r6881) -Fix r6874: uint > int to remove signedness warning MSVC (peter1138)
Darkvater
parents:
4904
diff
changeset
|
137 |
int w, h; |
4904
ed65b5e93fbd
(svn r6874) - [NewStations] Mark all tiles of a railway station dirty when adding or removing tiles.
peter1138
parents:
4886
diff
changeset
|
138 |
|
5929 | 139 |
/* XXX No station is recorded as 0, not INVALID_TILE... */ |
4904
ed65b5e93fbd
(svn r6874) - [NewStations] Mark all tiles of a railway station dirty when adding or removing tiles.
peter1138
parents:
4886
diff
changeset
|
140 |
if (tile == 0) return; |
ed65b5e93fbd
(svn r6874) - [NewStations] Mark all tiles of a railway station dirty when adding or removing tiles.
peter1138
parents:
4886
diff
changeset
|
141 |
|
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
142 |
for (h = 0; h < trainst_h; h++) { |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
143 |
for (w = 0; w < trainst_w; w++) { |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
144 |
if (TileBelongsToRailStation(tile)) { |
4904
ed65b5e93fbd
(svn r6874) - [NewStations] Mark all tiles of a railway station dirty when adding or removing tiles.
peter1138
parents:
4886
diff
changeset
|
145 |
MarkTileDirtyByTile(tile); |
ed65b5e93fbd
(svn r6874) - [NewStations] Mark all tiles of a railway station dirty when adding or removing tiles.
peter1138
parents:
4886
diff
changeset
|
146 |
} |
ed65b5e93fbd
(svn r6874) - [NewStations] Mark all tiles of a railway station dirty when adding or removing tiles.
peter1138
parents:
4886
diff
changeset
|
147 |
tile += TileDiffXY(1, 0); |
ed65b5e93fbd
(svn r6874) - [NewStations] Mark all tiles of a railway station dirty when adding or removing tiles.
peter1138
parents:
4886
diff
changeset
|
148 |
} |
ed65b5e93fbd
(svn r6874) - [NewStations] Mark all tiles of a railway station dirty when adding or removing tiles.
peter1138
parents:
4886
diff
changeset
|
149 |
tile += TileDiffXY(-w, 1); |
ed65b5e93fbd
(svn r6874) - [NewStations] Mark all tiles of a railway station dirty when adding or removing tiles.
peter1138
parents:
4886
diff
changeset
|
150 |
} |
ed65b5e93fbd
(svn r6874) - [NewStations] Mark all tiles of a railway station dirty when adding or removing tiles.
peter1138
parents:
4886
diff
changeset
|
151 |
} |
ed65b5e93fbd
(svn r6874) - [NewStations] Mark all tiles of a railway station dirty when adding or removing tiles.
peter1138
parents:
4886
diff
changeset
|
152 |
|
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
153 |
bool Station::TileBelongsToRailStation(TileIndex tile) const |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
154 |
{ |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
155 |
return IsTileType(tile, MP_STATION) && GetStationIndex(tile) == index && IsRailwayStation(tile); |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
156 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
157 |
|
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
158 |
/*static*/ Station *Station::AllocateRaw(void) |
0 | 159 |
{ |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
160 |
Station *st = NULL; |
0 | 161 |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
162 |
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
163 |
* TODO - This is just a temporary stage, this will be removed. */ |
4980 | 164 |
for (st = GetStation(0); st != NULL; st = (st->index + 1U < GetStationPoolSize()) ? GetStation(st->index + 1U) : NULL) { |
6322
3d191e6e89bc
(svn r8707) -Codechange: Turn IsValidStation into a method of Station
celestar
parents:
6316
diff
changeset
|
165 |
if (!st->IsValid()) { |
1551
eb05e6a90e67
(svn r2055) -CodeChange: Begun introducting StationID
celestar
parents:
1527
diff
changeset
|
166 |
StationID index = st->index; |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
167 |
|
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
168 |
memset(st, 0, sizeof(Station)); |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
169 |
st->index = index; |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
170 |
return st; |
0 | 171 |
} |
172 |
} |
|
173 |
||
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
174 |
/* Check if we can add a block to the pool */ |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
175 |
if (AddBlockToPool(&_Station_pool)) return AllocateRaw(); |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
176 |
|
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
177 |
_error_message = STR_3008_TOO_MANY_STATIONS_LOADING; |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
178 |
return NULL; |
0 | 179 |
} |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
180 |
|
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
181 |
|
6324
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
182 |
/** Obtain the length of a platform |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
183 |
* @pre tile must be a railway station tile |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
184 |
* @param tile A tile that contains the platform in question |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
185 |
* @returns The length of the platform |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
186 |
*/ |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
187 |
uint Station::GetPlatformLength(TileIndex tile) const |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
188 |
{ |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
189 |
TileIndex t; |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
190 |
TileIndexDiff delta; |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
191 |
uint len = 0; |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
192 |
assert(TileBelongsToRailStation(tile)); |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
193 |
|
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
194 |
delta = (GetRailStationAxis(tile) == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
195 |
|
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
196 |
t = tile; |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
197 |
do { |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
198 |
t -= delta; |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
199 |
len++; |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
200 |
} while (IsCompatibleTrainStationTile(t, tile)); |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
201 |
|
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
202 |
t = tile; |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
203 |
do { |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
204 |
t += delta; |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
205 |
len++; |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
206 |
} while (IsCompatibleTrainStationTile(t, tile)); |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
207 |
|
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
208 |
return len - 1; |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
209 |
} |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
210 |
|
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
211 |
/** Determines the REMAINING length of a platform, starting at (and including) |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
212 |
* the given tile. |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
213 |
* @param tile the tile from which to start searching. Must be a railway station tile |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
214 |
* @param dir The direction in which to search. |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
215 |
* @return The platform length |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
216 |
*/ |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
217 |
uint Station::GetPlatformLength(TileIndex tile, DiagDirection dir) const |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
218 |
{ |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
219 |
TileIndex start_tile = tile; |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
220 |
uint length = 0; |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
221 |
assert(IsRailwayStationTile(tile)); |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
222 |
assert(dir < DIAGDIR_END); |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
223 |
|
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
224 |
do { |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
225 |
length ++; |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
226 |
tile += TileOffsByDiagDir(dir); |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
227 |
} while (IsCompatibleTrainStationTile(tile, start_tile)); |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
228 |
|
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
229 |
return length; |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
230 |
} |
ebf3649bd88f
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents:
6323
diff
changeset
|
231 |
|
6147
2345f00d2a33
(svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents:
6118
diff
changeset
|
232 |
/** Determines whether a station is a buoy only. |
2345f00d2a33
(svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents:
6118
diff
changeset
|
233 |
* @todo Ditch this encoding of buoys |
2345f00d2a33
(svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents:
6118
diff
changeset
|
234 |
*/ |
2345f00d2a33
(svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents:
6118
diff
changeset
|
235 |
bool Station::IsBuoy() const |
2345f00d2a33
(svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents:
6118
diff
changeset
|
236 |
{ |
6323
cf5e2e4b3156
(svn r8708) -Codechange(r8514): No need to use "this->" in methods
celestar
parents:
6322
diff
changeset
|
237 |
return (had_vehicle_of_type & HVOT_BUOY) != 0; |
6147
2345f00d2a33
(svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents:
6118
diff
changeset
|
238 |
} |
2345f00d2a33
(svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents:
6118
diff
changeset
|
239 |
|
6322
3d191e6e89bc
(svn r8707) -Codechange: Turn IsValidStation into a method of Station
celestar
parents:
6316
diff
changeset
|
240 |
/** Determines whether a station exists |
3d191e6e89bc
(svn r8707) -Codechange: Turn IsValidStation into a method of Station
celestar
parents:
6316
diff
changeset
|
241 |
* @todo replace 0 by INVALID_TILE |
3d191e6e89bc
(svn r8707) -Codechange: Turn IsValidStation into a method of Station
celestar
parents:
6316
diff
changeset
|
242 |
*/ |
3d191e6e89bc
(svn r8707) -Codechange: Turn IsValidStation into a method of Station
celestar
parents:
6316
diff
changeset
|
243 |
bool Station::IsValid() const |
3d191e6e89bc
(svn r8707) -Codechange: Turn IsValidStation into a method of Station
celestar
parents:
6316
diff
changeset
|
244 |
{ |
3d191e6e89bc
(svn r8707) -Codechange: Turn IsValidStation into a method of Station
celestar
parents:
6316
diff
changeset
|
245 |
return xy != 0; |
3d191e6e89bc
(svn r8707) -Codechange: Turn IsValidStation into a method of Station
celestar
parents:
6316
diff
changeset
|
246 |
} |
3d191e6e89bc
(svn r8707) -Codechange: Turn IsValidStation into a method of Station
celestar
parents:
6316
diff
changeset
|
247 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
248 |
|
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
249 |
/************************************************************************/ |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
250 |
/* StationRect implementation */ |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
251 |
/************************************************************************/ |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
252 |
|
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
253 |
StationRect::StationRect() |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
254 |
{ |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
255 |
MakeEmpty(); |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
256 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
257 |
|
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
258 |
void StationRect::MakeEmpty() |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
259 |
{ |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
260 |
left = top = right = bottom = 0; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
261 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
262 |
|
6161
754debc55207
(svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents:
6147
diff
changeset
|
263 |
/** |
754debc55207
(svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents:
6147
diff
changeset
|
264 |
* Determines whether a given point (x, y) is within a certain distance of |
754debc55207
(svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents:
6147
diff
changeset
|
265 |
* the station rectangle. |
754debc55207
(svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents:
6147
diff
changeset
|
266 |
* @note x and y are in Tile coordinates |
754debc55207
(svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents:
6147
diff
changeset
|
267 |
* @param x X coordinate |
754debc55207
(svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents:
6147
diff
changeset
|
268 |
* @param y Y coordinate |
754debc55207
(svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents:
6147
diff
changeset
|
269 |
* @param distance The maxmium distance a point may have (L1 norm) |
754debc55207
(svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents:
6147
diff
changeset
|
270 |
* @return true if the point is within distance tiles of the station rectangle |
754debc55207
(svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents:
6147
diff
changeset
|
271 |
*/ |
754debc55207
(svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents:
6147
diff
changeset
|
272 |
bool StationRect::PtInExtendedRect(int x, int y, int distance) const |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
273 |
{ |
6161
754debc55207
(svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents:
6147
diff
changeset
|
274 |
return (left - distance <= x && x <= right + distance && top - distance <= y && y <= bottom + distance); |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
275 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
276 |
|
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
277 |
bool StationRect::IsEmpty() const |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
278 |
{ |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
279 |
return (left == 0 || left > right || top > bottom); |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
280 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
281 |
|
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
282 |
bool StationRect::BeforeAddTile(TileIndex tile, StationRectMode mode) |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
283 |
{ |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
284 |
int x = TileX(tile); |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
285 |
int y = TileY(tile); |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
286 |
if (IsEmpty()) { |
5929 | 287 |
/* we are adding the first station tile */ |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
288 |
left = right = x; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
289 |
top = bottom = y; |
5929 | 290 |
|
6161
754debc55207
(svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents:
6147
diff
changeset
|
291 |
} else if (!PtInExtendedRect(x, y)) { |
5929 | 292 |
/* current rect is not empty and new point is outside this rect */ |
293 |
/* make new spread-out rectangle */ |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
294 |
Rect new_rect = {min(x, left), min(y, top), max(x, right), max(y, bottom)}; |
5929 | 295 |
|
296 |
/* check new rect dimensions against preset max */ |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
297 |
int w = new_rect.right - new_rect.left + 1; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
298 |
int h = new_rect.bottom - new_rect.top + 1; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
299 |
if (mode != ADD_FORCE && (w > _patches.station_spread || h > _patches.station_spread)) { |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
300 |
assert(mode != ADD_TRY); |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
301 |
_error_message = STR_306C_STATION_TOO_SPREAD_OUT; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
302 |
return false; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
303 |
} |
5929 | 304 |
|
305 |
/* spread-out ok, return true */ |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
306 |
if (mode != ADD_TEST) { |
5929 | 307 |
/* we should update the station rect */ |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
308 |
*this = new_rect; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
309 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
310 |
} else { |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
311 |
; // new point is inside the rect, we don't need to do anything |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
312 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
313 |
return true; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
314 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
315 |
|
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
316 |
bool StationRect::BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode) |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
317 |
{ |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
318 |
return BeforeAddTile(tile, mode) && BeforeAddTile(TILE_ADDXY(tile, w - 1, h - 1), mode); |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
319 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
320 |
|
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
321 |
/*static*/ bool StationRect::ScanForStationTiles(StationID st_id, int left_a, int top_a, int right_a, int bottom_a) |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
322 |
{ |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
323 |
TileIndex top_left = TileXY(left_a, top_a); |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
324 |
int width = right_a - left_a + 1; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
325 |
int height = bottom_a - top_a + 1; |
5929 | 326 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
327 |
BEGIN_TILE_LOOP(tile, width, height, top_left) |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
328 |
if (IsTileType(tile, MP_STATION) && GetStationIndex(tile) == st_id) return true; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
329 |
END_TILE_LOOP(tile, width, height, top_left); |
5929 | 330 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
331 |
return false; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
332 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
333 |
|
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
334 |
bool StationRect::AfterRemoveTile(Station *st, TileIndex tile) |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
335 |
{ |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
336 |
int x = TileX(tile); |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
337 |
int y = TileY(tile); |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
338 |
|
5929 | 339 |
/* look if removed tile was on the bounding rect edge |
340 |
* and try to reduce the rect by this edge |
|
341 |
* do it until we have empty rect or nothing to do */ |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
342 |
for (;;) { |
5929 | 343 |
/* check if removed tile is on rect edge */ |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
344 |
bool left_edge = (x == left); |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
345 |
bool right_edge = (x == right); |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
346 |
bool top_edge = (y == top); |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
347 |
bool bottom_edge = (y == bottom); |
5929 | 348 |
|
349 |
/* can we reduce the rect in either direction? */ |
|
350 |
bool reduce_x = ((left_edge || right_edge) && !ScanForStationTiles(st->index, x, top, x, bottom)); |
|
351 |
bool reduce_y = ((top_edge || bottom_edge) && !ScanForStationTiles(st->index, left, y, right, y)); |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
352 |
if (!(reduce_x || reduce_y)) break; // nothing to do (can't reduce) |
5929 | 353 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
354 |
if (reduce_x) { |
5929 | 355 |
/* reduce horizontally */ |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
356 |
if (left_edge) { |
5929 | 357 |
/* move left edge right */ |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
358 |
left = x = x + 1; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
359 |
} else { |
5929 | 360 |
/* move right edge left */ |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
361 |
right = x = x - 1; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
362 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
363 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
364 |
if (reduce_y) { |
5929 | 365 |
/* reduce vertically */ |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
366 |
if (top_edge) { |
5929 | 367 |
/* move top edge down */ |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
368 |
top = y = y + 1; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
369 |
} else { |
5929 | 370 |
/* move bottom edge up */ |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
371 |
bottom = y = y - 1; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
372 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
373 |
} |
5929 | 374 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
375 |
if (left > right || top > bottom) { |
5929 | 376 |
/* can't continue, if the remaining rectangle is empty */ |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
377 |
MakeEmpty(); |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
378 |
return true; // empty remaining rect |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
379 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
380 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
381 |
return false; // non-empty remaining rect |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
382 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
383 |
|
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
384 |
bool StationRect::AfterRemoveRect(Station *st, TileIndex tile, int w, int h) |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
385 |
{ |
6161
754debc55207
(svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents:
6147
diff
changeset
|
386 |
assert(PtInExtendedRect(TileX(tile), TileY(tile))); |
754debc55207
(svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents:
6147
diff
changeset
|
387 |
assert(PtInExtendedRect(TileX(tile) + w - 1, TileY(tile) + h - 1)); |
5929 | 388 |
|
389 |
bool empty = AfterRemoveTile(st, tile); |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
390 |
if (w != 1 || h != 1) empty = empty || AfterRemoveTile(st, TILE_ADDXY(tile, w - 1, h - 1)); |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
391 |
return empty; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
392 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
393 |
|
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
394 |
StationRect& StationRect::operator = (Rect src) |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
395 |
{ |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
396 |
left = src.left; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
397 |
top = src.top; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
398 |
right = src.right; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
399 |
bottom = src.bottom; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
400 |
return *this; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
401 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
402 |
|
5959
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
403 |
|
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
404 |
/************************************************************************/ |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
405 |
/* RoadStop implementation */ |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
406 |
/************************************************************************/ |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
407 |
|
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
408 |
/** Allocates a new RoadStop onto the pool, or recycles an unsed one |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
409 |
* @return a pointer to the new roadstop |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
410 |
*/ |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
411 |
void *RoadStop::operator new(size_t size) |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
412 |
{ |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
413 |
RoadStop *rs = AllocateRaw(); |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
414 |
return rs; |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
415 |
} |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
416 |
|
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
417 |
/** Gets a RoadStop with a given index and allocates it when needed |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
418 |
* @return a pointer to the roadstop |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
419 |
*/ |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
420 |
void *RoadStop::operator new(size_t size, int index) |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
421 |
{ |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
422 |
if (!AddBlockIfNeeded(&_RoadStop_pool, index)) { |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
423 |
error("RoadStops: failed loading savegame: too many RoadStops"); |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
424 |
} |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
425 |
|
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
426 |
RoadStop *rs = GetRoadStop(index); |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
427 |
return rs; |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
428 |
} |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
429 |
|
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
430 |
void RoadStop::operator delete(void *p) |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
431 |
{ |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
432 |
} |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
433 |
|
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
434 |
void RoadStop::operator delete(void *p, int index) |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
435 |
{ |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
436 |
} |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
437 |
|
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
438 |
/** Initializes a RoadStop */ |
5967 | 439 |
RoadStop::RoadStop(TileIndex tile) : |
5964 | 440 |
xy(tile), |
441 |
status(3), // stop is free |
|
442 |
num_vehicles(0), |
|
6118 | 443 |
next(NULL) |
5959
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
444 |
{ |
5967 | 445 |
DEBUG(ms, cDebugCtorLevel, "I+ at %d[0x%x]", tile, tile); |
5959
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
446 |
} |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
447 |
|
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
448 |
/** De-Initializes a RoadStops. This includes clearing all slots that vehicles might |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
449 |
* have and unlinks it from the linked list of road stops at the given station |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
450 |
*/ |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
451 |
RoadStop::~RoadStop() |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
452 |
{ |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
453 |
/* Clear the slot assignment of all vehicles heading for this road stop */ |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
454 |
if (num_vehicles != 0) { |
5964 | 455 |
Vehicle *v; |
456 |
||
5959
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
457 |
FOR_ALL_VEHICLES(v) { |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
458 |
if (v->type == VEH_Road && v->u.road.slot == this) ClearSlot(v); |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
459 |
} |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
460 |
} |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
461 |
assert(num_vehicles == 0); |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
462 |
|
5967 | 463 |
DEBUG(ms, cDebugCtorLevel , "I- at %d[0x%x]", xy, xy); |
5959
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
464 |
|
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
465 |
xy = INVALID_TILE; |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
466 |
} |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
467 |
|
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
468 |
|
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
469 |
/** Low-level function for allocating a RoadStop on the pool */ |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
470 |
RoadStop *RoadStop::AllocateRaw( void ) |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
471 |
{ |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
472 |
RoadStop *rs; |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
473 |
|
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
474 |
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
475 |
* TODO - This is just a temporary stage, this will be removed. */ |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
476 |
for (rs = GetRoadStop(0); rs != NULL; rs = (rs->index + 1U < GetRoadStopPoolSize()) ? GetRoadStop(rs->index + 1U) : NULL) { |
6086
61742a8471f5
(svn r8401) -Codechange: Make 'IsValidRoadStop' a method of RoadStop and rename it to 'IsValid'
celestar
parents:
5972
diff
changeset
|
477 |
if (!rs->IsValid()) { |
5959
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
478 |
RoadStopID index = rs->index; |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
479 |
|
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
480 |
memset(rs, 0, sizeof(*rs)); |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
481 |
rs->index = index; |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
482 |
|
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
483 |
return rs; |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
484 |
} |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
485 |
} |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
486 |
|
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
487 |
/* Check if we can add a block to the pool */ |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
488 |
if (AddBlockToPool(&_RoadStop_pool)) return AllocateRaw(); |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
489 |
|
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
490 |
return NULL; |
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5929
diff
changeset
|
491 |
} |
6086
61742a8471f5
(svn r8401) -Codechange: Make 'IsValidRoadStop' a method of RoadStop and rename it to 'IsValid'
celestar
parents:
5972
diff
changeset
|
492 |
|
61742a8471f5
(svn r8401) -Codechange: Make 'IsValidRoadStop' a method of RoadStop and rename it to 'IsValid'
celestar
parents:
5972
diff
changeset
|
493 |
/** Determines whether a RoadStop is a valid (i.e. existing) one */ |
61742a8471f5
(svn r8401) -Codechange: Make 'IsValidRoadStop' a method of RoadStop and rename it to 'IsValid'
celestar
parents:
5972
diff
changeset
|
494 |
bool RoadStop::IsValid() const |
61742a8471f5
(svn r8401) -Codechange: Make 'IsValidRoadStop' a method of RoadStop and rename it to 'IsValid'
celestar
parents:
5972
diff
changeset
|
495 |
{ |
61742a8471f5
(svn r8401) -Codechange: Make 'IsValidRoadStop' a method of RoadStop and rename it to 'IsValid'
celestar
parents:
5972
diff
changeset
|
496 |
return xy != INVALID_TILE; |
61742a8471f5
(svn r8401) -Codechange: Make 'IsValidRoadStop' a method of RoadStop and rename it to 'IsValid'
celestar
parents:
5972
diff
changeset
|
497 |
} |
6316
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
498 |
|
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
499 |
/** Checks whether there is a free bay in this road stop */ |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
500 |
bool RoadStop::HasFreeBay() const |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
501 |
{ |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
502 |
return GB(status, 0, MAX_BAY_COUNT) != 0; |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
503 |
} |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
504 |
|
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6331
diff
changeset
|
505 |
/** Checks whether the given bay is free in this road stop */ |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6331
diff
changeset
|
506 |
bool RoadStop::IsFreeBay(uint nr) const |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6331
diff
changeset
|
507 |
{ |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6331
diff
changeset
|
508 |
assert(nr < MAX_BAY_COUNT); |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6331
diff
changeset
|
509 |
return HASBIT(status, nr); |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6331
diff
changeset
|
510 |
} |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6331
diff
changeset
|
511 |
|
6316
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
512 |
/** |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
513 |
* Allocates a bay |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
514 |
* @return the allocated bay number |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
515 |
* @pre this->HasFreeBay() |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
516 |
*/ |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
517 |
uint RoadStop::AllocateBay() |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
518 |
{ |
6331
9bc486e6cd0d
(svn r8726) -Codechange: bools are 1 or 0 according to the C++ standard and refactor RoadStop::AllocateBay to remove a loop condition. Suggestions by Tron.
rubidium
parents:
6324
diff
changeset
|
519 |
assert(HasFreeBay()); |
9bc486e6cd0d
(svn r8726) -Codechange: bools are 1 or 0 according to the C++ standard and refactor RoadStop::AllocateBay to remove a loop condition. Suggestions by Tron.
rubidium
parents:
6324
diff
changeset
|
520 |
|
6316
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
521 |
/* Find the first free bay. If the bit is set, the bay is free. */ |
6331
9bc486e6cd0d
(svn r8726) -Codechange: bools are 1 or 0 according to the C++ standard and refactor RoadStop::AllocateBay to remove a loop condition. Suggestions by Tron.
rubidium
parents:
6324
diff
changeset
|
522 |
uint bay_nr = 0; |
9bc486e6cd0d
(svn r8726) -Codechange: bools are 1 or 0 according to the C++ standard and refactor RoadStop::AllocateBay to remove a loop condition. Suggestions by Tron.
rubidium
parents:
6324
diff
changeset
|
523 |
while (!HASBIT(status, bay_nr)) bay_nr++; |
6316
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
524 |
|
6331
9bc486e6cd0d
(svn r8726) -Codechange: bools are 1 or 0 according to the C++ standard and refactor RoadStop::AllocateBay to remove a loop condition. Suggestions by Tron.
rubidium
parents:
6324
diff
changeset
|
525 |
CLRBIT(status, bay_nr); |
9bc486e6cd0d
(svn r8726) -Codechange: bools are 1 or 0 according to the C++ standard and refactor RoadStop::AllocateBay to remove a loop condition. Suggestions by Tron.
rubidium
parents:
6324
diff
changeset
|
526 |
return bay_nr; |
6316
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
527 |
} |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
528 |
|
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
529 |
/** |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6331
diff
changeset
|
530 |
* Allocates a bay in a drive-through road stop |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6331
diff
changeset
|
531 |
* @param nr the number of the bay to allocate |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6331
diff
changeset
|
532 |
*/ |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6331
diff
changeset
|
533 |
void RoadStop::AllocateDriveThroughBay(uint nr) |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6331
diff
changeset
|
534 |
{ |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6331
diff
changeset
|
535 |
assert(nr < MAX_BAY_COUNT); |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6331
diff
changeset
|
536 |
CLRBIT(status, nr); |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6331
diff
changeset
|
537 |
} |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6331
diff
changeset
|
538 |
|
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6331
diff
changeset
|
539 |
/** |
6316
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
540 |
* Frees the given bay |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
541 |
* @param nr the number of the bay to free |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
542 |
*/ |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
543 |
void RoadStop::FreeBay(uint nr) |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
544 |
{ |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
545 |
assert(nr < MAX_BAY_COUNT); |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
546 |
SETBIT(status, nr); |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
547 |
} |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
548 |
|
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
549 |
|
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
550 |
/** Checks whether the entrance of the road stop is occupied by a vehicle */ |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
551 |
bool RoadStop::IsEntranceBusy() const |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
552 |
{ |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
553 |
return HASBIT(status, 7); |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
554 |
} |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
555 |
|
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
556 |
/** Makes an entrance occupied or free */ |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
557 |
void RoadStop::SetEntranceBusy(bool busy) |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
558 |
{ |
6331
9bc486e6cd0d
(svn r8726) -Codechange: bools are 1 or 0 according to the C++ standard and refactor RoadStop::AllocateBay to remove a loop condition. Suggestions by Tron.
rubidium
parents:
6324
diff
changeset
|
559 |
SB(status, 7, 1, busy); |
6316
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
560 |
} |