author | Tero Marttila <terom@fixme.fi> |
Fri, 18 Jul 2008 21:28:42 +0300 | |
changeset 11175 | 020c61e39c94 |
parent 10775 | 7061477bfbcf |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
10429
1b99254f9607
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
10321
diff
changeset
|
3 |
/** @file station.cpp Implementation of the station base class. */ |
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" |
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
9 |
#include "station_map.h" |
9281
d8cd9ac52a68
(svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents:
9280
diff
changeset
|
10 |
#include "station_base.h" |
0 | 11 |
#include "town.h" |
12 |
#include "saveload.h" |
|
8750
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8721
diff
changeset
|
13 |
#include "player_func.h" |
0 | 14 |
#include "airport.h" |
405
6830ae7a0d5d
(svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents:
403
diff
changeset
|
15 |
#include "sprite.h" |
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2671
diff
changeset
|
16 |
#include "train.h" |
3111
1edf71aa942e
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3102
diff
changeset
|
17 |
#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
|
18 |
#include "industry_map.h" |
3754
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
19 |
#include "newgrf_callbacks.h" |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
20 |
#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
|
21 |
#include "yapf/yapf.h" |
7965
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
22 |
#include "cargotype.h" |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
23 |
#include "roadveh.h" |
10321
6d58c7470699
(svn r12862) -Codechange: reduce code duplication for VehicleType -> WindowClass lookup
smatz
parents:
10222
diff
changeset
|
24 |
#include "window_type.h" |
8512
e77c8fb7c0ed
(svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents:
8427
diff
changeset
|
25 |
#include "station_gui.h" |
8619
c2434269c3eb
(svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents:
8617
diff
changeset
|
26 |
#include "zoom_func.h" |
8627
448ebf3a8291
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents:
8626
diff
changeset
|
27 |
#include "functions.h" |
448ebf3a8291
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents:
8626
diff
changeset
|
28 |
#include "window_func.h" |
8636
2b158acb649c
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents:
8635
diff
changeset
|
29 |
#include "date_func.h" |
8707
55835d8fbfcd
(svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents:
8640
diff
changeset
|
30 |
#include "variables.h" |
8766
c86cfa3a7580
(svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents:
8760
diff
changeset
|
31 |
#include "settings_type.h" |
8771
f7ad4dba14bf
(svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents:
8766
diff
changeset
|
32 |
#include "command_func.h" |
9280
9c03416d26b1
(svn r12488) -Codechange: split order.h into order_base.h and order_func.h.
rubidium
parents:
9259
diff
changeset
|
33 |
#include "order_func.h" |
0 | 34 |
|
8760
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8754
diff
changeset
|
35 |
#include "table/sprites.h" |
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8754
diff
changeset
|
36 |
#include "table/strings.h" |
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8754
diff
changeset
|
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 |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6573
diff
changeset
|
51 |
last_vehicle_type = VEH_INVALID; |
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
|
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 |
/** |
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6585
diff
changeset
|
58 |
* Clean up a station by clearing vehicle orders and invalidating windows. |
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6585
diff
changeset
|
59 |
* Aircraft-Hangar orders need special treatment here, as the hangars are |
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6585
diff
changeset
|
60 |
* actually part of a station (tiletype is STATION), but the order type |
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6585
diff
changeset
|
61 |
* is OT_GOTO_DEPOT. |
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6585
diff
changeset
|
62 |
*/ |
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
|
63 |
Station::~Station() |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
64 |
{ |
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
|
65 |
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
|
66 |
|
8754
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
67 |
free(this->name); |
7909
8df54a2839a1
(svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents:
7873
diff
changeset
|
68 |
free(this->speclist); |
8df54a2839a1
(svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents:
7873
diff
changeset
|
69 |
|
8df54a2839a1
(svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents:
7873
diff
changeset
|
70 |
if (CleaningPool()) return; |
8df54a2839a1
(svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents:
7873
diff
changeset
|
71 |
|
7949
1fcfd903d923
(svn r10931) -Fix [FS#1131]: when a station was destroyed and a vehicle was still loading, changing the current order of the loading vehicle caused a crash. This could happen with removing docks and oil rigs.
rubidium
parents:
7916
diff
changeset
|
72 |
while (!loading_vehicles.empty()) { |
1fcfd903d923
(svn r10931) -Fix [FS#1131]: when a station was destroyed and a vehicle was still loading, changing the current order of the loading vehicle caused a crash. This could happen with removing docks and oil rigs.
rubidium
parents:
7916
diff
changeset
|
73 |
loading_vehicles.front()->LeaveStation(); |
1fcfd903d923
(svn r10931) -Fix [FS#1131]: when a station was destroyed and a vehicle was still loading, changing the current order of the loading vehicle caused a crash. This could happen with removing docks and oil rigs.
rubidium
parents:
7916
diff
changeset
|
74 |
} |
1fcfd903d923
(svn r10931) -Fix [FS#1131]: when a station was destroyed and a vehicle was still loading, changing the current order of the loading vehicle caused a crash. This could happen with removing docks and oil rigs.
rubidium
parents:
7916
diff
changeset
|
75 |
|
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
|
76 |
MarkDirty(); |
10621
3edd349d9c14
(svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium
parents:
10429
diff
changeset
|
77 |
InvalidateWindowData(WC_STATION_LIST, this->owner, 0); |
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
|
78 |
|
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 |
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
|
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 |
/* 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
|
82 |
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
|
83 |
|
5929 | 84 |
/* 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
|
85 |
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
|
86 |
|
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 |
xy = 0; |
7506
e52d89f5c7c1
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
7319
diff
changeset
|
88 |
|
e52d89f5c7c1
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
7319
diff
changeset
|
89 |
for (CargoID c = 0; c < NUM_CARGO; c++) { |
e52d89f5c7c1
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
7319
diff
changeset
|
90 |
goods[c].cargo.Truncate(0); |
e52d89f5c7c1
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
7319
diff
changeset
|
91 |
} |
7872
a0646ade9d4a
(svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents:
7506
diff
changeset
|
92 |
} |
a0646ade9d4a
(svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents:
7506
diff
changeset
|
93 |
|
7965
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
94 |
|
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
95 |
/** |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
96 |
* Get the primary road stop (the first road stop) that the given vehicle can load/unload. |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
97 |
* @param v the vehicle to get the first road stop for |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
98 |
* @return the first roadstop that this vehicle can load at |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
99 |
*/ |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
100 |
RoadStop *Station::GetPrimaryRoadStop(const Vehicle *v) const |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
101 |
{ |
9281
d8cd9ac52a68
(svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents:
9280
diff
changeset
|
102 |
RoadStop *rs = this->GetPrimaryRoadStop(IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? ROADSTOP_BUS : ROADSTOP_TRUCK); |
7965
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
103 |
|
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
104 |
for (; rs != NULL; rs = rs->next) { |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
105 |
/* The vehicle cannot go to this roadstop (different roadtype) */ |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
106 |
if ((GetRoadTypes(rs->xy) & v->u.road.compatible_roadtypes) == ROADTYPES_NONE) continue; |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
107 |
/* The vehicle is articulated and can therefor not go the a standard road stop */ |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
108 |
if (IsStandardRoadStopTile(rs->xy) && RoadVehHasArticPart(v)) continue; |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
109 |
|
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
110 |
/* The vehicle can actually go to this road stop. So, return it! */ |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
111 |
break; |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
112 |
} |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
113 |
|
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
114 |
return rs; |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
115 |
} |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
116 |
|
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
|
117 |
/** Called when new facility is built on the station. If it is the first facility |
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6585
diff
changeset
|
118 |
* it initializes also 'xy' and 'random_bits' members */ |
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
|
119 |
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
|
120 |
{ |
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
|
121 |
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
|
122 |
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
|
123 |
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
|
124 |
} |
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
|
125 |
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
|
126 |
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
|
127 |
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
|
128 |
} |
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
|
129 |
|
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
|
130 |
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
|
131 |
{ |
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
|
132 |
if (sign.width_1 != 0) { |
8512
e77c8fb7c0ed
(svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents:
8427
diff
changeset
|
133 |
InvalidateWindowWidget(WC_STATION_VIEW, index, SVW_CAPTION); |
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 |
|
7196
2659a044f6f7
(svn r9932) -Fix: can't assume a zoom-level with MarkAllViewportsDirty, causing segfaults when trying to load savegames in dedicated server via -g (reported by peter1138)
truelight
parents:
7149
diff
changeset
|
135 |
/* We use ZOOM_LVL_MAX here, as every viewport can have an other zoom, |
2659a044f6f7
(svn r9932) -Fix: can't assume a zoom-level with MarkAllViewportsDirty, causing segfaults when trying to load savegames in dedicated server via -g (reported by peter1138)
truelight
parents:
7149
diff
changeset
|
136 |
* and there is no way for us to know which is the biggest. So make the |
2659a044f6f7
(svn r9932) -Fix: can't assume a zoom-level with MarkAllViewportsDirty, causing segfaults when trying to load savegames in dedicated server via -g (reported by peter1138)
truelight
parents:
7149
diff
changeset
|
137 |
* biggest area dirty, and we are safe for sure. */ |
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
|
138 |
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
|
139 |
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
|
140 |
sign.top, |
7196
2659a044f6f7
(svn r9932) -Fix: can't assume a zoom-level with MarkAllViewportsDirty, causing segfaults when trying to load savegames in dedicated server via -g (reported by peter1138)
truelight
parents:
7149
diff
changeset
|
141 |
sign.left + ScaleByZoom(sign.width_1 + 12, ZOOM_LVL_MAX), |
2659a044f6f7
(svn r9932) -Fix: can't assume a zoom-level with MarkAllViewportsDirty, causing segfaults when trying to load savegames in dedicated server via -g (reported by peter1138)
truelight
parents:
7149
diff
changeset
|
142 |
sign.top + ScaleByZoom(12, ZOOM_LVL_MAX)); |
3587 | 143 |
} |
144 |
} |
|
145 |
||
7319
f884be171f04
(svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138
parents:
7196
diff
changeset
|
146 |
void Station::MarkTilesDirty(bool cargo_change) const |
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
147 |
{ |
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
|
148 |
TileIndex tile = train_tile; |
4910
ed97a9239b11
(svn r6881) -Fix r6874: uint > int to remove signedness warning MSVC (peter1138)
Darkvater
parents:
4904
diff
changeset
|
149 |
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
|
150 |
|
5929 | 151 |
/* 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
|
152 |
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
|
153 |
|
7319
f884be171f04
(svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138
parents:
7196
diff
changeset
|
154 |
/* cargo_change is set if we're refreshing the tiles due to cargo moving |
f884be171f04
(svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138
parents:
7196
diff
changeset
|
155 |
* around. */ |
f884be171f04
(svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138
parents:
7196
diff
changeset
|
156 |
if (cargo_change) { |
f884be171f04
(svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138
parents:
7196
diff
changeset
|
157 |
/* Don't waste time updating if there are no custom station graphics |
f884be171f04
(svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138
parents:
7196
diff
changeset
|
158 |
* that might change. Even if there are custom graphics, they might |
f884be171f04
(svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138
parents:
7196
diff
changeset
|
159 |
* not change. Unfortunately we have no way of telling. */ |
f884be171f04
(svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138
parents:
7196
diff
changeset
|
160 |
if (this->num_specs == 0) return; |
f884be171f04
(svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138
parents:
7196
diff
changeset
|
161 |
} |
f884be171f04
(svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138
parents:
7196
diff
changeset
|
162 |
|
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
|
163 |
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
|
164 |
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
|
165 |
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
|
166 |
MarkTileDirtyByTile(tile); |
ed65b5e93fbd
(svn r6874) - [NewStations] Mark all tiles of a railway station dirty when adding or removing tiles.
peter1138
parents:
4886
diff
changeset
|
167 |
} |
ed65b5e93fbd
(svn r6874) - [NewStations] Mark all tiles of a railway station dirty when adding or removing tiles.
peter1138
parents:
4886
diff
changeset
|
168 |
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
|
169 |
} |
ed65b5e93fbd
(svn r6874) - [NewStations] Mark all tiles of a railway station dirty when adding or removing tiles.
peter1138
parents:
4886
diff
changeset
|
170 |
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
|
171 |
} |
ed65b5e93fbd
(svn r6874) - [NewStations] Mark all tiles of a railway station dirty when adding or removing tiles.
peter1138
parents:
4886
diff
changeset
|
172 |
} |
ed65b5e93fbd
(svn r6874) - [NewStations] Mark all tiles of a railway station dirty when adding or removing tiles.
peter1138
parents:
4886
diff
changeset
|
173 |
|
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
|
174 |
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
|
175 |
{ |
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
|
176 |
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
|
177 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
178 |
|
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
|
179 |
/** 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
|
180 |
* @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
|
181 |
* @param tile A tile that contains the platform in question |
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6585
diff
changeset
|
182 |
* @return The length of the platform |
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
|
183 |
*/ |
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 |
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
|
185 |
{ |
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 |
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
|
187 |
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
|
188 |
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
|
189 |
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
|
190 |
|
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 |
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
|
192 |
|
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 |
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
|
194 |
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
|
195 |
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
|
196 |
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
|
197 |
} 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
|
198 |
|
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 |
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
|
200 |
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
|
201 |
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
|
202 |
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
|
203 |
} 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
|
204 |
|
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 |
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
|
206 |
} |
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 |
/** 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
|
209 |
* 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
|
210 |
* @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
|
211 |
* @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
|
212 |
* @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
|
213 |
*/ |
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 |
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
|
215 |
{ |
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 |
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
|
217 |
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
|
218 |
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
|
219 |
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
|
220 |
|
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 |
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
|
222 |
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
|
223 |
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
|
224 |
} 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
|
225 |
|
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 |
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
|
227 |
} |
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 |
|
6147
2345f00d2a33
(svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents:
6118
diff
changeset
|
229 |
/** Determines whether a station is a buoy only. |
2345f00d2a33
(svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents:
6118
diff
changeset
|
230 |
* @todo Ditch this encoding of buoys |
2345f00d2a33
(svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents:
6118
diff
changeset
|
231 |
*/ |
2345f00d2a33
(svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents:
6118
diff
changeset
|
232 |
bool Station::IsBuoy() const |
2345f00d2a33
(svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents:
6118
diff
changeset
|
233 |
{ |
6323
cf5e2e4b3156
(svn r8708) -Codechange(r8514): No need to use "this->" in methods
celestar
parents:
6322
diff
changeset
|
234 |
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
|
235 |
} |
2345f00d2a33
(svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents:
6118
diff
changeset
|
236 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
237 |
|
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
238 |
/************************************************************************/ |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
239 |
/* StationRect implementation */ |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
240 |
/************************************************************************/ |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
241 |
|
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
242 |
StationRect::StationRect() |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
243 |
{ |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
244 |
MakeEmpty(); |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
245 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
246 |
|
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
247 |
void StationRect::MakeEmpty() |
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 |
left = top = right = bottom = 0; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
250 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
251 |
|
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
|
252 |
/** |
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
|
253 |
* 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
|
254 |
* 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
|
255 |
* @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
|
256 |
* @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
|
257 |
* @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
|
258 |
* @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
|
259 |
* @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
|
260 |
*/ |
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
|
261 |
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
|
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 |
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
|
264 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
265 |
|
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
266 |
bool StationRect::IsEmpty() const |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
267 |
{ |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
268 |
return (left == 0 || left > right || top > bottom); |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
269 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
270 |
|
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
271 |
bool StationRect::BeforeAddTile(TileIndex tile, StationRectMode mode) |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
272 |
{ |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
273 |
int x = TileX(tile); |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
274 |
int y = TileY(tile); |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
275 |
if (IsEmpty()) { |
5929 | 276 |
/* 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
|
277 |
left = right = x; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
278 |
top = bottom = y; |
5929 | 279 |
|
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
|
280 |
} else if (!PtInExtendedRect(x, y)) { |
5929 | 281 |
/* current rect is not empty and new point is outside this rect */ |
282 |
/* make new spread-out rectangle */ |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
283 |
Rect new_rect = {min(x, left), min(y, top), max(x, right), max(y, bottom)}; |
5929 | 284 |
|
285 |
/* 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
|
286 |
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
|
287 |
int h = new_rect.bottom - new_rect.top + 1; |
10775
7061477bfbcf
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
10703
diff
changeset
|
288 |
if (mode != ADD_FORCE && (w > _settings_game.station.station_spread || h > _settings_game.station.station_spread)) { |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
289 |
assert(mode != ADD_TRY); |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
290 |
_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
|
291 |
return false; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
292 |
} |
5929 | 293 |
|
294 |
/* spread-out ok, return true */ |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
295 |
if (mode != ADD_TEST) { |
5929 | 296 |
/* we should update the station rect */ |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
297 |
*this = new_rect; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
298 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
299 |
} else { |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
300 |
; // 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
|
301 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
302 |
return true; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
303 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
304 |
|
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
305 |
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
|
306 |
{ |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
307 |
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
|
308 |
} |
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 |
/*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
|
311 |
{ |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
312 |
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
|
313 |
int width = right_a - left_a + 1; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
314 |
int height = bottom_a - top_a + 1; |
5929 | 315 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
316 |
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
|
317 |
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
|
318 |
END_TILE_LOOP(tile, width, height, top_left); |
5929 | 319 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
320 |
return false; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
321 |
} |
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 |
bool StationRect::AfterRemoveTile(Station *st, TileIndex tile) |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
324 |
{ |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
325 |
int x = TileX(tile); |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
326 |
int y = TileY(tile); |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
327 |
|
5929 | 328 |
/* look if removed tile was on the bounding rect edge |
329 |
* and try to reduce the rect by this edge |
|
330 |
* 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
|
331 |
for (;;) { |
5929 | 332 |
/* 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
|
333 |
bool left_edge = (x == left); |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
334 |
bool right_edge = (x == right); |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
335 |
bool top_edge = (y == top); |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
336 |
bool bottom_edge = (y == bottom); |
5929 | 337 |
|
338 |
/* can we reduce the rect in either direction? */ |
|
339 |
bool reduce_x = ((left_edge || right_edge) && !ScanForStationTiles(st->index, x, top, x, bottom)); |
|
340 |
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
|
341 |
if (!(reduce_x || reduce_y)) break; // nothing to do (can't reduce) |
5929 | 342 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
343 |
if (reduce_x) { |
5929 | 344 |
/* reduce horizontally */ |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
345 |
if (left_edge) { |
5929 | 346 |
/* move left edge right */ |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
347 |
left = x = x + 1; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
348 |
} else { |
5929 | 349 |
/* move right edge left */ |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
350 |
right = x = x - 1; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
351 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
352 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
353 |
if (reduce_y) { |
5929 | 354 |
/* reduce vertically */ |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
355 |
if (top_edge) { |
5929 | 356 |
/* move top edge down */ |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
357 |
top = y = y + 1; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
358 |
} else { |
5929 | 359 |
/* move bottom edge up */ |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
360 |
bottom = y = y - 1; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
361 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
362 |
} |
5929 | 363 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
364 |
if (left > right || top > bottom) { |
5929 | 365 |
/* 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
|
366 |
MakeEmpty(); |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
367 |
return true; // empty remaining rect |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
368 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
369 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
370 |
return false; // non-empty remaining rect |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
371 |
} |
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 |
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
|
374 |
{ |
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
|
375 |
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
|
376 |
assert(PtInExtendedRect(TileX(tile) + w - 1, TileY(tile) + h - 1)); |
5929 | 377 |
|
378 |
bool empty = AfterRemoveTile(st, tile); |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
379 |
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
|
380 |
return empty; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
381 |
} |
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 |
StationRect& StationRect::operator = (Rect src) |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
384 |
{ |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
385 |
left = src.left; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
386 |
top = src.top; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
387 |
right = src.right; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
388 |
bottom = src.bottom; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
389 |
return *this; |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
390 |
} |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5921
diff
changeset
|
391 |
|
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
|
392 |
|
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
|
393 |
/************************************************************************/ |
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
|
394 |
/* 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
|
395 |
/************************************************************************/ |
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
|
396 |
|
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
|
397 |
/** Initializes a RoadStop */ |
5967 | 398 |
RoadStop::RoadStop(TileIndex tile) : |
5964 | 399 |
xy(tile), |
400 |
status(3), // stop is free |
|
401 |
num_vehicles(0), |
|
6118 | 402 |
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
|
403 |
{ |
5967 | 404 |
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
|
405 |
} |
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 |
/** 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
|
408 |
* 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
|
409 |
*/ |
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 |
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
|
411 |
{ |
7916
8bc57ab02de6
(svn r10813) -Fix (r10799): some destructors were performing too much during the pool cleanups, which could cause crashes as already removed pool items could then be dereferenced by other destructors.
rubidium
parents:
7909
diff
changeset
|
412 |
if (CleaningPool()) return; |
8bc57ab02de6
(svn r10813) -Fix (r10799): some destructors were performing too much during the pool cleanups, which could cause crashes as already removed pool items could then be dereferenced by other destructors.
rubidium
parents:
7909
diff
changeset
|
413 |
|
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
|
414 |
/* 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
|
415 |
if (num_vehicles != 0) { |
5964 | 416 |
Vehicle *v; |
417 |
||
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
|
418 |
FOR_ALL_VEHICLES(v) { |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6573
diff
changeset
|
419 |
if (v->type == VEH_ROAD && v->u.road.slot == this) ClearSlot(v); |
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
|
420 |
} |
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 |
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
|
423 |
|
5967 | 424 |
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
|
425 |
|
7873
b3bccdcf85ef
(svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents:
7872
diff
changeset
|
426 |
xy = 0; |
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
|
427 |
} |
6086
61742a8471f5
(svn r8401) -Codechange: Make 'IsValidRoadStop' a method of RoadStop and rename it to 'IsValid'
celestar
parents:
5972
diff
changeset
|
428 |
|
6316
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
429 |
/** 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
|
430 |
bool RoadStop::HasFreeBay() const |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
431 |
{ |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
432 |
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
|
433 |
} |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
434 |
|
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6331
diff
changeset
|
435 |
/** 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
|
436 |
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
|
437 |
{ |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6331
diff
changeset
|
438 |
assert(nr < MAX_BAY_COUNT); |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7992
diff
changeset
|
439 |
return HasBit(status, nr); |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6331
diff
changeset
|
440 |
} |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6331
diff
changeset
|
441 |
|
6316
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
442 |
/** |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
443 |
* Allocates a bay |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
444 |
* @return the allocated bay number |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
445 |
* @pre this->HasFreeBay() |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
446 |
*/ |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
447 |
uint RoadStop::AllocateBay() |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
448 |
{ |
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
|
449 |
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
|
450 |
|
6316
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
451 |
/* 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
|
452 |
uint bay_nr = 0; |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7992
diff
changeset
|
453 |
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
|
454 |
|
8425
72a71d480c5f
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents:
8424
diff
changeset
|
455 |
ClrBit(status, bay_nr); |
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
|
456 |
return bay_nr; |
6316
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
457 |
} |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
458 |
|
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
459 |
/** |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6331
diff
changeset
|
460 |
* 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
|
461 |
* @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
|
462 |
*/ |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6331
diff
changeset
|
463 |
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
|
464 |
{ |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6331
diff
changeset
|
465 |
assert(nr < MAX_BAY_COUNT); |
8425
72a71d480c5f
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents:
8424
diff
changeset
|
466 |
ClrBit(status, nr); |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6331
diff
changeset
|
467 |
} |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6331
diff
changeset
|
468 |
|
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6331
diff
changeset
|
469 |
/** |
6316
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
470 |
* Frees the given bay |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
471 |
* @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
|
472 |
*/ |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
473 |
void RoadStop::FreeBay(uint nr) |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
474 |
{ |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
475 |
assert(nr < MAX_BAY_COUNT); |
8427
143b0be22af1
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
8425
diff
changeset
|
476 |
SetBit(status, nr); |
6316
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
477 |
} |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
478 |
|
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
479 |
|
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
480 |
/** 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
|
481 |
bool RoadStop::IsEntranceBusy() const |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
482 |
{ |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7992
diff
changeset
|
483 |
return HasBit(status, 7); |
6316
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
484 |
} |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
485 |
|
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
486 |
/** Makes an entrance occupied or free */ |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
487 |
void RoadStop::SetEntranceBusy(bool busy) |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
488 |
{ |
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
|
489 |
SB(status, 7, 1, busy); |
6316
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6161
diff
changeset
|
490 |
} |
7965
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
491 |
|
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
492 |
/** |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
493 |
* Get the next road stop accessible by this vehicle. |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
494 |
* @param v the vehicle to get the next road stop for. |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
495 |
* @return the next road stop accessible. |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
496 |
*/ |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
497 |
RoadStop *RoadStop::GetNextRoadStop(const Vehicle *v) const |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
498 |
{ |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
499 |
for (RoadStop *rs = this->next; rs != NULL; rs = rs->next) { |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
500 |
/* The vehicle cannot go to this roadstop (different roadtype) */ |
7967
7a931c848b69
(svn r10978) -Fix (r10974): only the first road stop (with correct roadtype) was considered when distributing vehicles.
rubidium
parents:
7965
diff
changeset
|
501 |
if ((GetRoadTypes(rs->xy) & v->u.road.compatible_roadtypes) == ROADTYPES_NONE) continue; |
7965
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
502 |
/* The vehicle is articulated and can therefor not go the a standard road stop */ |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
503 |
if (IsStandardRoadStopTile(rs->xy) && RoadVehHasArticPart(v)) continue; |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
504 |
|
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
505 |
/* The vehicle can actually go to this road stop. So, return it! */ |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
506 |
return rs; |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
507 |
} |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
508 |
|
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
509 |
return NULL; |
c1a170885a60
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents:
7949
diff
changeset
|
510 |
} |