Mercurial > hg > openttd
annotate src/train_cmd.cpp @ 19900:b4c4f1c24136 draft
(svn r24833) -Codechange: Replace magic numbers for invalidating vehicle-related windows with an enum.
author | michi_cc <michi_cc@openttd.org> |
---|---|
date | Thu, 20 Dec 2012 19:44:02 +0000 |
parents | 4f44e1c86f9c |
children | 9edbe277d872 |
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" |
18627
1972f6346144
(svn r23474) -Codechange: move the declaration error related functions to error.h
rubidium <rubidium@openttd.org>
parents:
18607
diff
changeset
|
13 #include "error.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 "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
|
21 #include "newgrf_text.h" |
8114
2d6af5d7a142
(svn r11675) -Codechange: split the string types from the string functions.
rubidium <rubidium@openttd.org>
parents:
8108
diff
changeset
|
22 #include "strings_func.h" |
17277
5b204f51b151
(svn r22017) -Codechange: move MarkTileDirtyByTile to viewport_func.h
rubidium <rubidium@openttd.org>
parents:
17236
diff
changeset
|
23 #include "viewport_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
|
24 #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
|
25 #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
|
26 #include "ai/ai.hpp" |
18774
1fa19d70aea9
(svn r23622) -Add: a set of events to trigger in a GameScript
truebrain <truebrain@openttd.org>
parents:
18692
diff
changeset
|
27 #include "game/game.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
|
28 #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
|
29 #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
|
30 #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
|
31 #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
|
32 #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
|
33 #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
|
34 #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
|
35 #include "order_backup.h" |
18472
11637619aa76
(svn r23316) -Feature: Add ability to zoom in to 2x and 4x level.
peter1138 <peter1138@openttd.org>
parents:
18446
diff
changeset
|
36 #include "zoom_func.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
|
37 |
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
|
38 #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
|
39 #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
|
40 |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
41 static Track ChooseTrainTrack(Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool force_res, bool *got_reservation, bool mark_stuck); |
18446
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
42 static bool TrainCheckIfLineEnds(Train *v, bool reverse = true); |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
43 bool TrainController(Train *v, Vehicle *nomove, bool reverse = true); // Also used in vehicle_sl.cpp. |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
44 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
|
45 static void CheckIfTrainNeedsService(Train *v); |
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
46 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
|
47 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
48 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
|
49 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
|
50 |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
51 |
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 * 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
|
54 * |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
55 * @param direction vehicle direction |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
56 * @param track vehicle track bits |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
57 * @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
|
58 */ |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
59 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
|
60 { |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
61 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
|
62 |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
63 DiagDirection diagdir = DirToDiagDir(direction); |
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 /* 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
|
66 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
|
67 diagdir = ChangeDiagDir(diagdir, DIAGDIRDIFF_90LEFT); |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
68 } |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
69 |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
70 return diagdir; |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
71 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
72 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
73 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
74 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
75 * 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
|
76 * @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
|
77 * @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
|
78 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
79 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
|
80 { |
12415
6a77d1df56e2
(svn r16849) -Codechange: replace GetCargo() by CargoSpec::Get()
smatz <smatz@openttd.org>
parents:
12351
diff
changeset
|
81 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
|
82 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
|
83 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
84 |
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
|
85 /** 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
|
86 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
|
87 { |
12035
dcc31c1d758a
(svn r16442) -Codechange: use new Vehicle accessors at more places
smatz <smatz@openttd.org>
parents:
12034
diff
changeset
|
88 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
|
89 bool first = true; |
12035
dcc31c1d758a
(svn r16442) -Codechange: use new Vehicle accessors at more places
smatz <smatz@openttd.org>
parents:
12034
diff
changeset
|
90 |
dcc31c1d758a
(svn r16442) -Codechange: use new Vehicle accessors at more places
smatz <smatz@openttd.org>
parents:
12034
diff
changeset
|
91 FOR_ALL_TRAINS(v) { |
dcc31c1d758a
(svn r16442) -Codechange: use new Vehicle accessors at more places
smatz <smatz@openttd.org>
parents:
12034
diff
changeset
|
92 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
|
93 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
|
94 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
|
95 if ((w->track != TRACK_BIT_DEPOT && |
18446
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
96 max(abs(u->x_pos - w->x_pos), abs(u->y_pos - w->y_pos)) != u->CalcNextVehicleOffset()) || |
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
|
97 (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
|
98 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
|
99 SetDParam(1, v->owner); |
14645
b7a22979b84e
(svn r19224) -Codechange: change parameters passed to ShowErrorMessage() a bit
smatz <smatz@openttd.org>
parents:
14520
diff
changeset
|
100 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
|
101 |
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
|
102 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
|
103 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
|
104 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
|
105 } |
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
|
106 /* 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
|
107 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
|
108 } |
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
|
109 } |
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
|
110 } |
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
|
111 } |
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
|
112 } |
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
|
113 } |
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
|
114 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
115 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
116 * 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
|
117 * 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
|
118 * 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
|
119 * @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
|
120 */ |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
121 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
|
122 { |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
123 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
|
124 |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
125 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
|
126 |
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
127 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
|
128 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
|
129 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
|
130 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
|
131 |
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
|
132 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
|
133 |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
134 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
|
135 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
|
136 |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
137 /* 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
|
138 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
|
139 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
140 /* 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
|
141 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
|
142 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
|
143 |
12302
fc8e41f34b8c
(svn r16719) -Codechange: make IsArticulatedPart(), IsTrainEngine(), IsTrainWagon(), IsMultiheaded(), EngineHasArticPart() and IsRearDualheaded() members of Train
smatz <smatz@openttd.org>
parents:
12301
diff
changeset
|
144 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
|
145 |
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
|
146 /* 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
|
147 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
|
148 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
|
149 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
|
150 } |
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
|
151 |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
152 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
|
153 /* 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
|
154 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
|
155 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
|
156 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
|
157 } |
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
|
158 |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
159 for (Train *u = this; u != NULL; u = u->Next()) { |
18238
3141f1ed78eb
(svn r23074) -Codechange: Add Vehicle::GetEngine() to simplify code.
frosch <frosch@openttd.org>
parents:
18159
diff
changeset
|
160 const Engine *e_u = u->GetEngine(); |
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
|
161 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
|
162 |
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
|
163 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
|
164 |
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
|
165 /* 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
|
166 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
|
167 |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
11018
diff
changeset
|
168 /* 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
|
169 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
|
170 |
15825
5a7d7a33055b
(svn r20504) -Codechange: Move updating of train's visual effect to separate function.
frosch <frosch@openttd.org>
parents:
15820
diff
changeset
|
171 /* 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
|
172 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
|
173 |
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
|
174 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
|
175 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
|
176 /* 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
|
177 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
|
178 } 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
|
179 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
|
180 } |
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
|
181 |
12302
fc8e41f34b8c
(svn r16719) -Codechange: make IsArticulatedPart(), IsTrainEngine(), IsTrainWagon(), IsMultiheaded(), EngineHasArticPart() and IsRearDualheaded() members of Train
smatz <smatz@openttd.org>
parents:
12301
diff
changeset
|
182 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
|
183 /* 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
|
184 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
|
185 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
|
186 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
|
187 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
188 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
189 /* 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
|
190 * 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
|
191 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
|
192 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
|
193 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
|
194 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
195 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
196 /* 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
|
197 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
|
198 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
|
199 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
|
200 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
201 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
202 |
18337
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18335
diff
changeset
|
203 u->cargo_cap = e_u->DetermineCapacity(u); |
17909
4d6b4b6d6069
(svn r22713) -Feature: [NewGRF] Per vehicle custom cargo ageing period.
michi_cc <michi_cc@openttd.org>
parents:
17804
diff
changeset
|
204 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
|
205 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
206 /* check the vehicle length (callback) */ |
6150 | 207 uint16 veh_len = CALLBACK_FAILED; |
18314
1f35799d5a8b
(svn r23150) -Change: [NewGRF v8] Deprecate callback 11, and use callback 36 instead.
frosch <frosch@openttd.org>
parents:
18312
diff
changeset
|
208 if (e_u->GetGRF() != NULL && e_u->GetGRF()->grf_version >= 8) { |
1f35799d5a8b
(svn r23150) -Change: [NewGRF v8] Deprecate callback 11, and use callback 36 instead.
frosch <frosch@openttd.org>
parents:
18312
diff
changeset
|
209 /* Use callback 36 */ |
1f35799d5a8b
(svn r23150) -Change: [NewGRF v8] Deprecate callback 11, and use callback 36 instead.
frosch <frosch@openttd.org>
parents:
18312
diff
changeset
|
210 veh_len = GetVehicleProperty(u, PROP_TRAIN_SHORTEN_FACTOR, CALLBACK_FAILED); |
19780
3e5e1e2af3ac
(svn r24713) -Fix [FS#5262]: [NewGRF] Tolerate old NewGRFs returning invalid values via CB 11.
frosch <frosch@openttd.org>
parents:
19481
diff
changeset
|
211 |
3e5e1e2af3ac
(svn r24713) -Fix [FS#5262]: [NewGRF] Tolerate old NewGRFs returning invalid values via CB 11.
frosch <frosch@openttd.org>
parents:
19481
diff
changeset
|
212 if (veh_len != CALLBACK_FAILED && veh_len >= VEHICLE_LENGTH) { |
3e5e1e2af3ac
(svn r24713) -Fix [FS#5262]: [NewGRF] Tolerate old NewGRFs returning invalid values via CB 11.
frosch <frosch@openttd.org>
parents:
19481
diff
changeset
|
213 ErrorUnknownCallbackResult(e_u->GetGRFID(), CBID_VEHICLE_LENGTH, veh_len); |
3e5e1e2af3ac
(svn r24713) -Fix [FS#5262]: [NewGRF] Tolerate old NewGRFs returning invalid values via CB 11.
frosch <frosch@openttd.org>
parents:
19481
diff
changeset
|
214 } |
18314
1f35799d5a8b
(svn r23150) -Change: [NewGRF v8] Deprecate callback 11, and use callback 36 instead.
frosch <frosch@openttd.org>
parents:
18312
diff
changeset
|
215 } else if (HasBit(e_u->info.callback_mask, CBM_VEHICLE_LENGTH)) { |
1f35799d5a8b
(svn r23150) -Change: [NewGRF v8] Deprecate callback 11, and use callback 36 instead.
frosch <frosch@openttd.org>
parents:
18312
diff
changeset
|
216 /* Use callback 11 */ |
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
|
217 veh_len = GetVehicleCallback(CBID_VEHICLE_LENGTH, 0, 0, u->engine_type, u); |
18314
1f35799d5a8b
(svn r23150) -Change: [NewGRF v8] Deprecate callback 11, and use callback 36 instead.
frosch <frosch@openttd.org>
parents:
18312
diff
changeset
|
218 } |
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 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
|
220 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
|
221 |
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
|
222 /* verify length hasn't changed */ |
18276
72e793b46dee
(svn r23112) -Codechange: Check if vehicle chain lengths stays constant when auto-refitting.
michi_cc <michi_cc@openttd.org>
parents:
18272
diff
changeset
|
223 if (same_length && veh_len != u->gcache.cached_veh_length) VehicleLengthChanged(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
|
224 |
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
|
225 /* 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
|
226 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
|
227 |
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
|
228 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
|
229 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
|
230 u->InvalidateNewGRFCache(); |
6150 | 231 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
232 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
233 /* 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
|
234 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
|
235 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
|
236 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
|
237 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
238 /* 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
|
239 this->CargoChanged(); |
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
240 |
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
241 if (this->IsFrontEngine()) { |
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
242 this->UpdateAcceleration(); |
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
243 SetWindowDirty(WC_VEHICLE_DETAILS, this->index); |
19900
b4c4f1c24136
(svn r24833) -Codechange: Replace magic numbers for invalidating vehicle-related windows with an enum.
michi_cc <michi_cc@openttd.org>
parents:
19899
diff
changeset
|
244 InvalidateWindowData(WC_VEHICLE_REFIT, this->index, VIWD_CONSIST_CHANGED); |
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
|
245 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
246 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
247 |
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
|
248 /** |
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
|
249 * 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
|
250 * 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
|
251 * @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
|
252 * @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
|
253 * @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
|
254 * @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
|
255 * @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
|
256 * @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
|
257 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
258 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
|
259 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11920
diff
changeset
|
260 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
|
261 *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
|
262 *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
|
263 |
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
|
264 /* 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
|
265 * 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
|
266 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
|
267 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
|
268 /* 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
|
269 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
|
270 } 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
|
271 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
|
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 |
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 /* 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
|
275 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
|
276 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
|
277 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
|
278 |
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 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
|
280 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
|
281 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
|
282 |
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 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
|
284 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
|
285 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
|
286 |
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 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
|
288 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
|
289 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
|
290 } |
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
|
291 |
15820
59fd8293b2ee
(svn r20499) -Doc: Spelling fixes, and one doxygen comment addition.
alberth <alberth@openttd.org>
parents:
15763
diff
changeset
|
292 /* Subtract half the front vehicle length of the train so we get the real |
18446
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
293 * stop location of the train. */ |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
294 return stop - (v->gcache.cached_veh_length + 1) / 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
|
295 } |
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 |
12085
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
297 |
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
298 /** |
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
299 * 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
|
300 * @return imposed speed limit |
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
301 */ |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
302 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
|
303 { |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
304 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
|
305 |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
306 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
|
307 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
|
308 |
14406
5f93639271ee
(svn r18963) -Codechange: Give AccelerationModel a generical name.
terkhen <terkhen@openttd.org>
parents:
14384
diff
changeset
|
309 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
|
310 |
6150 | 311 int curvecount[2] = {0, 0}; |
312 | |
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
|
313 /* first find the curve speed limit */ |
6150 | 314 int numcurve = 0; |
315 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
|
316 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
|
317 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
|
318 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
|
319 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
|
320 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
|
321 |
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
|
322 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
|
323 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
|
324 |
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
|
325 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
|
326 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
|
327 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
|
328 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
|
329 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
|
330 sum += pos - lastpos; |
18064
0108a6ec2d68
(svn r22879) -Fix: Miscalculation of train curve speed limits. (monoid)
terkhen <terkhen@openttd.org>
parents:
18007
diff
changeset
|
331 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
|
332 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
|
333 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
334 } |
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
|
335 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
|
336 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
337 |
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
|
338 /* 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
|
339 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
|
340 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
|
341 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
342 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
343 |
12085
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
344 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
|
345 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
|
346 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
|
347 } else { |
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
348 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
|
349 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
|
350 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
351 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
352 |
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
|
353 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
|
354 /* 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
|
355 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
|
356 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
|
357 |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
358 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
|
359 /* 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
|
360 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
|
361 } |
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
|
362 } |
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 |
12085
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
364 return max_speed; |
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
365 } |
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
366 |
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
|
367 /** |
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
|
368 * 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
|
369 * @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
|
370 */ |
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
|
371 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
|
372 { |
19349
6a741e3e18e1
(svn r24246) -Add [FS#5052-ish]: [NewGRF] Variable with the current max speed for vehicles.
michi_cc <michi_cc@openttd.org>
parents:
19201
diff
changeset
|
373 if (_settings_game.vehicle.train_acceleration_model == AM_ORIGINAL) return min(this->gcache.cached_max_track_speed, this->current_order.max_speed); |
6a741e3e18e1
(svn r24246) -Add [FS#5052-ish]: [NewGRF] Variable with the current max speed for vehicles.
michi_cc <michi_cc@openttd.org>
parents:
19201
diff
changeset
|
374 |
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
|
375 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
|
376 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
|
377 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
|
378 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
|
379 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
|
380 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
|
381 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
|
382 |
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
|
383 /* 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
|
384 * 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
|
385 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
|
386 |
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
|
387 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
|
388 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
|
389 |
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
|
390 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
|
391 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
|
392 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
|
393 } |
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
|
394 |
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
|
395 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
|
396 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
|
397 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
398 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
399 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
400 |
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
|
401 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
|
402 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
|
403 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
|
404 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
|
405 } |
19899
4f44e1c86f9c
(svn r24832) -Fix [FS#5397]: [NewGRF] Take bridge speed limits into account for vehicle variable 4C.
michi_cc <michi_cc@openttd.org>
parents:
19898
diff
changeset
|
406 |
4f44e1c86f9c
(svn r24832) -Fix [FS#5397]: [NewGRF] Take bridge speed limits into account for vehicle variable 4C.
michi_cc <michi_cc@openttd.org>
parents:
19898
diff
changeset
|
407 /* Vehicle is on the middle part of a bridge. */ |
4f44e1c86f9c
(svn r24832) -Fix [FS#5397]: [NewGRF] Take bridge speed limits into account for vehicle variable 4C.
michi_cc <michi_cc@openttd.org>
parents:
19898
diff
changeset
|
408 if (u->track == TRACK_BIT_WORMHOLE && !(u->vehstatus & VS_HIDDEN)) { |
4f44e1c86f9c
(svn r24832) -Fix [FS#5397]: [NewGRF] Take bridge speed limits into account for vehicle variable 4C.
michi_cc <michi_cc@openttd.org>
parents:
19898
diff
changeset
|
409 max_speed = min(max_speed, GetBridgeSpec(GetBridgeType(u->tile))->speed); |
4f44e1c86f9c
(svn r24832) -Fix [FS#5397]: [NewGRF] Take bridge speed limits into account for vehicle variable 4C.
michi_cc <michi_cc@openttd.org>
parents:
19898
diff
changeset
|
410 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
411 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
412 |
19093
38652cadf0fe
(svn r23947) -Feature: Timetabled maximum travel speeds for non-flying vehicles.
michi_cc <michi_cc@openttd.org>
parents:
18999
diff
changeset
|
413 max_speed = min(max_speed, this->current_order.max_speed); |
16785
775f357828e3
(svn r21518) -Codechange: Rename AccelerationCache to GroundVehicleCache.
terkhen <terkhen@openttd.org>
parents:
16776
diff
changeset
|
414 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
|
415 } |
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
|
416 |
18855
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
417 /** Update acceleration of the train from the cached power and weight. */ |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
418 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
|
419 { |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
420 assert(this->IsFrontEngine()); |
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
421 |
16785
775f357828e3
(svn r21518) -Codechange: Rename AccelerationCache to GroundVehicleCache.
terkhen <terkhen@openttd.org>
parents:
16776
diff
changeset
|
422 uint power = this->gcache.cached_power; |
775f357828e3
(svn r21518) -Codechange: Rename AccelerationCache to GroundVehicleCache.
terkhen <terkhen@openttd.org>
parents:
16776
diff
changeset
|
423 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
|
424 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
|
425 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
|
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 |
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
|
428 /** |
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
|
429 * 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
|
430 * @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
|
431 * @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
|
432 */ |
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
|
433 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
|
434 { |
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
|
435 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
|
436 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
|
437 |
18238
3141f1ed78eb
(svn r23074) -Codechange: Add Vehicle::GetEngine() to simplify code.
frosch <frosch@openttd.org>
parents:
18159
diff
changeset
|
438 const Engine *e = this->GetEngine(); |
18239
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18238
diff
changeset
|
439 if (e->GetGRF() != NULL && is_custom_sprite(e->u.rail.image_index)) { |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18238
diff
changeset
|
440 reference_width = e->GetGRF()->traininfo_vehicle_width; |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18238
diff
changeset
|
441 vehicle_pitch = e->GetGRF()->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
|
442 } |
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
|
443 |
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
|
444 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
|
445 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
|
446 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
|
447 } |
17451
2dbd537df54d
(svn r22205) -Codechange: replace magic number with constant
rubidium <rubidium@openttd.org>
parents:
17399
diff
changeset
|
448 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
|
449 } |
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 |
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
|
451 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
|
452 { |
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
|
453 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
|
454 } |
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
|
455 |
18855
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
456 /** |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
457 * Get the sprite to display the train. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
458 * @param direction Direction of view/travel. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
459 * @param image_type Visualisation context. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
460 * @return Sprite to display. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
461 */ |
18244
8f6022f41538
(svn r23080) -Feature: [NewGRF] Use variable 10 to enable vehicle GRFs to draw different sprites on the map and in various GUIs.
frosch <frosch@openttd.org>
parents:
18239
diff
changeset
|
462 SpriteID Train::GetImage(Direction direction, EngineImageType image_type) 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
|
463 { |
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
|
464 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
|
465 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
|
466 |
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
|
467 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
|
468 |
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
|
469 if (is_custom_sprite(spritenum)) { |
18244
8f6022f41538
(svn r23080) -Feature: [NewGRF] Use variable 10 to enable vehicle GRFs to draw different sprites on the map and in various GUIs.
frosch <frosch@openttd.org>
parents:
18239
diff
changeset
|
470 sprite = GetCustomVehicleSprite(this, (Direction)(direction + 4 * IS_CUSTOM_SECONDHEAD_SPRITE(spritenum)), image_type); |
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
|
471 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
|
472 |
18238
3141f1ed78eb
(svn r23074) -Codechange: Add Vehicle::GetEngine() to simplify code.
frosch <frosch@openttd.org>
parents:
18159
diff
changeset
|
473 spritenum = this->GetEngine()->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
|
474 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
475 |
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
|
476 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
|
477 |
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 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
|
479 |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
480 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
|
481 } |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
482 |
18244
8f6022f41538
(svn r23080) -Feature: [NewGRF] Use variable 10 to enable vehicle GRFs to draw different sprites on the map and in various GUIs.
frosch <frosch@openttd.org>
parents:
18239
diff
changeset
|
483 static SpriteID GetRailIcon(EngineID engine, bool rear_head, int &y, EngineImageType image_type) |
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
|
484 { |
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
|
485 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
|
486 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
|
487 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
|
488 |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
489 if (is_custom_sprite(spritenum)) { |
18244
8f6022f41538
(svn r23080) -Feature: [NewGRF] Use variable 10 to enable vehicle GRFs to draw different sprites on the map and in various GUIs.
frosch <frosch@openttd.org>
parents:
18239
diff
changeset
|
490 SpriteID sprite = GetCustomVehicleIcon(engine, dir, image_type); |
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 if (sprite != 0) { |
18239
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18238
diff
changeset
|
492 if (e->GetGRF() != NULL) { |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18238
diff
changeset
|
493 y += e->GetGRF()->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
|
494 } |
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
|
495 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
|
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 |
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
|
498 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
|
499 } |
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 |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
501 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
|
502 |
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
|
503 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
|
504 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
505 |
18244
8f6022f41538
(svn r23080) -Feature: [NewGRF] Use variable 10 to enable vehicle GRFs to draw different sprites on the map and in various GUIs.
frosch <frosch@openttd.org>
parents:
18239
diff
changeset
|
506 void DrawTrainEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
507 { |
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
|
508 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
|
509 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
|
510 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
|
511 |
18244
8f6022f41538
(svn r23080) -Feature: [NewGRF] Use variable 10 to enable vehicle GRFs to draw different sprites on the map and in various GUIs.
frosch <frosch@openttd.org>
parents:
18239
diff
changeset
|
512 SpriteID spritef = GetRailIcon(engine, false, yf, image_type); |
8f6022f41538
(svn r23080) -Feature: [NewGRF] Use variable 10 to enable vehicle GRFs to draw different sprites on the map and in various GUIs.
frosch <frosch@openttd.org>
parents:
18239
diff
changeset
|
513 SpriteID spriter = GetRailIcon(engine, true, yr, image_type); |
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
|
514 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
|
515 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
|
516 |
18472
11637619aa76
(svn r23316) -Feature: Add ability to zoom in to 2x and 4x level.
peter1138 <peter1138@openttd.org>
parents:
18446
diff
changeset
|
517 preferred_x = Clamp(preferred_x, left - UnScaleByZoom(real_spritef->x_offs, ZOOM_LVL_GUI) + 14, right - UnScaleByZoom(real_spriter->width, ZOOM_LVL_GUI) - UnScaleByZoom(real_spriter->x_offs, ZOOM_LVL_GUI) - 15); |
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
|
518 |
13597
706013b8e441
(svn r18121) -Codechange: pass the maximum left/right location to the Draw*Engine functions
rubidium <rubidium@openttd.org>
parents:
13492
diff
changeset
|
519 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
|
520 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
|
521 } else { |
18244
8f6022f41538
(svn r23080) -Feature: [NewGRF] Use variable 10 to enable vehicle GRFs to draw different sprites on the map and in various GUIs.
frosch <frosch@openttd.org>
parents:
18239
diff
changeset
|
522 SpriteID sprite = GetRailIcon(engine, false, y, image_type); |
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
|
523 const Sprite *real_sprite = GetSprite(sprite, ST_NORMAL); |
18472
11637619aa76
(svn r23316) -Feature: Add ability to zoom in to 2x and 4x level.
peter1138 <peter1138@openttd.org>
parents:
18446
diff
changeset
|
524 preferred_x = Clamp(preferred_x, left - UnScaleByZoom(real_sprite->x_offs, ZOOM_LVL_GUI), right - UnScaleByZoom(real_sprite->width, ZOOM_LVL_GUI) - UnScaleByZoom(real_sprite->x_offs, ZOOM_LVL_GUI)); |
13597
706013b8e441
(svn r18121) -Codechange: pass the maximum left/right location to the Draw*Engine functions
rubidium <rubidium@openttd.org>
parents:
13492
diff
changeset
|
525 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
|
526 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
527 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
528 |
15849
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
529 /** |
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
530 * 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
|
531 * @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
|
532 * @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
|
533 * @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
|
534 * @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
|
535 * @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
|
536 */ |
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
|
537 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
|
538 { |
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
|
539 const RailVehicleInfo *rvi = &e->u.rail; |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
540 |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
541 /* 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
|
542 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
|
543 |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
544 if (flags & DC_EXEC) { |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
545 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
|
546 *ret = v; |
11902
5b2be5f84fe8
(svn r16302) -Codechange: remove Vehicle::AllocateList
smatz <smatz@openttd.org>
parents:
11901
diff
changeset
|
547 v->spritenum = rvi->image_index; |
5b2be5f84fe8
(svn r16302) -Codechange: remove Vehicle::AllocateList
smatz <smatz@openttd.org>
parents:
11901
diff
changeset
|
548 |
15849
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
549 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
|
550 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
|
551 |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
552 DiagDirection dir = GetRailDepotDirection(tile); |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
553 |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
554 v->direction = DiagDirToDir(dir); |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
555 v->tile = tile; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
556 |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
557 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
|
558 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
|
559 |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
560 v->x_pos = x; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
561 v->y_pos = y; |
18255
b3cb40aab91b
(svn r23091) -Codechange: rename some Get*Z functions to Get*PixelZ functions if they return the Z in pixels (like TilePixelHeight)
rubidium <rubidium@openttd.org>
parents:
18244
diff
changeset
|
562 v->z_pos = GetSlopePixelZ(x, y); |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
563 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
|
564 v->track = TRACK_BIT_DEPOT; |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
565 v->vehstatus = VS_HIDDEN | VS_DEFPAL; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
566 |
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
|
567 v->SetWagon(); |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
568 |
13934
6c8c9b6e2b7b
(svn r18466) -Codechange: use CmdMoveRailWagon to attach a just build wagon to a chain
rubidium <rubidium@openttd.org>
parents:
13933
diff
changeset
|
569 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
|
570 InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
571 |
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
|
572 v->cargo_type = e->GetDefaultCargoType(); |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
573 v->cargo_cap = rvi->capacity; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
574 |
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
|
575 v->railtype = rvi->railtype; |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
576 |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
577 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
|
578 v->cur_image = SPR_IMG_QUERY; |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
579 v->random_bits = VehicleRandomBits(); |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
580 |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
581 v->group_id = DEFAULT_GROUP; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
582 |
13219
39e3a60fd47f
(svn r17726) -Cleanup: Remove some unneeded/unused parameters.
frosch <frosch@openttd.org>
parents:
13218
diff
changeset
|
583 AddArticulatedParts(v); |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
584 |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
585 _new_vehicle_id = v->index; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
586 |
18864
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18855
diff
changeset
|
587 VehicleUpdatePosition(v); |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
588 v->First()->ConsistChanged(false); |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
589 UpdateTrainGroupID(v->First()); |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
590 |
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
|
591 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
|
592 |
6c8c9b6e2b7b
(svn r18466) -Codechange: use CmdMoveRailWagon to attach a just build wagon to a chain
rubidium <rubidium@openttd.org>
parents:
13933
diff
changeset
|
593 /* 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
|
594 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
|
595 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
|
596 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
|
597 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
|
598 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
|
599 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
|
600 !(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
|
601 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
|
602 break; |
6c8c9b6e2b7b
(svn r18466) -Codechange: use CmdMoveRailWagon to attach a just build wagon to a chain
rubidium <rubidium@openttd.org>
parents:
13933
diff
changeset
|
603 } |
6c8c9b6e2b7b
(svn r18466) -Codechange: use CmdMoveRailWagon to attach a just build wagon to a chain
rubidium <rubidium@openttd.org>
parents:
13933
diff
changeset
|
604 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
605 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
606 |
15849
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
607 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
|
608 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
609 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
610 /** 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
|
611 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
|
612 { |
12035
dcc31c1d758a
(svn r16442) -Codechange: use new Vehicle accessors at more places
smatz <smatz@openttd.org>
parents:
12034
diff
changeset
|
613 const Train *v; |
dcc31c1d758a
(svn r16442) -Codechange: use new Vehicle accessors at more places
smatz <smatz@openttd.org>
parents:
12034
diff
changeset
|
614 FOR_ALL_TRAINS(v) { |
12301
218a41d3d557
(svn r16718) -Codechange: make IsFreeWagon() member of Train
smatz <smatz@openttd.org>
parents:
12300
diff
changeset
|
615 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
|
616 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
|
617 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
|
618 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
|
619 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
620 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
621 } |
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 |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
624 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
|
625 { |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
626 Train *u = new Train(); |
11902
5b2be5f84fe8
(svn r16302) -Codechange: remove Vehicle::AllocateList
smatz <smatz@openttd.org>
parents:
11901
diff
changeset
|
627 v->value >>= 1; |
5b2be5f84fe8
(svn r16302) -Codechange: remove Vehicle::AllocateList
smatz <smatz@openttd.org>
parents:
11901
diff
changeset
|
628 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
|
629 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
|
630 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
|
631 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
|
632 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
|
633 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
|
634 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
|
635 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
|
636 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
|
637 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
|
638 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
|
639 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
|
640 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
|
641 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
|
642 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
|
643 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
|
644 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
|
645 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
|
646 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
|
647 u->SetMultiheaded(); |
11902
5b2be5f84fe8
(svn r16302) -Codechange: remove Vehicle::AllocateList
smatz <smatz@openttd.org>
parents:
11901
diff
changeset
|
648 v->SetNext(u); |
18864
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18855
diff
changeset
|
649 VehicleUpdatePosition(u); |
11902
5b2be5f84fe8
(svn r16302) -Codechange: remove Vehicle::AllocateList
smatz <smatz@openttd.org>
parents:
11901
diff
changeset
|
650 |
5b2be5f84fe8
(svn r16302) -Codechange: remove Vehicle::AllocateList
smatz <smatz@openttd.org>
parents:
11901
diff
changeset
|
651 /* 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
|
652 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
|
653 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
|
654 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
655 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
656 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
657 * 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
|
658 * @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
|
659 * @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
|
660 * @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
|
661 * @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
|
662 * @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
|
663 * @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
|
664 */ |
15849
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
665 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
|
666 { |
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
|
667 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
|
668 |
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
669 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
|
670 |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
671 /* 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
|
672 * 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
|
673 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
|
674 |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
675 if (flags & DC_EXEC) { |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
676 DiagDirection dir = GetRailDepotDirection(tile); |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
677 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
|
678 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
|
679 |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
680 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
|
681 *ret = v; |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
682 v->direction = DiagDirToDir(dir); |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
683 v->tile = tile; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
684 v->owner = _current_company; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
685 v->x_pos = x; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
686 v->y_pos = y; |
18255
b3cb40aab91b
(svn r23091) -Codechange: rename some Get*Z functions to Get*PixelZ functions if they return the Z in pixels (like TilePixelHeight)
rubidium <rubidium@openttd.org>
parents:
18244
diff
changeset
|
687 v->z_pos = GetSlopePixelZ(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
|
688 v->track = TRACK_BIT_DEPOT; |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
689 v->vehstatus = VS_HIDDEN | VS_STOPPED | VS_DEFPAL; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
690 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
|
691 v->cargo_type = e->GetDefaultCargoType(); |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
692 v->cargo_cap = rvi->capacity; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
693 v->last_station_visited = INVALID_STATION; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
694 |
15849
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
695 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
|
696 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
|
697 |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
698 v->reliability = e->reliability; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
699 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
|
700 v->max_age = e->GetLifeLengthInDays(); |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
701 |
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->railtype = rvi->railtype; |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
703 _new_vehicle_id = v->index; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
704 |
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
|
705 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
|
706 v->date_of_last_service = _date; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
707 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
|
708 v->cur_image = SPR_IMG_QUERY; |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
709 v->random_bits = VehicleRandomBits(); |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
710 |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
711 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
|
712 |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
713 v->group_id = DEFAULT_GROUP; |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
714 |
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
|
715 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
|
716 v->SetEngine(); |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
717 |
18864
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18855
diff
changeset
|
718 VehicleUpdatePosition(v); |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
719 |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
720 if (rvi->railveh_type == RAILVEH_MULTIHEAD) { |
11902
5b2be5f84fe8
(svn r16302) -Codechange: remove Vehicle::AllocateList
smatz <smatz@openttd.org>
parents:
11901
diff
changeset
|
721 AddRearEngineToMultiheadedTrain(v); |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
722 } else { |
13219
39e3a60fd47f
(svn r17726) -Cleanup: Remove some unneeded/unused parameters.
frosch <frosch@openttd.org>
parents:
13218
diff
changeset
|
723 AddArticulatedParts(v); |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
724 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
725 |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
726 v->ConsistChanged(false); |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
727 UpdateTrainGroupID(v); |
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
728 |
15849
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
729 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
|
730 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
|
731 } |
10930
34cbf99eb82c
(svn r15269) -Codechange: reduced indentation in CmdBuildRail*
glx <glx@openttd.org>
parents:
10929
diff
changeset
|
732 |
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
|
733 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
|
734 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
735 |
15849
f4ed8e905fee
(svn r20531) -Codechange: unify quite a bit of the vehicle building commands
rubidium <rubidium@openttd.org>
parents:
15826
diff
changeset
|
736 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
|
737 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
738 |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
739 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
|
740 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
741 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
|
742 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
|
743 |
12034
aa140a9c419c
(svn r16441) -Codechange: new class SpecializedVehicle used as superclass for all vehicle types
smatz <smatz@openttd.org>
parents:
12032
diff
changeset
|
744 Train *dst; |
aa140a9c419c
(svn r16441) -Codechange: new class SpecializedVehicle used as superclass for all vehicle types
smatz <smatz@openttd.org>
parents:
12032
diff
changeset
|
745 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
|
746 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
|
747 /* 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
|
748 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
|
749 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
|
750 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
|
751 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
|
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 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
754 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
755 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
756 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
|
757 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
758 |
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
|
759 /** 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
|
760 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
|
761 |
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
|
762 /** |
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
|
763 * 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
|
764 * @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
|
765 * @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
|
766 */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
767 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
|
768 { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
769 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
|
770 } |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
771 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
772 /** |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
773 * 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
|
774 * @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
|
775 */ |
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
|
776 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
|
777 { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
778 /* 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
|
779 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
|
780 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
781 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
|
782 /* 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
|
783 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
|
784 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
|
785 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
|
786 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
|
787 } 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
|
788 /* 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
|
789 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
|
790 } |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
791 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
|
792 } |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
793 } |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 /** |
15002
baf0e12ad2b4
(svn r19614) -Codechange: "it's" => "its" where appropriate
smatz <smatz@openttd.org>
parents:
14898
diff
changeset
|
796 * 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
|
797 * @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
|
798 * @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
|
799 */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 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
|
801 { |
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
|
802 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
|
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 /* 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
|
805 * 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
|
806 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
|
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 /* 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
|
809 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
|
810 } |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 * 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
|
814 * @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
|
815 * @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
|
816 */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 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
|
818 { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 /* 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
|
820 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
|
821 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 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
|
823 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
|
824 } |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 /** |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 * 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
|
828 * 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
|
829 * @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
|
830 */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
831 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
|
832 { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 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
|
834 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
|
835 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
836 /* 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
|
837 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
|
838 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
|
839 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 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
|
841 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 /* 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
|
843 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
|
844 /* 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
|
845 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
|
846 } |
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
|
847 } |
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
|
848 |
13926
693d82515df6
(svn r18458) -Codechange: make the 'check train length' code of CmdMoveRailVehicle a separate function
rubidium <rubidium@openttd.org>
parents:
13924
diff
changeset
|
849 /** |
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
|
850 * 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
|
851 * @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
|
852 */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 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
|
854 { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 /* 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
|
856 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
|
857 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 /* 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
|
859 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
|
860 |
15820
59fd8293b2ee
(svn r20499) -Doc: Spelling fixes, and one doxygen comment addition.
alberth <alberth@openttd.org>
parents:
15763
diff
changeset
|
861 /* 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
|
862 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
|
863 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
|
864 } 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
|
865 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
|
866 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
|
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 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 /* 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
|
870 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
|
871 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
|
872 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
|
873 } |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 * 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
|
878 * @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
|
879 * @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
|
880 * @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
|
881 * @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
|
882 * @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
|
883 * @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
|
884 */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 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
|
886 { |
15820
59fd8293b2ee
(svn r20499) -Doc: Spelling fixes, and one doxygen comment addition.
alberth <alberth@openttd.org>
parents:
15763
diff
changeset
|
887 /* 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
|
888 * 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
|
889 * 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
|
890 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
|
891 (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
|
892 (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
|
893 (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
|
894 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
|
895 } |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
896 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 /* 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
|
898 * 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
|
899 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
|
900 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 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
|
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 /** |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 * 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
|
906 * @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
|
907 * @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
|
908 */ |
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
|
909 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
|
910 { |
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
|
911 /* 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
|
912 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
|
913 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 /* 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
|
915 * 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
|
916 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
|
917 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 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
|
919 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
|
920 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 /* 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
|
922 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
|
923 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
|
924 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 /* 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
|
926 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
|
927 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 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
|
929 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
|
930 |
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
|
931 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
|
932 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 /* 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
|
934 * 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
|
935 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
|
936 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 /* 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
|
938 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
|
939 /* 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
|
940 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
|
941 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
|
942 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
943 /* 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
|
944 * 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
|
945 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
|
946 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 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
|
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 /* 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
|
950 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
|
951 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 /* 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
|
953 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
|
954 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
|
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 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
|
957 /* 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
|
958 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
|
959 |
18895
d0ca24721a85
(svn r23744) -Fix (r23142) [FS#4923]: Check the version of the right GRF.
frosch <frosch@openttd.org>
parents:
18891
diff
changeset
|
960 if (head->GetGRF()->grf_version < 8) { |
18306
21d2cc91c3ce
(svn r23142) -Change: [NewGRF v8] Unify the return values of callbacks returning D0xx texts.
frosch <frosch@openttd.org>
parents:
18276
diff
changeset
|
961 if (callback == 0xFD) error = STR_ERROR_INCOMPATIBLE_RAIL_TYPES; |
21d2cc91c3ce
(svn r23142) -Change: [NewGRF v8] Unify the return values of callbacks returning D0xx texts.
frosch <frosch@openttd.org>
parents:
18276
diff
changeset
|
962 if (callback < 0xFD) error = GetGRFStringID(head->GetGRFID(), 0xD000 + callback); |
21d2cc91c3ce
(svn r23142) -Change: [NewGRF v8] Unify the return values of callbacks returning D0xx texts.
frosch <frosch@openttd.org>
parents:
18276
diff
changeset
|
963 if (callback >= 0x100) ErrorUnknownCallbackResult(head->GetGRFID(), CBID_TRAIN_ALLOW_WAGON_ATTACH, callback); |
21d2cc91c3ce
(svn r23142) -Change: [NewGRF v8] Unify the return values of callbacks returning D0xx texts.
frosch <frosch@openttd.org>
parents:
18276
diff
changeset
|
964 } else { |
21d2cc91c3ce
(svn r23142) -Change: [NewGRF v8] Unify the return values of callbacks returning D0xx texts.
frosch <frosch@openttd.org>
parents:
18276
diff
changeset
|
965 if (callback < 0x400) { |
21d2cc91c3ce
(svn r23142) -Change: [NewGRF v8] Unify the return values of callbacks returning D0xx texts.
frosch <frosch@openttd.org>
parents:
18276
diff
changeset
|
966 error = GetGRFStringID(head->GetGRFID(), 0xD000 + callback); |
21d2cc91c3ce
(svn r23142) -Change: [NewGRF v8] Unify the return values of callbacks returning D0xx texts.
frosch <frosch@openttd.org>
parents:
18276
diff
changeset
|
967 } else { |
21d2cc91c3ce
(svn r23142) -Change: [NewGRF v8] Unify the return values of callbacks returning D0xx texts.
frosch <frosch@openttd.org>
parents:
18276
diff
changeset
|
968 switch (callback) { |
18335
f95316892277
(svn r23171) -Fix (r23142): Fix comment.
frosch <frosch@openttd.org>
parents:
18314
diff
changeset
|
969 case 0x400: // allow if railtypes match (always the case for OpenTTD) |
f95316892277
(svn r23171) -Fix (r23142): Fix comment.
frosch <frosch@openttd.org>
parents:
18314
diff
changeset
|
970 case 0x401: // allow |
18306
21d2cc91c3ce
(svn r23142) -Change: [NewGRF v8] Unify the return values of callbacks returning D0xx texts.
frosch <frosch@openttd.org>
parents:
18276
diff
changeset
|
971 break; |
21d2cc91c3ce
(svn r23142) -Change: [NewGRF v8] Unify the return values of callbacks returning D0xx texts.
frosch <frosch@openttd.org>
parents:
18276
diff
changeset
|
972 |
21d2cc91c3ce
(svn r23142) -Change: [NewGRF v8] Unify the return values of callbacks returning D0xx texts.
frosch <frosch@openttd.org>
parents:
18276
diff
changeset
|
973 default: // unknown reason -> disallow |
21d2cc91c3ce
(svn r23142) -Change: [NewGRF v8] Unify the return values of callbacks returning D0xx texts.
frosch <frosch@openttd.org>
parents:
18276
diff
changeset
|
974 case 0x402: // disallow attaching |
21d2cc91c3ce
(svn r23142) -Change: [NewGRF v8] Unify the return values of callbacks returning D0xx texts.
frosch <frosch@openttd.org>
parents:
18276
diff
changeset
|
975 error = STR_ERROR_INCOMPATIBLE_RAIL_TYPES; |
21d2cc91c3ce
(svn r23142) -Change: [NewGRF v8] Unify the return values of callbacks returning D0xx texts.
frosch <frosch@openttd.org>
parents:
18276
diff
changeset
|
976 break; |
21d2cc91c3ce
(svn r23142) -Change: [NewGRF v8] Unify the return values of callbacks returning D0xx texts.
frosch <frosch@openttd.org>
parents:
18276
diff
changeset
|
977 } |
21d2cc91c3ce
(svn r23142) -Change: [NewGRF v8] Unify the return values of callbacks returning D0xx texts.
frosch <frosch@openttd.org>
parents:
18276
diff
changeset
|
978 } |
21d2cc91c3ce
(svn r23142) -Change: [NewGRF v8] Unify the return values of callbacks returning D0xx texts.
frosch <frosch@openttd.org>
parents:
18276
diff
changeset
|
979 } |
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
|
980 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 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
|
982 } |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
985 /* 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
|
986 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
|
987 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
|
988 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
|
989 } |
693d82515df6
(svn r18458) -Codechange: make the 'check train length' code of CmdMoveRailVehicle a separate function
rubidium <rubidium@openttd.org>
parents:
13924
diff
changeset
|
990 |
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
|
991 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
|
992 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
|
993 } |
693d82515df6
(svn r18458) -Codechange: make the 'check train length' code of CmdMoveRailVehicle a separate function
rubidium <rubidium@openttd.org>
parents:
13924
diff
changeset
|
994 |
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
|
995 /** |
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
|
996 * 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
|
997 * @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
|
998 * @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
|
999 * @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
|
1000 * @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
|
1001 * @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
|
1002 * @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
|
1003 * @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
|
1004 */ |
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
|
1005 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
|
1006 { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1007 /* 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
|
1008 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
|
1009 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
|
1010 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
|
1011 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
|
1012 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 /* 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
|
1014 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
|
1015 } |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 /** |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 * 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
|
1019 * @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
|
1020 * @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
|
1021 * @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
|
1022 * @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
|
1023 * @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
|
1024 */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 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
|
1026 { |
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
|
1027 /* 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
|
1028 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
|
1029 /* 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
|
1030 * 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
|
1031 *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
|
1032 } 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
|
1033 /* 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
|
1034 * 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
|
1035 *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
|
1036 } |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 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
|
1039 /* 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
|
1040 * 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
|
1041 * 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
|
1042 * 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
|
1043 * 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
|
1044 * 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
|
1045 *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
|
1046 (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
|
1047 } |
77e7637c04c8
(svn r18459) -Codechange: move the new train validity checking (attach callbacks) to a separate function
rubidium <rubidium@openttd.org>
parents:
13926
diff
changeset
|
1048 |
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
|
1049 /* 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
|
1050 * 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
|
1051 * 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
|
1052 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
|
1053 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
|
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 /* 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
|
1056 * 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
|
1057 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
|
1058 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
|
1059 } |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 /** |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 * 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
|
1063 * 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
|
1064 * @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
|
1065 */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 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
|
1067 { |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 /* 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
|
1069 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
|
1070 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 /* 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
|
1072 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
|
1073 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
|
1074 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 /* 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
|
1076 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
|
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 /* Update the refit button and window */ |
19900
b4c4f1c24136
(svn r24833) -Codechange: Replace magic numbers for invalidating vehicle-related windows with an enum.
michi_cc <michi_cc@openttd.org>
parents:
19899
diff
changeset
|
1079 InvalidateWindowData(WC_VEHICLE_REFIT, head->index, VIWD_CONSIST_CHANGED); |
18692
90d395fc678d
(svn r23540) -Codechange: unify and document vehicle widgets
rubidium <rubidium@openttd.org>
parents:
18627
diff
changeset
|
1080 SetWindowWidgetDirty(WC_VEHICLE_VIEW, head->index, WID_VV_REFIT); |
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
|
1081 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 /* 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
|
1083 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
|
1084 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
|
1085 } |
77e7637c04c8
(svn r18459) -Codechange: move the new train validity checking (attach callbacks) to a separate function
rubidium <rubidium@openttd.org>
parents:
13926
diff
changeset
|
1086 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
1087 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
1088 * 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
|
1089 * @param tile unused |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1090 * @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
|
1091 * 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
|
1092 * @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
|
1093 * - 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
|
1094 * - 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
|
1095 * @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
|
1096 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13054
diff
changeset
|
1097 * @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
|
1098 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11085
diff
changeset
|
1099 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
|
1100 { |
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
|
1101 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
|
1102 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
|
1103 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
|
1104 |
12034
aa140a9c419c
(svn r16441) -Codechange: new class SpecializedVehicle used as superclass for all vehicle types
smatz <smatz@openttd.org>
parents:
12032
diff
changeset
|
1105 Train *src = Train::GetIfValid(s); |
14815
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1106 if (src == NULL) return CMD_ERROR; |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1107 |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1108 CommandCost ret = CheckOwnership(src->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1109 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
|
1110 |
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
|
1111 /* 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
|
1112 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
|
1113 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1114 /* 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
|
1115 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
|
1116 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
|
1117 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
|
1118 } else { |
12034
aa140a9c419c
(svn r16441) -Codechange: new class SpecializedVehicle used as superclass for all vehicle types
smatz <smatz@openttd.org>
parents:
12032
diff
changeset
|
1119 dst = Train::GetIfValid(d); |
14815
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1120 if (dst == NULL) return CMD_ERROR; |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1121 |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1122 CommandCost ret = CheckOwnership(dst->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1123 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
|
1124 |
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
|
1125 /* 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
|
1126 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
|
1127 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1128 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1129 /* 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
|
1130 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
|
1131 if (dst != NULL) { |
12450
af266072d46c
(svn r16884) -Codechange: Add Train::GetFirstEnginePart() and use it.
frosch <frosch@openttd.org>
parents:
12433
diff
changeset
|
1132 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
|
1133 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1134 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1135 /* 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
|
1136 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
|
1137 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1138 /* 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
|
1139 Train *src_head = src->First(); |
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1140 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
|
1141 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
|
1142 dst_head = dst->First(); |
6136 | 1143 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
|
1144 /* 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
|
1145 dst = dst->GetLastEnginePart(); |
6136 | 1146 } else { |
1147 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
|
1148 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1149 |
12302
fc8e41f34b8c
(svn r16719) -Codechange: make IsArticulatedPart(), IsTrainEngine(), IsTrainWagon(), IsMultiheaded(), EngineHasArticPart() and IsRearDualheaded() members of Train
smatz <smatz@openttd.org>
parents:
12301
diff
changeset
|
1150 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
|
1151 |
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
|
1152 /* 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
|
1153 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
|
1154 |
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
|
1155 /* 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
|
1156 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
|
1157 |
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
|
1158 /* 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
|
1159 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
|
1160 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1161 /* 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
|
1162 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
|
1163 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1164 /* 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
|
1165 * 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
|
1166 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
|
1167 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
|
1168 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1169 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
|
1170 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
|
1171 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1172 /* 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
|
1173 * 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
|
1174 * 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
|
1175 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
|
1176 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
|
1177 |
18832
1d0a58216701
(svn r23681) -Fix [FS#4914]: vehicle numbers got misaccounted when autoreplacing failed due to length checks
rubidium <rubidium@openttd.org>
parents:
18774
diff
changeset
|
1178 /* We want this information from before the rearrangement, but execute this after the validation. */ |
1d0a58216701
(svn r23681) -Fix [FS#4914]: vehicle numbers got misaccounted when autoreplacing failed due to length checks
rubidium <rubidium@openttd.org>
parents:
18774
diff
changeset
|
1179 bool original_src_head_front_engine = original_src_head != NULL && original_src_head->IsFrontEngine(); |
1d0a58216701
(svn r23681) -Fix [FS#4914]: vehicle numbers got misaccounted when autoreplacing failed due to length checks
rubidium <rubidium@openttd.org>
parents:
18774
diff
changeset
|
1180 bool original_dst_head_front_engine = original_dst_head != NULL && original_dst_head->IsFrontEngine(); |
18159
de0749262352
(svn r22984) -Feature: Display profit icons for groups in the group GUI.
frosch <frosch@openttd.org>
parents:
18153
diff
changeset
|
1181 |
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
|
1182 /* (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
|
1183 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
|
1184 |
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
|
1185 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
|
1186 /* 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
|
1187 * 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
|
1188 * 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
|
1189 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
|
1190 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
|
1191 /* 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
|
1192 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
|
1193 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
|
1194 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
|
1195 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1196 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1197 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1198 /* 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
|
1199 if (flags & DC_EXEC) { |
18832
1d0a58216701
(svn r23681) -Fix [FS#4914]: vehicle numbers got misaccounted when autoreplacing failed due to length checks
rubidium <rubidium@openttd.org>
parents:
18774
diff
changeset
|
1200 /* Remove old heads from the statistics */ |
1d0a58216701
(svn r23681) -Fix [FS#4914]: vehicle numbers got misaccounted when autoreplacing failed due to length checks
rubidium <rubidium@openttd.org>
parents:
18774
diff
changeset
|
1201 if (original_src_head_front_engine) GroupStatistics::CountVehicle(original_src_head, -1); |
1d0a58216701
(svn r23681) -Fix [FS#4914]: vehicle numbers got misaccounted when autoreplacing failed due to length checks
rubidium <rubidium@openttd.org>
parents:
18774
diff
changeset
|
1202 if (original_dst_head_front_engine) GroupStatistics::CountVehicle(original_dst_head, -1); |
1d0a58216701
(svn r23681) -Fix [FS#4914]: vehicle numbers got misaccounted when autoreplacing failed due to length checks
rubidium <rubidium@openttd.org>
parents:
18774
diff
changeset
|
1203 |
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
|
1204 /* 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
|
1205 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
|
1206 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
|
1207 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1208 /* 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
|
1209 * 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
|
1210 * 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
|
1211 * 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
|
1212 * 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
|
1213 * 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
|
1214 * 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
|
1215 * 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
|
1216 * 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
|
1217 * 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
|
1218 * 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
|
1219 * 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
|
1220 * 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
|
1221 * 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
|
1222 * 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
|
1223 * 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
|
1224 * 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
|
1225 * 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
|
1226 * 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
|
1227 */ |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles 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 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
|
1229 /* 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
|
1230 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
|
1231 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
|
1232 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
|
1233 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
|
1234 DeleteWindowById(WC_VEHICLE_TIMETABLE, src->index); |
18607
b8fc708229a7
(svn r23454) -Change: Mark company window dirty when moving a rail engine creates or deletes a train.
peter1138 <peter1138@openttd.org>
parents:
18511
diff
changeset
|
1235 SetWindowDirty(WC_COMPANY, _current_company); |
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
|
1236 |
4dce922c787f
(svn r18470) -Codechange/Fix [part of FS#3146]: moving vehicles around in the depot could create states that are not allowed by the NewGRF attach callback.
rubidium <rubidium@openttd.org>
parents:
13934
diff
changeset
|
1237 /* 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
|
1238 * 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
|
1239 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
|
1240 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
|
1241 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
|
1242 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1243 |
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
|
1244 /* 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
|
1245 * 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
|
1246 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
|
1247 SetTrainGroupID(src, DEFAULT_GROUP); |
18607
b8fc708229a7
(svn r23454) -Change: Mark company window dirty when moving a rail engine creates or deletes a train.
peter1138 <peter1138@openttd.org>
parents:
18511
diff
changeset
|
1248 SetWindowDirty(WC_COMPANY, _current_company); |
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
|
1249 } |
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
|
1250 |
18159
de0749262352
(svn r22984) -Feature: Display profit icons for groups in the group GUI.
frosch <frosch@openttd.org>
parents:
18153
diff
changeset
|
1251 /* 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
|
1252 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
|
1253 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
|
1254 |
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
|
1255 /* 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
|
1256 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
|
1257 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
|
1258 |
18834
573054818505
(svn r23683) -Fix [FS#4912]-ish: when fitting another engine the cargo capacity of wagons could become lower, causing them to contain more than they should. This caused the cargo transfer from the replaced parts to put even more stuff in the already full wagon. Prevent this from happening by reducing the amount of cargo in the vehicle to the capacity when moving vehicles/wagons around, or when autoreplacing
rubidium <rubidium@openttd.org>
parents:
18832
diff
changeset
|
1259 if ((flags & DC_NO_CARGO_CAP_CHECK) == 0) { |
573054818505
(svn r23683) -Fix [FS#4912]-ish: when fitting another engine the cargo capacity of wagons could become lower, causing them to contain more than they should. This caused the cargo transfer from the replaced parts to put even more stuff in the already full wagon. Prevent this from happening by reducing the amount of cargo in the vehicle to the capacity when moving vehicles/wagons around, or when autoreplacing
rubidium <rubidium@openttd.org>
parents:
18832
diff
changeset
|
1260 CheckCargoCapacity(src_head); |
573054818505
(svn r23683) -Fix [FS#4912]-ish: when fitting another engine the cargo capacity of wagons could become lower, causing them to contain more than they should. This caused the cargo transfer from the replaced parts to put even more stuff in the already full wagon. Prevent this from happening by reducing the amount of cargo in the vehicle to the capacity when moving vehicles/wagons around, or when autoreplacing
rubidium <rubidium@openttd.org>
parents:
18832
diff
changeset
|
1261 CheckCargoCapacity(dst_head); |
573054818505
(svn r23683) -Fix [FS#4912]-ish: when fitting another engine the cargo capacity of wagons could become lower, causing them to contain more than they should. This caused the cargo transfer from the replaced parts to put even more stuff in the already full wagon. Prevent this from happening by reducing the amount of cargo in the vehicle to the capacity when moving vehicles/wagons around, or when autoreplacing
rubidium <rubidium@openttd.org>
parents:
18832
diff
changeset
|
1262 } |
573054818505
(svn r23683) -Fix [FS#4912]-ish: when fitting another engine the cargo capacity of wagons could become lower, causing them to contain more than they should. This caused the cargo transfer from the replaced parts to put even more stuff in the already full wagon. Prevent this from happening by reducing the amount of cargo in the vehicle to the capacity when moving vehicles/wagons around, or when autoreplacing
rubidium <rubidium@openttd.org>
parents:
18832
diff
changeset
|
1263 |
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
|
1264 /* 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
|
1265 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
|
1266 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
|
1267 } 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
|
1268 /* 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
|
1269 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
|
1270 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
|
1271 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1272 |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
1273 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
|
1274 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1275 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
1276 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
1277 * 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
|
1278 * @param flags type of operation |
15850
efc03d77eb93
(svn r20532) -Codechange: unify selling of vehicles a bit
rubidium <rubidium@openttd.org>
parents:
15849
diff
changeset
|
1279 * @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
|
1280 * @param data the selling mode |
efc03d77eb93
(svn r20532) -Codechange: unify selling of vehicles a bit
rubidium <rubidium@openttd.org>
parents:
15849
diff
changeset
|
1281 * - 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
|
1282 * - 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
|
1283 * 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
|
1284 * @param user the user for the order backup. |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13054
diff
changeset
|
1285 * @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
|
1286 */ |
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
|
1287 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
|
1288 { |
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
|
1289 /* 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
|
1290 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
|
1291 |
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
|
1292 /* 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
|
1293 bool sell_chain = HasBit(data, 0); |
efc03d77eb93
(svn r20532) -Codechange: unify selling of vehicles a bit
rubidium <rubidium@openttd.org>
parents:
15849
diff
changeset
|
1294 |
efc03d77eb93
(svn r20532) -Codechange: unify selling of vehicles a bit
rubidium <rubidium@openttd.org>
parents:
15849
diff
changeset
|
1295 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
|
1296 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
|
1297 |
12302
fc8e41f34b8c
(svn r16719) -Codechange: make IsArticulatedPart(), IsTrainEngine(), IsTrainWagon(), IsMultiheaded(), EngineHasArticPart() and IsRearDualheaded() members of Train
smatz <smatz@openttd.org>
parents:
12301
diff
changeset
|
1298 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
|
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 /* 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
|
1301 * 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
|
1302 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
|
1303 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
|
1304 |
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
|
1305 /* 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
|
1306 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
|
1307 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
|
1308 |
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 /* 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
|
1310 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
|
1311 |
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 /* 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
|
1313 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
|
1314 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
|
1315 /* 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
|
1316 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
|
1317 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
|
1318 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1319 |
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
|
1320 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
|
1321 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
|
1322 |
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
|
1323 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
|
1324 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
|
1325 } |
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
|
1326 |
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
|
1327 /* 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
|
1328 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
|
1329 /* 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
|
1330 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
|
1331 |
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
|
1332 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
|
1333 /* 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
|
1334 * '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
|
1335 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
|
1336 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
|
1337 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
|
1338 |
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 /* 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
|
1340 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
|
1341 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
|
1342 |
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 /* 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
|
1344 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
|
1345 } 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
|
1346 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
|
1347 } |
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 |
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
|
1349 /* 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
|
1350 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
|
1351 |
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 /* 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
|
1353 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
|
1354 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
|
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 /* 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
|
1357 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
|
1358 } 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
|
1359 /* 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
|
1360 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
|
1361 } |
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
|
1362 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1363 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
|
1364 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1365 |
6558
2fc024ee8217
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium <rubidium@openttd.org>
parents:
6554
diff
changeset
|
1366 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
|
1367 { |
18446
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1368 /* Set common defaults. */ |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1369 this->x_offs = -1; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1370 this->y_offs = -1; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1371 this->x_extent = 3; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1372 this->y_extent = 3; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1373 this->z_extent = 6; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1374 this->x_bb_offs = 0; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1375 this->y_bb_offs = 0; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1376 |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1377 if (!IsDiagonalDirection(direction)) { |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1378 static const int _sign_table[] = |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1379 { |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1380 // x, y |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1381 -1, -1, // DIR_N |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1382 -1, 1, // DIR_E |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1383 1, 1, // DIR_S |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1384 1, -1, // DIR_W |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1385 }; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1386 |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1387 int half_shorten = (VEHICLE_LENGTH - this->gcache.cached_veh_length) / 2; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1388 |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1389 /* For all straight directions, move the bound box to the centre of the vehicle, but keep the size. */ |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1390 this->x_offs -= half_shorten * _sign_table[direction]; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1391 this->y_offs -= half_shorten * _sign_table[direction + 1]; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1392 this->x_extent += this->x_bb_offs = half_shorten * _sign_table[direction]; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1393 this->y_extent += this->y_bb_offs = half_shorten * _sign_table[direction + 1]; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1394 } else { |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1395 switch (direction) { |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1396 /* Shorten southern corner of the bounding box according the vehicle length |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1397 * and center the bounding box on the vehicle. */ |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1398 case DIR_NE: |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1399 this->x_offs = 1 - (this->gcache.cached_veh_length + 1) / 2; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1400 this->x_extent = this->gcache.cached_veh_length - 1; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1401 this->x_bb_offs = -1; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1402 break; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1403 |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1404 case DIR_NW: |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1405 this->y_offs = 1 - (this->gcache.cached_veh_length + 1) / 2; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1406 this->y_extent = this->gcache.cached_veh_length - 1; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1407 this->y_bb_offs = -1; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1408 break; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1409 |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1410 /* Move northern corner of the bounding box down according to vehicle length |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1411 * and center the bounding box on the vehicle. */ |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1412 case DIR_SW: |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1413 this->x_offs = 1 + (this->gcache.cached_veh_length + 1) / 2 - VEHICLE_LENGTH; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1414 this->x_extent = VEHICLE_LENGTH - 1; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1415 this->x_bb_offs = VEHICLE_LENGTH - this->gcache.cached_veh_length - 1; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1416 break; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1417 |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1418 case DIR_SE: |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1419 this->y_offs = 1 + (this->gcache.cached_veh_length + 1) / 2 - VEHICLE_LENGTH; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1420 this->y_extent = VEHICLE_LENGTH - 1; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1421 this->y_bb_offs = VEHICLE_LENGTH - this->gcache.cached_veh_length - 1; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1422 break; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1423 |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1424 default: |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1425 NOT_REACHED(); |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1426 } |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1427 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1428 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1429 |
18855
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1430 /** |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1431 * Mark a train as stuck and stop it if it isn't stopped right now. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1432 * @param v %Train to mark as being stuck. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1433 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1434 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
|
1435 { |
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
|
1436 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
|
1437 /* 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
|
1438 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
|
1439 |
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
|
1440 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
|
1441 |
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
|
1442 /* 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
|
1443 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
|
1444 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
|
1445 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
|
1446 |
18692
90d395fc678d
(svn r23540) -Codechange: unify and document vehicle widgets
rubidium <rubidium@openttd.org>
parents:
18627
diff
changeset
|
1447 SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP); |
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
|
1448 } |
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
|
1449 } |
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
|
1450 |
18855
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1451 /** |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1452 * Swap the two up/down flags in two ways: |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1453 * - Swap values of \a swap_flag1 and \a swap_flag2, and |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1454 * - If going up previously (#GVF_GOINGUP_BIT set), the #GVF_GOINGDOWN_BIT is set, and vice versa. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1455 * @param swap_flag1 [inout] First train flag. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1456 * @param swap_flag2 [inout] Second train flag. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1457 */ |
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
|
1458 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
|
1459 { |
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
|
1460 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
|
1461 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
|
1462 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1463 /* Clear the flags */ |
14753
3e27a2798ca0
(svn r19341) -Codechange: Move GOINGUP/GOINGDOWN flags to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14751
diff
changeset
|
1464 ClrBit(*swap_flag1, GVF_GOINGUP_BIT); |
3e27a2798ca0
(svn r19341) -Codechange: Move GOINGUP/GOINGDOWN flags to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14751
diff
changeset
|
1465 ClrBit(*swap_flag1, GVF_GOINGDOWN_BIT); |
3e27a2798ca0
(svn r19341) -Codechange: Move GOINGUP/GOINGDOWN flags to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14751
diff
changeset
|
1466 ClrBit(*swap_flag2, GVF_GOINGUP_BIT); |
3e27a2798ca0
(svn r19341) -Codechange: Move GOINGUP/GOINGDOWN flags to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14751
diff
changeset
|
1467 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
|
1468 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1469 /* 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
|
1470 if (HasBit(flag1, GVF_GOINGUP_BIT)) { |
3e27a2798ca0
(svn r19341) -Codechange: Move GOINGUP/GOINGDOWN flags to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14751
diff
changeset
|
1471 SetBit(*swap_flag2, GVF_GOINGDOWN_BIT); |
3e27a2798ca0
(svn r19341) -Codechange: Move GOINGUP/GOINGDOWN flags to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14751
diff
changeset
|
1472 } 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
|
1473 SetBit(*swap_flag2, GVF_GOINGUP_BIT); |
14768
f31d8dc443fc
(svn r19356) -Fix: Whitespace.
frosch <frosch@openttd.org>
parents:
14754
diff
changeset
|
1474 } |
14753
3e27a2798ca0
(svn r19341) -Codechange: Move GOINGUP/GOINGDOWN flags to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14751
diff
changeset
|
1475 if (HasBit(flag2, GVF_GOINGUP_BIT)) { |
3e27a2798ca0
(svn r19341) -Codechange: Move GOINGUP/GOINGDOWN flags to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14751
diff
changeset
|
1476 SetBit(*swap_flag1, GVF_GOINGDOWN_BIT); |
3e27a2798ca0
(svn r19341) -Codechange: Move GOINGUP/GOINGDOWN flags to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14751
diff
changeset
|
1477 } 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
|
1478 SetBit(*swap_flag1, GVF_GOINGUP_BIT); |
14768
f31d8dc443fc
(svn r19356) -Fix: Whitespace.
frosch <frosch@openttd.org>
parents:
14754
diff
changeset
|
1479 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1480 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1481 |
17098
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1482 /** |
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1483 * 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
|
1484 * @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
|
1485 */ |
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1486 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
|
1487 { |
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1488 /* 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
|
1489 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
|
1490 |
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1491 /* 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
|
1492 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
|
1493 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
|
1494 } 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
|
1495 /* 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
|
1496 * 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
|
1497 * 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
|
1498 * 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
|
1499 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
|
1500 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
|
1501 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
|
1502 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
|
1503 /* 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
|
1504 * "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
|
1505 * because we are at the border of the tile. */ |
18865
ab93092e1cb2
(svn r23714) -Codechange: don't mix Viewport with non-viewport code
truebrain <truebrain@openttd.org>
parents:
18864
diff
changeset
|
1506 VehicleUpdatePosition(v); |
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
|
1507 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
|
1508 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
|
1509 } |
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
|
1510 } |
17098
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1511 } |
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1512 |
18865
ab93092e1cb2
(svn r23714) -Codechange: don't mix Viewport with non-viewport code
truebrain <truebrain@openttd.org>
parents:
18864
diff
changeset
|
1513 VehicleUpdatePosition(v); |
17098
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1514 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
|
1515 } |
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1516 |
18855
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1517 /** |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1518 * Swap vehicles \a l and \a r in consist \a v, and reverse their direction. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1519 * @param v Consist to change. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1520 * @param l %Vehicle index in the consist of the first vehicle. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1521 * @param r %Vehicle index in the consist of the second vehicle. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1522 */ |
18446
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1523 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
|
1524 { |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1525 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
|
1526 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1527 /* 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
|
1528 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
|
1529 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
|
1530 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1531 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
|
1532 /* 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
|
1533 { |
14678
68f4a5f222ef
(svn r19257) -Codechange: minor coding style fix
smatz <smatz@openttd.org>
parents:
14645
diff
changeset
|
1534 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
|
1535 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
|
1536 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
|
1537 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1538 |
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
|
1539 Swap(a->track, b->track); |
14680
f3dfa0c1c278
(svn r19260) -Codechange: another minor coding style fix
smatz <smatz@openttd.org>
parents:
14678
diff
changeset
|
1540 Swap(a->direction, b->direction); |
5733 | 1541 Swap(a->x_pos, b->x_pos); |
1542 Swap(a->y_pos, b->y_pos); | |
1543 Swap(a->tile, b->tile); | |
1544 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
|
1545 |
14753
3e27a2798ca0
(svn r19341) -Codechange: Move GOINGUP/GOINGDOWN flags to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14751
diff
changeset
|
1546 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
|
1547 |
17098
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1548 UpdateStatusAfterSwap(a); |
5035955400bc
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
smatz <smatz@openttd.org>
parents:
17063
diff
changeset
|
1549 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
|
1550 } 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
|
1551 /* 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
|
1552 * 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
|
1553 * 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
|
1554 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
|
1555 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
|
1556 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1557 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1558 |
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
|
1559 |
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 /** |
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 * 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
|
1562 * @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
|
1563 * @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
|
1564 */ |
9775
c3caa51b9888
(svn r13912) -Codechange: remove some casts by returning the proper type instead of void*.
rubidium <rubidium@openttd.org>
parents:
9774
diff
changeset
|
1565 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
|
1566 { |
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
|
1567 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
|
1568 } |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1569 |
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 |
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 /** |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1572 * 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
|
1573 * @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
|
1574 * @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
|
1575 * @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
|
1576 */ |
9775
c3caa51b9888
(svn r13912) -Codechange: remove some casts by returning the proper type instead of void*.
rubidium <rubidium@openttd.org>
parents:
9774
diff
changeset
|
1577 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
|
1578 { |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
1579 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
|
1580 |
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
1581 Train *t = Train::From(v); |
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
1582 if (!t->IsFrontEngine()) return NULL; |
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
1583 |
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
1584 TileIndex tile = *(TileIndex *)data; |
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
1585 |
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
1586 if (TrainApproachingCrossingTile(t) != tile) return NULL; |
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
1587 |
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
1588 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
|
1589 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1590 |
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
|
1591 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1592 /** |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1593 * 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
|
1594 * @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
|
1595 * @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
|
1596 * @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
|
1597 */ |
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
|
1598 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
|
1599 { |
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
|
1600 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
|
1601 |
8598
ef2c93a9589d
(svn r12179) -Codechange: use GetCrossingRailTrack() and GetCrossingRailAxis() to improve code readability
smatz <smatz@openttd.org>
parents:
8597
diff
changeset
|
1602 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
|
1603 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
|
1604 |
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
|
1605 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
|
1606 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1607 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
|
1608 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
|
1609 |
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
|
1610 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
|
1611 } |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1612 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1613 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1614 /** |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1615 * 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
|
1616 * @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
|
1617 * @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
|
1618 * @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
|
1619 */ |
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
|
1620 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
|
1621 { |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1622 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
|
1623 |
9824
fe3562a51648
(svn r13966) -Codechange [YAPP]: Bar level crossings upon path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9822
diff
changeset
|
1624 /* 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
|
1625 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
|
1626 |
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
|
1627 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
|
1628 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
|
1629 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
|
1630 } |
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
|
1631 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
|
1632 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
|
1633 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1634 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1635 |
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
|
1636 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1637 /** |
8356
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1638 * 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
|
1639 * @param tile tile with crossing |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1640 * @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
|
1641 */ |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1642 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
|
1643 { |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1644 if (!IsCrossingBarred(tile)) { |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1645 BarCrossing(tile); |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1646 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
|
1647 MarkTileDirtyByTile(tile); |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1648 } |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1649 } |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1650 |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1651 |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1652 /** |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1653 * 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
|
1654 * 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
|
1655 * @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
|
1656 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1657 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
|
1658 { |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1659 Train *base = v; |
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1660 Train *first = base; // first vehicle to move |
12460
4acae7d6f5ed
(svn r16894) -Codechange: Add [Specialised]Vehicle::Last().
frosch <frosch@openttd.org>
parents:
12450
diff
changeset
|
1661 Train *last = v->Last(); // last vehicle to move |
6150 | 1662 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
|
1663 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1664 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
|
1665 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
|
1666 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
|
1667 |
18446
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1668 int differential = base->CalcNextVehicleOffset() - last->CalcNextVehicleOffset(); |
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
|
1669 |
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 /* 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
|
1671 * 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
|
1672 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
|
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 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
|
1675 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
|
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 } |
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 |
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
|
1679 |
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
|
1680 /** |
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 * 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
|
1682 * 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
|
1683 * @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
|
1684 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1685 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
|
1686 { |
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
|
1687 /* 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
|
1688 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
|
1689 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
|
1690 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
|
1691 } |
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
|
1692 |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1693 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
|
1694 |
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
|
1695 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
|
1696 /* '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
|
1697 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
|
1698 |
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
|
1699 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
|
1700 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
|
1701 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
|
1702 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
|
1703 } |
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
|
1704 } 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
|
1705 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
|
1706 } |
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
|
1707 |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1708 Train *base = v; |
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1709 Train *first = base; // first vehicle to move |
12460
4acae7d6f5ed
(svn r16894) -Codechange: Add [Specialised]Vehicle::Last().
frosch <frosch@openttd.org>
parents:
12450
diff
changeset
|
1710 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
|
1711 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
|
1712 |
15820
59fd8293b2ee
(svn r20499) -Doc: Spelling fixes, and one doxygen comment addition.
alberth <alberth@openttd.org>
parents:
15763
diff
changeset
|
1713 /* 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
|
1714 * 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
|
1715 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
|
1716 |
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
|
1717 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
|
1718 /* 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
|
1719 * (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
|
1720 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
|
1721 |
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
|
1722 /* 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
|
1723 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
|
1724 |
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
|
1725 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
|
1726 first = first->Next(); |
6150 | 1727 |
18446
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1728 int differential = last->CalcNextVehicleOffset() - base->CalcNextVehicleOffset(); |
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
|
1729 |
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
|
1730 /* 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
|
1731 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
|
1732 |
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
|
1733 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
|
1734 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
|
1735 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1736 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1737 |
18855
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1738 /** |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1739 * Turn a train around. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1740 * @param v %Train to turn around. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1741 */ |
18446
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
1742 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
|
1743 { |
8961
b33bcd7fa037
(svn r12753) -Codechange: do not use IsDepotTypeTile() where simpler function can be used
smatz <smatz@openttd.org>
parents:
8954
diff
changeset
|
1744 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
|
1745 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
|
1746 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1747 |
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
|
1748 /* 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
|
1749 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
|
1750 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1751 /* 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
|
1752 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
|
1753 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1754 /* count number of vehicles */ |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
1755 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
|
1756 |
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
|
1757 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
|
1758 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1759 /* swap start<>end, start+1<>end-1, ... */ |
6150 | 1760 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
|
1761 do { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1762 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
|
1763 } 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
|
1764 |
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
|
1765 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
|
1766 |
8961
b33bcd7fa037
(svn r12753) -Codechange: do not use IsDepotTypeTile() where simpler function can be used
smatz <smatz@openttd.org>
parents:
8954
diff
changeset
|
1767 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
|
1768 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
|
1769 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1770 |
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
|
1771 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
|
1772 |
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
|
1773 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
|
1774 |
8667
4e73621c3950
(svn r12332) -Fix (r12331): Invalidate cached data and update image after setting flag.
peter1138 <peter1138@openttd.org>
parents:
8666
diff
changeset
|
1775 /* 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
|
1776 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
|
1777 |
4e73621c3950
(svn r12332) -Fix (r12331): Invalidate cached data and update image after setting flag.
peter1138 <peter1138@openttd.org>
parents:
8666
diff
changeset
|
1778 /* 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
|
1779 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
|
1780 |
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
|
1781 /* 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
|
1782 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
|
1783 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1784 /* 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
|
1785 crossing = TrainApproachingCrossingTile(v); |
8356
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1786 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
|
1787 |
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1788 /* 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
|
1789 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
|
1790 /* Can't be stuck here as inside a depot is always a safe tile. */ |
18692
90d395fc678d
(svn r23540) -Codechange: unify and document vehicle widgets
rubidium <rubidium@openttd.org>
parents:
18627
diff
changeset
|
1791 if (HasBit(v->flags, VRF_TRAIN_STUCK)) SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP); |
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
|
1792 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
|
1793 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
|
1794 } |
9819
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1795 |
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1796 /* 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
|
1797 * 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
|
1798 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
|
1799 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
|
1800 |
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1801 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
|
1802 /* 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
|
1803 * 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
|
1804 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
|
1805 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
|
1806 !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
|
1807 |
19201
a934b903e21e
(svn r24078) -Fix [FS#5093,FS#5130] (r24071): A fix that breaks all other cases isn't really a fix. Redo it to make sure that reservations of trains entering or exiting depots are properly made and freed.
michi_cc <michi_cc@openttd.org>
parents:
19197
diff
changeset
|
1808 /* If we are on a depot tile facing outwards, do not treat the current tile as safe. */ |
a934b903e21e
(svn r24078) -Fix [FS#5093,FS#5130] (r24071): A fix that breaks all other cases isn't really a fix. Redo it to make sure that reservations of trains entering or exiting depots are properly made and freed.
michi_cc <michi_cc@openttd.org>
parents:
19197
diff
changeset
|
1809 if (IsRailDepotTile(v->tile) && TrackdirToExitdir(v->GetVehicleTrackdir()) == GetRailDepotDirection(v->tile)) first_tile_okay = false; |
a934b903e21e
(svn r24078) -Fix [FS#5093,FS#5130] (r24071): A fix that breaks all other cases isn't really a fix. Redo it to make sure that reservations of trains entering or exiting depots are properly made and freed.
michi_cc <michi_cc@openttd.org>
parents:
19197
diff
changeset
|
1810 |
12502
9472b49c61a1
(svn r16939) -Codechange: s/RailwayStation/RailStation/ to unify the way it's written.
rubidium <rubidium@openttd.org>
parents:
12472
diff
changeset
|
1811 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
|
1812 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
|
1813 /* 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
|
1814 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
|
1815 } 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
|
1816 /* 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
|
1817 MarkTrainAsStuck(v); |
9819
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1818 } |
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
|
1819 } 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
|
1820 /* 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
|
1821 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
|
1822 v->wait_counter = 0; |
9819
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1823 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1824 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1825 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
1826 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
1827 * 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
|
1828 * @param tile unused |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1829 * @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
|
1830 * @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
|
1831 * @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
|
1832 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13054
diff
changeset
|
1833 * @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
|
1834 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11085
diff
changeset
|
1835 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
|
1836 { |
12034
aa140a9c419c
(svn r16441) -Codechange: new class SpecializedVehicle used as superclass for all vehicle types
smatz <smatz@openttd.org>
parents:
12032
diff
changeset
|
1837 Train *v = Train::GetIfValid(p1); |
14815
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1838 if (v == NULL) return CMD_ERROR; |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1839 |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1840 CommandCost ret = CheckOwnership(v->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1841 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
|
1842 |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
1843 if (p2 != 0) { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1844 /* 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
|
1845 |
13036
8e2a0e8fa275
(svn r17534) -Codechange: unify the naming of callback masks/flags
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
1846 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
|
1847 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
|
1848 } |
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
|
1849 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
|
1850 |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1851 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
|
1852 /* 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
|
1853 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
|
1854 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
|
1855 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1856 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1857 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
|
1858 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
|
1859 |
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
|
1860 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
|
1861 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
|
1862 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
|
1863 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
|
1864 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
|
1865 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1866 } 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
|
1867 /* 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
|
1868 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
|
1869 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1870 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
|
1871 /* 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
|
1872 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
|
1873 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
|
1874 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
|
1875 |
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
|
1876 /* 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
|
1877 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
|
1878 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
|
1879 } |
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
|
1880 } |
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
|
1881 |
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
|
1882 /* We cancel any 'skip signal at dangers' here */ |
15362
834b4f9842c2
(svn r20005) -Codechange: Enumify force_proceed.
frosch <frosch@openttd.org>
parents:
15351
diff
changeset
|
1883 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
|
1884 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
|
1885 |
14406
5f93639271ee
(svn r18963) -Codechange: Give AccelerationModel a generical name.
terkhen <terkhen@openttd.org>
parents:
14384
diff
changeset
|
1886 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
|
1887 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
|
1888 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1889 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
|
1890 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
|
1891 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
|
1892 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
|
1893 } |
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 } |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
1896 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
|
1897 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1898 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
1899 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
1900 * 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
|
1901 * @param tile unused |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1902 * @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
|
1903 * @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
|
1904 * @param p2 unused |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13054
diff
changeset
|
1905 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13054
diff
changeset
|
1906 * @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
|
1907 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11085
diff
changeset
|
1908 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
|
1909 { |
12034
aa140a9c419c
(svn r16441) -Codechange: new class SpecializedVehicle used as superclass for all vehicle types
smatz <smatz@openttd.org>
parents:
12032
diff
changeset
|
1910 Train *t = Train::GetIfValid(p1); |
14815
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1911 if (t == NULL) return CMD_ERROR; |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1912 |
19479
5c205cdec645
(svn r24382) -Fix: Call Vehicle::IsStoppedInDepot only for the first vehicle in a chain (i.e. primary vehicle or free wagon).
frosch <frosch@openttd.org>
parents:
19383
diff
changeset
|
1913 if (!t->IsPrimaryVehicle()) return CMD_ERROR; |
5c205cdec645
(svn r24382) -Fix: Call Vehicle::IsStoppedInDepot only for the first vehicle in a chain (i.e. primary vehicle or free wagon).
frosch <frosch@openttd.org>
parents:
19383
diff
changeset
|
1914 |
14815
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1915 CommandCost ret = CheckOwnership(t->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1916 if (ret.Failed()) return ret; |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14768
diff
changeset
|
1917 |
12034
aa140a9c419c
(svn r16441) -Codechange: new class SpecializedVehicle used as superclass for all vehicle types
smatz <smatz@openttd.org>
parents:
12032
diff
changeset
|
1918 |
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
|
1919 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
|
1920 /* 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
|
1921 * 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
|
1922 * 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
|
1923 * 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
|
1924 * next signal we encounter. */ |
19481
b271f4f060fa
(svn r24384) -Fix [FS#5188-ish]: Make IsInDepot() functions behave consistent across vehicle types and add IsChainInDepot instead, if that is what shall be checked.
frosch <frosch@openttd.org>
parents:
19479
diff
changeset
|
1925 t->force_proceed = t->force_proceed == TFP_SIGNAL ? TFP_NONE : HasBit(t->flags, VRF_TRAIN_STUCK) || t->IsChainInDepot() ? 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
|
1926 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
|
1927 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1928 |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
1929 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
|
1930 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1931 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
1932 /** |
18855
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1933 * Try to find a depot nearby. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1934 * @param v %Train that wants a depot. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1935 * @param max_distance Maximal search distance. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1936 * @return Information where the closest train depot is located. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1937 * @pre The given vehicle must not be crashed! |
15623
c62577640878
(svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents:
15620
diff
changeset
|
1938 */ |
13842
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
1939 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
|
1940 { |
6150 | 1941 assert(!(v->vehstatus & VS_CRASHED)); |
1942 | |
13842
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
1943 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
|
1944 |
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
|
1945 PBSTileInfo origin = FollowTrainReservation(v); |
13842
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
1946 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
|
1947 |
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
|
1948 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
|
1949 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
|
1950 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
|
1951 |
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
1952 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
|
1953 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1954 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1955 |
18855
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1956 /** |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1957 * Locate the closest depot for this consist, and return the information to the caller. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1958 * @param location [out] If not \c NULL and a depot is found, store its location in the given address. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1959 * @param destination [out] If not \c NULL and a depot is found, store its index in the given address. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1960 * @param reverse [out] If not \c NULL and a depot is found, store reversal information in the given address. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1961 * @return A depot has been found. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1962 */ |
8890
b1d45af72e04
(svn r12657) -Codechange: add 'FindClosestDepot' to the vehicle class.
rubidium <rubidium@openttd.org>
parents:
8862
diff
changeset
|
1963 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
|
1964 { |
13842
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
1965 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
|
1966 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
|
1967 |
b1d45af72e04
(svn r12657) -Codechange: add 'FindClosestDepot' to the vehicle class.
rubidium <rubidium@openttd.org>
parents:
8862
diff
changeset
|
1968 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
|
1969 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
|
1970 if (reverse != NULL) *reverse = tfdd.reverse; |
b1d45af72e04
(svn r12657) -Codechange: add 'FindClosestDepot' to the vehicle class.
rubidium <rubidium@openttd.org>
parents:
8862
diff
changeset
|
1971 |
b1d45af72e04
(svn r12657) -Codechange: add 'FindClosestDepot' to the vehicle class.
rubidium <rubidium@openttd.org>
parents:
8862
diff
changeset
|
1972 return true; |
b1d45af72e04
(svn r12657) -Codechange: add 'FindClosestDepot' to the vehicle class.
rubidium <rubidium@openttd.org>
parents:
8862
diff
changeset
|
1973 } |
b1d45af72e04
(svn r12657) -Codechange: add 'FindClosestDepot' to the vehicle class.
rubidium <rubidium@openttd.org>
parents:
8862
diff
changeset
|
1974 |
18855
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1975 /** Play a sound for a train leaving the station. */ |
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
|
1976 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
|
1977 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1978 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
|
1979 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
|
1980 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
|
1981 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
|
1982 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
|
1983 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
|
1984 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1985 |
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
|
1986 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
|
1987 |
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
|
1988 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
|
1989 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
|
1990 } |
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
|
1991 |
18855
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1992 /** |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1993 * Check if the train is on the last reserved tile and try to extend the path then. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1994 * @param v %Train that needs its path extended. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
1995 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
1996 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
|
1997 { |
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
|
1998 /* 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
|
1999 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
|
2000 |
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
|
2001 /* 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
|
2002 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
|
2003 |
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
|
2004 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
|
2005 /* 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
|
2006 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
|
2007 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
|
2008 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
|
2009 |
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
|
2010 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
|
2011 /* 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
|
2012 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
|
2013 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
|
2014 |
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
|
2015 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
|
2016 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
|
2017 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
|
2018 /* 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
|
2019 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
|
2020 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
|
2021 |
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
|
2022 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
|
2023 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
|
2024 } |
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
|
2025 /* 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
|
2026 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
|
2027 |
11976
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
2028 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
|
2029 |
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
|
2030 /* 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
|
2031 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
|
2032 !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
|
2033 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
|
2034 |
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
|
2035 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
|
2036 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
|
2037 |
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
|
2038 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
|
2039 /* 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
|
2040 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
|
2041 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
|
2042 /* 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
|
2043 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
|
2044 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
|
2045 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
|
2046 } |
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
|
2047 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
|
2048 } |
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
|
2049 } |
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
|
2050 } |
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
|
2051 } |
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
|
2052 |
18855
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2053 /** |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2054 * Will the train stay in the depot the next tick? |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2055 * @param v %Train to check. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2056 * @return True if it stays in the depot, false otherwise. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2057 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
2058 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
|
2059 { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2060 /* 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
|
2061 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
|
2062 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
|
2063 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2064 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2065 /* 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
|
2066 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
|
2067 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
|
2068 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
|
2069 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
|
2070 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2071 |
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
|
2072 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
|
2073 |
15362
834b4f9842c2
(svn r20005) -Codechange: Enumify force_proceed.
frosch <frosch@openttd.org>
parents:
15351
diff
changeset
|
2074 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
|
2075 /* 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
|
2076 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
|
2077 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
|
2078 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
|
2079 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2080 |
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
|
2081 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
|
2082 |
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
|
2083 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
|
2084 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
|
2085 /* 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
|
2086 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
|
2087 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
|
2088 } |
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
|
2089 } 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
|
2090 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
|
2091 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2092 |
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
|
2093 /* 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
|
2094 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
|
2095 /* 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
|
2096 if (HasDepotReservation(v->tile)) return true; |
c0587ce9da72
(svn r16908) -Codechange: s/DepotWaypointReservation/DepotReservation/
rubidium <rubidium@openttd.org>
parents:
12470
diff
changeset
|
2097 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
|
2098 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
|
2099 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
|
2100 } |
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
|
2101 |
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
|
2102 /* 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
|
2103 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
|
2104 /* 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
|
2105 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
|
2106 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
|
2107 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
|
2108 } |
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
|
2109 |
12471
c0587ce9da72
(svn r16908) -Codechange: s/DepotWaypointReservation/DepotReservation/
rubidium <rubidium@openttd.org>
parents:
12470
diff
changeset
|
2110 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
|
2111 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
|
2112 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2113 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
|
2114 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
|
2115 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
|
2116 |
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
|
2117 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
|
2118 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
|
2119 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2120 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
|
2121 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
|
2122 |
18865
ab93092e1cb2
(svn r23714) -Codechange: don't mix Viewport with non-viewport code
truebrain <truebrain@openttd.org>
parents:
18864
diff
changeset
|
2123 v->UpdateViewport(true, true); |
18864
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18855
diff
changeset
|
2124 VehicleUpdatePosition(v); |
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
|
2125 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
|
2126 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
|
2127 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
|
2128 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2129 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
|
2130 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2131 |
18855
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2132 /** |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2133 * Clear the reservation of \a tile that was just left by a wagon on \a track_dir. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2134 * @param v %Train owning the reservation. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2135 * @param tile Tile with reservation to clear. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2136 * @param track_dir Track direction to clear. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2137 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
2138 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
|
2139 { |
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
|
2140 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
|
2141 |
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
|
2142 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
|
2143 /* 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
|
2144 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
|
2145 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
|
2146 |
14707
ed6ca7f84893
(svn r19291) -Codechange: Rename HasVehicleOnTunnelBridge() to TunnelBridgeIsFree() and return a CommandCost status.
alberth <alberth@openttd.org>
parents:
14702
diff
changeset
|
2147 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
|
2148 /* 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
|
2149 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
|
2150 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
|
2151 |
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
|
2152 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
|
2153 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
|
2154 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
|
2155 } |
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
|
2156 } |
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
|
2157 } |
12502
9472b49c61a1
(svn r16939) -Codechange: s/RailwayStation/RailStation/ to unify the way it's written.
rubidium <rubidium@openttd.org>
parents:
12472
diff
changeset
|
2158 } 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
|
2159 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
|
2160 /* 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
|
2161 * 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
|
2162 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
|
2163 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
|
2164 } |
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
|
2165 } 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
|
2166 /* 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
|
2167 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
|
2168 } |
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
|
2169 } |
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
|
2170 |
18855
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2171 /** |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2172 * Free the reserved path in front of a vehicle. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2173 * @param v %Train owning the reserved path. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2174 * @param origin %Tile to start clearing (if #INVALID_TILE, use the current tile of \a v). |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2175 * @param orig_td Track direction (if #INVALID_TRACKDIR, use the track direction of \a v). |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2176 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
2177 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
|
2178 { |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
2179 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
|
2180 |
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
|
2181 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
|
2182 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
|
2183 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
|
2184 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
|
2185 |
19201
a934b903e21e
(svn r24078) -Fix [FS#5093,FS#5130] (r24071): A fix that breaks all other cases isn't really a fix. Redo it to make sure that reservations of trains entering or exiting depots are properly made and freed.
michi_cc <michi_cc@openttd.org>
parents:
19197
diff
changeset
|
2186 /* Can't be holding a reservation if we enter a depot. */ |
a934b903e21e
(svn r24078) -Fix [FS#5093,FS#5130] (r24071): A fix that breaks all other cases isn't really a fix. Redo it to make sure that reservations of trains entering or exiting depots are properly made and freed.
michi_cc <michi_cc@openttd.org>
parents:
19197
diff
changeset
|
2187 if (IsRailDepotTile(tile) && TrackdirToExitdir(td) != GetRailDepotDirection(tile)) return; |
a934b903e21e
(svn r24078) -Fix [FS#5093,FS#5130] (r24071): A fix that breaks all other cases isn't really a fix. Redo it to make sure that reservations of trains entering or exiting depots are properly made and freed.
michi_cc <michi_cc@openttd.org>
parents:
19197
diff
changeset
|
2188 if (v->track == TRACK_BIT_DEPOT) { |
a934b903e21e
(svn r24078) -Fix [FS#5093,FS#5130] (r24071): A fix that breaks all other cases isn't really a fix. Redo it to make sure that reservations of trains entering or exiting depots are properly made and freed.
michi_cc <michi_cc@openttd.org>
parents:
19197
diff
changeset
|
2189 /* Front engine is in a depot. We enter if some part is not in the depot. */ |
a934b903e21e
(svn r24078) -Fix [FS#5093,FS#5130] (r24071): A fix that breaks all other cases isn't really a fix. Redo it to make sure that reservations of trains entering or exiting depots are properly made and freed.
michi_cc <michi_cc@openttd.org>
parents:
19197
diff
changeset
|
2190 for (const Train *u = v; u != NULL; u = u->Next()) { |
a934b903e21e
(svn r24078) -Fix [FS#5093,FS#5130] (r24071): A fix that breaks all other cases isn't really a fix. Redo it to make sure that reservations of trains entering or exiting depots are properly made and freed.
michi_cc <michi_cc@openttd.org>
parents:
19197
diff
changeset
|
2191 if (u->track != TRACK_BIT_DEPOT || u->tile != v->tile) return; |
a934b903e21e
(svn r24078) -Fix [FS#5093,FS#5130] (r24071): A fix that breaks all other cases isn't really a fix. Redo it to make sure that reservations of trains entering or exiting depots are properly made and freed.
michi_cc <michi_cc@openttd.org>
parents:
19197
diff
changeset
|
2192 } |
a934b903e21e
(svn r24078) -Fix [FS#5093,FS#5130] (r24071): A fix that breaks all other cases isn't really a fix. Redo it to make sure that reservations of trains entering or exiting depots are properly made and freed.
michi_cc <michi_cc@openttd.org>
parents:
19197
diff
changeset
|
2193 } |
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
|
2194 /* 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
|
2195 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
|
2196 |
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
|
2197 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
|
2198 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
|
2199 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
|
2200 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
|
2201 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
|
2202 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
|
2203 |
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
|
2204 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
|
2205 |
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
|
2206 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
|
2207 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
|
2208 /* 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
|
2209 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
|
2210 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
|
2211 } |
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
|
2212 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
|
2213 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
|
2214 /* 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
|
2215 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
|
2216 } 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
|
2217 /* 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
|
2218 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
|
2219 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
|
2220 } |
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
|
2221 } 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
|
2222 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
|
2223 } |
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
|
2224 } |
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
|
2225 |
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
|
2226 /* 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
|
2227 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
|
2228 |
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
|
2229 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
|
2230 } |
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
|
2231 } |
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
|
2232 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2233 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
|
2234 {{ 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
|
2235 {{ 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
|
2236 {{ 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
|
2237 {{ 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
|
2238 {{ 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
|
2239 {{ 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
|
2240 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2241 |
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
|
2242 /** |
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
|
2243 * 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
|
2244 * |
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
|
2245 * @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
|
2246 * @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
|
2247 * @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
|
2248 * @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
|
2249 * @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
|
2250 * @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
|
2251 * @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
|
2252 * @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
|
2253 */ |
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
|
2254 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
|
2255 { |
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
|
2256 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
|
2257 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
|
2258 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
|
2259 |
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
2260 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
|
2261 } |
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
|
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 |
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 /** |
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
|
2265 * 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
|
2266 * 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
|
2267 * @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
|
2268 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
2269 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
|
2270 { |
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
|
2271 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
|
2272 |
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
|
2273 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
|
2274 |
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
|
2275 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
|
2276 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
|
2277 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
|
2278 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
|
2279 /* 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
|
2280 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
|
2281 } |
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
|
2282 |
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
|
2283 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
|
2284 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
|
2285 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
|
2286 } |
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
|
2287 |
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
|
2288 /* 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
|
2289 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
|
2290 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
|
2291 /* 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
|
2292 * 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
|
2293 * 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
|
2294 * 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
|
2295 * 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
|
2296 * 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
|
2297 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
|
2298 |
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
|
2299 /* 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
|
2300 * 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
|
2301 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
|
2302 |
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
|
2303 /* 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
|
2304 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
|
2305 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
|
2306 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
|
2307 } |
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
|
2308 |
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
|
2309 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
|
2310 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
|
2311 |
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
|
2312 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
|
2313 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
|
2314 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
|
2315 /* 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
|
2316 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
|
2317 } |
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
|
2318 |
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
|
2319 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
|
2320 } |
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
|
2321 |
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
|
2322 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
|
2323 /* 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
|
2324 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
|
2325 } |
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
|
2326 |
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
|
2327 /* 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
|
2328 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
|
2329 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
|
2330 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
|
2331 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
|
2332 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
|
2333 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
|
2334 |
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
|
2335 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
|
2336 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
|
2337 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
|
2338 } |
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
|
2339 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
|
2340 |
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
|
2341 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
|
2342 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
|
2343 |
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
|
2344 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
|
2345 } |
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
|
2346 |
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
|
2347 /* 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
|
2348 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
|
2349 } |
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
|
2350 |
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
|
2351 /** |
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
|
2352 * 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
|
2353 * 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
|
2354 * |
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
|
2355 * @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
|
2356 * @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
|
2357 * @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
|
2358 * @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
|
2359 * @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
|
2360 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
2361 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
|
2362 { |
13842
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
2363 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
|
2364 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
|
2365 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
|
2366 |
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
2367 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
|
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 } |
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 |
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
|
2371 /** This class will save the current order of a vehicle and restore it on destruction. */ |
18855
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2372 class VehicleOrderSaver { |
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
|
2373 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
|
2374 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
|
2375 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
|
2376 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
|
2377 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
|
2378 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
|
2379 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
|
2380 |
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
|
2381 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
|
2382 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
|
2383 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
|
2384 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
|
2385 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
|
2386 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
|
2387 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
|
2388 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
|
2389 { |
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
|
2390 } |
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
|
2391 |
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
|
2392 ~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
|
2393 { |
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
|
2394 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
|
2395 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
|
2396 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
|
2397 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
|
2398 } |
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
|
2399 |
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
|
2400 /** |
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
|
2401 * 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
|
2402 * @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
|
2403 * @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
|
2404 */ |
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
|
2405 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
|
2406 { |
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
|
2407 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
|
2408 |
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
|
2409 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
|
2410 |
18931
f3fa67f5398e
(svn r23781) -Fix [FS#4964]: under certain circumstances, e.g. a single invalid order, trying to determine the next order state could end up in an infinite loop
rubidium <rubidium@openttd.org>
parents:
18923
diff
changeset
|
2411 int depth = 0; |
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
|
2412 |
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
|
2413 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
|
2414 /* 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
|
2415 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
|
2416 |
11991
a4d3838349e6
(svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents:
11988
diff
changeset
|
2417 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
|
2418 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
|
2419 |
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
|
2420 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
|
2421 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
|
2422 /* 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
|
2423 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
|
2424 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
|
2425 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
|
2426 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
|
2427 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
|
2428 case OT_CONDITIONAL: { |
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
|
2429 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
|
2430 if (next != INVALID_VEH_ORDER_ID) { |
18931
f3fa67f5398e
(svn r23781) -Fix [FS#4964]: under certain circumstances, e.g. a single invalid order, trying to determine the next order state could end up in an infinite loop
rubidium <rubidium@openttd.org>
parents:
18923
diff
changeset
|
2431 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
|
2432 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
|
2433 /* 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
|
2434 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
|
2435 } |
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
|
2436 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
|
2437 } |
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
|
2438 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
|
2439 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
|
2440 } |
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
|
2441 /* 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
|
2442 * 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
|
2443 ++this->index; |
18931
f3fa67f5398e
(svn r23781) -Fix [FS#4964]: under certain circumstances, e.g. a single invalid order, trying to determine the next order state could end up in an infinite loop
rubidium <rubidium@openttd.org>
parents:
18923
diff
changeset
|
2444 depth++; |
f3fa67f5398e
(svn r23781) -Fix [FS#4964]: under certain circumstances, e.g. a single invalid order, trying to determine the next order state could end up in an infinite loop
rubidium <rubidium@openttd.org>
parents:
18923
diff
changeset
|
2445 } while (this->index != this->v->cur_real_order_index && depth < this->v->GetNumOrders()); |
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
|
2446 |
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
|
2447 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
|
2448 } |
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
|
2449 }; |
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
|
2450 |
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
|
2451 /* choose a track */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
2452 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
|
2453 { |
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 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
|
2455 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
|
2456 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
|
2457 |
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 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
|
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 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
|
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 /* 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
|
2463 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
|
2464 /* 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
|
2465 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
|
2466 |
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
|
2467 /* 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
|
2468 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
|
2469 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
|
2470 /* 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
|
2471 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
|
2472 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
|
2473 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
|
2474 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
|
2475 } 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
|
2476 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
|
2477 } |
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
|
2478 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
|
2479 } |
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
|
2480 |
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
|
2481 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
|
2482 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
|
2483 if (do_track_reservation) { |
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
|
2484 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
|
2485 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
|
2486 /* 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
|
2487 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
|
2488 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
|
2489 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
|
2490 } |
18839
1d05c702134c
(svn r23688) -Codechange: No need to check if a train needs servicing if we only extend a train's path without actually calling the pathfinder. The path extension will stop when hitting a junction tile, so it is impossible to miss a depot this way.
michi_cc <michi_cc@openttd.org>
parents:
18834
diff
changeset
|
2491 if (res_dest.okay) { |
1d05c702134c
(svn r23688) -Codechange: No need to check if a train needs servicing if we only extend a train's path without actually calling the pathfinder. The path extension will stop when hitting a junction tile, so it is impossible to miss a depot this way.
michi_cc <michi_cc@openttd.org>
parents:
18834
diff
changeset
|
2492 /* Got a valid reservation that ends at a safe target, quick exit. */ |
1d05c702134c
(svn r23688) -Codechange: No need to check if a train needs servicing if we only extend a train's path without actually calling the pathfinder. The path extension will stop when hitting a junction tile, so it is impossible to miss a depot this way.
michi_cc <michi_cc@openttd.org>
parents:
18834
diff
changeset
|
2493 if (got_reservation != NULL) *got_reservation = true; |
1d05c702134c
(svn r23688) -Codechange: No need to check if a train needs servicing if we only extend a train's path without actually calling the pathfinder. The path extension will stop when hitting a junction tile, so it is impossible to miss a depot this way.
michi_cc <michi_cc@openttd.org>
parents:
18834
diff
changeset
|
2494 if (changed_signal) MarkTileDirtyByTile(tile); |
1d05c702134c
(svn r23688) -Codechange: No need to check if a train needs servicing if we only extend a train's path without actually calling the pathfinder. The path extension will stop when hitting a junction tile, so it is impossible to miss a depot this way.
michi_cc <michi_cc@openttd.org>
parents:
18834
diff
changeset
|
2495 TryReserveRailTrack(v->tile, TrackdirToTrack(v->GetVehicleTrackdir())); |
1d05c702134c
(svn r23688) -Codechange: No need to check if a train needs servicing if we only extend a train's path without actually calling the pathfinder. The path extension will stop when hitting a junction tile, so it is impossible to miss a depot this way.
michi_cc <michi_cc@openttd.org>
parents:
18834
diff
changeset
|
2496 return best_track; |
1d05c702134c
(svn r23688) -Codechange: No need to check if a train needs servicing if we only extend a train's path without actually calling the pathfinder. The path extension will stop when hitting a junction tile, so it is impossible to miss a depot this way.
michi_cc <michi_cc@openttd.org>
parents:
18834
diff
changeset
|
2497 } |
1d05c702134c
(svn r23688) -Codechange: No need to check if a train needs servicing if we only extend a train's path without actually calling the pathfinder. The path extension will stop when hitting a junction tile, so it is impossible to miss a depot this way.
michi_cc <michi_cc@openttd.org>
parents:
18834
diff
changeset
|
2498 |
1d05c702134c
(svn r23688) -Codechange: No need to check if a train needs servicing if we only extend a train's path without actually calling the pathfinder. The path extension will stop when hitting a junction tile, so it is impossible to miss a depot this way.
michi_cc <michi_cc@openttd.org>
parents:
18834
diff
changeset
|
2499 /* Check if the train needs service here, so it has a chance to always find a depot. |
1d05c702134c
(svn r23688) -Codechange: No need to check if a train needs servicing if we only extend a train's path without actually calling the pathfinder. The path extension will stop when hitting a junction tile, so it is impossible to miss a depot this way.
michi_cc <michi_cc@openttd.org>
parents:
18834
diff
changeset
|
2500 * Also check if the current order is a service order so we don't reserve a path to |
1d05c702134c
(svn r23688) -Codechange: No need to check if a train needs servicing if we only extend a train's path without actually calling the pathfinder. The path extension will stop when hitting a junction tile, so it is impossible to miss a depot this way.
michi_cc <michi_cc@openttd.org>
parents:
18834
diff
changeset
|
2501 * the destination but instead to the next one if service isn't needed. */ |
1d05c702134c
(svn r23688) -Codechange: No need to check if a train needs servicing if we only extend a train's path without actually calling the pathfinder. The path extension will stop when hitting a junction tile, so it is impossible to miss a depot this way.
michi_cc <michi_cc@openttd.org>
parents:
18834
diff
changeset
|
2502 CheckIfTrainNeedsService(v); |
1d05c702134c
(svn r23688) -Codechange: No need to check if a train needs servicing if we only extend a train's path without actually calling the pathfinder. The path extension will stop when hitting a junction tile, so it is impossible to miss a depot this way.
michi_cc <michi_cc@openttd.org>
parents:
18834
diff
changeset
|
2503 if (v->current_order.IsType(OT_DUMMY) || v->current_order.IsType(OT_CONDITIONAL) || v->current_order.IsType(OT_GOTO_DEPOT)) ProcessOrders(v); |
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
|
2504 } |
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
|
2505 |
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
|
2506 /* 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
|
2507 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
|
2508 |
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
|
2509 /* 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
|
2510 * 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
|
2511 * 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
|
2512 * 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
|
2513 * 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
|
2514 * 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
|
2515 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
|
2516 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
|
2517 } 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
|
2518 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
|
2519 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
|
2520 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
|
2521 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
|
2522 } |
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
|
2523 |
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
|
2524 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
|
2525 /* 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
|
2526 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
|
2527 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
|
2528 |
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
|
2529 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
|
2530 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
|
2531 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
|
2532 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2533 |
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
|
2534 /* 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
|
2535 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
|
2536 |
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
|
2537 /* 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
|
2538 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
|
2539 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
|
2540 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
|
2541 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
|
2542 } |
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
|
2543 |
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
|
2544 /* 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
|
2545 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
|
2546 /* 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
|
2547 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
|
2548 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
|
2549 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
|
2550 best_track = FindFirstTrack(res); |
11976
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
2551 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
|
2552 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
|
2553 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
|
2554 } 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
|
2555 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
|
2556 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
|
2557 } |
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
|
2558 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
|
2559 } |
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
|
2560 |
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
|
2561 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
|
2562 |
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
|
2563 /* 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
|
2564 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
|
2565 /* 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
|
2566 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
|
2567 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
|
2568 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
|
2569 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
|
2570 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
|
2571 } |
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
|
2572 |
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
|
2573 /* 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
|
2574 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
|
2575 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
|
2576 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
|
2577 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
|
2578 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
|
2579 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
|
2580 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
|
2581 /* 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
|
2582 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
|
2583 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
|
2584 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
|
2585 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
|
2586 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
|
2587 } |
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
|
2588 } |
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
|
2589 /* 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
|
2590 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
|
2591 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
|
2592 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
|
2593 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
|
2594 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
|
2595 } |
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
|
2596 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
|
2597 } |
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
|
2598 |
11976
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
2599 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
|
2600 |
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
|
2601 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
|
2602 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2603 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
|
2604 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2605 |
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
|
2606 /** |
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
|
2607 * 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
|
2608 * |
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
|
2609 * @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
|
2610 * @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
|
2611 * @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
|
2612 * @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
|
2613 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
2614 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
|
2615 { |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
2616 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
|
2617 |
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
|
2618 /* 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
|
2619 * 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
|
2620 * 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
|
2621 if (v->track == TRACK_BIT_DEPOT) { |
12471
c0587ce9da72
(svn r16908) -Codechange: s/DepotWaypointReservation/DepotReservation/
rubidium <rubidium@openttd.org>
parents:
12470
diff
changeset
|
2622 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
|
2623 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
|
2624 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
|
2625 } 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
|
2626 /* 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
|
2627 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
|
2628 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
|
2629 } |
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
|
2630 } |
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
|
2631 |
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
|
2632 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
|
2633 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
|
2634 /* 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
|
2635 * 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
|
2636 * 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
|
2637 * 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
|
2638 * 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
|
2639 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
|
2640 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
|
2641 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
|
2642 } |
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
|
2643 /* 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
|
2644 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
|
2645 /* Can't be stuck then. */ |
18692
90d395fc678d
(svn r23540) -Codechange: unify and document vehicle widgets
rubidium <rubidium@openttd.org>
parents:
18627
diff
changeset
|
2646 if (HasBit(v->flags, VRF_TRAIN_STUCK)) SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP); |
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
|
2647 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
|
2648 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
|
2649 } |
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
|
2650 |
15820
59fd8293b2ee
(svn r20499) -Doc: Spelling fixes, and one doxygen comment addition.
alberth <alberth@openttd.org>
parents:
15763
diff
changeset
|
2651 /* 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
|
2652 if (v->track == TRACK_BIT_DEPOT) { |
12471
c0587ce9da72
(svn r16908) -Codechange: s/DepotWaypointReservation/DepotReservation/
rubidium <rubidium@openttd.org>
parents:
12470
diff
changeset
|
2653 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
|
2654 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
|
2655 } |
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
|
2656 |
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
|
2657 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
|
2658 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
|
2659 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
|
2660 |
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
|
2661 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
|
2662 |
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
|
2663 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
|
2664 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
|
2665 |
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
|
2666 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
|
2667 /* Free the depot reservation as well. */ |
12471
c0587ce9da72
(svn r16908) -Codechange: s/DepotWaypointReservation/DepotReservation/
rubidium <rubidium@openttd.org>
parents:
12470
diff
changeset
|
2668 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
|
2669 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
|
2670 } |
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
|
2671 |
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
|
2672 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
|
2673 v->wait_counter = 0; |
18692
90d395fc678d
(svn r23540) -Codechange: unify and document vehicle widgets
rubidium <rubidium@openttd.org>
parents:
18627
diff
changeset
|
2674 SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP); |
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
|
2675 } |
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
|
2676 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
|
2677 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
|
2678 } |
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
|
2679 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2680 |
13842
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
2681 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
|
2682 { |
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
|
2683 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
|
2684 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
|
2685 !(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
|
2686 return false; |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2687 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2688 |
13842
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
2689 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
|
2690 |
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
|
2691 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
|
2692 case VPF_NPF: return NPFTrainCheckReverse(v); |
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
2693 case VPF_YAPF: return YapfTrainCheckReverse(v); |
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
2694 |
72b2245c3b0d
(svn r18371) -Codechange: unify calling of the train pathfinders
rubidium <rubidium@openttd.org>
parents:
13835
diff
changeset
|
2695 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
|
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 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2698 |
18855
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2699 /** |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2700 * Get the location of the next station to visit. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2701 * @param station Next station to visit. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2702 * @return Location of the new station. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2703 */ |
8827
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8794
diff
changeset
|
2704 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
|
2705 { |
8830
981a95f3204d
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents:
8827
diff
changeset
|
2706 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
|
2707 |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11920
diff
changeset
|
2708 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
|
2709 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
|
2710 /* 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
|
2711 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
|
2712 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
|
2713 } |
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
|
2714 |
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
|
2715 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
|
2716 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2717 |
18855
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2718 /** Goods at the consist have changed, update the graphics, cargo, and acceleration. */ |
6553
733ef9947fe2
(svn r9755) -Codechange: refactor some more of the begin loading stuff.
rubidium <rubidium@openttd.org>
parents:
6552
diff
changeset
|
2719 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
|
2720 { |
15127
c065afa82756
(svn r19756) -Codechange: move UpdateViewport() from Vehicle to SpecializedVehicle in order to improve performance
smatz <smatz@openttd.org>
parents:
15073
diff
changeset
|
2721 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
|
2722 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
|
2723 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
|
2724 } 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
|
2725 |
733ef9947fe2
(svn r9755) -Codechange: refactor some more of the begin loading stuff.
rubidium <rubidium@openttd.org>
parents:
6552
diff
changeset
|
2726 /* 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
|
2727 this->CargoChanged(); |
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
2728 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
|
2729 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2730 |
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
|
2731 /** |
15002
baf0e12ad2b4
(svn r19614) -Codechange: "it's" => "its" where appropriate
smatz <smatz@openttd.org>
parents:
14898
diff
changeset
|
2732 * 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
|
2733 * 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
|
2734 * 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
|
2735 * 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
|
2736 * @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
|
2737 */ |
14284
fc532d11eb85
(svn r18836) -Codechange: make TrainUpdateSpeed a class function and update some comments (Terkhen)
rubidium <rubidium@openttd.org>
parents:
14261
diff
changeset
|
2738 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
|
2739 { |
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
|
2740 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
|
2741 default: NOT_REACHED(); |
14406
5f93639271ee
(svn r18963) -Codechange: Give AccelerationModel a generical name.
terkhen <terkhen@openttd.org>
parents:
14384
diff
changeset
|
2742 case AM_ORIGINAL: |
19093
38652cadf0fe
(svn r23947) -Feature: Timetabled maximum travel speeds for non-flying vehicles.
michi_cc <michi_cc@openttd.org>
parents:
18999
diff
changeset
|
2743 return this->DoUpdateSpeed(this->acceleration * (this->GetAccelerationStatus() == AS_BRAKE ? -4 : 2), 0, min(this->gcache.cached_max_track_speed, this->current_order.max_speed)); |
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
|
2744 |
14406
5f93639271ee
(svn r18963) -Codechange: Give AccelerationModel a generical name.
terkhen <terkhen@openttd.org>
parents:
14384
diff
changeset
|
2745 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
|
2746 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
|
2747 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2748 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2749 |
16372
ea86953aa185
(svn r21088) -Doc: Additions/corrections of doxygen comments.
alberth <alberth@openttd.org>
parents:
16349
diff
changeset
|
2750 /** |
ea86953aa185
(svn r21088) -Doc: Additions/corrections of doxygen comments.
alberth <alberth@openttd.org>
parents:
16349
diff
changeset
|
2751 * 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
|
2752 * @param v Train that entered the station. |
ea86953aa185
(svn r21088) -Doc: Additions/corrections of doxygen comments.
alberth <alberth@openttd.org>
parents:
16349
diff
changeset
|
2753 * @param station Station visited. |
ea86953aa185
(svn r21088) -Doc: Additions/corrections of doxygen comments.
alberth <alberth@openttd.org>
parents:
16349
diff
changeset
|
2754 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
2755 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
|
2756 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2757 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
|
2758 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2759 /* 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
|
2760 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
|
2761 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
|
2762 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
|
2763 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
|
2764 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
|
2765 STR_NEWS_FIRST_TRAIN_ARRIVAL, |
19383
0c6420024e22
(svn r24284) -Codechange: Remove NewsSubtypes and directly use NewsTypes and NewsFlag instead.
frosch <frosch@openttd.org>
parents:
19381
diff
changeset
|
2766 v->owner == _local_company ? NT_ARRIVAL_COMPANY : NT_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
|
2767 v->index, |
10123
57aa34285d05
(svn r14307) -Fix: when deleting a station, remove news items regarding it
smatz <smatz@openttd.org>
parents:
10103
diff
changeset
|
2768 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
|
2769 ); |
18511
f1214da4c397
(svn r23355) -Codechange: rename all AI* to Script* (Rubidium)
truebrain <truebrain@openttd.org>
parents:
18472
diff
changeset
|
2770 AI::NewEvent(v->owner, new ScriptEventStationFirstVehicle(st->index, v->index)); |
18774
1fa19d70aea9
(svn r23622) -Add: a set of events to trigger in a GameScript
truebrain <truebrain@openttd.org>
parents:
18692
diff
changeset
|
2771 Game::NewEvent(new ScriptEventStationFirstVehicle(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
|
2772 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2773 |
15362
834b4f9842c2
(svn r20005) -Codechange: Enumify force_proceed.
frosch <frosch@openttd.org>
parents:
15351
diff
changeset
|
2774 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
|
2775 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
|
2776 |
6550
2fa52ce08b41
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium <rubidium@openttd.org>
parents:
6546
diff
changeset
|
2777 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
|
2778 |
15935
a4fa352275f4
(svn r20623) -Codechange: unify the storing of animation related information
rubidium <rubidium@openttd.org>
parents:
15899
diff
changeset
|
2779 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
|
2780 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2781 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2782 /* 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
|
2783 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
|
2784 { |
16547
a11cd939c335
(svn r21273) -Codechange: Return values should start at the same line.
alberth <alberth@openttd.org>
parents:
16511
diff
changeset
|
2785 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
|
2786 (!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
|
2787 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2788 |
18999
081eb943326c
(svn r23855) -Fix [FS#5007]: out of bounds read for slowdown parameter caused desync when railtype >= 4, vehicles were fast, and the original acceleration model was used
rubidium <rubidium@openttd.org>
parents:
18931
diff
changeset
|
2789 /** Data structure for storing engine speed changes of an acceleration type. */ |
081eb943326c
(svn r23855) -Fix [FS#5007]: out of bounds read for slowdown parameter caused desync when railtype >= 4, vehicles were fast, and the original acceleration model was used
rubidium <rubidium@openttd.org>
parents:
18931
diff
changeset
|
2790 struct AccelerationSlowdownParams { |
18855
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2791 byte small_turn; ///< Speed change due to a small turn. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2792 byte large_turn; ///< Speed change due to a large turn. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2793 byte z_up; ///< Fraction to remove when moving up. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2794 byte z_down; ///< Fraction to add when moving down. |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6247
diff
changeset
|
2795 }; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2796 |
18999
081eb943326c
(svn r23855) -Fix [FS#5007]: out of bounds read for slowdown parameter caused desync when railtype >= 4, vehicles were fast, and the original acceleration model was used
rubidium <rubidium@openttd.org>
parents:
18931
diff
changeset
|
2797 /** Speed update fractions for each acceleration type. */ |
081eb943326c
(svn r23855) -Fix [FS#5007]: out of bounds read for slowdown parameter caused desync when railtype >= 4, vehicles were fast, and the original acceleration model was used
rubidium <rubidium@openttd.org>
parents:
18931
diff
changeset
|
2798 static const AccelerationSlowdownParams _accel_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
|
2799 /* normal accel */ |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2800 {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
|
2801 {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
|
2802 {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
|
2803 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2804 |
18855
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2805 /** |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2806 * Modify the speed of the vehicle due to a change in altitude. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2807 * @param v %Train to update. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2808 * @param old_z Previous height. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2809 */ |
18272
3ebab55c5495
(svn r23108) -Codechange: more uint -> int / byte -> int conversions for Z related variables
rubidium <rubidium@openttd.org>
parents:
18255
diff
changeset
|
2810 static inline void AffectSpeedByZChange(Train *v, int 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
|
2811 { |
14406
5f93639271ee
(svn r18963) -Codechange: Give AccelerationModel a generical name.
terkhen <terkhen@openttd.org>
parents:
14384
diff
changeset
|
2812 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
|
2813 |
18999
081eb943326c
(svn r23855) -Fix [FS#5007]: out of bounds read for slowdown parameter caused desync when railtype >= 4, vehicles were fast, and the original acceleration model was used
rubidium <rubidium@openttd.org>
parents:
18931
diff
changeset
|
2814 const AccelerationSlowdownParams *asp = &_accel_slowdown[GetRailTypeInfo(v->railtype)->acceleration_type]; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2815 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2816 if (old_z < v->z_pos) { |
18999
081eb943326c
(svn r23855) -Fix [FS#5007]: out of bounds read for slowdown parameter caused desync when railtype >= 4, vehicles were fast, and the original acceleration model was used
rubidium <rubidium@openttd.org>
parents:
18931
diff
changeset
|
2817 v->cur_speed -= (v->cur_speed * asp->z_up >> 8); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2818 } else { |
18999
081eb943326c
(svn r23855) -Fix [FS#5007]: out of bounds read for slowdown parameter caused desync when railtype >= 4, vehicles were fast, and the original acceleration model was used
rubidium <rubidium@openttd.org>
parents:
18931
diff
changeset
|
2819 uint16 spd = v->cur_speed + asp->z_down; |
16785
775f357828e3
(svn r21518) -Codechange: Rename AccelerationCache to GroundVehicleCache.
terkhen <terkhen@openttd.org>
parents:
16776
diff
changeset
|
2820 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
|
2821 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2822 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2823 |
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
|
2824 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
|
2825 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2826 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
|
2827 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
|
2828 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
|
2829 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
|
2830 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
|
2831 /* 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
|
2832 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
|
2833 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2834 } |
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
|
2835 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
|
2836 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2837 |
18855
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2838 /** Tries to reserve track under whole train consist. */ |
12423
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2839 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
|
2840 { |
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2841 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
|
2842 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
|
2843 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
|
2844 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
|
2845 break; |
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2846 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
|
2847 break; |
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2848 default: |
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2849 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
|
2850 break; |
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2851 } |
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2852 } |
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2853 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2854 |
18855
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2855 /** |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2856 * The train vehicle crashed! |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2857 * Update its status and other parts around it. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2858 * @param flooded Crash was caused by flooding. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2859 * @return Number of people killed. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2860 */ |
13873
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13842
diff
changeset
|
2861 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
|
2862 { |
13873
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13842
diff
changeset
|
2863 uint pass = 0; |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13842
diff
changeset
|
2864 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
|
2865 pass += 2; // driver |
13873
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13842
diff
changeset
|
2866 |
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
|
2867 /* 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
|
2868 * 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
|
2869 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
|
2870 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
|
2871 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
|
2872 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
|
2873 /* 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
|
2874 * 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
|
2875 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
|
2876 } |
9811
84013100eac2
(svn r13953) -Add [YAPP]: Free track reservations of crashed trains. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9810
diff
changeset
|
2877 } |
13873
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13842
diff
changeset
|
2878 |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13842
diff
changeset
|
2879 /* 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
|
2880 * 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
|
2881 TileIndex crossing = TrainApproachingCrossingTile(this); |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13842
diff
changeset
|
2882 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
|
2883 |
7015f43f6a77
(svn r18941) -Fix [FS#3575]: remove the loading indicators as soon as a train crashes
yexo <yexo@openttd.org>
parents:
14382
diff
changeset
|
2884 /* 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
|
2885 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
|
2886 } |
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
|
2887 |
17141
4ccee6c9442b
(svn r21879) -Codechange: reset vehicle's GOINGUP/DOWN bits when it crashes
smatz <smatz@openttd.org>
parents:
17137
diff
changeset
|
2888 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
|
2889 |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13842
diff
changeset
|
2890 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
|
2891 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
|
2892 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2893 |
11150
7e9a1181206a
(svn r15497) -Fix (r15027): when trains crashed, AIEvent was created only for one train
smatz <smatz@openttd.org>
parents:
11149
diff
changeset
|
2894 /** |
7e9a1181206a
(svn r15497) -Fix (r15027): when trains crashed, AIEvent was created only for one train
smatz <smatz@openttd.org>
parents:
11149
diff
changeset
|
2895 * 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
|
2896 * 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
|
2897 * @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
|
2898 * @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
|
2899 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
2900 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
|
2901 { |
12423
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2902 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
|
2903 |
11150
7e9a1181206a
(svn r15497) -Fix (r15027): when trains crashed, AIEvent was created only for one train
smatz <smatz@openttd.org>
parents:
11149
diff
changeset
|
2904 /* 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
|
2905 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
|
2906 num = v->Crash(); |
18511
f1214da4c397
(svn r23355) -Codechange: rename all AI* to Script* (Rubidium)
truebrain <truebrain@openttd.org>
parents:
18472
diff
changeset
|
2907 AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_TRAIN)); |
18774
1fa19d70aea9
(svn r23622) -Add: a set of events to trigger in a GameScript
truebrain <truebrain@openttd.org>
parents:
18692
diff
changeset
|
2908 Game::NewEvent(new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_TRAIN)); |
12423
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2909 } |
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2910 |
698a97a3744a
(svn r16857) -Fix [FS#3036](r16652): crash when train partially in depot crashed
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
2911 /* 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
|
2912 * 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
|
2913 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
|
2914 |
7e9a1181206a
(svn r15497) -Fix (r15027): when trains crashed, AIEvent was created only for one train
smatz <smatz@openttd.org>
parents:
11149
diff
changeset
|
2915 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
|
2916 } |
7e9a1181206a
(svn r15497) -Fix (r15027): when trains crashed, AIEvent was created only for one train
smatz <smatz@openttd.org>
parents:
11149
diff
changeset
|
2917 |
18855
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2918 /** Temporary data storage for testing collisions. */ |
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
|
2919 struct TrainCollideChecker { |
18855
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2920 Train *v; ///< %Vehicle we are testing for collision. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2921 uint num; ///< Total 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
|
2922 }; |
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
|
2923 |
18855
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2924 /** |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2925 * Collision test function. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2926 * @param v %Train vehicle to test collision with. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2927 * @param data %Train being examined. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2928 * @return \c NULL (always continue search) |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2929 */ |
9775
c3caa51b9888
(svn r13912) -Codechange: remove some casts by returning the proper type instead of void*.
rubidium <rubidium@openttd.org>
parents:
9774
diff
changeset
|
2930 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
|
2931 { |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2932 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
|
2933 |
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
|
2934 /* 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
|
2935 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
|
2936 |
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
|
2937 /* 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
|
2938 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
|
2939 |
8281
a3736272d02a
(svn r11845) -Codechange: simplify train collision detection a bit
smatz <smatz@openttd.org>
parents:
8271
diff
changeset
|
2940 /* 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
|
2941 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
|
2942 |
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
|
2943 /* 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
|
2944 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
|
2945 |
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
|
2946 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
|
2947 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
|
2948 |
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
|
2949 /* 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
|
2950 * 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
|
2951 * 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
|
2952 * 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
|
2953 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
|
2954 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
|
2955 |
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
|
2956 /* Slower check using multiplication */ |
18446
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
2957 int min_diff = (Train::From(v)->gcache.cached_veh_length + 1) / 2 + (tcc->v->gcache.cached_veh_length + 1) / 2 - 1; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
2958 if (x_diff * x_diff + y_diff * y_diff > min_diff * min_diff) return NULL; |
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
|
2959 |
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
|
2960 /* 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
|
2961 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
|
2962 |
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
|
2963 /* 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
|
2964 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
|
2965 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
|
2966 |
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
|
2967 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
|
2968 } |
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
|
2969 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2970 /** |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2971 * 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
|
2972 * 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
|
2973 * 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
|
2974 * plays a sound. |
18855
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
2975 * @param v %Train to test. |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2976 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
2977 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
|
2978 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2979 /* 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
|
2980 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
|
2981 |
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
|
2982 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
|
2983 |
6150 | 2984 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
|
2985 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
|
2986 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
|
2987 |
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
|
2988 /* 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
|
2989 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
|
2990 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
|
2991 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
|
2992 } 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
|
2993 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
|
2994 } |
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
|
2995 |
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
|
2996 /* 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
|
2997 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
|
2998 |
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
|
2999 SetDParam(0, tcc.num); |
19383
0c6420024e22
(svn r24284) -Codechange: Remove NewsSubtypes and directly use NewsTypes and NewsFlag instead.
frosch <frosch@openttd.org>
parents:
19381
diff
changeset
|
3000 AddVehicleNewsItem(STR_NEWS_TRAIN_CRASH, NT_ACCIDENT, 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
|
3001 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3002 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
|
3003 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
|
3004 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
|
3005 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3006 |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
3007 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
|
3008 { |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
3009 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
|
3010 |
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
3011 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
|
3012 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
|
3013 |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
3014 /* 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
|
3015 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
|
3016 |
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
3017 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
|
3018 |
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
3019 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
|
3020 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3021 |
18446
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3022 /** |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3023 * Move a vehicle chain one movement stop forwards. |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3024 * @param v First vehicle to move. |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3025 * @param nomove Stop moving this and all following vehicles. |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3026 * @param reverse Set to false to not execute the vehicle reversing. This does not change any other logic. |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3027 * @return True if the vehicle could be moved forward, false otherwise. |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3028 */ |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3029 bool TrainController(Train *v, Vehicle *nomove, bool reverse) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3030 { |
12085
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
3031 Train *first = v->First(); |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
3032 Train *prev; |
12085
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
3033 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
|
3034 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3035 /* 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
|
3036 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
|
3037 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
|
3038 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
|
3039 |
6153 | 3040 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
|
3041 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
|
3042 /* Not inside tunnel */ |
6152 | 3043 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
|
3044 /* 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
|
3045 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
|
3046 /* 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
|
3047 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
|
3048 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
|
3049 } 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
|
3050 /* 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
|
3051 |
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
|
3052 /* Reverse when we are at the end of the track already, do not move to the new position */ |
18446
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3053 if (v->IsFrontEngine() && !TrainCheckIfLineEnds(v, reverse)) 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
|
3054 |
6150 | 3055 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
|
3056 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
|
3057 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
|
3058 } |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
3059 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
|
3060 /* 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
|
3061 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
|
3062 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3063 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3064 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3065 /* 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
|
3066 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3067 /* 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
|
3068 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
|
3069 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
|
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 /* 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
|
3072 * 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
|
3073 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
|
3074 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
|
3075 |
0a524ed2b87b
(svn r12532) -Cleanup: Replace two tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8793
diff
changeset
|
3076 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
|
3077 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
|
3078 |
9e46ac001a8c
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch <frosch@openttd.org>
parents:
8614
diff
changeset
|
3079 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
|
3080 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
|
3081 /* 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
|
3082 * 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
|
3083 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
|
3084 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3085 |
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
|
3086 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
|
3087 |
15820
59fd8293b2ee
(svn r20499) -Doc: Spelling fixes, and one doxygen comment addition.
alberth <alberth@openttd.org>
parents:
15763
diff
changeset
|
3088 /* 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
|
3089 * 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
|
3090 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
|
3091 |
6150 | 3092 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
|
3093 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
|
3094 /* 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
|
3095 * 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
|
3096 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
|
3097 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
|
3098 |
15362
834b4f9842c2
(svn r20005) -Codechange: Enumify force_proceed.
frosch <frosch@openttd.org>
parents:
15351
diff
changeset
|
3099 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
|
3100 /* 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
|
3101 * 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
|
3102 * 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
|
3103 * 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
|
3104 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
|
3105 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
|
3106 !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
|
3107 /* 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
|
3108 * entered via the back. */ |
15362
834b4f9842c2
(svn r20005) -Codechange: Enumify force_proceed.
frosch <frosch@openttd.org>
parents:
15351
diff
changeset
|
3109 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
|
3110 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
|
3111 } |
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
|
3112 } |
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
|
3113 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3114 /* 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
|
3115 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
|
3116 /* 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
|
3117 Trackdir i = FindFirstTrackdir(trackdirbits); |
6151 | 3118 |
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
|
3119 /* Don't handle stuck trains here. */ |
18446
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3120 if (HasBit(v->flags, VRF_TRAIN_STUCK)) return false; |
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
|
3121 |
6151 | 3122 if (!HasSignalOnTrackdir(gp.new_tile, ReverseTrackdir(i))) { |
3123 v->cur_speed = 0; | |
3124 v->subspeed = 0; | |
3125 v->progress = 255 - 100; | |
18446
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3126 if (!_settings_game.pf.reverse_at_signals || ++v->wait_counter < _settings_game.pf.wait_oneway_signal * 20) return false; |
6151 | 3127 } else if (HasSignalOnTrackdir(gp.new_tile, i)) { |
3128 v->cur_speed = 0; | |
3129 v->subspeed = 0; | |
6491
696f0e1b046e
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium <rubidium@openttd.org>
parents:
6490
diff
changeset
|
3130 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
|
3131 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
|
3132 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
|
3133 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
|
3134 |
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
|
3135 exitdir = ReverseDiagDir(exitdir); |
6151 | 3136 |
3137 /* check if a train is waiting on the other side */ | |
18446
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3138 if (!HasVehicleOnPos(o_tile, &exitdir, &CheckTrainAtSignal)) return false; |
6151 | 3139 } |
3140 } | |
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
|
3141 |
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
|
3142 /* 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
|
3143 * 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
|
3144 * 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
|
3145 * 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
|
3146 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
|
3147 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
|
3148 v->wait_counter = 0; |
18446
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3149 return false; |
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
|
3150 } |
6151 | 3151 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
|
3152 } 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
|
3153 TryReserveRailTrack(gp.new_tile, TrackBitsToTrack(chosen_track)); |
6151 | 3154 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3155 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3156 /* 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
|
3157 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
|
3158 /* 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
|
3159 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
|
3160 /* 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
|
3161 * 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
|
3162 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
|
3163 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
|
3164 } 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
|
3165 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
|
3166 } |
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
|
3167 } else { |
11690
eb5d9897c030
(svn r16075) -Fix (r15792)[FS#2844]: Mixed up TRACK_BIT_X/Y.
frosch <frosch@openttd.org>
parents:
11677
diff
changeset
|
3168 /* 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
|
3169 * 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
|
3170 * 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
|
3171 * 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
|
3172 * 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
|
3173 * 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
|
3174 */ |
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
|
3175 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
|
3176 {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
|
3177 {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
|
3178 {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
|
3179 {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
|
3180 }; |
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
|
3181 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
|
3182 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
|
3183 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
|
3184 } |
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
|
3185 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
|
3186 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3187 |
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
|
3188 /* 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
|
3189 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
|
3190 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
|
3191 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
|
3192 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
|
3193 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3194 /* Update XY to reflect the entrance to the new tile, and select the direction to use */ |
6150 | 3195 const byte *b = _initial_tile_subcoord[FIND_FIRST_BIT(chosen_track)][enterdir]; |
3196 gp.x = (gp.x & ~0xF) | b[0]; | |
3197 gp.y = (gp.y & ~0xF) | b[1]; | |
3198 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
|
3199 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3200 /* Call the landscape function and tell it that the vehicle entered the tile */ |
6150 | 3201 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
|
3202 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
|
3203 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
|
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 |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
3206 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
|
3207 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
|
3208 Trackdir tdir = TrackDirectionToTrackdir(track, chosen_dir); |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
3209 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
|
3210 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
|
3211 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
|
3212 } |
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
|
3213 |
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
|
3214 /* 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
|
3215 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
|
3216 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3217 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
|
3218 |
6154 | 3219 if (GetTileRailType(gp.new_tile) != GetTileRailType(gp.old_tile)) { |
18923
429c5d53bda8
(svn r23773) -Change: [NewGRF] Update all cached train properties if a train vehicle enters a new railtype.
michi_cc <michi_cc@openttd.org>
parents:
18895
diff
changeset
|
3220 v->First()->ConsistChanged(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
|
3221 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3222 |
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
|
3223 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
|
3224 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
|
3225 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3226 |
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
|
3227 /* 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
|
3228 * 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
|
3229 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
|
3230 |
12085
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
3231 if (chosen_dir != v->direction) { |
14406
5f93639271ee
(svn r18963) -Codechange: Give AccelerationModel a generical name.
terkhen <terkhen@openttd.org>
parents:
14384
diff
changeset
|
3232 if (prev == NULL && _settings_game.vehicle.train_acceleration_model == AM_ORIGINAL) { |
18999
081eb943326c
(svn r23855) -Fix [FS#5007]: out of bounds read for slowdown parameter caused desync when railtype >= 4, vehicles were fast, and the original acceleration model was used
rubidium <rubidium@openttd.org>
parents:
18931
diff
changeset
|
3233 const AccelerationSlowdownParams *asp = &_accel_slowdown[GetRailTypeInfo(v->railtype)->acceleration_type]; |
12085
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
3234 DirDiff diff = DirDifference(v->direction, chosen_dir); |
18999
081eb943326c
(svn r23855) -Fix [FS#5007]: out of bounds read for slowdown parameter caused desync when railtype >= 4, vehicles were fast, and the original acceleration model was used
rubidium <rubidium@openttd.org>
parents:
18931
diff
changeset
|
3235 v->cur_speed -= (diff == DIRDIFF_45RIGHT || diff == DIRDIFF_45LEFT ? asp->small_turn : asp->large_turn) * v->cur_speed >> 8; |
12085
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
3236 } |
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
3237 direction_changed = true; |
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
3238 v->direction = chosen_dir; |
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
3239 } |
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
|
3240 |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
3241 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
|
3242 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
|
3243 |
15820
59fd8293b2ee
(svn r20499) -Doc: Spelling fixes, and one doxygen comment addition.
alberth <alberth@openttd.org>
parents:
15763
diff
changeset
|
3244 /* 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
|
3245 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
|
3246 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
|
3247 |
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
|
3248 /* 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
|
3249 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
|
3250 } |
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
|
3251 |
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
|
3252 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
|
3253 /* 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
|
3254 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
|
3255 } |
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 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3257 } else { |
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
|
3258 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
|
3259 /* Perform look-ahead on tunnel exit. */ |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
3260 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
|
3261 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
|
3262 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
|
3263 } |
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
|
3264 /* 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
|
3265 * 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
|
3266 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
|
3267 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
|
3268 } |
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
|
3269 } 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
|
3270 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
|
3271 v->y_pos = gp.y; |
18864
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18855
diff
changeset
|
3272 VehicleUpdatePosition(v); |
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18855
diff
changeset
|
3273 if ((v->vehstatus & VS_HIDDEN) == 0) VehicleUpdateViewport(v, 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
|
3274 continue; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3275 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3276 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3277 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3278 /* 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
|
3279 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
|
3280 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3281 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
|
3282 v->y_pos = gp.y; |
18865
ab93092e1cb2
(svn r23714) -Codechange: don't mix Viewport with non-viewport code
truebrain <truebrain@openttd.org>
parents:
18864
diff
changeset
|
3283 VehicleUpdatePosition(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
|
3284 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3285 /* update the Z position of the vehicle */ |
18272
3ebab55c5495
(svn r23108) -Codechange: more uint -> int / byte -> int conversions for Z related variables
rubidium <rubidium@openttd.org>
parents:
18255
diff
changeset
|
3286 int 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
|
3287 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3288 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
|
3289 /* 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
|
3290 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
|
3291 } |
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
|
3292 |
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
|
3293 if (update_signals_crossing) { |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
3294 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
|
3295 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
|
3296 /* 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
|
3297 * 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
|
3298 * 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
|
3299 * 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
|
3300 * 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
|
3301 * 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
|
3302 * 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
|
3303 * 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
|
3304 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
|
3305 !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
|
3306 !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
|
3307 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
|
3308 } |
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
|
3309 } |
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
|
3310 } |
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
|
3311 |
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
|
3312 /* 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
|
3313 * (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
|
3314 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
|
3315 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
|
3316 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
|
3317 } |
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
|
3318 } |
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
|
3319 |
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
|
3320 /* 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
|
3321 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
|
3322 } |
12085
067bb705b7bc
(svn r16494) -Codechange: cache train's speed limit caused by curves
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
3323 |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
3324 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
|
3325 |
18446
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3326 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
|
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 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
|
3329 /* 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
|
3330 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
|
3331 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3332 reverse_train_direction: |
18446
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3333 if (reverse) { |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3334 v->wait_counter = 0; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3335 v->cur_speed = 0; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3336 v->subspeed = 0; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3337 ReverseTrainDirection(v); |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3338 } |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3339 |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3340 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
|
3341 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3342 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
3343 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
3344 * 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
|
3345 * @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
|
3346 * @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
|
3347 * @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
|
3348 */ |
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
|
3349 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
|
3350 { |
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
|
3351 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
|
3352 |
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
|
3353 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
|
3354 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
|
3355 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
|
3356 /* 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
|
3357 *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
|
3358 } 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
|
3359 *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
|
3360 } |
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
|
3361 } |
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
|
3362 |
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
|
3363 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
|
3364 } |
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
|
3365 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3366 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3367 * 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
|
3368 * 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
|
3369 * 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
|
3370 * 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
|
3371 * @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
|
3372 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
3373 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
|
3374 { |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
3375 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
|
3376 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3377 /* 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
|
3378 * *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
|
3379 * 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
|
3380 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
|
3381 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
|
3382 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
|
3383 |
10493
5531e81401ee
(svn r14748) -Codechange: unduplicate window updating when deleting vehicles.
rubidium <rubidium@openttd.org>
parents:
10492
diff
changeset
|
3384 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
|
3385 /* 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
|
3386 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
|
3387 /* 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
|
3388 * 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
|
3389 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
|
3390 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
|
3391 } |
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
|
3392 } |
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
|
3393 |
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
|
3394 /* '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
|
3395 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
|
3396 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
|
3397 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
|
3398 |
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
|
3399 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
|
3400 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
|
3401 |
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
|
3402 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
|
3403 /* 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
|
3404 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
|
3405 } |
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
|
3406 |
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
|
3407 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
|
3408 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
|
3409 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
|
3410 |
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
|
3411 /* 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
|
3412 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
|
3413 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
|
3414 |
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
|
3415 /* 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
|
3416 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
|
3417 Track t; |
5fa5a4d1f409
(svn r19792) -Change: use the typed FOR_EACH_SET_BIT for Tracks (adf88)
rubidium <rubidium@openttd.org>
parents:
15156
diff
changeset
|
3418 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
|
3419 } |
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 |
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
|
3421 /* 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
|
3422 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
|
3423 |
8257
38d56fa7b6f7
(svn r11821) -Fix (r11802): 'optimization assert' when removing crashed wagon in some cases
smatz <smatz@openttd.org>
parents:
8256
diff
changeset
|
3424 /* 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
|
3425 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
|
3426 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
|
3427 } 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
|
3428 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
|
3429 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3430 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3431 |
17236
2401b5b905f3
(svn r21976) -Doc: Document several crash handling functions.
alberth <alberth@openttd.org>
parents:
17227
diff
changeset
|
3432 /** |
2401b5b905f3
(svn r21976) -Doc: Document several crash handling functions.
alberth <alberth@openttd.org>
parents:
17227
diff
changeset
|
3433 * 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
|
3434 * @param v First crashed vehicle. |
2401b5b905f3
(svn r21976) -Doc: Document several crash handling functions.
alberth <alberth@openttd.org>
parents:
17227
diff
changeset
|
3435 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
3436 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
|
3437 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3438 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
|
3439 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
|
3440 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3441 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3442 do { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3443 /* 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
|
3444 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
|
3445 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
|
3446 v->UpdateDeltaXY(v->direction); |
18244
8f6022f41538
(svn r23080) -Feature: [NewGRF] Use variable 10 to enable vehicle GRFs to draw different sprites on the map and in various GUIs.
frosch <frosch@openttd.org>
parents:
18239
diff
changeset
|
3447 v->cur_image = v->GetImage(v->direction, EIT_ON_MAP); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3448 /* 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
|
3449 * 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
|
3450 * the bridge in that case */ |
18865
ab93092e1cb2
(svn r23714) -Codechange: don't mix Viewport with non-viewport code
truebrain <truebrain@openttd.org>
parents:
18864
diff
changeset
|
3451 if (v->track != TRACK_BIT_WORMHOLE) { |
ab93092e1cb2
(svn r23714) -Codechange: don't mix Viewport with non-viewport code
truebrain <truebrain@openttd.org>
parents:
18864
diff
changeset
|
3452 VehicleUpdatePosition(v); |
ab93092e1cb2
(svn r23714) -Codechange: don't mix Viewport with non-viewport code
truebrain <truebrain@openttd.org>
parents:
18864
diff
changeset
|
3453 v->UpdateInclination(false, false); |
ab93092e1cb2
(svn r23714) -Codechange: don't mix Viewport with non-viewport code
truebrain <truebrain@openttd.org>
parents:
18864
diff
changeset
|
3454 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3455 } |
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
|
3456 } 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
|
3457 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3458 |
17236
2401b5b905f3
(svn r21976) -Doc: Document several crash handling functions.
alberth <alberth@openttd.org>
parents:
17227
diff
changeset
|
3459 /** |
2401b5b905f3
(svn r21976) -Doc: Document several crash handling functions.
alberth <alberth@openttd.org>
parents:
17227
diff
changeset
|
3460 * Handle a crashed train. |
2401b5b905f3
(svn r21976) -Doc: Document several crash handling functions.
alberth <alberth@openttd.org>
parents:
17227
diff
changeset
|
3461 * @param v First train vehicle. |
2401b5b905f3
(svn r21976) -Doc: Document several crash handling functions.
alberth <alberth@openttd.org>
parents:
17227
diff
changeset
|
3462 * @return %Vehicle chain still exists. |
2401b5b905f3
(svn r21976) -Doc: Document several crash handling functions.
alberth <alberth@openttd.org>
parents:
17227
diff
changeset
|
3463 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
3464 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
|
3465 { |
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
|
3466 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
|
3467 |
5993
2498be7c7e94
(svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium <rubidium@openttd.org>
parents:
5992
diff
changeset
|
3468 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
|
3469 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
|
3470 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3471 |
6150 | 3472 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
|
3473 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
|
3474 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
|
3475 |
6150 | 3476 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
|
3477 do { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3478 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
|
3479 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
|
3480 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3481 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
|
3482 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
|
3483 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
|
3484 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
|
3485 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
|
3486 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3487 } |
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
|
3488 } 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
|
3489 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3490 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3491 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
|
3492 |
8969
01cc3ee6ecb1
(svn r12761) -Codechange: lots of minor whitespace coding style fixes around operators.
rubidium <rubidium@openttd.org>
parents:
8962
diff
changeset
|
3493 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
|
3494 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
|
3495 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
|
3496 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
|
3497 } |
11970
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3498 |
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3499 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
|
3500 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3501 |
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
|
3502 /** 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
|
3503 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
|
3504 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
|
3505 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3506 |
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 |
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
|
3508 /** |
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
|
3509 * 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
|
3510 * |
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
|
3511 * @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
|
3512 * @param signal not line end, just a red signal |
18446
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3513 * @param reverse Set to false to not execute the vehicle reversing. This does not change any other logic. |
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 * @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
|
3515 */ |
18446
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3516 static bool TrainApproachingLineEnd(Train *v, bool signal, bool reverse) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3517 { |
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
|
3518 /* Calc position within the current tile */ |
6150 | 3519 uint x = v->x_pos & 0xF; |
3520 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
|
3521 |
8312
f6764781d2eb
(svn r11877) -Fix: another way to crash competitors' train in a station
smatz <smatz@openttd.org>
parents:
8305
diff
changeset
|
3522 /* 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
|
3523 * 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
|
3524 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
|
3525 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
|
3526 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
|
3527 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
|
3528 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
|
3529 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
|
3530 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
|
3531 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
|
3532 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
|
3533 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3534 |
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
|
3535 /* 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
|
3536 * 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
|
3537 * location is based on their center, use half a vehicle's length as offset. |
18446
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3538 * Multiply the half-length by two for straight directions to compensate that |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3539 * we only get odd x offsets there. */ |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3540 if (!signal && x + (v->gcache.cached_veh_length + 1) / 2 * (IsDiagonalDirection(v->direction) ? 1 : 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
|
3541 /* 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
|
3542 v->cur_speed = 0; |
18446
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3543 if (reverse) ReverseTrainDirection(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
|
3544 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
|
3545 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3546 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
3547 /* 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
|
3548 v->vehstatus |= VS_TRAIN_SLOWING; |
6150 | 3549 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
|
3550 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
|
3551 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3552 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
|
3553 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3554 |
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
|
3555 |
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
|
3556 /** |
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
|
3557 * 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
|
3558 * @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
|
3559 * @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
|
3560 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
3561 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
|
3562 { |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3563 /* 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
|
3564 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
|
3565 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3566 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
|
3567 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3568 /* 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
|
3569 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
|
3570 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
|
3571 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
|
3572 } |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3573 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3574 /* 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
|
3575 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
|
3576 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
|
3577 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
|
3578 } |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3579 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3580 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
|
3581 } |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3582 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3583 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3584 /** |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3585 * 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
|
3586 * (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
|
3587 * @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
|
3588 * @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
|
3589 * @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
|
3590 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
3591 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
|
3592 { |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
3593 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
|
3594 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
|
3595 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3596 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
|
3597 |
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
|
3598 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
|
3599 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
|
3600 |
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
|
3601 /* 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
|
3602 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
|
3603 !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
|
3604 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
|
3605 } |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3606 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3607 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
|
3608 } |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3609 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3610 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3611 /** |
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
|
3612 * 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
|
3613 * |
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
|
3614 * @param v vehicle we are checking |
18446
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3615 * @param reverse Set to false to not execute the vehicle reversing. This does not change any other logic. |
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
|
3616 * @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
|
3617 */ |
18446
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3618 static bool TrainCheckIfLineEnds(Train *v, bool reverse) |
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
|
3619 { |
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
|
3620 /* 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
|
3621 |
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
|
3622 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
|
3623 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
|
3624 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
|
3625 |
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
|
3626 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
|
3627 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
|
3628 } 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
|
3629 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
|
3630 } |
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
|
3631 |
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
|
3632 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
|
3633 |
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
|
3634 /* 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
|
3635 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
|
3636 /* 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
|
3637 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
|
3638 |
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
|
3639 /* 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
|
3640 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
|
3641 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
|
3642 |
0a524ed2b87b
(svn r12532) -Cleanup: Replace two tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8793
diff
changeset
|
3643 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
|
3644 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
|
3645 |
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
|
3646 /* 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
|
3647 |
8482
dd2dbdff6d0d
(svn r12057) -Fix: slowdown train when approaching 90deg turn when 90deg turns are forbidden
smatz <smatz@openttd.org>
parents:
8467
diff
changeset
|
3648 /* 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
|
3649 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
|
3650 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
|
3651 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
|
3652 } |
dd2dbdff6d0d
(svn r12057) -Fix: slowdown train when approaching 90deg turn when 90deg turns are forbidden
smatz <smatz@openttd.org>
parents:
8467
diff
changeset
|
3653 |
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
|
3654 /* 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
|
3655 if (bits == TRACK_BIT_NONE || !CheckCompatibleRail(v, tile)) { |
18446
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3656 return TrainApproachingLineEnd(v, false, reverse); |
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
|
3657 } |
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
|
3658 |
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
|
3659 /* approaching red signal */ |
18446
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18337
diff
changeset
|
3660 if ((trackdirbits & red_signals) != 0) return TrainApproachingLineEnd(v, true, reverse); |
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
|
3661 |
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
|
3662 /* 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
|
3663 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
|
3664 |
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
|
3665 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
|
3666 } |
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
|
3667 |
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
|
3668 |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
3669 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
|
3670 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3671 /* 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
|
3672 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
|
3673 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
|
3674 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3675 |
15362
834b4f9842c2
(svn r20005) -Codechange: Enumify force_proceed.
frosch <frosch@openttd.org>
parents:
15351
diff
changeset
|
3676 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
|
3677 ClrBit(v->flags, VRF_TRAIN_STUCK); |
18692
90d395fc678d
(svn r23540) -Codechange: unify and document vehicle widgets
rubidium <rubidium@openttd.org>
parents:
18627
diff
changeset
|
3678 SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP); |
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
|
3679 } |
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 /* 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
|
3682 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
|
3683 |
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
|
3684 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
|
3685 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
|
3686 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3687 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3688 /* 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
|
3689 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
|
3690 |
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
|
3691 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
|
3692 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
|
3693 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
|
3694 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
|
3695 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
|
3696 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
|
3697 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
|
3698 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
|
3699 } 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
|
3700 /* 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
|
3701 * 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
|
3702 * 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
|
3703 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
|
3704 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
|
3705 |
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
|
3706 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
|
3707 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
|
3708 } |
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
|
3709 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
|
3710 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3711 |
6594
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6593
diff
changeset
|
3712 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
|
3713 |
11970
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3714 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
|
3715 |
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3716 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
|
3717 |
16511
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16510
diff
changeset
|
3718 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
|
3719 |
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
|
3720 /* 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
|
3721 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
|
3722 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
|
3723 } |
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
|
3724 |
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
|
3725 /* 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
|
3726 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
|
3727 ++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
|
3728 |
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
|
3729 /* 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
|
3730 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
|
3731 |
15362
834b4f9842c2
(svn r20005) -Codechange: Enumify force_proceed.
frosch <frosch@openttd.org>
parents:
15351
diff
changeset
|
3732 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
|
3733 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
|
3734 /* 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
|
3735 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
|
3736 |
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
|
3737 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
|
3738 /* 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
|
3739 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
|
3740 SetDParam(0, v->index); |
19381
f37c5813696b
(svn r24282) -Codechange: Add AddVehicleAdviceNewsItem function to preemptively deduplicate code.
frosch <frosch@openttd.org>
parents:
19349
diff
changeset
|
3741 AddVehicleAdviceNewsItem(STR_NEWS_TRAIN_IS_STUCK, v->index); |
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
|
3742 } |
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
|
3743 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
|
3744 } |
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
|
3745 /* 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
|
3746 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
|
3747 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
|
3748 v->wait_counter = 0; |
18692
90d395fc678d
(svn r23540) -Codechange: unify and document vehicle widgets
rubidium <rubidium@openttd.org>
parents:
18627
diff
changeset
|
3749 SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP); |
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
|
3750 } |
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
|
3751 } |
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
|
3752 |
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
|
3753 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
|
3754 v->current_order.Free(); |
18692
90d395fc678d
(svn r23540) -Codechange: unify and document vehicle widgets
rubidium <rubidium@openttd.org>
parents:
18627
diff
changeset
|
3755 SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP); |
11970
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3756 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
|
3757 } |
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
|
3758 |
14284
fc532d11eb85
(svn r18836) -Codechange: make TrainUpdateSpeed a class function and update some comments (Terkhen)
rubidium <rubidium@openttd.org>
parents:
14261
diff
changeset
|
3759 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
|
3760 |
916b061b84a0
(svn r11996) -Fix [FS#1706]: update train statusbar when stopping from zero speed
smatz <smatz@openttd.org>
parents:
8390
diff
changeset
|
3761 /* 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
|
3762 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
|
3763 /* 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
|
3764 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
|
3765 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
|
3766 } |
916b061b84a0
(svn r11996) -Fix [FS#1706]: update train statusbar when stopping from zero speed
smatz <smatz@openttd.org>
parents:
8390
diff
changeset
|
3767 |
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
|
3768 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
|
3769 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
|
3770 /* 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
|
3771 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
|
3772 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3773 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
|
3774 /* 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
|
3775 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
|
3776 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
|
3777 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
|
3778 /* 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
|
3779 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
|
3780 /* 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
|
3781 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
|
3782 |
11701
362680cbb585
(svn r16087) -Fix (r16079): slow trains wouldn't crash into eachother anymore
rubidium <rubidium@openttd.org>
parents:
11694
diff
changeset
|
3783 /* 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
|
3784 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
|
3785 |
362680cbb585
(svn r16087) -Fix (r16079): slow trains wouldn't crash into eachother anymore
rubidium <rubidium@openttd.org>
parents:
11694
diff
changeset
|
3786 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
|
3787 /* 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
|
3788 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
|
3789 (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
|
3790 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
|
3791 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
|
3792 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
|
3793 } |
11701
362680cbb585
(svn r16087) -Fix (r16079): slow trains wouldn't crash into eachother anymore
rubidium <rubidium@openttd.org>
parents:
11694
diff
changeset
|
3794 } |
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
|
3795 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
|
3796 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3797 |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
3798 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
|
3799 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
|
3800 |
12666
0275245c6c62
(svn r17121) -Fix [FS#3060]: Update vehicle position cache when the vehicle sprite changes.
frosch <frosch@openttd.org>
parents:
12635
diff
changeset
|
3801 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
|
3802 } |
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
|
3803 |
10641
94cbc9a0158b
(svn r14943) -Cleanup: remove some rogue spaces/replace some rogue tabs with spaces
rubidium <rubidium@openttd.org>
parents:
10589
diff
changeset
|
3804 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
|
3805 |
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3806 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
|
3807 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3808 |
18855
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
3809 /** |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
3810 * Get running cost for the train consist. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
3811 * @return Yearly running costs. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
3812 */ |
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
|
3813 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
|
3814 { |
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
|
3815 Money cost = 0; |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
3816 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
|
3817 |
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
|
3818 do { |
18238
3141f1ed78eb
(svn r23074) -Codechange: Add Vehicle::GetEngine() to simplify code.
frosch <frosch@openttd.org>
parents:
18159
diff
changeset
|
3819 const Engine *e = v->GetEngine(); |
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
|
3820 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
|
3821 |
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
|
3822 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
|
3823 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
|
3824 |
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
|
3825 /* 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
|
3826 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
|
3827 |
18239
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18238
diff
changeset
|
3828 cost += GetPrice(e->u.rail.running_cost_class, cost_factor, e->GetGRF()); |
12306
d0ff55a976ad
(svn r16723) -Codechange: make GetNextArticPart(), GetLastEnginePart(), GetNextVehicle(), GetPrevVehicle(), GetNextUnit(), GetPrevUnit() members of Train
smatz <smatz@openttd.org>
parents:
12303
diff
changeset
|
3829 } 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
|
3830 |
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
|
3831 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
|
3832 } |
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
|
3833 |
18855
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
3834 /** |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
3835 * Update train vehicle data for a tick. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
3836 * @return True if the vehicle still exists, false if it has ceased to exist (front of consists only). |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
3837 */ |
11970
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3838 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
|
3839 { |
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
|
3840 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
|
3841 |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
3842 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
|
3843 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
|
3844 |
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
|
3845 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
|
3846 |
11970
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3847 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
|
3848 |
11970
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3849 return TrainLocoHandler(this, true); |
12301
218a41d3d557
(svn r16718) -Codechange: make IsFreeWagon() member of Train
smatz <smatz@openttd.org>
parents:
12300
diff
changeset
|
3850 } 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
|
3851 /* 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
|
3852 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
|
3853 delete this; |
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3854 return false; |
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3855 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3856 } |
11970
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3857 |
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
3858 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
|
3859 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3860 |
18855
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
3861 /** |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
3862 * Check whether a train needs serivce, and if so, find a depot or service it. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
3863 * @return v %Train to check. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
3864 */ |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11978
diff
changeset
|
3865 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
|
3866 { |
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
|
3867 if (Company::Get(v->owner)->settings.vehicle.servint_trains == 0 || !v->NeedsAutomaticServicing()) return; |
19481
b271f4f060fa
(svn r24384) -Fix [FS#5188-ish]: Make IsInDepot() functions behave consistent across vehicle types and add IsChainInDepot instead, if that is what shall be checked.
frosch <frosch@openttd.org>
parents:
19479
diff
changeset
|
3868 if (v->IsChainInDepot()) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3869 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
|
3870 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3871 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3872 |
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
|
3873 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
|
3874 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
|
3875 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
|
3876 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
|
3877 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
|
3878 } |
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
|
3879 |
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
|
3880 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
|
3881 /* 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
|
3882 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
|
3883 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
|
3884 /* 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
|
3885 * 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
|
3886 * schedule? */ |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8832
diff
changeset
|
3887 v->current_order.MakeDummy(); |
18692
90d395fc678d
(svn r23540) -Codechange: unify and document vehicle widgets
rubidium <rubidium@openttd.org>
parents:
18627
diff
changeset
|
3888 SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3889 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3890 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3891 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3892 |
13001
c2298b1d3f83
(svn r17495) -Codechange: replace 'Depot::Get(GetDepotIndex(tile))->index' with GetDepotIndex(tile)
rubidium <rubidium@openttd.org>
parents:
12860
diff
changeset
|
3893 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
|
3894 |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8832
diff
changeset
|
3895 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
|
3896 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
|
3897 !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
|
3898 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3899 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3900 |
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
|
3901 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
|
3902 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
|
3903 v->dest_tile = tfdd.tile; |
18692
90d395fc678d
(svn r23540) -Codechange: unify and document vehicle widgets
rubidium <rubidium@openttd.org>
parents:
18627
diff
changeset
|
3904 SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3905 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3906 |
18855
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
3907 /** Update day counters of the train vehicle. */ |
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
|
3908 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
|
3909 { |
18007
c7a5373f1a03
(svn r22816) -Feature(ette): [NewGRF] Also age wagons and articulated parts.
frosch <frosch@openttd.org>
parents:
17909
diff
changeset
|
3910 AgeVehicle(this); |
c7a5373f1a03
(svn r22816) -Feature(ette): [NewGRF] Also age wagons and articulated parts.
frosch <frosch@openttd.org>
parents:
17909
diff
changeset
|
3911 |
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
|
3912 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
|
3913 |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12240
diff
changeset
|
3914 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
|
3915 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
|
3916 |
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
|
3917 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
|
3918 |
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
|
3919 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
|
3920 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3921 /* update destination */ |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8832
diff
changeset
|
3922 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
|
3923 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
|
3924 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
|
3925 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3926 |
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
|
3927 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
|
3928 /* running costs */ |
10744
0118ca646690
(svn r15077) -Codechange: enumify DAYS_IN_YEAR and DAYS_IN_LEAP_YEAR
smatz <smatz@openttd.org>
parents:
10696
diff
changeset
|
3929 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
|
3930 |
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
|
3931 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
|
3932 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
|
3933 |
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
|
3934 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
|
3935 |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
13001
diff
changeset
|
3936 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
|
3937 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
|
3938 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3939 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3940 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3941 |
18855
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
3942 /** |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
3943 * Get the tracks of the train vehicle. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
3944 * @return Current tracks of the vehicle. |
a0d7e20ebafe
(svn r23704) -Doc: Doxygen comment fixes and additions.
alberth <alberth@openttd.org>
parents:
18839
diff
changeset
|
3945 */ |
11976
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
3946 Trackdir Train::GetVehicleTrackdir() const |
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
3947 { |
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
3948 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
|
3949 |
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
|
3950 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
|
3951 /* 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
|
3952 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
|
3953 } |
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
3954 |
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
|
3955 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
|
3956 /* 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
|
3957 return DiagDirToDiagTrackdir(DirToDiagDir(this->direction)); |
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
3958 } |
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
3959 |
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
|
3960 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
|
3961 } |