Mercurial > hg > openttd
annotate src/train_cmd.cpp @ 18159:de0749262352 draft
(svn r22984) -Feature: Display profit icons for groups in the group GUI.
author | frosch <frosch@openttd.org> |
---|---|
date | Mon, 03 Oct 2011 17:25:44 +0000 |
parents | ca071969f8d7 |
children | 3141f1ed78eb |
rev | line source |
---|---|
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1 /* $Id$ */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2 |
12778
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12705
diff
changeset
|
3 /* |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12705
diff
changeset
|
4 * This file is part of OpenTTD. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12705
diff
changeset
|
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12705
diff
changeset
|
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12705
diff
changeset
|
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12705
diff
changeset
|
8 */ |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12705
diff
changeset
|
9 |
9111
d48433370037
(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 <rubidium@openttd.org>
parents:
9070
diff
changeset
|
10 /** @file train_cmd.cpp Handling of trains. */ |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
11 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
12 #include "stdafx.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
13 #include "gui.h" |
6772
5d92b1c91256
(svn r10008) -Codechange: Move a couple of functions related to articulated vehicles to a file of their own.
maedhros <maedhros@openttd.org>
parents:
6771
diff
changeset
|
14 #include "articulated_vehicles.h" |
8116
9cc845deddfe
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium <rubidium@openttd.org>
parents:
8114
diff
changeset
|
15 #include "command_func.h" |
13842
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
16 #include "pathfinder/npf/npf_func.h" |
13890
32e58ed16e0b
(svn r18420) -Codechange: split YAPF's track follower from the actual YAPF code
rubidium <rubidium@openttd.org>
parents:
13873
diff
changeset
|
17 #include "pathfinder/yapf/yapf.hpp" |
8763
d6e363672edb
(svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium <rubidium@openttd.org>
parents:
8712
diff
changeset
|
18 #include "news_func.h" |
10208
39cf8eebfda5
(svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium <rubidium@openttd.org>
parents:
10207
diff
changeset
|
19 #include "company_func.h" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
20 #include "vehicle_gui.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
21 #include "newgrf_sound.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
22 #include "newgrf_text.h" |
6643
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6608
diff
changeset
|
23 #include "group.h" |
8114
2d6af5d7a142
(svn r11675) -Codechange: split the string types from the string functions.
rubidium <rubidium@openttd.org>
parents:
8108
diff
changeset
|
24 #include "strings_func.h" |
17277
5b204f51b151
(svn r22017) -Codechange: move MarkTileDirtyByTile to viewport_func.h
rubidium <rubidium@openttd.org>
parents:
17236
diff
changeset
|
25 #include "viewport_func.h" |
8131
e300ac8001ae
(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 <rubidium@openttd.org>
parents:
8119
diff
changeset
|
26 #include "window_func.h" |
8144
d18c8a0bb638
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium <rubidium@openttd.org>
parents:
8143
diff
changeset
|
27 #include "vehicle_func.h" |
8157
019833e42fda
(svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium <rubidium@openttd.org>
parents:
8145
diff
changeset
|
28 #include "sound_func.h" |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
10690
diff
changeset
|
29 #include "ai/ai.hpp" |
9003
ac23e012c9d7
(svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents:
9000
diff
changeset
|
30 #include "newgrf_station.h" |
9009
870efbdb988d
(svn r12804) -Codechange: move the effect vehicle handling out of vehicle.cpp
rubidium <rubidium@openttd.org>
parents:
9008
diff
changeset
|
31 #include "effectvehicle_func.h" |
9704
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
32 #include "gamelog.h" |
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
33 #include "network/network.h" |
13599
28fe769d10b8
(svn r18123) -Codechange: try our best to keep the vehicles within the build vehicle list/autoreplace lists instead of overflowing.
rubidium <rubidium@openttd.org>
parents:
13597
diff
changeset
|
34 #include "spritecache.h" |
14258
a899d4e5ee1a
(svn r18809) -Codechange/Cleanup: remove unneeded headers from some files, if a header require a header make it include that header
rubidium <rubidium@openttd.org>
parents:
14227
diff
changeset
|
35 #include "core/random_func.hpp" |
a899d4e5ee1a
(svn r18809) -Codechange/Cleanup: remove unneeded headers from some files, if a header require a header make it include that header
rubidium <rubidium@openttd.org>
parents:
14227
diff
changeset
|
36 #include "company_base.h" |
a899d4e5ee1a
(svn r18809) -Codechange/Cleanup: remove unneeded headers from some files, if a header require a header make it include that header
rubidium <rubidium@openttd.org>
parents:
14227
diff
changeset
|
37 #include "newgrf.h" |
15865
270f9b0689cc
(svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents:
15854
diff
changeset
|
38 #include "order_backup.h" |
8083
e02014b06c7f
(svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz <smatz@openttd.org>
parents:
8081
diff
changeset
|
39 |
8264
2495310e220f
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents:
8258
diff
changeset
|
40 #include "table/strings.h" |
2495310e220f
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents:
8258
diff
changeset
|
41 #include "table/train_cmd.h" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
42 |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
43 static Track ChooseTrainTrack(Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool force_res, bool *got_reservation, bool mark_stuck); |
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
44 static bool TrainCheckIfLineEnds(Train *v); |
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
45 static void TrainController(Train *v, Vehicle *nomove); |
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
46 static TileIndex TrainApproachingCrossingTile(const Train *v); |
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
47 static void CheckIfTrainNeedsService(Train *v); |
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
48 static void CheckNextTrainTile(Train *v); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
49 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
50 static const byte _vehicle_initial_x_fract[4] = {10, 8, 4, 8}; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
51 static const byte _vehicle_initial_y_fract[4] = { 8, 4, 8, 10}; |
8248
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
52 |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
53 |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
54 /** |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
55 * Determine the side in which the train will leave the tile |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
56 * |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
57 * @param direction vehicle direction |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
58 * @param track vehicle track bits |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
59 * @return side of tile the train will leave |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
60 */ |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
61 static inline DiagDirection TrainExitDir(Direction direction, TrackBits track) |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
62 { |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
63 static const TrackBits state_dir_table[DIAGDIR_END] = { TRACK_BIT_RIGHT, TRACK_BIT_LOWER, TRACK_BIT_LEFT, TRACK_BIT_UPPER }; |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
64 |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
65 DiagDirection diagdir = DirToDiagDir(direction); |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
66 |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
67 /* Determine the diagonal direction in which we will exit this tile */ |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
68 if (!HasBit(direction, 0) && track != state_dir_table[diagdir]) { |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
69 diagdir = ChangeDiagDir(diagdir, DIAGDIRDIFF_90LEFT); |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
70 } |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
71 |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
72 return diagdir; |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
73 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
74 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
75 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
76 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
77 * Return the cargo weight multiplier to use for a rail vehicle |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
78 * @param cargo Cargo type to get multiplier for |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
79 * @return Cargo weight multiplier |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
80 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
81 byte FreightWagonMult(CargoID cargo) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
82 { |
12415
6a77d1df56e2
(svn r16849) -Codechange: replace GetCargo() by CargoSpec::Get()
smatz <smatz@openttd.org>
parents:
12351
diff
changeset
|
83 if (!CargoSpec::Get(cargo)->is_freight) return 1; |
9413
512ea64da840
(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 <rubidium@openttd.org>
parents:
9358
diff
changeset
|
84 return _settings_game.vehicle.freight_trains; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
85 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
86 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
87 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
88 * Logs a bug in GRF and shows a warning message if this |
9704
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
89 * is for the first time this happened. |
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
90 * @param u first vehicle of chain |
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
91 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
92 static void RailVehicleLengthChanged(const Train *u) |
9704
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
93 { |
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
94 /* show a warning once for each engine in whole game and once for each GRF after each game load */ |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11920
diff
changeset
|
95 const Engine *engine = Engine::Get(u->engine_type); |
15763
a60a50f29f64
(svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents:
15710
diff
changeset
|
96 uint32 grfid = engine->grf_prop.grffile->grfid; |
9704
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
97 GRFConfig *grfconfig = GetGRFConfig(grfid); |
15763
a60a50f29f64
(svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents:
15710
diff
changeset
|
98 if (GamelogGRFBugReverse(grfid, engine->grf_prop.local_id) || !HasBit(grfconfig->grf_bugs, GBUG_VEH_LENGTH)) { |
11351
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11327
diff
changeset
|
99 ShowNewGrfVehicleError(u->engine_type, STR_NEWGRF_BROKEN, STR_NEWGRF_BROKEN_VEHICLE_LENGTH, GBUG_VEH_LENGTH, true); |
9704
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
100 } |
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
101 } |
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
102 |
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
103 /** Checks if lengths of all rail vehicles are valid. If not, shows an error message. */ |
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
104 void CheckTrainsLengths() |
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
105 { |
12035
dcc31c1d758a
(svn r16442) -Codechange: use new Vehicle accessors at more places
smatz <smatz@openttd.org>
parents:
12034
diff
changeset
|
106 const Train *v; |
17165
3c9baf898829
(svn r21903) -Codechange: warn only once for a train that has invalid length, not for each its wagon with invalid length
smatz <smatz@openttd.org>
parents:
17142
diff
changeset
|
107 bool first = true; |
12035
dcc31c1d758a
(svn r16442) -Codechange: use new Vehicle accessors at more places
smatz <smatz@openttd.org>
parents:
12034
diff
changeset
|
108 |
dcc31c1d758a
(svn r16442) -Codechange: use new Vehicle accessors at more places
smatz <smatz@openttd.org>
parents:
12034
diff
changeset
|
109 FOR_ALL_TRAINS(v) { |
dcc31c1d758a
(svn r16442) -Codechange: use new Vehicle accessors at more places
smatz <smatz@openttd.org>
parents:
12034
diff
changeset
|
110 if (v->First() == v && !(v->vehstatus & VS_CRASHED)) { |
dcc31c1d758a
(svn r16442) -Codechange: use new Vehicle accessors at more places
smatz <smatz@openttd.org>
parents:
12034
diff
changeset
|
111 for (const Train *u = v, *w = v->Next(); w != NULL; u = w, w = w->Next()) { |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
112 if (u->track != TRACK_BIT_DEPOT) { |
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
113 if ((w->track != TRACK_BIT_DEPOT && |
16788
efb0333e5aad
(svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
114 max(abs(u->x_pos - w->x_pos), abs(u->y_pos - w->y_pos)) != u->gcache.cached_veh_length) || |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
115 (w->track == TRACK_BIT_DEPOT && TicksToLeaveDepot(u) <= 0)) { |
9704
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
116 SetDParam(0, v->index); |
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
117 SetDParam(1, v->owner); |
14645
b7a22979b84e
(svn r19224) -Codechange: change parameters passed to ShowErrorMessage() a bit
smatz <smatz@openttd.org>
parents:
14520
diff
changeset
|
118 ShowErrorMessage(STR_BROKEN_VEHICLE_LENGTH, INVALID_STRING_ID, WL_CRITICAL); |
9705
228505046e27
(svn r13817) -Cleanup (r13816): no need to check for ENABLE_NETWORK, _networking is defined anyway
smatz <smatz@openttd.org>
parents:
9704
diff
changeset
|
119 |
17165
3c9baf898829
(svn r21903) -Codechange: warn only once for a train that has invalid length, not for each its wagon with invalid length
smatz <smatz@openttd.org>
parents:
17142
diff
changeset
|
120 if (!_networking && first) { |
3c9baf898829
(svn r21903) -Codechange: warn only once for a train that has invalid length, not for each its wagon with invalid length
smatz <smatz@openttd.org>
parents:
17142
diff
changeset
|
121 first = false; |
3c9baf898829
(svn r21903) -Codechange: warn only once for a train that has invalid length, not for each its wagon with invalid length
smatz <smatz@openttd.org>
parents:
17142
diff
changeset
|
122 DoCommandP(0, PM_PAUSED_ERROR, 1, CMD_PAUSE); |
3c9baf898829
(svn r21903) -Codechange: warn only once for a train that has invalid length, not for each its wagon with invalid length
smatz <smatz@openttd.org>
parents:
17142
diff
changeset
|
123 } |
3c9baf898829
(svn r21903) -Codechange: warn only once for a train that has invalid length, not for each its wagon with invalid length
smatz <smatz@openttd.org>
parents:
17142
diff
changeset
|
124 /* Break so we warn only once for each train. */ |
3c9baf898829
(svn r21903) -Codechange: warn only once for a train that has invalid length, not for each its wagon with invalid length
smatz <smatz@openttd.org>
parents:
17142
diff
changeset
|
125 break; |
9704
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
126 } |
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
127 } |
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
128 } |
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
129 } |
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
130 } |
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
131 } |
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
132 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
133 /** |
15826
7f692dcca929
(svn r20505) -Feature [FS#3978]: Allow changing visual effect when changing railtype.
frosch <frosch@openttd.org>
parents:
15825
diff
changeset
|
134 * Update visual effect, power and acceleration caches. |
7f692dcca929
(svn r20505) -Feature [FS#3978]: Allow changing visual effect when changing railtype.
frosch <frosch@openttd.org>
parents:
15825
diff
changeset
|
135 * Called when a vehicle in the consist enters a different railtype. |
15825
5a7d7a33055b
(svn r20504) -Codechange: Move updating of train's visual effect to separate function.
frosch <frosch@openttd.org>
parents:
15820
diff
changeset
|
136 */ |
15826
7f692dcca929
(svn r20505) -Feature [FS#3978]: Allow changing visual effect when changing railtype.
frosch <frosch@openttd.org>
parents:
15825
diff
changeset
|
137 void Train::RailtypeChanged() |
15825
5a7d7a33055b
(svn r20504) -Codechange: Move updating of train's visual effect to separate function.
frosch <frosch@openttd.org>
parents:
15820
diff
changeset
|
138 { |
15826
7f692dcca929
(svn r20505) -Feature [FS#3978]: Allow changing visual effect when changing railtype.
frosch <frosch@openttd.org>
parents:
15825
diff
changeset
|
139 for (Train *u = this; u != NULL; u = u->Next()) { |
7f692dcca929
(svn r20505) -Feature [FS#3978]: Allow changing visual effect when changing railtype.
frosch <frosch@openttd.org>
parents:
15825
diff
changeset
|
140 /* The wagon-is-powered-state should not change, so the weight does not change. */ |
7f692dcca929
(svn r20505) -Feature [FS#3978]: Allow changing visual effect when changing railtype.
frosch <frosch@openttd.org>
parents:
15825
diff
changeset
|
141 u->UpdateVisualEffect(false); |
7f692dcca929
(svn r20505) -Feature [FS#3978]: Allow changing visual effect when changing railtype.
frosch <frosch@openttd.org>
parents:
15825
diff
changeset
|
142 } |
7f692dcca929
(svn r20505) -Feature [FS#3978]: Allow changing visual effect when changing railtype.
frosch <frosch@openttd.org>
parents:
15825
diff
changeset
|
143 this->PowerChanged(); |
7f692dcca929
(svn r20505) -Feature [FS#3978]: Allow changing visual effect when changing railtype.
frosch <frosch@openttd.org>
parents:
15825
diff
changeset
|
144 if (this->IsFrontEngine()) this->UpdateAcceleration(); |
7f692dcca929
(svn r20505) -Feature [FS#3978]: Allow changing visual effect when changing railtype.
frosch <frosch@openttd.org>
parents:
15825
diff
changeset
|
145 } |
7f692dcca929
(svn r20505) -Feature [FS#3978]: Allow changing visual effect when changing railtype.
frosch <frosch@openttd.org>
parents:
15825
diff
changeset
|
146 |
7f692dcca929
(svn r20505) -Feature [FS#3978]: Allow changing visual effect when changing railtype.
frosch <frosch@openttd.org>
parents:
15825
diff
changeset
|
147 /** |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
148 * Recalculates the cached stuff of a train. Should be called each time a vehicle is added |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
149 * to/removed from the chain, and when the game is loaded. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
150 * Note: this needs to be called too for 'wagon chains' (in the depot, without an engine) |
9704
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
151 * @param same_length should length of vehicles stay the same? |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
152 */ |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
153 void Train::ConsistChanged(bool same_length) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
154 { |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
155 uint16 max_speed = UINT16_MAX; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
156 |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
157 assert(this->IsFrontEngine() || this->IsFreeWagon()); |
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
158 |
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
159 const RailVehicleInfo *rvi_v = RailVehInfo(this->engine_type); |
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
160 EngineID first_engine = this->IsFrontEngine() ? this->engine_type : INVALID_ENGINE; |
16788
efb0333e5aad
(svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
161 this->gcache.cached_total_length = 0; |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
162 this->compatible_railtypes = RAILTYPES_NONE; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
163 |
8178
682fb03eb247
(svn r11741) -Feature: Add support for NewGRF's train 'tilt' flag. Trains with tilt capability (specific details are per NewGRF set) will be given a 20% speed limit bonus on curves.
peter1138 <peter1138@openttd.org>
parents:
8175
diff
changeset
|
164 bool train_can_tilt = true; |
682fb03eb247
(svn r11741) -Feature: Add support for NewGRF's train 'tilt' flag. Trains with tilt capability (specific details are per NewGRF set) will be given a 20% speed limit bonus on curves.
peter1138 <peter1138@openttd.org>
parents:
8175
diff
changeset
|
165 |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
166 for (Train *u = this; u != NULL; u = u->Next()) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
167 const RailVehicleInfo *rvi_u = RailVehInfo(u->engine_type); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
168 |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
169 /* Check the this->first cache. */ |
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
170 assert(u->First() == this); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
171 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
172 /* update the 'first engine' */ |
16788
efb0333e5aad
(svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
173 u->gcache.first_engine = this == u ? INVALID_ENGINE : first_engine; |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
174 u->railtype = rvi_u->railtype; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
175 |
12302
fc8e41f34b8c
(svn r16719) -Codechange: make IsArticulatedPart(), IsTrainEngine(), IsTrainWagon(), IsMultiheaded(), EngineHasArticPart() and IsRearDualheaded() members of Train
smatz <smatz@openttd.org>
parents:
12301
diff
changeset
|
176 if (u->IsEngine()) first_engine = u->engine_type; |
9515
bcc765d85155
(svn r13507) -Fix (r12856): first engine change should've been moved too
peter1138 <peter1138@openttd.org>
parents:
9488
diff
changeset
|
177 |
9037
8132939c7773
(svn r12856) -Fix: Taking r12377 further, ensure that prop 25 is set for all vehicles in the consist before other properties.
peter1138 <peter1138@openttd.org>
parents:
9022
diff
changeset
|
178 /* Set user defined data to its default value */ |
11987
81554d4e6d76
(svn r16393) -Codechange: move VehicleRail to Train.
rubidium <rubidium@openttd.org>
parents:
11986
diff
changeset
|
179 u->tcache.user_def_data = rvi_u->user_def_data; |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
180 this->InvalidateNewGRFCache(); |
12073
02d3a628e6db
(svn r16480) -Fix (r15617): Invalidate newgrf variable caches of more vehicles in more places. Esp. they were only invalidated for trains.
frosch <frosch@openttd.org>
parents:
12035
diff
changeset
|
181 u->InvalidateNewGRFCache(); |
9037
8132939c7773
(svn r12856) -Fix: Taking r12377 further, ensure that prop 25 is set for all vehicles in the consist before other properties.
peter1138 <peter1138@openttd.org>
parents:
9022
diff
changeset
|
182 } |
8132939c7773
(svn r12856) -Fix: Taking r12377 further, ensure that prop 25 is set for all vehicles in the consist before other properties.
peter1138 <peter1138@openttd.org>
parents:
9022
diff
changeset
|
183 |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
184 for (Train *u = this; u != NULL; u = u->Next()) { |
9037
8132939c7773
(svn r12856) -Fix: Taking r12377 further, ensure that prop 25 is set for all vehicles in the consist before other properties.
peter1138 <peter1138@openttd.org>
parents:
9022
diff
changeset
|
185 /* Update user defined data (must be done before other properties) */ |
13114
940252f91c5f
(svn r17616) -Codechange [FS#3222]: Enumerize properties used in callback 0x36. Based on Terkhen's work.
frosch <frosch@openttd.org>
parents:
13094
diff
changeset
|
186 u->tcache.user_def_data = GetVehicleProperty(u, PROP_TRAIN_USER_DATA, u->tcache.user_def_data); |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
187 this->InvalidateNewGRFCache(); |
12073
02d3a628e6db
(svn r16480) -Fix (r15617): Invalidate newgrf variable caches of more vehicles in more places. Esp. they were only invalidated for trains.
frosch <frosch@openttd.org>
parents:
12035
diff
changeset
|
188 u->InvalidateNewGRFCache(); |
9037
8132939c7773
(svn r12856) -Fix: Taking r12377 further, ensure that prop 25 is set for all vehicles in the consist before other properties.
peter1138 <peter1138@openttd.org>
parents:
9022
diff
changeset
|
189 } |
8132939c7773
(svn r12856) -Fix: Taking r12377 further, ensure that prop 25 is set for all vehicles in the consist before other properties.
peter1138 <peter1138@openttd.org>
parents:
9022
diff
changeset
|
190 |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
191 for (Train *u = this; u != NULL; u = u->Next()) { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11920
diff
changeset
|
192 const Engine *e_u = Engine::Get(u->engine_type); |
11188
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11150
diff
changeset
|
193 const RailVehicleInfo *rvi_u = &e_u->u.rail; |
9037
8132939c7773
(svn r12856) -Fix: Taking r12377 further, ensure that prop 25 is set for all vehicles in the consist before other properties.
peter1138 <peter1138@openttd.org>
parents:
9022
diff
changeset
|
194 |
13218
03a409fa4c29
(svn r17725) -Codechange: Reduce usage of EngInfo and XxxVehInfo, esp. when a Engine * is already present.
frosch <frosch@openttd.org>
parents:
13186
diff
changeset
|
195 if (!HasBit(e_u->info.misc_flags, EF_RAIL_TILTS)) train_can_tilt = false; |
9037
8132939c7773
(svn r12856) -Fix: Taking r12377 further, ensure that prop 25 is set for all vehicles in the consist before other properties.
peter1138 <peter1138@openttd.org>
parents:
9022
diff
changeset
|
196 |
6603
2124b871a178
(svn r9818) -Codechange: Cache wagon override sprite set whenever consist is changed, instead of 'recalculating' it every time it is used or just tested.
peter1138 <peter1138@openttd.org>
parents:
6594
diff
changeset
|
197 /* Cache wagon override sprite group. NULL is returned if there is none */ |
16788
efb0333e5aad
(svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
198 u->tcache.cached_override = GetWagonOverrideSpriteSet(u->engine_type, u->cargo_type, u->gcache.first_engine); |
6603
2124b871a178
(svn r9818) -Codechange: Cache wagon override sprite set whenever consist is changed, instead of 'recalculating' it every time it is used or just tested.
peter1138 <peter1138@openttd.org>
parents:
6594
diff
changeset
|
199 |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
11018
diff
changeset
|
200 /* Reset colour map */ |
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
11018
diff
changeset
|
201 u->colourmap = PAL_NONE; |
7802
bb4e6370dfdf
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx <glx@openttd.org>
parents:
7783
diff
changeset
|
202 |
15825
5a7d7a33055b
(svn r20504) -Codechange: Move updating of train's visual effect to separate function.
frosch <frosch@openttd.org>
parents:
15820
diff
changeset
|
203 /* Update powered-wagon-status and visual effect */ |
15826
7f692dcca929
(svn r20505) -Feature [FS#3978]: Allow changing visual effect when changing railtype.
frosch <frosch@openttd.org>
parents:
15825
diff
changeset
|
204 u->UpdateVisualEffect(true); |
9738
469d98bb080e
(svn r13870) -Fix [FS#2167]: Callback 10 (visual effect and powered wagons setting) and powered wagons operation were not performed for articulated wagons.
peter1138 <peter1138@openttd.org>
parents:
9705
diff
changeset
|
205 |
469d98bb080e
(svn r13870) -Fix [FS#2167]: Callback 10 (visual effect and powered wagons setting) and powered wagons operation were not performed for articulated wagons.
peter1138 <peter1138@openttd.org>
parents:
9705
diff
changeset
|
206 if (rvi_v->pow_wag_power != 0 && rvi_u->railveh_type == RAILVEH_WAGON && |
16507
e89b23c58633
(svn r21233) -Codechange: Introduce an enum to remove some magic numbers from the visual effect code (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16506
diff
changeset
|
207 UsesWagonOverride(u) && !HasBit(u->vcache.cached_vis_effect, VE_DISABLE_WAGON_POWER)) { |
9738
469d98bb080e
(svn r13870) -Fix [FS#2167]: Callback 10 (visual effect and powered wagons setting) and powered wagons operation were not performed for articulated wagons.
peter1138 <peter1138@openttd.org>
parents:
9705
diff
changeset
|
208 /* wagon is powered */ |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
209 SetBit(u->flags, VRF_POWEREDWAGON); // cache 'powered' status |
9738
469d98bb080e
(svn r13870) -Fix [FS#2167]: Callback 10 (visual effect and powered wagons setting) and powered wagons operation were not performed for articulated wagons.
peter1138 <peter1138@openttd.org>
parents:
9705
diff
changeset
|
210 } else { |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
211 ClrBit(u->flags, VRF_POWEREDWAGON); |
9738
469d98bb080e
(svn r13870) -Fix [FS#2167]: Callback 10 (visual effect and powered wagons setting) and powered wagons operation were not performed for articulated wagons.
peter1138 <peter1138@openttd.org>
parents:
9705
diff
changeset
|
212 } |
469d98bb080e
(svn r13870) -Fix [FS#2167]: Callback 10 (visual effect and powered wagons setting) and powered wagons operation were not performed for articulated wagons.
peter1138 <peter1138@openttd.org>
parents:
9705
diff
changeset
|
213 |
12302
fc8e41f34b8c
(svn r16719) -Codechange: make IsArticulatedPart(), IsTrainEngine(), IsTrainWagon(), IsMultiheaded(), EngineHasArticPart() and IsRearDualheaded() members of Train
smatz <smatz@openttd.org>
parents:
12301
diff
changeset
|
214 if (!u->IsArticulatedPart()) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
215 /* Do not count powered wagons for the compatible railtypes, as wagons always |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
216 have railtype normal */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
217 if (rvi_u->power > 0) { |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
218 this->compatible_railtypes |= GetRailTypeInfo(u->railtype)->powered_railtypes; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
219 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
220 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
221 /* Some electric engines can be allowed to run on normal rail. It happens to all |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
222 * existing electric engines when elrails are disabled and then re-enabled */ |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
223 if (HasBit(u->flags, VRF_EL_ENGINE_ALLOWED_NORMAL_RAIL)) { |
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
224 u->railtype = RAILTYPE_RAIL; |
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
225 u->compatible_railtypes |= RAILTYPES_RAIL; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
226 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
227 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
228 /* max speed is the minimum of the speed limits of all vehicles in the consist */ |
9413
512ea64da840
(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 <rubidium@openttd.org>
parents:
9358
diff
changeset
|
229 if ((rvi_u->railveh_type != RAILVEH_WAGON || _settings_game.vehicle.wagon_speed_limits) && !UsesWagonOverride(u)) { |
13114
940252f91c5f
(svn r17616) -Codechange [FS#3222]: Enumerize properties used in callback 0x36. Based on Terkhen's work.
frosch <frosch@openttd.org>
parents:
13094
diff
changeset
|
230 uint16 speed = GetVehicleProperty(u, PROP_TRAIN_SPEED, rvi_u->max_speed); |
6490
fcc1843c68c6
(svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138 <peter1138@openttd.org>
parents:
6484
diff
changeset
|
231 if (speed != 0) max_speed = min(speed, max_speed); |
fcc1843c68c6
(svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138 <peter1138@openttd.org>
parents:
6484
diff
changeset
|
232 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
233 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
234 |
13388
96253b319c10
(svn r17897) -Fix [FS#3255]: CB15 and CB36 (capacity) were not always called when they should.
frosch <frosch@openttd.org>
parents:
13385
diff
changeset
|
235 u->cargo_cap = GetVehicleCapacity(u); |
17909
4d6b4b6d6069
(svn r22713) -Feature: [NewGRF] Per vehicle custom cargo ageing period.
michi_cc <michi_cc@openttd.org>
parents:
17804
diff
changeset
|
236 u->vcache.cached_cargo_age_period = GetVehicleProperty(u, PROP_TRAIN_CARGO_AGE_PERIOD, e_u->info.cargo_age_period); |
6608
68e9e501d4d8
(svn r9828) -Codechange: [NewGRF] Add support for changing cargo capacity with callback 36. This is set on construction for ships and roadvehicles, and whenever carriages are attached for trains.
peter1138 <peter1138@openttd.org>
parents:
6603
diff
changeset
|
237 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
238 /* check the vehicle length (callback) */ |
6150 | 239 uint16 veh_len = CALLBACK_FAILED; |
13218
03a409fa4c29
(svn r17725) -Codechange: Reduce usage of EngInfo and XxxVehInfo, esp. when a Engine * is already present.
frosch <frosch@openttd.org>
parents:
13186
diff
changeset
|
240 if (HasBit(e_u->info.callback_mask, CBM_VEHICLE_LENGTH)) { |
7215
ba8faf180ec2
(svn r10493) -Codechange: update some callback ID enums to reflect their changed usage, add a few and update the comments.
rubidium <rubidium@openttd.org>
parents:
7196
diff
changeset
|
241 veh_len = GetVehicleCallback(CBID_VEHICLE_LENGTH, 0, 0, u->engine_type, u); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
242 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
243 if (veh_len == CALLBACK_FAILED) veh_len = rvi_u->shorten_factor; |
17451
2dbd537df54d
(svn r22205) -Codechange: replace magic number with constant
rubidium <rubidium@openttd.org>
parents:
17399
diff
changeset
|
244 veh_len = VEHICLE_LENGTH - Clamp(veh_len, 0, VEHICLE_LENGTH - 1); |
9704
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
245 |
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
246 /* verify length hasn't changed */ |
16788
efb0333e5aad
(svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
247 if (same_length && veh_len != u->gcache.cached_veh_length) RailVehicleLengthChanged(u); |
9704
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
248 |
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
249 /* update vehicle length? */ |
16788
efb0333e5aad
(svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
250 if (!same_length) u->gcache.cached_veh_length = veh_len; |
efb0333e5aad
(svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
251 |
efb0333e5aad
(svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
252 this->gcache.cached_total_length += u->gcache.cached_veh_length; |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
253 this->InvalidateNewGRFCache(); |
12073
02d3a628e6db
(svn r16480) -Fix (r15617): Invalidate newgrf variable caches of more vehicles in more places. Esp. they were only invalidated for trains.
frosch <frosch@openttd.org>
parents:
12035
diff
changeset
|
254 u->InvalidateNewGRFCache(); |
6150 | 255 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
256 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
257 /* store consist weight/max speed in cache */ |
16381
6d81f8cd1497
(svn r21097) -Codechange: Unify cached max speed for all vehicle types.
terkhen <terkhen@openttd.org>
parents:
16372
diff
changeset
|
258 this->vcache.cached_max_speed = max_speed; |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
259 this->tcache.cached_tilt = train_can_tilt; |
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
260 this->tcache.cached_max_curve_speed = this->GetCurveSpeedLimit(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
261 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
262 /* recalculate cached weights and power too (we do this *after* the rest, so it is known which wagons are powered and need extra weight added) */ |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
263 this->CargoChanged(); |
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
264 |
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
265 if (this->IsFrontEngine()) { |
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
266 this->UpdateAcceleration(); |
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
267 SetWindowDirty(WC_VEHICLE_DETAILS, this->index); |
17489
7e48879a9608
(svn r22244) -Codechange: Make vehicle windows handle command-/GUI-scope invalidations themself (from autoreplace and refitting).
frosch <frosch@openttd.org>
parents:
17452
diff
changeset
|
268 InvalidateWindowData(WC_VEHICLE_REFIT, this->index); |
8706
20434584b743
(svn r12380) -Fix: update train acceleration and max speed after setting cached value to ensure the correct max speed is used with disabled real acceleration
glx <glx@openttd.org>
parents:
8705
diff
changeset
|
269 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
270 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
271 |
11657
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
272 /** |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
273 * Get the stop location of (the center) of the front vehicle of a train at |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
274 * a platform of a station. |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
275 * @param station_id the ID of the station where we're stopping |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
276 * @param tile the tile where the vehicle currently is |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
277 * @param v the vehicle to get the stop location of |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
278 * @param station_ahead 'return' the amount of 1/16th tiles in front of the train |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
279 * @param station_length 'return' the station length in 1/16th tiles |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
280 * @return the location, calculated from the begin of the station to stop at. |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
281 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
282 int GetTrainStopLocation(StationID station_id, TileIndex tile, const Train *v, int *station_ahead, int *station_length) |
11657
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
283 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11920
diff
changeset
|
284 const Station *st = Station::Get(station_id); |
11657
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
285 *station_ahead = st->GetPlatformLength(tile, DirToDiagDir(v->direction)) * TILE_SIZE; |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
286 *station_length = st->GetPlatformLength(tile) * TILE_SIZE; |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
287 |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
288 /* Default to the middle of the station for stations stops that are not in |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
289 * the order list like intermediate stations when non-stop is disabled */ |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
290 OrderStopLocation osl = OSL_PLATFORM_MIDDLE; |
16788
efb0333e5aad
(svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
291 if (v->gcache.cached_total_length >= *station_length) { |
11657
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
292 /* The train is longer than the station, make it stop at the far end of the platform */ |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
293 osl = OSL_PLATFORM_FAR_END; |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
294 } else if (v->current_order.IsType(OT_GOTO_STATION) && v->current_order.GetDestination() == station_id) { |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
295 osl = v->current_order.GetStopLocation(); |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
296 } |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
297 |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
298 /* The stop location of the FRONT! of the train */ |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
299 int stop; |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
300 switch (osl) { |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
301 default: NOT_REACHED(); |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
302 |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
303 case OSL_PLATFORM_NEAR_END: |
16788
efb0333e5aad
(svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
304 stop = v->gcache.cached_total_length; |
11657
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
305 break; |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
306 |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
307 case OSL_PLATFORM_MIDDLE: |
16788
efb0333e5aad
(svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
308 stop = *station_length - (*station_length - v->gcache.cached_total_length) / 2; |
11657
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
309 break; |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
310 |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
311 case OSL_PLATFORM_FAR_END: |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
312 stop = *station_length; |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
313 break; |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
314 } |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
315 |
15820
59fd8293b2ee
(svn r20499) -Doc: Spelling fixes, and one doxygen comment addition.
alberth <alberth@openttd.org>
parents:
15763
diff
changeset
|
316 /* Subtract half the front vehicle length of the train so we get the real |
17452
aad8b54a8fa6
(svn r22206) -Revert-ish (r14526) / Unfix-ish [FS#3569] / Fix [FS#4545]: the "center" (for movement) of vehicles is (currently still) always at 4/8th original vehicle length from the front, so trains should stop at the same location regardless of the length of the front engine
rubidium <rubidium@openttd.org>
parents:
17451
diff
changeset
|
317 * stop location of the train. |
aad8b54a8fa6
(svn r22206) -Revert-ish (r14526) / Unfix-ish [FS#3569] / Fix [FS#4545]: the "center" (for movement) of vehicles is (currently still) always at 4/8th original vehicle length from the front, so trains should stop at the same location regardless of the length of the front engine
rubidium <rubidium@openttd.org>
parents:
17451
diff
changeset
|
318 * Actually, the center of all vehicles is half a normal vehicle's length |
aad8b54a8fa6
(svn r22206) -Revert-ish (r14526) / Unfix-ish [FS#3569] / Fix [FS#4545]: the "center" (for movement) of vehicles is (currently still) always at 4/8th original vehicle length from the front, so trains should stop at the same location regardless of the length of the front engine
rubidium <rubidium@openttd.org>
parents:
17451
diff
changeset
|
319 * from the front of the vehicle, so even in case the vehicle is 1/8th |
aad8b54a8fa6
(svn r22206) -Revert-ish (r14526) / Unfix-ish [FS#3569] / Fix [FS#4545]: the "center" (for movement) of vehicles is (currently still) always at 4/8th original vehicle length from the front, so trains should stop at the same location regardless of the length of the front engine
rubidium <rubidium@openttd.org>
parents:
17451
diff
changeset
|
320 * long, the center is still at 1/2 of VEHICLE_LENGTH. Basically FS#3569. */ |
aad8b54a8fa6
(svn r22206) -Revert-ish (r14526) / Unfix-ish [FS#3569] / Fix [FS#4545]: the "center" (for movement) of vehicles is (currently still) always at 4/8th original vehicle length from the front, so trains should stop at the same location regardless of the length of the front engine
rubidium <rubidium@openttd.org>
parents:
17451
diff
changeset
|
321 return stop - VEHICLE_LENGTH / 2; |
11657
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
322 } |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
323 |
12085
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
324 |
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
325 /** |
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
326 * Computes train speed limit caused by curves |
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
327 * @return imposed speed limit |
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
328 */ |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
329 int Train::GetCurveSpeedLimit() const |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
330 { |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
331 assert(this->First() == this); |
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
332 |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
333 static const int absolute_max_speed = UINT16_MAX; |
8169
7962907a27a1
(svn r11732) -Fix (r4150): elrail merge gave elrail, monorail & maglev unintended speed bonuses for curves, as the bonus was based on the railtype index. The bonus is now specified by a property of the railtype.
peter1138 <peter1138@openttd.org>
parents:
8168
diff
changeset
|
334 int max_speed = absolute_max_speed; |
12085
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
335 |
14406
5f93639271ee
(svn r18963) -Codechange: Give AccelerationModel a generical name.
terkhen <terkhen@openttd.org>
parents:
14384
diff
changeset
|
336 if (_settings_game.vehicle.train_acceleration_model == AM_ORIGINAL) return max_speed; |
12085
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
337 |
6150 | 338 int curvecount[2] = {0, 0}; |
339 | |
11368
82c90cd591ab
(svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents:
11351
diff
changeset
|
340 /* first find the curve speed limit */ |
6150 | 341 int numcurve = 0; |
342 int sum = 0; | |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
343 int pos = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
344 int lastpos = -1; |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
345 for (const Vehicle *u = this; u->Next() != NULL; u = u->Next(), pos++) { |
8175
b6a2bebbaaed
(svn r11738) -Codechange: Refactor realistic acceleration's curve counting to use DirDiffs instead of local tables, and remove an unnecessary loop.
peter1138 <peter1138@openttd.org>
parents:
8170
diff
changeset
|
346 Direction this_dir = u->direction; |
b6a2bebbaaed
(svn r11738) -Codechange: Refactor realistic acceleration's curve counting to use DirDiffs instead of local tables, and remove an unnecessary loop.
peter1138 <peter1138@openttd.org>
parents:
8170
diff
changeset
|
347 Direction next_dir = u->Next()->direction; |
b6a2bebbaaed
(svn r11738) -Codechange: Refactor realistic acceleration's curve counting to use DirDiffs instead of local tables, and remove an unnecessary loop.
peter1138 <peter1138@openttd.org>
parents:
8170
diff
changeset
|
348 |
b6a2bebbaaed
(svn r11738) -Codechange: Refactor realistic acceleration's curve counting to use DirDiffs instead of local tables, and remove an unnecessary loop.
peter1138 <peter1138@openttd.org>
parents:
8170
diff
changeset
|
349 DirDiff dirdiff = DirDifference(this_dir, next_dir); |
b6a2bebbaaed
(svn r11738) -Codechange: Refactor realistic acceleration's curve counting to use DirDiffs instead of local tables, and remove an unnecessary loop.
peter1138 <peter1138@openttd.org>
parents:
8170
diff
changeset
|
350 if (dirdiff == DIRDIFF_SAME) continue; |
b6a2bebbaaed
(svn r11738) -Codechange: Refactor realistic acceleration's curve counting to use DirDiffs instead of local tables, and remove an unnecessary loop.
peter1138 <peter1138@openttd.org>
parents:
8170
diff
changeset
|
351 |
b6a2bebbaaed
(svn r11738) -Codechange: Refactor realistic acceleration's curve counting to use DirDiffs instead of local tables, and remove an unnecessary loop.
peter1138 <peter1138@openttd.org>
parents:
8170
diff
changeset
|
352 if (dirdiff == DIRDIFF_45LEFT) curvecount[0]++; |
b6a2bebbaaed
(svn r11738) -Codechange: Refactor realistic acceleration's curve counting to use DirDiffs instead of local tables, and remove an unnecessary loop.
peter1138 <peter1138@openttd.org>
parents:
8170
diff
changeset
|
353 if (dirdiff == DIRDIFF_45RIGHT) curvecount[1]++; |
b6a2bebbaaed
(svn r11738) -Codechange: Refactor realistic acceleration's curve counting to use DirDiffs instead of local tables, and remove an unnecessary loop.
peter1138 <peter1138@openttd.org>
parents:
8170
diff
changeset
|
354 if (dirdiff == DIRDIFF_45LEFT || dirdiff == DIRDIFF_45RIGHT) { |
b6a2bebbaaed
(svn r11738) -Codechange: Refactor realistic acceleration's curve counting to use DirDiffs instead of local tables, and remove an unnecessary loop.
peter1138 <peter1138@openttd.org>
parents:
8170
diff
changeset
|
355 if (lastpos != -1) { |
b6a2bebbaaed
(svn r11738) -Codechange: Refactor realistic acceleration's curve counting to use DirDiffs instead of local tables, and remove an unnecessary loop.
peter1138 <peter1138@openttd.org>
parents:
8170
diff
changeset
|
356 numcurve++; |
b6a2bebbaaed
(svn r11738) -Codechange: Refactor realistic acceleration's curve counting to use DirDiffs instead of local tables, and remove an unnecessary loop.
peter1138 <peter1138@openttd.org>
parents:
8170
diff
changeset
|
357 sum += pos - lastpos; |
18064
0108a6ec2d68
(svn r22879) -Fix: Miscalculation of train curve speed limits. (monoid)
terkhen <terkhen@openttd.org>
parents:
18007
diff
changeset
|
358 if (pos - lastpos == 1 && max_speed > 88) { |
8175
b6a2bebbaaed
(svn r11738) -Codechange: Refactor realistic acceleration's curve counting to use DirDiffs instead of local tables, and remove an unnecessary loop.
peter1138 <peter1138@openttd.org>
parents:
8170
diff
changeset
|
359 max_speed = 88; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
360 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
361 } |
8175
b6a2bebbaaed
(svn r11738) -Codechange: Refactor realistic acceleration's curve counting to use DirDiffs instead of local tables, and remove an unnecessary loop.
peter1138 <peter1138@openttd.org>
parents:
8170
diff
changeset
|
362 lastpos = pos; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
363 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
364 |
11368
82c90cd591ab
(svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents:
11351
diff
changeset
|
365 /* if we have a 90 degree turn, fix the speed limit to 60 */ |
8175
b6a2bebbaaed
(svn r11738) -Codechange: Refactor realistic acceleration's curve counting to use DirDiffs instead of local tables, and remove an unnecessary loop.
peter1138 <peter1138@openttd.org>
parents:
8170
diff
changeset
|
366 if (dirdiff == DIRDIFF_90LEFT || dirdiff == DIRDIFF_90RIGHT) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
367 max_speed = 61; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
368 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
369 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
370 |
12085
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
371 if (numcurve > 0 && max_speed > 88) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
372 if (curvecount[0] == 1 && curvecount[1] == 1) { |
8169
7962907a27a1
(svn r11732) -Fix (r4150): elrail merge gave elrail, monorail & maglev unintended speed bonuses for curves, as the bonus was based on the railtype index. The bonus is now specified by a property of the railtype.
peter1138 <peter1138@openttd.org>
parents:
8168
diff
changeset
|
373 max_speed = absolute_max_speed; |
12085
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
374 } else { |
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
375 sum /= numcurve; |
7922
ff1975ced735
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13 <skidd13@openttd.org>
parents:
7881
diff
changeset
|
376 max_speed = 232 - (13 - Clamp(sum, 1, 12)) * (13 - Clamp(sum, 1, 12)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
377 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
378 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
379 |
8169
7962907a27a1
(svn r11732) -Fix (r4150): elrail merge gave elrail, monorail & maglev unintended speed bonuses for curves, as the bonus was based on the railtype index. The bonus is now specified by a property of the railtype.
peter1138 <peter1138@openttd.org>
parents:
8168
diff
changeset
|
380 if (max_speed != absolute_max_speed) { |
7962907a27a1
(svn r11732) -Fix (r4150): elrail merge gave elrail, monorail & maglev unintended speed bonuses for curves, as the bonus was based on the railtype index. The bonus is now specified by a property of the railtype.
peter1138 <peter1138@openttd.org>
parents:
8168
diff
changeset
|
381 /* Apply the engine's rail type curve speed advantage, if it slowed by curves */ |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
382 const RailtypeInfo *rti = GetRailTypeInfo(this->railtype); |
8169
7962907a27a1
(svn r11732) -Fix (r4150): elrail merge gave elrail, monorail & maglev unintended speed bonuses for curves, as the bonus was based on the railtype index. The bonus is now specified by a property of the railtype.
peter1138 <peter1138@openttd.org>
parents:
8168
diff
changeset
|
383 max_speed += (max_speed / 2) * rti->curve_speed; |
8178
682fb03eb247
(svn r11741) -Feature: Add support for NewGRF's train 'tilt' flag. Trains with tilt capability (specific details are per NewGRF set) will be given a 20% speed limit bonus on curves.
peter1138 <peter1138@openttd.org>
parents:
8175
diff
changeset
|
384 |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
385 if (this->tcache.cached_tilt) { |
8178
682fb03eb247
(svn r11741) -Feature: Add support for NewGRF's train 'tilt' flag. Trains with tilt capability (specific details are per NewGRF set) will be given a 20% speed limit bonus on curves.
peter1138 <peter1138@openttd.org>
parents:
8175
diff
changeset
|
386 /* Apply max_speed bonus of 20% for a tilting train */ |
682fb03eb247
(svn r11741) -Feature: Add support for NewGRF's train 'tilt' flag. Trains with tilt capability (specific details are per NewGRF set) will be given a 20% speed limit bonus on curves.
peter1138 <peter1138@openttd.org>
parents:
8175
diff
changeset
|
387 max_speed += max_speed / 5; |
682fb03eb247
(svn r11741) -Feature: Add support for NewGRF's train 'tilt' flag. Trains with tilt capability (specific details are per NewGRF set) will be given a 20% speed limit bonus on curves.
peter1138 <peter1138@openttd.org>
parents:
8175
diff
changeset
|
388 } |
8169
7962907a27a1
(svn r11732) -Fix (r4150): elrail merge gave elrail, monorail & maglev unintended speed bonuses for curves, as the bonus was based on the railtype index. The bonus is now specified by a property of the railtype.
peter1138 <peter1138@openttd.org>
parents:
8168
diff
changeset
|
389 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
390 |
12085
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
391 return max_speed; |
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
392 } |
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
393 |
14286
f96af1b6a264
(svn r18838) -Codechange [FS#3524]: reorganisation of the train acceleration code plus some minor optimisations (Terkhen)
rubidium <rubidium@openttd.org>
parents:
14284
diff
changeset
|
394 /** |
f96af1b6a264
(svn r18838) -Codechange [FS#3524]: reorganisation of the train acceleration code plus some minor optimisations (Terkhen)
rubidium <rubidium@openttd.org>
parents:
14284
diff
changeset
|
395 * Calculates the maximum speed of the vehicle under its current conditions. |
f96af1b6a264
(svn r18838) -Codechange [FS#3524]: reorganisation of the train acceleration code plus some minor optimisations (Terkhen)
rubidium <rubidium@openttd.org>
parents:
14284
diff
changeset
|
396 * @return Maximum speed of the vehicle. |
f96af1b6a264
(svn r18838) -Codechange [FS#3524]: reorganisation of the train acceleration code plus some minor optimisations (Terkhen)
rubidium <rubidium@openttd.org>
parents:
14284
diff
changeset
|
397 */ |
f96af1b6a264
(svn r18838) -Codechange [FS#3524]: reorganisation of the train acceleration code plus some minor optimisations (Terkhen)
rubidium <rubidium@openttd.org>
parents:
14284
diff
changeset
|
398 int Train::GetCurrentMaxSpeed() const |
12085
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
399 { |
14286
f96af1b6a264
(svn r18838) -Codechange [FS#3524]: reorganisation of the train acceleration code plus some minor optimisations (Terkhen)
rubidium <rubidium@openttd.org>
parents:
14284
diff
changeset
|
400 int max_speed = this->tcache.cached_max_curve_speed; |
f96af1b6a264
(svn r18838) -Codechange [FS#3524]: reorganisation of the train acceleration code plus some minor optimisations (Terkhen)
rubidium <rubidium@openttd.org>
parents:
14284
diff
changeset
|
401 assert(max_speed == this->GetCurveSpeedLimit()); |
f96af1b6a264
(svn r18838) -Codechange [FS#3524]: reorganisation of the train acceleration code plus some minor optimisations (Terkhen)
rubidium <rubidium@openttd.org>
parents:
14284
diff
changeset
|
402 |
f96af1b6a264
(svn r18838) -Codechange [FS#3524]: reorganisation of the train acceleration code plus some minor optimisations (Terkhen)
rubidium <rubidium@openttd.org>
parents:
14284
diff
changeset
|
403 if (IsRailStationTile(this->tile)) { |
f96af1b6a264
(svn r18838) -Codechange [FS#3524]: reorganisation of the train acceleration code plus some minor optimisations (Terkhen)
rubidium <rubidium@openttd.org>
parents:
14284
diff
changeset
|
404 StationID sid = GetStationIndex(this->tile); |
f96af1b6a264
(svn r18838) -Codechange [FS#3524]: reorganisation of the train acceleration code plus some minor optimisations (Terkhen)
rubidium <rubidium@openttd.org>
parents:
14284
diff
changeset
|
405 if (this->current_order.ShouldStopAtStation(this, sid)) { |
11657
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
406 int station_ahead; |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
407 int station_length; |
14286
f96af1b6a264
(svn r18838) -Codechange [FS#3524]: reorganisation of the train acceleration code plus some minor optimisations (Terkhen)
rubidium <rubidium@openttd.org>
parents:
14284
diff
changeset
|
408 int stop_at = GetTrainStopLocation(sid, this->tile, this, &station_ahead, &station_length); |
11657
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
409 |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
410 /* The distance to go is whatever is still ahead of the train minus the |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
411 * distance from the train's stop location to the end of the platform */ |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
412 int distance_to_go = station_ahead / TILE_SIZE - (station_length - stop_at) / TILE_SIZE; |
11677
8d40b1680957
(svn r16057) -Fix [FS#2834] (r16037): division by zero when having an order with only one station that has either middle or near end stop location and where the platform is (significantly) longer than the train.
rubidium <rubidium@openttd.org>
parents:
11657
diff
changeset
|
413 |
8d40b1680957
(svn r16057) -Fix [FS#2834] (r16037): division by zero when having an order with only one station that has either middle or near end stop location and where the platform is (significantly) longer than the train.
rubidium <rubidium@openttd.org>
parents:
11657
diff
changeset
|
414 if (distance_to_go > 0) { |
8d40b1680957
(svn r16057) -Fix [FS#2834] (r16037): division by zero when having an order with only one station that has either middle or near end stop location and where the platform is (significantly) longer than the train.
rubidium <rubidium@openttd.org>
parents:
11657
diff
changeset
|
415 int st_max_speed = 120; |
8d40b1680957
(svn r16057) -Fix [FS#2834] (r16037): division by zero when having an order with only one station that has either middle or near end stop location and where the platform is (significantly) longer than the train.
rubidium <rubidium@openttd.org>
parents:
11657
diff
changeset
|
416 |
14286
f96af1b6a264
(svn r18838) -Codechange [FS#3524]: reorganisation of the train acceleration code plus some minor optimisations (Terkhen)
rubidium <rubidium@openttd.org>
parents:
14284
diff
changeset
|
417 int delta_v = this->cur_speed / (distance_to_go + 1); |
15064
a34ec81b63b0
(svn r19687) -Fix: desync when joining the game because of using the wrong variable
rubidium <rubidium@openttd.org>
parents:
15009
diff
changeset
|
418 if (max_speed > (this->cur_speed - delta_v)) { |
14286
f96af1b6a264
(svn r18838) -Codechange [FS#3524]: reorganisation of the train acceleration code plus some minor optimisations (Terkhen)
rubidium <rubidium@openttd.org>
parents:
14284
diff
changeset
|
419 st_max_speed = this->cur_speed - (delta_v / 10); |
11677
8d40b1680957
(svn r16057) -Fix [FS#2834] (r16037): division by zero when having an order with only one station that has either middle or near end stop location and where the platform is (significantly) longer than the train.
rubidium <rubidium@openttd.org>
parents:
11657
diff
changeset
|
420 } |
8d40b1680957
(svn r16057) -Fix [FS#2834] (r16037): division by zero when having an order with only one station that has either middle or near end stop location and where the platform is (significantly) longer than the train.
rubidium <rubidium@openttd.org>
parents:
11657
diff
changeset
|
421 |
8d40b1680957
(svn r16057) -Fix [FS#2834] (r16037): division by zero when having an order with only one station that has either middle or near end stop location and where the platform is (significantly) longer than the train.
rubidium <rubidium@openttd.org>
parents:
11657
diff
changeset
|
422 st_max_speed = max(st_max_speed, 25 * distance_to_go); |
8d40b1680957
(svn r16057) -Fix [FS#2834] (r16037): division by zero when having an order with only one station that has either middle or near end stop location and where the platform is (significantly) longer than the train.
rubidium <rubidium@openttd.org>
parents:
11657
diff
changeset
|
423 max_speed = min(max_speed, st_max_speed); |
8170
a8be61a5213c
(svn r11733) -Fix: Max speed for entering stations overrode the max speed of curves
peter1138 <peter1138@openttd.org>
parents:
8169
diff
changeset
|
424 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
425 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
426 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
427 |
14286
f96af1b6a264
(svn r18838) -Codechange [FS#3524]: reorganisation of the train acceleration code plus some minor optimisations (Terkhen)
rubidium <rubidium@openttd.org>
parents:
14284
diff
changeset
|
428 for (const Train *u = this; u != NULL; u = u->Next()) { |
f96af1b6a264
(svn r18838) -Codechange [FS#3524]: reorganisation of the train acceleration code plus some minor optimisations (Terkhen)
rubidium <rubidium@openttd.org>
parents:
14284
diff
changeset
|
429 if (u->track == TRACK_BIT_DEPOT) { |
f96af1b6a264
(svn r18838) -Codechange [FS#3524]: reorganisation of the train acceleration code plus some minor optimisations (Terkhen)
rubidium <rubidium@openttd.org>
parents:
14284
diff
changeset
|
430 max_speed = min(max_speed, 61); |
f96af1b6a264
(svn r18838) -Codechange [FS#3524]: reorganisation of the train acceleration code plus some minor optimisations (Terkhen)
rubidium <rubidium@openttd.org>
parents:
14284
diff
changeset
|
431 break; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
432 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
433 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
434 |
16785
775f357828e3
(svn r21518) -Codechange: Rename AccelerationCache to GroundVehicleCache.
terkhen <terkhen@openttd.org>
parents:
16776
diff
changeset
|
435 return min(max_speed, this->gcache.cached_max_track_speed); |
14286
f96af1b6a264
(svn r18838) -Codechange [FS#3524]: reorganisation of the train acceleration code plus some minor optimisations (Terkhen)
rubidium <rubidium@openttd.org>
parents:
14284
diff
changeset
|
436 } |
f96af1b6a264
(svn r18838) -Codechange [FS#3524]: reorganisation of the train acceleration code plus some minor optimisations (Terkhen)
rubidium <rubidium@openttd.org>
parents:
14284
diff
changeset
|
437 |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
438 void Train::UpdateAcceleration() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
439 { |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
440 assert(this->IsFrontEngine()); |
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
441 |
16785
775f357828e3
(svn r21518) -Codechange: Rename AccelerationCache to GroundVehicleCache.
terkhen <terkhen@openttd.org>
parents:
16776
diff
changeset
|
442 uint power = this->gcache.cached_power; |
775f357828e3
(svn r21518) -Codechange: Rename AccelerationCache to GroundVehicleCache.
terkhen <terkhen@openttd.org>
parents:
16776
diff
changeset
|
443 uint weight = this->gcache.cached_weight; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
444 assert(weight != 0); |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
445 this->acceleration = Clamp(power / weight * 4, 1, 255); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
446 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
447 |
12433
c3588e7cb8f6
(svn r16867) -Feature(ette): Turn variable 0E/8E (vertical offset for trains in depot) and variable 1E/9E bit 3 (wagon width in depot) into grf-local variables.
frosch <frosch@openttd.org>
parents:
12423
diff
changeset
|
448 /** |
c3588e7cb8f6
(svn r16867) -Feature(ette): Turn variable 0E/8E (vertical offset for trains in depot) and variable 1E/9E bit 3 (wagon width in depot) into grf-local variables.
frosch <frosch@openttd.org>
parents:
12423
diff
changeset
|
449 * Get the width of a train vehicle image in the GUI. |
c3588e7cb8f6
(svn r16867) -Feature(ette): Turn variable 0E/8E (vertical offset for trains in depot) and variable 1E/9E bit 3 (wagon width in depot) into grf-local variables.
frosch <frosch@openttd.org>
parents:
12423
diff
changeset
|
450 * @param offset Additional offset for positioning the sprite; set to NULL if not needed |
c3588e7cb8f6
(svn r16867) -Feature(ette): Turn variable 0E/8E (vertical offset for trains in depot) and variable 1E/9E bit 3 (wagon width in depot) into grf-local variables.
frosch <frosch@openttd.org>
parents:
12423
diff
changeset
|
451 * @return Width in pixels |
c3588e7cb8f6
(svn r16867) -Feature(ette): Turn variable 0E/8E (vertical offset for trains in depot) and variable 1E/9E bit 3 (wagon width in depot) into grf-local variables.
frosch <frosch@openttd.org>
parents:
12423
diff
changeset
|
452 */ |
c3588e7cb8f6
(svn r16867) -Feature(ette): Turn variable 0E/8E (vertical offset for trains in depot) and variable 1E/9E bit 3 (wagon width in depot) into grf-local variables.
frosch <frosch@openttd.org>
parents:
12423
diff
changeset
|
453 int Train::GetDisplayImageWidth(Point *offset) const |
c3588e7cb8f6
(svn r16867) -Feature(ette): Turn variable 0E/8E (vertical offset for trains in depot) and variable 1E/9E bit 3 (wagon width in depot) into grf-local variables.
frosch <frosch@openttd.org>
parents:
12423
diff
changeset
|
454 { |
c3588e7cb8f6
(svn r16867) -Feature(ette): Turn variable 0E/8E (vertical offset for trains in depot) and variable 1E/9E bit 3 (wagon width in depot) into grf-local variables.
frosch <frosch@openttd.org>
parents:
12423
diff
changeset
|
455 int reference_width = TRAININFO_DEFAULT_VEHICLE_WIDTH; |
c3588e7cb8f6
(svn r16867) -Feature(ette): Turn variable 0E/8E (vertical offset for trains in depot) and variable 1E/9E bit 3 (wagon width in depot) into grf-local variables.
frosch <frosch@openttd.org>
parents:
12423
diff
changeset
|
456 int vehicle_pitch = 0; |
c3588e7cb8f6
(svn r16867) -Feature(ette): Turn variable 0E/8E (vertical offset for trains in depot) and variable 1E/9E bit 3 (wagon width in depot) into grf-local variables.
frosch <frosch@openttd.org>
parents:
12423
diff
changeset
|
457 |
c3588e7cb8f6
(svn r16867) -Feature(ette): Turn variable 0E/8E (vertical offset for trains in depot) and variable 1E/9E bit 3 (wagon width in depot) into grf-local variables.
frosch <frosch@openttd.org>
parents:
12423
diff
changeset
|
458 const Engine *e = Engine::Get(this->engine_type); |
15763
a60a50f29f64
(svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents:
15710
diff
changeset
|
459 if (e->grf_prop.grffile != NULL && is_custom_sprite(e->u.rail.image_index)) { |
a60a50f29f64
(svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents:
15710
diff
changeset
|
460 reference_width = e->grf_prop.grffile->traininfo_vehicle_width; |
a60a50f29f64
(svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents:
15710
diff
changeset
|
461 vehicle_pitch = e->grf_prop.grffile->traininfo_vehicle_pitch; |
12433
c3588e7cb8f6
(svn r16867) -Feature(ette): Turn variable 0E/8E (vertical offset for trains in depot) and variable 1E/9E bit 3 (wagon width in depot) into grf-local variables.
frosch <frosch@openttd.org>
parents:
12423
diff
changeset
|
462 } |
c3588e7cb8f6
(svn r16867) -Feature(ette): Turn variable 0E/8E (vertical offset for trains in depot) and variable 1E/9E bit 3 (wagon width in depot) into grf-local variables.
frosch <frosch@openttd.org>
parents:
12423
diff
changeset
|
463 |
c3588e7cb8f6
(svn r16867) -Feature(ette): Turn variable 0E/8E (vertical offset for trains in depot) and variable 1E/9E bit 3 (wagon width in depot) into grf-local variables.
frosch <frosch@openttd.org>
parents:
12423
diff
changeset
|
464 if (offset != NULL) { |
c3588e7cb8f6
(svn r16867) -Feature(ette): Turn variable 0E/8E (vertical offset for trains in depot) and variable 1E/9E bit 3 (wagon width in depot) into grf-local variables.
frosch <frosch@openttd.org>
parents:
12423
diff
changeset
|
465 offset->x = reference_width / 2; |
c3588e7cb8f6
(svn r16867) -Feature(ette): Turn variable 0E/8E (vertical offset for trains in depot) and variable 1E/9E bit 3 (wagon width in depot) into grf-local variables.
frosch <frosch@openttd.org>
parents:
12423
diff
changeset
|
466 offset->y = vehicle_pitch; |
c3588e7cb8f6
(svn r16867) -Feature(ette): Turn variable 0E/8E (vertical offset for trains in depot) and variable 1E/9E bit 3 (wagon width in depot) into grf-local variables.
frosch <frosch@openttd.org>
parents:
12423
diff
changeset
|
467 } |
17451
2dbd537df54d
(svn r22205) -Codechange: replace magic number with constant
rubidium <rubidium@openttd.org>
parents:
17399
diff
changeset
|
468 return this->gcache.cached_veh_length * reference_width / VEHICLE_LENGTH; |
12433
c3588e7cb8f6
(svn r16867) -Feature(ette): Turn variable 0E/8E (vertical offset for trains in depot) and variable 1E/9E bit 3 (wagon width in depot) into grf-local variables.
frosch <frosch@openttd.org>
parents:
12423
diff
changeset
|
469 } |
c3588e7cb8f6
(svn r16867) -Feature(ette): Turn variable 0E/8E (vertical offset for trains in depot) and variable 1E/9E bit 3 (wagon width in depot) into grf-local variables.
frosch <frosch@openttd.org>
parents:
12423
diff
changeset
|
470 |
12020
e9a4f34044d8
(svn r16427) -Codechange: replace a few magic numbers with an existing constant and unduplicate a few lines.
rubidium <rubidium@openttd.org>
parents:
12015
diff
changeset
|
471 static SpriteID GetDefaultTrainSprite(uint8 spritenum, Direction direction) |
e9a4f34044d8
(svn r16427) -Codechange: replace a few magic numbers with an existing constant and unduplicate a few lines.
rubidium <rubidium@openttd.org>
parents:
12015
diff
changeset
|
472 { |
e9a4f34044d8
(svn r16427) -Codechange: replace a few magic numbers with an existing constant and unduplicate a few lines.
rubidium <rubidium@openttd.org>
parents:
12015
diff
changeset
|
473 return ((direction + _engine_sprite_add[spritenum]) & _engine_sprite_and[spritenum]) + _engine_sprite_base[spritenum]; |
e9a4f34044d8
(svn r16427) -Codechange: replace a few magic numbers with an existing constant and unduplicate a few lines.
rubidium <rubidium@openttd.org>
parents:
12015
diff
changeset
|
474 } |
e9a4f34044d8
(svn r16427) -Codechange: replace a few magic numbers with an existing constant and unduplicate a few lines.
rubidium <rubidium@openttd.org>
parents:
12015
diff
changeset
|
475 |
9022
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
476 SpriteID Train::GetImage(Direction direction) const |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
477 { |
9022
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
478 uint8 spritenum = this->spritenum; |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
479 SpriteID sprite; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
480 |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
481 if (HasBit(this->flags, VRF_REVERSE_DIRECTION)) direction = ReverseDir(direction); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
482 |
9022
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
483 if (is_custom_sprite(spritenum)) { |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
484 sprite = GetCustomVehicleSprite(this, (Direction)(direction + 4 * IS_CUSTOM_SECONDHEAD_SPRITE(spritenum))); |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
485 if (sprite != 0) return sprite; |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
486 |
12164
d1a94177c6ec
(svn r16580) -Codechange: rename Engine::image_index to original_image_index to not confuse it with image_index from *VehInfo.
rubidium <rubidium@openttd.org>
parents:
12155
diff
changeset
|
487 spritenum = Engine::Get(this->engine_type)->original_image_index; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
488 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
489 |
12020
e9a4f34044d8
(svn r16427) -Codechange: replace a few magic numbers with an existing constant and unduplicate a few lines.
rubidium <rubidium@openttd.org>
parents:
12015
diff
changeset
|
490 sprite = GetDefaultTrainSprite(spritenum, direction); |
9022
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
491 |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
492 if (this->cargo.Count() >= this->cargo_cap / 2U) sprite += _wagon_full_adder[spritenum]; |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
493 |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
494 return sprite; |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
495 } |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
496 |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
497 static SpriteID GetRailIcon(EngineID engine, bool rear_head, int &y) |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
498 { |
12433
c3588e7cb8f6
(svn r16867) -Feature(ette): Turn variable 0E/8E (vertical offset for trains in depot) and variable 1E/9E bit 3 (wagon width in depot) into grf-local variables.
frosch <frosch@openttd.org>
parents:
12423
diff
changeset
|
499 const Engine *e = Engine::Get(engine); |
9022
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
500 Direction dir = rear_head ? DIR_E : DIR_W; |
12433
c3588e7cb8f6
(svn r16867) -Feature(ette): Turn variable 0E/8E (vertical offset for trains in depot) and variable 1E/9E bit 3 (wagon width in depot) into grf-local variables.
frosch <frosch@openttd.org>
parents:
12423
diff
changeset
|
501 uint8 spritenum = e->u.rail.image_index; |
9022
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
502 |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
503 if (is_custom_sprite(spritenum)) { |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
504 SpriteID sprite = GetCustomVehicleIcon(engine, dir); |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
505 if (sprite != 0) { |
15763
a60a50f29f64
(svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents:
15710
diff
changeset
|
506 if (e->grf_prop.grffile != NULL) { |
a60a50f29f64
(svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents:
15710
diff
changeset
|
507 y += e->grf_prop.grffile->traininfo_vehicle_pitch; |
12433
c3588e7cb8f6
(svn r16867) -Feature(ette): Turn variable 0E/8E (vertical offset for trains in depot) and variable 1E/9E bit 3 (wagon width in depot) into grf-local variables.
frosch <frosch@openttd.org>
parents:
12423
diff
changeset
|
508 } |
9022
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
509 return sprite; |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
510 } |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
511 |
12164
d1a94177c6ec
(svn r16580) -Codechange: rename Engine::image_index to original_image_index to not confuse it with image_index from *VehInfo.
rubidium <rubidium@openttd.org>
parents:
12155
diff
changeset
|
512 spritenum = Engine::Get(engine)->original_image_index; |
9022
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
513 } |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
514 |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
515 if (rear_head) spritenum++; |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
516 |
12020
e9a4f34044d8
(svn r16427) -Codechange: replace a few magic numbers with an existing constant and unduplicate a few lines.
rubidium <rubidium@openttd.org>
parents:
12015
diff
changeset
|
517 return GetDefaultTrainSprite(spritenum, DIR_W); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
518 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
519 |
14319
72cb3c72d619
(svn r18872) -Codechange: introduce PaletteID and use it
rubidium <rubidium@openttd.org>
parents:
14314
diff
changeset
|
520 void DrawTrainEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
521 { |
9022
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
522 if (RailVehInfo(engine)->railveh_type == RAILVEH_MULTIHEAD) { |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
523 int yf = y; |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
524 int yr = y; |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
525 |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
526 SpriteID spritef = GetRailIcon(engine, false, yf); |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
527 SpriteID spriter = GetRailIcon(engine, true, yr); |
13599
28fe769d10b8
(svn r18123) -Codechange: try our best to keep the vehicles within the build vehicle list/autoreplace lists instead of overflowing.
rubidium <rubidium@openttd.org>
parents:
13597
diff
changeset
|
528 const Sprite *real_spritef = GetSprite(spritef, ST_NORMAL); |
28fe769d10b8
(svn r18123) -Codechange: try our best to keep the vehicles within the build vehicle list/autoreplace lists instead of overflowing.
rubidium <rubidium@openttd.org>
parents:
13597
diff
changeset
|
529 const Sprite *real_spriter = GetSprite(spriter, ST_NORMAL); |
28fe769d10b8
(svn r18123) -Codechange: try our best to keep the vehicles within the build vehicle list/autoreplace lists instead of overflowing.
rubidium <rubidium@openttd.org>
parents:
13597
diff
changeset
|
530 |
28fe769d10b8
(svn r18123) -Codechange: try our best to keep the vehicles within the build vehicle list/autoreplace lists instead of overflowing.
rubidium <rubidium@openttd.org>
parents:
13597
diff
changeset
|
531 preferred_x = Clamp(preferred_x, left - real_spritef->x_offs + 14, right - real_spriter->width - real_spriter->x_offs - 15); |
28fe769d10b8
(svn r18123) -Codechange: try our best to keep the vehicles within the build vehicle list/autoreplace lists instead of overflowing.
rubidium <rubidium@openttd.org>
parents:
13597
diff
changeset
|
532 |
13597
706013b8e441
(svn r18121) -Codechange: pass the maximum left/right location to the Draw*Engine functions
rubidium <rubidium@openttd.org>
parents:
13492
diff
changeset
|
533 DrawSprite(spritef, pal, preferred_x - 14, yf); |
706013b8e441
(svn r18121) -Codechange: pass the maximum left/right location to the Draw*Engine functions
rubidium <rubidium@openttd.org>
parents:
13492
diff
changeset
|
534 DrawSprite(spriter, pal, preferred_x + 15, yr); |
9022
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
535 } else { |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
536 SpriteID sprite = GetRailIcon(engine, false, y); |
13599
28fe769d10b8
(svn r18123) -Codechange: try our best to keep the vehicles within the build vehicle list/autoreplace lists instead of overflowing.
rubidium <rubidium@openttd.org>
parents:
13597
diff
changeset
|
537 const Sprite *real_sprite = GetSprite(sprite, ST_NORMAL); |
28fe769d10b8
(svn r18123) -Codechange: try our best to keep the vehicles within the build vehicle list/autoreplace lists instead of overflowing.
rubidium <rubidium@openttd.org>
parents:
13597
diff
changeset
|
538 preferred_x = Clamp(preferred_x, left - real_sprite->x_offs, right - real_sprite->width - real_sprite->x_offs); |
13597
706013b8e441
(svn r18121) -Codechange: pass the maximum left/right location to the Draw*Engine functions
rubidium <rubidium@openttd.org>
parents:
13492
diff
changeset
|
539 DrawSprite(sprite, pal, preferred_x, y); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
540 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
541 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
542 |
15849
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
543 /** |
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
544 * Build a railroad wagon. |
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
545 * @param tile tile of the depot where rail-vehicle is built. |
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
546 * @param flags type of operation. |
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
547 * @param e the engine to build. |
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
548 * @param ret[out] the vehicle that has been built. |
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
549 * @return the cost of this operation or an error. |
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
550 */ |
15890
52d3e250c976
(svn r20572) -Codechange: free/reserve some bits in the wagon move command to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents:
15865
diff
changeset
|
551 static CommandCost CmdBuildRailWagon(TileIndex tile, DoCommandFlag flags, const Engine *e, Vehicle **ret) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
552 { |
11188
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11150
diff
changeset
|
553 const RailVehicleInfo *rvi = &e->u.rail; |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
554 |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
555 /* Check that the wagon can drive on the track in question */ |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
556 if (!IsCompatibleRail(rvi->railtype, GetRailType(tile))) return CMD_ERROR; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
557 |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
558 if (flags & DC_EXEC) { |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
559 Train *v = new Train(); |
15849
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
560 *ret = v; |
11902
5b2be5f84fe8
(svn r16302) -Codechange: remove Vehicle::AllocateList
smatz <smatz@openttd.org>
parents:
11901
diff
changeset
|
561 v->spritenum = rvi->image_index; |
5b2be5f84fe8
(svn r16302) -Codechange: remove Vehicle::AllocateList
smatz <smatz@openttd.org>
parents:
11901
diff
changeset
|
562 |
15849
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
563 v->engine_type = e->index; |
16788
efb0333e5aad
(svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
564 v->gcache.first_engine = INVALID_ENGINE; // needs to be set before first callback |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
565 |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
566 DiagDirection dir = GetRailDepotDirection(tile); |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
567 |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
568 v->direction = DiagDirToDir(dir); |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
569 v->tile = tile; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
570 |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
571 int x = TileX(tile) * TILE_SIZE | _vehicle_initial_x_fract[dir]; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
572 int y = TileY(tile) * TILE_SIZE | _vehicle_initial_y_fract[dir]; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
573 |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
574 v->x_pos = x; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
575 v->y_pos = y; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
576 v->z_pos = GetSlopeZ(x, y); |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
577 v->owner = _current_company; |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
578 v->track = TRACK_BIT_DEPOT; |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
579 v->vehstatus = VS_HIDDEN | VS_DEFPAL; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
580 |
12303
ca4bc7e70a4d
(svn r16720) -Codechange: make Set/ClearFrontEngine(), Set/ClearArticulatedPart(), Set/ClearWagon(), Set/ClearEngine(), Set/ClearFreeWagon() and Set/ClearMultiheaded() members of Train
smatz <smatz@openttd.org>
parents:
12302
diff
changeset
|
581 v->SetWagon(); |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
582 |
13934
6c8c9b6e2b7b
(svn r18466) -Codechange: use CmdMoveRailWagon to attach a just build wagon to a chain
rubidium <rubidium@openttd.org>
parents:
13933
diff
changeset
|
583 v->SetFreeWagon(); |
6c8c9b6e2b7b
(svn r18466) -Codechange: use CmdMoveRailWagon to attach a just build wagon to a chain
rubidium <rubidium@openttd.org>
parents:
13933
diff
changeset
|
584 InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
585 |
11188
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11150
diff
changeset
|
586 v->cargo_type = e->GetDefaultCargoType(); |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
587 v->cargo_cap = rvi->capacity; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
588 |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
589 v->railtype = rvi->railtype; |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
590 |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
591 v->build_year = _cur_year; |
11903
c40e241e65ba
(svn r16303) -Codechange: Use the question mark as default sprite when creating vehicles, instead of arbitrary sprites not related to the vehicle. (though that also applies to the question mark)
frosch <frosch@openttd.org>
parents:
11902
diff
changeset
|
592 v->cur_image = SPR_IMG_QUERY; |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
593 v->random_bits = VehicleRandomBits(); |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
594 |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
595 v->group_id = DEFAULT_GROUP; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
596 |
13219
39e3a60fd47f
(svn r17726) -Cleanup: Remove some unneeded/unused parameters.
frosch <frosch@openttd.org>
parents:
13218
diff
changeset
|
597 AddArticulatedParts(v); |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
598 |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
599 _new_vehicle_id = v->index; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
600 |
11326
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11268
diff
changeset
|
601 VehicleMove(v, false); |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
602 v->First()->ConsistChanged(false); |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
603 UpdateTrainGroupID(v->First()); |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
604 |
11351
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11327
diff
changeset
|
605 CheckConsistencyOfArticulatedVehicle(v); |
13934
6c8c9b6e2b7b
(svn r18466) -Codechange: use CmdMoveRailWagon to attach a just build wagon to a chain
rubidium <rubidium@openttd.org>
parents:
13933
diff
changeset
|
606 |
6c8c9b6e2b7b
(svn r18466) -Codechange: use CmdMoveRailWagon to attach a just build wagon to a chain
rubidium <rubidium@openttd.org>
parents:
13933
diff
changeset
|
607 /* Try to connect the vehicle to one of free chains of wagons. */ |
6c8c9b6e2b7b
(svn r18466) -Codechange: use CmdMoveRailWagon to attach a just build wagon to a chain
rubidium <rubidium@openttd.org>
parents:
13933
diff
changeset
|
608 Train *w; |
6c8c9b6e2b7b
(svn r18466) -Codechange: use CmdMoveRailWagon to attach a just build wagon to a chain
rubidium <rubidium@openttd.org>
parents:
13933
diff
changeset
|
609 FOR_ALL_TRAINS(w) { |
14106
4b9804ff406b
(svn r18653) -Fix [FS#3442]: when trying to attach a wagon to an existing free wagon chain, don't attach it to itself
rubidium <rubidium@openttd.org>
parents:
14100
diff
changeset
|
610 if (w->tile == tile && ///< Same depot |
4b9804ff406b
(svn r18653) -Fix [FS#3442]: when trying to attach a wagon to an existing free wagon chain, don't attach it to itself
rubidium <rubidium@openttd.org>
parents:
14100
diff
changeset
|
611 w->IsFreeWagon() && ///< A free wagon chain |
15849
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
612 w->engine_type == e->index && ///< Same type |
14106
4b9804ff406b
(svn r18653) -Fix [FS#3442]: when trying to attach a wagon to an existing free wagon chain, don't attach it to itself
rubidium <rubidium@openttd.org>
parents:
14100
diff
changeset
|
613 w->First() != v && ///< Don't connect to ourself |
4b9804ff406b
(svn r18653) -Fix [FS#3442]: when trying to attach a wagon to an existing free wagon chain, don't attach it to itself
rubidium <rubidium@openttd.org>
parents:
14100
diff
changeset
|
614 !(w->vehstatus & VS_CRASHED)) { ///< Not crashed/flooded |
15890
52d3e250c976
(svn r20572) -Codechange: free/reserve some bits in the wagon move command to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents:
15865
diff
changeset
|
615 DoCommand(0, v->index | 1 << 20, w->Last()->index, DC_EXEC, CMD_MOVE_RAIL_VEHICLE); |
13934
6c8c9b6e2b7b
(svn r18466) -Codechange: use CmdMoveRailWagon to attach a just build wagon to a chain
rubidium <rubidium@openttd.org>
parents:
13933
diff
changeset
|
616 break; |
6c8c9b6e2b7b
(svn r18466) -Codechange: use CmdMoveRailWagon to attach a just build wagon to a chain
rubidium <rubidium@openttd.org>
parents:
13933
diff
changeset
|
617 } |
6c8c9b6e2b7b
(svn r18466) -Codechange: use CmdMoveRailWagon to attach a just build wagon to a chain
rubidium <rubidium@openttd.org>
parents:
13933
diff
changeset
|
618 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
619 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
620 |
15849
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
621 return CommandCost(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
622 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
623 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
624 /** Move all free vehicles in the depot to the train */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
625 static void NormalizeTrainVehInDepot(const Train *u) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
626 { |
12035
dcc31c1d758a
(svn r16442) -Codechange: use new Vehicle accessors at more places
smatz <smatz@openttd.org>
parents:
12034
diff
changeset
|
627 const Train *v; |
dcc31c1d758a
(svn r16442) -Codechange: use new Vehicle accessors at more places
smatz <smatz@openttd.org>
parents:
12034
diff
changeset
|
628 FOR_ALL_TRAINS(v) { |
12301
218a41d3d557
(svn r16718) -Codechange: make IsFreeWagon() member of Train
smatz <smatz@openttd.org>
parents:
12300
diff
changeset
|
629 if (v->IsFreeWagon() && v->tile == u->tile && |
12035
dcc31c1d758a
(svn r16442) -Codechange: use new Vehicle accessors at more places
smatz <smatz@openttd.org>
parents:
12034
diff
changeset
|
630 v->track == TRACK_BIT_DEPOT) { |
15890
52d3e250c976
(svn r20572) -Codechange: free/reserve some bits in the wagon move command to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents:
15865
diff
changeset
|
631 if (DoCommand(0, v->index | 1 << 20, u->index, DC_EXEC, |
14314
60d313b887b8
(svn r18866) -Codechange: remove the CmdFailed(ret)/CmdSucceeded(ret) wrapper functions
rubidium <rubidium@openttd.org>
parents:
14302
diff
changeset
|
632 CMD_MOVE_RAIL_VEHICLE).Failed()) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
633 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
634 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
635 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
636 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
637 |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
638 static void AddRearEngineToMultiheadedTrain(Train *v) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
639 { |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
640 Train *u = new Train(); |
11902
5b2be5f84fe8
(svn r16302) -Codechange: remove Vehicle::AllocateList
smatz <smatz@openttd.org>
parents:
11901
diff
changeset
|
641 v->value >>= 1; |
5b2be5f84fe8
(svn r16302) -Codechange: remove Vehicle::AllocateList
smatz <smatz@openttd.org>
parents:
11901
diff
changeset
|
642 u->value = v->value; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
643 u->direction = v->direction; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
644 u->owner = v->owner; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
645 u->tile = v->tile; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
646 u->x_pos = v->x_pos; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
647 u->y_pos = v->y_pos; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
648 u->z_pos = v->z_pos; |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
649 u->track = TRACK_BIT_DEPOT; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
650 u->vehstatus = v->vehstatus & ~VS_STOPPED; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
651 u->spritenum = v->spritenum + 1; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
652 u->cargo_type = v->cargo_type; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
653 u->cargo_subtype = v->cargo_subtype; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
654 u->cargo_cap = v->cargo_cap; |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
655 u->railtype = v->railtype; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
656 u->engine_type = v->engine_type; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
657 u->build_year = v->build_year; |
11903
c40e241e65ba
(svn r16303) -Codechange: Use the question mark as default sprite when creating vehicles, instead of arbitrary sprites not related to the vehicle. (though that also applies to the question mark)
frosch <frosch@openttd.org>
parents:
11902
diff
changeset
|
658 u->cur_image = SPR_IMG_QUERY; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
659 u->random_bits = VehicleRandomBits(); |
12303
ca4bc7e70a4d
(svn r16720) -Codechange: make Set/ClearFrontEngine(), Set/ClearArticulatedPart(), Set/ClearWagon(), Set/ClearEngine(), Set/ClearFreeWagon() and Set/ClearMultiheaded() members of Train
smatz <smatz@openttd.org>
parents:
12302
diff
changeset
|
660 v->SetMultiheaded(); |
ca4bc7e70a4d
(svn r16720) -Codechange: make Set/ClearFrontEngine(), Set/ClearArticulatedPart(), Set/ClearWagon(), Set/ClearEngine(), Set/ClearFreeWagon() and Set/ClearMultiheaded() members of Train
smatz <smatz@openttd.org>
parents:
12302
diff
changeset
|
661 u->SetMultiheaded(); |
11902
5b2be5f84fe8
(svn r16302) -Codechange: remove Vehicle::AllocateList
smatz <smatz@openttd.org>
parents:
11901
diff
changeset
|
662 v->SetNext(u); |
11326
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11268
diff
changeset
|
663 VehicleMove(u, false); |
11902
5b2be5f84fe8
(svn r16302) -Codechange: remove Vehicle::AllocateList
smatz <smatz@openttd.org>
parents:
11901
diff
changeset
|
664 |
5b2be5f84fe8
(svn r16302) -Codechange: remove Vehicle::AllocateList
smatz <smatz@openttd.org>
parents:
11901
diff
changeset
|
665 /* Now we need to link the front and rear engines together */ |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
666 v->other_multiheaded_part = u; |
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
667 u->other_multiheaded_part = v; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
668 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
669 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
670 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
671 * Build a railroad vehicle. |
15849
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
672 * @param tile tile of the depot where rail-vehicle is built. |
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
673 * @param flags type of operation. |
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
674 * @param e the engine to build. |
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
675 * @param data bit 0 prevents any free cars from being added to the train. |
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
676 * @param ret[out] the vehicle that has been built. |
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
677 * @return the cost of this operation or an error. |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
678 */ |
15849
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
679 CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **ret) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
680 { |
13218
03a409fa4c29
(svn r17725) -Codechange: Reduce usage of EngInfo and XxxVehInfo, esp. when a Engine * is already present.
frosch <frosch@openttd.org>
parents:
13186
diff
changeset
|
681 const RailVehicleInfo *rvi = &e->u.rail; |
15849
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
682 |
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
683 if (rvi->railveh_type == RAILVEH_WAGON) return CmdBuildRailWagon(tile, flags, e, ret); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
684 |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
685 /* Check if depot and new engine uses the same kind of tracks * |
15820
59fd8293b2ee
(svn r20499) -Doc: Spelling fixes, and one doxygen comment addition.
alberth <alberth@openttd.org>
parents:
15763
diff
changeset
|
686 * We need to see if the engine got power on the tile to avoid electric engines in non-electric depots */ |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
687 if (!HasPowerOnRail(rvi->railtype, GetRailType(tile))) return CMD_ERROR; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
688 |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
689 if (flags & DC_EXEC) { |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
690 DiagDirection dir = GetRailDepotDirection(tile); |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
691 int x = TileX(tile) * TILE_SIZE + _vehicle_initial_x_fract[dir]; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
692 int y = TileY(tile) * TILE_SIZE + _vehicle_initial_y_fract[dir]; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
693 |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
694 Train *v = new Train(); |
15849
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
695 *ret = v; |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
696 v->direction = DiagDirToDir(dir); |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
697 v->tile = tile; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
698 v->owner = _current_company; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
699 v->x_pos = x; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
700 v->y_pos = y; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
701 v->z_pos = GetSlopeZ(x, y); |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
702 v->track = TRACK_BIT_DEPOT; |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
703 v->vehstatus = VS_HIDDEN | VS_STOPPED | VS_DEFPAL; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
704 v->spritenum = rvi->image_index; |
11188
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11150
diff
changeset
|
705 v->cargo_type = e->GetDefaultCargoType(); |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
706 v->cargo_cap = rvi->capacity; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
707 v->last_station_visited = INVALID_STATION; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
708 |
15849
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
709 v->engine_type = e->index; |
16788
efb0333e5aad
(svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
710 v->gcache.first_engine = INVALID_ENGINE; // needs to be set before first callback |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
711 |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
712 v->reliability = e->reliability; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
713 v->reliability_spd_dec = e->reliability_spd_dec; |
12165
299a364a2abc
(svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents:
12164
diff
changeset
|
714 v->max_age = e->GetLifeLengthInDays(); |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
715 |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
716 v->railtype = rvi->railtype; |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
717 _new_vehicle_id = v->index; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
718 |
12032
2afeb10ae6ba
(svn r16439) -Change: Make the default vehicle servicing settings company-based settings, so in a multiplayer game everyone can change them.
yexo <yexo@openttd.org>
parents:
12020
diff
changeset
|
719 v->service_interval = Company::Get(_current_company)->settings.vehicle.servint_trains; |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
720 v->date_of_last_service = _date; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
721 v->build_year = _cur_year; |
11903
c40e241e65ba
(svn r16303) -Codechange: Use the question mark as default sprite when creating vehicles, instead of arbitrary sprites not related to the vehicle. (though that also applies to the question mark)
frosch <frosch@openttd.org>
parents:
11902
diff
changeset
|
722 v->cur_image = SPR_IMG_QUERY; |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
723 v->random_bits = VehicleRandomBits(); |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
724 |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
725 if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE); |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
726 |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
727 v->group_id = DEFAULT_GROUP; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
728 |
12303
ca4bc7e70a4d
(svn r16720) -Codechange: make Set/ClearFrontEngine(), Set/ClearArticulatedPart(), Set/ClearWagon(), Set/ClearEngine(), Set/ClearFreeWagon() and Set/ClearMultiheaded() members of Train
smatz <smatz@openttd.org>
parents:
12302
diff
changeset
|
729 v->SetFrontEngine(); |
ca4bc7e70a4d
(svn r16720) -Codechange: make Set/ClearFrontEngine(), Set/ClearArticulatedPart(), Set/ClearWagon(), Set/ClearEngine(), Set/ClearFreeWagon() and Set/ClearMultiheaded() members of Train
smatz <smatz@openttd.org>
parents:
12302
diff
changeset
|
730 v->SetEngine(); |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
731 |
11326
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11268
diff
changeset
|
732 VehicleMove(v, false); |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
733 |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
734 if (rvi->railveh_type == RAILVEH_MULTIHEAD) { |
11902
5b2be5f84fe8
(svn r16302) -Codechange: remove Vehicle::AllocateList
smatz <smatz@openttd.org>
parents:
11901
diff
changeset
|
735 AddRearEngineToMultiheadedTrain(v); |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
736 } else { |
13219
39e3a60fd47f
(svn r17726) -Cleanup: Remove some unneeded/unused parameters.
frosch <frosch@openttd.org>
parents:
13218
diff
changeset
|
737 AddArticulatedParts(v); |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
738 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
739 |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
740 v->ConsistChanged(false); |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
741 UpdateTrainGroupID(v); |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
742 |
15849
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
743 if (!HasBit(data, 0) && !(flags & DC_AUTOREPLACE)) { // check if the cars should be added to the new vehicle |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
744 NormalizeTrainVehInDepot(v); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
745 } |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
746 |
11351
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11327
diff
changeset
|
747 CheckConsistencyOfArticulatedVehicle(v); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
748 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
749 |
15849
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
750 return CommandCost(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
751 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
752 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
753 |
13948
1a7862d4528d
(svn r18484) -Codechange: simplify the Is(Stopped)InDepot functions for trains
rubidium <rubidium@openttd.org>
parents:
13945
diff
changeset
|
754 bool Train::IsInDepot() const |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
755 { |
13948
1a7862d4528d
(svn r18484) -Codechange: simplify the Is(Stopped)InDepot functions for trains
rubidium <rubidium@openttd.org>
parents:
13945
diff
changeset
|
756 /* Is the front engine stationary in the depot? */ |
1a7862d4528d
(svn r18484) -Codechange: simplify the Is(Stopped)InDepot functions for trains
rubidium <rubidium@openttd.org>
parents:
13945
diff
changeset
|
757 if (!IsRailDepotTile(this->tile) || this->cur_speed != 0) return false; |
1a7862d4528d
(svn r18484) -Codechange: simplify the Is(Stopped)InDepot functions for trains
rubidium <rubidium@openttd.org>
parents:
13945
diff
changeset
|
758 |
1a7862d4528d
(svn r18484) -Codechange: simplify the Is(Stopped)InDepot functions for trains
rubidium <rubidium@openttd.org>
parents:
13945
diff
changeset
|
759 /* Check whether the rest is also already trying to enter the depot. */ |
1a7862d4528d
(svn r18484) -Codechange: simplify the Is(Stopped)InDepot functions for trains
rubidium <rubidium@openttd.org>
parents:
13945
diff
changeset
|
760 for (const Train *v = this; v != NULL; v = v->Next()) { |
1a7862d4528d
(svn r18484) -Codechange: simplify the Is(Stopped)InDepot functions for trains
rubidium <rubidium@openttd.org>
parents:
13945
diff
changeset
|
761 if (v->track != TRACK_BIT_DEPOT || v->tile != this->tile) return false; |
13933
a71da8c8c5e2
(svn r18465) -Codechange: simplify CheckTrainInDepot and remove some unneeded wrapper functions
rubidium <rubidium@openttd.org>
parents:
13931
diff
changeset
|
762 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
763 |
13948
1a7862d4528d
(svn r18484) -Codechange: simplify the Is(Stopped)InDepot functions for trains
rubidium <rubidium@openttd.org>
parents:
13945
diff
changeset
|
764 return true; |
1a7862d4528d
(svn r18484) -Codechange: simplify the Is(Stopped)InDepot functions for trains
rubidium <rubidium@openttd.org>
parents:
13945
diff
changeset
|
765 } |
1a7862d4528d
(svn r18484) -Codechange: simplify the Is(Stopped)InDepot functions for trains
rubidium <rubidium@openttd.org>
parents:
13945
diff
changeset
|
766 |
1a7862d4528d
(svn r18484) -Codechange: simplify the Is(Stopped)InDepot functions for trains
rubidium <rubidium@openttd.org>
parents:
13945
diff
changeset
|
767 bool Train::IsStoppedInDepot() const |
1a7862d4528d
(svn r18484) -Codechange: simplify the Is(Stopped)InDepot functions for trains
rubidium <rubidium@openttd.org>
parents:
13945
diff
changeset
|
768 { |
15820
59fd8293b2ee
(svn r20499) -Doc: Spelling fixes, and one doxygen comment addition.
alberth <alberth@openttd.org>
parents:
15763
diff
changeset
|
769 /* Are we stopped? Of course wagons don't really care... */ |
13948
1a7862d4528d
(svn r18484) -Codechange: simplify the Is(Stopped)InDepot functions for trains
rubidium <rubidium@openttd.org>
parents:
13945
diff
changeset
|
770 if (this->IsFrontEngine() && !(this->vehstatus & VS_STOPPED)) return false; |
1a7862d4528d
(svn r18484) -Codechange: simplify the Is(Stopped)InDepot functions for trains
rubidium <rubidium@openttd.org>
parents:
13945
diff
changeset
|
771 return this->IsInDepot(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
772 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
773 |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
774 static Train *FindGoodVehiclePos(const Train *src) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
775 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
776 EngineID eng = src->engine_type; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
777 TileIndex tile = src->tile; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
778 |
12034
aa140a9c419c
(svn r16441) -Codechange: new class SpecializedVehicle used as superclass for all vehicle types
smatz <smatz@openttd.org>
parents:
12032
diff
changeset
|
779 Train *dst; |
aa140a9c419c
(svn r16441) -Codechange: new class SpecializedVehicle used as superclass for all vehicle types
smatz <smatz@openttd.org>
parents:
12032
diff
changeset
|
780 FOR_ALL_TRAINS(dst) { |
12302
fc8e41f34b8c
(svn r16719) -Codechange: make IsArticulatedPart(), IsTrainEngine(), IsTrainWagon(), IsMultiheaded(), EngineHasArticPart() and IsRearDualheaded() members of Train
smatz <smatz@openttd.org>
parents:
12301
diff
changeset
|
781 if (dst->IsFreeWagon() && dst->tile == tile && !(dst->vehstatus & VS_CRASHED)) { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
782 /* check so all vehicles in the line have the same engine. */ |
12034
aa140a9c419c
(svn r16441) -Codechange: new class SpecializedVehicle used as superclass for all vehicle types
smatz <smatz@openttd.org>
parents:
12032
diff
changeset
|
783 Train *t = dst; |
aa140a9c419c
(svn r16441) -Codechange: new class SpecializedVehicle used as superclass for all vehicle types
smatz <smatz@openttd.org>
parents:
12032
diff
changeset
|
784 while (t->engine_type == eng) { |
aa140a9c419c
(svn r16441) -Codechange: new class SpecializedVehicle used as superclass for all vehicle types
smatz <smatz@openttd.org>
parents:
12032
diff
changeset
|
785 t = t->Next(); |
aa140a9c419c
(svn r16441) -Codechange: new class SpecializedVehicle used as superclass for all vehicle types
smatz <smatz@openttd.org>
parents:
12032
diff
changeset
|
786 if (t == NULL) return dst; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
787 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
788 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
789 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
790 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
791 return NULL; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
792 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
793 |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
794 /** Helper type for lists/vectors of trains */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
795 typedef SmallVector<Train *, 16> TrainList; |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
796 |
13924
9a4225ccc64b
(svn r18456) -Codechange: make the length checking functionality of CmdMoveRailVehicle a separate function and simplify the logic
rubidium <rubidium@openttd.org>
parents:
13890
diff
changeset
|
797 /** |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
798 * Make a backup of a train into a train list. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
799 * @param list to make the backup in |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
800 * @param t the train to make the backup of |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
801 */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
802 static void MakeTrainBackup(TrainList &list, Train *t) |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
803 { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
804 for (; t != NULL; t = t->Next()) *list.Append() = t; |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
805 } |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
806 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
807 /** |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
808 * Restore the train from the backup list. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
809 * @param list the train to restore. |
13924
9a4225ccc64b
(svn r18456) -Codechange: make the length checking functionality of CmdMoveRailVehicle a separate function and simplify the logic
rubidium <rubidium@openttd.org>
parents:
13890
diff
changeset
|
810 */ |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
811 static void RestoreTrainBackup(TrainList &list) |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
812 { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
813 /* No train, nothing to do. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
814 if (list.Length() == 0) return; |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
815 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
816 Train *prev = NULL; |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
817 /* Iterate over the list and rebuild it. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
818 for (Train **iter = list.Begin(); iter != list.End(); iter++) { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
819 Train *t = *iter; |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
820 if (prev != NULL) { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
821 prev->SetNext(t); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
822 } else if (t->Previous() != NULL) { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
823 /* Make sure the head of the train is always the first in the chain. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
824 t->Previous()->SetNext(NULL); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
825 } |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
826 prev = t; |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
827 } |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
828 } |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
829 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
830 /** |
15002
baf0e12ad2b4
(svn r19614) -Codechange: "it's" => "its" where appropriate
smatz <smatz@openttd.org>
parents:
14898
diff
changeset
|
831 * Remove the given wagon from its consist. |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
832 * @param part the part of the train to remove. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
833 * @param chain whether to remove the whole chain. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
834 */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
835 static void RemoveFromConsist(Train *part, bool chain = false) |
13924
9a4225ccc64b
(svn r18456) -Codechange: make the length checking functionality of CmdMoveRailVehicle a separate function and simplify the logic
rubidium <rubidium@openttd.org>
parents:
13890
diff
changeset
|
836 { |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
837 Train *tail = chain ? part->Last() : part->GetLastEnginePart(); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
838 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
839 /* Unlink at the front, but make it point to the next |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
840 * vehicle after the to be remove part. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
841 if (part->Previous() != NULL) part->Previous()->SetNext(tail->Next()); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
842 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
843 /* Unlink at the back */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
844 tail->SetNext(NULL); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
845 } |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
846 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
847 /** |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
848 * Inserts a chain into the train at dst. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
849 * @param dst the place where to append after. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
850 * @param chain the chain to actually add. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
851 */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
852 static void InsertInConsist(Train *dst, Train *chain) |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
853 { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
854 /* We do not want to add something in the middle of an articulated part. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
855 assert(dst->Next() == NULL || !dst->Next()->IsArticulatedPart()); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
856 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
857 chain->Last()->SetNext(dst->Next()); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
858 dst->SetNext(chain); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
859 } |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
860 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
861 /** |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
862 * Normalise the dual heads in the train, i.e. if one is |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
863 * missing move that one to this train. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
864 * @param t the train to normalise. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
865 */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
866 static void NormaliseDualHeads(Train *t) |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
867 { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
868 for (; t != NULL; t = t->GetNextVehicle()) { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
869 if (!t->IsMultiheaded() || !t->IsEngine()) continue; |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
870 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
871 /* Make sure that there are no free cars before next engine */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
872 Train *u; |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
873 for (u = t; u->Next() != NULL && !u->Next()->IsEngine(); u = u->Next()) {} |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
874 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
875 if (u == t->other_multiheaded_part) continue; |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
876 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
877 /* Remove the part from the 'wrong' train */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
878 RemoveFromConsist(t->other_multiheaded_part); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
879 /* And add it to the 'right' train */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
880 InsertInConsist(u, t->other_multiheaded_part); |
13924
9a4225ccc64b
(svn r18456) -Codechange: make the length checking functionality of CmdMoveRailVehicle a separate function and simplify the logic
rubidium <rubidium@openttd.org>
parents:
13890
diff
changeset
|
881 } |
9a4225ccc64b
(svn r18456) -Codechange: make the length checking functionality of CmdMoveRailVehicle a separate function and simplify the logic
rubidium <rubidium@openttd.org>
parents:
13890
diff
changeset
|
882 } |
9a4225ccc64b
(svn r18456) -Codechange: make the length checking functionality of CmdMoveRailVehicle a separate function and simplify the logic
rubidium <rubidium@openttd.org>
parents:
13890
diff
changeset
|
883 |
13926
693d82515df6
(svn r18458) -Codechange: make the 'check train length' code of CmdMoveRailVehicle a separate function
rubidium <rubidium@openttd.org>
parents:
13924
diff
changeset
|
884 /** |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
885 * Normalise the sub types of the parts in this chain. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
886 * @param chain the chain to normalise. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
887 */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
888 static void NormaliseSubtypes(Train *chain) |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
889 { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
890 /* Nothing to do */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
891 if (chain == NULL) return; |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
892 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
893 /* We must be the first in the chain. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
894 assert(chain->Previous() == NULL); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
895 |
15820
59fd8293b2ee
(svn r20499) -Doc: Spelling fixes, and one doxygen comment addition.
alberth <alberth@openttd.org>
parents:
15763
diff
changeset
|
896 /* Set the appropriate bits for the first in the chain. */ |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
897 if (chain->IsWagon()) { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
898 chain->SetFreeWagon(); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
899 } else { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
900 assert(chain->IsEngine()); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
901 chain->SetFrontEngine(); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
902 } |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
903 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
904 /* Now clear the bits for the rest of the chain */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
905 for (Train *t = chain->Next(); t != NULL; t = t->Next()) { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
906 t->ClearFreeWagon(); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
907 t->ClearFrontEngine(); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
908 } |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
909 } |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
910 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
911 /** |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
912 * Check/validate whether we may actually build a new train. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
913 * @note All vehicles are/were 'heads' of their chains. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
914 * @param original_dst The original destination chain. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
915 * @param dst The destination chain after constructing the train. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
916 * @param original_dst The original source chain. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
917 * @param dst The source chain after constructing the train. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
918 * @return possible error of this command. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
919 */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
920 static CommandCost CheckNewTrain(Train *original_dst, Train *dst, Train *original_src, Train *src) |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
921 { |
15820
59fd8293b2ee
(svn r20499) -Doc: Spelling fixes, and one doxygen comment addition.
alberth <alberth@openttd.org>
parents:
15763
diff
changeset
|
922 /* Just add 'new' engines and subtract the original ones. |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
923 * If that's less than or equal to 0 we can be sure we did |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
924 * not add any engines (read: trains) along the way. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
925 if ((src != NULL && src->IsEngine() ? 1 : 0) + |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
926 (dst != NULL && dst->IsEngine() ? 1 : 0) - |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
927 (original_src != NULL && original_src->IsEngine() ? 1 : 0) - |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
928 (original_dst != NULL && original_dst->IsEngine() ? 1 : 0) <= 0) { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
929 return CommandCost(); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
930 } |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
931 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
932 /* Get a free unit number and check whether it's within the bounds. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
933 * There will always be a maximum of one new train. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
934 if (GetFreeUnitNumber(VEH_TRAIN) <= _settings_game.vehicle.max_trains) return CommandCost(); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
935 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
936 return_cmd_error(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
937 } |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
938 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
939 /** |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
940 * Check whether the train parts can be attached. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
941 * @param t the train to check |
13926
693d82515df6
(svn r18458) -Codechange: make the 'check train length' code of CmdMoveRailVehicle a separate function
rubidium <rubidium@openttd.org>
parents:
13924
diff
changeset
|
942 * @return possible error of this command. |
693d82515df6
(svn r18458) -Codechange: make the 'check train length' code of CmdMoveRailVehicle a separate function
rubidium <rubidium@openttd.org>
parents:
13924
diff
changeset
|
943 */ |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
944 static CommandCost CheckTrainAttachment(Train *t) |
13926
693d82515df6
(svn r18458) -Codechange: make the 'check train length' code of CmdMoveRailVehicle a separate function
rubidium <rubidium@openttd.org>
parents:
13924
diff
changeset
|
945 { |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
946 /* No multi-part train, no need to check. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
947 if (t == NULL || t->Next() == NULL || !t->IsEngine()) return CommandCost(); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
948 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
949 /* The maximum length for a train. For each part we decrease this by one |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
950 * and if the result is negative the train is simply too long. */ |
17221
edf36d7f3f86
(svn r21960) -Change: show the length of vehicles in tiles, instead of half tiles in the depot
rubidium <rubidium@openttd.org>
parents:
17194
diff
changeset
|
951 int allowed_len = _settings_game.vehicle.max_train_length * TILE_SIZE - t->gcache.cached_veh_length; |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
952 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
953 Train *head = t; |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
954 Train *prev = t; |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
955 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
956 /* Break the prev -> t link so it always holds within the loop. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
957 t = t->Next(); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
958 prev->SetNext(NULL); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
959 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
960 /* Make sure the cache is cleared. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
961 head->InvalidateNewGRFCache(); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
962 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
963 while (t != NULL) { |
17221
edf36d7f3f86
(svn r21960) -Change: show the length of vehicles in tiles, instead of half tiles in the depot
rubidium <rubidium@openttd.org>
parents:
17194
diff
changeset
|
964 allowed_len -= t->gcache.cached_veh_length; |
edf36d7f3f86
(svn r21960) -Change: show the length of vehicles in tiles, instead of half tiles in the depot
rubidium <rubidium@openttd.org>
parents:
17194
diff
changeset
|
965 |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
966 Train *next = t->Next(); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
967 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
968 /* Unlink the to-be-added piece; it is already unlinked from the previous |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
969 * part due to the fact that the prev -> t link is broken. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
970 t->SetNext(NULL); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
971 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
972 /* Don't check callback for articulated or rear dual headed parts */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
973 if (!t->IsArticulatedPart() && !t->IsRearDualheaded()) { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
974 /* Back up and clear the first_engine data to avoid using wagon override group */ |
16788
efb0333e5aad
(svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
975 EngineID first_engine = t->gcache.first_engine; |
efb0333e5aad
(svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
976 t->gcache.first_engine = INVALID_ENGINE; |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
977 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
978 /* We don't want the cache to interfere. head's cache is cleared before |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
979 * the loop and after each callback does not need to be cleared here. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
980 t->InvalidateNewGRFCache(); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
981 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
982 uint16 callback = GetVehicleCallbackParent(CBID_TRAIN_ALLOW_WAGON_ATTACH, 0, 0, head->engine_type, t, head); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
983 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
984 /* Restore original first_engine data */ |
16788
efb0333e5aad
(svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
985 t->gcache.first_engine = first_engine; |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
986 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
987 /* We do not want to remember any cached variables from the test run */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
988 t->InvalidateNewGRFCache(); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
989 head->InvalidateNewGRFCache(); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
990 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
991 if (callback != CALLBACK_FAILED) { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
992 /* A failing callback means everything is okay */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
993 StringID error = STR_NULL; |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
994 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
995 if (callback == 0xFD) error = STR_ERROR_INCOMPATIBLE_RAIL_TYPES; |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
996 if (callback < 0xFD) error = GetGRFStringID(GetEngineGRFID(head->engine_type), 0xD000 + callback); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
997 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
998 if (error != STR_NULL) return_cmd_error(error); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
999 } |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1000 } |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1001 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1002 /* And link it to the new part. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1003 prev->SetNext(t); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1004 prev = t; |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1005 t = next; |
13926
693d82515df6
(svn r18458) -Codechange: make the 'check train length' code of CmdMoveRailVehicle a separate function
rubidium <rubidium@openttd.org>
parents:
13924
diff
changeset
|
1006 } |
693d82515df6
(svn r18458) -Codechange: make the 'check train length' code of CmdMoveRailVehicle a separate function
rubidium <rubidium@openttd.org>
parents:
13924
diff
changeset
|
1007 |
17221
edf36d7f3f86
(svn r21960) -Change: show the length of vehicles in tiles, instead of half tiles in the depot
rubidium <rubidium@openttd.org>
parents:
17194
diff
changeset
|
1008 if (allowed_len < 0) return_cmd_error(STR_ERROR_TRAIN_TOO_LONG); |
13926
693d82515df6
(svn r18458) -Codechange: make the 'check train length' code of CmdMoveRailVehicle a separate function
rubidium <rubidium@openttd.org>
parents:
13924
diff
changeset
|
1009 return CommandCost(); |
693d82515df6
(svn r18458) -Codechange: make the 'check train length' code of CmdMoveRailVehicle a separate function
rubidium <rubidium@openttd.org>
parents:
13924
diff
changeset
|
1010 } |
693d82515df6
(svn r18458) -Codechange: make the 'check train length' code of CmdMoveRailVehicle a separate function
rubidium <rubidium@openttd.org>
parents:
13924
diff
changeset
|
1011 |
13927
77e7637c04c8
(svn r18459) -Codechange: move the new train validity checking (attach callbacks) to a separate function
rubidium <rubidium@openttd.org>
parents:
13926
diff
changeset
|
1012 /** |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1013 * Validate whether we are going to create valid trains. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1014 * @note All vehicles are/were 'heads' of their chains. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1015 * @param original_dst The original destination chain. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1016 * @param dst The destination chain after constructing the train. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1017 * @param original_dst The original source chain. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1018 * @param dst The source chain after constructing the train. |
15899
097904c36bde
(svn r20582) -Fix [FS#4044]: Autoreplace can trigger an assertion when at the vehicle limit
rubidium <rubidium@openttd.org>
parents:
15891
diff
changeset
|
1019 * @param check_limit Whether to check the vehicle limit. |
13927
77e7637c04c8
(svn r18459) -Codechange: move the new train validity checking (attach callbacks) to a separate function
rubidium <rubidium@openttd.org>
parents:
13926
diff
changeset
|
1020 * @return possible error of this command. |
77e7637c04c8
(svn r18459) -Codechange: move the new train validity checking (attach callbacks) to a separate function
rubidium <rubidium@openttd.org>
parents:
13926
diff
changeset
|
1021 */ |
15899
097904c36bde
(svn r20582) -Fix [FS#4044]: Autoreplace can trigger an assertion when at the vehicle limit
rubidium <rubidium@openttd.org>
parents:
15891
diff
changeset
|
1022 static CommandCost ValidateTrains(Train *original_dst, Train *dst, Train *original_src, Train *src, bool check_limit) |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1023 { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1024 /* Check whether we may actually construct the trains. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1025 CommandCost ret = CheckTrainAttachment(src); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1026 if (ret.Failed()) return ret; |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1027 ret = CheckTrainAttachment(dst); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1028 if (ret.Failed()) return ret; |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1029 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1030 /* Check whether we need to build a new train. */ |
15899
097904c36bde
(svn r20582) -Fix [FS#4044]: Autoreplace can trigger an assertion when at the vehicle limit
rubidium <rubidium@openttd.org>
parents:
15891
diff
changeset
|
1031 return check_limit ? CheckNewTrain(original_dst, dst, original_src, src) : CommandCost(); |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1032 } |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1033 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1034 /** |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1035 * Arrange the trains in the wanted way. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1036 * @param dst_head The destination chain of the to be moved vehicle. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1037 * @param dst The destination for the to be moved vehicle. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1038 * @param src_head The source chain of the to be moved vehicle. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1039 * @param src The to be moved vehicle. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1040 * @param move_chain Whether to move all vehicles after src or not. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1041 */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1042 static void ArrangeTrains(Train **dst_head, Train *dst, Train **src_head, Train *src, bool move_chain) |
13927
77e7637c04c8
(svn r18459) -Codechange: move the new train validity checking (attach callbacks) to a separate function
rubidium <rubidium@openttd.org>
parents:
13926
diff
changeset
|
1043 { |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1044 /* First determine the front of the two resulting trains */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1045 if (*src_head == *dst_head) { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1046 /* If we aren't moving part(s) to a new train, we are just moving the |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1047 * front back and there is not destination head. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1048 *dst_head = NULL; |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1049 } else if (*dst_head == NULL) { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1050 /* If we are moving to a new train the head of the move train would become |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1051 * the head of the new vehicle. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1052 *dst_head = src; |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1053 } |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1054 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1055 if (src == *src_head) { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1056 /* If we are moving the front of a train then we are, in effect, creating |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1057 * a new head for the train. Point to that. Unless we are moving the whole |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1058 * train in which case there is not 'source' train anymore. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1059 * In case we are a multiheaded part we want the complete thing to come |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1060 * with us, so src->GetNextUnit(), however... when we are e.g. a wagon |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1061 * that is followed by a rear multihead we do not want to include that. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1062 *src_head = move_chain ? NULL : |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1063 (src->IsMultiheaded() ? src->GetNextUnit() : src->GetNextVehicle()); |
13927
77e7637c04c8
(svn r18459) -Codechange: move the new train validity checking (attach callbacks) to a separate function
rubidium <rubidium@openttd.org>
parents:
13926
diff
changeset
|
1064 } |
77e7637c04c8
(svn r18459) -Codechange: move the new train validity checking (attach callbacks) to a separate function
rubidium <rubidium@openttd.org>
parents:
13926
diff
changeset
|
1065 |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1066 /* Now it's just simply removing the part that we are going to move from the |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1067 * source train and *if* the destination is a not a new train add the chain |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1068 * at the destination location. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1069 RemoveFromConsist(src, move_chain); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1070 if (*dst_head != src) InsertInConsist(dst, src); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1071 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1072 /* Now normalise the dual heads, that is move the dual heads around in such |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1073 * a way that the head and rear of a dual head are in the same train */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1074 NormaliseDualHeads(*src_head); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1075 NormaliseDualHeads(*dst_head); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1076 } |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1077 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1078 /** |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1079 * Normalise the head of the train again, i.e. that is tell the world that |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1080 * we have changed and update all kinds of variables. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1081 * @param head the train to update. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1082 */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1083 static void NormaliseTrainHead(Train *head) |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1084 { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1085 /* Not much to do! */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1086 if (head == NULL) return; |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1087 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1088 /* Tell the 'world' the train changed. */ |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
1089 head->ConsistChanged(false); |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1090 UpdateTrainGroupID(head); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1091 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1092 /* Not a front engine, i.e. a free wagon chain. No need to do more. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1093 if (!head->IsFrontEngine()) return; |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1094 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1095 /* Update the refit button and window */ |
17489
7e48879a9608
(svn r22244) -Codechange: Make vehicle windows handle command-/GUI-scope invalidations themself (from autoreplace and refitting).
frosch <frosch@openttd.org>
parents:
17452
diff
changeset
|
1096 InvalidateWindowData(WC_VEHICLE_REFIT, head->index); |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1097 SetWindowWidgetDirty(WC_VEHICLE_VIEW, head->index, VVW_WIDGET_REFIT_VEH); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1098 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1099 /* If we don't have a unit number yet, set one. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1100 if (head->unitnumber != 0) return; |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1101 head->unitnumber = GetFreeUnitNumber(VEH_TRAIN); |
13927
77e7637c04c8
(svn r18459) -Codechange: move the new train validity checking (attach callbacks) to a separate function
rubidium <rubidium@openttd.org>
parents:
13926
diff
changeset
|
1102 } |
77e7637c04c8
(svn r18459) -Codechange: move the new train validity checking (attach callbacks) to a separate function
rubidium <rubidium@openttd.org>
parents:
13926
diff
changeset
|
1103 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
1104 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
1105 * Move a rail vehicle around inside the depot. |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1106 * @param tile unused |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1107 * @param flags type of operation |
9928
0cc9c6c36c43
(svn r14083) -Fix [FS#1264, FS#2037, FS#2038, FS#2110]: Rewrite the autoreplace kernel.
frosch <frosch@openttd.org>
parents:
9923
diff
changeset
|
1108 * Note: DC_AUTOREPLACE is set when autoreplace tries to undo its modifications or moves vehicles to temporary locations inside the depot. |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1109 * @param p1 various bitstuffed elements |
15890
52d3e250c976
(svn r20572) -Codechange: free/reserve some bits in the wagon move command to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents:
15865
diff
changeset
|
1110 * - p1 (bit 0 - 19) source vehicle index |
52d3e250c976
(svn r20572) -Codechange: free/reserve some bits in the wagon move command to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents:
15865
diff
changeset
|
1111 * - p1 (bit 20) move all vehicles following the source vehicle |
52d3e250c976
(svn r20572) -Codechange: free/reserve some bits in the wagon move command to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents:
15865
diff
changeset
|
1112 * @param p2 what wagon to put the source wagon AFTER, XXX - INVALID_VEHICLE to make a new line |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13054
diff
changeset
|
1113 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13054
diff
changeset
|
1114 * @return the cost of this operation or an error |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1115 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11085
diff
changeset
|
1116 CommandCost CmdMoveRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1117 { |
15890
52d3e250c976
(svn r20572) -Codechange: free/reserve some bits in the wagon move command to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents:
15865
diff
changeset
|
1118 VehicleID s = GB(p1, 0, 20); |
52d3e250c976
(svn r20572) -Codechange: free/reserve some bits in the wagon move command to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents:
15865
diff
changeset
|
1119 VehicleID d = GB(p2, 0, 20); |
52d3e250c976
(svn r20572) -Codechange: free/reserve some bits in the wagon move command to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents:
15865
diff
changeset
|
1120 bool move_chain = HasBit(p1, 20); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1121 |
12034
aa140a9c419c
(svn r16441) -Codechange: new class SpecializedVehicle used as superclass for all vehicle types
smatz <smatz@openttd.org>
parents:
12032
diff
changeset
|
1122 Train *src = Train::GetIfValid(s); |
14815
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1123 if (src == NULL) return CMD_ERROR; |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1124 |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1125 CommandCost ret = CheckOwnership(src->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1126 if (ret.Failed()) return ret; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1127 |
7696
7ae4d4720c11
(svn r11230) -Fix [FS#1228]: one could construct trains out of crashed wagons and engines. Based on a patch by SmatZ.
rubidium <rubidium@openttd.org>
parents:
7695
diff
changeset
|
1128 /* Do not allow moving crashed vehicles inside the depot, it is likely to cause asserts later */ |
12089
482bdd64bbe8
(svn r16498) -Codechange: Remove hardly used HASBITS.
frosch <frosch@openttd.org>
parents:
12085
diff
changeset
|
1129 if (src->vehstatus & VS_CRASHED) return CMD_ERROR; |
7696
7ae4d4720c11
(svn r11230) -Fix [FS#1228]: one could construct trains out of crashed wagons and engines. Based on a patch by SmatZ.
rubidium <rubidium@openttd.org>
parents:
7695
diff
changeset
|
1130 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1131 /* if nothing is selected as destination, try and find a matching vehicle to drag to. */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1132 Train *dst; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1133 if (d == INVALID_VEHICLE) { |
12302
fc8e41f34b8c
(svn r16719) -Codechange: make IsArticulatedPart(), IsTrainEngine(), IsTrainWagon(), IsMultiheaded(), EngineHasArticPart() and IsRearDualheaded() members of Train
smatz <smatz@openttd.org>
parents:
12301
diff
changeset
|
1134 dst = src->IsEngine() ? NULL : FindGoodVehiclePos(src); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1135 } else { |
12034
aa140a9c419c
(svn r16441) -Codechange: new class SpecializedVehicle used as superclass for all vehicle types
smatz <smatz@openttd.org>
parents:
12032
diff
changeset
|
1136 dst = Train::GetIfValid(d); |
14815
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1137 if (dst == NULL) return CMD_ERROR; |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1138 |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1139 CommandCost ret = CheckOwnership(dst->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1140 if (ret.Failed()) return ret; |
7696
7ae4d4720c11
(svn r11230) -Fix [FS#1228]: one could construct trains out of crashed wagons and engines. Based on a patch by SmatZ.
rubidium <rubidium@openttd.org>
parents:
7695
diff
changeset
|
1141 |
7ae4d4720c11
(svn r11230) -Fix [FS#1228]: one could construct trains out of crashed wagons and engines. Based on a patch by SmatZ.
rubidium <rubidium@openttd.org>
parents:
7695
diff
changeset
|
1142 /* Do not allow appending to crashed vehicles, too */ |
12089
482bdd64bbe8
(svn r16498) -Codechange: Remove hardly used HASBITS.
frosch <frosch@openttd.org>
parents:
12085
diff
changeset
|
1143 if (dst->vehstatus & VS_CRASHED) return CMD_ERROR; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1144 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1145 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1146 /* if an articulated part is being handled, deal with its parent vehicle */ |
12450
af266072d46c
(svn r16884) -Codechange: Add Train::GetFirstEnginePart() and use it.
frosch <frosch@openttd.org>
parents:
12433
diff
changeset
|
1147 src = src->GetFirstEnginePart(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1148 if (dst != NULL) { |
12450
af266072d46c
(svn r16884) -Codechange: Add Train::GetFirstEnginePart() and use it.
frosch <frosch@openttd.org>
parents:
12433
diff
changeset
|
1149 dst = dst->GetFirstEnginePart(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1150 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1151 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1152 /* don't move the same vehicle.. */ |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
1153 if (src == dst) return CommandCost(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1154 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1155 /* locate the head of the two chains */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1156 Train *src_head = src->First(); |
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1157 Train *dst_head; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1158 if (dst != NULL) { |
7497
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
1159 dst_head = dst->First(); |
6136 | 1160 if (dst_head->tile != src_head->tile) return CMD_ERROR; |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1161 /* Now deal with articulated part of destination wagon */ |
12306
d0ff55a976ad
(svn r16723) -Codechange: make GetNextArticPart(), GetLastEnginePart(), GetNextVehicle(), GetPrevVehicle(), GetNextUnit(), GetPrevUnit() members of Train
smatz <smatz@openttd.org>
parents:
12303
diff
changeset
|
1162 dst = dst->GetLastEnginePart(); |
6136 | 1163 } else { |
1164 dst_head = NULL; | |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1165 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1166 |
12302
fc8e41f34b8c
(svn r16719) -Codechange: make IsArticulatedPart(), IsTrainEngine(), IsTrainWagon(), IsMultiheaded(), EngineHasArticPart() and IsRearDualheaded() members of Train
smatz <smatz@openttd.org>
parents:
12301
diff
changeset
|
1167 if (src->IsRearDualheaded()) return_cmd_error(STR_ERROR_REAR_ENGINE_FOLLOW_FRONT); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1168 |
13941
5a2efeabdd21
(svn r18473) -Fix (r18470): crash when moving a multiheaded part to be just after itself
rubidium <rubidium@openttd.org>
parents:
13940
diff
changeset
|
1169 /* When moving all wagons, we can't have the same src_head and dst_head */ |
13926
693d82515df6
(svn r18458) -Codechange: make the 'check train length' code of CmdMoveRailVehicle a separate function
rubidium <rubidium@openttd.org>
parents:
13924
diff
changeset
|
1170 if (move_chain && src_head == dst_head) return CommandCost(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1171 |
13941
5a2efeabdd21
(svn r18473) -Fix (r18470): crash when moving a multiheaded part to be just after itself
rubidium <rubidium@openttd.org>
parents:
13940
diff
changeset
|
1172 /* When moving a multiheaded part to be place after itself, bail out. */ |
13942
06db5e527f36
(svn r18474) -Fix (r18470): in some odd corner cases the group (vehicle) counts could be off
rubidium <rubidium@openttd.org>
parents:
13941
diff
changeset
|
1173 if (!move_chain && dst != NULL && dst->IsRearDualheaded() && src == dst->other_multiheaded_part) return CommandCost(); |
13941
5a2efeabdd21
(svn r18473) -Fix (r18470): crash when moving a multiheaded part to be just after itself
rubidium <rubidium@openttd.org>
parents:
13940
diff
changeset
|
1174 |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1175 /* Check if all vehicles in the source train are stopped inside a depot. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1176 if (!src_head->IsStoppedInDepot()) return_cmd_error(STR_ERROR_TRAINS_CAN_ONLY_BE_ALTERED_INSIDE_A_DEPOT); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1177 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1178 /* Check if all vehicles in the destination train are stopped inside a depot. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1179 if (dst_head != NULL && !dst_head->IsStoppedInDepot()) return_cmd_error(STR_ERROR_TRAINS_CAN_ONLY_BE_ALTERED_INSIDE_A_DEPOT); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1180 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1181 /* First make a backup of the order of the trains. That way we can do |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1182 * whatever we want with the order and later on easily revert. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1183 TrainList original_src; |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1184 TrainList original_dst; |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1185 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1186 MakeTrainBackup(original_src, src_head); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1187 MakeTrainBackup(original_dst, dst_head); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1188 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1189 /* Also make backup of the original heads as ArrangeTrains can change them. |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1190 * For the destination head we do not care if it is the same as the source |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1191 * head because in that case it's just a copy. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1192 Train *original_src_head = src_head; |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1193 Train *original_dst_head = (dst_head == src_head ? NULL : dst_head); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1194 |
18159
de0749262352
(svn r22984) -Feature: Display profit icons for groups in the group GUI.
frosch <frosch@openttd.org>
parents:
18153
diff
changeset
|
1195 if (flags & DC_EXEC) { |
de0749262352
(svn r22984) -Feature: Display profit icons for groups in the group GUI.
frosch <frosch@openttd.org>
parents:
18153
diff
changeset
|
1196 /* Remove old heads from the statistics */ |
de0749262352
(svn r22984) -Feature: Display profit icons for groups in the group GUI.
frosch <frosch@openttd.org>
parents:
18153
diff
changeset
|
1197 if (original_src_head != NULL && original_src_head->IsFrontEngine()) GroupStatistics::CountVehicle(original_src_head, -1); |
de0749262352
(svn r22984) -Feature: Display profit icons for groups in the group GUI.
frosch <frosch@openttd.org>
parents:
18153
diff
changeset
|
1198 if (original_dst_head != NULL && original_dst_head->IsFrontEngine()) GroupStatistics::CountVehicle(original_dst_head, -1); |
de0749262352
(svn r22984) -Feature: Display profit icons for groups in the group GUI.
frosch <frosch@openttd.org>
parents:
18153
diff
changeset
|
1199 } |
de0749262352
(svn r22984) -Feature: Display profit icons for groups in the group GUI.
frosch <frosch@openttd.org>
parents:
18153
diff
changeset
|
1200 |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1201 /* (Re)arrange the trains in the wanted arrangement. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1202 ArrangeTrains(&dst_head, dst, &src_head, src, move_chain); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1203 |
9928
0cc9c6c36c43
(svn r14083) -Fix [FS#1264, FS#2037, FS#2038, FS#2110]: Rewrite the autoreplace kernel.
frosch <frosch@openttd.org>
parents:
9923
diff
changeset
|
1204 if ((flags & DC_AUTOREPLACE) == 0) { |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1205 /* If the autoreplace flag is set we do not need to test for the validity |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1206 * because we are going to revert the train to its original state. As we |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1207 * assume the original state was correct autoreplace can skip this. */ |
15899
097904c36bde
(svn r20582) -Fix [FS#4044]: Autoreplace can trigger an assertion when at the vehicle limit
rubidium <rubidium@openttd.org>
parents:
15891
diff
changeset
|
1208 CommandCost ret = ValidateTrains(original_dst_head, dst_head, original_src_head, src_head, true); |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1209 if (ret.Failed()) { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1210 /* Restore the train we had. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1211 RestoreTrainBackup(original_src); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1212 RestoreTrainBackup(original_dst); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1213 return ret; |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1214 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1215 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1216 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1217 /* do it? */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1218 if (flags & DC_EXEC) { |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1219 /* First normalise the sub types of the chains. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1220 NormaliseSubtypes(src_head); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1221 NormaliseSubtypes(dst_head); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1222 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1223 /* There are 14 different cases: |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1224 * 1) front engine gets moved to a new train, it stays a front engine. |
16349
b1fc0cfd2943
(svn r21060) -Doc: Improved wording of comments (mostly by __ln__)
alberth <alberth@openttd.org>
parents:
16306
diff
changeset
|
1225 * a) the 'next' part is a wagon that becomes a free wagon chain. |
b1fc0cfd2943
(svn r21060) -Doc: Improved wording of comments (mostly by __ln__)
alberth <alberth@openttd.org>
parents:
16306
diff
changeset
|
1226 * b) the 'next' part is an engine that becomes a front engine. |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1227 * c) there is no 'next' part, nothing else happens |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1228 * 2) front engine gets moved to another train, it is not a front engine anymore |
16349
b1fc0cfd2943
(svn r21060) -Doc: Improved wording of comments (mostly by __ln__)
alberth <alberth@openttd.org>
parents:
16306
diff
changeset
|
1229 * a) the 'next' part is a wagon that becomes a free wagon chain. |
b1fc0cfd2943
(svn r21060) -Doc: Improved wording of comments (mostly by __ln__)
alberth <alberth@openttd.org>
parents:
16306
diff
changeset
|
1230 * b) the 'next' part is an engine that becomes a front engine. |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1231 * c) there is no 'next' part, nothing else happens |
16481
89cd59264ee1
(svn r21205) -Fix [FS#4207]: Under some conditions, group count would be wrong after moving train engines in the depot window.
terkhen <terkhen@openttd.org>
parents:
16466
diff
changeset
|
1232 * 3) front engine gets moved to later in the current train, it is not a front engine anymore. |
16349
b1fc0cfd2943
(svn r21060) -Doc: Improved wording of comments (mostly by __ln__)
alberth <alberth@openttd.org>
parents:
16306
diff
changeset
|
1233 * a) the 'next' part is a wagon that becomes a free wagon chain. |
b1fc0cfd2943
(svn r21060) -Doc: Improved wording of comments (mostly by __ln__)
alberth <alberth@openttd.org>
parents:
16306
diff
changeset
|
1234 * b) the 'next' part is an engine that becomes a front engine. |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1235 * 4) free wagon gets moved |
16349
b1fc0cfd2943
(svn r21060) -Doc: Improved wording of comments (mostly by __ln__)
alberth <alberth@openttd.org>
parents:
16306
diff
changeset
|
1236 * a) the 'next' part is a wagon that becomes a free wagon chain. |
b1fc0cfd2943
(svn r21060) -Doc: Improved wording of comments (mostly by __ln__)
alberth <alberth@openttd.org>
parents:
16306
diff
changeset
|
1237 * b) the 'next' part is an engine that becomes a front engine. |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1238 * c) there is no 'next' part, nothing else happens |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1239 * 5) non front engine gets moved and becomes a new train, nothing else happens |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1240 * 6) non front engine gets moved within a train / to another train, nothing hapens |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1241 * 7) wagon gets moved, nothing happens |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1242 */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1243 if (src == original_src_head && src->IsEngine() && !src->IsFrontEngine()) { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1244 /* Cases #2 and #3: the front engine gets trashed. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1245 DeleteWindowById(WC_VEHICLE_VIEW, src->index); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1246 DeleteWindowById(WC_VEHICLE_ORDERS, src->index); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1247 DeleteWindowById(WC_VEHICLE_REFIT, src->index); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1248 DeleteWindowById(WC_VEHICLE_DETAILS, src->index); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1249 DeleteWindowById(WC_VEHICLE_TIMETABLE, src->index); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1250 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1251 /* Delete orders, group stuff and the unit number as we're not the |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1252 * front of any vehicle anymore. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1253 DeleteVehicleOrders(src); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1254 RemoveVehicleFromGroup(src); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1255 src->unitnumber = 0; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1256 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1257 |
13942
06db5e527f36
(svn r18474) -Fix (r18470): in some odd corner cases the group (vehicle) counts could be off
rubidium <rubidium@openttd.org>
parents:
13941
diff
changeset
|
1258 /* We weren't a front engine but are becoming one. So |
06db5e527f36
(svn r18474) -Fix (r18470): in some odd corner cases the group (vehicle) counts could be off
rubidium <rubidium@openttd.org>
parents:
13941
diff
changeset
|
1259 * we should be put in the default group. */ |
06db5e527f36
(svn r18474) -Fix (r18470): in some odd corner cases the group (vehicle) counts could be off
rubidium <rubidium@openttd.org>
parents:
13941
diff
changeset
|
1260 if (original_src_head != src && dst_head == src) { |
06db5e527f36
(svn r18474) -Fix (r18470): in some odd corner cases the group (vehicle) counts could be off
rubidium <rubidium@openttd.org>
parents:
13941
diff
changeset
|
1261 SetTrainGroupID(src, DEFAULT_GROUP); |
06db5e527f36
(svn r18474) -Fix (r18470): in some odd corner cases the group (vehicle) counts could be off
rubidium <rubidium@openttd.org>
parents:
13941
diff
changeset
|
1262 } |
06db5e527f36
(svn r18474) -Fix (r18470): in some odd corner cases the group (vehicle) counts could be off
rubidium <rubidium@openttd.org>
parents:
13941
diff
changeset
|
1263 |
18159
de0749262352
(svn r22984) -Feature: Display profit icons for groups in the group GUI.
frosch <frosch@openttd.org>
parents:
18153
diff
changeset
|
1264 /* Add new heads to statistics */ |
de0749262352
(svn r22984) -Feature: Display profit icons for groups in the group GUI.
frosch <frosch@openttd.org>
parents:
18153
diff
changeset
|
1265 if (src_head != NULL && src_head->IsFrontEngine()) GroupStatistics::CountVehicle(src_head, 1); |
de0749262352
(svn r22984) -Feature: Display profit icons for groups in the group GUI.
frosch <frosch@openttd.org>
parents:
18153
diff
changeset
|
1266 if (dst_head != NULL && dst_head->IsFrontEngine()) GroupStatistics::CountVehicle(dst_head, 1); |
de0749262352
(svn r22984) -Feature: Display profit icons for groups in the group GUI.
frosch <frosch@openttd.org>
parents:
18153
diff
changeset
|
1267 |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1268 /* Handle 'new engine' part of cases #1b, #2b, #3b, #4b and #5 in NormaliseTrainHead. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1269 NormaliseTrainHead(src_head); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1270 NormaliseTrainHead(dst_head); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1271 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1272 /* We are undoubtedly changing something in the depot and train list. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1273 InvalidateWindowData(WC_VEHICLE_DEPOT, src->tile); |
9297
add307f2e6ea
(svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium <rubidium@openttd.org>
parents:
9274
diff
changeset
|
1274 InvalidateWindowClassesData(WC_TRAINS_LIST, 0); |
13938
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1275 } else { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1276 /* We don't want to execute what we're just tried. */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1277 RestoreTrainBackup(original_src); |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1278 RestoreTrainBackup(original_dst); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1279 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1280 |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
1281 return CommandCost(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1282 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1283 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
1284 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
1285 * Sell a (single) train wagon/engine. |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1286 * @param flags type of operation |
15850
efc03d77eb93
(svn r20532) -Codechange: unify selling of vehicles a bit
rubidium <rubidium@openttd.org>
parents:
15849
diff
changeset
|
1287 * @param t the train wagon to sell |
efc03d77eb93
(svn r20532) -Codechange: unify selling of vehicles a bit
rubidium <rubidium@openttd.org>
parents:
15849
diff
changeset
|
1288 * @param data the selling mode |
efc03d77eb93
(svn r20532) -Codechange: unify selling of vehicles a bit
rubidium <rubidium@openttd.org>
parents:
15849
diff
changeset
|
1289 * - data = 0: only sell the single dragged wagon/engine (and any belonging rear-engines) |
efc03d77eb93
(svn r20532) -Codechange: unify selling of vehicles a bit
rubidium <rubidium@openttd.org>
parents:
15849
diff
changeset
|
1290 * - data = 1: sell the vehicle and all vehicles following it in the chain |
efc03d77eb93
(svn r20532) -Codechange: unify selling of vehicles a bit
rubidium <rubidium@openttd.org>
parents:
15849
diff
changeset
|
1291 * if the wagon is dragged, don't delete the possibly belonging rear-engine to some front |
15865
270f9b0689cc
(svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents:
15854
diff
changeset
|
1292 * @param user the user for the order backup. |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13054
diff
changeset
|
1293 * @return the cost of this operation or an error |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1294 */ |
15865
270f9b0689cc
(svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents:
15854
diff
changeset
|
1295 CommandCost CmdSellRailWagon(DoCommandFlag flags, Vehicle *t, uint16 data, uint32 user) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1296 { |
6789
26a3c3985d67
(svn r10028) -Fix (r2270/r2951): When deleting the first engine of a train with multiple engines, only reopen the train window if the player had the original train window open. This fixes 'random' windows opening for multiple players of the same company.
peter1138 <peter1138@openttd.org>
parents:
6788
diff
changeset
|
1297 /* Check if we deleted a vehicle window */ |
26a3c3985d67
(svn r10028) -Fix (r2270/r2951): When deleting the first engine of a train with multiple engines, only reopen the train window if the player had the original train window open. This fixes 'random' windows opening for multiple players of the same company.
peter1138 <peter1138@openttd.org>
parents:
6788
diff
changeset
|
1298 Window *w = NULL; |
26a3c3985d67
(svn r10028) -Fix (r2270/r2951): When deleting the first engine of a train with multiple engines, only reopen the train window if the player had the original train window open. This fixes 'random' windows opening for multiple players of the same company.
peter1138 <peter1138@openttd.org>
parents:
6788
diff
changeset
|
1299 |
13940
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1300 /* Sell a chain of vehicles or not? */ |
15850
efc03d77eb93
(svn r20532) -Codechange: unify selling of vehicles a bit
rubidium <rubidium@openttd.org>
parents:
15849
diff
changeset
|
1301 bool sell_chain = HasBit(data, 0); |
efc03d77eb93
(svn r20532) -Codechange: unify selling of vehicles a bit
rubidium <rubidium@openttd.org>
parents:
15849
diff
changeset
|
1302 |
efc03d77eb93
(svn r20532) -Codechange: unify selling of vehicles a bit
rubidium <rubidium@openttd.org>
parents:
15849
diff
changeset
|
1303 Train *v = Train::From(t)->GetFirstEnginePart(); |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1304 Train *first = v->First(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1305 |
12302
fc8e41f34b8c
(svn r16719) -Codechange: make IsArticulatedPart(), IsTrainEngine(), IsTrainWagon(), IsMultiheaded(), EngineHasArticPart() and IsRearDualheaded() members of Train
smatz <smatz@openttd.org>
parents:
12301
diff
changeset
|
1306 if (v->IsRearDualheaded()) return_cmd_error(STR_ERROR_REAR_ENGINE_FOLLOW_FRONT); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1307 |
13940
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1308 /* First make a backup of the order of the train. That way we can do |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1309 * whatever we want with the order and later on easily revert. */ |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1310 TrainList original; |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1311 MakeTrainBackup(original, first); |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1312 |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1313 /* We need to keep track of the new head and the head of what we're going to sell. */ |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1314 Train *new_head = first; |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1315 Train *sell_head = NULL; |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1316 |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1317 /* Split the train in the wanted way. */ |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1318 ArrangeTrains(&sell_head, NULL, &new_head, v, sell_chain); |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1319 |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1320 /* We don't need to validate the second train; it's going to be sold. */ |
15899
097904c36bde
(svn r20582) -Fix [FS#4044]: Autoreplace can trigger an assertion when at the vehicle limit
rubidium <rubidium@openttd.org>
parents:
15891
diff
changeset
|
1321 CommandCost ret = ValidateTrains(NULL, NULL, first, new_head, (flags & DC_AUTOREPLACE) == 0); |
13940
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1322 if (ret.Failed()) { |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1323 /* Restore the train we had. */ |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1324 RestoreTrainBackup(original); |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1325 return ret; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1326 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1327 |
8230
5b61305fcdd4
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents:
8226
diff
changeset
|
1328 CommandCost cost(EXPENSES_NEW_VEHICLES); |
13940
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1329 for (Train *t = sell_head; t != NULL; t = t->Next()) cost.AddCost(-t->value); |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1330 |
17284
acb919c16a29
(svn r22024) -Fix [FS#4468]: verify we can allocate an OrderList before we actually try to do so (Rubidium)
smatz <smatz@openttd.org>
parents:
17277
diff
changeset
|
1331 if (first->orders.list == NULL && !OrderList::CanAllocateItem()) { |
acb919c16a29
(svn r22024) -Fix [FS#4468]: verify we can allocate an OrderList before we actually try to do so (Rubidium)
smatz <smatz@openttd.org>
parents:
17277
diff
changeset
|
1332 return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS); |
acb919c16a29
(svn r22024) -Fix [FS#4468]: verify we can allocate an OrderList before we actually try to do so (Rubidium)
smatz <smatz@openttd.org>
parents:
17277
diff
changeset
|
1333 } |
acb919c16a29
(svn r22024) -Fix [FS#4468]: verify we can allocate an OrderList before we actually try to do so (Rubidium)
smatz <smatz@openttd.org>
parents:
17277
diff
changeset
|
1334 |
13940
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1335 /* do it? */ |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1336 if (flags & DC_EXEC) { |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1337 /* First normalise the sub types of the chain. */ |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1338 NormaliseSubtypes(new_head); |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1339 |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1340 if (v == first && v->IsEngine() && !sell_chain && new_head != NULL && new_head->IsFrontEngine()) { |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1341 /* We are selling the front engine. In this case we want to |
15820
59fd8293b2ee
(svn r20499) -Doc: Spelling fixes, and one doxygen comment addition.
alberth <alberth@openttd.org>
parents:
15763
diff
changeset
|
1342 * 'give' the order, unit number and such to the new head. */ |
13940
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1343 new_head->orders.list = first->orders.list; |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1344 new_head->AddToShared(first); |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1345 DeleteVehicleOrders(first); |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1346 |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1347 /* Copy other important data from the front engine */ |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1348 new_head->CopyVehicleConfigAndStatistics(first); |
18159
de0749262352
(svn r22984) -Feature: Display profit icons for groups in the group GUI.
frosch <frosch@openttd.org>
parents:
18153
diff
changeset
|
1349 GroupStatistics::CountVehicle(new_head, 1); // after copying over the profit |
13940
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1350 |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1351 /* If we deleted a window then open a new one for the 'new' train */ |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1352 if (IsLocalCompany() && w != NULL) ShowVehicleViewWindow(new_head); |
15891
67b39929d6a2
(svn r20573) -Codechange: free/reserve some bits in the sell vehicle command to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents:
15890
diff
changeset
|
1353 } else if (v->IsPrimaryVehicle() && data & (MAKE_ORDER_BACKUP_FLAG >> 20)) { |
15865
270f9b0689cc
(svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
rubidium <rubidium@openttd.org>
parents:
15854
diff
changeset
|
1354 OrderBackup::Backup(v, user); |
13940
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1355 } |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1356 |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1357 /* We need to update the information about the train. */ |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1358 NormaliseTrainHead(new_head); |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1359 |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1360 /* We are undoubtedly changing something in the depot and train list. */ |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1361 InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1362 InvalidateWindowClassesData(WC_TRAINS_LIST, 0); |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1363 |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1364 /* Actually delete the sold 'goods' */ |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1365 delete sell_head; |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1366 } else { |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1367 /* We don't want to execute what we're just tried. */ |
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1368 RestoreTrainBackup(original); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1369 } |
13940
b76c3fa5c59d
(svn r18472) -Fix [FS#3146]: selling vehicles in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13938
diff
changeset
|
1370 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1371 return cost; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1372 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1373 |
6558
2fc024ee8217
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium <rubidium@openttd.org>
parents:
6554
diff
changeset
|
1374 void Train::UpdateDeltaXY(Direction direction) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1375 { |
6558
2fc024ee8217
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium <rubidium@openttd.org>
parents:
6554
diff
changeset
|
1376 #define MKIT(a, b, c, d) ((a & 0xFF) << 24) | ((b & 0xFF) << 16) | ((c & 0xFF) << 8) | ((d & 0xFF) << 0) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1377 static const uint32 _delta_xy_table[8] = { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1378 MKIT(3, 3, -1, -1), |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1379 MKIT(3, 7, -1, -3), |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1380 MKIT(3, 3, -1, -1), |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1381 MKIT(7, 3, -3, -1), |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1382 MKIT(3, 3, -1, -1), |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1383 MKIT(3, 7, -1, -3), |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1384 MKIT(3, 3, -1, -1), |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1385 MKIT(7, 3, -3, -1), |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1386 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1387 #undef MKIT |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1388 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1389 uint32 x = _delta_xy_table[direction]; |
6558
2fc024ee8217
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium <rubidium@openttd.org>
parents:
6554
diff
changeset
|
1390 this->x_offs = GB(x, 0, 8); |
2fc024ee8217
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium <rubidium@openttd.org>
parents:
6554
diff
changeset
|
1391 this->y_offs = GB(x, 8, 8); |
8793
27556e5b9388
(svn r12531) -Codechange: Rename some variables for consistency.
frosch <frosch@openttd.org>
parents:
8786
diff
changeset
|
1392 this->x_extent = GB(x, 16, 8); |
27556e5b9388
(svn r12531) -Codechange: Rename some variables for consistency.
frosch <frosch@openttd.org>
parents:
8786
diff
changeset
|
1393 this->y_extent = GB(x, 24, 8); |
27556e5b9388
(svn r12531) -Codechange: Rename some variables for consistency.
frosch <frosch@openttd.org>
parents:
8786
diff
changeset
|
1394 this->z_extent = 6; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1395 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1396 |
9808
fa8743b489ff
(svn r13950) -Add [YAPP]: Trains can now also be in a 'stuck' state when waiting on a path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9775
diff
changeset
|
1397 /** Mark a train as stuck and stop it if it isn't stopped right now. */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1398 static void MarkTrainAsStuck(Train *v) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1399 { |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
1400 if (!HasBit(v->flags, VRF_TRAIN_STUCK)) { |
15604
ca959eb5d431
(svn r20266) -Doc: Mostly typo fixes, a few doxygen-related improvements.
alberth <alberth@openttd.org>
parents:
15579
diff
changeset
|
1401 /* It is the first time the problem occurred, set the "train stuck" flag. */ |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
1402 SetBit(v->flags, VRF_TRAIN_STUCK); |
12467
cf0ccd158d37
(svn r16901) -Fix [FS#3046] (rpbs): when marking trains stuck don't reset the unload counter/stuck when the vehicle is unloading. It'll be automatically reset once the vehicle wants to leave the station
rubidium <rubidium@openttd.org>
parents:
12460
diff
changeset
|
1403 |
14213
41b2e7bf03da
(svn r18764) -Fix [FS#3422]: split the (un)load ticks counter and signal wait counter; sometimes they might get into eachother's way
rubidium <rubidium@openttd.org>
parents:
14127
diff
changeset
|
1404 v->wait_counter = 0; |
9808
fa8743b489ff
(svn r13950) -Add [YAPP]: Trains can now also be in a 'stuck' state when waiting on a path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9775
diff
changeset
|
1405 |
fa8743b489ff
(svn r13950) -Add [YAPP]: Trains can now also be in a 'stuck' state when waiting on a path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9775
diff
changeset
|
1406 /* Stop train */ |
fa8743b489ff
(svn r13950) -Add [YAPP]: Trains can now also be in a 'stuck' state when waiting on a path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9775
diff
changeset
|
1407 v->cur_speed = 0; |
fa8743b489ff
(svn r13950) -Add [YAPP]: Trains can now also be in a 'stuck' state when waiting on a path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9775
diff
changeset
|
1408 v->subspeed = 0; |
17172
679a25d71a9d
(svn r21911) -Codechange: move tcache.last_speed to gcache.last_speed and make SetLastSpeed a function of GroundVehicle
rubidium <rubidium@openttd.org>
parents:
17165
diff
changeset
|
1409 v->SetLastSpeed(); |
9808
fa8743b489ff
(svn r13950) -Add [YAPP]: Trains can now also be in a 'stuck' state when waiting on a path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9775
diff
changeset
|
1410 |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
13001
diff
changeset
|
1411 SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
9808
fa8743b489ff
(svn r13950) -Add [YAPP]: Trains can now also be in a 'stuck' state when waiting on a path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9775
diff
changeset
|
1412 } |
fa8743b489ff
(svn r13950) -Add [YAPP]: Trains can now also be in a 'stuck' state when waiting on a path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9775
diff
changeset
|
1413 } |
fa8743b489ff
(svn r13950) -Add [YAPP]: Trains can now also be in a 'stuck' state when waiting on a path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9775
diff
changeset
|
1414 |
fa8743b489ff
(svn r13950) -Add [YAPP]: Trains can now also be in a 'stuck' state when waiting on a path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9775
diff
changeset
|
1415 static void SwapTrainFlags(uint16 *swap_flag1, uint16 *swap_flag2) |
fa8743b489ff
(svn r13950) -Add [YAPP]: Trains can now also be in a 'stuck' state when waiting on a path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9775
diff
changeset
|
1416 { |
fa8743b489ff
(svn r13950) -Add [YAPP]: Trains can now also be in a 'stuck' state when waiting on a path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9775
diff
changeset
|
1417 uint16 flag1 = *swap_flag1; |
fa8743b489ff
(svn r13950) -Add [YAPP]: Trains can now also be in a 'stuck' state when waiting on a path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9775
diff
changeset
|
1418 uint16 flag2 = *swap_flag2; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1419 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1420 /* Clear the flags */ |
14753
3e27a2798ca0
(svn r19341) -Codechange: Move GOINGUP/GOINGDOWN flags to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14751
diff
changeset
|
1421 ClrBit(*swap_flag1, GVF_GOINGUP_BIT); |
3e27a2798ca0
(svn r19341) -Codechange: Move GOINGUP/GOINGDOWN flags to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14751
diff
changeset
|
1422 ClrBit(*swap_flag1, GVF_GOINGDOWN_BIT); |
3e27a2798ca0
(svn r19341) -Codechange: Move GOINGUP/GOINGDOWN flags to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14751
diff
changeset
|
1423 ClrBit(*swap_flag2, GVF_GOINGUP_BIT); |
3e27a2798ca0
(svn r19341) -Codechange: Move GOINGUP/GOINGDOWN flags to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14751
diff
changeset
|
1424 ClrBit(*swap_flag2, GVF_GOINGDOWN_BIT); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1425 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1426 /* Reverse the rail-flags (if needed) */ |
14753
3e27a2798ca0
(svn r19341) -Codechange: Move GOINGUP/GOINGDOWN flags to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14751
diff
changeset
|
1427 if (HasBit(flag1, GVF_GOINGUP_BIT)) { |
3e27a2798ca0
(svn r19341) -Codechange: Move GOINGUP/GOINGDOWN flags to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14751
diff
changeset
|
1428 SetBit(*swap_flag2, GVF_GOINGDOWN_BIT); |
3e27a2798ca0
(svn r19341) -Codechange: Move GOINGUP/GOINGDOWN flags to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14751
diff
changeset
|
1429 } else if (HasBit(flag1, GVF_GOINGDOWN_BIT)) { |
3e27a2798ca0
(svn r19341) -Codechange: Move GOINGUP/GOINGDOWN flags to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14751
diff
changeset
|
1430 SetBit(*swap_flag2, GVF_GOINGUP_BIT); |
14768
f31d8dc443fc
(svn r19356) -Fix: Whitespace.
frosch <frosch@openttd.org>
parents:
14754
diff
changeset
|
1431 } |
14753
3e27a2798ca0
(svn r19341) -Codechange: Move GOINGUP/GOINGDOWN flags to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14751
diff
changeset
|
1432 if (HasBit(flag2, GVF_GOINGUP_BIT)) { |
3e27a2798ca0
(svn r19341) -Codechange: Move GOINGUP/GOINGDOWN flags to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14751
diff
changeset
|
1433 SetBit(*swap_flag1, GVF_GOINGDOWN_BIT); |
3e27a2798ca0
(svn r19341) -Codechange: Move GOINGUP/GOINGDOWN flags to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14751
diff
changeset
|
1434 } else if (HasBit(flag2, GVF_GOINGDOWN_BIT)) { |
3e27a2798ca0
(svn r19341) -Codechange: Move GOINGUP/GOINGDOWN flags to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14751
diff
changeset
|
1435 SetBit(*swap_flag1, GVF_GOINGUP_BIT); |
14768
f31d8dc443fc
(svn r19356) -Fix: Whitespace.
frosch <frosch@openttd.org>
parents:
14754
diff
changeset
|
1436 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1437 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1438 |
17098
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1439 /** |
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1440 * Updates some variables after swapping the vehicle. |
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1441 * @param v swapped vehicle |
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1442 */ |
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1443 static void UpdateStatusAfterSwap(Train *v) |
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1444 { |
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1445 /* Reverse the direction. */ |
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1446 if (v->track != TRACK_BIT_DEPOT) v->direction = ReverseDir(v->direction); |
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1447 |
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1448 /* Call the proper EnterTile function unless we are in a wormhole. */ |
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1449 if (v->track != TRACK_BIT_WORMHOLE) { |
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1450 VehicleEnterTile(v, v->tile, v->x_pos, v->y_pos); |
17142
958bcdb45229
(svn r21880) -Fix: when a train after reversing ended at the last bit of a bridge ramp and directed outside the bridge, it could still have track set to TRACK_BIT_WORMHOLE
smatz <smatz@openttd.org>
parents:
17141
diff
changeset
|
1451 } else { |
958bcdb45229
(svn r21880) -Fix: when a train after reversing ended at the last bit of a bridge ramp and directed outside the bridge, it could still have track set to TRACK_BIT_WORMHOLE
smatz <smatz@openttd.org>
parents:
17141
diff
changeset
|
1452 /* VehicleEnter_TunnelBridge() sets TRACK_BIT_WORMHOLE when the vehicle |
958bcdb45229
(svn r21880) -Fix: when a train after reversing ended at the last bit of a bridge ramp and directed outside the bridge, it could still have track set to TRACK_BIT_WORMHOLE
smatz <smatz@openttd.org>
parents:
17141
diff
changeset
|
1453 * is on the last bit of the bridge head (frame == TILE_SIZE - 1). |
958bcdb45229
(svn r21880) -Fix: when a train after reversing ended at the last bit of a bridge ramp and directed outside the bridge, it could still have track set to TRACK_BIT_WORMHOLE
smatz <smatz@openttd.org>
parents:
17141
diff
changeset
|
1454 * If we were swapped with such a vehicle, we have set TRACK_BIT_WORMHOLE, |
958bcdb45229
(svn r21880) -Fix: when a train after reversing ended at the last bit of a bridge ramp and directed outside the bridge, it could still have track set to TRACK_BIT_WORMHOLE
smatz <smatz@openttd.org>
parents:
17141
diff
changeset
|
1455 * when we shouldn't have. Check if this is the case. */ |
958bcdb45229
(svn r21880) -Fix: when a train after reversing ended at the last bit of a bridge ramp and directed outside the bridge, it could still have track set to TRACK_BIT_WORMHOLE
smatz <smatz@openttd.org>
parents:
17141
diff
changeset
|
1456 TileIndex vt = TileVirtXY(v->x_pos, v->y_pos); |
958bcdb45229
(svn r21880) -Fix: when a train after reversing ended at the last bit of a bridge ramp and directed outside the bridge, it could still have track set to TRACK_BIT_WORMHOLE
smatz <smatz@openttd.org>
parents:
17141
diff
changeset
|
1457 if (IsTileType(vt, MP_TUNNELBRIDGE)) { |
958bcdb45229
(svn r21880) -Fix: when a train after reversing ended at the last bit of a bridge ramp and directed outside the bridge, it could still have track set to TRACK_BIT_WORMHOLE
smatz <smatz@openttd.org>
parents:
17141
diff
changeset
|
1458 VehicleEnterTile(v, vt, v->x_pos, v->y_pos); |
958bcdb45229
(svn r21880) -Fix: when a train after reversing ended at the last bit of a bridge ramp and directed outside the bridge, it could still have track set to TRACK_BIT_WORMHOLE
smatz <smatz@openttd.org>
parents:
17141
diff
changeset
|
1459 if (v->track != TRACK_BIT_WORMHOLE && IsBridgeTile(v->tile)) { |
958bcdb45229
(svn r21880) -Fix: when a train after reversing ended at the last bit of a bridge ramp and directed outside the bridge, it could still have track set to TRACK_BIT_WORMHOLE
smatz <smatz@openttd.org>
parents:
17141
diff
changeset
|
1460 /* We have just left the wormhole, possibly set the |
958bcdb45229
(svn r21880) -Fix: when a train after reversing ended at the last bit of a bridge ramp and directed outside the bridge, it could still have track set to TRACK_BIT_WORMHOLE
smatz <smatz@openttd.org>
parents:
17141
diff
changeset
|
1461 * "goingdown" bit. UpdateInclination() can be used |
958bcdb45229
(svn r21880) -Fix: when a train after reversing ended at the last bit of a bridge ramp and directed outside the bridge, it could still have track set to TRACK_BIT_WORMHOLE
smatz <smatz@openttd.org>
parents:
17141
diff
changeset
|
1462 * because we are at the border of the tile. */ |
958bcdb45229
(svn r21880) -Fix: when a train after reversing ended at the last bit of a bridge ramp and directed outside the bridge, it could still have track set to TRACK_BIT_WORMHOLE
smatz <smatz@openttd.org>
parents:
17141
diff
changeset
|
1463 v->UpdateInclination(true, true); |
958bcdb45229
(svn r21880) -Fix: when a train after reversing ended at the last bit of a bridge ramp and directed outside the bridge, it could still have track set to TRACK_BIT_WORMHOLE
smatz <smatz@openttd.org>
parents:
17141
diff
changeset
|
1464 return; |
958bcdb45229
(svn r21880) -Fix: when a train after reversing ended at the last bit of a bridge ramp and directed outside the bridge, it could still have track set to TRACK_BIT_WORMHOLE
smatz <smatz@openttd.org>
parents:
17141
diff
changeset
|
1465 } |
958bcdb45229
(svn r21880) -Fix: when a train after reversing ended at the last bit of a bridge ramp and directed outside the bridge, it could still have track set to TRACK_BIT_WORMHOLE
smatz <smatz@openttd.org>
parents:
17141
diff
changeset
|
1466 } |
17098
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1467 } |
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1468 |
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1469 v->UpdateViewport(true, true); |
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1470 } |
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1471 |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1472 static void ReverseTrainSwapVeh(Train *v, int l, int r) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1473 { |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1474 Train *a, *b; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1475 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1476 /* locate vehicles to swap */ |
7492
09743324277c
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium <rubidium@openttd.org>
parents:
7488
diff
changeset
|
1477 for (a = v; l != 0; l--) a = a->Next(); |
09743324277c
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium <rubidium@openttd.org>
parents:
7488
diff
changeset
|
1478 for (b = v; r != 0; r--) b = b->Next(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1479 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1480 if (a != b) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1481 /* swap the hidden bits */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1482 { |
14678
68f4a5f222ef
(svn r19257) -Codechange: minor coding style fix
smatz <smatz@openttd.org>
parents:
14645
diff
changeset
|
1483 uint16 tmp = (a->vehstatus & ~VS_HIDDEN) | (b->vehstatus & VS_HIDDEN); |
68f4a5f222ef
(svn r19257) -Codechange: minor coding style fix
smatz <smatz@openttd.org>
parents:
14645
diff
changeset
|
1484 b->vehstatus = (b->vehstatus & ~VS_HIDDEN) | (a->vehstatus & VS_HIDDEN); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1485 a->vehstatus = tmp; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1486 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1487 |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
1488 Swap(a->track, b->track); |
14680
f3dfa0c1c278
(svn r19260) -Codechange: another minor coding style fix
smatz <smatz@openttd.org>
parents:
14678
diff
changeset
|
1489 Swap(a->direction, b->direction); |
5733 | 1490 Swap(a->x_pos, b->x_pos); |
1491 Swap(a->y_pos, b->y_pos); | |
1492 Swap(a->tile, b->tile); | |
1493 Swap(a->z_pos, b->z_pos); | |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1494 |
14753
3e27a2798ca0
(svn r19341) -Codechange: Move GOINGUP/GOINGDOWN flags to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14751
diff
changeset
|
1495 SwapTrainFlags(&a->gv_flags, &b->gv_flags); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1496 |
17098
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1497 UpdateStatusAfterSwap(a); |
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1498 UpdateStatusAfterSwap(b); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1499 } else { |
17136
85e9c2a2bdb2
(svn r21874) -Fix: when a single-vehicle train was reversed while on a slope, its GOINGUP/DOWN weren't swapped
smatz <smatz@openttd.org>
parents:
17110
diff
changeset
|
1500 /* Swap GVF_GOINGUP_BIT/GVF_GOINGDOWN_BIT. |
85e9c2a2bdb2
(svn r21874) -Fix: when a single-vehicle train was reversed while on a slope, its GOINGUP/DOWN weren't swapped
smatz <smatz@openttd.org>
parents:
17110
diff
changeset
|
1501 * This is a little bit redundant way, a->gv_flags will |
85e9c2a2bdb2
(svn r21874) -Fix: when a single-vehicle train was reversed while on a slope, its GOINGUP/DOWN weren't swapped
smatz <smatz@openttd.org>
parents:
17110
diff
changeset
|
1502 * be (re)set twice, but it reduces code duplication */ |
85e9c2a2bdb2
(svn r21874) -Fix: when a single-vehicle train was reversed while on a slope, its GOINGUP/DOWN weren't swapped
smatz <smatz@openttd.org>
parents:
17110
diff
changeset
|
1503 SwapTrainFlags(&a->gv_flags, &a->gv_flags); |
17098
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1504 UpdateStatusAfterSwap(a); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1505 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1506 |
15820
59fd8293b2ee
(svn r20499) -Doc: Spelling fixes, and one doxygen comment addition.
alberth <alberth@openttd.org>
parents:
15763
diff
changeset
|
1507 /* Update power of the train in case tiles were different rail type. */ |
15826
7f692dcca929
(svn r20505) -Feature [FS#3978]: Allow changing visual effect when changing railtype.
frosch <frosch@openttd.org>
parents:
15825
diff
changeset
|
1508 v->RailtypeChanged(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1509 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1510 |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1511 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1512 /** |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1513 * Check if the vehicle is a train |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1514 * @param v vehicle on tile |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1515 * @return v if it is a train, NULL otherwise |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1516 */ |
9775
c3caa51b9888
(svn r13912) -Codechange: remove some casts by returning the proper type instead of void*.
rubidium <rubidium@openttd.org>
parents:
9774
diff
changeset
|
1517 static Vehicle *TrainOnTileEnum(Vehicle *v, void *) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1518 { |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1519 return (v->type == VEH_TRAIN) ? v : NULL; |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1520 } |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1521 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1522 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1523 /** |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1524 * Checks if a train is approaching a rail-road crossing |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1525 * @param v vehicle on tile |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1526 * @param data tile with crossing we are testing |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1527 * @return v if it is approaching a crossing, NULL otherwise |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1528 */ |
9775
c3caa51b9888
(svn r13912) -Codechange: remove some casts by returning the proper type instead of void*.
rubidium <rubidium@openttd.org>
parents:
9774
diff
changeset
|
1529 static Vehicle *TrainApproachingCrossingEnum(Vehicle *v, void *data) |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1530 { |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
1531 if (v->type != VEH_TRAIN || (v->vehstatus & VS_CRASHED)) return NULL; |
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
1532 |
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
1533 Train *t = Train::From(v); |
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
1534 if (!t->IsFrontEngine()) return NULL; |
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
1535 |
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
1536 TileIndex tile = *(TileIndex *)data; |
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
1537 |
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
1538 if (TrainApproachingCrossingTile(t) != tile) return NULL; |
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
1539 |
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
1540 return t; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1541 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1542 |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1543 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1544 /** |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1545 * Finds a vehicle approaching rail-road crossing |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1546 * @param tile tile to test |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9992
diff
changeset
|
1547 * @return true if a vehicle is approaching the crossing |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1548 * @pre tile is a rail-road crossing |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1549 */ |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9992
diff
changeset
|
1550 static bool TrainApproachingCrossing(TileIndex tile) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1551 { |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1552 assert(IsLevelCrossingTile(tile)); |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1553 |
8598
ef2c93a9589d
(svn r12179) -Codechange: use GetCrossingRailTrack() and GetCrossingRailAxis() to improve code readability
smatz <smatz@openttd.org>
parents:
8597
diff
changeset
|
1554 DiagDirection dir = AxisToDiagDir(GetCrossingRailAxis(tile)); |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1555 TileIndex tile_from = tile + TileOffsByDiagDir(dir); |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1556 |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9992
diff
changeset
|
1557 if (HasVehicleOnPos(tile_from, &tile, &TrainApproachingCrossingEnum)) return true; |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1558 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1559 dir = ReverseDiagDir(dir); |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1560 tile_from = tile + TileOffsByDiagDir(dir); |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1561 |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9992
diff
changeset
|
1562 return HasVehicleOnPos(tile_from, &tile, &TrainApproachingCrossingEnum); |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1563 } |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1564 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1565 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1566 /** |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1567 * Sets correct crossing state |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1568 * @param tile tile to update |
8344
6312fafcfe47
(svn r11910) -Fix: play 'ding-ding' crossing sound in more cases (except gameload and crossing construction)
smatz <smatz@openttd.org>
parents:
8342
diff
changeset
|
1569 * @param sound should we play sound? |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1570 * @pre tile is a rail-road crossing |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1571 */ |
8344
6312fafcfe47
(svn r11910) -Fix: play 'ding-ding' crossing sound in more cases (except gameload and crossing construction)
smatz <smatz@openttd.org>
parents:
8342
diff
changeset
|
1572 void UpdateLevelCrossing(TileIndex tile, bool sound) |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1573 { |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1574 assert(IsLevelCrossingTile(tile)); |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1575 |
9824
fe3562a51648
(svn r13966) -Codechange [YAPP]: Bar level crossings upon path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9822
diff
changeset
|
1576 /* train on crossing || train approaching crossing || reserved */ |
12470
299da608443d
(svn r16907) -Codechange: make a more clear distinction between reservation functions that return a bool and that return TrackBits; GetRailStationReservation vs GetRailwayStationReservation, which one returns the bool and which one the TrackBits?
rubidium <rubidium@openttd.org>
parents:
12467
diff
changeset
|
1577 bool new_state = HasVehicleOnPos(tile, NULL, &TrainOnTileEnum) || TrainApproachingCrossing(tile) || HasCrossingReservation(tile); |
8344
6312fafcfe47
(svn r11910) -Fix: play 'ding-ding' crossing sound in more cases (except gameload and crossing construction)
smatz <smatz@openttd.org>
parents:
8342
diff
changeset
|
1578 |
6312fafcfe47
(svn r11910) -Fix: play 'ding-ding' crossing sound in more cases (except gameload and crossing construction)
smatz <smatz@openttd.org>
parents:
8342
diff
changeset
|
1579 if (new_state != IsCrossingBarred(tile)) { |
6312fafcfe47
(svn r11910) -Fix: play 'ding-ding' crossing sound in more cases (except gameload and crossing construction)
smatz <smatz@openttd.org>
parents:
8342
diff
changeset
|
1580 if (new_state && sound) { |
6312fafcfe47
(svn r11910) -Fix: play 'ding-ding' crossing sound in more cases (except gameload and crossing construction)
smatz <smatz@openttd.org>
parents:
8342
diff
changeset
|
1581 SndPlayTileFx(SND_0E_LEVEL_CROSSING, tile); |
6312fafcfe47
(svn r11910) -Fix: play 'ding-ding' crossing sound in more cases (except gameload and crossing construction)
smatz <smatz@openttd.org>
parents:
8342
diff
changeset
|
1582 } |
6312fafcfe47
(svn r11910) -Fix: play 'ding-ding' crossing sound in more cases (except gameload and crossing construction)
smatz <smatz@openttd.org>
parents:
8342
diff
changeset
|
1583 SetCrossingBarred(tile, new_state); |
6312fafcfe47
(svn r11910) -Fix: play 'ding-ding' crossing sound in more cases (except gameload and crossing construction)
smatz <smatz@openttd.org>
parents:
8342
diff
changeset
|
1584 MarkTileDirtyByTile(tile); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1585 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1586 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1587 |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1588 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1589 /** |
8356
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1590 * Bars crossing and plays ding-ding sound if not barred already |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1591 * @param tile tile with crossing |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1592 * @pre tile is a rail-road crossing |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1593 */ |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1594 static inline void MaybeBarCrossingWithSound(TileIndex tile) |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1595 { |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1596 if (!IsCrossingBarred(tile)) { |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1597 BarCrossing(tile); |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1598 SndPlayTileFx(SND_0E_LEVEL_CROSSING, tile); |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1599 MarkTileDirtyByTile(tile); |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1600 } |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1601 } |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1602 |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1603 |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1604 /** |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1605 * Advances wagons for train reversing, needed for variable length wagons. |
8712
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1606 * This one is called before the train is reversed. |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1607 * @param v First vehicle in chain |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1608 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1609 static void AdvanceWagonsBeforeSwap(Train *v) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1610 { |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1611 Train *base = v; |
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1612 Train *first = base; // first vehicle to move |
12460
4acae7d6f5ed
(svn r16894) -Codechange: Add [Specialised]Vehicle::Last().
frosch <frosch@openttd.org>
parents:
12450
diff
changeset
|
1613 Train *last = v->Last(); // last vehicle to move |
6150 | 1614 uint length = CountVehiclesInChain(v); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1615 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1616 while (length > 2) { |
8712
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1617 last = last->Previous(); |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1618 first = first->Next(); |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1619 |
16788
efb0333e5aad
(svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
1620 int differential = base->gcache.cached_veh_length - last->gcache.cached_veh_length; |
8712
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1621 |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1622 /* do not update images now |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1623 * negative differential will be handled in AdvanceWagonsAfterSwap() */ |
11327
fc99317cb85b
(svn r15677) -Fix [FS#2546]: vehicle images would be determined during the process of moving the vehicle which means that only the (orientation) data for the vehicles in front of it is valid. Now the data for the vehicles behind the vehicle are valid too.
rubidium <rubidium@openttd.org>
parents:
11326
diff
changeset
|
1624 for (int i = 0; i < differential; i++) TrainController(first, last->Next()); |
8712
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1625 |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1626 base = first; // == base->Next() |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1627 length -= 2; |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1628 } |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1629 } |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1630 |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1631 |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1632 /** |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1633 * Advances wagons for train reversing, needed for variable length wagons. |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1634 * This one is called after the train is reversed. |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1635 * @param v First vehicle in chain |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1636 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1637 static void AdvanceWagonsAfterSwap(Train *v) |
8712
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1638 { |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1639 /* first of all, fix the situation when the train was entering a depot */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1640 Train *dep = v; // last vehicle in front of just left depot |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
1641 while (dep->Next() != NULL && (dep->track == TRACK_BIT_DEPOT || dep->Next()->track != TRACK_BIT_DEPOT)) { |
8712
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1642 dep = dep->Next(); // find first vehicle outside of a depot, with next vehicle inside a depot |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1643 } |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1644 |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1645 Train *leave = dep->Next(); // first vehicle in a depot we are leaving now |
8712
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1646 |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1647 if (leave != NULL) { |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1648 /* 'pull' next wagon out of the depot, so we won't miss it (it could stay in depot forever) */ |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1649 int d = TicksToLeaveDepot(dep); |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1650 |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1651 if (d <= 0) { |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1652 leave->vehstatus &= ~VS_HIDDEN; // move it out of the depot |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
1653 leave->track = TrackToTrackBits(GetRailDepotTrack(leave->tile)); |
11327
fc99317cb85b
(svn r15677) -Fix [FS#2546]: vehicle images would be determined during the process of moving the vehicle which means that only the (orientation) data for the vehicles in front of it is valid. Now the data for the vehicles behind the vehicle are valid too.
rubidium <rubidium@openttd.org>
parents:
11326
diff
changeset
|
1654 for (int i = 0; i >= d; i--) TrainController(leave, NULL); // maybe move it, and maybe let another wagon leave |
8712
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1655 } |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1656 } else { |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1657 dep = NULL; // no vehicle in a depot, so no vehicle leaving a depot |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1658 } |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1659 |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1660 Train *base = v; |
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1661 Train *first = base; // first vehicle to move |
12460
4acae7d6f5ed
(svn r16894) -Codechange: Add [Specialised]Vehicle::Last().
frosch <frosch@openttd.org>
parents:
12450
diff
changeset
|
1662 Train *last = v->Last(); // last vehicle to move |
8712
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1663 uint length = CountVehiclesInChain(v); |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1664 |
15820
59fd8293b2ee
(svn r20499) -Doc: Spelling fixes, and one doxygen comment addition.
alberth <alberth@openttd.org>
parents:
15763
diff
changeset
|
1665 /* We have to make sure all wagons that leave a depot because of train reversing are moved correctly |
8712
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1666 * they have already correct spacing, so we have to make sure they are moved how they should */ |
15820
59fd8293b2ee
(svn r20499) -Doc: Spelling fixes, and one doxygen comment addition.
alberth <alberth@openttd.org>
parents:
15763
diff
changeset
|
1667 bool nomove = (dep == NULL); // If there is no vehicle leaving a depot, limit the number of wagons moved immediately. |
8712
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1668 |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1669 while (length > 2) { |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1670 /* we reached vehicle (originally) in front of a depot, stop now |
15820
59fd8293b2ee
(svn r20499) -Doc: Spelling fixes, and one doxygen comment addition.
alberth <alberth@openttd.org>
parents:
15763
diff
changeset
|
1671 * (we would move wagons that are already moved with new wagon length). */ |
8712
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1672 if (base == dep) break; |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1673 |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1674 /* the last wagon was that one leaving a depot, so do not move it anymore */ |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1675 if (last == dep) nomove = true; |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1676 |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1677 last = last->Previous(); |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1678 first = first->Next(); |
6150 | 1679 |
16788
efb0333e5aad
(svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
1680 int differential = last->gcache.cached_veh_length - base->gcache.cached_veh_length; |
8712
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1681 |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1682 /* do not update images now */ |
11327
fc99317cb85b
(svn r15677) -Fix [FS#2546]: vehicle images would be determined during the process of moving the vehicle which means that only the (orientation) data for the vehicles in front of it is valid. Now the data for the vehicles behind the vehicle are valid too.
rubidium <rubidium@openttd.org>
parents:
11326
diff
changeset
|
1683 for (int i = 0; i < differential; i++) TrainController(first, (nomove ? last->Next() : NULL)); |
8712
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1684 |
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1685 base = first; // == base->Next() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1686 length -= 2; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1687 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1688 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1689 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1690 |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1691 static void ReverseTrainDirection(Train *v) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1692 { |
8961
b33bcd7fa037
(svn r12753) -Codechange: do not use IsDepotTypeTile() where simpler function can be used
smatz <smatz@openttd.org>
parents:
8954
diff
changeset
|
1693 if (IsRailDepotTile(v->tile)) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1694 InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1695 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1696 |
12693
3916fe720543
(svn r17152) -Fix: A stuck train could free the reservation of another train if it was reversed or did crash.
michi_cc <michi_cc@openttd.org>
parents:
12692
diff
changeset
|
1697 /* Clear path reservation in front if train is not stuck. */ |
3916fe720543
(svn r17152) -Fix: A stuck train could free the reservation of another train if it was reversed or did crash.
michi_cc <michi_cc@openttd.org>
parents:
12692
diff
changeset
|
1698 if (!HasBit(v->flags, VRF_TRAIN_STUCK)) FreeTrainTrackReservation(v); |
9819
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1699 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1700 /* Check if we were approaching a rail/road-crossing */ |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1701 TileIndex crossing = TrainApproachingCrossingTile(v); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1702 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1703 /* count number of vehicles */ |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
1704 int r = CountVehiclesInChain(v) - 1; // number of vehicles - 1 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1705 |
8712
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1706 AdvanceWagonsBeforeSwap(v); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1707 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1708 /* swap start<>end, start+1<>end-1, ... */ |
6150 | 1709 int l = 0; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1710 do { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1711 ReverseTrainSwapVeh(v, l++, r--); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1712 } while (l <= r); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1713 |
8712
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1714 AdvanceWagonsAfterSwap(v); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1715 |
8961
b33bcd7fa037
(svn r12753) -Codechange: do not use IsDepotTypeTile() where simpler function can be used
smatz <smatz@openttd.org>
parents:
8954
diff
changeset
|
1716 if (IsRailDepotTile(v->tile)) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1717 InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1718 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1719 |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
1720 ToggleBit(v->flags, VRF_TOGGLE_REVERSE); |
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
1721 |
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
1722 ClrBit(v->flags, VRF_REVERSING); |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1723 |
8667
4e73621c3950
(svn r12332) -Fix (r12331): Invalidate cached data and update image after setting flag.
peter1138 <peter1138@openttd.org>
parents:
8666
diff
changeset
|
1724 /* recalculate cached data */ |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
1725 v->ConsistChanged(true); |
8667
4e73621c3950
(svn r12332) -Fix (r12331): Invalidate cached data and update image after setting flag.
peter1138 <peter1138@openttd.org>
parents:
8666
diff
changeset
|
1726 |
4e73621c3950
(svn r12332) -Fix (r12331): Invalidate cached data and update image after setting flag.
peter1138 <peter1138@openttd.org>
parents:
8666
diff
changeset
|
1727 /* update all images */ |
15127
c065afa82756
(svn r19756) -Codechange: move UpdateViewport() from Vehicle to SpecializedVehicle in order to improve performance
smatz <smatz@openttd.org>
parents:
15073
diff
changeset
|
1728 for (Train *u = v; u != NULL; u = u->Next()) u->UpdateViewport(false, false); |
8667
4e73621c3950
(svn r12332) -Fix (r12331): Invalidate cached data and update image after setting flag.
peter1138 <peter1138@openttd.org>
parents:
8666
diff
changeset
|
1729 |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1730 /* update crossing we were approaching */ |
8342
441cda3cfbdb
(svn r11908) -Fix: update crossing when merging a company, when building a crossing and after loading older savegame
smatz <smatz@openttd.org>
parents:
8334
diff
changeset
|
1731 if (crossing != INVALID_TILE) UpdateLevelCrossing(crossing); |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1732 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1733 /* maybe we are approaching crossing now, after reversal */ |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1734 crossing = TrainApproachingCrossingTile(v); |
8356
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1735 if (crossing != INVALID_TILE) MaybeBarCrossingWithSound(crossing); |
9819
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1736 |
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1737 /* If we are inside a depot after reversing, don't bother with path reserving. */ |
12137
b3c5a6c9146a
(svn r16553) -Codechange: don't use TRACK_BIT_WORMHOLE and TRACK_BIT_DEPOT as bitmasks
smatz <smatz@openttd.org>
parents:
12129
diff
changeset
|
1738 if (v->track == TRACK_BIT_DEPOT) { |
9973
ed2e764e5d6b
(svn r14130) -Fix (r13961) [FS#2248]: Clear the stuck state of a train that is reversing with the first vehicle inside a depot. (michi_cc)
frosch <frosch@openttd.org>
parents:
9941
diff
changeset
|
1739 /* Can't be stuck here as inside a depot is always a safe tile. */ |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
13001
diff
changeset
|
1740 if (HasBit(v->flags, VRF_TRAIN_STUCK)) SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
1741 ClrBit(v->flags, VRF_TRAIN_STUCK); |
9973
ed2e764e5d6b
(svn r14130) -Fix (r13961) [FS#2248]: Clear the stuck state of a train that is reversing with the first vehicle inside a depot. (michi_cc)
frosch <frosch@openttd.org>
parents:
9941
diff
changeset
|
1742 return; |
ed2e764e5d6b
(svn r14130) -Fix (r13961) [FS#2248]: Clear the stuck state of a train that is reversing with the first vehicle inside a depot. (michi_cc)
frosch <frosch@openttd.org>
parents:
9941
diff
changeset
|
1743 } |
9819
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1744 |
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1745 /* TrainExitDir does not always produce the desired dir for depots and |
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1746 * tunnels/bridges that is needed for UpdateSignalsOnSegment. */ |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
1747 DiagDirection dir = TrainExitDir(v->direction, v->track); |
9819
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1748 if (IsRailDepotTile(v->tile) || IsTileType(v->tile, MP_TUNNELBRIDGE)) dir = INVALID_DIAGDIR; |
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1749 |
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1750 if (UpdateSignalsOnSegment(v->tile, dir, v->owner) == SIGSEG_PBS || _settings_game.pf.reserve_paths) { |
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1751 /* If we are currently on a tile with conventional signals, we can't treat the |
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1752 * current tile as a safe tile or we would enter a PBS block without a reservation. */ |
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1753 bool first_tile_okay = !(IsTileType(v->tile, MP_RAILWAY) && |
11976
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
1754 HasSignalOnTrackdir(v->tile, v->GetVehicleTrackdir()) && |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
1755 !IsPbsSignal(GetSignalType(v->tile, FindFirstTrack(v->track)))); |
9819
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1756 |
12502
9472b49c61a1
(svn r16939) -Codechange: s/RailwayStation/RailStation/ to unify the way it's written.
rubidium <rubidium@openttd.org>
parents:
12472
diff
changeset
|
1757 if (IsRailStationTile(v->tile)) SetRailStationPlatformReservation(v->tile, TrackdirToExitdir(v->GetVehicleTrackdir()), true); |
9891
95fb811fb1d3
(svn r14039) -Fix [FS#2217]: reversing an overlength train at a station would try to find a route out and sometimes reset the unload counter making it wait 2.5 years before departing instead of waiting until the train would actually leave the station (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9888
diff
changeset
|
1758 if (TryPathReserve(v, false, first_tile_okay)) { |
9819
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1759 /* Do a look-ahead now in case our current tile was already a safe tile. */ |
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1760 CheckNextTrainTile(v); |
9891
95fb811fb1d3
(svn r14039) -Fix [FS#2217]: reversing an overlength train at a station would try to find a route out and sometimes reset the unload counter making it wait 2.5 years before departing instead of waiting until the train would actually leave the station (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9888
diff
changeset
|
1761 } else if (v->current_order.GetType() != OT_LOADING) { |
95fb811fb1d3
(svn r14039) -Fix [FS#2217]: reversing an overlength train at a station would try to find a route out and sometimes reset the unload counter making it wait 2.5 years before departing instead of waiting until the train would actually leave the station (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9888
diff
changeset
|
1762 /* Do not wait for a way out when we're still loading */ |
95fb811fb1d3
(svn r14039) -Fix [FS#2217]: reversing an overlength train at a station would try to find a route out and sometimes reset the unload counter making it wait 2.5 years before departing instead of waiting until the train would actually leave the station (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9888
diff
changeset
|
1763 MarkTrainAsStuck(v); |
9819
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1764 } |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
1765 } else if (HasBit(v->flags, VRF_TRAIN_STUCK)) { |
10588
1c8fb7b3873a
(svn r14851) -Fix: A train reversing in a non-PBS block can't be stuck.
michi_cc <michi_cc@openttd.org>
parents:
10587
diff
changeset
|
1766 /* A train not inside a PBS block can't be stuck. */ |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
1767 ClrBit(v->flags, VRF_TRAIN_STUCK); |
14213
41b2e7bf03da
(svn r18764) -Fix [FS#3422]: split the (un)load ticks counter and signal wait counter; sometimes they might get into eachother's way
rubidium <rubidium@openttd.org>
parents:
14127
diff
changeset
|
1768 v->wait_counter = 0; |
9819
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1769 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1770 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1771 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
1772 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
1773 * Reverse train. |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1774 * @param tile unused |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1775 * @param flags type of operation |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1776 * @param p1 train to reverse |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1777 * @param p2 if true, reverse a unit in a train (needs to be in a depot) |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13054
diff
changeset
|
1778 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13054
diff
changeset
|
1779 * @return the cost of this operation or an error |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1780 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11085
diff
changeset
|
1781 CommandCost CmdReverseTrainDirection(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1782 { |
12034
aa140a9c419c
(svn r16441) -Codechange: new class SpecializedVehicle used as superclass for all vehicle types
smatz <smatz@openttd.org>
parents:
12032
diff
changeset
|
1783 Train *v = Train::GetIfValid(p1); |
14815
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1784 if (v == NULL) return CMD_ERROR; |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1785 |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1786 CommandCost ret = CheckOwnership(v->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1787 if (ret.Failed()) return ret; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1788 |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
1789 if (p2 != 0) { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1790 /* turn a single unit around */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1791 |
13036
8e2a0e8fa275
(svn r17534) -Codechange: unify the naming of callback masks/flags
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
1792 if (v->IsMultiheaded() || HasBit(EngInfo(v->engine_type)->callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) { |
12351
65732f6bed3f
(svn r16772) -Fix [FS#3019]: don't use the same error message for turning around road vehicles and flipping parts of trains in the depot
rubidium <rubidium@openttd.org>
parents:
12306
diff
changeset
|
1793 return_cmd_error(STR_ERROR_CAN_T_REVERSE_DIRECTION_RAIL_VEHICLE_MULTIPLE_UNITS); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1794 } |
17227
7135c0129418
(svn r21966) -Change [FS#4462]: [NewGRF] Disable the flipping of train engines/wagons in the depot by default for NewGRFs
rubidium <rubidium@openttd.org>
parents:
17223
diff
changeset
|
1795 if (!HasBit(EngInfo(v->engine_type)->misc_flags, EF_RAIL_FLIPS)) return CMD_ERROR; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1796 |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1797 Train *front = v->First(); |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1798 /* make sure the vehicle is stopped in the depot */ |
13933
a71da8c8c5e2
(svn r18465) -Codechange: simplify CheckTrainInDepot and remove some unneeded wrapper functions
rubidium <rubidium@openttd.org>
parents:
13931
diff
changeset
|
1799 if (!front->IsStoppedInDepot()) { |
11730
a39da1e4c1f5
(svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents:
11701
diff
changeset
|
1800 return_cmd_error(STR_ERROR_TRAINS_CAN_ONLY_BE_ALTERED_INSIDE_A_DEPOT); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1801 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1802 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1803 if (flags & DC_EXEC) { |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
1804 ToggleBit(v->flags, VRF_REVERSE_DIRECTION); |
17303
9bb1535a33c0
(svn r22043) -Fix: invalidate the right windows when a part of a train is flipped in the depot
rubidium <rubidium@openttd.org>
parents:
17284
diff
changeset
|
1805 |
17304
aea54f56915d
(svn r22044) -Fix [FS#4493]: update the consist cache when a part of a train is flipped in the depot
rubidium <rubidium@openttd.org>
parents:
17303
diff
changeset
|
1806 front->ConsistChanged(false); |
17303
9bb1535a33c0
(svn r22043) -Fix: invalidate the right windows when a part of a train is flipped in the depot
rubidium <rubidium@openttd.org>
parents:
17284
diff
changeset
|
1807 SetWindowDirty(WC_VEHICLE_DEPOT, front->tile); |
9bb1535a33c0
(svn r22043) -Fix: invalidate the right windows when a part of a train is flipped in the depot
rubidium <rubidium@openttd.org>
parents:
17284
diff
changeset
|
1808 SetWindowDirty(WC_VEHICLE_DETAILS, front->index); |
9bb1535a33c0
(svn r22043) -Fix: invalidate the right windows when a part of a train is flipped in the depot
rubidium <rubidium@openttd.org>
parents:
17284
diff
changeset
|
1809 SetWindowDirty(WC_VEHICLE_VIEW, front->index); |
9bb1535a33c0
(svn r22043) -Fix: invalidate the right windows when a part of a train is flipped in the depot
rubidium <rubidium@openttd.org>
parents:
17284
diff
changeset
|
1810 SetWindowClassesDirty(WC_TRAINS_LIST); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1811 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1812 } else { |
7476
a24293df92f5
(svn r10983) -Codechange: use vehstatus & VS_CRASHED instead of some other "methods" custom to each vehicle to determine whether the vehicle is crashed.
rubidium <rubidium@openttd.org>
parents:
7425
diff
changeset
|
1813 /* turn the whole train around */ |
12082
d092f17a921d
(svn r16491) -Codechange: Added parentheses around bitwise operators for code style.
alberth <alberth@openttd.org>
parents:
12073
diff
changeset
|
1814 if ((v->vehstatus & VS_CRASHED) || v->breakdown_ctr != 0) return CMD_ERROR; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1815 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1816 if (flags & DC_EXEC) { |
11094
6a6a59f20daf
(svn r15439) -Fix [FS#2626]: call Vehicle::LeaveStation() before reversing overlength loading train (station triggers were missed, PBS reservation could cause crash)
smatz <smatz@openttd.org>
parents:
11090
diff
changeset
|
1817 /* Properly leave the station if we are loading and won't be loading anymore */ |
6a6a59f20daf
(svn r15439) -Fix [FS#2626]: call Vehicle::LeaveStation() before reversing overlength loading train (station triggers were missed, PBS reservation could cause crash)
smatz <smatz@openttd.org>
parents:
11090
diff
changeset
|
1818 if (v->current_order.IsType(OT_LOADING)) { |
6a6a59f20daf
(svn r15439) -Fix [FS#2626]: call Vehicle::LeaveStation() before reversing overlength loading train (station triggers were missed, PBS reservation could cause crash)
smatz <smatz@openttd.org>
parents:
11090
diff
changeset
|
1819 const Vehicle *last = v; |
6a6a59f20daf
(svn r15439) -Fix [FS#2626]: call Vehicle::LeaveStation() before reversing overlength loading train (station triggers were missed, PBS reservation could cause crash)
smatz <smatz@openttd.org>
parents:
11090
diff
changeset
|
1820 while (last->Next() != NULL) last = last->Next(); |
6a6a59f20daf
(svn r15439) -Fix [FS#2626]: call Vehicle::LeaveStation() before reversing overlength loading train (station triggers were missed, PBS reservation could cause crash)
smatz <smatz@openttd.org>
parents:
11090
diff
changeset
|
1821 |
6a6a59f20daf
(svn r15439) -Fix [FS#2626]: call Vehicle::LeaveStation() before reversing overlength loading train (station triggers were missed, PBS reservation could cause crash)
smatz <smatz@openttd.org>
parents:
11090
diff
changeset
|
1822 /* not a station || different station --> leave the station */ |
6a6a59f20daf
(svn r15439) -Fix [FS#2626]: call Vehicle::LeaveStation() before reversing overlength loading train (station triggers were missed, PBS reservation could cause crash)
smatz <smatz@openttd.org>
parents:
11090
diff
changeset
|
1823 if (!IsTileType(last->tile, MP_STATION) || GetStationIndex(last->tile) != GetStationIndex(v->tile)) { |
6a6a59f20daf
(svn r15439) -Fix [FS#2626]: call Vehicle::LeaveStation() before reversing overlength loading train (station triggers were missed, PBS reservation could cause crash)
smatz <smatz@openttd.org>
parents:
11090
diff
changeset
|
1824 v->LeaveStation(); |
6a6a59f20daf
(svn r15439) -Fix [FS#2626]: call Vehicle::LeaveStation() before reversing overlength loading train (station triggers were missed, PBS reservation could cause crash)
smatz <smatz@openttd.org>
parents:
11090
diff
changeset
|
1825 } |
6a6a59f20daf
(svn r15439) -Fix [FS#2626]: call Vehicle::LeaveStation() before reversing overlength loading train (station triggers were missed, PBS reservation could cause crash)
smatz <smatz@openttd.org>
parents:
11090
diff
changeset
|
1826 } |
6a6a59f20daf
(svn r15439) -Fix [FS#2626]: call Vehicle::LeaveStation() before reversing overlength loading train (station triggers were missed, PBS reservation could cause crash)
smatz <smatz@openttd.org>
parents:
11090
diff
changeset
|
1827 |
13977
bb2258bdc43d
(svn r18515) -Change: make it visible when you're to pass the next signal on danger and possible to cancel it
rubidium <rubidium@openttd.org>
parents:
13958
diff
changeset
|
1828 /* We cancel any 'skip signal at dangers' here */ |
15362
834b4f9842c2
(svn r20005) -Codechange: Enumify force_proceed.
frosch <frosch@openttd.org>
parents:
15351
diff
changeset
|
1829 v->force_proceed = TFP_NONE; |
13977
bb2258bdc43d
(svn r18515) -Change: make it visible when you're to pass the next signal on danger and possible to cancel it
rubidium <rubidium@openttd.org>
parents:
13958
diff
changeset
|
1830 SetWindowDirty(WC_VEHICLE_VIEW, v->index); |
bb2258bdc43d
(svn r18515) -Change: make it visible when you're to pass the next signal on danger and possible to cancel it
rubidium <rubidium@openttd.org>
parents:
13958
diff
changeset
|
1831 |
14406
5f93639271ee
(svn r18963) -Codechange: Give AccelerationModel a generical name.
terkhen <terkhen@openttd.org>
parents:
14384
diff
changeset
|
1832 if (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL && v->cur_speed != 0) { |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
1833 ToggleBit(v->flags, VRF_REVERSING); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1834 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1835 v->cur_speed = 0; |
17172
679a25d71a9d
(svn r21911) -Codechange: move tcache.last_speed to gcache.last_speed and make SetLastSpeed a function of GroundVehicle
rubidium <rubidium@openttd.org>
parents:
17165
diff
changeset
|
1836 v->SetLastSpeed(); |
10176
71daf486081d
(svn r14371) -Fix [FS#2313]: loading indicator didn't stay with the front engine when turning a train in a station.
rubidium <rubidium@openttd.org>
parents:
10173
diff
changeset
|
1837 HideFillingPercent(&v->fill_percent_te_id); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1838 ReverseTrainDirection(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1839 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1840 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1841 } |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
1842 return CommandCost(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1843 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1844 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
1845 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
1846 * Force a train through a red signal |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1847 * @param tile unused |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1848 * @param flags type of operation |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1849 * @param p1 train to ignore the red signal |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1850 * @param p2 unused |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13054
diff
changeset
|
1851 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13054
diff
changeset
|
1852 * @return the cost of this operation or an error |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1853 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11085
diff
changeset
|
1854 CommandCost CmdForceTrainProceed(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1855 { |
12034
aa140a9c419c
(svn r16441) -Codechange: new class SpecializedVehicle used as superclass for all vehicle types
smatz <smatz@openttd.org>
parents:
12032
diff
changeset
|
1856 Train *t = Train::GetIfValid(p1); |
14815
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1857 if (t == NULL) return CMD_ERROR; |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1858 |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1859 CommandCost ret = CheckOwnership(t->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1860 if (ret.Failed()) return ret; |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1861 |
12034
aa140a9c419c
(svn r16441) -Codechange: new class SpecializedVehicle used as superclass for all vehicle types
smatz <smatz@openttd.org>
parents:
12032
diff
changeset
|
1862 |
13977
bb2258bdc43d
(svn r18515) -Change: make it visible when you're to pass the next signal on danger and possible to cancel it
rubidium <rubidium@openttd.org>
parents:
13958
diff
changeset
|
1863 if (flags & DC_EXEC) { |
bb2258bdc43d
(svn r18515) -Change: make it visible when you're to pass the next signal on danger and possible to cancel it
rubidium <rubidium@openttd.org>
parents:
13958
diff
changeset
|
1864 /* If we are forced to proceed, cancel that order. |
bb2258bdc43d
(svn r18515) -Change: make it visible when you're to pass the next signal on danger and possible to cancel it
rubidium <rubidium@openttd.org>
parents:
13958
diff
changeset
|
1865 * If we are marked stuck we would want to force the train |
bb2258bdc43d
(svn r18515) -Change: make it visible when you're to pass the next signal on danger and possible to cancel it
rubidium <rubidium@openttd.org>
parents:
13958
diff
changeset
|
1866 * to proceed to the next signal. In the other cases we |
bb2258bdc43d
(svn r18515) -Change: make it visible when you're to pass the next signal on danger and possible to cancel it
rubidium <rubidium@openttd.org>
parents:
13958
diff
changeset
|
1867 * would like to pass the signal at danger and run till the |
bb2258bdc43d
(svn r18515) -Change: make it visible when you're to pass the next signal on danger and possible to cancel it
rubidium <rubidium@openttd.org>
parents:
13958
diff
changeset
|
1868 * next signal we encounter. */ |
15362
834b4f9842c2
(svn r20005) -Codechange: Enumify force_proceed.
frosch <frosch@openttd.org>
parents:
15351
diff
changeset
|
1869 t->force_proceed = t->force_proceed == TFP_SIGNAL ? TFP_NONE : HasBit(t->flags, VRF_TRAIN_STUCK) || t->IsInDepot() ? TFP_STUCK : TFP_SIGNAL; |
13977
bb2258bdc43d
(svn r18515) -Change: make it visible when you're to pass the next signal on danger and possible to cancel it
rubidium <rubidium@openttd.org>
parents:
13958
diff
changeset
|
1870 SetWindowDirty(WC_VEHICLE_VIEW, t->index); |
bb2258bdc43d
(svn r18515) -Change: make it visible when you're to pass the next signal on danger and possible to cancel it
rubidium <rubidium@openttd.org>
parents:
13958
diff
changeset
|
1871 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1872 |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
1873 return CommandCost(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1874 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1875 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
1876 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
1877 * returns the tile of a depot to goto to. The given vehicle must not be |
15623
c62577640878
(svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents:
15620
diff
changeset
|
1878 * crashed! |
c62577640878
(svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents:
15620
diff
changeset
|
1879 */ |
13842
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
1880 static FindDepotData FindClosestTrainDepot(Train *v, int max_distance) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1881 { |
6150 | 1882 assert(!(v->vehstatus & VS_CRASHED)); |
1883 | |
13842
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
1884 if (IsRailDepotTile(v->tile)) return FindDepotData(v->tile, 0); |
9934
26c9719c4ae0
(svn r14089) -Fix [FS#2219]: trains not being able to find a route to a depot when the front is already in the depot.
rubidium <rubidium@openttd.org>
parents:
9928
diff
changeset
|
1885 |
9810
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
1886 PBSTileInfo origin = FollowTrainReservation(v); |
13842
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
1887 if (IsRailDepotTile(origin.tile)) return FindDepotData(origin.tile, 0); |
9934
26c9719c4ae0
(svn r14089) -Fix [FS#2219]: trains not being able to find a route to a depot when the front is already in the depot.
rubidium <rubidium@openttd.org>
parents:
9928
diff
changeset
|
1888 |
13833
ad09d18a3e34
(svn r18362) -Cleanup: remove OPF for RVs and NTP to clean up lots of code and simplify some things for the future
rubidium <rubidium@openttd.org>
parents:
13832
diff
changeset
|
1889 switch (_settings_game.pf.pathfinder_for_trains) { |
14031
c603550031d4
(svn r18574) -Fix [FS#3392] (r18481): manually sending trains and RVs to depots didn't quite work
rubidium <rubidium@openttd.org>
parents:
13977
diff
changeset
|
1890 case VPF_NPF: return NPFTrainFindNearestDepot(v, max_distance); |
c603550031d4
(svn r18574) -Fix [FS#3392] (r18481): manually sending trains and RVs to depots didn't quite work
rubidium <rubidium@openttd.org>
parents:
13977
diff
changeset
|
1891 case VPF_YAPF: return YapfTrainFindNearestDepot(v, max_distance); |
13842
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
1892 |
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
1893 default: NOT_REACHED(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1894 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1895 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1896 |
8890
b1d45af72e04
(svn r12657) -Codechange: add 'FindClosestDepot' to the vehicle class.
rubidium <rubidium@openttd.org>
parents:
8862
diff
changeset
|
1897 bool Train::FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse) |
b1d45af72e04
(svn r12657) -Codechange: add 'FindClosestDepot' to the vehicle class.
rubidium <rubidium@openttd.org>
parents:
8862
diff
changeset
|
1898 { |
13842
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
1899 FindDepotData tfdd = FindClosestTrainDepot(this, 0); |
10236
59398a628f10
(svn r14464) -Codechange: replace (uint)-1 with UINT_MAX (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10214
diff
changeset
|
1900 if (tfdd.best_length == UINT_MAX) return false; |
8890
b1d45af72e04
(svn r12657) -Codechange: add 'FindClosestDepot' to the vehicle class.
rubidium <rubidium@openttd.org>
parents:
8862
diff
changeset
|
1901 |
b1d45af72e04
(svn r12657) -Codechange: add 'FindClosestDepot' to the vehicle class.
rubidium <rubidium@openttd.org>
parents:
8862
diff
changeset
|
1902 if (location != NULL) *location = tfdd.tile; |
13001
c2298b1d3f83
(svn r17495) -Codechange: replace 'Depot::Get(GetDepotIndex(tile))->index' with GetDepotIndex(tile)
rubidium <rubidium@openttd.org>
parents:
12860
diff
changeset
|
1903 if (destination != NULL) *destination = GetDepotIndex(tfdd.tile); |
8890
b1d45af72e04
(svn r12657) -Codechange: add 'FindClosestDepot' to the vehicle class.
rubidium <rubidium@openttd.org>
parents:
8862
diff
changeset
|
1904 if (reverse != NULL) *reverse = tfdd.reverse; |
b1d45af72e04
(svn r12657) -Codechange: add 'FindClosestDepot' to the vehicle class.
rubidium <rubidium@openttd.org>
parents:
8862
diff
changeset
|
1905 |
b1d45af72e04
(svn r12657) -Codechange: add 'FindClosestDepot' to the vehicle class.
rubidium <rubidium@openttd.org>
parents:
8862
diff
changeset
|
1906 return true; |
b1d45af72e04
(svn r12657) -Codechange: add 'FindClosestDepot' to the vehicle class.
rubidium <rubidium@openttd.org>
parents:
8862
diff
changeset
|
1907 } |
b1d45af72e04
(svn r12657) -Codechange: add 'FindClosestDepot' to the vehicle class.
rubidium <rubidium@openttd.org>
parents:
8862
diff
changeset
|
1908 |
8550
14ecde7f8abf
(svn r12128) -Codechange: Replace last use of TrainPlayLeaveStationSound(v) with v->PlayLeaveStationSound(), and remove wrapper function.
peter1138 <peter1138@openttd.org>
parents:
8510
diff
changeset
|
1909 void Train::PlayLeaveStationSound() const |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1910 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1911 static const SoundFx sfx[] = { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1912 SND_04_TRAIN, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1913 SND_0A_TRAIN_HORN, |
6586
245129bf2b8d
(svn r9800) -Codechange: play sound effects based on the engine class, not the rail type (mart3p).
rubidium <rubidium@openttd.org>
parents:
6580
diff
changeset
|
1914 SND_0A_TRAIN_HORN, |
245129bf2b8d
(svn r9800) -Codechange: play sound effects based on the engine class, not the rail type (mart3p).
rubidium <rubidium@openttd.org>
parents:
6580
diff
changeset
|
1915 SND_47_MAGLEV_2, |
245129bf2b8d
(svn r9800) -Codechange: play sound effects based on the engine class, not the rail type (mart3p).
rubidium <rubidium@openttd.org>
parents:
6580
diff
changeset
|
1916 SND_41_MAGLEV |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1917 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1918 |
8550
14ecde7f8abf
(svn r12128) -Codechange: Replace last use of TrainPlayLeaveStationSound(v) with v->PlayLeaveStationSound(), and remove wrapper function.
peter1138 <peter1138@openttd.org>
parents:
8510
diff
changeset
|
1919 if (PlayVehicleSound(this, VSE_START)) return; |
14ecde7f8abf
(svn r12128) -Codechange: Replace last use of TrainPlayLeaveStationSound(v) with v->PlayLeaveStationSound(), and remove wrapper function.
peter1138 <peter1138@openttd.org>
parents:
8510
diff
changeset
|
1920 |
14ecde7f8abf
(svn r12128) -Codechange: Replace last use of TrainPlayLeaveStationSound(v) with v->PlayLeaveStationSound(), and remove wrapper function.
peter1138 <peter1138@openttd.org>
parents:
8510
diff
changeset
|
1921 EngineID engtype = this->engine_type; |
14ecde7f8abf
(svn r12128) -Codechange: Replace last use of TrainPlayLeaveStationSound(v) with v->PlayLeaveStationSound(), and remove wrapper function.
peter1138 <peter1138@openttd.org>
parents:
8510
diff
changeset
|
1922 SndPlayVehicleFx(sfx[RailVehInfo(engtype)->engclass], this); |
6593
431c5039b1f1
(svn r9807) -Codechange: unify playing of sound when vehicle has been loaded and leaves the station.
rubidium <rubidium@openttd.org>
parents:
6592
diff
changeset
|
1923 } |
431c5039b1f1
(svn r9807) -Codechange: unify playing of sound when vehicle has been loaded and leaves the station.
rubidium <rubidium@openttd.org>
parents:
6592
diff
changeset
|
1924 |
9816
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1925 /** Check if the train is on the last reserved tile and try to extend the path then. */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1926 static void CheckNextTrainTile(Train *v) |
9816
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1927 { |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1928 /* Don't do any look-ahead if path_backoff_interval is 255. */ |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1929 if (_settings_game.pf.path_backoff_interval == 255) return; |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1930 |
15156
46dfa3614ec1
(svn r19785) -Codechange: reorder/rework the checks for CheckNextTrainTile a bit, causing the whole function to be a few percent faster and hopefully better to understand
rubidium <rubidium@openttd.org>
parents:
15155
diff
changeset
|
1931 /* Exit if we are inside a depot. */ |
46dfa3614ec1
(svn r19785) -Codechange: reorder/rework the checks for CheckNextTrainTile a bit, causing the whole function to be a few percent faster and hopefully better to understand
rubidium <rubidium@openttd.org>
parents:
15155
diff
changeset
|
1932 if (v->track == TRACK_BIT_DEPOT) return; |
46dfa3614ec1
(svn r19785) -Codechange: reorder/rework the checks for CheckNextTrainTile a bit, causing the whole function to be a few percent faster and hopefully better to understand
rubidium <rubidium@openttd.org>
parents:
15155
diff
changeset
|
1933 |
46dfa3614ec1
(svn r19785) -Codechange: reorder/rework the checks for CheckNextTrainTile a bit, causing the whole function to be a few percent faster and hopefully better to understand
rubidium <rubidium@openttd.org>
parents:
15155
diff
changeset
|
1934 switch (v->current_order.GetType()) { |
46dfa3614ec1
(svn r19785) -Codechange: reorder/rework the checks for CheckNextTrainTile a bit, causing the whole function to be a few percent faster and hopefully better to understand
rubidium <rubidium@openttd.org>
parents:
15155
diff
changeset
|
1935 /* Exit if we reached our destination depot. */ |
46dfa3614ec1
(svn r19785) -Codechange: reorder/rework the checks for CheckNextTrainTile a bit, causing the whole function to be a few percent faster and hopefully better to understand
rubidium <rubidium@openttd.org>
parents:
15155
diff
changeset
|
1936 case OT_GOTO_DEPOT: |
46dfa3614ec1
(svn r19785) -Codechange: reorder/rework the checks for CheckNextTrainTile a bit, causing the whole function to be a few percent faster and hopefully better to understand
rubidium <rubidium@openttd.org>
parents:
15155
diff
changeset
|
1937 if (v->tile == v->dest_tile) return; |
46dfa3614ec1
(svn r19785) -Codechange: reorder/rework the checks for CheckNextTrainTile a bit, causing the whole function to be a few percent faster and hopefully better to understand
rubidium <rubidium@openttd.org>
parents:
15155
diff
changeset
|
1938 break; |
46dfa3614ec1
(svn r19785) -Codechange: reorder/rework the checks for CheckNextTrainTile a bit, causing the whole function to be a few percent faster and hopefully better to understand
rubidium <rubidium@openttd.org>
parents:
15155
diff
changeset
|
1939 |
46dfa3614ec1
(svn r19785) -Codechange: reorder/rework the checks for CheckNextTrainTile a bit, causing the whole function to be a few percent faster and hopefully better to understand
rubidium <rubidium@openttd.org>
parents:
15155
diff
changeset
|
1940 case OT_GOTO_WAYPOINT: |
46dfa3614ec1
(svn r19785) -Codechange: reorder/rework the checks for CheckNextTrainTile a bit, causing the whole function to be a few percent faster and hopefully better to understand
rubidium <rubidium@openttd.org>
parents:
15155
diff
changeset
|
1941 /* If we reached our waypoint, make sure we see that. */ |
46dfa3614ec1
(svn r19785) -Codechange: reorder/rework the checks for CheckNextTrainTile a bit, causing the whole function to be a few percent faster and hopefully better to understand
rubidium <rubidium@openttd.org>
parents:
15155
diff
changeset
|
1942 if (IsRailWaypointTile(v->tile) && GetStationIndex(v->tile) == v->current_order.GetDestination()) ProcessOrders(v); |
46dfa3614ec1
(svn r19785) -Codechange: reorder/rework the checks for CheckNextTrainTile a bit, causing the whole function to be a few percent faster and hopefully better to understand
rubidium <rubidium@openttd.org>
parents:
15155
diff
changeset
|
1943 break; |
46dfa3614ec1
(svn r19785) -Codechange: reorder/rework the checks for CheckNextTrainTile a bit, causing the whole function to be a few percent faster and hopefully better to understand
rubidium <rubidium@openttd.org>
parents:
15155
diff
changeset
|
1944 |
46dfa3614ec1
(svn r19785) -Codechange: reorder/rework the checks for CheckNextTrainTile a bit, causing the whole function to be a few percent faster and hopefully better to understand
rubidium <rubidium@openttd.org>
parents:
15155
diff
changeset
|
1945 case OT_NOTHING: |
46dfa3614ec1
(svn r19785) -Codechange: reorder/rework the checks for CheckNextTrainTile a bit, causing the whole function to be a few percent faster and hopefully better to understand
rubidium <rubidium@openttd.org>
parents:
15155
diff
changeset
|
1946 case OT_LEAVESTATION: |
46dfa3614ec1
(svn r19785) -Codechange: reorder/rework the checks for CheckNextTrainTile a bit, causing the whole function to be a few percent faster and hopefully better to understand
rubidium <rubidium@openttd.org>
parents:
15155
diff
changeset
|
1947 case OT_LOADING: |
46dfa3614ec1
(svn r19785) -Codechange: reorder/rework the checks for CheckNextTrainTile a bit, causing the whole function to be a few percent faster and hopefully better to understand
rubidium <rubidium@openttd.org>
parents:
15155
diff
changeset
|
1948 /* Exit if the current order doesn't have a destination, but the train has orders. */ |
46dfa3614ec1
(svn r19785) -Codechange: reorder/rework the checks for CheckNextTrainTile a bit, causing the whole function to be a few percent faster and hopefully better to understand
rubidium <rubidium@openttd.org>
parents:
15155
diff
changeset
|
1949 if (v->GetNumOrders() > 0) return; |
46dfa3614ec1
(svn r19785) -Codechange: reorder/rework the checks for CheckNextTrainTile a bit, causing the whole function to be a few percent faster and hopefully better to understand
rubidium <rubidium@openttd.org>
parents:
15155
diff
changeset
|
1950 break; |
46dfa3614ec1
(svn r19785) -Codechange: reorder/rework the checks for CheckNextTrainTile a bit, causing the whole function to be a few percent faster and hopefully better to understand
rubidium <rubidium@openttd.org>
parents:
15155
diff
changeset
|
1951 |
46dfa3614ec1
(svn r19785) -Codechange: reorder/rework the checks for CheckNextTrainTile a bit, causing the whole function to be a few percent faster and hopefully better to understand
rubidium <rubidium@openttd.org>
parents:
15155
diff
changeset
|
1952 default: |
46dfa3614ec1
(svn r19785) -Codechange: reorder/rework the checks for CheckNextTrainTile a bit, causing the whole function to be a few percent faster and hopefully better to understand
rubidium <rubidium@openttd.org>
parents:
15155
diff
changeset
|
1953 break; |
46dfa3614ec1
(svn r19785) -Codechange: reorder/rework the checks for CheckNextTrainTile a bit, causing the whole function to be a few percent faster and hopefully better to understand
rubidium <rubidium@openttd.org>
parents:
15155
diff
changeset
|
1954 } |
9816
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1955 /* Exit if we are on a station tile and are going to stop. */ |
12502
9472b49c61a1
(svn r16939) -Codechange: s/RailwayStation/RailStation/ to unify the way it's written.
rubidium <rubidium@openttd.org>
parents:
12472
diff
changeset
|
1956 if (IsRailStationTile(v->tile) && v->current_order.ShouldStopAtStation(v, GetStationIndex(v->tile))) return; |
9816
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1957 |
11976
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
1958 Trackdir td = v->GetVehicleTrackdir(); |
9816
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1959 |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1960 /* On a tile with a red non-pbs signal, don't look ahead. */ |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1961 if (IsTileType(v->tile, MP_RAILWAY) && HasSignalOnTrackdir(v->tile, td) && |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1962 !IsPbsSignal(GetSignalType(v->tile, TrackdirToTrack(td))) && |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1963 GetSignalStateByTrackdir(v->tile, td) == SIGNAL_STATE_RED) return; |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1964 |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1965 CFollowTrackRail ft(v); |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1966 if (!ft.Follow(v->tile, td)) return; |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1967 |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1968 if (!HasReservedTracks(ft.m_new_tile, TrackdirBitsToTrackBits(ft.m_new_td_bits))) { |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1969 /* Next tile is not reserved. */ |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1970 if (KillFirstBit(ft.m_new_td_bits) == TRACKDIR_BIT_NONE) { |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1971 if (HasPbsSignalOnTrackdir(ft.m_new_tile, FindFirstTrackdir(ft.m_new_td_bits))) { |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1972 /* If the next tile is a PBS signal, try to make a reservation. */ |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1973 TrackBits tracks = TrackdirBitsToTrackBits(ft.m_new_td_bits); |
13833
ad09d18a3e34
(svn r18362) -Cleanup: remove OPF for RVs and NTP to clean up lots of code and simplify some things for the future
rubidium <rubidium@openttd.org>
parents:
13832
diff
changeset
|
1974 if (_settings_game.pf.forbid_90_deg) { |
9816
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1975 tracks &= ~TrackCrossesTracks(TrackdirToTrack(ft.m_old_td)); |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1976 } |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1977 ChooseTrainTrack(v, ft.m_new_tile, ft.m_exitdir, tracks, false, NULL, false); |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1978 } |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1979 } |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1980 } |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1981 } |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
1982 |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1983 static bool CheckTrainStayInDepot(Train *v) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1984 { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1985 /* bail out if not all wagons are in the same depot or not in a depot at all */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1986 for (const Train *u = v; u != NULL; u = u->Next()) { |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
1987 if (u->track != TRACK_BIT_DEPOT || u->tile != v->tile) return false; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1988 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1989 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1990 /* if the train got no power, then keep it in the depot */ |
16785
775f357828e3
(svn r21518) -Codechange: Rename AccelerationCache to GroundVehicleCache.
terkhen <terkhen@openttd.org>
parents:
16776
diff
changeset
|
1991 if (v->gcache.cached_power == 0) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1992 v->vehstatus |= VS_STOPPED; |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
13001
diff
changeset
|
1993 SetWindowDirty(WC_VEHICLE_DEPOT, v->tile); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1994 return true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1995 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1996 |
9818
14edde00b131
(svn r13960) -Codechange [YAPP]: Reserve a path when exiting a depot into a PBS block. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9817
diff
changeset
|
1997 SigSegState seg_state; |
14edde00b131
(svn r13960) -Codechange [YAPP]: Reserve a path when exiting a depot into a PBS block. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9817
diff
changeset
|
1998 |
15362
834b4f9842c2
(svn r20005) -Codechange: Enumify force_proceed.
frosch <frosch@openttd.org>
parents:
15351
diff
changeset
|
1999 if (v->force_proceed == TFP_NONE) { |
9818
14edde00b131
(svn r13960) -Codechange [YAPP]: Reserve a path when exiting a depot into a PBS block. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9817
diff
changeset
|
2000 /* force proceed was not pressed */ |
14213
41b2e7bf03da
(svn r18764) -Fix [FS#3422]: split the (un)load ticks counter and signal wait counter; sometimes they might get into eachother's way
rubidium <rubidium@openttd.org>
parents:
14127
diff
changeset
|
2001 if (++v->wait_counter < 37) { |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
13001
diff
changeset
|
2002 SetWindowClassesDirty(WC_TRAINS_LIST); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2003 return true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2004 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2005 |
14213
41b2e7bf03da
(svn r18764) -Fix [FS#3422]: split the (un)load ticks counter and signal wait counter; sometimes they might get into eachother's way
rubidium <rubidium@openttd.org>
parents:
14127
diff
changeset
|
2006 v->wait_counter = 0; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2007 |
9818
14edde00b131
(svn r13960) -Codechange [YAPP]: Reserve a path when exiting a depot into a PBS block. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9817
diff
changeset
|
2008 seg_state = _settings_game.pf.reserve_paths ? SIGSEG_PBS : UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR, v->owner); |
12471
c0587ce9da72
(svn r16908) -Codechange: s/DepotWaypointReservation/DepotReservation/
rubidium <rubidium@openttd.org>
parents:
12470
diff
changeset
|
2009 if (seg_state == SIGSEG_FULL || HasDepotReservation(v->tile)) { |
9818
14edde00b131
(svn r13960) -Codechange [YAPP]: Reserve a path when exiting a depot into a PBS block. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9817
diff
changeset
|
2010 /* Full and no PBS signal in block or depot reserved, can't exit. */ |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
13001
diff
changeset
|
2011 SetWindowClassesDirty(WC_TRAINS_LIST); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2012 return true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2013 } |
9818
14edde00b131
(svn r13960) -Codechange [YAPP]: Reserve a path when exiting a depot into a PBS block. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9817
diff
changeset
|
2014 } else { |
14edde00b131
(svn r13960) -Codechange [YAPP]: Reserve a path when exiting a depot into a PBS block. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9817
diff
changeset
|
2015 seg_state = _settings_game.pf.reserve_paths ? SIGSEG_PBS : UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR, v->owner); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2016 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2017 |
11920
06375a564163
(svn r16322) -Fix [FS#2873]: trains could get stuck in a depot when they wanted to go to the same depot again.
rubidium <rubidium@openttd.org>
parents:
11903
diff
changeset
|
2018 /* We are leaving a depot, but have to go to the exact same one; re-enter */ |
12155
884d20bcc977
(svn r16571) -Fix [FS#2974](r16322): in some cases, train could be stuck in depot
smatz <smatz@openttd.org>
parents:
12137
diff
changeset
|
2019 if (v->current_order.IsType(OT_GOTO_DEPOT) && v->tile == v->dest_tile) { |
11920
06375a564163
(svn r16322) -Fix [FS#2873]: trains could get stuck in a depot when they wanted to go to the same depot again.
rubidium <rubidium@openttd.org>
parents:
11903
diff
changeset
|
2020 /* We need to have a reservation for this to work. */ |
12471
c0587ce9da72
(svn r16908) -Codechange: s/DepotWaypointReservation/DepotReservation/
rubidium <rubidium@openttd.org>
parents:
12470
diff
changeset
|
2021 if (HasDepotReservation(v->tile)) return true; |
c0587ce9da72
(svn r16908) -Codechange: s/DepotWaypointReservation/DepotReservation/
rubidium <rubidium@openttd.org>
parents:
12470
diff
changeset
|
2022 SetDepotReservation(v->tile, true); |
11920
06375a564163
(svn r16322) -Fix [FS#2873]: trains could get stuck in a depot when they wanted to go to the same depot again.
rubidium <rubidium@openttd.org>
parents:
11903
diff
changeset
|
2023 VehicleEnterDepot(v); |
06375a564163
(svn r16322) -Fix [FS#2873]: trains could get stuck in a depot when they wanted to go to the same depot again.
rubidium <rubidium@openttd.org>
parents:
11903
diff
changeset
|
2024 return true; |
06375a564163
(svn r16322) -Fix [FS#2873]: trains could get stuck in a depot when they wanted to go to the same depot again.
rubidium <rubidium@openttd.org>
parents:
11903
diff
changeset
|
2025 } |
06375a564163
(svn r16322) -Fix [FS#2873]: trains could get stuck in a depot when they wanted to go to the same depot again.
rubidium <rubidium@openttd.org>
parents:
11903
diff
changeset
|
2026 |
9818
14edde00b131
(svn r13960) -Codechange [YAPP]: Reserve a path when exiting a depot into a PBS block. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9817
diff
changeset
|
2027 /* Only leave when we can reserve a path to our destination. */ |
15362
834b4f9842c2
(svn r20005) -Codechange: Enumify force_proceed.
frosch <frosch@openttd.org>
parents:
15351
diff
changeset
|
2028 if (seg_state == SIGSEG_PBS && !TryPathReserve(v) && v->force_proceed == TFP_NONE) { |
9818
14edde00b131
(svn r13960) -Codechange [YAPP]: Reserve a path when exiting a depot into a PBS block. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9817
diff
changeset
|
2029 /* No path and no force proceed. */ |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
13001
diff
changeset
|
2030 SetWindowClassesDirty(WC_TRAINS_LIST); |
9818
14edde00b131
(svn r13960) -Codechange [YAPP]: Reserve a path when exiting a depot into a PBS block. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9817
diff
changeset
|
2031 MarkTrainAsStuck(v); |
14edde00b131
(svn r13960) -Codechange [YAPP]: Reserve a path when exiting a depot into a PBS block. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9817
diff
changeset
|
2032 return true; |
14edde00b131
(svn r13960) -Codechange [YAPP]: Reserve a path when exiting a depot into a PBS block. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9817
diff
changeset
|
2033 } |
14edde00b131
(svn r13960) -Codechange [YAPP]: Reserve a path when exiting a depot into a PBS block. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9817
diff
changeset
|
2034 |
12471
c0587ce9da72
(svn r16908) -Codechange: s/DepotWaypointReservation/DepotReservation/
rubidium <rubidium@openttd.org>
parents:
12470
diff
changeset
|
2035 SetDepotReservation(v->tile, true); |
9818
14edde00b131
(svn r13960) -Codechange [YAPP]: Reserve a path when exiting a depot into a PBS block. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9817
diff
changeset
|
2036 if (_settings_client.gui.show_track_reservation) MarkTileDirtyByTile(v->tile); |
14edde00b131
(svn r13960) -Codechange [YAPP]: Reserve a path when exiting a depot into a PBS block. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9817
diff
changeset
|
2037 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2038 VehicleServiceInDepot(v); |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
13001
diff
changeset
|
2039 SetWindowClassesDirty(WC_TRAINS_LIST); |
8550
14ecde7f8abf
(svn r12128) -Codechange: Replace last use of TrainPlayLeaveStationSound(v) with v->PlayLeaveStationSound(), and remove wrapper function.
peter1138 <peter1138@openttd.org>
parents:
8510
diff
changeset
|
2040 v->PlayLeaveStationSound(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2041 |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
2042 v->track = TRACK_BIT_X; |
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
2043 if (v->direction & 2) v->track = TRACK_BIT_Y; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2044 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2045 v->vehstatus &= ~VS_HIDDEN; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2046 v->cur_speed = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2047 |
6558
2fc024ee8217
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium <rubidium@openttd.org>
parents:
6554
diff
changeset
|
2048 v->UpdateDeltaXY(v->direction); |
7134
e1c4f52f82cd
(svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium <rubidium@openttd.org>
parents:
7109
diff
changeset
|
2049 v->cur_image = v->GetImage(v->direction); |
11326
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11268
diff
changeset
|
2050 VehicleMove(v, false); |
8300
ae1baac75172
(svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz <smatz@openttd.org>
parents:
8283
diff
changeset
|
2051 UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR, v->owner); |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
2052 v->UpdateAcceleration(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2053 InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2054 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2055 return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2056 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2057 |
9809
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
2058 /** Clear the reservation of a tile that was just left by a wagon on track_dir. */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
2059 static void ClearPathReservation(const Train *v, TileIndex tile, Trackdir track_dir) |
9809
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
2060 { |
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
2061 DiagDirection dir = TrackdirToExitdir(track_dir); |
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
2062 |
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
2063 if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
2064 /* Are we just leaving a tunnel/bridge? */ |
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
2065 if (GetTunnelBridgeDirection(tile) == ReverseDiagDir(dir)) { |
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
2066 TileIndex end = GetOtherTunnelBridgeEnd(tile); |
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
2067 |
14707
ed6ca7f84893
(svn r19291) -Codechange: Rename HasVehicleOnTunnelBridge() to TunnelBridgeIsFree() and return a CommandCost status.
alberth <alberth@openttd.org>
parents:
14702
diff
changeset
|
2068 if (TunnelBridgeIsFree(tile, end, v).Succeeded()) { |
10103
9a884d182149
(svn r14285) -Fix [FS#2263]: A train inside a wormhole could free the reservation of another train inside the wormhole.
michi_cc <michi_cc@openttd.org>
parents:
10102
diff
changeset
|
2069 /* Free the reservation only if no other train is on the tiles. */ |
9a884d182149
(svn r14285) -Fix [FS#2263]: A train inside a wormhole could free the reservation of another train inside the wormhole.
michi_cc <michi_cc@openttd.org>
parents:
10102
diff
changeset
|
2070 SetTunnelBridgeReservation(tile, false); |
9a884d182149
(svn r14285) -Fix [FS#2263]: A train inside a wormhole could free the reservation of another train inside the wormhole.
michi_cc <michi_cc@openttd.org>
parents:
10102
diff
changeset
|
2071 SetTunnelBridgeReservation(end, false); |
9a884d182149
(svn r14285) -Fix [FS#2263]: A train inside a wormhole could free the reservation of another train inside the wormhole.
michi_cc <michi_cc@openttd.org>
parents:
10102
diff
changeset
|
2072 |
9a884d182149
(svn r14285) -Fix [FS#2263]: A train inside a wormhole could free the reservation of another train inside the wormhole.
michi_cc <michi_cc@openttd.org>
parents:
10102
diff
changeset
|
2073 if (_settings_client.gui.show_track_reservation) { |
9a884d182149
(svn r14285) -Fix [FS#2263]: A train inside a wormhole could free the reservation of another train inside the wormhole.
michi_cc <michi_cc@openttd.org>
parents:
10102
diff
changeset
|
2074 MarkTileDirtyByTile(tile); |
9a884d182149
(svn r14285) -Fix [FS#2263]: A train inside a wormhole could free the reservation of another train inside the wormhole.
michi_cc <michi_cc@openttd.org>
parents:
10102
diff
changeset
|
2075 MarkTileDirtyByTile(end); |
9a884d182149
(svn r14285) -Fix [FS#2263]: A train inside a wormhole could free the reservation of another train inside the wormhole.
michi_cc <michi_cc@openttd.org>
parents:
10102
diff
changeset
|
2076 } |
9809
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
2077 } |
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
2078 } |
12502
9472b49c61a1
(svn r16939) -Codechange: s/RailwayStation/RailStation/ to unify the way it's written.
rubidium <rubidium@openttd.org>
parents:
12472
diff
changeset
|
2079 } else if (IsRailStationTile(tile)) { |
9809
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
2080 TileIndex new_tile = TileAddByDiagDir(tile, dir); |
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
2081 /* If the new tile is not a further tile of the same station, we |
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
2082 * clear the reservation for the whole platform. */ |
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
2083 if (!IsCompatibleTrainStationTile(new_tile, tile)) { |
12502
9472b49c61a1
(svn r16939) -Codechange: s/RailwayStation/RailStation/ to unify the way it's written.
rubidium <rubidium@openttd.org>
parents:
12472
diff
changeset
|
2084 SetRailStationPlatformReservation(tile, ReverseDiagDir(dir), false); |
9809
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
2085 } |
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
2086 } else { |
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
2087 /* Any other tile */ |
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
2088 UnreserveRailTrack(tile, TrackdirToTrack(track_dir)); |
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
2089 } |
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
2090 } |
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
2091 |
9810
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2092 /** Free the reserved path in front of a vehicle. */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
2093 void FreeTrainTrackReservation(const Train *v, TileIndex origin, Trackdir orig_td) |
9810
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2094 { |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
2095 assert(v->IsFrontEngine()); |
9810
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2096 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2097 TileIndex tile = origin != INVALID_TILE ? origin : v->tile; |
11976
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
2098 Trackdir td = orig_td != INVALID_TRACKDIR ? orig_td : v->GetVehicleTrackdir(); |
12502
9472b49c61a1
(svn r16939) -Codechange: s/RailwayStation/RailStation/ to unify the way it's written.
rubidium <rubidium@openttd.org>
parents:
12472
diff
changeset
|
2099 bool free_tile = tile != v->tile || !(IsRailStationTile(v->tile) || IsTileType(v->tile, MP_TUNNELBRIDGE)); |
9472b49c61a1
(svn r16939) -Codechange: s/RailwayStation/RailStation/ to unify the way it's written.
rubidium <rubidium@openttd.org>
parents:
12472
diff
changeset
|
2100 StationID station_id = IsRailStationTile(v->tile) ? GetStationIndex(v->tile) : INVALID_STATION; |
9810
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2101 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2102 /* Don't free reservation if it's not ours. */ |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2103 if (TracksOverlap(GetReservedTrackbits(tile) | TrackToTrackBits(TrackdirToTrack(td)))) return; |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2104 |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
2105 CFollowTrackRail ft(v, GetRailTypeInfo(v->railtype)->compatible_railtypes); |
9810
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2106 while (ft.Follow(tile, td)) { |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2107 tile = ft.m_new_tile; |
10974
7bd3e2d0f151
(svn r15313) -Cleanup: Use helper functions we already have and add some documentation.
michi_cc <michi_cc@openttd.org>
parents:
10960
diff
changeset
|
2108 TrackdirBits bits = ft.m_new_td_bits & TrackBitsToTrackdirBits(GetReservedTrackbits(tile)); |
9810
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2109 td = RemoveFirstTrackdir(&bits); |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2110 assert(bits == TRACKDIR_BIT_NONE); |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2111 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2112 if (!IsValidTrackdir(td)) break; |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2113 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2114 if (IsTileType(tile, MP_RAILWAY)) { |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2115 if (HasSignalOnTrackdir(tile, td) && !IsPbsSignal(GetSignalType(tile, TrackdirToTrack(td)))) { |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2116 /* Conventional signal along trackdir: remove reservation and stop. */ |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2117 UnreserveRailTrack(tile, TrackdirToTrack(td)); |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2118 break; |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2119 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2120 if (HasPbsSignalOnTrackdir(tile, td)) { |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2121 if (GetSignalStateByTrackdir(tile, td) == SIGNAL_STATE_RED) { |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2122 /* Red PBS signal? Can't be our reservation, would be green then. */ |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2123 break; |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2124 } else { |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2125 /* Turn the signal back to red. */ |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2126 SetSignalStateByTrackdir(tile, td, SIGNAL_STATE_RED); |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2127 MarkTileDirtyByTile(tile); |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2128 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2129 } else if (HasSignalOnTrackdir(tile, ReverseTrackdir(td)) && IsOnewaySignal(tile, TrackdirToTrack(td))) { |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2130 break; |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2131 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2132 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2133 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2134 /* Don't free first station/bridge/tunnel if we are on it. */ |
10103
9a884d182149
(svn r14285) -Fix [FS#2263]: A train inside a wormhole could free the reservation of another train inside the wormhole.
michi_cc <michi_cc@openttd.org>
parents:
10102
diff
changeset
|
2135 if (free_tile || (!(ft.m_is_station && GetStationIndex(ft.m_new_tile) == station_id) && !ft.m_is_tunnel && !ft.m_is_bridge)) ClearPathReservation(v, tile, td); |
9810
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2136 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2137 free_tile = true; |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2138 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2139 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2140 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2141 static const byte _initial_tile_subcoord[6][4][3] = { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2142 {{ 15, 8, 1 }, { 0, 0, 0 }, { 0, 8, 5 }, { 0, 0, 0 }}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2143 {{ 0, 0, 0 }, { 8, 0, 3 }, { 0, 0, 0 }, { 8, 15, 7 }}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2144 {{ 0, 0, 0 }, { 7, 0, 2 }, { 0, 7, 6 }, { 0, 0, 0 }}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2145 {{ 15, 8, 2 }, { 0, 0, 0 }, { 0, 0, 0 }, { 8, 15, 6 }}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2146 {{ 15, 7, 0 }, { 8, 0, 4 }, { 0, 0, 0 }, { 0, 0, 0 }}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2147 {{ 0, 0, 0 }, { 0, 0, 0 }, { 0, 8, 4 }, { 7, 15, 0 }}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2148 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2149 |
9810
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2150 /** |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2151 * Perform pathfinding for a train. |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2152 * |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2153 * @param v The train |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2154 * @param tile The tile the train is about to enter |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2155 * @param enterdir Diagonal direction the train is coming from |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2156 * @param tracks Usable tracks on the new tile |
16776
93de8ffd68f7
(svn r21509) -Codechange: rename the rail pathfinders "path_not_found" parameter to "path_found" and remove the ! where the variables are set / read
rubidium <rubidium@openttd.org>
parents:
16775
diff
changeset
|
2157 * @param path_found [out] Whether a path has been found or not. |
10974
7bd3e2d0f151
(svn r15313) -Cleanup: Use helper functions we already have and add some documentation.
michi_cc <michi_cc@openttd.org>
parents:
10960
diff
changeset
|
2158 * @param do_track_reservation Path reservation is requested |
7bd3e2d0f151
(svn r15313) -Cleanup: Use helper functions we already have and add some documentation.
michi_cc <michi_cc@openttd.org>
parents:
10960
diff
changeset
|
2159 * @param dest [out] State and destination of the requested path |
9810
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2160 * @return The best track the train should follow |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2161 */ |
16776
93de8ffd68f7
(svn r21509) -Codechange: rename the rail pathfinders "path_not_found" parameter to "path_found" and remove the ! where the variables are set / read
rubidium <rubidium@openttd.org>
parents:
16775
diff
changeset
|
2162 static Track DoTrainPathfind(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, bool do_track_reservation, PBSTileInfo *dest) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2163 { |
13833
ad09d18a3e34
(svn r18362) -Cleanup: remove OPF for RVs and NTP to clean up lots of code and simplify some things for the future
rubidium <rubidium@openttd.org>
parents:
13832
diff
changeset
|
2164 switch (_settings_game.pf.pathfinder_for_trains) { |
16776
93de8ffd68f7
(svn r21509) -Codechange: rename the rail pathfinders "path_not_found" parameter to "path_found" and remove the ! where the variables are set / read
rubidium <rubidium@openttd.org>
parents:
16775
diff
changeset
|
2165 case VPF_NPF: return NPFTrainChooseTrack(v, tile, enterdir, tracks, path_found, do_track_reservation, dest); |
93de8ffd68f7
(svn r21509) -Codechange: rename the rail pathfinders "path_not_found" parameter to "path_found" and remove the ! where the variables are set / read
rubidium <rubidium@openttd.org>
parents:
16775
diff
changeset
|
2166 case VPF_YAPF: return YapfTrainChooseTrack(v, tile, enterdir, tracks, path_found, do_track_reservation, dest); |
13842
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
2167 |
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
2168 default: NOT_REACHED(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2169 } |
9810
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2170 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2171 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2172 /** |
9817
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2173 * Extend a train path as far as possible. Stops on encountering a safe tile, |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2174 * another reservation or a track choice. |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2175 * @return INVALID_TILE indicates that the reservation failed. |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2176 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
2177 static PBSTileInfo ExtendTrainReservation(const Train *v, TrackBits *new_tracks, DiagDirection *enterdir) |
9817
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2178 { |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2179 PBSTileInfo origin = FollowTrainReservation(v); |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2180 |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2181 CFollowTrackRail ft(v); |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2182 |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2183 TileIndex tile = origin.tile; |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2184 Trackdir cur_td = origin.trackdir; |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2185 while (ft.Follow(tile, cur_td)) { |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2186 if (KillFirstBit(ft.m_new_td_bits) == TRACKDIR_BIT_NONE) { |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2187 /* Possible signal tile. */ |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2188 if (HasOnewaySignalBlockingTrackdir(ft.m_new_tile, FindFirstTrackdir(ft.m_new_td_bits))) break; |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2189 } |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2190 |
13833
ad09d18a3e34
(svn r18362) -Cleanup: remove OPF for RVs and NTP to clean up lots of code and simplify some things for the future
rubidium <rubidium@openttd.org>
parents:
13832
diff
changeset
|
2191 if (_settings_game.pf.forbid_90_deg) { |
9817
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2192 ft.m_new_td_bits &= ~TrackdirCrossesTrackdirs(ft.m_old_td); |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2193 if (ft.m_new_td_bits == TRACKDIR_BIT_NONE) break; |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2194 } |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2195 |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2196 /* Station, depot or waypoint are a possible target. */ |
11946
d5716f5a9844
(svn r16349) -Codechange: rename IsPlainRailTile() to IsPlainRail(), introduce shiny new IsPlainRailTile()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
2197 bool target_seen = ft.m_is_station || (IsTileType(ft.m_new_tile, MP_RAILWAY) && !IsPlainRail(ft.m_new_tile)); |
9817
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2198 if (target_seen || KillFirstBit(ft.m_new_td_bits) != TRACKDIR_BIT_NONE) { |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2199 /* Choice found or possible target encountered. |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2200 * On finding a possible target, we need to stop and let the pathfinder handle the |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2201 * remaining path. This is because we don't know if this target is in one of our |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2202 * orders, so we might cause pathfinding to fail later on if we find a choice. |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2203 * This failure would cause a bogous call to TryReserveSafePath which might reserve |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2204 * a wrong path not leading to our next destination. */ |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2205 if (HasReservedTracks(ft.m_new_tile, TrackdirBitsToTrackBits(TrackdirReachesTrackdirs(ft.m_old_td)))) break; |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2206 |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2207 /* If we did skip some tiles, backtrack to the first skipped tile so the pathfinder |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2208 * actually starts its search at the first unreserved tile. */ |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2209 if (ft.m_tiles_skipped != 0) ft.m_new_tile -= TileOffsByDiagDir(ft.m_exitdir) * ft.m_tiles_skipped; |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2210 |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2211 /* Choice found, path valid but not okay. Save info about the choice tile as well. */ |
17399
c8b6698f2078
(svn r22145) -Codechange: Do explicit test for non-bool values.
alberth <alberth@openttd.org>
parents:
17394
diff
changeset
|
2212 if (new_tracks != NULL) *new_tracks = TrackdirBitsToTrackBits(ft.m_new_td_bits); |
c8b6698f2078
(svn r22145) -Codechange: Do explicit test for non-bool values.
alberth <alberth@openttd.org>
parents:
17394
diff
changeset
|
2213 if (enterdir != NULL) *enterdir = ft.m_exitdir; |
9817
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2214 return PBSTileInfo(ft.m_new_tile, ft.m_old_td, false); |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2215 } |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2216 |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2217 tile = ft.m_new_tile; |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2218 cur_td = FindFirstTrackdir(ft.m_new_td_bits); |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2219 |
13833
ad09d18a3e34
(svn r18362) -Cleanup: remove OPF for RVs and NTP to clean up lots of code and simplify some things for the future
rubidium <rubidium@openttd.org>
parents:
13832
diff
changeset
|
2220 if (IsSafeWaitingPosition(v, tile, cur_td, true, _settings_game.pf.forbid_90_deg)) { |
ad09d18a3e34
(svn r18362) -Cleanup: remove OPF for RVs and NTP to clean up lots of code and simplify some things for the future
rubidium <rubidium@openttd.org>
parents:
13832
diff
changeset
|
2221 bool wp_free = IsWaitingPositionFree(v, tile, cur_td, _settings_game.pf.forbid_90_deg); |
9817
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2222 if (!(wp_free && TryReserveRailTrack(tile, TrackdirToTrack(cur_td)))) break; |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2223 /* Safe position is all good, path valid and okay. */ |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2224 return PBSTileInfo(tile, cur_td, true); |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2225 } |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2226 |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2227 if (!TryReserveRailTrack(tile, TrackdirToTrack(cur_td))) break; |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2228 } |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2229 |
10186
d5dea47b6172
(svn r14397) -Fix: possible buffer overrun, wrong parameter type passed to printf and && where || is meant. Found by MSVC's code analysis (Darkvater)
rubidium <rubidium@openttd.org>
parents:
10178
diff
changeset
|
2230 if (ft.m_err == CFollowTrackRail::EC_OWNER || ft.m_err == CFollowTrackRail::EC_NO_WAY) { |
9817
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2231 /* End of line, path valid and okay. */ |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2232 return PBSTileInfo(ft.m_old_tile, ft.m_old_td, true); |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2233 } |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2234 |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2235 /* Sorry, can't reserve path, back out. */ |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2236 tile = origin.tile; |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2237 cur_td = origin.trackdir; |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2238 TileIndex stopped = ft.m_old_tile; |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2239 Trackdir stopped_td = ft.m_old_td; |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2240 while (tile != stopped || cur_td != stopped_td) { |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2241 if (!ft.Follow(tile, cur_td)) break; |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2242 |
13833
ad09d18a3e34
(svn r18362) -Cleanup: remove OPF for RVs and NTP to clean up lots of code and simplify some things for the future
rubidium <rubidium@openttd.org>
parents:
13832
diff
changeset
|
2243 if (_settings_game.pf.forbid_90_deg) { |
9817
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2244 ft.m_new_td_bits &= ~TrackdirCrossesTrackdirs(ft.m_old_td); |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2245 assert(ft.m_new_td_bits != TRACKDIR_BIT_NONE); |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2246 } |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2247 assert(KillFirstBit(ft.m_new_td_bits) == TRACKDIR_BIT_NONE); |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2248 |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2249 tile = ft.m_new_tile; |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2250 cur_td = FindFirstTrackdir(ft.m_new_td_bits); |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2251 |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2252 UnreserveRailTrack(tile, TrackdirToTrack(cur_td)); |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2253 } |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2254 |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2255 /* Path invalid. */ |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2256 return PBSTileInfo(); |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2257 } |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2258 |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2259 /** |
9810
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2260 * Try to reserve any path to a safe tile, ignoring the vehicle's destination. |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2261 * Safe tiles are tiles in front of a signal, depots and station tiles at end of line. |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2262 * |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2263 * @param v The vehicle. |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2264 * @param tile The tile the search should start from. |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2265 * @param td The trackdir the search should start from. |
13842
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
2266 * @param override_railtype Whether all physically compatible railtypes should be followed. |
9810
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2267 * @return True if a path to a safe stopping tile could be reserved. |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2268 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
2269 static bool TryReserveSafeTrack(const Train *v, TileIndex tile, Trackdir td, bool override_tailtype) |
9810
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2270 { |
13842
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
2271 switch (_settings_game.pf.pathfinder_for_trains) { |
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
2272 case VPF_NPF: return NPFTrainFindNearestSafeTile(v, tile, td, override_tailtype); |
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
2273 case VPF_YAPF: return YapfTrainFindNearestSafeTile(v, tile, td, override_tailtype); |
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
2274 |
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
2275 default: NOT_REACHED(); |
9810
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2276 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2277 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2278 |
10251
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2279 /** This class will save the current order of a vehicle and restore it on destruction. */ |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2280 class VehicleOrderSaver |
9812
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2281 { |
10251
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2282 private: |
17564
d5ff867052a5
(svn r22328) -Add: a flag to GroundVehicles to disable insertion and removal of automatic orders until the next real order is reached.
frosch <frosch@openttd.org>
parents:
17489
diff
changeset
|
2283 Train *v; |
10251
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2284 Order old_order; |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2285 TileIndex old_dest_tile; |
10343
dd96353a63c7
(svn r14594) -Fix [FS#2412]: trains could get their their last visited station reset when still (un)loading causing an invalid state.
rubidium <rubidium@openttd.org>
parents:
10328
diff
changeset
|
2286 StationID old_last_station_visited; |
10251
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2287 VehicleOrderID index; |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17564
diff
changeset
|
2288 bool suppress_implicit_orders; |
10251
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2289 |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2290 public: |
17564
d5ff867052a5
(svn r22328) -Add: a flag to GroundVehicles to disable insertion and removal of automatic orders until the next real order is reached.
frosch <frosch@openttd.org>
parents:
17489
diff
changeset
|
2291 VehicleOrderSaver(Train *_v) : |
10343
dd96353a63c7
(svn r14594) -Fix [FS#2412]: trains could get their their last visited station reset when still (un)loading causing an invalid state.
rubidium <rubidium@openttd.org>
parents:
10328
diff
changeset
|
2292 v(_v), |
dd96353a63c7
(svn r14594) -Fix [FS#2412]: trains could get their their last visited station reset when still (un)loading causing an invalid state.
rubidium <rubidium@openttd.org>
parents:
10328
diff
changeset
|
2293 old_order(_v->current_order), |
dd96353a63c7
(svn r14594) -Fix [FS#2412]: trains could get their their last visited station reset when still (un)loading causing an invalid state.
rubidium <rubidium@openttd.org>
parents:
10328
diff
changeset
|
2294 old_dest_tile(_v->dest_tile), |
dd96353a63c7
(svn r14594) -Fix [FS#2412]: trains could get their their last visited station reset when still (un)loading causing an invalid state.
rubidium <rubidium@openttd.org>
parents:
10328
diff
changeset
|
2295 old_last_station_visited(_v->last_station_visited), |
17564
d5ff867052a5
(svn r22328) -Add: a flag to GroundVehicles to disable insertion and removal of automatic orders until the next real order is reached.
frosch <frosch@openttd.org>
parents:
17489
diff
changeset
|
2296 index(_v->cur_real_order_index), |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17564
diff
changeset
|
2297 suppress_implicit_orders(HasBit(_v->gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS)) |
10251
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2298 { |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2299 } |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2300 |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2301 ~VehicleOrderSaver() |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2302 { |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2303 this->v->current_order = this->old_order; |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2304 this->v->dest_tile = this->old_dest_tile; |
10343
dd96353a63c7
(svn r14594) -Fix [FS#2412]: trains could get their their last visited station reset when still (un)loading causing an invalid state.
rubidium <rubidium@openttd.org>
parents:
10328
diff
changeset
|
2305 this->v->last_station_visited = this->old_last_station_visited; |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17564
diff
changeset
|
2306 SB(this->v->gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS, 1, suppress_implicit_orders ? 1: 0); |
10251
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2307 } |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2308 |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2309 /** |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2310 * Set the current vehicle order to the next order in the order list. |
10683
4742228a9d1d
(svn r14994) -Fix [FS#Aali]: Better handling of OT_LOADING and OT_LEAVESTATION in ChooseTrainTrack.
frosch <frosch@openttd.org>
parents:
10682
diff
changeset
|
2311 * @param skip_first Shall the first (i.e. active) order be skipped? |
10251
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2312 * @return True if a suitable next order could be found. |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2313 */ |
10683
4742228a9d1d
(svn r14994) -Fix [FS#Aali]: Better handling of OT_LOADING and OT_LEAVESTATION in ChooseTrainTrack.
frosch <frosch@openttd.org>
parents:
10682
diff
changeset
|
2314 bool SwitchToNextOrder(bool skip_first) |
10251
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2315 { |
10792
dcc9b146a749
(svn r15125) -Fix [FS#2544]: Do not try to determine the next order destination, if there are no orders.
frosch <frosch@openttd.org>
parents:
10744
diff
changeset
|
2316 if (this->v->GetNumOrders() == 0) return false; |
dcc9b146a749
(svn r15125) -Fix [FS#2544]: Do not try to determine the next order destination, if there are no orders.
frosch <frosch@openttd.org>
parents:
10744
diff
changeset
|
2317 |
10683
4742228a9d1d
(svn r14994) -Fix [FS#Aali]: Better handling of OT_LOADING and OT_LEAVESTATION in ChooseTrainTrack.
frosch <frosch@openttd.org>
parents:
10682
diff
changeset
|
2318 if (skip_first) ++this->index; |
10251
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2319 |
10569
c7206a6dabf0
(svn r14826) -Fix [FS#2494]: infinite loop in order lookahead when reserving a path (Swallow)
rubidium <rubidium@openttd.org>
parents:
10546
diff
changeset
|
2320 int conditional_depth = 0; |
c7206a6dabf0
(svn r14826) -Fix [FS#2494]: infinite loop in order lookahead when reserving a path (Swallow)
rubidium <rubidium@openttd.org>
parents:
10546
diff
changeset
|
2321 |
10251
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2322 do { |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2323 /* Wrap around. */ |
10544
836dfaca2a32
(svn r14801) -Codechange: don't reference Vehicle::num_orders directly but through a method GetNumOrders() (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10528
diff
changeset
|
2324 if (this->index >= this->v->GetNumOrders()) this->index = 0; |
10251
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2325 |
11991
a4d3838349e6
(svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents:
11988
diff
changeset
|
2326 Order *order = this->v->GetOrder(this->index); |
10251
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2327 assert(order != NULL); |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2328 |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2329 switch (order->GetType()) { |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2330 case OT_GOTO_DEPOT: |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2331 /* Skip service in depot orders when the train doesn't need service. */ |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2332 if ((order->GetDepotOrderType() & ODTFB_SERVICE) && !this->v->NeedsServicing()) break; |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2333 case OT_GOTO_STATION: |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2334 case OT_GOTO_WAYPOINT: |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2335 this->v->current_order = *order; |
17804
7fc728e847d1
(svn r22589) -Fix [FS#4641]: PBS order forecasting modified the current order index in case of a goto-nearest-depot order and no depot could be found.
frosch <frosch@openttd.org>
parents:
17693
diff
changeset
|
2336 return UpdateOrderDest(this->v, order, 0, true); |
10251
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2337 case OT_CONDITIONAL: { |
10569
c7206a6dabf0
(svn r14826) -Fix [FS#2494]: infinite loop in order lookahead when reserving a path (Swallow)
rubidium <rubidium@openttd.org>
parents:
10546
diff
changeset
|
2338 if (conditional_depth > this->v->GetNumOrders()) return false; |
10251
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2339 VehicleOrderID next = ProcessConditionalOrder(order, this->v); |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2340 if (next != INVALID_VEH_ORDER_ID) { |
10569
c7206a6dabf0
(svn r14826) -Fix [FS#2494]: infinite loop in order lookahead when reserving a path (Swallow)
rubidium <rubidium@openttd.org>
parents:
10546
diff
changeset
|
2341 conditional_depth++; |
10251
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2342 this->index = next; |
10261
486e807fb404
(svn r14492) -Fix [FS#2366] (r14482): Conditional orders could lead to an infinite loop on path look-ahead.
michi_cc <michi_cc@openttd.org>
parents:
10252
diff
changeset
|
2343 /* Don't increment next, so no break here. */ |
10251
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2344 continue; |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2345 } |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2346 break; |
9812
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2347 } |
10251
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2348 default: |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2349 break; |
9812
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2350 } |
10261
486e807fb404
(svn r14492) -Fix [FS#2366] (r14482): Conditional orders could lead to an infinite loop on path look-ahead.
michi_cc <michi_cc@openttd.org>
parents:
10252
diff
changeset
|
2351 /* Don't increment inside the while because otherwise conditional |
486e807fb404
(svn r14492) -Fix [FS#2366] (r14482): Conditional orders could lead to an infinite loop on path look-ahead.
michi_cc <michi_cc@openttd.org>
parents:
10252
diff
changeset
|
2352 * orders can lead to an infinite loop. */ |
486e807fb404
(svn r14492) -Fix [FS#2366] (r14482): Conditional orders could lead to an infinite loop on path look-ahead.
michi_cc <michi_cc@openttd.org>
parents:
10252
diff
changeset
|
2353 ++this->index; |
17194
b590eca5d805
(svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents:
17175
diff
changeset
|
2354 } while (this->index != this->v->cur_real_order_index); |
10251
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2355 |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2356 return false; |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2357 } |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2358 }; |
9812
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2359 |
9810
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2360 /* choose a track */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
2361 static Track ChooseTrainTrack(Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool force_res, bool *got_reservation, bool mark_stuck) |
9810
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2362 { |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2363 Track best_track = INVALID_TRACK; |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2364 bool do_track_reservation = _settings_game.pf.reserve_paths || force_res; |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2365 bool changed_signal = false; |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2366 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2367 assert((tracks & ~TRACK_BIT_MASK) == 0); |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2368 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2369 if (got_reservation != NULL) *got_reservation = false; |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2370 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2371 /* Don't use tracks here as the setting to forbid 90 deg turns might have been switched between reservation and now. */ |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2372 TrackBits res_tracks = (TrackBits)(GetReservedTrackbits(tile) & DiagdirReachesTracks(enterdir)); |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2373 /* Do we have a suitable reserved track? */ |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2374 if (res_tracks != TRACK_BIT_NONE) return FindFirstTrack(res_tracks); |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2375 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2376 /* Quick return in case only one possible track is available */ |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2377 if (KillFirstBit(tracks) == TRACK_BIT_NONE) { |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2378 Track track = FindFirstTrack(tracks); |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2379 /* We need to check for signals only here, as a junction tile can't have signals. */ |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2380 if (track != INVALID_TRACK && HasPbsSignalOnTrackdir(tile, TrackEnterdirToTrackdir(track, enterdir))) { |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2381 do_track_reservation = true; |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2382 changed_signal = true; |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2383 SetSignalStateByTrackdir(tile, TrackEnterdirToTrackdir(track, enterdir), SIGNAL_STATE_GREEN); |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2384 } else if (!do_track_reservation) { |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2385 return track; |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2386 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2387 best_track = track; |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2388 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2389 |
9817
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2390 PBSTileInfo res_dest(tile, INVALID_TRACKDIR, false); |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2391 DiagDirection dest_enterdir = enterdir; |
9810
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2392 if (do_track_reservation) { |
9822
d61801babe63
(svn r13964) -Codechange [YAPP]: Check if a train needs servicing when reserving the next path segment. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9821
diff
changeset
|
2393 /* Check if the train needs service here, so it has a chance to always find a depot. |
d61801babe63
(svn r13964) -Codechange [YAPP]: Check if a train needs servicing when reserving the next path segment. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9821
diff
changeset
|
2394 * Also check if the current order is a service order so we don't reserve a path to |
d61801babe63
(svn r13964) -Codechange [YAPP]: Check if a train needs servicing when reserving the next path segment. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9821
diff
changeset
|
2395 * the destination but instead to the next one if service isn't needed. */ |
d61801babe63
(svn r13964) -Codechange [YAPP]: Check if a train needs servicing when reserving the next path segment. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9821
diff
changeset
|
2396 CheckIfTrainNeedsService(v); |
d61801babe63
(svn r13964) -Codechange [YAPP]: Check if a train needs servicing when reserving the next path segment. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9821
diff
changeset
|
2397 if (v->current_order.IsType(OT_DUMMY) || v->current_order.IsType(OT_CONDITIONAL) || v->current_order.IsType(OT_GOTO_DEPOT)) ProcessOrders(v); |
9817
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2398 |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2399 res_dest = ExtendTrainReservation(v, &tracks, &dest_enterdir); |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2400 if (res_dest.tile == INVALID_TILE) { |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2401 /* Reservation failed? */ |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2402 if (mark_stuck) MarkTrainAsStuck(v); |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2403 if (changed_signal) SetSignalStateByTrackdir(tile, TrackEnterdirToTrackdir(best_track, enterdir), SIGNAL_STATE_RED); |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2404 return FindFirstTrack(tracks); |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2405 } |
9810
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2406 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2407 |
10252
d0582ee8991e
(svn r14483) -Fix [FS#2340]: On reaching a waypoint a train could falsely be reported as lost when doing the look ahead for a path.
michi_cc <michi_cc@openttd.org>
parents:
10251
diff
changeset
|
2408 /* Save the current train order. The destructor will restore the old order on function exit. */ |
d0582ee8991e
(svn r14483) -Fix [FS#2340]: On reaching a waypoint a train could falsely be reported as lost when doing the look ahead for a path.
michi_cc <michi_cc@openttd.org>
parents:
10251
diff
changeset
|
2409 VehicleOrderSaver orders(v); |
d0582ee8991e
(svn r14483) -Fix [FS#2340]: On reaching a waypoint a train could falsely be reported as lost when doing the look ahead for a path.
michi_cc <michi_cc@openttd.org>
parents:
10251
diff
changeset
|
2410 |
d0582ee8991e
(svn r14483) -Fix [FS#2340]: On reaching a waypoint a train could falsely be reported as lost when doing the look ahead for a path.
michi_cc <michi_cc@openttd.org>
parents:
10251
diff
changeset
|
2411 /* If the current tile is the destination of the current order and |
10307
534319441220
(svn r14550) -Fix [FS#2391]: Don't assert on path look-ahead when processing a not-part-of-orders depot-order.
michi_cc <michi_cc@openttd.org>
parents:
10287
diff
changeset
|
2412 * a reservation was requested, advance to the next order. |
534319441220
(svn r14550) -Fix [FS#2391]: Don't assert on path look-ahead when processing a not-part-of-orders depot-order.
michi_cc <michi_cc@openttd.org>
parents:
10287
diff
changeset
|
2413 * Don't advance on a depot order as depots are always safe end points |
534319441220
(svn r14550) -Fix [FS#2391]: Don't assert on path look-ahead when processing a not-part-of-orders depot-order.
michi_cc <michi_cc@openttd.org>
parents:
10287
diff
changeset
|
2414 * for a path and no look-ahead is necessary. This also avoids a |
534319441220
(svn r14550) -Fix [FS#2391]: Don't assert on path look-ahead when processing a not-part-of-orders depot-order.
michi_cc <michi_cc@openttd.org>
parents:
10287
diff
changeset
|
2415 * problem with depot orders not part of the order list when the |
534319441220
(svn r14550) -Fix [FS#2391]: Don't assert on path look-ahead when processing a not-part-of-orders depot-order.
michi_cc <michi_cc@openttd.org>
parents:
10287
diff
changeset
|
2416 * order list itself is empty. */ |
10683
4742228a9d1d
(svn r14994) -Fix [FS#Aali]: Better handling of OT_LOADING and OT_LEAVESTATION in ChooseTrainTrack.
frosch <frosch@openttd.org>
parents:
10682
diff
changeset
|
2417 if (v->current_order.IsType(OT_LEAVESTATION)) { |
4742228a9d1d
(svn r14994) -Fix [FS#Aali]: Better handling of OT_LOADING and OT_LEAVESTATION in ChooseTrainTrack.
frosch <frosch@openttd.org>
parents:
10682
diff
changeset
|
2418 orders.SwitchToNextOrder(false); |
4742228a9d1d
(svn r14994) -Fix [FS#Aali]: Better handling of OT_LOADING and OT_LEAVESTATION in ChooseTrainTrack.
frosch <frosch@openttd.org>
parents:
10682
diff
changeset
|
2419 } else if (v->current_order.IsType(OT_LOADING) || (!v->current_order.IsType(OT_GOTO_DEPOT) && ( |
10444
368a9eb9207e
(svn r14699) -Fix (r14483): Do not use v->dest_tile for trains heading to a station. Reaching that tile does not mean reaching the station.
frosch <frosch@openttd.org>
parents:
10441
diff
changeset
|
2420 v->current_order.IsType(OT_GOTO_STATION) ? |
12502
9472b49c61a1
(svn r16939) -Codechange: s/RailwayStation/RailStation/ to unify the way it's written.
rubidium <rubidium@openttd.org>
parents:
12472
diff
changeset
|
2421 IsRailStationTile(v->tile) && v->current_order.GetDestination() == GetStationIndex(v->tile) : |
10683
4742228a9d1d
(svn r14994) -Fix [FS#Aali]: Better handling of OT_LOADING and OT_LEAVESTATION in ChooseTrainTrack.
frosch <frosch@openttd.org>
parents:
10682
diff
changeset
|
2422 v->tile == v->dest_tile))) { |
4742228a9d1d
(svn r14994) -Fix [FS#Aali]: Better handling of OT_LOADING and OT_LEAVESTATION in ChooseTrainTrack.
frosch <frosch@openttd.org>
parents:
10682
diff
changeset
|
2423 orders.SwitchToNextOrder(true); |
10252
d0582ee8991e
(svn r14483) -Fix [FS#2340]: On reaching a waypoint a train could falsely be reported as lost when doing the look ahead for a path.
michi_cc <michi_cc@openttd.org>
parents:
10251
diff
changeset
|
2424 } |
d0582ee8991e
(svn r14483) -Fix [FS#2340]: On reaching a waypoint a train could falsely be reported as lost when doing the look ahead for a path.
michi_cc <michi_cc@openttd.org>
parents:
10251
diff
changeset
|
2425 |
9817
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2426 if (res_dest.tile != INVALID_TILE && !res_dest.okay) { |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2427 /* Pathfinders are able to tell that route was only 'guessed'. */ |
16776
93de8ffd68f7
(svn r21509) -Codechange: rename the rail pathfinders "path_not_found" parameter to "path_found" and remove the ! where the variables are set / read
rubidium <rubidium@openttd.org>
parents:
16775
diff
changeset
|
2428 bool path_found = true; |
9817
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2429 TileIndex new_tile = res_dest.tile; |
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2430 |
16776
93de8ffd68f7
(svn r21509) -Codechange: rename the rail pathfinders "path_not_found" parameter to "path_found" and remove the ! where the variables are set / read
rubidium <rubidium@openttd.org>
parents:
16775
diff
changeset
|
2431 Track next_track = DoTrainPathfind(v, new_tile, dest_enterdir, tracks, path_found, do_track_reservation, &res_dest); |
9817
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2432 if (new_tile == tile) best_track = next_track; |
16776
93de8ffd68f7
(svn r21509) -Codechange: rename the rail pathfinders "path_not_found" parameter to "path_found" and remove the ! where the variables are set / read
rubidium <rubidium@openttd.org>
parents:
16775
diff
changeset
|
2433 v->HandlePathfindingResult(path_found); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2434 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2435 |
9810
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2436 /* No track reservation requested -> finished. */ |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2437 if (!do_track_reservation) return best_track; |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2438 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2439 /* A path was found, but could not be reserved. */ |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2440 if (res_dest.tile != INVALID_TILE && !res_dest.okay) { |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2441 if (mark_stuck) MarkTrainAsStuck(v); |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2442 FreeTrainTrackReservation(v); |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2443 return best_track; |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2444 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2445 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2446 /* No possible reservation target found, we are probably lost. */ |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2447 if (res_dest.tile == INVALID_TILE) { |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2448 /* Try to find any safe destination. */ |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2449 PBSTileInfo origin = FollowTrainReservation(v); |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2450 if (TryReserveSafeTrack(v, origin.tile, origin.trackdir, false)) { |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2451 TrackBits res = GetReservedTrackbits(tile) & DiagdirReachesTracks(enterdir); |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2452 best_track = FindFirstTrack(res); |
11976
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
2453 TryReserveRailTrack(v->tile, TrackdirToTrack(v->GetVehicleTrackdir())); |
9810
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2454 if (got_reservation != NULL) *got_reservation = true; |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2455 if (changed_signal) MarkTileDirtyByTile(tile); |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2456 } else { |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2457 FreeTrainTrackReservation(v); |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2458 if (mark_stuck) MarkTrainAsStuck(v); |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2459 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2460 return best_track; |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2461 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2462 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2463 if (got_reservation != NULL) *got_reservation = true; |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2464 |
9812
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2465 /* Reservation target found and free, check if it is safe. */ |
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2466 while (!IsSafeWaitingPosition(v, res_dest.tile, res_dest.trackdir, true, _settings_game.pf.forbid_90_deg)) { |
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2467 /* Extend reservation until we have found a safe position. */ |
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2468 DiagDirection exitdir = TrackdirToExitdir(res_dest.trackdir); |
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2469 TileIndex next_tile = TileAddByDiagDir(res_dest.tile, exitdir); |
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2470 TrackBits reachable = TrackdirBitsToTrackBits((TrackdirBits)(GetTileTrackStatus(next_tile, TRANSPORT_RAIL, 0))) & DiagdirReachesTracks(exitdir); |
13833
ad09d18a3e34
(svn r18362) -Cleanup: remove OPF for RVs and NTP to clean up lots of code and simplify some things for the future
rubidium <rubidium@openttd.org>
parents:
13832
diff
changeset
|
2471 if (_settings_game.pf.forbid_90_deg) { |
9812
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2472 reachable &= ~TrackCrossesTracks(TrackdirToTrack(res_dest.trackdir)); |
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2473 } |
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2474 |
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2475 /* Get next order with destination. */ |
10683
4742228a9d1d
(svn r14994) -Fix [FS#Aali]: Better handling of OT_LOADING and OT_LEAVESTATION in ChooseTrainTrack.
frosch <frosch@openttd.org>
parents:
10682
diff
changeset
|
2476 if (orders.SwitchToNextOrder(true)) { |
9812
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2477 PBSTileInfo cur_dest; |
16776
93de8ffd68f7
(svn r21509) -Codechange: rename the rail pathfinders "path_not_found" parameter to "path_found" and remove the ! where the variables are set / read
rubidium <rubidium@openttd.org>
parents:
16775
diff
changeset
|
2478 bool path_found; |
93de8ffd68f7
(svn r21509) -Codechange: rename the rail pathfinders "path_not_found" parameter to "path_found" and remove the ! where the variables are set / read
rubidium <rubidium@openttd.org>
parents:
16775
diff
changeset
|
2479 DoTrainPathfind(v, next_tile, exitdir, reachable, path_found, true, &cur_dest); |
9812
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2480 if (cur_dest.tile != INVALID_TILE) { |
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2481 res_dest = cur_dest; |
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2482 if (res_dest.okay) continue; |
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2483 /* Path found, but could not be reserved. */ |
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2484 FreeTrainTrackReservation(v); |
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2485 if (mark_stuck) MarkTrainAsStuck(v); |
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2486 if (got_reservation != NULL) *got_reservation = false; |
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2487 changed_signal = false; |
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2488 break; |
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2489 } |
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2490 } |
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2491 /* No order or no safe position found, try any position. */ |
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2492 if (!TryReserveSafeTrack(v, res_dest.tile, res_dest.trackdir, true)) { |
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2493 FreeTrainTrackReservation(v); |
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2494 if (mark_stuck) MarkTrainAsStuck(v); |
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2495 if (got_reservation != NULL) *got_reservation = false; |
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2496 changed_signal = false; |
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2497 } |
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2498 break; |
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2499 } |
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2500 |
11976
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
2501 TryReserveRailTrack(v->tile, TrackdirToTrack(v->GetVehicleTrackdir())); |
9810
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2502 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2503 if (changed_signal) MarkTileDirtyByTile(tile); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2504 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2505 return best_track; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2506 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2507 |
9813
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2508 /** |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2509 * Try to reserve a path to a safe position. |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2510 * |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2511 * @param v The vehicle |
10974
7bd3e2d0f151
(svn r15313) -Cleanup: Use helper functions we already have and add some documentation.
michi_cc <michi_cc@openttd.org>
parents:
10960
diff
changeset
|
2512 * @param mark_as_stuck Should the train be marked as stuck on a failed reservation? |
7bd3e2d0f151
(svn r15313) -Cleanup: Use helper functions we already have and add some documentation.
michi_cc <michi_cc@openttd.org>
parents:
10960
diff
changeset
|
2513 * @param first_tile_okay True if no path should be reserved if the current tile is a safe position. |
7bd3e2d0f151
(svn r15313) -Cleanup: Use helper functions we already have and add some documentation.
michi_cc <michi_cc@openttd.org>
parents:
10960
diff
changeset
|
2514 * @return True if a path could be reserved. |
9813
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2515 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
2516 bool TryPathReserve(Train *v, bool mark_as_stuck, bool first_tile_okay) |
9813
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2517 { |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
2518 assert(v->IsFrontEngine()); |
9813
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2519 |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2520 /* We have to handle depots specially as the track follower won't look |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2521 * at the depot tile itself but starts from the next tile. If we are still |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2522 * inside the depot, a depot reservation can never be ours. */ |
12137
b3c5a6c9146a
(svn r16553) -Codechange: don't use TRACK_BIT_WORMHOLE and TRACK_BIT_DEPOT as bitmasks
smatz <smatz@openttd.org>
parents:
12129
diff
changeset
|
2523 if (v->track == TRACK_BIT_DEPOT) { |
12471
c0587ce9da72
(svn r16908) -Codechange: s/DepotWaypointReservation/DepotReservation/
rubidium <rubidium@openttd.org>
parents:
12470
diff
changeset
|
2524 if (HasDepotReservation(v->tile)) { |
9813
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2525 if (mark_as_stuck) MarkTrainAsStuck(v); |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2526 return false; |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2527 } else { |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2528 /* Depot not reserved, but the next tile might be. */ |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2529 TileIndex next_tile = TileAddByDiagDir(v->tile, GetRailDepotDirection(v->tile)); |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2530 if (HasReservedTracks(next_tile, DiagdirReachesTracks(GetRailDepotDirection(v->tile)))) return false; |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2531 } |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2532 } |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2533 |
14100
e4f2ba58a34f
(svn r18647) -Fix: [YAPP] A train inside a station was not always found when checking for trains on a reserved path.
michi_cc <michi_cc@openttd.org>
parents:
14081
diff
changeset
|
2534 Vehicle *other_train = NULL; |
9831
7c2cb1b0402d
(svn r13974) -Fix [YAPP]: A train crash could lead to stale reservations. (michi_cc)
frosch <frosch@openttd.org>
parents:
9828
diff
changeset
|
2535 PBSTileInfo origin = FollowTrainReservation(v, &other_train); |
15820
59fd8293b2ee
(svn r20499) -Doc: Spelling fixes, and one doxygen comment addition.
alberth <alberth@openttd.org>
parents:
15763
diff
changeset
|
2536 /* The path we are driving on is already blocked by some other train. |
12692
09fa66ffeadd
(svn r17151) -Fix [FS#3104] (r13974): A train entering a PBS section through a block signal could cause a train crash if another reservation ending at a safe tile was already present in the section.
michi_cc <michi_cc@openttd.org>
parents:
12666
diff
changeset
|
2537 * This can only happen in certain situations when mixing path and |
09fa66ffeadd
(svn r17151) -Fix [FS#3104] (r13974): A train entering a PBS section through a block signal could cause a train crash if another reservation ending at a safe tile was already present in the section.
michi_cc <michi_cc@openttd.org>
parents:
12666
diff
changeset
|
2538 * block signals or when changing tracks and/or signals. |
09fa66ffeadd
(svn r17151) -Fix [FS#3104] (r13974): A train entering a PBS section through a block signal could cause a train crash if another reservation ending at a safe tile was already present in the section.
michi_cc <michi_cc@openttd.org>
parents:
12666
diff
changeset
|
2539 * Exit here as doing any further reservations will probably just |
09fa66ffeadd
(svn r17151) -Fix [FS#3104] (r13974): A train entering a PBS section through a block signal could cause a train crash if another reservation ending at a safe tile was already present in the section.
michi_cc <michi_cc@openttd.org>
parents:
12666
diff
changeset
|
2540 * make matters worse. */ |
14100
e4f2ba58a34f
(svn r18647) -Fix: [YAPP] A train inside a station was not always found when checking for trains on a reserved path.
michi_cc <michi_cc@openttd.org>
parents:
14081
diff
changeset
|
2541 if (other_train != NULL && other_train->index != v->index) { |
12692
09fa66ffeadd
(svn r17151) -Fix [FS#3104] (r13974): A train entering a PBS section through a block signal could cause a train crash if another reservation ending at a safe tile was already present in the section.
michi_cc <michi_cc@openttd.org>
parents:
12666
diff
changeset
|
2542 if (mark_as_stuck) MarkTrainAsStuck(v); |
09fa66ffeadd
(svn r17151) -Fix [FS#3104] (r13974): A train entering a PBS section through a block signal could cause a train crash if another reservation ending at a safe tile was already present in the section.
michi_cc <michi_cc@openttd.org>
parents:
12666
diff
changeset
|
2543 return false; |
09fa66ffeadd
(svn r17151) -Fix [FS#3104] (r13974): A train entering a PBS section through a block signal could cause a train crash if another reservation ending at a safe tile was already present in the section.
michi_cc <michi_cc@openttd.org>
parents:
12666
diff
changeset
|
2544 } |
9813
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2545 /* If we have a reserved path and the path ends at a safe tile, we are finished already. */ |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2546 if (origin.okay && (v->tile != origin.tile || first_tile_okay)) { |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2547 /* Can't be stuck then. */ |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
13001
diff
changeset
|
2548 if (HasBit(v->flags, VRF_TRAIN_STUCK)) SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
2549 ClrBit(v->flags, VRF_TRAIN_STUCK); |
9813
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2550 return true; |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2551 } |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2552 |
15820
59fd8293b2ee
(svn r20499) -Doc: Spelling fixes, and one doxygen comment addition.
alberth <alberth@openttd.org>
parents:
15763
diff
changeset
|
2553 /* If we are in a depot, tentatively reserve the depot. */ |
12137
b3c5a6c9146a
(svn r16553) -Codechange: don't use TRACK_BIT_WORMHOLE and TRACK_BIT_DEPOT as bitmasks
smatz <smatz@openttd.org>
parents:
12129
diff
changeset
|
2554 if (v->track == TRACK_BIT_DEPOT) { |
12471
c0587ce9da72
(svn r16908) -Codechange: s/DepotWaypointReservation/DepotReservation/
rubidium <rubidium@openttd.org>
parents:
12470
diff
changeset
|
2555 SetDepotReservation(v->tile, true); |
9813
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2556 if (_settings_client.gui.show_track_reservation) MarkTileDirtyByTile(v->tile); |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2557 } |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2558 |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2559 DiagDirection exitdir = TrackdirToExitdir(origin.trackdir); |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2560 TileIndex new_tile = TileAddByDiagDir(origin.tile, exitdir); |
10974
7bd3e2d0f151
(svn r15313) -Cleanup: Use helper functions we already have and add some documentation.
michi_cc <michi_cc@openttd.org>
parents:
10960
diff
changeset
|
2561 TrackBits reachable = TrackdirBitsToTrackBits(TrackStatusToTrackdirBits(GetTileTrackStatus(new_tile, TRANSPORT_RAIL, 0)) & DiagdirReachesTrackdirs(exitdir)); |
9813
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2562 |
13833
ad09d18a3e34
(svn r18362) -Cleanup: remove OPF for RVs and NTP to clean up lots of code and simplify some things for the future
rubidium <rubidium@openttd.org>
parents:
13832
diff
changeset
|
2563 if (_settings_game.pf.forbid_90_deg) reachable &= ~TrackCrossesTracks(TrackdirToTrack(origin.trackdir)); |
9813
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2564 |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2565 bool res_made = false; |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2566 ChooseTrainTrack(v, new_tile, exitdir, reachable, true, &res_made, mark_as_stuck); |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2567 |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2568 if (!res_made) { |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2569 /* Free the depot reservation as well. */ |
12471
c0587ce9da72
(svn r16908) -Codechange: s/DepotWaypointReservation/DepotReservation/
rubidium <rubidium@openttd.org>
parents:
12470
diff
changeset
|
2570 if (v->track == TRACK_BIT_DEPOT) SetDepotReservation(v->tile, false); |
9813
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2571 return false; |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2572 } |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2573 |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
2574 if (HasBit(v->flags, VRF_TRAIN_STUCK)) { |
14213
41b2e7bf03da
(svn r18764) -Fix [FS#3422]: split the (un)load ticks counter and signal wait counter; sometimes they might get into eachother's way
rubidium <rubidium@openttd.org>
parents:
14127
diff
changeset
|
2575 v->wait_counter = 0; |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
13001
diff
changeset
|
2576 SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
10587
f03dcfd93ae5
(svn r14850) -Fix [FS#2503]: Reversing a stuck train that is then not stuck anymore did not always reset the waiting timer.
michi_cc <michi_cc@openttd.org>
parents:
10577
diff
changeset
|
2577 } |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
2578 ClrBit(v->flags, VRF_TRAIN_STUCK); |
9813
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2579 return true; |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2580 } |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
2581 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2582 |
13842
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
2583 static bool CheckReverseTrain(const Train *v) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2584 { |
9413
512ea64da840
(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 <rubidium@openttd.org>
parents:
9358
diff
changeset
|
2585 if (_settings_game.difficulty.line_reverse_mode != 0 || |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
2586 v->track == TRACK_BIT_DEPOT || v->track == TRACK_BIT_WORMHOLE || |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2587 !(v->direction & 1)) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2588 return false; |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2589 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2590 |
13842
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
2591 assert(v->track != TRACK_BIT_NONE); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2592 |
9413
512ea64da840
(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 <rubidium@openttd.org>
parents:
9358
diff
changeset
|
2593 switch (_settings_game.pf.pathfinder_for_trains) { |
13842
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
2594 case VPF_NPF: return NPFTrainCheckReverse(v); |
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
2595 case VPF_YAPF: return YapfTrainCheckReverse(v); |
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
2596 |
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
2597 default: NOT_REACHED(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2598 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2599 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2600 |
8827
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8794
diff
changeset
|
2601 TileIndex Train::GetOrderStationLocation(StationID station) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2602 { |
8830
981a95f3204d
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents:
8827
diff
changeset
|
2603 if (station == this->last_station_visited) this->last_station_visited = INVALID_STATION; |
981a95f3204d
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents:
8827
diff
changeset
|
2604 |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11920
diff
changeset
|
2605 const Station *st = Station::Get(station); |
8928
f256fabe6441
(svn r12698) -Codechange: skip orders to stations that do not have a train part anymore, just like is done for road vehicles and ships.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
2606 if (!(st->facilities & FACIL_TRAIN)) { |
f256fabe6441
(svn r12698) -Codechange: skip orders to stations that do not have a train part anymore, just like is done for road vehicles and ships.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
2607 /* The destination station has no trainstation tiles. */ |
17194
b590eca5d805
(svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents:
17175
diff
changeset
|
2608 this->IncrementRealOrderIndex(); |
8928
f256fabe6441
(svn r12698) -Codechange: skip orders to stations that do not have a train part anymore, just like is done for road vehicles and ships.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
2609 return 0; |
f256fabe6441
(svn r12698) -Codechange: skip orders to stations that do not have a train part anymore, just like is done for road vehicles and ships.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
2610 } |
f256fabe6441
(svn r12698) -Codechange: skip orders to stations that do not have a train part anymore, just like is done for road vehicles and ships.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
2611 |
f256fabe6441
(svn r12698) -Codechange: skip orders to stations that do not have a train part anymore, just like is done for road vehicles and ships.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
2612 return st->xy; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2613 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2614 |
6553
733ef9947fe2
(svn r9755) -Codechange: refactor some more of the begin loading stuff.
rubidium <rubidium@openttd.org>
parents:
6552
diff
changeset
|
2615 void Train::MarkDirty() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2616 { |
15127
c065afa82756
(svn r19756) -Codechange: move UpdateViewport() from Vehicle to SpecializedVehicle in order to improve performance
smatz <smatz@openttd.org>
parents:
15073
diff
changeset
|
2617 Train *v = this; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2618 do { |
12666
0275245c6c62
(svn r17121) -Fix [FS#3060]: Update vehicle position cache when the vehicle sprite changes.
frosch <frosch@openttd.org>
parents:
12635
diff
changeset
|
2619 v->UpdateViewport(false, false); |
7492
09743324277c
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium <rubidium@openttd.org>
parents:
7488
diff
changeset
|
2620 } while ((v = v->Next()) != NULL); |
6553
733ef9947fe2
(svn r9755) -Codechange: refactor some more of the begin loading stuff.
rubidium <rubidium@openttd.org>
parents:
6552
diff
changeset
|
2621 |
733ef9947fe2
(svn r9755) -Codechange: refactor some more of the begin loading stuff.
rubidium <rubidium@openttd.org>
parents:
6552
diff
changeset
|
2622 /* need to update acceleration and cached values since the goods on the train changed. */ |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
2623 this->CargoChanged(); |
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
2624 this->UpdateAcceleration(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2625 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2626 |
10214
44a5ab175885
(svn r14436) -Fix [FS#1793]: (fast) trains would sometimes move one time too often/little when moving from diagonal<->non-diagonal tracks (iguannab)
rubidium <rubidium@openttd.org>
parents:
10208
diff
changeset
|
2627 /** |
15002
baf0e12ad2b4
(svn r19614) -Codechange: "it's" => "its" where appropriate
smatz <smatz@openttd.org>
parents:
14898
diff
changeset
|
2628 * This function looks at the vehicle and updates its speed (cur_speed |
10214
44a5ab175885
(svn r14436) -Fix [FS#1793]: (fast) trains would sometimes move one time too often/little when moving from diagonal<->non-diagonal tracks (iguannab)
rubidium <rubidium@openttd.org>
parents:
10208
diff
changeset
|
2629 * and subspeed) variables. Furthermore, it returns the distance that |
15436
a90f03aeb026
(svn r20079) -Codechange [FS#3922]: Add helper functions to deal with the 192-256-magic of vehicle movement.
frosch <frosch@openttd.org>
parents:
15363
diff
changeset
|
2630 * the train can drive this tick. #Vehicle::GetAdvanceDistance() determines |
a90f03aeb026
(svn r20079) -Codechange [FS#3922]: Add helper functions to deal with the 192-256-magic of vehicle movement.
frosch <frosch@openttd.org>
parents:
15363
diff
changeset
|
2631 * the distance to drive before moving a step on the map. |
10214
44a5ab175885
(svn r14436) -Fix [FS#1793]: (fast) trains would sometimes move one time too often/little when moving from diagonal<->non-diagonal tracks (iguannab)
rubidium <rubidium@openttd.org>
parents:
10208
diff
changeset
|
2632 * @return distance to drive. |
44a5ab175885
(svn r14436) -Fix [FS#1793]: (fast) trains would sometimes move one time too often/little when moving from diagonal<->non-diagonal tracks (iguannab)
rubidium <rubidium@openttd.org>
parents:
10208
diff
changeset
|
2633 */ |
14284
fc532d11eb85
(svn r18836) -Codechange: make TrainUpdateSpeed a class function and update some comments (Terkhen)
rubidium <rubidium@openttd.org>
parents:
14261
diff
changeset
|
2634 int Train::UpdateSpeed() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2635 { |
14286
f96af1b6a264
(svn r18838) -Codechange [FS#3524]: reorganisation of the train acceleration code plus some minor optimisations (Terkhen)
rubidium <rubidium@openttd.org>
parents:
14284
diff
changeset
|
2636 switch (_settings_game.vehicle.train_acceleration_model) { |
f96af1b6a264
(svn r18838) -Codechange [FS#3524]: reorganisation of the train acceleration code plus some minor optimisations (Terkhen)
rubidium <rubidium@openttd.org>
parents:
14284
diff
changeset
|
2637 default: NOT_REACHED(); |
14406
5f93639271ee
(svn r18963) -Codechange: Give AccelerationModel a generical name.
terkhen <terkhen@openttd.org>
parents:
14384
diff
changeset
|
2638 case AM_ORIGINAL: |
17175
b21a59ab8453
(svn r21914) -Codechange: move the algorithmic part of Train::UpdateSpeed to a function in GroundVehicle
rubidium <rubidium@openttd.org>
parents:
17172
diff
changeset
|
2639 return this->DoUpdateSpeed(this->acceleration * (this->GetAccelerationStatus() == AS_BRAKE ? -4 : 2), 0, this->gcache.cached_max_track_speed); |
b21a59ab8453
(svn r21914) -Codechange: move the algorithmic part of Train::UpdateSpeed to a function in GroundVehicle
rubidium <rubidium@openttd.org>
parents:
17172
diff
changeset
|
2640 |
14406
5f93639271ee
(svn r18963) -Codechange: Give AccelerationModel a generical name.
terkhen <terkhen@openttd.org>
parents:
14384
diff
changeset
|
2641 case AM_REALISTIC: |
17175
b21a59ab8453
(svn r21914) -Codechange: move the algorithmic part of Train::UpdateSpeed to a function in GroundVehicle
rubidium <rubidium@openttd.org>
parents:
17172
diff
changeset
|
2642 return this->DoUpdateSpeed(this->GetAcceleration(), this->GetAccelerationStatus() == AS_BRAKE ? 0 : 2, this->GetCurrentMaxSpeed()); |
14289
d4cfa529dcec
(svn r18841) -Fix (r16869): Default-waypoint was drawn incorrectly for monorail and maglev in the waypoint picker.
frosch <frosch@openttd.org>
parents:
14286
diff
changeset
|
2643 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2644 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2645 |
16372
ea86953aa185
(svn r21088) -Doc: Additions/corrections of doxygen comments.
alberth <alberth@openttd.org>
parents:
16349
diff
changeset
|
2646 /** |
ea86953aa185
(svn r21088) -Doc: Additions/corrections of doxygen comments.
alberth <alberth@openttd.org>
parents:
16349
diff
changeset
|
2647 * Trains enters a station, send out a news item if it is the first train, and start loading. |
ea86953aa185
(svn r21088) -Doc: Additions/corrections of doxygen comments.
alberth <alberth@openttd.org>
parents:
16349
diff
changeset
|
2648 * @param v Train that entered the station. |
ea86953aa185
(svn r21088) -Doc: Additions/corrections of doxygen comments.
alberth <alberth@openttd.org>
parents:
16349
diff
changeset
|
2649 * @param station Station visited. |
ea86953aa185
(svn r21088) -Doc: Additions/corrections of doxygen comments.
alberth <alberth@openttd.org>
parents:
16349
diff
changeset
|
2650 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
2651 static void TrainEnterStation(Train *v, StationID station) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2652 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2653 v->last_station_visited = station; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2654 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2655 /* check if a train ever visited this station before */ |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11920
diff
changeset
|
2656 Station *st = Station::Get(station); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2657 if (!(st->had_vehicle_of_type & HVOT_TRAIN)) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2658 st->had_vehicle_of_type |= HVOT_TRAIN; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2659 SetDParam(0, st->index); |
12010
d0bf08a7c260
(svn r16416) -Fix [FS#2912]: Rework deleting of news when referenced vehicles/stations/industries are deleted.
frosch <frosch@openttd.org>
parents:
12008
diff
changeset
|
2660 AddVehicleNewsItem( |
11730
a39da1e4c1f5
(svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents:
11701
diff
changeset
|
2661 STR_NEWS_FIRST_TRAIN_ARRIVAL, |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10192
diff
changeset
|
2662 v->owner == _local_company ? NS_ARRIVAL_COMPANY : NS_ARRIVAL_OTHER, |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2663 v->index, |
10123
57aa34285d05
(svn r14307) -Fix: when deleting a station, remove news items regarding it
smatz <smatz@openttd.org>
parents:
10103
diff
changeset
|
2664 st->index |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2665 ); |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
10690
diff
changeset
|
2666 AI::NewEvent(v->owner, new AIEventStationFirstVehicle(st->index, v->index)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2667 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2668 |
15362
834b4f9842c2
(svn r20005) -Codechange: Enumify force_proceed.
frosch <frosch@openttd.org>
parents:
15351
diff
changeset
|
2669 v->force_proceed = TFP_NONE; |
15351
6adf1d7d80cd
(svn r19992) -Fix [FS#3878]: Clear force_proceed when entering depots and when loading.
frosch <frosch@openttd.org>
parents:
15320
diff
changeset
|
2670 SetWindowDirty(WC_VEHICLE_VIEW, v->index); |
6adf1d7d80cd
(svn r19992) -Fix [FS#3878]: Clear force_proceed when entering depots and when loading.
frosch <frosch@openttd.org>
parents:
15320
diff
changeset
|
2671 |
6550
2fa52ce08b41
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium <rubidium@openttd.org>
parents:
6546
diff
changeset
|
2672 v->BeginLoading(); |
9003
ac23e012c9d7
(svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents:
9000
diff
changeset
|
2673 |
15935
a4fa352275f4
(svn r20623) -Codechange: unify the storing of animation related information
rubidium <rubidium@openttd.org>
parents:
15899
diff
changeset
|
2674 TriggerStationAnimation(st, v->tile, SAT_TRAIN_ARRIVES); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2675 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2676 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2677 /* Check if the vehicle is compatible with the specified tile */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
2678 static inline bool CheckCompatibleRail(const Train *v, TileIndex tile) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2679 { |
16547
a11cd939c335
(svn r21273) -Codechange: Return values should start at the same line.
alberth <alberth@openttd.org>
parents:
16511
diff
changeset
|
2680 return IsTileOwner(tile, v->owner) && |
a11cd939c335
(svn r21273) -Codechange: Return values should start at the same line.
alberth <alberth@openttd.org>
parents:
16511
diff
changeset
|
2681 (!v->IsFrontEngine() || HasBit(v->compatible_railtypes, GetRailType(tile))); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2682 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2683 |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6247
diff
changeset
|
2684 struct RailtypeSlowdownParams { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2685 byte small_turn, large_turn; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2686 byte z_up; // fraction to remove when moving up |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2687 byte z_down; // fraction to remove when moving down |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6247
diff
changeset
|
2688 }; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2689 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2690 static const RailtypeSlowdownParams _railtype_slowdown[] = { |
11368
82c90cd591ab
(svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents:
11351
diff
changeset
|
2691 /* normal accel */ |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2692 {256 / 4, 256 / 2, 256 / 4, 2}, ///< normal |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2693 {256 / 4, 256 / 2, 256 / 4, 2}, ///< electrified |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2694 {256 / 4, 256 / 2, 256 / 4, 2}, ///< monorail |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2695 {0, 256 / 2, 256 / 4, 2}, ///< maglev |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2696 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2697 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2698 /** Modify the speed of the vehicle due to a change in altitude */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
2699 static inline void AffectSpeedByZChange(Train *v, byte old_z) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2700 { |
14406
5f93639271ee
(svn r18963) -Codechange: Give AccelerationModel a generical name.
terkhen <terkhen@openttd.org>
parents:
14384
diff
changeset
|
2701 if (old_z == v->z_pos || _settings_game.vehicle.train_acceleration_model != AM_ORIGINAL) return; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2702 |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
2703 const RailtypeSlowdownParams *rsp = &_railtype_slowdown[v->railtype]; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2704 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2705 if (old_z < v->z_pos) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2706 v->cur_speed -= (v->cur_speed * rsp->z_up >> 8); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2707 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2708 uint16 spd = v->cur_speed + rsp->z_down; |
16785
775f357828e3
(svn r21518) -Codechange: Rename AccelerationCache to GroundVehicleCache.
terkhen <terkhen@openttd.org>
parents:
16776
diff
changeset
|
2709 if (spd <= v->gcache.cached_max_track_speed) v->cur_speed = spd; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2710 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2711 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2712 |
9821
2b151a3dc570
(svn r13963) -Codechange [YAPP]: Reserve a track when entering a PBS block through a conventional signal. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9820
diff
changeset
|
2713 static bool TrainMovedChangeSignals(TileIndex tile, DiagDirection dir) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2714 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2715 if (IsTileType(tile, MP_RAILWAY) && |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2716 GetRailTileType(tile) == RAIL_TILE_SIGNALS) { |
8794
0a524ed2b87b
(svn r12532) -Cleanup: Replace two tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8793
diff
changeset
|
2717 TrackdirBits tracks = TrackBitsToTrackdirBits(GetTrackBits(tile)) & DiagdirReachesTrackdirs(dir); |
0a524ed2b87b
(svn r12532) -Cleanup: Replace two tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8793
diff
changeset
|
2718 Trackdir trackdir = FindFirstTrackdir(tracks); |
9821
2b151a3dc570
(svn r13963) -Codechange [YAPP]: Reserve a track when entering a PBS block through a conventional signal. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9820
diff
changeset
|
2719 if (UpdateSignalsOnSegment(tile, TrackdirToExitdir(trackdir), GetTileOwner(tile)) == SIGSEG_PBS && HasSignalOnTrackdir(tile, trackdir)) { |
2b151a3dc570
(svn r13963) -Codechange [YAPP]: Reserve a track when entering a PBS block through a conventional signal. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9820
diff
changeset
|
2720 /* A PBS block with a non-PBS signal facing us? */ |
2b151a3dc570
(svn r13963) -Codechange [YAPP]: Reserve a track when entering a PBS block through a conventional signal. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9820
diff
changeset
|
2721 if (!IsPbsSignal(GetSignalType(tile, TrackdirToTrack(trackdir)))) return true; |
2b151a3dc570
(svn r13963) -Codechange [YAPP]: Reserve a track when entering a PBS block through a conventional signal. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9820
diff
changeset
|
2722 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2723 } |
9821
2b151a3dc570
(svn r13963) -Codechange [YAPP]: Reserve a track when entering a PBS block through a conventional signal. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9820
diff
changeset
|
2724 return false; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2725 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2726 |
12423
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2727 /** |
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2728 * Tries to reserve track under whole train consist |
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2729 */ |
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2730 void Train::ReserveTrackUnderConsist() const |
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2731 { |
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2732 for (const Train *u = this; u != NULL; u = u->Next()) { |
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2733 switch (u->track) { |
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2734 case TRACK_BIT_WORMHOLE: |
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2735 TryReserveRailTrack(u->tile, DiagDirToDiagTrack(GetTunnelBridgeDirection(u->tile))); |
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2736 break; |
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2737 case TRACK_BIT_DEPOT: |
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2738 break; |
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2739 default: |
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2740 TryReserveRailTrack(u->tile, TrackBitsToTrack(u->track)); |
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2741 break; |
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2742 } |
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2743 } |
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2744 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2745 |
13873
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13842
diff
changeset
|
2746 uint Train::Crash(bool flooded) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2747 { |
13873
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13842
diff
changeset
|
2748 uint pass = 0; |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13842
diff
changeset
|
2749 if (this->IsFrontEngine()) { |
16769
1a7dbc448da5
(svn r21502) -Change/Fix [FS#3991] (r150, r18402): before r18402 a train crash caused 2 "driver" deaths and a flooding 4 (added in r150). In r18402 the counting was merged and the flooding code was taken for counting drivers. Given those numbers were inconsistent (unlike for other vehicles) we better use the real original amount of driver deaths instead of the erroneous amount.
rubidium <rubidium@openttd.org>
parents:
16547
diff
changeset
|
2750 pass += 2; // driver |
13873
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13842
diff
changeset
|
2751 |
12693
3916fe720543
(svn r17152) -Fix: A stuck train could free the reservation of another train if it was reversed or did crash.
michi_cc <michi_cc@openttd.org>
parents:
12692
diff
changeset
|
2752 /* Remove the reserved path in front of the train if it is not stuck. |
3916fe720543
(svn r17152) -Fix: A stuck train could free the reservation of another train if it was reversed or did crash.
michi_cc <michi_cc@openttd.org>
parents:
12692
diff
changeset
|
2753 * Also clear all reserved tracks the train is currently on. */ |
13873
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13842
diff
changeset
|
2754 if (!HasBit(this->flags, VRF_TRAIN_STUCK)) FreeTrainTrackReservation(this); |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13842
diff
changeset
|
2755 for (const Train *v = this; v != NULL; v = v->Next()) { |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13842
diff
changeset
|
2756 ClearPathReservation(v, v->tile, v->GetVehicleTrackdir()); |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13842
diff
changeset
|
2757 if (IsTileType(v->tile, MP_TUNNELBRIDGE)) { |
9845
ee10319a40b6
(svn r13989) -Fix [FS#2186] (r13953): YAPP track reservation for crashed trains was broken for depots and wormholes (michi_cc).
rubidium <rubidium@openttd.org>
parents:
9840
diff
changeset
|
2758 /* ClearPathReservation will not free the wormhole exit |
ee10319a40b6
(svn r13989) -Fix [FS#2186] (r13953): YAPP track reservation for crashed trains was broken for depots and wormholes (michi_cc).
rubidium <rubidium@openttd.org>
parents:
9840
diff
changeset
|
2759 * if the train has just entered the wormhole. */ |
13873
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13842
diff
changeset
|
2760 SetTunnelBridgeReservation(GetOtherTunnelBridgeEnd(v->tile), false); |
9845
ee10319a40b6
(svn r13989) -Fix [FS#2186] (r13953): YAPP track reservation for crashed trains was broken for depots and wormholes (michi_cc).
rubidium <rubidium@openttd.org>
parents:
9840
diff
changeset
|
2761 } |
9811
84013100eac2
(svn r13953) -Add [YAPP]: Free track reservations of crashed trains. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9810
diff
changeset
|
2762 } |
13873
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13842
diff
changeset
|
2763 |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13842
diff
changeset
|
2764 /* we may need to update crossing we were approaching, |
17137
0e25103841ef
(svn r21875) -Codechange: indentation of some comments was wrong
smatz <smatz@openttd.org>
parents:
17136
diff
changeset
|
2765 * but must be updated after the train has been marked crashed */ |
13873
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13842
diff
changeset
|
2766 TileIndex crossing = TrainApproachingCrossingTile(this); |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13842
diff
changeset
|
2767 if (crossing != INVALID_TILE) UpdateLevelCrossing(crossing); |
14384
7015f43f6a77
(svn r18941) -Fix [FS#3575]: remove the loading indicators as soon as a train crashes
yexo <yexo@openttd.org>
parents:
14382
diff
changeset
|
2768 |
7015f43f6a77
(svn r18941) -Fix [FS#3575]: remove the loading indicators as soon as a train crashes
yexo <yexo@openttd.org>
parents:
14382
diff
changeset
|
2769 /* Remove the loading indicators (if any) */ |
7015f43f6a77
(svn r18941) -Fix [FS#3575]: remove the loading indicators as soon as a train crashes
yexo <yexo@openttd.org>
parents:
14382
diff
changeset
|
2770 HideFillingPercent(&this->fill_percent_te_id); |
8271
359d451c24ef
(svn r11835) -Fix: mark depot, viewports, vehicle lists and vehicle details dirty when a train crashes
smatz <smatz@openttd.org>
parents:
8270
diff
changeset
|
2771 } |
359d451c24ef
(svn r11835) -Fix: mark depot, viewports, vehicle lists and vehicle details dirty when a train crashes
smatz <smatz@openttd.org>
parents:
8270
diff
changeset
|
2772 |
17141
4ccee6c9442b
(svn r21879) -Codechange: reset vehicle's GOINGUP/DOWN bits when it crashes
smatz <smatz@openttd.org>
parents:
17137
diff
changeset
|
2773 pass += this->GroundVehicleBase::Crash(flooded); |
13873
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13842
diff
changeset
|
2774 |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13842
diff
changeset
|
2775 this->crash_anim_pos = flooded ? 4000 : 1; // max 4440, disappear pretty fast when flooded |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13842
diff
changeset
|
2776 return pass; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2777 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2778 |
11150
7e9a1181206a
(svn r15497) -Fix (r15027): when trains crashed, AIEvent was created only for one train
smatz <smatz@openttd.org>
parents:
11149
diff
changeset
|
2779 /** |
7e9a1181206a
(svn r15497) -Fix (r15027): when trains crashed, AIEvent was created only for one train
smatz <smatz@openttd.org>
parents:
11149
diff
changeset
|
2780 * Marks train as crashed and creates an AI event. |
7e9a1181206a
(svn r15497) -Fix (r15027): when trains crashed, AIEvent was created only for one train
smatz <smatz@openttd.org>
parents:
11149
diff
changeset
|
2781 * Doesn't do anything if the train is crashed already. |
7e9a1181206a
(svn r15497) -Fix (r15027): when trains crashed, AIEvent was created only for one train
smatz <smatz@openttd.org>
parents:
11149
diff
changeset
|
2782 * @param v first vehicle of chain |
7e9a1181206a
(svn r15497) -Fix (r15027): when trains crashed, AIEvent was created only for one train
smatz <smatz@openttd.org>
parents:
11149
diff
changeset
|
2783 * @return number of victims (including 2 drivers; zero if train was already crashed) |
7e9a1181206a
(svn r15497) -Fix (r15027): when trains crashed, AIEvent was created only for one train
smatz <smatz@openttd.org>
parents:
11149
diff
changeset
|
2784 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
2785 static uint TrainCrashed(Train *v) |
11150
7e9a1181206a
(svn r15497) -Fix (r15027): when trains crashed, AIEvent was created only for one train
smatz <smatz@openttd.org>
parents:
11149
diff
changeset
|
2786 { |
12423
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2787 uint num = 0; |
12237
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2788 |
11150
7e9a1181206a
(svn r15497) -Fix (r15027): when trains crashed, AIEvent was created only for one train
smatz <smatz@openttd.org>
parents:
11149
diff
changeset
|
2789 /* do not crash train twice */ |
12423
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2790 if (!(v->vehstatus & VS_CRASHED)) { |
13873
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13842
diff
changeset
|
2791 num = v->Crash(); |
12423
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2792 AI::NewEvent(v->owner, new AIEventVehicleCrashed(v->index, v->tile, AIEventVehicleCrashed::CRASH_TRAIN)); |
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2793 } |
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2794 |
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2795 /* Try to re-reserve track under already crashed train too. |
16796
9d03c51b3f0a
(svn r21529) -Doc: update comment after function name change (Krille)
rubidium <rubidium@openttd.org>
parents:
16788
diff
changeset
|
2796 * Crash() clears the reservation! */ |
12423
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2797 v->ReserveTrackUnderConsist(); |
11150
7e9a1181206a
(svn r15497) -Fix (r15027): when trains crashed, AIEvent was created only for one train
smatz <smatz@openttd.org>
parents:
11149
diff
changeset
|
2798 |
7e9a1181206a
(svn r15497) -Fix (r15027): when trains crashed, AIEvent was created only for one train
smatz <smatz@openttd.org>
parents:
11149
diff
changeset
|
2799 return num; |
7e9a1181206a
(svn r15497) -Fix (r15027): when trains crashed, AIEvent was created only for one train
smatz <smatz@openttd.org>
parents:
11149
diff
changeset
|
2800 } |
7e9a1181206a
(svn r15497) -Fix (r15027): when trains crashed, AIEvent was created only for one train
smatz <smatz@openttd.org>
parents:
11149
diff
changeset
|
2801 |
6966
83a9857fde12
(svn r10222) -Fix [FS#892]: Only 2 trains could crash at one time as collision checking stopped on the first hit. This could cause desyncs in network games as the collision hash order is not guaranteed. (patch by B. N. Smatz)
peter1138 <peter1138@openttd.org>
parents:
6953
diff
changeset
|
2802 struct TrainCollideChecker { |
12237
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2803 Train *v; ///< vehicle we are testing for collision |
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2804 uint num; ///< number of victims if train collided |
6966
83a9857fde12
(svn r10222) -Fix [FS#892]: Only 2 trains could crash at one time as collision checking stopped on the first hit. This could cause desyncs in network games as the collision hash order is not guaranteed. (patch by B. N. Smatz)
peter1138 <peter1138@openttd.org>
parents:
6953
diff
changeset
|
2805 }; |
83a9857fde12
(svn r10222) -Fix [FS#892]: Only 2 trains could crash at one time as collision checking stopped on the first hit. This could cause desyncs in network games as the collision hash order is not guaranteed. (patch by B. N. Smatz)
peter1138 <peter1138@openttd.org>
parents:
6953
diff
changeset
|
2806 |
9775
c3caa51b9888
(svn r13912) -Codechange: remove some casts by returning the proper type instead of void*.
rubidium <rubidium@openttd.org>
parents:
9774
diff
changeset
|
2807 static Vehicle *FindTrainCollideEnum(Vehicle *v, void *data) |
6966
83a9857fde12
(svn r10222) -Fix [FS#892]: Only 2 trains could crash at one time as collision checking stopped on the first hit. This could cause desyncs in network games as the collision hash order is not guaranteed. (patch by B. N. Smatz)
peter1138 <peter1138@openttd.org>
parents:
6953
diff
changeset
|
2808 { |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2809 TrainCollideChecker *tcc = (TrainCollideChecker*)data; |
6966
83a9857fde12
(svn r10222) -Fix [FS#892]: Only 2 trains could crash at one time as collision checking stopped on the first hit. This could cause desyncs in network games as the collision hash order is not guaranteed. (patch by B. N. Smatz)
peter1138 <peter1138@openttd.org>
parents:
6953
diff
changeset
|
2810 |
12237
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2811 /* not a train or in depot */ |
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2812 if (v->type != VEH_TRAIN || Train::From(v)->track == TRACK_BIT_DEPOT) return NULL; |
8281
a3736272d02a
(svn r11845) -Codechange: simplify train collision detection a bit
smatz <smatz@openttd.org>
parents:
8271
diff
changeset
|
2813 |
17063
9f041188fc49
(svn r21800) -Fix [FS#3569]: under certain circumstances one could crash a competitor's train; take the lazy non-future proof version of the fix from the 1.0 branch as fixing the real bug is significantly more complex and might even break some backwards compatability if not done perfectly
rubidium <rubidium@openttd.org>
parents:
16796
diff
changeset
|
2814 /* do not crash into trains of another company. */ |
9f041188fc49
(svn r21800) -Fix [FS#3569]: under certain circumstances one could crash a competitor's train; take the lazy non-future proof version of the fix from the 1.0 branch as fixing the real bug is significantly more complex and might even break some backwards compatability if not done perfectly
rubidium <rubidium@openttd.org>
parents:
16796
diff
changeset
|
2815 if (v->owner != tcc->v->owner) return NULL; |
9f041188fc49
(svn r21800) -Fix [FS#3569]: under certain circumstances one could crash a competitor's train; take the lazy non-future proof version of the fix from the 1.0 branch as fixing the real bug is significantly more complex and might even break some backwards compatability if not done perfectly
rubidium <rubidium@openttd.org>
parents:
16796
diff
changeset
|
2816 |
8281
a3736272d02a
(svn r11845) -Codechange: simplify train collision detection a bit
smatz <smatz@openttd.org>
parents:
8271
diff
changeset
|
2817 /* get first vehicle now to make most usual checks faster */ |
12237
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2818 Train *coll = Train::From(v)->First(); |
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2819 |
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2820 /* can't collide with own wagons */ |
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2821 if (coll == tcc->v) return NULL; |
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2822 |
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2823 int x_diff = v->x_pos - tcc->v->x_pos; |
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2824 int y_diff = v->y_pos - tcc->v->y_pos; |
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2825 |
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2826 /* Do fast calculation to check whether trains are not in close vicinity |
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2827 * and quickly reject trains distant enough for any collision. |
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2828 * Differences are shifted by 7, mapping range [-7 .. 8] into [0 .. 15] |
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2829 * Differences are then ORed and then we check for any higher bits */ |
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2830 uint hash = (y_diff + 7) | (x_diff + 7); |
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2831 if (hash & ~15) return NULL; |
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2832 |
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2833 /* Slower check using multiplication */ |
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2834 if (x_diff * x_diff + y_diff * y_diff > 25) return NULL; |
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2835 |
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2836 /* Happens when there is a train under bridge next to bridge head */ |
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2837 if (abs(v->z_pos - tcc->v->z_pos) > 5) return NULL; |
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2838 |
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2839 /* crash both trains */ |
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2840 tcc->num += TrainCrashed(tcc->v); |
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2841 tcc->num += TrainCrashed(coll); |
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2842 |
52ee820c1243
(svn r16652) -Codechange: use less strict, but faster check for quickly bailing out in FindTrainCollideEnum() (Bilbo)
smatz <smatz@openttd.org>
parents:
12231
diff
changeset
|
2843 return NULL; // continue searching |
6966
83a9857fde12
(svn r10222) -Fix [FS#892]: Only 2 trains could crash at one time as collision checking stopped on the first hit. This could cause desyncs in network games as the collision hash order is not guaranteed. (patch by B. N. Smatz)
peter1138 <peter1138@openttd.org>
parents:
6953
diff
changeset
|
2844 } |
83a9857fde12
(svn r10222) -Fix [FS#892]: Only 2 trains could crash at one time as collision checking stopped on the first hit. This could cause desyncs in network games as the collision hash order is not guaranteed. (patch by B. N. Smatz)
peter1138 <peter1138@openttd.org>
parents:
6953
diff
changeset
|
2845 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2846 /** |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2847 * Checks whether the specified train has a collision with another vehicle. If |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2848 * so, destroys this vehicle, and the other vehicle if its subtype has TS_Front. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2849 * Reports the incident in a flashy news item, modifies station ratings and |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2850 * plays a sound. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2851 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
2852 static bool CheckTrainCollision(Train *v) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2853 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2854 /* can't collide in depot */ |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
2855 if (v->track == TRACK_BIT_DEPOT) return false; |
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
2856 |
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
2857 assert(v->track == TRACK_BIT_WORMHOLE || TileVirtXY(v->x_pos, v->y_pos) == v->tile); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2858 |
6150 | 2859 TrainCollideChecker tcc; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2860 tcc.v = v; |
6966
83a9857fde12
(svn r10222) -Fix [FS#892]: Only 2 trains could crash at one time as collision checking stopped on the first hit. This could cause desyncs in network games as the collision hash order is not guaranteed. (patch by B. N. Smatz)
peter1138 <peter1138@openttd.org>
parents:
6953
diff
changeset
|
2861 tcc.num = 0; |
83a9857fde12
(svn r10222) -Fix [FS#892]: Only 2 trains could crash at one time as collision checking stopped on the first hit. This could cause desyncs in network games as the collision hash order is not guaranteed. (patch by B. N. Smatz)
peter1138 <peter1138@openttd.org>
parents:
6953
diff
changeset
|
2862 |
83a9857fde12
(svn r10222) -Fix [FS#892]: Only 2 trains could crash at one time as collision checking stopped on the first hit. This could cause desyncs in network games as the collision hash order is not guaranteed. (patch by B. N. Smatz)
peter1138 <peter1138@openttd.org>
parents:
6953
diff
changeset
|
2863 /* find colliding vehicles */ |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
2864 if (v->track == TRACK_BIT_WORMHOLE) { |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9992
diff
changeset
|
2865 FindVehicleOnPos(v->tile, &tcc, FindTrainCollideEnum); |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9992
diff
changeset
|
2866 FindVehicleOnPos(GetOtherTunnelBridgeEnd(v->tile), &tcc, FindTrainCollideEnum); |
7371
e03ba4271be4
(svn r10734) -Fix [FS#1030]: Revert r10513) and add special cases for collision detection on bridges/tunnels.
peter1138 <peter1138@openttd.org>
parents:
7334
diff
changeset
|
2867 } else { |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9992
diff
changeset
|
2868 FindVehicleOnPosXY(v->x_pos, v->y_pos, &tcc, FindTrainCollideEnum); |
7371
e03ba4271be4
(svn r10734) -Fix [FS#1030]: Revert r10513) and add special cases for collision detection on bridges/tunnels.
peter1138 <peter1138@openttd.org>
parents:
7334
diff
changeset
|
2869 } |
6966
83a9857fde12
(svn r10222) -Fix [FS#892]: Only 2 trains could crash at one time as collision checking stopped on the first hit. This could cause desyncs in network games as the collision hash order is not guaranteed. (patch by B. N. Smatz)
peter1138 <peter1138@openttd.org>
parents:
6953
diff
changeset
|
2870 |
83a9857fde12
(svn r10222) -Fix [FS#892]: Only 2 trains could crash at one time as collision checking stopped on the first hit. This could cause desyncs in network games as the collision hash order is not guaranteed. (patch by B. N. Smatz)
peter1138 <peter1138@openttd.org>
parents:
6953
diff
changeset
|
2871 /* any dead -> no crash */ |
10282
9f1f7dad1803
(svn r14521) -Fix [FS#2378]: fast trains could continue to move after a crash
glx <glx@openttd.org>
parents:
10261
diff
changeset
|
2872 if (tcc.num == 0) return false; |
6966
83a9857fde12
(svn r10222) -Fix [FS#892]: Only 2 trains could crash at one time as collision checking stopped on the first hit. This could cause desyncs in network games as the collision hash order is not guaranteed. (patch by B. N. Smatz)
peter1138 <peter1138@openttd.org>
parents:
6953
diff
changeset
|
2873 |
83a9857fde12
(svn r10222) -Fix [FS#892]: Only 2 trains could crash at one time as collision checking stopped on the first hit. This could cause desyncs in network games as the collision hash order is not guaranteed. (patch by B. N. Smatz)
peter1138 <peter1138@openttd.org>
parents:
6953
diff
changeset
|
2874 SetDParam(0, tcc.num); |
12010
d0bf08a7c260
(svn r16416) -Fix [FS#2912]: Rework deleting of news when referenced vehicles/stations/industries are deleted.
frosch <frosch@openttd.org>
parents:
12008
diff
changeset
|
2875 AddVehicleNewsItem(STR_NEWS_TRAIN_CRASH, |
d0bf08a7c260
(svn r16416) -Fix [FS#2912]: Rework deleting of news when referenced vehicles/stations/industries are deleted.
frosch <frosch@openttd.org>
parents:
12008
diff
changeset
|
2876 NS_ACCIDENT, |
d0bf08a7c260
(svn r16416) -Fix [FS#2912]: Rework deleting of news when referenced vehicles/stations/industries are deleted.
frosch <frosch@openttd.org>
parents:
12008
diff
changeset
|
2877 v->index |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2878 ); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2879 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2880 ModifyStationRatingAround(v->tile, v->owner, -160, 30); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2881 SndPlayVehicleFx(SND_13_BIG_CRASH, v); |
10282
9f1f7dad1803
(svn r14521) -Fix [FS#2378]: fast trains could continue to move after a crash
glx <glx@openttd.org>
parents:
10261
diff
changeset
|
2882 return true; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2883 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2884 |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
2885 static Vehicle *CheckTrainAtSignal(Vehicle *v, void *data) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2886 { |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
2887 if (v->type != VEH_TRAIN || (v->vehstatus & VS_CRASHED)) return NULL; |
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
2888 |
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
2889 Train *t = Train::From(v); |
9699
128a1a7ade68
(svn r13806) -Fix [FS#2162]: checking for train waiting at other side of two-way signal was broken
smatz <smatz@openttd.org>
parents:
9628
diff
changeset
|
2890 DiagDirection exitdir = *(DiagDirection *)data; |
128a1a7ade68
(svn r13806) -Fix [FS#2162]: checking for train waiting at other side of two-way signal was broken
smatz <smatz@openttd.org>
parents:
9628
diff
changeset
|
2891 |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
2892 /* not front engine of a train, inside wormhole or depot, crashed */ |
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
2893 if (!t->IsFrontEngine() || !(t->track & TRACK_BIT_MASK)) return NULL; |
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
2894 |
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
2895 if (t->cur_speed > 5 || TrainExitDir(t->direction, t->track) != exitdir) return NULL; |
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
2896 |
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
2897 return t; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2898 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2899 |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
2900 static void TrainController(Train *v, Vehicle *nomove) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2901 { |
12085
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
2902 Train *first = v->First(); |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
2903 Train *prev; |
12085
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
2904 bool direction_changed = false; // has direction of any part changed? |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2905 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2906 /* For every vehicle after and including the given vehicle */ |
8710
d087f1604050
(svn r12384) -Fix (r2428): do not disconnect train when reversing, it may 'think' it is whole in a depot
smatz <smatz@openttd.org>
parents:
8706
diff
changeset
|
2907 for (prev = v->Previous(); v != nomove; prev = v, v = v->Next()) { |
6871
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
2908 DiagDirection enterdir = DIAGDIR_BEGIN; |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
2909 bool update_signals_crossing = false; // will we update signals or crossing state? |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2910 |
6153 | 2911 GetNewVehiclePosResult gp = GetNewVehiclePos(v); |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
2912 if (v->track != TRACK_BIT_WORMHOLE) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2913 /* Not inside tunnel */ |
6152 | 2914 if (gp.old_tile == gp.new_tile) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2915 /* Staying in the old tile */ |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
2916 if (v->track == TRACK_BIT_DEPOT) { |
5994
f7885ece4c67
(svn r8703) -Codechange/cleanup: some magic numbers -> enums and other small coding style changes to the ShipController and TrainController.
rubidium <rubidium@openttd.org>
parents:
5993
diff
changeset
|
2917 /* Inside depot */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2918 gp.x = v->x_pos; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2919 gp.y = v->y_pos; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2920 } else { |
5994
f7885ece4c67
(svn r8703) -Codechange/cleanup: some magic numbers -> enums and other small coding style changes to the ShipController and TrainController.
rubidium <rubidium@openttd.org>
parents:
5993
diff
changeset
|
2921 /* Not inside depot */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2922 |
10655
66da07b05801
(svn r14957) -Fix [FS#2516]: Do not abort train movement, when we are just about to reach the end of the platform.
frosch <frosch@openttd.org>
parents:
10647
diff
changeset
|
2923 /* Reverse when we are at the end of the track already, do not move to the new position */ |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
2924 if (v->IsFrontEngine() && !TrainCheckIfLineEnds(v)) return; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2925 |
6150 | 2926 uint32 r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y); |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
2927 if (HasBit(r, VETS_CANNOT_ENTER)) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2928 goto invalid_rail; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2929 } |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
2930 if (HasBit(r, VETS_ENTERED_STATION)) { |
10655
66da07b05801
(svn r14957) -Fix [FS#2516]: Do not abort train movement, when we are just about to reach the end of the platform.
frosch <frosch@openttd.org>
parents:
10647
diff
changeset
|
2931 /* The new position is the end of the platform */ |
5991
1b793d99b5ba
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium <rubidium@openttd.org>
parents:
5944
diff
changeset
|
2932 TrainEnterStation(v, r >> VETS_STATION_ID_OFFSET); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2933 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2934 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2935 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2936 /* A new tile is about to be entered. */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2937 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2938 /* Determine what direction we're entering the new tile from */ |
11431
936773e993af
(svn r15789) -Codechange: Add DiagdirBetweenTiles() and use it.
frosch <frosch@openttd.org>
parents:
11368
diff
changeset
|
2939 enterdir = DiagdirBetweenTiles(gp.old_tile, gp.new_tile); |
5994
f7885ece4c67
(svn r8703) -Codechange/cleanup: some magic numbers -> enums and other small coding style changes to the ShipController and TrainController.
rubidium <rubidium@openttd.org>
parents:
5993
diff
changeset
|
2940 assert(IsValidDiagDirection(enterdir)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2941 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2942 /* Get the status of the tracks in the new tile and mask |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2943 * away the bits that aren't reachable. */ |
8794
0a524ed2b87b
(svn r12532) -Cleanup: Replace two tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8793
diff
changeset
|
2944 TrackStatus ts = GetTileTrackStatus(gp.new_tile, TRANSPORT_RAIL, 0, ReverseDiagDir(enterdir)); |
0a524ed2b87b
(svn r12532) -Cleanup: Replace two tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8793
diff
changeset
|
2945 TrackdirBits reachable_trackdirs = DiagdirReachesTrackdirs(enterdir); |
0a524ed2b87b
(svn r12532) -Cleanup: Replace two tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8793
diff
changeset
|
2946 |
0a524ed2b87b
(svn r12532) -Cleanup: Replace two tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8793
diff
changeset
|
2947 TrackdirBits trackdirbits = TrackStatusToTrackdirBits(ts) & reachable_trackdirs; |
0a524ed2b87b
(svn r12532) -Cleanup: Replace two tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8793
diff
changeset
|
2948 TrackBits red_signals = TrackdirBitsToTrackBits(TrackStatusToRedSignals(ts) & reachable_trackdirs); |
8616
9e46ac001a8c
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch <frosch@openttd.org>
parents:
8614
diff
changeset
|
2949 |
9e46ac001a8c
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch <frosch@openttd.org>
parents:
8614
diff
changeset
|
2950 TrackBits bits = TrackdirBitsToTrackBits(trackdirbits); |
13833
ad09d18a3e34
(svn r18362) -Cleanup: remove OPF for RVs and NTP to clean up lots of code and simplify some things for the future
rubidium <rubidium@openttd.org>
parents:
13832
diff
changeset
|
2951 if (_settings_game.pf.forbid_90_deg && prev == NULL) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2952 /* We allow wagons to make 90 deg turns, because forbid_90_deg |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2953 * can be switched on halfway a turn */ |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
2954 bits &= ~TrackCrossesTracks(FindFirstTrack(v->track)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2955 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2956 |
5994
f7885ece4c67
(svn r8703) -Codechange/cleanup: some magic numbers -> enums and other small coding style changes to the ShipController and TrainController.
rubidium <rubidium@openttd.org>
parents:
5993
diff
changeset
|
2957 if (bits == TRACK_BIT_NONE) goto invalid_rail; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2958 |
15820
59fd8293b2ee
(svn r20499) -Doc: Spelling fixes, and one doxygen comment addition.
alberth <alberth@openttd.org>
parents:
15763
diff
changeset
|
2959 /* Check if the new tile constrains tracks that are compatible |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2960 * with the current train, if not, bail out. */ |
5994
f7885ece4c67
(svn r8703) -Codechange/cleanup: some magic numbers -> enums and other small coding style changes to the ShipController and TrainController.
rubidium <rubidium@openttd.org>
parents:
5993
diff
changeset
|
2961 if (!CheckCompatibleRail(v, gp.new_tile)) goto invalid_rail; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2962 |
6150 | 2963 TrackBits chosen_track; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2964 if (prev == NULL) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2965 /* Currently the locomotive is active. Determine which one of the |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2966 * available tracks to choose */ |
9810
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2967 chosen_track = TrackToTrackBits(ChooseTrainTrack(v, gp.new_tile, enterdir, bits, false, NULL, true)); |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2968 assert(chosen_track & (bits | GetReservedTrackbits(gp.new_tile))); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2969 |
15362
834b4f9842c2
(svn r20005) -Codechange: Enumify force_proceed.
frosch <frosch@openttd.org>
parents:
15351
diff
changeset
|
2970 if (v->force_proceed != TFP_NONE && IsPlainRailTile(gp.new_tile) && HasSignals(gp.new_tile)) { |
13977
bb2258bdc43d
(svn r18515) -Change: make it visible when you're to pass the next signal on danger and possible to cancel it
rubidium <rubidium@openttd.org>
parents:
13958
diff
changeset
|
2971 /* For each signal we find decrease the counter by one. |
bb2258bdc43d
(svn r18515) -Change: make it visible when you're to pass the next signal on danger and possible to cancel it
rubidium <rubidium@openttd.org>
parents:
13958
diff
changeset
|
2972 * We start at two, so the first signal we pass decreases |
bb2258bdc43d
(svn r18515) -Change: make it visible when you're to pass the next signal on danger and possible to cancel it
rubidium <rubidium@openttd.org>
parents:
13958
diff
changeset
|
2973 * this to one, then if we reach the next signal it is |
bb2258bdc43d
(svn r18515) -Change: make it visible when you're to pass the next signal on danger and possible to cancel it
rubidium <rubidium@openttd.org>
parents:
13958
diff
changeset
|
2974 * decreased to zero and we won't pass that new signal. */ |
bb2258bdc43d
(svn r18515) -Change: make it visible when you're to pass the next signal on danger and possible to cancel it
rubidium <rubidium@openttd.org>
parents:
13958
diff
changeset
|
2975 Trackdir dir = FindFirstTrackdir(trackdirbits); |
bb2258bdc43d
(svn r18515) -Change: make it visible when you're to pass the next signal on danger and possible to cancel it
rubidium <rubidium@openttd.org>
parents:
13958
diff
changeset
|
2976 if (GetSignalType(gp.new_tile, TrackdirToTrack(dir)) != SIGTYPE_PBS || |
bb2258bdc43d
(svn r18515) -Change: make it visible when you're to pass the next signal on danger and possible to cancel it
rubidium <rubidium@openttd.org>
parents:
13958
diff
changeset
|
2977 !HasSignalOnTrackdir(gp.new_tile, ReverseTrackdir(dir))) { |
bb2258bdc43d
(svn r18515) -Change: make it visible when you're to pass the next signal on danger and possible to cancel it
rubidium <rubidium@openttd.org>
parents:
13958
diff
changeset
|
2978 /* However, we do not want to be stopped by PBS signals |
bb2258bdc43d
(svn r18515) -Change: make it visible when you're to pass the next signal on danger and possible to cancel it
rubidium <rubidium@openttd.org>
parents:
13958
diff
changeset
|
2979 * entered via the back. */ |
15362
834b4f9842c2
(svn r20005) -Codechange: Enumify force_proceed.
frosch <frosch@openttd.org>
parents:
15351
diff
changeset
|
2980 v->force_proceed = (v->force_proceed == TFP_SIGNAL) ? TFP_STUCK : TFP_NONE; |
13977
bb2258bdc43d
(svn r18515) -Change: make it visible when you're to pass the next signal on danger and possible to cancel it
rubidium <rubidium@openttd.org>
parents:
13958
diff
changeset
|
2981 SetWindowDirty(WC_VEHICLE_VIEW, v->index); |
bb2258bdc43d
(svn r18515) -Change: make it visible when you're to pass the next signal on danger and possible to cancel it
rubidium <rubidium@openttd.org>
parents:
13958
diff
changeset
|
2982 } |
bb2258bdc43d
(svn r18515) -Change: make it visible when you're to pass the next signal on danger and possible to cancel it
rubidium <rubidium@openttd.org>
parents:
13958
diff
changeset
|
2983 } |
bb2258bdc43d
(svn r18515) -Change: make it visible when you're to pass the next signal on danger and possible to cancel it
rubidium <rubidium@openttd.org>
parents:
13958
diff
changeset
|
2984 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2985 /* Check if it's a red signal and that force proceed is not clicked. */ |
15362
834b4f9842c2
(svn r20005) -Codechange: Enumify force_proceed.
frosch <frosch@openttd.org>
parents:
15351
diff
changeset
|
2986 if ((red_signals & chosen_track) && v->force_proceed == TFP_NONE) { |
8616
9e46ac001a8c
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch <frosch@openttd.org>
parents:
8614
diff
changeset
|
2987 /* In front of a red signal */ |
9e46ac001a8c
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch <frosch@openttd.org>
parents:
8614
diff
changeset
|
2988 Trackdir i = FindFirstTrackdir(trackdirbits); |
6151 | 2989 |
9808
fa8743b489ff
(svn r13950) -Add [YAPP]: Trains can now also be in a 'stuck' state when waiting on a path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9775
diff
changeset
|
2990 /* Don't handle stuck trains here. */ |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
2991 if (HasBit(v->flags, VRF_TRAIN_STUCK)) return; |
9808
fa8743b489ff
(svn r13950) -Add [YAPP]: Trains can now also be in a 'stuck' state when waiting on a path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9775
diff
changeset
|
2992 |
6151 | 2993 if (!HasSignalOnTrackdir(gp.new_tile, ReverseTrackdir(i))) { |
2994 v->cur_speed = 0; | |
2995 v->subspeed = 0; | |
2996 v->progress = 255 - 100; | |
17223
a1dda316ecbe
(svn r21962) -Feature-ish: GUI setting to disable reversing at signals
rubidium <rubidium@openttd.org>
parents:
17221
diff
changeset
|
2997 if (!_settings_game.pf.reverse_at_signals || ++v->wait_counter < _settings_game.pf.wait_oneway_signal * 20) return; |
6151 | 2998 } else if (HasSignalOnTrackdir(gp.new_tile, i)) { |
2999 v->cur_speed = 0; | |
3000 v->subspeed = 0; | |
6491
696f0e1b046e
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium <rubidium@openttd.org>
parents:
6490
diff
changeset
|
3001 v->progress = 255 - 10; |
17223
a1dda316ecbe
(svn r21962) -Feature-ish: GUI setting to disable reversing at signals
rubidium <rubidium@openttd.org>
parents:
17221
diff
changeset
|
3002 if (!_settings_game.pf.reverse_at_signals || ++v->wait_counter < _settings_game.pf.wait_twoway_signal * 73) { |
9699
128a1a7ade68
(svn r13806) -Fix [FS#2162]: checking for train waiting at other side of two-way signal was broken
smatz <smatz@openttd.org>
parents:
9628
diff
changeset
|
3003 DiagDirection exitdir = TrackdirToExitdir(i); |
128a1a7ade68
(svn r13806) -Fix [FS#2162]: checking for train waiting at other side of two-way signal was broken
smatz <smatz@openttd.org>
parents:
9628
diff
changeset
|
3004 TileIndex o_tile = TileAddByDiagDir(gp.new_tile, exitdir); |
128a1a7ade68
(svn r13806) -Fix [FS#2162]: checking for train waiting at other side of two-way signal was broken
smatz <smatz@openttd.org>
parents:
9628
diff
changeset
|
3005 |
128a1a7ade68
(svn r13806) -Fix [FS#2162]: checking for train waiting at other side of two-way signal was broken
smatz <smatz@openttd.org>
parents:
9628
diff
changeset
|
3006 exitdir = ReverseDiagDir(exitdir); |
6151 | 3007 |
3008 /* check if a train is waiting on the other side */ | |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
3009 if (!HasVehicleOnPos(o_tile, &exitdir, &CheckTrainAtSignal)) return; |
6151 | 3010 } |
3011 } | |
9820
7ad7c8e6ca13
(svn r13962) -Codechange [YAPP]: Do not reverse in front of red signals when inside a PBS block and reversing of stuck trains is disabled. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9819
diff
changeset
|
3012 |
7ad7c8e6ca13
(svn r13962) -Codechange [YAPP]: Do not reverse in front of red signals when inside a PBS block and reversing of stuck trains is disabled. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9819
diff
changeset
|
3013 /* If we would reverse but are currently in a PBS block and |
14702
66e6b13805cb
(svn r19286) -Fix (r18648): [YAPP] If reversing at path signals was disabled, a train would not reverse when hitting the back of an one-way signal.
michi_cc <michi_cc@openttd.org>
parents:
14680
diff
changeset
|
3014 * reversing of stuck trains is disabled, don't reverse. |
66e6b13805cb
(svn r19286) -Fix (r18648): [YAPP] If reversing at path signals was disabled, a train would not reverse when hitting the back of an one-way signal.
michi_cc <michi_cc@openttd.org>
parents:
14680
diff
changeset
|
3015 * This does not apply if the reason for reversing is a one-way |
66e6b13805cb
(svn r19286) -Fix (r18648): [YAPP] If reversing at path signals was disabled, a train would not reverse when hitting the back of an one-way signal.
michi_cc <michi_cc@openttd.org>
parents:
14680
diff
changeset
|
3016 * signal blocking us, because a train would then be stuck forever. */ |
17223
a1dda316ecbe
(svn r21962) -Feature-ish: GUI setting to disable reversing at signals
rubidium <rubidium@openttd.org>
parents:
17221
diff
changeset
|
3017 if (!_settings_game.pf.reverse_at_signals && !HasOnewaySignalBlockingTrackdir(gp.new_tile, i) && |
14702
66e6b13805cb
(svn r19286) -Fix (r18648): [YAPP] If reversing at path signals was disabled, a train would not reverse when hitting the back of an one-way signal.
michi_cc <michi_cc@openttd.org>
parents:
14680
diff
changeset
|
3018 UpdateSignalsOnSegment(v->tile, enterdir, v->owner) == SIGSEG_PBS) { |
14213
41b2e7bf03da
(svn r18764) -Fix [FS#3422]: split the (un)load ticks counter and signal wait counter; sometimes they might get into eachother's way
rubidium <rubidium@openttd.org>
parents:
14127
diff
changeset
|
3019 v->wait_counter = 0; |
9820
7ad7c8e6ca13
(svn r13962) -Codechange [YAPP]: Do not reverse in front of red signals when inside a PBS block and reversing of stuck trains is disabled. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9819
diff
changeset
|
3020 return; |
7ad7c8e6ca13
(svn r13962) -Codechange [YAPP]: Do not reverse in front of red signals when inside a PBS block and reversing of stuck trains is disabled. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9819
diff
changeset
|
3021 } |
6151 | 3022 goto reverse_train_direction; |
9888
b849464ebe27
(svn r14036) -Fix [FS#2197,FS#2198]: trains crashing into eachother when signals are changed (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9874
diff
changeset
|
3023 } else { |
b849464ebe27
(svn r14036) -Fix [FS#2197,FS#2198]: trains crashing into eachother when signals are changed (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9874
diff
changeset
|
3024 TryReserveRailTrack(gp.new_tile, TrackBitsToTrack(chosen_track)); |
6151 | 3025 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3026 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3027 /* The wagon is active, simply follow the prev vehicle. */ |
11434
2535211ea182
(svn r15792) -Codechange: Use a different algorithm for train vehicles to follow the vehicle in front of them.
frosch <frosch@openttd.org>
parents:
11431
diff
changeset
|
3028 if (prev->tile == gp.new_tile) { |
2535211ea182
(svn r15792) -Codechange: Use a different algorithm for train vehicles to follow the vehicle in front of them.
frosch <frosch@openttd.org>
parents:
11431
diff
changeset
|
3029 /* Choose the same track as prev */ |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
3030 if (prev->track == TRACK_BIT_WORMHOLE) { |
11434
2535211ea182
(svn r15792) -Codechange: Use a different algorithm for train vehicles to follow the vehicle in front of them.
frosch <frosch@openttd.org>
parents:
11431
diff
changeset
|
3031 /* Vehicles entering tunnels enter the wormhole earlier than for bridges. |
2535211ea182
(svn r15792) -Codechange: Use a different algorithm for train vehicles to follow the vehicle in front of them.
frosch <frosch@openttd.org>
parents:
11431
diff
changeset
|
3032 * However, just choose the track into the wormhole. */ |
2535211ea182
(svn r15792) -Codechange: Use a different algorithm for train vehicles to follow the vehicle in front of them.
frosch <frosch@openttd.org>
parents:
11431
diff
changeset
|
3033 assert(IsTunnel(prev->tile)); |
2535211ea182
(svn r15792) -Codechange: Use a different algorithm for train vehicles to follow the vehicle in front of them.
frosch <frosch@openttd.org>
parents:
11431
diff
changeset
|
3034 chosen_track = bits; |
2535211ea182
(svn r15792) -Codechange: Use a different algorithm for train vehicles to follow the vehicle in front of them.
frosch <frosch@openttd.org>
parents:
11431
diff
changeset
|
3035 } else { |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
3036 chosen_track = prev->track; |
11434
2535211ea182
(svn r15792) -Codechange: Use a different algorithm for train vehicles to follow the vehicle in front of them.
frosch <frosch@openttd.org>
parents:
11431
diff
changeset
|
3037 } |
2535211ea182
(svn r15792) -Codechange: Use a different algorithm for train vehicles to follow the vehicle in front of them.
frosch <frosch@openttd.org>
parents:
11431
diff
changeset
|
3038 } else { |
11690
eb5d9897c030
(svn r16075) -Fix (r15792)[FS#2844]: Mixed up TRACK_BIT_X/Y.
frosch <frosch@openttd.org>
parents:
11677
diff
changeset
|
3039 /* Choose the track that leads to the tile where prev is. |
eb5d9897c030
(svn r16075) -Fix (r15792)[FS#2844]: Mixed up TRACK_BIT_X/Y.
frosch <frosch@openttd.org>
parents:
11677
diff
changeset
|
3040 * This case is active if 'prev' is already on the second next tile, when 'v' just enters the next tile. |
eb5d9897c030
(svn r16075) -Fix (r15792)[FS#2844]: Mixed up TRACK_BIT_X/Y.
frosch <frosch@openttd.org>
parents:
11677
diff
changeset
|
3041 * I.e. when the tile between them has only space for a single vehicle like |
eb5d9897c030
(svn r16075) -Fix (r15792)[FS#2844]: Mixed up TRACK_BIT_X/Y.
frosch <frosch@openttd.org>
parents:
11677
diff
changeset
|
3042 * 1) horizontal/vertical track tiles and |
15820
59fd8293b2ee
(svn r20499) -Doc: Spelling fixes, and one doxygen comment addition.
alberth <alberth@openttd.org>
parents:
15763
diff
changeset
|
3043 * 2) some orientations of tunnel entries, where the vehicle is already inside the wormhole at 8/16 from the tile edge. |
59fd8293b2ee
(svn r20499) -Doc: Spelling fixes, and one doxygen comment addition.
alberth <alberth@openttd.org>
parents:
15763
diff
changeset
|
3044 * Is also the train just reversing, the wagon inside the tunnel is 'on' the tile of the opposite tunnel entry. |
11690
eb5d9897c030
(svn r16075) -Fix (r15792)[FS#2844]: Mixed up TRACK_BIT_X/Y.
frosch <frosch@openttd.org>
parents:
11677
diff
changeset
|
3045 */ |
11434
2535211ea182
(svn r15792) -Codechange: Use a different algorithm for train vehicles to follow the vehicle in front of them.
frosch <frosch@openttd.org>
parents:
11431
diff
changeset
|
3046 static const TrackBits _connecting_track[DIAGDIR_END][DIAGDIR_END] = { |
11690
eb5d9897c030
(svn r16075) -Fix (r15792)[FS#2844]: Mixed up TRACK_BIT_X/Y.
frosch <frosch@openttd.org>
parents:
11677
diff
changeset
|
3047 {TRACK_BIT_X, TRACK_BIT_LOWER, TRACK_BIT_NONE, TRACK_BIT_LEFT }, |
eb5d9897c030
(svn r16075) -Fix (r15792)[FS#2844]: Mixed up TRACK_BIT_X/Y.
frosch <frosch@openttd.org>
parents:
11677
diff
changeset
|
3048 {TRACK_BIT_UPPER, TRACK_BIT_Y, TRACK_BIT_LEFT, TRACK_BIT_NONE }, |
eb5d9897c030
(svn r16075) -Fix (r15792)[FS#2844]: Mixed up TRACK_BIT_X/Y.
frosch <frosch@openttd.org>
parents:
11677
diff
changeset
|
3049 {TRACK_BIT_NONE, TRACK_BIT_RIGHT, TRACK_BIT_X, TRACK_BIT_UPPER}, |
eb5d9897c030
(svn r16075) -Fix (r15792)[FS#2844]: Mixed up TRACK_BIT_X/Y.
frosch <frosch@openttd.org>
parents:
11677
diff
changeset
|
3050 {TRACK_BIT_RIGHT, TRACK_BIT_NONE, TRACK_BIT_LOWER, TRACK_BIT_Y } |
11434
2535211ea182
(svn r15792) -Codechange: Use a different algorithm for train vehicles to follow the vehicle in front of them.
frosch <frosch@openttd.org>
parents:
11431
diff
changeset
|
3051 }; |
2535211ea182
(svn r15792) -Codechange: Use a different algorithm for train vehicles to follow the vehicle in front of them.
frosch <frosch@openttd.org>
parents:
11431
diff
changeset
|
3052 DiagDirection exitdir = DiagdirBetweenTiles(gp.new_tile, prev->tile); |
2535211ea182
(svn r15792) -Codechange: Use a different algorithm for train vehicles to follow the vehicle in front of them.
frosch <frosch@openttd.org>
parents:
11431
diff
changeset
|
3053 assert(IsValidDiagDirection(exitdir)); |
2535211ea182
(svn r15792) -Codechange: Use a different algorithm for train vehicles to follow the vehicle in front of them.
frosch <frosch@openttd.org>
parents:
11431
diff
changeset
|
3054 chosen_track = _connecting_track[enterdir][exitdir]; |
2535211ea182
(svn r15792) -Codechange: Use a different algorithm for train vehicles to follow the vehicle in front of them.
frosch <frosch@openttd.org>
parents:
11431
diff
changeset
|
3055 } |
2535211ea182
(svn r15792) -Codechange: Use a different algorithm for train vehicles to follow the vehicle in front of them.
frosch <frosch@openttd.org>
parents:
11431
diff
changeset
|
3056 chosen_track &= bits; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3057 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3058 |
5994
f7885ece4c67
(svn r8703) -Codechange/cleanup: some magic numbers -> enums and other small coding style changes to the ShipController and TrainController.
rubidium <rubidium@openttd.org>
parents:
5993
diff
changeset
|
3059 /* Make sure chosen track is a valid track */ |
f7885ece4c67
(svn r8703) -Codechange/cleanup: some magic numbers -> enums and other small coding style changes to the ShipController and TrainController.
rubidium <rubidium@openttd.org>
parents:
5993
diff
changeset
|
3060 assert( |
f7885ece4c67
(svn r8703) -Codechange/cleanup: some magic numbers -> enums and other small coding style changes to the ShipController and TrainController.
rubidium <rubidium@openttd.org>
parents:
5993
diff
changeset
|
3061 chosen_track == TRACK_BIT_X || chosen_track == TRACK_BIT_Y || |
f7885ece4c67
(svn r8703) -Codechange/cleanup: some magic numbers -> enums and other small coding style changes to the ShipController and TrainController.
rubidium <rubidium@openttd.org>
parents:
5993
diff
changeset
|
3062 chosen_track == TRACK_BIT_UPPER || chosen_track == TRACK_BIT_LOWER || |
f7885ece4c67
(svn r8703) -Codechange/cleanup: some magic numbers -> enums and other small coding style changes to the ShipController and TrainController.
rubidium <rubidium@openttd.org>
parents:
5993
diff
changeset
|
3063 chosen_track == TRACK_BIT_LEFT || chosen_track == TRACK_BIT_RIGHT); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3064 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3065 /* Update XY to reflect the entrance to the new tile, and select the direction to use */ |
6150 | 3066 const byte *b = _initial_tile_subcoord[FIND_FIRST_BIT(chosen_track)][enterdir]; |
3067 gp.x = (gp.x & ~0xF) | b[0]; | |
3068 gp.y = (gp.y & ~0xF) | b[1]; | |
3069 Direction chosen_dir = (Direction)b[2]; | |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3070 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3071 /* Call the landscape function and tell it that the vehicle entered the tile */ |
6150 | 3072 uint32 r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y); |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
3073 if (HasBit(r, VETS_CANNOT_ENTER)) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3074 goto invalid_rail; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3075 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3076 |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
3077 if (!HasBit(r, VETS_ENTERED_WORMHOLE)) { |
9809
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
3078 Track track = FindFirstTrack(chosen_track); |
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
3079 Trackdir tdir = TrackDirectionToTrackdir(track, chosen_dir); |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
3080 if (v->IsFrontEngine() && HasPbsSignalOnTrackdir(gp.new_tile, tdir)) { |
9809
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
3081 SetSignalStateByTrackdir(gp.new_tile, tdir, SIGNAL_STATE_RED); |
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
3082 MarkTileDirtyByTile(gp.new_tile); |
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
3083 } |
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
3084 |
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
3085 /* Clear any track reservation when the last vehicle leaves the tile */ |
11976
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
3086 if (v->Next() == NULL) ClearPathReservation(v, v->tile, v->GetVehicleTrackdir()); |
9809
7a8655114c79
(svn r13951) -Codechange [YAPP]: A train leaving a tile should unreserve the track it came from if it was reserved. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
3087 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3088 v->tile = gp.new_tile; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3089 |
6154 | 3090 if (GetTileRailType(gp.new_tile) != GetTileRailType(gp.old_tile)) { |
15826
7f692dcca929
(svn r20505) -Feature [FS#3978]: Allow changing visual effect when changing railtype.
frosch <frosch@openttd.org>
parents:
15825
diff
changeset
|
3091 v->First()->RailtypeChanged(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3092 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3093 |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
3094 v->track = chosen_track; |
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
3095 assert(v->track); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3096 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3097 |
6871
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
3098 /* We need to update signal status, but after the vehicle position hash |
14754
691e61140880
(svn r19342) -Codechange: Move inclination update functions to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14753
diff
changeset
|
3099 * has been updated by UpdateInclination() */ |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3100 update_signals_crossing = true; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3101 |
12085
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
3102 if (chosen_dir != v->direction) { |
14406
5f93639271ee
(svn r18963) -Codechange: Give AccelerationModel a generical name.
terkhen <terkhen@openttd.org>
parents:
14384
diff
changeset
|
3103 if (prev == NULL && _settings_game.vehicle.train_acceleration_model == AM_ORIGINAL) { |
12085
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
3104 const RailtypeSlowdownParams *rsp = &_railtype_slowdown[v->railtype]; |
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
3105 DirDiff diff = DirDifference(v->direction, chosen_dir); |
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
3106 v->cur_speed -= (diff == DIRDIFF_45RIGHT || diff == DIRDIFF_45LEFT ? rsp->small_turn : rsp->large_turn) * v->cur_speed >> 8; |
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
3107 } |
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
3108 direction_changed = true; |
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
3109 v->direction = chosen_dir; |
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
3110 } |
9816
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
3111 |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
3112 if (v->IsFrontEngine()) { |
14213
41b2e7bf03da
(svn r18764) -Fix [FS#3422]: split the (un)load ticks counter and signal wait counter; sometimes they might get into eachother's way
rubidium <rubidium@openttd.org>
parents:
14127
diff
changeset
|
3113 v->wait_counter = 0; |
9816
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
3114 |
15820
59fd8293b2ee
(svn r20499) -Doc: Spelling fixes, and one doxygen comment addition.
alberth <alberth@openttd.org>
parents:
15763
diff
changeset
|
3115 /* If we are approaching a crossing that is reserved, play the sound now. */ |
9824
fe3562a51648
(svn r13966) -Codechange [YAPP]: Bar level crossings upon path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9822
diff
changeset
|
3116 TileIndex crossing = TrainApproachingCrossingTile(v); |
12470
299da608443d
(svn r16907) -Codechange: make a more clear distinction between reservation functions that return a bool and that return TrackBits; GetRailStationReservation vs GetRailwayStationReservation, which one returns the bool and which one the TrackBits?
rubidium <rubidium@openttd.org>
parents:
12467
diff
changeset
|
3117 if (crossing != INVALID_TILE && HasCrossingReservation(crossing)) SndPlayTileFx(SND_0E_LEVEL_CROSSING, crossing); |
9824
fe3562a51648
(svn r13966) -Codechange [YAPP]: Bar level crossings upon path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9822
diff
changeset
|
3118 |
9816
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
3119 /* Always try to extend the reservation when entering a tile. */ |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
3120 CheckNextTrainTile(v); |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
3121 } |
11657
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
3122 |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
3123 if (HasBit(r, VETS_ENTERED_STATION)) { |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
3124 /* The new position is the location where we want to stop */ |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
3125 TrainEnterStation(v, r >> VETS_STATION_ID_OFFSET); |
ff1084d0d8a0
(svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents:
11435
diff
changeset
|
3126 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3127 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3128 } else { |
8143
1c7033494d92
(svn r11705) -Fix [FS#1557]: trains could have sprites with wrong direction when reversing, also was inconsistent with save/load process (possible desyncs)
smatz <smatz@openttd.org>
parents:
8140
diff
changeset
|
3129 /* In a tunnel or on a bridge |
1c7033494d92
(svn r11705) -Fix [FS#1557]: trains could have sprites with wrong direction when reversing, also was inconsistent with save/load process (possible desyncs)
smatz <smatz@openttd.org>
parents:
8140
diff
changeset
|
3130 * - for tunnels, only the part when the vehicle is not visible (part of enter/exit tile too) |
1c7033494d92
(svn r11705) -Fix [FS#1557]: trains could have sprites with wrong direction when reversing, also was inconsistent with save/load process (possible desyncs)
smatz <smatz@openttd.org>
parents:
8140
diff
changeset
|
3131 * - for bridges, only the middle part - without the bridge heads */ |
6141 | 3132 if (!(v->vehstatus & VS_HIDDEN)) { |
16420
f74d1996f90c
(svn r21136) -Fix [FS#4213]: bridge speed limits should apply to all wagons of a vehicle, not just the head of the vehicle
rubidium <rubidium@openttd.org>
parents:
16407
diff
changeset
|
3133 Train *first = v->First(); |
f74d1996f90c
(svn r21136) -Fix [FS#4213]: bridge speed limits should apply to all wagons of a vehicle, not just the head of the vehicle
rubidium <rubidium@openttd.org>
parents:
16407
diff
changeset
|
3134 first->cur_speed = min(first->cur_speed, GetBridgeSpec(GetBridgeType(v->tile))->speed); |
6141 | 3135 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3136 |
9816
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
3137 if (IsTileType(gp.new_tile, MP_TUNNELBRIDGE) && HasBit(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y), VETS_ENTERED_WORMHOLE)) { |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
3138 /* Perform look-ahead on tunnel exit. */ |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
3139 if (v->IsFrontEngine()) { |
9888
b849464ebe27
(svn r14036) -Fix [FS#2197,FS#2198]: trains crashing into eachother when signals are changed (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9874
diff
changeset
|
3140 TryReserveRailTrack(gp.new_tile, DiagDirToDiagTrack(GetTunnelBridgeDirection(gp.new_tile))); |
b849464ebe27
(svn r14036) -Fix [FS#2197,FS#2198]: trains crashing into eachother when signals are changed (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9874
diff
changeset
|
3141 CheckNextTrainTile(v); |
b849464ebe27
(svn r14036) -Fix [FS#2197,FS#2198]: trains crashing into eachother when signals are changed (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9874
diff
changeset
|
3142 } |
17099
b23e23e3904a
(svn r21836) -Fix: when a train was reversed while inside a tunnel/bridge, it wouldn't have (re)set the GOINGUP/DOWN bits after leaving the tunnel/bridge
smatz <smatz@openttd.org>
parents:
17098
diff
changeset
|
3143 /* Prevent v->UpdateInclination() being called with wrong parameters. |
b23e23e3904a
(svn r21836) -Fix: when a train was reversed while inside a tunnel/bridge, it wouldn't have (re)set the GOINGUP/DOWN bits after leaving the tunnel/bridge
smatz <smatz@openttd.org>
parents:
17098
diff
changeset
|
3144 * This could happen if the train was reversed inside the tunnel/bridge. */ |
b23e23e3904a
(svn r21836) -Fix: when a train was reversed while inside a tunnel/bridge, it wouldn't have (re)set the GOINGUP/DOWN bits after leaving the tunnel/bridge
smatz <smatz@openttd.org>
parents:
17098
diff
changeset
|
3145 if (gp.old_tile == gp.new_tile) { |
b23e23e3904a
(svn r21836) -Fix: when a train was reversed while inside a tunnel/bridge, it wouldn't have (re)set the GOINGUP/DOWN bits after leaving the tunnel/bridge
smatz <smatz@openttd.org>
parents:
17098
diff
changeset
|
3146 gp.old_tile = GetOtherTunnelBridgeEnd(gp.old_tile); |
b23e23e3904a
(svn r21836) -Fix: when a train was reversed while inside a tunnel/bridge, it wouldn't have (re)set the GOINGUP/DOWN bits after leaving the tunnel/bridge
smatz <smatz@openttd.org>
parents:
17098
diff
changeset
|
3147 } |
9816
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
3148 } else { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3149 v->x_pos = gp.x; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3150 v->y_pos = gp.y; |
11326
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11268
diff
changeset
|
3151 VehicleMove(v, !(v->vehstatus & VS_HIDDEN)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3152 continue; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3153 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3154 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3155 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3156 /* update image of train, as well as delta XY */ |
8143
1c7033494d92
(svn r11705) -Fix [FS#1557]: trains could have sprites with wrong direction when reversing, also was inconsistent with save/load process (possible desyncs)
smatz <smatz@openttd.org>
parents:
8140
diff
changeset
|
3157 v->UpdateDeltaXY(v->direction); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3158 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3159 v->x_pos = gp.x; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3160 v->y_pos = gp.y; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3161 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3162 /* update the Z position of the vehicle */ |
14754
691e61140880
(svn r19342) -Codechange: Move inclination update functions to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14753
diff
changeset
|
3163 byte old_z = v->UpdateInclination(gp.new_tile != gp.old_tile, false); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3164 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3165 if (prev == NULL) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3166 /* This is the first vehicle in the train */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3167 AffectSpeedByZChange(v, old_z); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3168 } |
6871
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
3169 |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3170 if (update_signals_crossing) { |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
3171 if (v->IsFrontEngine()) { |
9821
2b151a3dc570
(svn r13963) -Codechange [YAPP]: Reserve a track when entering a PBS block through a conventional signal. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9820
diff
changeset
|
3172 if (TrainMovedChangeSignals(gp.new_tile, enterdir)) { |
2b151a3dc570
(svn r13963) -Codechange [YAPP]: Reserve a track when entering a PBS block through a conventional signal. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9820
diff
changeset
|
3173 /* We are entering a block with PBS signals right now, but |
2b151a3dc570
(svn r13963) -Codechange [YAPP]: Reserve a track when entering a PBS block through a conventional signal. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9820
diff
changeset
|
3174 * not through a PBS signal. This means we don't have a |
2b151a3dc570
(svn r13963) -Codechange [YAPP]: Reserve a track when entering a PBS block through a conventional signal. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9820
diff
changeset
|
3175 * reservation right now. As a conventional signal will only |
2b151a3dc570
(svn r13963) -Codechange [YAPP]: Reserve a track when entering a PBS block through a conventional signal. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9820
diff
changeset
|
3176 * ever be green if no other train is in the block, getting |
2b151a3dc570
(svn r13963) -Codechange [YAPP]: Reserve a track when entering a PBS block through a conventional signal. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9820
diff
changeset
|
3177 * a path should always be possible. If the player built |
2b151a3dc570
(svn r13963) -Codechange [YAPP]: Reserve a track when entering a PBS block through a conventional signal. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9820
diff
changeset
|
3178 * such a strange network that it is not possible, the train |
2b151a3dc570
(svn r13963) -Codechange [YAPP]: Reserve a track when entering a PBS block through a conventional signal. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9820
diff
changeset
|
3179 * will be marked as stuck and the player has to deal with |
2b151a3dc570
(svn r13963) -Codechange [YAPP]: Reserve a track when entering a PBS block through a conventional signal. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9820
diff
changeset
|
3180 * the problem. */ |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
3181 if ((!HasReservedTracks(gp.new_tile, v->track) && |
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
3182 !TryReserveRailTrack(gp.new_tile, FindFirstTrack(v->track))) || |
9821
2b151a3dc570
(svn r13963) -Codechange [YAPP]: Reserve a track when entering a PBS block through a conventional signal. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9820
diff
changeset
|
3183 !TryPathReserve(v)) { |
2b151a3dc570
(svn r13963) -Codechange [YAPP]: Reserve a track when entering a PBS block through a conventional signal. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9820
diff
changeset
|
3184 MarkTrainAsStuck(v); |
2b151a3dc570
(svn r13963) -Codechange [YAPP]: Reserve a track when entering a PBS block through a conventional signal. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9820
diff
changeset
|
3185 } |
2b151a3dc570
(svn r13963) -Codechange [YAPP]: Reserve a track when entering a PBS block through a conventional signal. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9820
diff
changeset
|
3186 } |
2b151a3dc570
(svn r13963) -Codechange [YAPP]: Reserve a track when entering a PBS block through a conventional signal. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9820
diff
changeset
|
3187 } |
6871
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
3188 |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
3189 /* Signals can only change when the first |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
3190 * (above) or the last vehicle moves. */ |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3191 if (v->Next() == NULL) { |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3192 TrainMovedChangeSignals(gp.old_tile, ReverseDiagDir(enterdir)); |
8342
441cda3cfbdb
(svn r11908) -Fix: update crossing when merging a company, when building a crossing and after loading older savegame
smatz <smatz@openttd.org>
parents:
8334
diff
changeset
|
3193 if (IsLevelCrossingTile(gp.old_tile)) UpdateLevelCrossing(gp.old_tile); |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3194 } |
6871
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
3195 } |
9816
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
3196 |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
3197 /* Do not check on every tick to save some computing time. */ |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
3198 if (v->IsFrontEngine() && v->tick_counter % _settings_game.pf.path_backoff_interval == 0) CheckNextTrainTile(v); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3199 } |
12085
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
3200 |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
3201 if (direction_changed) first->tcache.cached_max_curve_speed = first->GetCurveSpeedLimit(); |
12085
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
3202 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3203 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3204 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3205 invalid_rail: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3206 /* We've reached end of line?? */ |
9470
47924a4b2ad4
(svn r13390) -Codechange: introduce usererror() for fatal but not openttd related errors. Now all error() will 'crash' openttd after showing the message in win32 releases (MSVC), creating a crash.log and crash.dmp (like the '!' hack used before). On the other hand, usererror() will just close the game. So use error() only when it can be helpful to debugging, else use usererror().
glx <glx@openttd.org>
parents:
9413
diff
changeset
|
3207 if (prev != NULL) error("Disconnecting train"); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3208 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3209 reverse_train_direction: |
14213
41b2e7bf03da
(svn r18764) -Fix [FS#3422]: split the (un)load ticks counter and signal wait counter; sometimes they might get into eachother's way
rubidium <rubidium@openttd.org>
parents:
14127
diff
changeset
|
3210 v->wait_counter = 0; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3211 v->cur_speed = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3212 v->subspeed = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3213 ReverseTrainDirection(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3214 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3215 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
3216 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
3217 * Collect trackbits of all crashed train vehicles on a tile |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9992
diff
changeset
|
3218 * @param v Vehicle passed from Find/HasVehicleOnPos() |
9840
b2082b3c8224
(svn r13983) -Fix (r13953) [YAPP]: Crashed trains can be on different trackbits. Make sure there is still a track reservation when one vehicle is cleaned up.
frosch <frosch@openttd.org>
parents:
9833
diff
changeset
|
3219 * @param data trackdirbits for the result |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9992
diff
changeset
|
3220 * @return NULL to iterate over all vehicles on the tile. |
9840
b2082b3c8224
(svn r13983) -Fix (r13953) [YAPP]: Crashed trains can be on different trackbits. Make sure there is still a track reservation when one vehicle is cleaned up.
frosch <frosch@openttd.org>
parents:
9833
diff
changeset
|
3221 */ |
b2082b3c8224
(svn r13983) -Fix (r13953) [YAPP]: Crashed trains can be on different trackbits. Make sure there is still a track reservation when one vehicle is cleaned up.
frosch <frosch@openttd.org>
parents:
9833
diff
changeset
|
3222 static Vehicle *CollectTrackbitsFromCrashedVehiclesEnum(Vehicle *v, void *data) |
b2082b3c8224
(svn r13983) -Fix (r13953) [YAPP]: Crashed trains can be on different trackbits. Make sure there is still a track reservation when one vehicle is cleaned up.
frosch <frosch@openttd.org>
parents:
9833
diff
changeset
|
3223 { |
b2082b3c8224
(svn r13983) -Fix (r13953) [YAPP]: Crashed trains can be on different trackbits. Make sure there is still a track reservation when one vehicle is cleaned up.
frosch <frosch@openttd.org>
parents:
9833
diff
changeset
|
3224 TrackBits *trackbits = (TrackBits *)data; |
b2082b3c8224
(svn r13983) -Fix (r13953) [YAPP]: Crashed trains can be on different trackbits. Make sure there is still a track reservation when one vehicle is cleaned up.
frosch <frosch@openttd.org>
parents:
9833
diff
changeset
|
3225 |
9845
ee10319a40b6
(svn r13989) -Fix [FS#2186] (r13953): YAPP track reservation for crashed trains was broken for depots and wormholes (michi_cc).
rubidium <rubidium@openttd.org>
parents:
9840
diff
changeset
|
3226 if (v->type == VEH_TRAIN && (v->vehstatus & VS_CRASHED) != 0) { |
15257
25f7ec98dc69
(svn r19892) -Fix [FS#3856] (r19792): crash when trying to reserve 'in depot' track on clearing a crashed train
rubidium <rubidium@openttd.org>
parents:
15163
diff
changeset
|
3227 TrackBits train_tbits = Train::From(v)->track; |
25f7ec98dc69
(svn r19892) -Fix [FS#3856] (r19792): crash when trying to reserve 'in depot' track on clearing a crashed train
rubidium <rubidium@openttd.org>
parents:
15163
diff
changeset
|
3228 if (train_tbits == TRACK_BIT_WORMHOLE) { |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
3229 /* Vehicle is inside a wormhole, v->track contains no useful value then. */ |
9845
ee10319a40b6
(svn r13989) -Fix [FS#2186] (r13953): YAPP track reservation for crashed trains was broken for depots and wormholes (michi_cc).
rubidium <rubidium@openttd.org>
parents:
9840
diff
changeset
|
3230 *trackbits |= DiagDirToDiagTrackBits(GetTunnelBridgeDirection(v->tile)); |
15257
25f7ec98dc69
(svn r19892) -Fix [FS#3856] (r19792): crash when trying to reserve 'in depot' track on clearing a crashed train
rubidium <rubidium@openttd.org>
parents:
15163
diff
changeset
|
3231 } else if (train_tbits != TRACK_BIT_DEPOT) { |
25f7ec98dc69
(svn r19892) -Fix [FS#3856] (r19792): crash when trying to reserve 'in depot' track on clearing a crashed train
rubidium <rubidium@openttd.org>
parents:
15163
diff
changeset
|
3232 *trackbits |= train_tbits; |
9845
ee10319a40b6
(svn r13989) -Fix [FS#2186] (r13953): YAPP track reservation for crashed trains was broken for depots and wormholes (michi_cc).
rubidium <rubidium@openttd.org>
parents:
9840
diff
changeset
|
3233 } |
ee10319a40b6
(svn r13989) -Fix [FS#2186] (r13953): YAPP track reservation for crashed trains was broken for depots and wormholes (michi_cc).
rubidium <rubidium@openttd.org>
parents:
9840
diff
changeset
|
3234 } |
9840
b2082b3c8224
(svn r13983) -Fix (r13953) [YAPP]: Crashed trains can be on different trackbits. Make sure there is still a track reservation when one vehicle is cleaned up.
frosch <frosch@openttd.org>
parents:
9833
diff
changeset
|
3235 |
b2082b3c8224
(svn r13983) -Fix (r13953) [YAPP]: Crashed trains can be on different trackbits. Make sure there is still a track reservation when one vehicle is cleaned up.
frosch <frosch@openttd.org>
parents:
9833
diff
changeset
|
3236 return NULL; |
b2082b3c8224
(svn r13983) -Fix (r13953) [YAPP]: Crashed trains can be on different trackbits. Make sure there is still a track reservation when one vehicle is cleaned up.
frosch <frosch@openttd.org>
parents:
9833
diff
changeset
|
3237 } |
b2082b3c8224
(svn r13983) -Fix (r13953) [YAPP]: Crashed trains can be on different trackbits. Make sure there is still a track reservation when one vehicle is cleaned up.
frosch <frosch@openttd.org>
parents:
9833
diff
changeset
|
3238 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3239 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3240 * Deletes/Clears the last wagon of a crashed train. It takes the engine of the |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3241 * train, then goes to the last wagon and deletes that. Each call to this function |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3242 * will remove the last wagon of a crashed train. If this wagon was on a crossing, |
8073
ab953ea59f2e
(svn r11634) -Fix: update signals when deleting crashed train on a bridge, update even when train is rotated
smatz <smatz@openttd.org>
parents:
8072
diff
changeset
|
3243 * or inside a tunnel/bridge, recalculate the signals as they might need updating |
6484
17fdaec13730
(svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas <belugas@openttd.org>
parents:
6453
diff
changeset
|
3244 * @param v the Vehicle of which last wagon is to be removed |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3245 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
3246 static void DeleteLastWagon(Train *v) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3247 { |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
3248 Train *first = v->First(); |
8267
e377a682e7a4
(svn r11831) -Fix: call TrainConsistChanged() when removing crashed train part to be consistent with saveload process
smatz <smatz@openttd.org>
parents:
8264
diff
changeset
|
3249 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3250 /* Go to the last wagon and delete the link pointing there |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3251 * *u is then the one-before-last wagon, and *v the last |
15820
59fd8293b2ee
(svn r20499) -Doc: Spelling fixes, and one doxygen comment addition.
alberth <alberth@openttd.org>
parents:
15763
diff
changeset
|
3252 * one which will physically be removed */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
3253 Train *u = v; |
7492
09743324277c
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium <rubidium@openttd.org>
parents:
7488
diff
changeset
|
3254 for (; v->Next() != NULL; v = v->Next()) u = v; |
09743324277c
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium <rubidium@openttd.org>
parents:
7488
diff
changeset
|
3255 u->SetNext(NULL); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3256 |
10493
5531e81401ee
(svn r14748) -Codechange: unduplicate window updating when deleting vehicles.
rubidium <rubidium@openttd.org>
parents:
10492
diff
changeset
|
3257 if (first != v) { |
8267
e377a682e7a4
(svn r11831) -Fix: call TrainConsistChanged() when removing crashed train part to be consistent with saveload process
smatz <smatz@openttd.org>
parents:
8264
diff
changeset
|
3258 /* Recalculate cached train properties */ |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
3259 first->ConsistChanged(false); |
8267
e377a682e7a4
(svn r11831) -Fix: call TrainConsistChanged() when removing crashed train part to be consistent with saveload process
smatz <smatz@openttd.org>
parents:
8264
diff
changeset
|
3260 /* Update the depot window if the first vehicle is in depot - |
e377a682e7a4
(svn r11831) -Fix: call TrainConsistChanged() when removing crashed train part to be consistent with saveload process
smatz <smatz@openttd.org>
parents:
8264
diff
changeset
|
3261 * if v == first, then it is updated in PreDestructor() */ |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
3262 if (first->track == TRACK_BIT_DEPOT) { |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
13001
diff
changeset
|
3263 SetWindowDirty(WC_VEHICLE_DEPOT, first->tile); |
8267
e377a682e7a4
(svn r11831) -Fix: call TrainConsistChanged() when removing crashed train part to be consistent with saveload process
smatz <smatz@openttd.org>
parents:
8264
diff
changeset
|
3264 } |
e377a682e7a4
(svn r11831) -Fix: call TrainConsistChanged() when removing crashed train part to be consistent with saveload process
smatz <smatz@openttd.org>
parents:
8264
diff
changeset
|
3265 } |
e377a682e7a4
(svn r11831) -Fix: call TrainConsistChanged() when removing crashed train part to be consistent with saveload process
smatz <smatz@openttd.org>
parents:
8264
diff
changeset
|
3266 |
8255
dc16e054fd8f
(svn r11819) -Fix: do not access the Vehicle struct that has been already deleted when removing crashed train
smatz <smatz@openttd.org>
parents:
8254
diff
changeset
|
3267 /* 'v' shouldn't be accessed after it has been deleted */ |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
3268 TrackBits trackbits = v->track; |
8255
dc16e054fd8f
(svn r11819) -Fix: do not access the Vehicle struct that has been already deleted when removing crashed train
smatz <smatz@openttd.org>
parents:
8254
diff
changeset
|
3269 TileIndex tile = v->tile; |
8300
ae1baac75172
(svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz <smatz@openttd.org>
parents:
8283
diff
changeset
|
3270 Owner owner = v->owner; |
8255
dc16e054fd8f
(svn r11819) -Fix: do not access the Vehicle struct that has been already deleted when removing crashed train
smatz <smatz@openttd.org>
parents:
8254
diff
changeset
|
3271 |
7398
6324d82f421d
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium <rubidium@openttd.org>
parents:
7371
diff
changeset
|
3272 delete v; |
9840
b2082b3c8224
(svn r13983) -Fix (r13953) [YAPP]: Crashed trains can be on different trackbits. Make sure there is still a track reservation when one vehicle is cleaned up.
frosch <frosch@openttd.org>
parents:
9833
diff
changeset
|
3273 v = NULL; // make sure nobody will try to read 'v' anymore |
b2082b3c8224
(svn r13983) -Fix (r13953) [YAPP]: Crashed trains can be on different trackbits. Make sure there is still a track reservation when one vehicle is cleaned up.
frosch <frosch@openttd.org>
parents:
9833
diff
changeset
|
3274 |
12137
b3c5a6c9146a
(svn r16553) -Codechange: don't use TRACK_BIT_WORMHOLE and TRACK_BIT_DEPOT as bitmasks
smatz <smatz@openttd.org>
parents:
12129
diff
changeset
|
3275 if (trackbits == TRACK_BIT_WORMHOLE) { |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
3276 /* Vehicle is inside a wormhole, v->track contains no useful value then. */ |
12137
b3c5a6c9146a
(svn r16553) -Codechange: don't use TRACK_BIT_WORMHOLE and TRACK_BIT_DEPOT as bitmasks
smatz <smatz@openttd.org>
parents:
12129
diff
changeset
|
3277 trackbits = DiagDirToDiagTrackBits(GetTunnelBridgeDirection(tile)); |
9845
ee10319a40b6
(svn r13989) -Fix [FS#2186] (r13953): YAPP track reservation for crashed trains was broken for depots and wormholes (michi_cc).
rubidium <rubidium@openttd.org>
parents:
9840
diff
changeset
|
3278 } |
ee10319a40b6
(svn r13989) -Fix [FS#2186] (r13953): YAPP track reservation for crashed trains was broken for depots and wormholes (michi_cc).
rubidium <rubidium@openttd.org>
parents:
9840
diff
changeset
|
3279 |
ee10319a40b6
(svn r13989) -Fix [FS#2186] (r13953): YAPP track reservation for crashed trains was broken for depots and wormholes (michi_cc).
rubidium <rubidium@openttd.org>
parents:
9840
diff
changeset
|
3280 Track track = TrackBitsToTrack(trackbits); |
9840
b2082b3c8224
(svn r13983) -Fix (r13953) [YAPP]: Crashed trains can be on different trackbits. Make sure there is still a track reservation when one vehicle is cleaned up.
frosch <frosch@openttd.org>
parents:
9833
diff
changeset
|
3281 if (HasReservedTracks(tile, trackbits)) { |
b2082b3c8224
(svn r13983) -Fix (r13953) [YAPP]: Crashed trains can be on different trackbits. Make sure there is still a track reservation when one vehicle is cleaned up.
frosch <frosch@openttd.org>
parents:
9833
diff
changeset
|
3282 UnreserveRailTrack(tile, track); |
b2082b3c8224
(svn r13983) -Fix (r13953) [YAPP]: Crashed trains can be on different trackbits. Make sure there is still a track reservation when one vehicle is cleaned up.
frosch <frosch@openttd.org>
parents:
9833
diff
changeset
|
3283 |
b2082b3c8224
(svn r13983) -Fix (r13953) [YAPP]: Crashed trains can be on different trackbits. Make sure there is still a track reservation when one vehicle is cleaned up.
frosch <frosch@openttd.org>
parents:
9833
diff
changeset
|
3284 /* If there are still crashed vehicles on the tile, give the track reservation to them */ |
b2082b3c8224
(svn r13983) -Fix (r13953) [YAPP]: Crashed trains can be on different trackbits. Make sure there is still a track reservation when one vehicle is cleaned up.
frosch <frosch@openttd.org>
parents:
9833
diff
changeset
|
3285 TrackBits remaining_trackbits = TRACK_BIT_NONE; |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
9992
diff
changeset
|
3286 FindVehicleOnPos(tile, &remaining_trackbits, CollectTrackbitsFromCrashedVehiclesEnum); |
9840
b2082b3c8224
(svn r13983) -Fix (r13953) [YAPP]: Crashed trains can be on different trackbits. Make sure there is still a track reservation when one vehicle is cleaned up.
frosch <frosch@openttd.org>
parents:
9833
diff
changeset
|
3287 |
b2082b3c8224
(svn r13983) -Fix (r13953) [YAPP]: Crashed trains can be on different trackbits. Make sure there is still a track reservation when one vehicle is cleaned up.
frosch <frosch@openttd.org>
parents:
9833
diff
changeset
|
3288 /* It is important that these two are the first in the loop, as reservation cannot deal with every trackbit combination */ |
b2082b3c8224
(svn r13983) -Fix (r13953) [YAPP]: Crashed trains can be on different trackbits. Make sure there is still a track reservation when one vehicle is cleaned up.
frosch <frosch@openttd.org>
parents:
9833
diff
changeset
|
3289 assert(TRACK_BEGIN == TRACK_X && TRACK_Y == TRACK_BEGIN + 1); |
15163
5fa5a4d1f409
(svn r19792) -Change: use the typed FOR_EACH_SET_BIT for Tracks (adf88)
rubidium <rubidium@openttd.org>
parents:
15156
diff
changeset
|
3290 Track t; |
5fa5a4d1f409
(svn r19792) -Change: use the typed FOR_EACH_SET_BIT for Tracks (adf88)
rubidium <rubidium@openttd.org>
parents:
15156
diff
changeset
|
3291 FOR_EACH_SET_TRACK(t, remaining_trackbits) TryReserveRailTrack(tile, t); |
9840
b2082b3c8224
(svn r13983) -Fix (r13953) [YAPP]: Crashed trains can be on different trackbits. Make sure there is still a track reservation when one vehicle is cleaned up.
frosch <frosch@openttd.org>
parents:
9833
diff
changeset
|
3292 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3293 |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3294 /* check if the wagon was on a road/rail-crossing */ |
8342
441cda3cfbdb
(svn r11908) -Fix: update crossing when merging a company, when building a crossing and after loading older savegame
smatz <smatz@openttd.org>
parents:
8334
diff
changeset
|
3295 if (IsLevelCrossingTile(tile)) UpdateLevelCrossing(tile); |
8255
dc16e054fd8f
(svn r11819) -Fix: do not access the Vehicle struct that has been already deleted when removing crashed train
smatz <smatz@openttd.org>
parents:
8254
diff
changeset
|
3296 |
8257
38d56fa7b6f7
(svn r11821) -Fix (r11802): 'optimization assert' when removing crashed wagon in some cases
smatz <smatz@openttd.org>
parents:
8256
diff
changeset
|
3297 /* Update signals */ |
8961
b33bcd7fa037
(svn r12753) -Codechange: do not use IsDepotTypeTile() where simpler function can be used
smatz <smatz@openttd.org>
parents:
8954
diff
changeset
|
3298 if (IsTileType(tile, MP_TUNNELBRIDGE) || IsRailDepotTile(tile)) { |
8300
ae1baac75172
(svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz <smatz@openttd.org>
parents:
8283
diff
changeset
|
3299 UpdateSignalsOnSegment(tile, INVALID_DIAGDIR, owner); |
8257
38d56fa7b6f7
(svn r11821) -Fix (r11802): 'optimization assert' when removing crashed wagon in some cases
smatz <smatz@openttd.org>
parents:
8256
diff
changeset
|
3300 } else { |
9840
b2082b3c8224
(svn r13983) -Fix (r13953) [YAPP]: Crashed trains can be on different trackbits. Make sure there is still a track reservation when one vehicle is cleaned up.
frosch <frosch@openttd.org>
parents:
9833
diff
changeset
|
3301 SetSignalsOnBothDir(tile, track, owner); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3302 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3303 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3304 |
17236
2401b5b905f3
(svn r21976) -Doc: Document several crash handling functions.
alberth <alberth@openttd.org>
parents:
17227
diff
changeset
|
3305 /** |
2401b5b905f3
(svn r21976) -Doc: Document several crash handling functions.
alberth <alberth@openttd.org>
parents:
17227
diff
changeset
|
3306 * Rotate all vehicles of a (crashed) train chain randomly to animate the crash. |
2401b5b905f3
(svn r21976) -Doc: Document several crash handling functions.
alberth <alberth@openttd.org>
parents:
17227
diff
changeset
|
3307 * @param v First crashed vehicle. |
2401b5b905f3
(svn r21976) -Doc: Document several crash handling functions.
alberth <alberth@openttd.org>
parents:
17227
diff
changeset
|
3308 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
3309 static void ChangeTrainDirRandomly(Train *v) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3310 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3311 static const DirDiff delta[] = { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3312 DIRDIFF_45LEFT, DIRDIFF_SAME, DIRDIFF_SAME, DIRDIFF_45RIGHT |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3313 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3314 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3315 do { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3316 /* We don't need to twist around vehicles if they're not visible */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3317 if (!(v->vehstatus & VS_HIDDEN)) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3318 v->direction = ChangeDir(v->direction, delta[GB(Random(), 0, 2)]); |
6558
2fc024ee8217
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium <rubidium@openttd.org>
parents:
6554
diff
changeset
|
3319 v->UpdateDeltaXY(v->direction); |
7134
e1c4f52f82cd
(svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium <rubidium@openttd.org>
parents:
7109
diff
changeset
|
3320 v->cur_image = v->GetImage(v->direction); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3321 /* Refrain from updating the z position of the vehicle when on |
14754
691e61140880
(svn r19342) -Codechange: Move inclination update functions to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14753
diff
changeset
|
3322 * a bridge, because UpdateInclination() will put the vehicle under |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
3323 * the bridge in that case */ |
14754
691e61140880
(svn r19342) -Codechange: Move inclination update functions to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14753
diff
changeset
|
3324 if (v->track != TRACK_BIT_WORMHOLE) v->UpdateInclination(false, false); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3325 } |
7492
09743324277c
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium <rubidium@openttd.org>
parents:
7488
diff
changeset
|
3326 } while ((v = v->Next()) != NULL); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3327 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3328 |
17236
2401b5b905f3
(svn r21976) -Doc: Document several crash handling functions.
alberth <alberth@openttd.org>
parents:
17227
diff
changeset
|
3329 /** |
2401b5b905f3
(svn r21976) -Doc: Document several crash handling functions.
alberth <alberth@openttd.org>
parents:
17227
diff
changeset
|
3330 * Handle a crashed train. |
2401b5b905f3
(svn r21976) -Doc: Document several crash handling functions.
alberth <alberth@openttd.org>
parents:
17227
diff
changeset
|
3331 * @param v First train vehicle. |
2401b5b905f3
(svn r21976) -Doc: Document several crash handling functions.
alberth <alberth@openttd.org>
parents:
17227
diff
changeset
|
3332 * @return %Vehicle chain still exists. |
2401b5b905f3
(svn r21976) -Doc: Document several crash handling functions.
alberth <alberth@openttd.org>
parents:
17227
diff
changeset
|
3333 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
3334 static bool HandleCrashedTrain(Train *v) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3335 { |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
3336 int state = ++v->crash_anim_pos; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3337 |
5993
2498be7c7e94
(svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium <rubidium@openttd.org>
parents:
5992
diff
changeset
|
3338 if (state == 4 && !(v->vehstatus & VS_HIDDEN)) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3339 CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3340 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3341 |
6150 | 3342 uint32 r; |
7967
e30c5ec2d272
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13 <skidd13@openttd.org>
parents:
7932
diff
changeset
|
3343 if (state <= 200 && Chance16R(1, 7, r)) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3344 int index = (r * 10 >> 16); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3345 |
6150 | 3346 Vehicle *u = v; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3347 do { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3348 if (--index < 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3349 r = Random(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3350 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3351 CreateEffectVehicleRel(u, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3352 GB(r, 8, 3) + 2, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3353 GB(r, 16, 3) + 2, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3354 GB(r, 0, 3) + 5, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3355 EV_EXPLOSION_SMALL); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3356 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3357 } |
7492
09743324277c
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium <rubidium@openttd.org>
parents:
7488
diff
changeset
|
3358 } while ((u = u->Next()) != NULL); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3359 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3360 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3361 if (state <= 240 && !(v->tick_counter & 3)) ChangeTrainDirRandomly(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3362 |
8969
01cc3ee6ecb1
(svn r12761) -Codechange: lots of minor whitespace coding style fixes around operators.
rubidium <rubidium@openttd.org>
parents:
8962
diff
changeset
|
3363 if (state >= 4440 && !(v->tick_counter & 0x1F)) { |
11970
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3364 bool ret = v->Next() != NULL; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3365 DeleteLastWagon(v); |
11970
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3366 return ret; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3367 } |
11970
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3368 |
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3369 return true; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3370 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3371 |
8283
dca081896c52
(svn r11847) -Fix: do not affect the speed a train is entering a depot by trackbits behind it
smatz <smatz@openttd.org>
parents:
8281
diff
changeset
|
3372 /** Maximum speeds for train that is broken down or approaching line end */ |
8312
f6764781d2eb
(svn r11877) -Fix: another way to crash competitors' train in a station
smatz <smatz@openttd.org>
parents:
8305
diff
changeset
|
3373 static const uint16 _breakdown_speeds[16] = { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3374 225, 210, 195, 180, 165, 150, 135, 120, 105, 90, 75, 60, 45, 30, 15, 15 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3375 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3376 |
8305
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3377 |
8283
dca081896c52
(svn r11847) -Fix: do not affect the speed a train is entering a depot by trackbits behind it
smatz <smatz@openttd.org>
parents:
8281
diff
changeset
|
3378 /** |
8305
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3379 * Train is approaching line end, slow down and possibly reverse |
8283
dca081896c52
(svn r11847) -Fix: do not affect the speed a train is entering a depot by trackbits behind it
smatz <smatz@openttd.org>
parents:
8281
diff
changeset
|
3380 * |
8305
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3381 * @param v front train engine |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3382 * @param signal not line end, just a red signal |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3383 * @return true iff we did NOT have to reverse |
8283
dca081896c52
(svn r11847) -Fix: do not affect the speed a train is entering a depot by trackbits behind it
smatz <smatz@openttd.org>
parents:
8281
diff
changeset
|
3384 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
3385 static bool TrainApproachingLineEnd(Train *v, bool signal) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3386 { |
8305
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3387 /* Calc position within the current tile */ |
6150 | 3388 uint x = v->x_pos & 0xF; |
3389 uint y = v->y_pos & 0xF; | |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3390 |
8312
f6764781d2eb
(svn r11877) -Fix: another way to crash competitors' train in a station
smatz <smatz@openttd.org>
parents:
8305
diff
changeset
|
3391 /* for diagonal directions, 'x' will be 0..15 - |
f6764781d2eb
(svn r11877) -Fix: another way to crash competitors' train in a station
smatz <smatz@openttd.org>
parents:
8305
diff
changeset
|
3392 * for other directions, it will be 1, 3, 5, ..., 15 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3393 switch (v->direction) { |
8312
f6764781d2eb
(svn r11877) -Fix: another way to crash competitors' train in a station
smatz <smatz@openttd.org>
parents:
8305
diff
changeset
|
3394 case DIR_N : x = ~x + ~y + 25; break; |
15579
5f128be91f59
(svn r20239) -Doc: Give a common name to all fall throughs (FALL THROUGH).
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
3395 case DIR_NW: x = y; // FALL THROUGH |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3396 case DIR_NE: x = ~x + 16; break; |
8312
f6764781d2eb
(svn r11877) -Fix: another way to crash competitors' train in a station
smatz <smatz@openttd.org>
parents:
8305
diff
changeset
|
3397 case DIR_E : x = ~x + y + 9; break; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3398 case DIR_SE: x = y; break; |
8312
f6764781d2eb
(svn r11877) -Fix: another way to crash competitors' train in a station
smatz <smatz@openttd.org>
parents:
8305
diff
changeset
|
3399 case DIR_S : x = x + y - 7; break; |
f6764781d2eb
(svn r11877) -Fix: another way to crash competitors' train in a station
smatz <smatz@openttd.org>
parents:
8305
diff
changeset
|
3400 case DIR_W : x = ~y + x + 9; break; |
5587
c44c070c5032
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents:
5584
diff
changeset
|
3401 default: break; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3402 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3403 |
17452
aad8b54a8fa6
(svn r22206) -Revert-ish (r14526) / Unfix-ish [FS#3569] / Fix [FS#4545]: the "center" (for movement) of vehicles is (currently still) always at 4/8th original vehicle length from the front, so trains should stop at the same location regardless of the length of the front engine
rubidium <rubidium@openttd.org>
parents:
17451
diff
changeset
|
3404 /* Do not reverse when approaching red signal. Make sure the vehicle's front |
aad8b54a8fa6
(svn r22206) -Revert-ish (r14526) / Unfix-ish [FS#3569] / Fix [FS#4545]: the "center" (for movement) of vehicles is (currently still) always at 4/8th original vehicle length from the front, so trains should stop at the same location regardless of the length of the front engine
rubidium <rubidium@openttd.org>
parents:
17451
diff
changeset
|
3405 * does not cross the tile boundary when we do reverse, but as the vehicle's |
aad8b54a8fa6
(svn r22206) -Revert-ish (r14526) / Unfix-ish [FS#3569] / Fix [FS#4545]: the "center" (for movement) of vehicles is (currently still) always at 4/8th original vehicle length from the front, so trains should stop at the same location regardless of the length of the front engine
rubidium <rubidium@openttd.org>
parents:
17451
diff
changeset
|
3406 * location is based on their center, use half a vehicle's length as offset. |
aad8b54a8fa6
(svn r22206) -Revert-ish (r14526) / Unfix-ish [FS#3569] / Fix [FS#4545]: the "center" (for movement) of vehicles is (currently still) always at 4/8th original vehicle length from the front, so trains should stop at the same location regardless of the length of the front engine
rubidium <rubidium@openttd.org>
parents:
17451
diff
changeset
|
3407 * Actually, the center of all vehicles is half a normal vehicle's length |
aad8b54a8fa6
(svn r22206) -Revert-ish (r14526) / Unfix-ish [FS#3569] / Fix [FS#4545]: the "center" (for movement) of vehicles is (currently still) always at 4/8th original vehicle length from the front, so trains should stop at the same location regardless of the length of the front engine
rubidium <rubidium@openttd.org>
parents:
17451
diff
changeset
|
3408 * from the front of the vehicle, so even in case the vehicle is 1/8th |
aad8b54a8fa6
(svn r22206) -Revert-ish (r14526) / Unfix-ish [FS#3569] / Fix [FS#4545]: the "center" (for movement) of vehicles is (currently still) always at 4/8th original vehicle length from the front, so trains should stop at the same location regardless of the length of the front engine
rubidium <rubidium@openttd.org>
parents:
17451
diff
changeset
|
3409 * long, the center is still at 1/2 of VEHICLE_LENGTH. Basically FS#3569. */ |
aad8b54a8fa6
(svn r22206) -Revert-ish (r14526) / Unfix-ish [FS#3569] / Fix [FS#4545]: the "center" (for movement) of vehicles is (currently still) always at 4/8th original vehicle length from the front, so trains should stop at the same location regardless of the length of the front engine
rubidium <rubidium@openttd.org>
parents:
17451
diff
changeset
|
3410 if (!signal && x + VEHICLE_LENGTH / 2 >= TILE_SIZE) { |
8305
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3411 /* we are too near the tile end, reverse now */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3412 v->cur_speed = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3413 ReverseTrainDirection(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3414 return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3415 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3416 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
3417 /* slow down */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3418 v->vehstatus |= VS_TRAIN_SLOWING; |
6150 | 3419 uint16 break_speed = _breakdown_speeds[x & 0xF]; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3420 if (break_speed < v->cur_speed) v->cur_speed = break_speed; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3421 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3422 return true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3423 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3424 |
8305
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3425 |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3426 /** |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3427 * Determines whether train would like to leave the tile |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3428 * @param v train to test |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3429 * @return true iff vehicle is NOT entering or inside a depot or tunnel/bridge |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3430 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
3431 static bool TrainCanLeaveTile(const Train *v) |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3432 { |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3433 /* Exit if inside a tunnel/bridge or a depot */ |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
3434 if (v->track == TRACK_BIT_WORMHOLE || v->track == TRACK_BIT_DEPOT) return false; |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3435 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3436 TileIndex tile = v->tile; |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3437 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3438 /* entering a tunnel/bridge? */ |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3439 if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3440 DiagDirection dir = GetTunnelBridgeDirection(tile); |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3441 if (DiagDirToDir(dir) == v->direction) return false; |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3442 } |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3443 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3444 /* entering a depot? */ |
8961
b33bcd7fa037
(svn r12753) -Codechange: do not use IsDepotTypeTile() where simpler function can be used
smatz <smatz@openttd.org>
parents:
8954
diff
changeset
|
3445 if (IsRailDepotTile(tile)) { |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3446 DiagDirection dir = ReverseDiagDir(GetRailDepotDirection(tile)); |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3447 if (DiagDirToDir(dir) == v->direction) return false; |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3448 } |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3449 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3450 return true; |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3451 } |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3452 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3453 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3454 /** |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3455 * Determines whether train is approaching a rail-road crossing |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3456 * (thus making it barred) |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3457 * @param v front engine of train |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3458 * @return TileIndex of crossing the train is approaching, else INVALID_TILE |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3459 * @pre v in non-crashed front engine |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3460 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
3461 static TileIndex TrainApproachingCrossingTile(const Train *v) |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3462 { |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
3463 assert(v->IsFrontEngine()); |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3464 assert(!(v->vehstatus & VS_CRASHED)); |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3465 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3466 if (!TrainCanLeaveTile(v)) return INVALID_TILE; |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3467 |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
3468 DiagDirection dir = TrainExitDir(v->direction, v->track); |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3469 TileIndex tile = v->tile + TileOffsByDiagDir(dir); |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3470 |
8606
86c438420c53
(svn r12188) -Codechange [FS#1782]: do not check twice for correct rail owner (patch by Vikthor)
smatz <smatz@openttd.org>
parents:
8598
diff
changeset
|
3471 /* not a crossing || wrong axis || unusable rail (wrong type or owner) */ |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3472 if (!IsLevelCrossingTile(tile) || DiagDirToAxis(dir) == GetCrossingRoadAxis(tile) || |
8606
86c438420c53
(svn r12188) -Codechange [FS#1782]: do not check twice for correct rail owner (patch by Vikthor)
smatz <smatz@openttd.org>
parents:
8598
diff
changeset
|
3473 !CheckCompatibleRail(v, tile)) { |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3474 return INVALID_TILE; |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3475 } |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3476 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3477 return tile; |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3478 } |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3479 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3480 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3481 /** |
8305
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3482 * Checks for line end. Also, bars crossing at next tile if needed |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3483 * |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3484 * @param v vehicle we are checking |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3485 * @return true iff we did NOT have to reverse |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3486 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
3487 static bool TrainCheckIfLineEnds(Train *v) |
8305
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3488 { |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3489 /* First, handle broken down train */ |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3490 |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3491 int t = v->breakdown_ctr; |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3492 if (t > 1) { |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3493 v->vehstatus |= VS_TRAIN_SLOWING; |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3494 |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3495 uint16 break_speed = _breakdown_speeds[GB(~t, 4, 4)]; |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3496 if (break_speed < v->cur_speed) v->cur_speed = break_speed; |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3497 } else { |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3498 v->vehstatus &= ~VS_TRAIN_SLOWING; |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3499 } |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3500 |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3501 if (!TrainCanLeaveTile(v)) return true; |
8305
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3502 |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3503 /* Determine the non-diagonal direction in which we will exit this tile */ |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
3504 DiagDirection dir = TrainExitDir(v->direction, v->track); |
8305
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3505 /* Calculate next tile */ |
8334
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3506 TileIndex tile = v->tile + TileOffsByDiagDir(dir); |
8305
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3507 |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3508 /* Determine the track status on the next tile */ |
8794
0a524ed2b87b
(svn r12532) -Cleanup: Replace two tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8793
diff
changeset
|
3509 TrackStatus ts = GetTileTrackStatus(tile, TRANSPORT_RAIL, 0, ReverseDiagDir(dir)); |
0a524ed2b87b
(svn r12532) -Cleanup: Replace two tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8793
diff
changeset
|
3510 TrackdirBits reachable_trackdirs = DiagdirReachesTrackdirs(dir); |
0a524ed2b87b
(svn r12532) -Cleanup: Replace two tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8793
diff
changeset
|
3511 |
0a524ed2b87b
(svn r12532) -Cleanup: Replace two tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8793
diff
changeset
|
3512 TrackdirBits trackdirbits = TrackStatusToTrackdirBits(ts) & reachable_trackdirs; |
0a524ed2b87b
(svn r12532) -Cleanup: Replace two tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8793
diff
changeset
|
3513 TrackdirBits red_signals = TrackStatusToRedSignals(ts) & reachable_trackdirs; |
8305
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3514 |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3515 /* We are sure the train is not entering a depot, it is detected above */ |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3516 |
8482
dd2dbdff6d0d
(svn r12057) -Fix: slowdown train when approaching 90deg turn when 90deg turns are forbidden
smatz <smatz@openttd.org>
parents:
8467
diff
changeset
|
3517 /* mask unreachable track bits if we are forbidden to do 90deg turns */ |
8616
9e46ac001a8c
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch <frosch@openttd.org>
parents:
8614
diff
changeset
|
3518 TrackBits bits = TrackdirBitsToTrackBits(trackdirbits); |
13833
ad09d18a3e34
(svn r18362) -Cleanup: remove OPF for RVs and NTP to clean up lots of code and simplify some things for the future
rubidium <rubidium@openttd.org>
parents:
13832
diff
changeset
|
3519 if (_settings_game.pf.forbid_90_deg) { |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
3520 bits &= ~TrackCrossesTracks(FindFirstTrack(v->track)); |
8482
dd2dbdff6d0d
(svn r12057) -Fix: slowdown train when approaching 90deg turn when 90deg turns are forbidden
smatz <smatz@openttd.org>
parents:
8467
diff
changeset
|
3521 } |
dd2dbdff6d0d
(svn r12057) -Fix: slowdown train when approaching 90deg turn when 90deg turns are forbidden
smatz <smatz@openttd.org>
parents:
8467
diff
changeset
|
3522 |
8606
86c438420c53
(svn r12188) -Codechange [FS#1782]: do not check twice for correct rail owner (patch by Vikthor)
smatz <smatz@openttd.org>
parents:
8598
diff
changeset
|
3523 /* no suitable trackbits at all || unusable rail (wrong type or owner) */ |
86c438420c53
(svn r12188) -Codechange [FS#1782]: do not check twice for correct rail owner (patch by Vikthor)
smatz <smatz@openttd.org>
parents:
8598
diff
changeset
|
3524 if (bits == TRACK_BIT_NONE || !CheckCompatibleRail(v, tile)) { |
8305
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3525 return TrainApproachingLineEnd(v, false); |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3526 } |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3527 |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3528 /* approaching red signal */ |
8616
9e46ac001a8c
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch <frosch@openttd.org>
parents:
8614
diff
changeset
|
3529 if ((trackdirbits & red_signals) != 0) return TrainApproachingLineEnd(v, true); |
8305
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3530 |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3531 /* approaching a rail/road crossing? then make it red */ |
8356
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
3532 if (IsLevelCrossingTile(tile)) MaybeBarCrossingWithSound(tile); |
8305
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3533 |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3534 return true; |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3535 } |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3536 |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
3537 |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
3538 static bool TrainLocoHandler(Train *v, bool mode) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3539 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3540 /* train has crashed? */ |
7476
a24293df92f5
(svn r10983) -Codechange: use vehstatus & VS_CRASHED instead of some other "methods" custom to each vehicle to determine whether the vehicle is crashed.
rubidium <rubidium@openttd.org>
parents:
7425
diff
changeset
|
3541 if (v->vehstatus & VS_CRASHED) { |
11970
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3542 return mode ? true : HandleCrashedTrain(v); // 'this' can be deleted here |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3543 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3544 |
15362
834b4f9842c2
(svn r20005) -Codechange: Enumify force_proceed.
frosch <frosch@openttd.org>
parents:
15351
diff
changeset
|
3545 if (v->force_proceed != TFP_NONE) { |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
3546 ClrBit(v->flags, VRF_TRAIN_STUCK); |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
13001
diff
changeset
|
3547 SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
9808
fa8743b489ff
(svn r13950) -Add [YAPP]: Trains can now also be in a 'stuck' state when waiting on a path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9775
diff
changeset
|
3548 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3549 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3550 /* train is broken down? */ |
15957
1452fca58b4f
(svn r20645) -Codechange [FS#4086]: unify the code for checking for breakdown handling as well (Hirundo)
rubidium <rubidium@openttd.org>
parents:
15956
diff
changeset
|
3551 if (v->HandleBreakdown()) return true; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3552 |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
3553 if (HasBit(v->flags, VRF_REVERSING) && v->cur_speed == 0) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3554 ReverseTrainDirection(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3555 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3556 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3557 /* exit if train is stopped */ |
12082
d092f17a921d
(svn r16491) -Codechange: Added parentheses around bitwise operators for code style.
alberth <alberth@openttd.org>
parents:
12073
diff
changeset
|
3558 if ((v->vehstatus & VS_STOPPED) && v->cur_speed == 0) return true; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3559 |
11972
fd10870d74d4
(svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents:
11970
diff
changeset
|
3560 bool valid_order = !v->current_order.IsType(OT_NOTHING) && v->current_order.GetType() != OT_CONDITIONAL; |
8827
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8794
diff
changeset
|
3561 if (ProcessOrders(v) && CheckReverseTrain(v)) { |
14213
41b2e7bf03da
(svn r18764) -Fix [FS#3422]: split the (un)load ticks counter and signal wait counter; sometimes they might get into eachother's way
rubidium <rubidium@openttd.org>
parents:
14127
diff
changeset
|
3562 v->wait_counter = 0; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3563 v->cur_speed = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3564 v->subspeed = 0; |
15449
f6ee1b7fde96
(svn r20098) -Fix [FS#3898]: A train reversing in a station would sometimes fail to release its reserved path.
michi_cc <michi_cc@openttd.org>
parents:
15436
diff
changeset
|
3565 ClrBit(v->flags, VRF_LEAVING_STATION); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3566 ReverseTrainDirection(v); |
11970
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3567 return true; |
15449
f6ee1b7fde96
(svn r20098) -Fix [FS#3898]: A train reversing in a station would sometimes fail to release its reserved path.
michi_cc <michi_cc@openttd.org>
parents:
15436
diff
changeset
|
3568 } else if (HasBit(v->flags, VRF_LEAVING_STATION)) { |
f6ee1b7fde96
(svn r20098) -Fix [FS#3898]: A train reversing in a station would sometimes fail to release its reserved path.
michi_cc <michi_cc@openttd.org>
parents:
15436
diff
changeset
|
3569 /* Try to reserve a path when leaving the station as we |
f6ee1b7fde96
(svn r20098) -Fix [FS#3898]: A train reversing in a station would sometimes fail to release its reserved path.
michi_cc <michi_cc@openttd.org>
parents:
15436
diff
changeset
|
3570 * might not be marked as wanting a reservation, e.g. |
f6ee1b7fde96
(svn r20098) -Fix [FS#3898]: A train reversing in a station would sometimes fail to release its reserved path.
michi_cc <michi_cc@openttd.org>
parents:
15436
diff
changeset
|
3571 * when an overlength train gets turned around in a station. */ |
16306
091fcb86fcba
(svn r21014) -Fix [FS#4179](r20098): Reversing of trains in stations while last wagon was in a depot or on a bridge-/tunnelhead caused trouble.
frosch <frosch@openttd.org>
parents:
16075
diff
changeset
|
3572 DiagDirection dir = TrainExitDir(v->direction, v->track); |
091fcb86fcba
(svn r21014) -Fix [FS#4179](r20098): Reversing of trains in stations while last wagon was in a depot or on a bridge-/tunnelhead caused trouble.
frosch <frosch@openttd.org>
parents:
16075
diff
changeset
|
3573 if (IsRailDepotTile(v->tile) || IsTileType(v->tile, MP_TUNNELBRIDGE)) dir = INVALID_DIAGDIR; |
091fcb86fcba
(svn r21014) -Fix [FS#4179](r20098): Reversing of trains in stations while last wagon was in a depot or on a bridge-/tunnelhead caused trouble.
frosch <frosch@openttd.org>
parents:
16075
diff
changeset
|
3574 |
091fcb86fcba
(svn r21014) -Fix [FS#4179](r20098): Reversing of trains in stations while last wagon was in a depot or on a bridge-/tunnelhead caused trouble.
frosch <frosch@openttd.org>
parents:
16075
diff
changeset
|
3575 if (UpdateSignalsOnSegment(v->tile, dir, v->owner) == SIGSEG_PBS || _settings_game.pf.reserve_paths) { |
15449
f6ee1b7fde96
(svn r20098) -Fix [FS#3898]: A train reversing in a station would sometimes fail to release its reserved path.
michi_cc <michi_cc@openttd.org>
parents:
15436
diff
changeset
|
3576 TryPathReserve(v, true, true); |
f6ee1b7fde96
(svn r20098) -Fix [FS#3898]: A train reversing in a station would sometimes fail to release its reserved path.
michi_cc <michi_cc@openttd.org>
parents:
15436
diff
changeset
|
3577 } |
f6ee1b7fde96
(svn r20098) -Fix [FS#3898]: A train reversing in a station would sometimes fail to release its reserved path.
michi_cc <michi_cc@openttd.org>
parents:
15436
diff
changeset
|
3578 ClrBit(v->flags, VRF_LEAVING_STATION); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3579 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3580 |
6594
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6593
diff
changeset
|
3581 v->HandleLoading(mode); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3582 |
11970
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3583 if (v->current_order.IsType(OT_LOADING)) return true; |
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3584 |
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3585 if (CheckTrainStayInDepot(v)) return true; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3586 |
16511
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16510
diff
changeset
|
3587 if (!mode) v->ShowVisualEffect(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3588 |
9816
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
3589 /* We had no order but have an order now, do look ahead. */ |
11972
fd10870d74d4
(svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents:
11970
diff
changeset
|
3590 if (!valid_order && !v->current_order.IsType(OT_NOTHING)) { |
9816
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
3591 CheckNextTrainTile(v); |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
3592 } |
72806df62429
(svn r13958) -Add [YAPP]: Implement look-ahead for trains so they extend their reservation before reaching the end. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9813
diff
changeset
|
3593 |
9813
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
3594 /* Handle stuck trains. */ |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
3595 if (!mode && HasBit(v->flags, VRF_TRAIN_STUCK)) { |
14213
41b2e7bf03da
(svn r18764) -Fix [FS#3422]: split the (un)load ticks counter and signal wait counter; sometimes they might get into eachother's way
rubidium <rubidium@openttd.org>
parents:
14127
diff
changeset
|
3596 ++v->wait_counter; |
9813
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
3597 |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
3598 /* Should we try reversing this tick if still stuck? */ |
17223
a1dda316ecbe
(svn r21962) -Feature-ish: GUI setting to disable reversing at signals
rubidium <rubidium@openttd.org>
parents:
17221
diff
changeset
|
3599 bool turn_around = v->wait_counter % (_settings_game.pf.wait_for_pbs_path * DAY_TICKS) == 0 && _settings_game.pf.reverse_at_signals; |
14213
41b2e7bf03da
(svn r18764) -Fix [FS#3422]: split the (un)load ticks counter and signal wait counter; sometimes they might get into eachother's way
rubidium <rubidium@openttd.org>
parents:
14127
diff
changeset
|
3600 |
15362
834b4f9842c2
(svn r20005) -Codechange: Enumify force_proceed.
frosch <frosch@openttd.org>
parents:
15351
diff
changeset
|
3601 if (!turn_around && v->wait_counter % _settings_game.pf.path_backoff_interval != 0 && v->force_proceed == TFP_NONE) return true; |
9813
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
3602 if (!TryPathReserve(v)) { |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
3603 /* Still stuck. */ |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
3604 if (turn_around) ReverseTrainDirection(v); |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
3605 |
14213
41b2e7bf03da
(svn r18764) -Fix [FS#3422]: split the (un)load ticks counter and signal wait counter; sometimes they might get into eachother's way
rubidium <rubidium@openttd.org>
parents:
14127
diff
changeset
|
3606 if (HasBit(v->flags, VRF_TRAIN_STUCK) && v->wait_counter > 2 * _settings_game.pf.wait_for_pbs_path * DAY_TICKS) { |
9813
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
3607 /* Show message to player. */ |
16772
975815b08336
(svn r21505) -Change: generalise the lost_train_warning setting to lost_vehicle_warning
rubidium <rubidium@openttd.org>
parents:
16771
diff
changeset
|
3608 if (_settings_client.gui.lost_vehicle_warn && v->owner == _local_company) { |
10574
bf4424d086f0
(svn r14831) -Codechange: use {VEHICLE} instead of Train/Ship/Road veh/Aircraft/{STRING} {COMMA} in lang files (part by Swallow)
smatz <smatz@openttd.org>
parents:
10571
diff
changeset
|
3609 SetDParam(0, v->index); |
12010
d0bf08a7c260
(svn r16416) -Fix [FS#2912]: Rework deleting of news when referenced vehicles/stations/industries are deleted.
frosch <frosch@openttd.org>
parents:
12008
diff
changeset
|
3610 AddVehicleNewsItem( |
12619
2f530108f787
(svn r17062) -Change: unify the naming of some 125 strings
rubidium <rubidium@openttd.org>
parents:
12510
diff
changeset
|
3611 STR_NEWS_TRAIN_IS_STUCK, |
9813
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
3612 NS_ADVICE, |
12010
d0bf08a7c260
(svn r16416) -Fix [FS#2912]: Rework deleting of news when referenced vehicles/stations/industries are deleted.
frosch <frosch@openttd.org>
parents:
12008
diff
changeset
|
3613 v->index |
d0bf08a7c260
(svn r16416) -Fix [FS#2912]: Rework deleting of news when referenced vehicles/stations/industries are deleted.
frosch <frosch@openttd.org>
parents:
12008
diff
changeset
|
3614 ); |
9813
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
3615 } |
14213
41b2e7bf03da
(svn r18764) -Fix [FS#3422]: split the (un)load ticks counter and signal wait counter; sometimes they might get into eachother's way
rubidium <rubidium@openttd.org>
parents:
14127
diff
changeset
|
3616 v->wait_counter = 0; |
9813
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
3617 } |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
3618 /* Exit if force proceed not pressed, else reset stuck flag anyway. */ |
15362
834b4f9842c2
(svn r20005) -Codechange: Enumify force_proceed.
frosch <frosch@openttd.org>
parents:
15351
diff
changeset
|
3619 if (v->force_proceed == TFP_NONE) return true; |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
3620 ClrBit(v->flags, VRF_TRAIN_STUCK); |
14213
41b2e7bf03da
(svn r18764) -Fix [FS#3422]: split the (un)load ticks counter and signal wait counter; sometimes they might get into eachother's way
rubidium <rubidium@openttd.org>
parents:
14127
diff
changeset
|
3621 v->wait_counter = 0; |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
13001
diff
changeset
|
3622 SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
9813
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
3623 } |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
3624 } |
77ed5f6edd46
(svn r13955) -Codechange [YAPP]: Try to extend the path of a stuck train so it is able to continue. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9812
diff
changeset
|
3625 |
10682
2d192d93d11c
(svn r14993) -Fix (r14957, r14975): Do not reverse the train with OT_LEAVESTATION as that breaks PBS prediction.
frosch <frosch@openttd.org>
parents:
10672
diff
changeset
|
3626 if (v->current_order.IsType(OT_LEAVESTATION)) { |
2d192d93d11c
(svn r14993) -Fix (r14957, r14975): Do not reverse the train with OT_LEAVESTATION as that breaks PBS prediction.
frosch <frosch@openttd.org>
parents:
10672
diff
changeset
|
3627 v->current_order.Free(); |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
13001
diff
changeset
|
3628 SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
11970
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3629 return true; |
10682
2d192d93d11c
(svn r14993) -Fix (r14957, r14975): Do not reverse the train with OT_LEAVESTATION as that breaks PBS prediction.
frosch <frosch@openttd.org>
parents:
10672
diff
changeset
|
3630 } |
2d192d93d11c
(svn r14993) -Fix (r14957, r14975): Do not reverse the train with OT_LEAVESTATION as that breaks PBS prediction.
frosch <frosch@openttd.org>
parents:
10672
diff
changeset
|
3631 |
14284
fc532d11eb85
(svn r18836) -Codechange: make TrainUpdateSpeed a class function and update some comments (Terkhen)
rubidium <rubidium@openttd.org>
parents:
14261
diff
changeset
|
3632 int j = v->UpdateSpeed(); |
8426
916b061b84a0
(svn r11996) -Fix [FS#1706]: update train statusbar when stopping from zero speed
smatz <smatz@openttd.org>
parents:
8390
diff
changeset
|
3633 |
916b061b84a0
(svn r11996) -Fix [FS#1706]: update train statusbar when stopping from zero speed
smatz <smatz@openttd.org>
parents:
8390
diff
changeset
|
3634 /* we need to invalidate the widget if we are stopping from 'Stopping 0 km/h' to 'Stopped' */ |
15351
6adf1d7d80cd
(svn r19992) -Fix [FS#3878]: Clear force_proceed when entering depots and when loading.
frosch <frosch@openttd.org>
parents:
15320
diff
changeset
|
3635 if (v->cur_speed == 0 && (v->vehstatus & VS_STOPPED)) { |
13977
bb2258bdc43d
(svn r18515) -Change: make it visible when you're to pass the next signal on danger and possible to cancel it
rubidium <rubidium@openttd.org>
parents:
13958
diff
changeset
|
3636 /* If we manually stopped, we're not force-proceeding anymore. */ |
15362
834b4f9842c2
(svn r20005) -Codechange: Enumify force_proceed.
frosch <frosch@openttd.org>
parents:
15351
diff
changeset
|
3637 v->force_proceed = TFP_NONE; |
15351
6adf1d7d80cd
(svn r19992) -Fix [FS#3878]: Clear force_proceed when entering depots and when loading.
frosch <frosch@openttd.org>
parents:
15320
diff
changeset
|
3638 SetWindowDirty(WC_VEHICLE_VIEW, v->index); |
8426
916b061b84a0
(svn r11996) -Fix [FS#1706]: update train statusbar when stopping from zero speed
smatz <smatz@openttd.org>
parents:
8390
diff
changeset
|
3639 } |
916b061b84a0
(svn r11996) -Fix [FS#1706]: update train statusbar when stopping from zero speed
smatz <smatz@openttd.org>
parents:
8390
diff
changeset
|
3640 |
15436
a90f03aeb026
(svn r20079) -Codechange [FS#3922]: Add helper functions to deal with the 192-256-magic of vehicle movement.
frosch <frosch@openttd.org>
parents:
15363
diff
changeset
|
3641 int adv_spd = v->GetAdvanceDistance(); |
10214
44a5ab175885
(svn r14436) -Fix [FS#1793]: (fast) trains would sometimes move one time too often/little when moving from diagonal<->non-diagonal tracks (iguannab)
rubidium <rubidium@openttd.org>
parents:
10208
diff
changeset
|
3642 if (j < adv_spd) { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
3643 /* if the vehicle has speed 0, update the last_speed field. */ |
17172
679a25d71a9d
(svn r21911) -Codechange: move tcache.last_speed to gcache.last_speed and make SetLastSpeed a function of GroundVehicle
rubidium <rubidium@openttd.org>
parents:
17165
diff
changeset
|
3644 if (v->cur_speed == 0) v->SetLastSpeed(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3645 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3646 TrainCheckIfLineEnds(v); |
10214
44a5ab175885
(svn r14436) -Fix [FS#1793]: (fast) trains would sometimes move one time too often/little when moving from diagonal<->non-diagonal tracks (iguannab)
rubidium <rubidium@openttd.org>
parents:
10208
diff
changeset
|
3647 /* Loop until the train has finished moving. */ |
11701
362680cbb585
(svn r16087) -Fix (r16079): slow trains wouldn't crash into eachother anymore
rubidium <rubidium@openttd.org>
parents:
11694
diff
changeset
|
3648 for (;;) { |
10214
44a5ab175885
(svn r14436) -Fix [FS#1793]: (fast) trains would sometimes move one time too often/little when moving from diagonal<->non-diagonal tracks (iguannab)
rubidium <rubidium@openttd.org>
parents:
10208
diff
changeset
|
3649 j -= adv_spd; |
11327
fc99317cb85b
(svn r15677) -Fix [FS#2546]: vehicle images would be determined during the process of moving the vehicle which means that only the (orientation) data for the vehicles in front of it is valid. Now the data for the vehicles behind the vehicle are valid too.
rubidium <rubidium@openttd.org>
parents:
11326
diff
changeset
|
3650 TrainController(v, NULL); |
11701
362680cbb585
(svn r16087) -Fix (r16079): slow trains wouldn't crash into eachother anymore
rubidium <rubidium@openttd.org>
parents:
11694
diff
changeset
|
3651 /* Don't continue to move if the train crashed. */ |
362680cbb585
(svn r16087) -Fix (r16079): slow trains wouldn't crash into eachother anymore
rubidium <rubidium@openttd.org>
parents:
11694
diff
changeset
|
3652 if (CheckTrainCollision(v)) break; |
15436
a90f03aeb026
(svn r20079) -Codechange [FS#3922]: Add helper functions to deal with the 192-256-magic of vehicle movement.
frosch <frosch@openttd.org>
parents:
15363
diff
changeset
|
3653 /* Determine distance to next map position */ |
a90f03aeb026
(svn r20079) -Codechange [FS#3922]: Add helper functions to deal with the 192-256-magic of vehicle movement.
frosch <frosch@openttd.org>
parents:
15363
diff
changeset
|
3654 adv_spd = v->GetAdvanceDistance(); |
11694
50291ef7d6e6
(svn r16079) -Fix [FS#2824]: insanely fast trains would not stop in time for stations
rubidium <rubidium@openttd.org>
parents:
11690
diff
changeset
|
3655 |
11701
362680cbb585
(svn r16087) -Fix (r16079): slow trains wouldn't crash into eachother anymore
rubidium <rubidium@openttd.org>
parents:
11694
diff
changeset
|
3656 /* No more moving this tick */ |
362680cbb585
(svn r16087) -Fix (r16079): slow trains wouldn't crash into eachother anymore
rubidium <rubidium@openttd.org>
parents:
11694
diff
changeset
|
3657 if (j < adv_spd || v->cur_speed == 0) break; |
362680cbb585
(svn r16087) -Fix (r16079): slow trains wouldn't crash into eachother anymore
rubidium <rubidium@openttd.org>
parents:
11694
diff
changeset
|
3658 |
362680cbb585
(svn r16087) -Fix (r16079): slow trains wouldn't crash into eachother anymore
rubidium <rubidium@openttd.org>
parents:
11694
diff
changeset
|
3659 OrderType order_type = v->current_order.GetType(); |
362680cbb585
(svn r16087) -Fix (r16079): slow trains wouldn't crash into eachother anymore
rubidium <rubidium@openttd.org>
parents:
11694
diff
changeset
|
3660 /* Do not skip waypoints (incl. 'via' stations) when passing through at full speed. */ |
12472
604a2cfc77ab
(svn r16909) -Fix [FS#2996]: NewGRF stations would be triggering assertions all over the place when using the more advanced station types.
rubidium <rubidium@openttd.org>
parents:
12471
diff
changeset
|
3661 if ((order_type == OT_GOTO_WAYPOINT || order_type == OT_GOTO_STATION) && |
11701
362680cbb585
(svn r16087) -Fix (r16079): slow trains wouldn't crash into eachother anymore
rubidium <rubidium@openttd.org>
parents:
11694
diff
changeset
|
3662 (v->current_order.GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) && |
362680cbb585
(svn r16087) -Fix (r16079): slow trains wouldn't crash into eachother anymore
rubidium <rubidium@openttd.org>
parents:
11694
diff
changeset
|
3663 IsTileType(v->tile, MP_STATION) && |
12472
604a2cfc77ab
(svn r16909) -Fix [FS#2996]: NewGRF stations would be triggering assertions all over the place when using the more advanced station types.
rubidium <rubidium@openttd.org>
parents:
12471
diff
changeset
|
3664 v->current_order.GetDestination() == GetStationIndex(v->tile)) { |
11701
362680cbb585
(svn r16087) -Fix (r16079): slow trains wouldn't crash into eachother anymore
rubidium <rubidium@openttd.org>
parents:
11694
diff
changeset
|
3665 ProcessOrders(v); |
11694
50291ef7d6e6
(svn r16079) -Fix [FS#2824]: insanely fast trains would not stop in time for stations
rubidium <rubidium@openttd.org>
parents:
11690
diff
changeset
|
3666 } |
11701
362680cbb585
(svn r16087) -Fix (r16079): slow trains wouldn't crash into eachother anymore
rubidium <rubidium@openttd.org>
parents:
11694
diff
changeset
|
3667 } |
17172
679a25d71a9d
(svn r21911) -Codechange: move tcache.last_speed to gcache.last_speed and make SetLastSpeed a function of GroundVehicle
rubidium <rubidium@openttd.org>
parents:
17165
diff
changeset
|
3668 v->SetLastSpeed(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3669 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3670 |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
3671 for (Train *u = v; u != NULL; u = u->Next()) { |
11327
fc99317cb85b
(svn r15677) -Fix [FS#2546]: vehicle images would be determined during the process of moving the vehicle which means that only the (orientation) data for the vehicles in front of it is valid. Now the data for the vehicles behind the vehicle are valid too.
rubidium <rubidium@openttd.org>
parents:
11326
diff
changeset
|
3672 if ((u->vehstatus & VS_HIDDEN) != 0) continue; |
fc99317cb85b
(svn r15677) -Fix [FS#2546]: vehicle images would be determined during the process of moving the vehicle which means that only the (orientation) data for the vehicles in front of it is valid. Now the data for the vehicles behind the vehicle are valid too.
rubidium <rubidium@openttd.org>
parents:
11326
diff
changeset
|
3673 |
12666
0275245c6c62
(svn r17121) -Fix [FS#3060]: Update vehicle position cache when the vehicle sprite changes.
frosch <frosch@openttd.org>
parents:
12635
diff
changeset
|
3674 u->UpdateViewport(false, false); |
11327
fc99317cb85b
(svn r15677) -Fix [FS#2546]: vehicle images would be determined during the process of moving the vehicle which means that only the (orientation) data for the vehicles in front of it is valid. Now the data for the vehicles behind the vehicle are valid too.
rubidium <rubidium@openttd.org>
parents:
11326
diff
changeset
|
3675 } |
fc99317cb85b
(svn r15677) -Fix [FS#2546]: vehicle images would be determined during the process of moving the vehicle which means that only the (orientation) data for the vehicles in front of it is valid. Now the data for the vehicles behind the vehicle are valid too.
rubidium <rubidium@openttd.org>
parents:
11326
diff
changeset
|
3676 |
10641
94cbc9a0158b
(svn r14943) -Cleanup: remove some rogue spaces/replace some rogue tabs with spaces
rubidium <rubidium@openttd.org>
parents:
10589
diff
changeset
|
3677 if (v->progress == 0) v->progress = j; // Save unused spd for next time, if TrainController didn't set progress |
11970
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3678 |
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3679 return true; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3680 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3681 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3682 |
7488
307a03e3f031
(svn r10999) -Codechange: unify the way the running cost of a vehicle is determined. Patch by nycom.
rubidium <rubidium@openttd.org>
parents:
7486
diff
changeset
|
3683 |
307a03e3f031
(svn r10999) -Codechange: unify the way the running cost of a vehicle is determined. Patch by nycom.
rubidium <rubidium@openttd.org>
parents:
7486
diff
changeset
|
3684 Money Train::GetRunningCost() const |
307a03e3f031
(svn r10999) -Codechange: unify the way the running cost of a vehicle is determined. Patch by nycom.
rubidium <rubidium@openttd.org>
parents:
7486
diff
changeset
|
3685 { |
307a03e3f031
(svn r10999) -Codechange: unify the way the running cost of a vehicle is determined. Patch by nycom.
rubidium <rubidium@openttd.org>
parents:
7486
diff
changeset
|
3686 Money cost = 0; |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
3687 const Train *v = this; |
7488
307a03e3f031
(svn r10999) -Codechange: unify the way the running cost of a vehicle is determined. Patch by nycom.
rubidium <rubidium@openttd.org>
parents:
7486
diff
changeset
|
3688 |
307a03e3f031
(svn r10999) -Codechange: unify the way the running cost of a vehicle is determined. Patch by nycom.
rubidium <rubidium@openttd.org>
parents:
7486
diff
changeset
|
3689 do { |
13741
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13599
diff
changeset
|
3690 const Engine *e = Engine::Get(v->engine_type); |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13599
diff
changeset
|
3691 if (e->u.rail.running_cost_class == INVALID_PRICE) continue; |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13599
diff
changeset
|
3692 |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13599
diff
changeset
|
3693 uint cost_factor = GetVehicleProperty(v, PROP_TRAIN_RUNNING_COST_FACTOR, e->u.rail.running_cost); |
7488
307a03e3f031
(svn r10999) -Codechange: unify the way the running cost of a vehicle is determined. Patch by nycom.
rubidium <rubidium@openttd.org>
parents:
7486
diff
changeset
|
3694 if (cost_factor == 0) continue; |
307a03e3f031
(svn r10999) -Codechange: unify the way the running cost of a vehicle is determined. Patch by nycom.
rubidium <rubidium@openttd.org>
parents:
7486
diff
changeset
|
3695 |
9208
aa4576e5111a
(svn r13074) -Fix: For multiheaded engines, halve power and running cost when used instead of when loading, to allow callback values to work properly.
peter1138 <peter1138@openttd.org>
parents:
9115
diff
changeset
|
3696 /* Halve running cost for multiheaded parts */ |
12302
fc8e41f34b8c
(svn r16719) -Codechange: make IsArticulatedPart(), IsTrainEngine(), IsTrainWagon(), IsMultiheaded(), EngineHasArticPart() and IsRearDualheaded() members of Train
smatz <smatz@openttd.org>
parents:
12301
diff
changeset
|
3697 if (v->IsMultiheaded()) cost_factor /= 2; |
9208
aa4576e5111a
(svn r13074) -Fix: For multiheaded engines, halve power and running cost when used instead of when loading, to allow callback values to work properly.
peter1138 <peter1138@openttd.org>
parents:
9115
diff
changeset
|
3698 |
15763
a60a50f29f64
(svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents:
15710
diff
changeset
|
3699 cost += GetPrice(e->u.rail.running_cost_class, cost_factor, e->grf_prop.grffile); |
12306
d0ff55a976ad
(svn r16723) -Codechange: make GetNextArticPart(), GetLastEnginePart(), GetNextVehicle(), GetPrevVehicle(), GetNextUnit(), GetPrevUnit() members of Train
smatz <smatz@openttd.org>
parents:
12303
diff
changeset
|
3700 } while ((v = v->GetNextVehicle()) != NULL); |
7488
307a03e3f031
(svn r10999) -Codechange: unify the way the running cost of a vehicle is determined. Patch by nycom.
rubidium <rubidium@openttd.org>
parents:
7486
diff
changeset
|
3701 |
307a03e3f031
(svn r10999) -Codechange: unify the way the running cost of a vehicle is determined. Patch by nycom.
rubidium <rubidium@openttd.org>
parents:
7486
diff
changeset
|
3702 return cost; |
307a03e3f031
(svn r10999) -Codechange: unify the way the running cost of a vehicle is determined. Patch by nycom.
rubidium <rubidium@openttd.org>
parents:
7486
diff
changeset
|
3703 } |
307a03e3f031
(svn r10999) -Codechange: unify the way the running cost of a vehicle is determined. Patch by nycom.
rubidium <rubidium@openttd.org>
parents:
7486
diff
changeset
|
3704 |
307a03e3f031
(svn r10999) -Codechange: unify the way the running cost of a vehicle is determined. Patch by nycom.
rubidium <rubidium@openttd.org>
parents:
7486
diff
changeset
|
3705 |
11970
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3706 bool Train::Tick() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3707 { |
7135
45123abbc930
(svn r10409) -Codechange: replace (Aircraft|RoadVeh|Ship|Train)_Tick with a Tick method in the Vehicle class.
rubidium <rubidium@openttd.org>
parents:
7134
diff
changeset
|
3708 this->tick_counter++; |
45123abbc930
(svn r10409) -Codechange: replace (Aircraft|RoadVeh|Ship|Train)_Tick with a Tick method in the Vehicle class.
rubidium <rubidium@openttd.org>
parents:
7134
diff
changeset
|
3709 |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
3710 if (this->IsFrontEngine()) { |
15363
5ea4f4fa8ea2
(svn r20006) -Fix: Trains should also have running cost while slowing down for stop.
frosch <frosch@openttd.org>
parents:
15362
diff
changeset
|
3711 if (!(this->vehstatus & VS_STOPPED) || this->cur_speed > 0) this->running_ticks++; |
11970
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3712 |
7135
45123abbc930
(svn r10409) -Codechange: replace (Aircraft|RoadVeh|Ship|Train)_Tick with a Tick method in the Vehicle class.
rubidium <rubidium@openttd.org>
parents:
7134
diff
changeset
|
3713 this->current_order_time++; |
45123abbc930
(svn r10409) -Codechange: replace (Aircraft|RoadVeh|Ship|Train)_Tick with a Tick method in the Vehicle class.
rubidium <rubidium@openttd.org>
parents:
7134
diff
changeset
|
3714 |
11970
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3715 if (!TrainLocoHandler(this, false)) return false; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3716 |
11970
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3717 return TrainLocoHandler(this, true); |
12301
218a41d3d557
(svn r16718) -Codechange: make IsFreeWagon() member of Train
smatz <smatz@openttd.org>
parents:
12300
diff
changeset
|
3718 } else if (this->IsFreeWagon() && (this->vehstatus & VS_CRASHED)) { |
7696
7ae4d4720c11
(svn r11230) -Fix [FS#1228]: one could construct trains out of crashed wagons and engines. Based on a patch by SmatZ.
rubidium <rubidium@openttd.org>
parents:
7695
diff
changeset
|
3719 /* Delete flooded standalone wagon chain */ |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
3720 if (++this->crash_anim_pos >= 4400) { |
11970
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3721 delete this; |
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3722 return false; |
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3723 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3724 } |
11970
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3725 |
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3726 return true; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3727 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3728 |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
3729 static void CheckIfTrainNeedsService(Train *v) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3730 { |
12032
2afeb10ae6ba
(svn r16439) -Change: Make the default vehicle servicing settings company-based settings, so in a multiplayer game everyone can change them.
yexo <yexo@openttd.org>
parents:
12020
diff
changeset
|
3731 if (Company::Get(v->owner)->settings.vehicle.servint_trains == 0 || !v->NeedsAutomaticServicing()) return; |
7502
2250b8ea9466
(svn r11017) -Codechange: unify determining whether a vehicle needs/can be service a little more.
rubidium <rubidium@openttd.org>
parents:
7497
diff
changeset
|
3732 if (v->IsInDepot()) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3733 VehicleServiceInDepot(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3734 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3735 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3736 |
13945
d725b850c967
(svn r18481) -Codechange: unify the curve pathfinder penalty defaults; 0.01 tile won't make a dent, 3 tiles might be a bit too much
rubidium <rubidium@openttd.org>
parents:
13942
diff
changeset
|
3737 uint max_penalty; |
d725b850c967
(svn r18481) -Codechange: unify the curve pathfinder penalty defaults; 0.01 tile won't make a dent, 3 tiles might be a bit too much
rubidium <rubidium@openttd.org>
parents:
13942
diff
changeset
|
3738 switch (_settings_game.pf.pathfinder_for_trains) { |
d725b850c967
(svn r18481) -Codechange: unify the curve pathfinder penalty defaults; 0.01 tile won't make a dent, 3 tiles might be a bit too much
rubidium <rubidium@openttd.org>
parents:
13942
diff
changeset
|
3739 case VPF_NPF: max_penalty = _settings_game.pf.npf.maximum_go_to_depot_penalty; break; |
d725b850c967
(svn r18481) -Codechange: unify the curve pathfinder penalty defaults; 0.01 tile won't make a dent, 3 tiles might be a bit too much
rubidium <rubidium@openttd.org>
parents:
13942
diff
changeset
|
3740 case VPF_YAPF: max_penalty = _settings_game.pf.yapf.maximum_go_to_depot_penalty; break; |
d725b850c967
(svn r18481) -Codechange: unify the curve pathfinder penalty defaults; 0.01 tile won't make a dent, 3 tiles might be a bit too much
rubidium <rubidium@openttd.org>
parents:
13942
diff
changeset
|
3741 default: NOT_REACHED(); |
d725b850c967
(svn r18481) -Codechange: unify the curve pathfinder penalty defaults; 0.01 tile won't make a dent, 3 tiles might be a bit too much
rubidium <rubidium@openttd.org>
parents:
13942
diff
changeset
|
3742 } |
d725b850c967
(svn r18481) -Codechange: unify the curve pathfinder penalty defaults; 0.01 tile won't make a dent, 3 tiles might be a bit too much
rubidium <rubidium@openttd.org>
parents:
13942
diff
changeset
|
3743 |
d725b850c967
(svn r18481) -Codechange: unify the curve pathfinder penalty defaults; 0.01 tile won't make a dent, 3 tiles might be a bit too much
rubidium <rubidium@openttd.org>
parents:
13942
diff
changeset
|
3744 FindDepotData tfdd = FindClosestTrainDepot(v, max_penalty); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3745 /* Only go to the depot if it is not too far out of our way. */ |
13945
d725b850c967
(svn r18481) -Codechange: unify the curve pathfinder penalty defaults; 0.01 tile won't make a dent, 3 tiles might be a bit too much
rubidium <rubidium@openttd.org>
parents:
13942
diff
changeset
|
3746 if (tfdd.best_length == UINT_MAX || tfdd.best_length > max_penalty) { |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8832
diff
changeset
|
3747 if (v->current_order.IsType(OT_GOTO_DEPOT)) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3748 /* If we were already heading for a depot but it has |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3749 * suddenly moved farther away, we continue our normal |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3750 * schedule? */ |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8832
diff
changeset
|
3751 v->current_order.MakeDummy(); |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
13001
diff
changeset
|
3752 SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3753 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3754 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3755 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3756 |
13001
c2298b1d3f83
(svn r17495) -Codechange: replace 'Depot::Get(GetDepotIndex(tile))->index' with GetDepotIndex(tile)
rubidium <rubidium@openttd.org>
parents:
12860
diff
changeset
|
3757 DepotID depot = GetDepotIndex(tfdd.tile); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3758 |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8832
diff
changeset
|
3759 if (v->current_order.IsType(OT_GOTO_DEPOT) && |
13001
c2298b1d3f83
(svn r17495) -Codechange: replace 'Depot::Get(GetDepotIndex(tile))->index' with GetDepotIndex(tile)
rubidium <rubidium@openttd.org>
parents:
12860
diff
changeset
|
3760 v->current_order.GetDestination() != depot && |
7967
e30c5ec2d272
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13 <skidd13@openttd.org>
parents:
7932
diff
changeset
|
3761 !Chance16(3, 16)) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3762 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3763 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3764 |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17564
diff
changeset
|
3765 SetBit(v->gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS); |
13001
c2298b1d3f83
(svn r17495) -Codechange: replace 'Depot::Get(GetDepotIndex(tile))->index' with GetDepotIndex(tile)
rubidium <rubidium@openttd.org>
parents:
12860
diff
changeset
|
3766 v->current_order.MakeGoToDepot(depot, ODTFB_SERVICE); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3767 v->dest_tile = tfdd.tile; |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
13001
diff
changeset
|
3768 SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3769 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3770 |
8467
284a76aa2868
(svn r12037) -Codechange: replace OnNewDay_(Aircraft|RoadVeh|Ship|Train) with an OnNewDay method in the Vehicle class
glx <glx@openttd.org>
parents:
8426
diff
changeset
|
3771 void Train::OnNewDay() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3772 { |
18007
c7a5373f1a03
(svn r22816) -Feature(ette): [NewGRF] Also age wagons and articulated parts.
frosch <frosch@openttd.org>
parents:
17909
diff
changeset
|
3773 AgeVehicle(this); |
c7a5373f1a03
(svn r22816) -Feature(ette): [NewGRF] Also age wagons and articulated parts.
frosch <frosch@openttd.org>
parents:
17909
diff
changeset
|
3774 |
8467
284a76aa2868
(svn r12037) -Codechange: replace OnNewDay_(Aircraft|RoadVeh|Ship|Train) with an OnNewDay method in the Vehicle class
glx <glx@openttd.org>
parents:
8426
diff
changeset
|
3775 if ((++this->day_counter & 7) == 0) DecreaseVehicleValue(this); |
284a76aa2868
(svn r12037) -Codechange: replace OnNewDay_(Aircraft|RoadVeh|Ship|Train) with an OnNewDay method in the Vehicle class
glx <glx@openttd.org>
parents:
8426
diff
changeset
|
3776 |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
3777 if (this->IsFrontEngine()) { |
8467
284a76aa2868
(svn r12037) -Codechange: replace OnNewDay_(Aircraft|RoadVeh|Ship|Train) with an OnNewDay method in the Vehicle class
glx <glx@openttd.org>
parents:
8426
diff
changeset
|
3778 CheckVehicleBreakdown(this); |
284a76aa2868
(svn r12037) -Codechange: replace OnNewDay_(Aircraft|RoadVeh|Ship|Train) with an OnNewDay method in the Vehicle class
glx <glx@openttd.org>
parents:
8426
diff
changeset
|
3779 |
284a76aa2868
(svn r12037) -Codechange: replace OnNewDay_(Aircraft|RoadVeh|Ship|Train) with an OnNewDay method in the Vehicle class
glx <glx@openttd.org>
parents:
8426
diff
changeset
|
3780 CheckIfTrainNeedsService(this); |
284a76aa2868
(svn r12037) -Codechange: replace OnNewDay_(Aircraft|RoadVeh|Ship|Train) with an OnNewDay method in the Vehicle class
glx <glx@openttd.org>
parents:
8426
diff
changeset
|
3781 |
284a76aa2868
(svn r12037) -Codechange: replace OnNewDay_(Aircraft|RoadVeh|Ship|Train) with an OnNewDay method in the Vehicle class
glx <glx@openttd.org>
parents:
8426
diff
changeset
|
3782 CheckOrders(this); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3783 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3784 /* update destination */ |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8832
diff
changeset
|
3785 if (this->current_order.IsType(OT_GOTO_STATION)) { |
12510
3e976121ced2
(svn r16947) -Codechange: use TileArea instead of train_tile, trainst_w and trainst_h.
rubidium <rubidium@openttd.org>
parents:
12502
diff
changeset
|
3786 TileIndex tile = Station::Get(this->current_order.GetDestination())->train_station.tile; |
10488
a9ecb9be9814
(svn r14743) -Codechange: use INVALID_TILE to indicate station doesn't have queried facility (or station/roadstop is invalid) instead of 0 (Yexo)
smatz <smatz@openttd.org>
parents:
10444
diff
changeset
|
3787 if (tile != INVALID_TILE) this->dest_tile = tile; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3788 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3789 |
8556
8aae08d562cc
(svn r12134) -Change: count the number of ticks a vehicle was running this day to calculate running cost
smatz <smatz@openttd.org>
parents:
8554
diff
changeset
|
3790 if (this->running_ticks != 0) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3791 /* running costs */ |
10744
0118ca646690
(svn r15077) -Codechange: enumify DAYS_IN_YEAR and DAYS_IN_LEAP_YEAR
smatz <smatz@openttd.org>
parents:
10696
diff
changeset
|
3792 CommandCost cost(EXPENSES_TRAIN_RUN, this->GetRunningCost() * this->running_ticks / (DAYS_IN_YEAR * DAY_TICKS)); |
8556
8aae08d562cc
(svn r12134) -Change: count the number of ticks a vehicle was running this day to calculate running cost
smatz <smatz@openttd.org>
parents:
8554
diff
changeset
|
3793 |
8aae08d562cc
(svn r12134) -Change: count the number of ticks a vehicle was running this day to calculate running cost
smatz <smatz@openttd.org>
parents:
8554
diff
changeset
|
3794 this->profit_this_year -= cost.GetCost(); |
8aae08d562cc
(svn r12134) -Change: count the number of ticks a vehicle was running this day to calculate running cost
smatz <smatz@openttd.org>
parents:
8554
diff
changeset
|
3795 this->running_ticks = 0; |
8467
284a76aa2868
(svn r12037) -Codechange: replace OnNewDay_(Aircraft|RoadVeh|Ship|Train) with an OnNewDay method in the Vehicle class
glx <glx@openttd.org>
parents:
8426
diff
changeset
|
3796 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10192
diff
changeset
|
3797 SubtractMoneyFromCompanyFract(this->owner, cost); |
8467
284a76aa2868
(svn r12037) -Codechange: replace OnNewDay_(Aircraft|RoadVeh|Ship|Train) with an OnNewDay method in the Vehicle class
glx <glx@openttd.org>
parents:
8426
diff
changeset
|
3798 |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
13001
diff
changeset
|
3799 SetWindowDirty(WC_VEHICLE_DETAILS, this->index); |
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
13001
diff
changeset
|
3800 SetWindowClassesDirty(WC_TRAINS_LIST); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3801 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3802 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3803 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3804 |
11976
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
3805 Trackdir Train::GetVehicleTrackdir() const |
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
3806 { |
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
3807 if (this->vehstatus & VS_CRASHED) return INVALID_TRACKDIR; |
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
3808 |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
3809 if (this->track == TRACK_BIT_DEPOT) { |
11976
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
3810 /* We'll assume the train is facing outwards */ |
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
3811 return DiagDirToDiagTrackdir(GetRailDepotDirection(this->tile)); // Train in depot |
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
3812 } |
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
3813 |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
3814 if (this->track == TRACK_BIT_WORMHOLE) { |
11976
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
3815 /* train in tunnel or on bridge, so just use his direction and assume a diagonal track */ |
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
3816 return DiagDirToDiagTrackdir(DirToDiagDir(this->direction)); |
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
3817 } |
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
3818 |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
3819 return TrackDirectionToTrackdir(FindFirstTrack(this->track), this->direction); |
11976
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
3820 } |