Mercurial > hg > openttd
annotate src/train_cmd.cpp @ 10499:45ca88a8de7d draft
(svn r14754) -Codechange: get rid of _cmd_text and just pass it as (optional) parameter.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Sun, 28 Dec 2008 14:37:19 +0000 |
parents | 5531e81401ee |
children | 21e2aec5a241 |
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 |
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
|
3 /** @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
|
4 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
5 #include "stdafx.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
6 #include "openttd.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
7 #include "bridge_map.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
8 #include "debug.h" |
8119
b6ec923e9fa8
(svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium <rubidium@openttd.org>
parents:
8116
diff
changeset
|
9 #include "tile_cmd.h" |
6453
666fc3ef3174
(svn r9609) -Codechange: Move some function prototypes out of functions.h and into landscape.h, and add a few where they didn't exist.
maedhros <maedhros@openttd.org>
parents:
6422
diff
changeset
|
10 #include "landscape.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
|
11 #include "gui.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
12 #include "station_map.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
13 #include "tunnel_map.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" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
16 #include "pathfind.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
17 #include "npf.h" |
8785
2a8950a812dc
(svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium <rubidium@openttd.org>
parents:
8784
diff
changeset
|
18 #include "station_base.h" |
8763
d6e363672edb
(svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium <rubidium@openttd.org>
parents:
8712
diff
changeset
|
19 #include "news_func.h" |
8786
e2d4956b7251
(svn r12490) -Codechange: rename engine.h to engine_func.h and remove unneeded inclusions of engine.h and/or replace them with engine_type.h.
rubidium <rubidium@openttd.org>
parents:
8785
diff
changeset
|
20 #include "engine_func.h" |
9070
11b5b3f4175d
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents:
9041
diff
changeset
|
21 #include "engine_base.h" |
10208
39cf8eebfda5
(svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium <rubidium@openttd.org>
parents:
10207
diff
changeset
|
22 #include "company_func.h" |
39cf8eebfda5
(svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium <rubidium@openttd.org>
parents:
10207
diff
changeset
|
23 #include "company_base.h" |
8962
322e2779f67a
(svn r12754) -Codechange: split depot.h into depot_map.h, depot_func.h and depot_base.h and remove quite a lot of unneeded (before this) includes of depot.h.
rubidium <rubidium@openttd.org>
parents:
8961
diff
changeset
|
24 #include "depot_base.h" |
322e2779f67a
(svn r12754) -Codechange: split depot.h into depot_map.h, depot_func.h and depot_base.h and remove quite a lot of unneeded (before this) includes of depot.h.
rubidium <rubidium@openttd.org>
parents:
8961
diff
changeset
|
25 #include "depot_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
|
26 #include "waypoint.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
27 #include "vehicle_gui.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
28 #include "train.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
29 #include "bridge.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
30 #include "newgrf_callbacks.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
31 #include "newgrf_engine.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
32 #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
|
33 #include "newgrf_text.h" |
8100
6d739a5490a9
(svn r11661) -Codechange: some header reworks in order to try to reduce the compile time of OpenTTD by reduce the amount of circular-ish dependencies.
rubidium <rubidium@openttd.org>
parents:
8088
diff
changeset
|
34 #include "direction_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
|
35 #include "yapf/yapf.h" |
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
|
36 #include "yapf/follow_track.hpp" |
6091
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
5998
diff
changeset
|
37 #include "cargotype.h" |
6643
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6608
diff
changeset
|
38 #include "group.h" |
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
|
39 #include "table/sprites.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
|
40 #include "tunnelbridge_map.h" |
8114
2d6af5d7a142
(svn r11675) -Codechange: split the string types from the string functions.
rubidium <rubidium@openttd.org>
parents:
8108
diff
changeset
|
41 #include "strings_func.h" |
8131
e300ac8001ae
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium <rubidium@openttd.org>
parents:
8119
diff
changeset
|
42 #include "functions.h" |
e300ac8001ae
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium <rubidium@openttd.org>
parents:
8119
diff
changeset
|
43 #include "window_func.h" |
8140
fb8a05d579da
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium <rubidium@openttd.org>
parents:
8139
diff
changeset
|
44 #include "date_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
|
45 #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
|
46 #include "sound_func.h" |
8238
e9d8b0764f38
(svn r11802) -Fix [FS#716]: do not crash trains when leaving depot to a very long track
smatz <smatz@openttd.org>
parents:
8236
diff
changeset
|
47 #include "signal_func.h" |
8211
165064de4629
(svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium <rubidium@openttd.org>
parents:
8197
diff
changeset
|
48 #include "variables.h" |
8212
11263ebe590a
(svn r11775) -Codechange: move all autoreplace/autorenew functions to a single location.
rubidium <rubidium@openttd.org>
parents:
8211
diff
changeset
|
49 #include "autoreplace_gui.h" |
8224
c45446125bf0
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents:
8212
diff
changeset
|
50 #include "gfx_func.h" |
8270
5613b863190d
(svn r11834) -Codechange: only include settings_type.h if needed.
rubidium <rubidium@openttd.org>
parents:
8267
diff
changeset
|
51 #include "settings_type.h" |
8784
6280c0d48a6d
(svn r12488) -Codechange: split order.h into order_base.h and order_func.h.
rubidium <rubidium@openttd.org>
parents:
8781
diff
changeset
|
52 #include "order_func.h" |
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
|
53 #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
|
54 #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
|
55 #include "gamelog.h" |
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
56 #include "network/network.h" |
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
|
57 #include "pbs.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
|
58 |
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
|
59 #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
|
60 #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
|
61 |
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
|
62 static Track ChooseTrainTrack(Vehicle* v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool force_res, bool *got_reservation, bool mark_stuck); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
63 static bool TrainCheckIfLineEnds(Vehicle *v); |
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
|
64 static void TrainController(Vehicle *v, Vehicle *nomove, bool update_image); |
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
|
65 static TileIndex TrainApproachingCrossingTile(const Vehicle *v); |
9822
d61801babe63
(svn r13964) -Codechange [YAPP]: Check if a train needs servicing when reserving the next path segment. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9821
diff
changeset
|
66 static void CheckIfTrainNeedsService(Vehicle *v); |
9819
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
67 static void CheckNextTrainTile(Vehicle *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
|
68 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
69 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
|
70 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
|
71 |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
72 |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
73 /** |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
74 * 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
|
75 * |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
76 * @param direction vehicle direction |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
77 * @param track vehicle track bits |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
78 * @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
|
79 */ |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
80 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
|
81 { |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
82 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
|
83 |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
84 DiagDirection diagdir = DirToDiagDir(direction); |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
85 |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
86 /* 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
|
87 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
|
88 diagdir = ChangeDiagDir(diagdir, DIAGDIRDIFF_90LEFT); |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
89 } |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
90 |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
91 return diagdir; |
836273f128b5
(svn r11812) -Codechange: introduce TrainExitDir() to simplify some functions
smatz <smatz@openttd.org>
parents:
8238
diff
changeset
|
92 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
93 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
94 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
95 /** Return the cargo weight multiplier to use for a rail vehicle |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
96 * @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
|
97 * @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
|
98 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
99 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
|
100 { |
6114
466aa6880749
(svn r8850) -Codechange: Use the cargo type's is_freight flag instead of checking the cargo type to determine if the cargo type is freight cargo type cargo type.
peter1138 <peter1138@openttd.org>
parents:
6091
diff
changeset
|
101 if (!GetCargo(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
|
102 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
|
103 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
104 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
105 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
106 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
107 * Recalculates the cached total power of a train. Should be called when the consist is changed |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
108 * @param v First vehicle of the consist. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
109 */ |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
110 void TrainPowerChanged(Vehicle *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
|
111 { |
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
|
112 uint32 total_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
|
113 uint32 max_te = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
114 |
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
|
115 for (const Vehicle *u = v; u != NULL; u = u->Next()) { |
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
|
116 RailType railtype = GetRailType(u->tile); |
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
|
117 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
118 /* Power is not added for articulated parts */ |
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
|
119 if (!IsArticulatedPart(u)) { |
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
|
120 bool engine_has_power = HasPowerOnRail(u->u.rail.railtype, railtype); |
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
|
121 |
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
|
122 const RailVehicleInfo *rvi_u = RailVehInfo(u->engine_type); |
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
|
123 |
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
|
124 if (engine_has_power) { |
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
|
125 uint16 power = GetVehicleProperty(u, 0x0B, rvi_u->power); |
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
|
126 if (power != 0) { |
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
|
127 /* Halve power for multiheaded parts */ |
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
|
128 if (IsMultiheaded(u)) power /= 2; |
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
|
129 |
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
|
130 total_power += power; |
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
|
131 /* Tractive effort in (tonnes * 1000 * 10 =) N */ |
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
|
132 max_te += (u->u.rail.cached_veh_weight * 10000 * GetVehicleProperty(u, 0x1F, rvi_u->tractive_effort)) / 256; |
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
|
133 } |
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
|
134 } |
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 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
136 |
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
|
137 if (HasBit(u->u.rail.flags, VRF_POWEREDWAGON) && HasPowerOnRail(v->u.rail.railtype, railtype)) { |
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
|
138 total_power += RailVehInfo(u->u.rail.first_engine)->pow_wag_power; |
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 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
140 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
141 |
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
|
142 if (v->u.rail.cached_power != total_power || v->u.rail.cached_max_te != max_te) { |
7539
2695ac2e8baa
(svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium <rubidium@openttd.org>
parents:
7529
diff
changeset
|
143 /* If it has no power (no catenary), stop the train */ |
2695ac2e8baa
(svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium <rubidium@openttd.org>
parents:
7529
diff
changeset
|
144 if (total_power == 0) v->vehstatus |= VS_STOPPED; |
2695ac2e8baa
(svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium <rubidium@openttd.org>
parents:
7529
diff
changeset
|
145 |
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
|
146 v->u.rail.cached_power = total_power; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
147 v->u.rail.cached_max_te = max_te; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
148 InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
8350
8cde0dcc6818
(svn r11916) -Codechange: use enums from VehicleViewWindowWidgets instead of constants
smatz <smatz@openttd.org>
parents:
8344
diff
changeset
|
149 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
150 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
151 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
152 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
153 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
154 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
155 * Recalculates the cached weight of a train and its vehicles. Should be called each time the cargo on |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
156 * the consist changes. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
157 * @param v First vehicle of the consist. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
158 */ |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
159 static void TrainCargoChanged(Vehicle *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
|
160 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
161 uint32 weight = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
162 |
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
|
163 for (Vehicle *u = v; u != NULL; u = u->Next()) { |
7010
f0f87c5a431e
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium <rubidium@openttd.org>
parents:
7002
diff
changeset
|
164 uint32 vweight = GetCargo(u->cargo_type)->weight * u->cargo.Count() * FreightWagonMult(u->cargo_type) / 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
|
165 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
166 /* Vehicle weight is not added for articulated parts. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
167 if (!IsArticulatedPart(u)) { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
168 /* vehicle weight is the sum of the weight of the vehicle and the weight of its cargo */ |
6572
8c5c700bf758
(svn r9780) -Codechange: [NewGRF] Add support for variable vehicle weight for trains (callback 36, property 16)
peter1138 <peter1138@openttd.org>
parents:
6565
diff
changeset
|
169 vweight += GetVehicleProperty(u, 0x16, RailVehInfo(u->engine_type)->weight); |
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
|
170 } |
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
|
171 |
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
|
172 /* powered wagons have extra weight added */ |
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 if (HasBit(u->u.rail.flags, VRF_POWEREDWAGON)) { |
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 vweight += RailVehInfo(u->u.rail.first_engine)->pow_wag_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
|
175 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
176 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
177 /* consist weight is the sum of the weight of all vehicles in the consist */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
178 weight += vweight; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
179 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
180 /* store vehicle weight in cache */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
181 u->u.rail.cached_veh_weight = vweight; |
6150 | 182 } |
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 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
184 /* store consist weight in cache */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
185 v->u.rail.cached_weight = weight; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
186 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
187 /* Now update train power (tractive effort is dependent on weight) */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
188 TrainPowerChanged(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
189 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
190 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
191 |
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
|
192 /** Logs a bug in GRF and shows a warning message if this |
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
|
193 * is for the first time this happened. |
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
194 * @param u first vehicle of chain |
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
195 */ |
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
|
196 static void RailVehicleLengthChanged(const Vehicle *u) |
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
|
197 { |
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
|
198 /* show a warning once for each engine in whole game and once for each GRF after each game load */ |
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
|
199 const Engine *engine = GetEngine(u->engine_type); |
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
|
200 uint32 grfid = engine->grffile->grfid; |
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
|
201 GRFConfig *grfconfig = GetGRFConfig(grfid); |
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
|
202 if (GamelogGRFBugReverse(grfid, engine->internal_id) || !HasBit(grfconfig->grf_bugs, GBUG_VEH_LENGTH)) { |
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
|
203 SetBit(grfconfig->grf_bugs, GBUG_VEH_LENGTH); |
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
|
204 SetDParamStr(0, grfconfig->name); |
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
|
205 SetDParam(1, u->engine_type); |
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
|
206 ShowErrorMessage(STR_NEWGRF_BROKEN_VEHICLE_LENGTH, STR_NEWGRF_BROKEN, 0, 0); |
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
|
207 |
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
|
208 /* debug output */ |
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
|
209 char buffer[512]; |
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
|
210 |
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
|
211 SetDParamStr(0, grfconfig->name); |
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
|
212 GetString(buffer, STR_NEWGRF_BROKEN, lastof(buffer)); |
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
|
213 DEBUG(grf, 0, "%s", buffer + 3); |
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
|
214 |
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
|
215 SetDParam(1, u->engine_type); |
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
|
216 GetString(buffer, STR_NEWGRF_BROKEN_VEHICLE_LENGTH, lastof(buffer)); |
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
|
217 DEBUG(grf, 0, "%s", buffer + 3); |
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
|
218 |
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
|
219 if (!_networking) _pause_game = -1; |
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
|
220 } |
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 |
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
|
223 /** 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
|
224 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
|
225 { |
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
|
226 const Vehicle *v; |
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
|
227 |
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
|
228 FOR_ALL_VEHICLES(v) { |
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
|
229 if (v->type == VEH_TRAIN && v->First() == v && !(v->vehstatus & VS_CRASHED)) { |
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
|
230 for (const Vehicle *u = v, *w = v->Next(); w != NULL; u = w, w = w->Next()) { |
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
|
231 if (u->u.rail.track != TRACK_BIT_DEPOT) { |
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
|
232 if ((w->u.rail.track != TRACK_BIT_DEPOT && |
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
|
233 max(abs(u->x_pos - w->x_pos), abs(u->y_pos - w->y_pos)) != u->u.rail.cached_veh_length) || |
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
|
234 (w->u.rail.track == TRACK_BIT_DEPOT && TicksToLeaveDepot(u) <= 0)) { |
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
|
235 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
|
236 SetDParam(1, v->owner); |
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
|
237 ShowErrorMessage(INVALID_STRING_ID, STR_BROKEN_VEHICLE_LENGTH, 0, 0); |
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
|
238 |
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
|
239 if (!_networking) _pause_game = -1; |
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
|
240 } |
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
|
241 } |
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
|
242 } |
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
|
243 } |
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
|
244 } |
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
245 } |
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9699
diff
changeset
|
246 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
247 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
248 * 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
|
249 * 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
|
250 * Note: this needs to be called too for 'wagon chains' (in the depot, without an engine) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
251 * @param v First vehicle of the chain. |
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
|
252 * @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
|
253 */ |
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
|
254 void TrainConsistChanged(Vehicle *v, 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
|
255 { |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
256 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
|
257 |
6259
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
258 assert(v->type == VEH_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
|
259 assert(IsFrontEngine(v) || IsFreeWagon(v)); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
260 |
6150 | 261 const RailVehicleInfo *rvi_v = RailVehInfo(v->engine_type); |
262 EngineID first_engine = IsFrontEngine(v) ? v->engine_type : INVALID_ENGINE; | |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
263 v->u.rail.cached_total_length = 0; |
8236
d1191295967a
(svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium <rubidium@openttd.org>
parents:
8230
diff
changeset
|
264 v->u.rail.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
|
265 |
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
|
266 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
|
267 |
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
|
268 for (Vehicle *u = v; 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
|
269 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
|
270 |
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
|
271 /* Check the v->first cache. */ |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
272 assert(u->First() == 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
|
273 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
274 /* update the 'first engine' */ |
6150 | 275 u->u.rail.first_engine = v == u ? INVALID_ENGINE : first_engine; |
5823 | 276 u->u.rail.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
|
277 |
9515
bcc765d85155
(svn r13507) -Fix (r12856): first engine change should've been moved too
peter1138 <peter1138@openttd.org>
parents:
9488
diff
changeset
|
278 if (IsTrainEngine(u)) first_engine = u->engine_type; |
bcc765d85155
(svn r13507) -Fix (r12856): first engine change should've been moved too
peter1138 <peter1138@openttd.org>
parents:
9488
diff
changeset
|
279 |
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
|
280 /* Set user defined data to its default value */ |
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
|
281 u->u.rail.user_def_data = rvi_u->user_def_data; |
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
|
282 } |
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
|
283 |
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
|
284 for (Vehicle *u = v; u != NULL; u = u->Next()) { |
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
|
285 /* Update user defined data (must be done before other properties) */ |
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
|
286 u->u.rail.user_def_data = GetVehicleProperty(u, 0x25, u->u.rail.user_def_data); |
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
|
287 } |
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
|
288 |
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
|
289 for (Vehicle *u = v; u != NULL; u = u->Next()) { |
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
|
290 const RailVehicleInfo *rvi_u = RailVehInfo(u->engine_type); |
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
|
291 |
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
|
292 if (!HasBit(EngInfo(u->engine_type)->misc_flags, EF_RAIL_TILTS)) train_can_tilt = false; |
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
|
293 |
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
|
294 /* Cache wagon override sprite group. NULL is returned if there is none */ |
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
|
295 u->u.rail.cached_override = GetWagonOverrideSpriteSet(u->engine_type, u->cargo_type, u->u.rail.first_engine); |
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
|
296 |
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
|
297 /* Reset color map */ |
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
|
298 u->colormap = PAL_NONE; |
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
|
299 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
300 if (rvi_u->visual_effect != 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
301 u->u.rail.cached_vis_effect = rvi_u->visual_effect; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
302 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
303 if (IsTrainWagon(u) || IsArticulatedPart(u)) { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
304 /* Wagons and articulated parts have no effect by default */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
305 u->u.rail.cached_vis_effect = 0x40; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
306 } else if (rvi_u->engclass == 0) { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
307 /* Steam is offset by -4 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
|
308 u->u.rail.cached_vis_effect = 4; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
309 } else { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
310 /* Diesel fumes and sparks come from the centre */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
311 u->u.rail.cached_vis_effect = 8; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
312 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
313 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
314 |
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
|
315 /* Check powered wagon / visual effect callback */ |
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
|
316 if (HasBit(EngInfo(u->engine_type)->callbackmask, CBM_TRAIN_WAGON_POWER)) { |
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
|
317 uint16 callback = GetVehicleCallback(CBID_TRAIN_WAGON_POWER, 0, 0, u->engine_type, u); |
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
|
318 |
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
|
319 if (callback != CALLBACK_FAILED) u->u.rail.cached_vis_effect = GB(callback, 0, 8); |
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
|
320 } |
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
|
321 |
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
|
322 if (rvi_v->pow_wag_power != 0 && rvi_u->railveh_type == RAILVEH_WAGON && |
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
|
323 UsesWagonOverride(u) && !HasBit(u->u.rail.cached_vis_effect, 7)) { |
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
|
324 /* wagon is powered */ |
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
|
325 SetBit(u->u.rail.flags, VRF_POWEREDWAGON); // cache 'powered' status |
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
|
326 } else { |
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
|
327 ClrBit(u->u.rail.flags, VRF_POWEREDWAGON); |
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
|
328 } |
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
|
329 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
330 if (!IsArticulatedPart(u)) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
331 /* 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
|
332 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
|
333 if (rvi_u->power > 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
334 v->u.rail.compatible_railtypes |= GetRailTypeInfo(u->u.rail.railtype)->powered_railtypes; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
335 } |
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 /* 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
|
338 * existing electric engines when elrails are disabled and then re-enabled */ |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
339 if (HasBit(u->u.rail.flags, VRF_EL_ENGINE_ALLOWED_NORMAL_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
|
340 u->u.rail.railtype = RAILTYPE_RAIL; |
8236
d1191295967a
(svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium <rubidium@openttd.org>
parents:
8230
diff
changeset
|
341 u->u.rail.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
|
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 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
344 /* 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
|
345 if ((rvi_u->railveh_type != RAILVEH_WAGON || _settings_game.vehicle.wagon_speed_limits) && !UsesWagonOverride(u)) { |
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
|
346 uint16 speed = GetVehicleProperty(u, 0x09, rvi_u->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
|
347 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
|
348 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
349 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
350 |
6644
e329ee28c7ba
(svn r9875) -Fix (r9828): Only set carriage capacity if the wagon has not been refitted.
peter1138 <peter1138@openttd.org>
parents:
6643
diff
changeset
|
351 if (u->cargo_type == rvi_u->cargo_type && u->cargo_subtype == 0) { |
e329ee28c7ba
(svn r9875) -Fix (r9828): Only set carriage capacity if the wagon has not been refitted.
peter1138 <peter1138@openttd.org>
parents:
6643
diff
changeset
|
352 /* Set cargo capacity if we've not been refitted */ |
e329ee28c7ba
(svn r9875) -Fix (r9828): Only set carriage capacity if the wagon has not been refitted.
peter1138 <peter1138@openttd.org>
parents:
6643
diff
changeset
|
353 u->cargo_cap = GetVehicleProperty(u, 0x14, rvi_u->capacity); |
e329ee28c7ba
(svn r9875) -Fix (r9828): Only set carriage capacity if the wagon has not been refitted.
peter1138 <peter1138@openttd.org>
parents:
6643
diff
changeset
|
354 } |
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
|
355 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
356 /* check the vehicle length (callback) */ |
6150 | 357 uint16 veh_len = CALLBACK_FAILED; |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
358 if (HasBit(EngInfo(u->engine_type)->callbackmask, CBM_VEHICLE_LENGTH)) { |
7215
ba8faf180ec2
(svn r10493) -Codechange: update some callback ID enums to reflect their changed usage, add a few and update the comments.
rubidium <rubidium@openttd.org>
parents:
7196
diff
changeset
|
359 veh_len = GetVehicleCallback(CBID_VEHICLE_LENGTH, 0, 0, u->engine_type, u); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
360 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
361 if (veh_len == CALLBACK_FAILED) veh_len = rvi_u->shorten_factor; |
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
|
362 veh_len = 8 - Clamp(veh_len, 0, u->Next() == NULL ? 7 : 5); // the clamp on vehicles not the last in chain is stricter, as too short wagons can break the 'follow next vehicle' code |
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
|
363 |
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
|
364 /* verify length hasn't changed */ |
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
|
365 if (same_length && veh_len != u->u.rail.cached_veh_length) RailVehicleLengthChanged(u); |
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
|
366 |
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
|
367 /* update vehicle length? */ |
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
|
368 if (!same_length) u->u.rail.cached_veh_length = veh_len; |
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
|
369 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
370 v->u.rail.cached_total_length += u->u.rail.cached_veh_length; |
6150 | 371 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
372 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
373 /* store consist weight/max speed in cache */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
374 v->u.rail.cached_max_speed = max_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
|
375 v->u.rail.cached_tilt = train_can_tilt; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
376 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
377 /* 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) */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
378 TrainCargoChanged(v); |
8704
1c8728113c57
(svn r12378) -Fix: refresh vehicle details window when cached values are updated
glx <glx@openttd.org>
parents:
8703
diff
changeset
|
379 |
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
|
380 if (IsFrontEngine(v)) { |
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
|
381 UpdateTrainAcceleration(v); |
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
|
382 InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
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
|
383 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
384 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
385 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
386 enum AccelType { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
387 AM_ACCEL, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
388 AM_BRAKE |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
389 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
390 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
391 /** new acceleration*/ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
392 static int GetTrainAcceleration(Vehicle *v, bool mode) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
393 { |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
394 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
|
395 int max_speed = absolute_max_speed; |
7561
b4747a092643
(svn r11086) -Fix/Revert (r11053, r10984): "fixing" r11053 made the acceleration code use the wrong speed, which can be fixed by reverting a small piece of r10984.
rubidium <rubidium@openttd.org>
parents:
7551
diff
changeset
|
396 int speed = v->cur_speed * 10 / 16; // km-ish/h -> mp/h |
6150 | 397 int curvecount[2] = {0, 0}; |
398 | |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
399 /*first find the curve speed limit */ |
6150 | 400 int numcurve = 0; |
401 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
|
402 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
|
403 int lastpos = -1; |
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
|
404 for (const Vehicle *u = v; 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
|
405 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
|
406 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
|
407 |
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
|
408 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
|
409 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
|
410 |
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
|
411 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
|
412 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
|
413 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
|
414 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
|
415 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
|
416 sum += pos - lastpos; |
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
|
417 if (pos - 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
|
418 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
|
419 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
420 } |
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
|
421 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
|
422 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
423 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
424 /*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
|
425 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
|
426 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
|
427 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
428 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
429 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
430 if ((curvecount[0] != 0 || curvecount[1] != 0) && max_speed > 88) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
431 int total = curvecount[0] + curvecount[1]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
432 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
433 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
|
434 max_speed = absolute_max_speed; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
435 } else if (total > 1) { |
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
|
436 if (numcurve > 0) 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
|
437 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
|
438 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
439 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
440 |
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
|
441 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
|
442 /* Apply the engine's rail type curve speed advantage, if it slowed by curves */ |
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
|
443 const RailtypeInfo *rti = GetRailTypeInfo(v->u.rail.railtype); |
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
|
444 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
|
445 |
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
|
446 if (v->u.rail.cached_tilt) { |
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
|
447 /* 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
|
448 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
|
449 } |
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
|
450 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
451 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
452 if (IsTileType(v->tile, MP_STATION) && IsFrontEngine(v)) { |
8832
870ff040ec3e
(svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium <rubidium@openttd.org>
parents:
8830
diff
changeset
|
453 if (v->current_order.ShouldStopAtStation(v, GetStationIndex(v->tile))) { |
5998
bec0f8d9440b
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar <celestar@openttd.org>
parents:
5994
diff
changeset
|
454 int station_length = GetStationByTile(v->tile)->GetPlatformLength(v->tile, DirToDiagDir(v->direction)); |
8170
a8be61a5213c
(svn r11733) -Fix: Max speed for entering stations overrode the max speed of curves
peter1138 <peter1138@openttd.org>
parents:
8169
diff
changeset
|
455 |
a8be61a5213c
(svn r11733) -Fix: Max speed for entering stations overrode the max speed of curves
peter1138 <peter1138@openttd.org>
parents:
8169
diff
changeset
|
456 int st_max_speed = 120; |
a8be61a5213c
(svn r11733) -Fix: Max speed for entering stations overrode the max speed of curves
peter1138 <peter1138@openttd.org>
parents:
8169
diff
changeset
|
457 |
a8be61a5213c
(svn r11733) -Fix: Max speed for entering stations overrode the max speed of curves
peter1138 <peter1138@openttd.org>
parents:
8169
diff
changeset
|
458 int delta_v = v->cur_speed / (station_length + 1); |
a8be61a5213c
(svn r11733) -Fix: Max speed for entering stations overrode the max speed of curves
peter1138 <peter1138@openttd.org>
parents:
8169
diff
changeset
|
459 if (v->max_speed > (v->cur_speed - delta_v)) { |
a8be61a5213c
(svn r11733) -Fix: Max speed for entering stations overrode the max speed of curves
peter1138 <peter1138@openttd.org>
parents:
8169
diff
changeset
|
460 st_max_speed = v->cur_speed - (delta_v / 10); |
a8be61a5213c
(svn r11733) -Fix: Max speed for entering stations overrode the max speed of curves
peter1138 <peter1138@openttd.org>
parents:
8169
diff
changeset
|
461 } |
a8be61a5213c
(svn r11733) -Fix: Max speed for entering stations overrode the max speed of curves
peter1138 <peter1138@openttd.org>
parents:
8169
diff
changeset
|
462 |
a8be61a5213c
(svn r11733) -Fix: Max speed for entering stations overrode the max speed of curves
peter1138 <peter1138@openttd.org>
parents:
8169
diff
changeset
|
463 st_max_speed = max(st_max_speed, 25 * station_length); |
a8be61a5213c
(svn r11733) -Fix: Max speed for entering stations overrode the max speed of curves
peter1138 <peter1138@openttd.org>
parents:
8169
diff
changeset
|
464 max_speed = min(max_speed, st_max_speed); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
465 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
466 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
467 |
6150 | 468 int mass = v->u.rail.cached_weight; |
469 int power = v->u.rail.cached_power * 746; | |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
470 max_speed = min(max_speed, v->u.rail.cached_max_speed); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
471 |
6150 | 472 int num = 0; //number of vehicles, change this into the number of axles later |
473 int incl = 0; | |
474 int drag_coeff = 20; //[1e-4] | |
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
|
475 for (const Vehicle *u = v; 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
|
476 num++; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
477 drag_coeff += 3; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
478 |
5993
2498be7c7e94
(svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium <rubidium@openttd.org>
parents:
5992
diff
changeset
|
479 if (u->u.rail.track == TRACK_BIT_DEPOT) max_speed = min(max_speed, 61); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
480 |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
481 if (HasBit(u->u.rail.flags, VRF_GOINGUP)) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
482 incl += u->u.rail.cached_veh_weight * 60; //3% slope, quite a bit actually |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
483 } else if (HasBit(u->u.rail.flags, VRF_GOINGDOWN)) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
484 incl -= u->u.rail.cached_veh_weight * 60; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
485 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
486 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
487 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
488 v->max_speed = max_speed; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
489 |
6150 | 490 const int area = 120; |
491 const int friction = 35; //[1e-3] | |
492 int resistance; | |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
493 if (v->u.rail.railtype != RAILTYPE_MAGLEV) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
494 resistance = 13 * mass / 10; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
495 resistance += 60 * num; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
496 resistance += friction * mass * speed / 1000; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
497 resistance += (area * drag_coeff * speed * speed) / 10000; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
498 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
499 resistance = (area * (drag_coeff / 2) * speed * speed) / 10000; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
500 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
501 resistance += incl; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
502 resistance *= 4; //[N] |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
503 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
504 /* Due to the mph to m/s conversion below, at speeds below 3 mph the force is |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
505 * actually double the train's power */ |
6150 | 506 const int max_te = v->u.rail.cached_max_te; // [N] |
507 int force; | |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
508 if (speed > 2) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
509 switch (v->u.rail.railtype) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
510 case RAILTYPE_RAIL: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
511 case RAILTYPE_ELECTRIC: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
512 case RAILTYPE_MONO: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
513 force = power / speed; //[N] |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
514 force *= 22; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
515 force /= 10; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
516 if (mode == AM_ACCEL && force > max_te) force = max_te; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
517 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
518 |
6150 | 519 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
|
520 case RAILTYPE_MAGLEV: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
521 force = power / 25; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
522 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
523 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
524 } else { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
525 /* "kickoff" acceleration */ |
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 force = (mode == AM_ACCEL && v->u.rail.railtype != RAILTYPE_MAGLEV) ? min(max_te, power) : power; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
527 force = max(force, (mass * 8) + resistance); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
528 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
529 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
530 if (force <= 0) force = 10000; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
531 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
532 if (v->u.rail.railtype != RAILTYPE_MAGLEV) force = min(force, mass * 10 * 200); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
533 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
534 if (mode == AM_ACCEL) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
535 return (force - resistance) / (mass * 4); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
536 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
537 return min((-force - resistance) / (mass * 4), -10000 / (mass * 4)); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
538 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
539 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
540 |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
541 void UpdateTrainAcceleration(Vehicle *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
|
542 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
543 assert(IsFrontEngine(v)); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
544 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
545 v->max_speed = v->u.rail.cached_max_speed; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
546 |
6150 | 547 uint power = v->u.rail.cached_power; |
548 uint weight = v->u.rail.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
|
549 assert(weight != 0); |
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
|
550 v->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
|
551 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
552 |
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
|
553 SpriteID Train::GetImage(Direction direction) const |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
554 { |
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
|
555 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
|
556 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
|
557 |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
558 if (HasBit(this->u.rail.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
|
559 |
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
|
560 if (is_custom_sprite(spritenum)) { |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
561 sprite = GetCustomVehicleSprite(this, (Direction)(direction + 4 * IS_CUSTOM_SECONDHEAD_SPRITE(spritenum))); |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
562 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
|
563 |
9070
11b5b3f4175d
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents:
9041
diff
changeset
|
564 spritenum = GetEngine(this->engine_type)->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
|
565 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
566 |
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
|
567 sprite = _engine_sprite_base[spritenum] + ((direction + _engine_sprite_add[spritenum]) & _engine_sprite_and[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
|
568 |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
569 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
|
570 |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
571 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
|
572 } |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
573 |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
574 static SpriteID GetRailIcon(EngineID engine, bool rear_head, int &y) |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
575 { |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
576 Direction dir = rear_head ? DIR_E : DIR_W; |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
577 uint8 spritenum = RailVehInfo(engine)->image_index; |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
578 |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
579 if (is_custom_sprite(spritenum)) { |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
580 SpriteID sprite = GetCustomVehicleIcon(engine, dir); |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
581 if (sprite != 0) { |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
582 y += _traininfo_vehicle_pitch; // TODO Make this per-GRF |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
583 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
|
584 } |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
585 |
9070
11b5b3f4175d
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents:
9041
diff
changeset
|
586 spritenum = GetEngine(engine)->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
|
587 } |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
588 |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
589 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
|
590 |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
591 return ((6 + _engine_sprite_add[spritenum]) & _engine_sprite_and[spritenum]) + _engine_sprite_base[spritenum]; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
592 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
593 |
5668
3d6d9bff3dd8
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents:
5651
diff
changeset
|
594 void DrawTrainEngine(int x, int y, EngineID engine, SpriteID pal) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
595 { |
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
|
596 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
|
597 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
|
598 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
|
599 |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
600 SpriteID spritef = GetRailIcon(engine, false, yf); |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
601 SpriteID spriter = GetRailIcon(engine, true, yr); |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
602 DrawSprite(spritef, pal, x - 14, yf); |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
603 DrawSprite(spriter, pal, x + 15, yr); |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
604 } else { |
db43607c4798
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138 <peter1138@openttd.org>
parents:
9020
diff
changeset
|
605 SpriteID sprite = GetRailIcon(engine, false, 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
|
606 DrawSprite(sprite, pal, 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
|
607 } |
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 |
6943
fd42cb9816c6
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium <rubidium@openttd.org>
parents:
6924
diff
changeset
|
610 static CommandCost CmdBuildRailWagon(EngineID engine, TileIndex tile, uint32 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
|
611 { |
6150 | 612 const RailVehicleInfo *rvi = RailVehInfo(engine); |
9923
82b94a0a3f6c
(svn r14078) -Codechange: Rename *VehicleInfo::base_cost to cost_factor, indicating what it actually is.
peter1138 <peter1138@openttd.org>
parents:
9921
diff
changeset
|
613 CommandCost value(EXPENSES_NEW_VEHICLES, (GetEngineProperty(engine, 0x17, rvi->cost_factor) * _price.build_railwagon) >> 8); |
6150 | 614 |
7595
bb5f187ff5a7
(svn r11122) -Fix [FS#1234]: crash when building a NewGRF vehicle when the articulated build vehicle callback returneed a different value for the purchase window than the normal build. Thanks for Dalestan and _minime_ for pointers to possible causes.
rubidium <rubidium@openttd.org>
parents:
7593
diff
changeset
|
615 uint num_vehicles = 1 + CountArticulatedParts(engine, 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
|
616 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
617 if (!(flags & DC_QUERY_COST)) { |
8781
632cce4076f7
(svn r12482) -Fix: [build train] we don't need to have a depot in order to just check the price of a rail vehicle so don't check for compatible rails on the tile either
bjarni <bjarni@openttd.org>
parents:
8763
diff
changeset
|
618 /* Check that the wagon can drive on the track in question */ |
632cce4076f7
(svn r12482) -Fix: [build train] we don't need to have a depot in order to just check the price of a rail vehicle so don't check for compatible rails on the tile either
bjarni <bjarni@openttd.org>
parents:
8763
diff
changeset
|
619 if (!IsCompatibleRail(rvi->railtype, GetRailType(tile))) return CMD_ERROR; |
632cce4076f7
(svn r12482) -Fix: [build train] we don't need to have a depot in order to just check the price of a rail vehicle so don't check for compatible rails on the tile either
bjarni <bjarni@openttd.org>
parents:
8763
diff
changeset
|
620 |
7595
bb5f187ff5a7
(svn r11122) -Fix [FS#1234]: crash when building a NewGRF vehicle when the articulated build vehicle callback returneed a different value for the purchase window than the normal build. Thanks for Dalestan and _minime_ for pointers to possible causes.
rubidium <rubidium@openttd.org>
parents:
7593
diff
changeset
|
621 /* Allow for the wagon and the articulated parts, plus one to "terminate" the list. */ |
9488
9572fb37cb7c
(svn r13456) -Codechange: use AllocaM() macro instead of alloca() at most places
smatz <smatz@openttd.org>
parents:
9470
diff
changeset
|
622 Vehicle **vl = AllocaM(Vehicle*, num_vehicles + 1); |
7595
bb5f187ff5a7
(svn r11122) -Fix [FS#1234]: crash when building a NewGRF vehicle when the articulated build vehicle callback returneed a different value for the purchase window than the normal build. Thanks for Dalestan and _minime_ for pointers to possible causes.
rubidium <rubidium@openttd.org>
parents:
7593
diff
changeset
|
623 memset(vl, 0, sizeof(*vl) * (num_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
|
624 |
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
|
625 if (!Vehicle::AllocateList(vl, num_vehicles)) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
626 return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
627 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
628 if (flags & DC_EXEC) { |
6150 | 629 Vehicle *v = vl[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
|
630 v->spritenum = rvi->image_index; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
631 |
6150 | 632 Vehicle *u = NULL; |
633 | |
634 Vehicle *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
|
635 FOR_ALL_VEHICLES(w) { |
6259
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
636 if (w->type == VEH_TRAIN && w->tile == tile && |
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
|
637 IsFreeWagon(w) && w->engine_type == engine && |
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
|
638 !HASBITS(w->vehstatus, VS_CRASHED)) { /// do not connect new wagon with crashed/flooded consists |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
639 u = GetLastVehicleInChain(w); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
640 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
641 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
642 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
643 |
7782
f81103463949
(svn r11332) -Fix: vehicles getting a value of 0 on construction.
rubidium <rubidium@openttd.org>
parents:
7696
diff
changeset
|
644 v = new (v) 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
|
645 v->engine_type = engine; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
646 |
6150 | 647 DiagDirection dir = GetRailDepotDirection(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
|
648 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
649 v->direction = DiagDirToDir(dir); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
650 v->tile = tile; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
651 |
6150 | 652 int x = TileX(tile) * TILE_SIZE | _vehicle_initial_x_fract[dir]; |
653 int y = TileY(tile) * TILE_SIZE | _vehicle_initial_y_fract[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
|
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 v->x_pos = x; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
656 v->y_pos = y; |
6150 | 657 v->z_pos = GetSlopeZ(x, y); |
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
|
658 v->owner = _current_company; |
5993
2498be7c7e94
(svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium <rubidium@openttd.org>
parents:
5992
diff
changeset
|
659 v->u.rail.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
|
660 v->vehstatus = VS_HIDDEN | VS_DEFPAL; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
661 |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
662 // v->subtype = 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
|
663 SetTrainWagon(v); |
6771
8c1fa460e018
(svn r10007) -Codechange: Add some asserts to IsFrontEngine and friends to ensure that only trains use them.
maedhros <maedhros@openttd.org>
parents:
6752
diff
changeset
|
664 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
665 if (u != NULL) { |
7493
2068a51c2e6c
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium <rubidium@openttd.org>
parents:
7492
diff
changeset
|
666 u->SetNext(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
|
667 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
668 SetFreeWagon(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
669 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
|
670 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
671 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
672 v->cargo_type = rvi->cargo_type; |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
673 // v->cargo_subtype = 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
|
674 v->cargo_cap = rvi->capacity; |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
675 v->value = value.GetCost(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
676 // v->day_counter = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
677 |
5823 | 678 v->u.rail.railtype = rvi->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
|
679 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
680 v->build_year = _cur_year; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
681 v->cur_image = 0xAC2; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
682 v->random_bits = VehicleRandomBits(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
683 |
6643
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6608
diff
changeset
|
684 v->group_id = DEFAULT_GROUP; |
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6608
diff
changeset
|
685 |
6857
0005a9ed1903
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros <maedhros@openttd.org>
parents:
6789
diff
changeset
|
686 AddArticulatedParts(vl, VEH_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
|
687 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
688 _new_vehicle_id = v->index; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
689 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
690 VehiclePositionChanged(v); |
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
|
691 TrainConsistChanged(v->First(), false); |
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
|
692 UpdateTrainGroupID(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
|
693 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
694 InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
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
|
695 if (IsLocalCompany()) { |
7425
d2dde99b2258
(svn r10823) -Fix r8610 [FS#1097]: the autoreplace window vehicle count didn't always update correctly) (Matthias)
bjarni <bjarni@openttd.org>
parents:
7398
diff
changeset
|
696 InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the replace Train window |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
697 } |
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
|
698 GetCompany(_current_company)->num_engines[engine]++; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
699 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
700 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
701 |
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
|
702 return 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
|
703 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
704 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
705 /** Move all free vehicles in the depot to the train */ |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
706 static void NormalizeTrainVehInDepot(const Vehicle *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
|
707 { |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
708 const Vehicle *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
|
709 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
710 FOR_ALL_VEHICLES(v) { |
6259
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
711 if (v->type == VEH_TRAIN && IsFreeWagon(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
|
712 v->tile == u->tile && |
5993
2498be7c7e94
(svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium <rubidium@openttd.org>
parents:
5992
diff
changeset
|
713 v->u.rail.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
|
714 if (CmdFailed(DoCommand(0, v->index | (u->index << 16), 1, DC_EXEC, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
715 CMD_MOVE_RAIL_VEHICLE))) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
716 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
717 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
718 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
719 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
720 |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
721 static CommandCost EstimateTrainCost(EngineID engine, const RailVehicleInfo *rvi) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
722 { |
9923
82b94a0a3f6c
(svn r14078) -Codechange: Rename *VehicleInfo::base_cost to cost_factor, indicating what it actually is.
peter1138 <peter1138@openttd.org>
parents:
9921
diff
changeset
|
723 return CommandCost(EXPENSES_NEW_VEHICLES, GetEngineProperty(engine, 0x17, rvi->cost_factor) * (_price.build_railvehicle >> 3) >> 5); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
724 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
725 |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
726 static void AddRearEngineToMultiheadedTrain(Vehicle *v, Vehicle *u, bool building) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
727 { |
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
|
728 u = new (u) 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
|
729 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
|
730 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
|
731 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
|
732 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
|
733 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
|
734 u->z_pos = v->z_pos; |
5993
2498be7c7e94
(svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium <rubidium@openttd.org>
parents:
5992
diff
changeset
|
735 u->u.rail.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
|
736 u->vehstatus = v->vehstatus & ~VS_STOPPED; |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
737 // u->subtype = 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
|
738 SetMultiheaded(u); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
739 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
|
740 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
|
741 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
|
742 u->cargo_cap = v->cargo_cap; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
743 u->u.rail.railtype = v->u.rail.railtype; |
7493
2068a51c2e6c
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium <rubidium@openttd.org>
parents:
7492
diff
changeset
|
744 if (building) v->SetNext(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
|
745 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
|
746 u->build_year = v->build_year; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
747 if (building) v->value >>= 1; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
748 u->value = v->value; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
749 u->cur_image = 0xAC2; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
750 u->random_bits = VehicleRandomBits(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
751 VehiclePositionChanged(u); |
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 /** Build a railroad vehicle. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
755 * @param tile tile of the depot where rail-vehicle is built |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
756 * @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
|
757 * @param p1 engine type id |
9628
f1d95c5d5553
(svn r13691) -Codechange: make it easier to determine whether a command is ran in the context of autoreplace or not
smatz <smatz@openttd.org>
parents:
9515
diff
changeset
|
758 * @param p2 bit 1 prevents any free cars from being added to the 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
|
759 */ |
10499
45ca88a8de7d
(svn r14754) -Codechange: get rid of _cmd_text and just pass it as (optional) parameter.
rubidium <rubidium@openttd.org>
parents:
10493
diff
changeset
|
760 CommandCost CmdBuildRailVehicle(TileIndex tile, uint32 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
|
761 { |
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
|
762 /* Check if the engine-type is valid (for the company) */ |
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
|
763 if (!IsEngineBuildable(p1, VEH_TRAIN, _current_company)) return_cmd_error(STR_RAIL_VEHICLE_NOT_AVAILABLE); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
764 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
765 /* Check if the train is actually being built in a depot belonging |
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
|
766 * to the company. Doesn't matter if only the cost is queried */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
767 if (!(flags & DC_QUERY_COST)) { |
8961
b33bcd7fa037
(svn r12753) -Codechange: do not use IsDepotTypeTile() where simpler function can be used
smatz <smatz@openttd.org>
parents:
8954
diff
changeset
|
768 if (!IsRailDepotTile(tile)) return CMD_ERROR; |
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
|
769 if (!IsTileOwner(tile, _current_company)) 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
|
770 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
771 |
6150 | 772 const RailVehicleInfo *rvi = RailVehInfo(p1); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
773 |
5868
941f6c5a4668
(svn r8455) -Codechange: Give a more meaningful name (railveh_type)to member flags of RailVehInfo, as well as changing the code to reflect the fact that it was not a flag but rather a one value only variable. Doing so, some evaluations have been simplified.
belugas <belugas@openttd.org>
parents:
5858
diff
changeset
|
774 if (rvi->railveh_type == RAILVEH_WAGON) return CmdBuildRailWagon(p1, tile, 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
|
775 |
6943
fd42cb9816c6
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium <rubidium@openttd.org>
parents:
6924
diff
changeset
|
776 CommandCost value = EstimateTrainCost(p1, rvi); |
6150 | 777 |
778 uint num_vehicles = | |
779 (rvi->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1) + | |
7595
bb5f187ff5a7
(svn r11122) -Fix [FS#1234]: crash when building a NewGRF vehicle when the articulated build vehicle callback returneed a different value for the purchase window than the normal build. Thanks for Dalestan and _minime_ for pointers to possible causes.
rubidium <rubidium@openttd.org>
parents:
7593
diff
changeset
|
780 CountArticulatedParts(p1, 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
|
781 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
782 if (!(flags & DC_QUERY_COST)) { |
8781
632cce4076f7
(svn r12482) -Fix: [build train] we don't need to have a depot in order to just check the price of a rail vehicle so don't check for compatible rails on the tile either
bjarni <bjarni@openttd.org>
parents:
8763
diff
changeset
|
783 /* Check if depot and new engine uses the same kind of tracks * |
632cce4076f7
(svn r12482) -Fix: [build train] we don't need to have a depot in order to just check the price of a rail vehicle so don't check for compatible rails on the tile either
bjarni <bjarni@openttd.org>
parents:
8763
diff
changeset
|
784 * We need to see if the engine got power on the tile to avoid eletric engines in non-electric depots */ |
632cce4076f7
(svn r12482) -Fix: [build train] we don't need to have a depot in order to just check the price of a rail vehicle so don't check for compatible rails on the tile either
bjarni <bjarni@openttd.org>
parents:
8763
diff
changeset
|
785 if (!HasPowerOnRail(rvi->railtype, GetRailType(tile))) return CMD_ERROR; |
632cce4076f7
(svn r12482) -Fix: [build train] we don't need to have a depot in order to just check the price of a rail vehicle so don't check for compatible rails on the tile either
bjarni <bjarni@openttd.org>
parents:
8763
diff
changeset
|
786 |
7595
bb5f187ff5a7
(svn r11122) -Fix [FS#1234]: crash when building a NewGRF vehicle when the articulated build vehicle callback returneed a different value for the purchase window than the normal build. Thanks for Dalestan and _minime_ for pointers to possible causes.
rubidium <rubidium@openttd.org>
parents:
7593
diff
changeset
|
787 /* Allow for the dual-heads and the articulated parts, plus one to "terminate" the list. */ |
9488
9572fb37cb7c
(svn r13456) -Codechange: use AllocaM() macro instead of alloca() at most places
smatz <smatz@openttd.org>
parents:
9470
diff
changeset
|
788 Vehicle **vl = AllocaM(Vehicle*, num_vehicles + 1); |
7595
bb5f187ff5a7
(svn r11122) -Fix [FS#1234]: crash when building a NewGRF vehicle when the articulated build vehicle callback returneed a different value for the purchase window than the normal build. Thanks for Dalestan and _minime_ for pointers to possible causes.
rubidium <rubidium@openttd.org>
parents:
7593
diff
changeset
|
789 memset(vl, 0, sizeof(*vl) * (num_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
|
790 |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
791 if (!Vehicle::AllocateList(vl, num_vehicles)) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
792 return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
793 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
794 |
6150 | 795 Vehicle *v = vl[0]; |
796 | |
9628
f1d95c5d5553
(svn r13691) -Codechange: make it easier to determine whether a command is ran in the context of autoreplace or not
smatz <smatz@openttd.org>
parents:
9515
diff
changeset
|
797 UnitID unit_num = (flags & DC_AUTOREPLACE) ? 0 : GetFreeUnitNumber(VEH_TRAIN); |
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
|
798 if (unit_num > _settings_game.vehicle.max_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
|
799 return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
800 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
801 if (flags & DC_EXEC) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
802 DiagDirection dir = GetRailDepotDirection(tile); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
803 int x = TileX(tile) * TILE_SIZE + _vehicle_initial_x_fract[dir]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
804 int y = TileY(tile) * TILE_SIZE + _vehicle_initial_y_fract[dir]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
805 |
7783
ea876c197cb2
(svn r11333) -Fix: Train engines still had a value of 0.
maedhros <maedhros@openttd.org>
parents:
7782
diff
changeset
|
806 v = new (v) 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
|
807 v->unitnumber = unit_num; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
808 v->direction = DiagDirToDir(dir); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
809 v->tile = tile; |
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
|
810 v->owner = _current_company; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
811 v->x_pos = x; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
812 v->y_pos = y; |
6150 | 813 v->z_pos = GetSlopeZ(x, y); |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
814 // v->running_ticks = 0; |
5993
2498be7c7e94
(svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium <rubidium@openttd.org>
parents:
5992
diff
changeset
|
815 v->u.rail.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
|
816 v->vehstatus = VS_HIDDEN | VS_STOPPED | VS_DEFPAL; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
817 v->spritenum = rvi->image_index; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
818 v->cargo_type = rvi->cargo_type; |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
819 // v->cargo_subtype = 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
|
820 v->cargo_cap = rvi->capacity; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
821 v->max_speed = rvi->max_speed; |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
822 v->value = value.GetCost(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
823 v->last_station_visited = INVALID_STATION; |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
824 // v->dest_tile = 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
|
825 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
826 v->engine_type = p1; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
827 |
5823 | 828 const Engine *e = GetEngine(p1); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
829 v->reliability = e->reliability; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
830 v->reliability_spd_dec = e->reliability_spd_dec; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
831 v->max_age = e->lifelength * 366; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
832 |
8258
6017c5ebeb7e
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138 <peter1138@openttd.org>
parents:
8257
diff
changeset
|
833 v->name = NULL; |
5823 | 834 v->u.rail.railtype = rvi->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
|
835 _new_vehicle_id = v->index; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
836 |
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
|
837 v->service_interval = _settings_game.vehicle.servint_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
|
838 v->date_of_last_service = _date; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
839 v->build_year = _cur_year; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
840 v->cur_image = 0xAC2; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
841 v->random_bits = VehicleRandomBits(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
842 |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
843 // v->vehicle_flags = 0; |
7931
44ff7a6d801f
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7929
diff
changeset
|
844 if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE); |
6176
863c86137fc1
(svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros <maedhros@openttd.org>
parents:
6175
diff
changeset
|
845 |
6643
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6608
diff
changeset
|
846 v->group_id = DEFAULT_GROUP; |
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6608
diff
changeset
|
847 |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
848 // v->subtype = 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
|
849 SetFrontEngine(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
850 SetTrainEngine(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
851 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
852 VehiclePositionChanged(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
853 |
5868
941f6c5a4668
(svn r8455) -Codechange: Give a more meaningful name (railveh_type)to member flags of RailVehInfo, as well as changing the code to reflect the fact that it was not a flag but rather a one value only variable. Doing so, some evaluations have been simplified.
belugas <belugas@openttd.org>
parents:
5858
diff
changeset
|
854 if (rvi->railveh_type == RAILVEH_MULTIHEAD) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
855 SetMultiheaded(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
856 AddRearEngineToMultiheadedTrain(vl[0], vl[1], true); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
857 /* Now we need to link the front and rear engines together |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
858 * other_multiheaded_part is the pointer that links to the other half of the engine |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
859 * vl[0] is the front and vl[1] is the rear |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
860 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
861 vl[0]->u.rail.other_multiheaded_part = vl[1]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
862 vl[1]->u.rail.other_multiheaded_part = vl[0]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
863 } else { |
6857
0005a9ed1903
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros <maedhros@openttd.org>
parents:
6789
diff
changeset
|
864 AddArticulatedParts(vl, VEH_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
|
865 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
866 |
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
|
867 TrainConsistChanged(v, false); |
6643
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6608
diff
changeset
|
868 UpdateTrainGroupID(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
|
869 |
9628
f1d95c5d5553
(svn r13691) -Codechange: make it easier to determine whether a command is ran in the context of autoreplace or not
smatz <smatz@openttd.org>
parents:
9515
diff
changeset
|
870 if (!HasBit(p2, 1) && !(flags & DC_AUTOREPLACE)) { // check if the cars should be added to the new 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
|
871 NormalizeTrainVehInDepot(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
872 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
873 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
874 InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
9297
add307f2e6ea
(svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium <rubidium@openttd.org>
parents:
9274
diff
changeset
|
875 InvalidateWindowClassesData(WC_TRAINS_LIST, 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
|
876 InvalidateWindow(WC_COMPANY, v->owner); |
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
|
877 if (IsLocalCompany()) { |
7425
d2dde99b2258
(svn r10823) -Fix r8610 [FS#1097]: the autoreplace window vehicle count didn't always update correctly) (Matthias)
bjarni <bjarni@openttd.org>
parents:
7398
diff
changeset
|
878 InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the replace Train window |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
879 } |
5944
ca95cde4d1b4
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni <bjarni@openttd.org>
parents:
5922
diff
changeset
|
880 |
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
|
881 GetCompany(_current_company)->num_engines[p1]++; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
882 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
883 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
884 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
885 return value; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
886 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
887 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
888 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
889 /* Check if all the wagons of the given train are in a depot, returns the |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
890 * number of cars (including loco) then. If not it returns -1 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
891 int CheckTrainInDepot(const Vehicle *v, bool needs_to_be_stopped) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
892 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
893 TileIndex 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
|
894 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
895 /* check if stopped in 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
|
896 if (!IsRailDepotTile(tile) || v->cur_speed != 0) return -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
|
897 |
6150 | 898 int count = 0; |
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
|
899 for (; v != NULL; v = v->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
|
900 /* This count is used by the depot code to determine the number of engines |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
901 * in the consist. Exclude articulated parts so that autoreplacing to |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
902 * engines with more articulated parts than before works correctly. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
903 * |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
904 * Also skip counting rear ends of multiheaded engines */ |
7526
e463f6756541
(svn r11045) -Codechange: added a function to tell if a vehicle is the rear part of a dualheaded train engine
bjarni <bjarni@openttd.org>
parents:
7502
diff
changeset
|
905 if (!IsArticulatedPart(v) && !IsRearDualheaded(v)) count++; |
5993
2498be7c7e94
(svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium <rubidium@openttd.org>
parents:
5992
diff
changeset
|
906 if (v->u.rail.track != TRACK_BIT_DEPOT || v->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
|
907 (IsFrontEngine(v) && needs_to_be_stopped && !(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
|
908 return -1; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
909 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
910 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
911 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
912 return count; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
913 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
914 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
915 /* Used to check if the train is inside the depot and verifying that the VS_STOPPED flag is set */ |
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
|
916 int CheckTrainStoppedInDepot(const Vehicle *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
|
917 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
918 return CheckTrainInDepot(v, true); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
919 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
920 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
921 /* Used to check if the train is inside the depot, but not checking the VS_STOPPED flag */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
922 inline bool CheckTrainIsInsideDepot(const Vehicle *v) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
923 { |
6150 | 924 return CheckTrainInDepot(v, false) > 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
|
925 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
926 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
927 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
928 * Unlink a rail wagon from the consist. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
929 * @param v Vehicle to remove. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
930 * @param first The first vehicle of the consist. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
931 * @return The first vehicle of the consist. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
932 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
933 static Vehicle *UnlinkWagon(Vehicle *v, Vehicle *first) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
934 { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
935 /* unlinking the first vehicle of the chain? */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
936 if (v == first) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
937 v = GetNextVehicle(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
938 if (v == NULL) 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
|
939 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
940 if (IsTrainWagon(v)) SetFreeWagon(v); |
10492
28fa021b003c
(svn r14747) -Codechange: remove DeleteVehicleChain in favour of the vehicle destructor as that was already doing the same for a few vehicle types.
rubidium <rubidium@openttd.org>
parents:
10488
diff
changeset
|
941 first->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
|
942 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
943 return v; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
944 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
945 |
6150 | 946 Vehicle *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
|
947 for (u = first; GetNextVehicle(u) != v; u = GetNextVehicle(u)) {} |
7493
2068a51c2e6c
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium <rubidium@openttd.org>
parents:
7492
diff
changeset
|
948 GetLastEnginePart(u)->SetNext(GetNextVehicle(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
|
949 return first; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
950 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
951 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
952 static Vehicle *FindGoodVehiclePos(const Vehicle *src) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
953 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
954 Vehicle *dst; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
955 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
|
956 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
|
957 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
958 FOR_ALL_VEHICLES(dst) { |
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
|
959 if (dst->type == VEH_TRAIN && IsFreeWagon(dst) && dst->tile == tile && !HASBITS(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
|
960 /* check so all vehicles in the line have the same engine. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
961 Vehicle *v = dst; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
962 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
963 while (v->engine_type == eng) { |
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
|
964 v = v->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
|
965 if (v == NULL) return dst; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
966 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
967 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
968 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
969 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
970 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
|
971 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
972 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
973 /* |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
974 * add a vehicle v behind vehicle dest |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
975 * use this function since it sets flags as needed |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
976 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
977 static void AddWagonToConsist(Vehicle *v, Vehicle *dest) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
978 { |
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
|
979 UnlinkWagon(v, 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
|
980 if (dest == NULL) return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
981 |
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
|
982 Vehicle *next = dest->Next(); |
8007
aaded46b8daf
(svn r11567) -Fix [FS#1512] (r11011): break the chain before moving a vehicle after another in the same chain
glx <glx@openttd.org>
parents:
7967
diff
changeset
|
983 v->SetNext(NULL); |
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
|
984 dest->SetNext(v); |
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
|
985 v->SetNext(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
|
986 ClearFreeWagon(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
987 ClearFrontEngine(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
988 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
989 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
990 /* |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
991 * move around on the train so rear engines are placed correctly according to the other engines |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
992 * always call with the front engine |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
993 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
994 static void NormaliseTrainConsist(Vehicle *v) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
995 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
996 if (IsFreeWagon(v)) return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
997 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
998 assert(IsFrontEngine(v)); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
999 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1000 for (; v != NULL; v = GetNextVehicle(v)) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1001 if (!IsMultiheaded(v) || !IsTrainEngine(v)) continue; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1002 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1003 /* make sure that there are no free cars before next engine */ |
6150 | 1004 Vehicle *u; |
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
|
1005 for (u = v; u->Next() != NULL && !IsTrainEngine(u->Next()); 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
|
1006 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1007 if (u == v->u.rail.other_multiheaded_part) continue; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1008 AddWagonToConsist(v->u.rail.other_multiheaded_part, u); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1009 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1010 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1011 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1012 /** Move a rail vehicle around inside the depot. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1013 * @param tile unused |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1014 * @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
|
1015 * 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
|
1016 * @param p1 various bitstuffed elements |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1017 * - p1 (bit 0 - 15) source vehicle index |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1018 * - p1 (bit 16 - 31) what wagon to put the source wagon AFTER, XXX - INVALID_VEHICLE to make a new line |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1019 * @param p2 (bit 0) move all vehicles following the source vehicle |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1020 */ |
10499
45ca88a8de7d
(svn r14754) -Codechange: get rid of _cmd_text and just pass it as (optional) parameter.
rubidium <rubidium@openttd.org>
parents:
10493
diff
changeset
|
1021 CommandCost CmdMoveRailVehicle(TileIndex tile, uint32 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
|
1022 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1023 VehicleID s = GB(p1, 0, 16); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1024 VehicleID d = GB(p1, 16, 16); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1025 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1026 if (!IsValidVehicleID(s)) return CMD_ERROR; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1027 |
6150 | 1028 Vehicle *src = GetVehicle(s); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1029 |
6259
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
1030 if (src->type != VEH_TRAIN || !CheckOwnership(src->owner)) 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
|
1031 |
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
|
1032 /* Do not allow moving crashed vehicles inside the depot, it is likely to cause asserts later */ |
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
|
1033 if (HASBITS(src->vehstatus, VS_CRASHED)) return CMD_ERROR; |
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
|
1034 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1035 /* if nothing is selected as destination, try and find a matching vehicle to drag to. */ |
6150 | 1036 Vehicle *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
|
1037 if (d == INVALID_VEHICLE) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1038 dst = IsTrainEngine(src) ? NULL : FindGoodVehiclePos(src); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1039 } else { |
6136 | 1040 if (!IsValidVehicleID(d)) 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
|
1041 dst = GetVehicle(d); |
6259
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
1042 if (dst->type != VEH_TRAIN || !CheckOwnership(dst->owner)) 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
|
1043 |
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
|
1044 /* Do not allow appending to crashed vehicles, too */ |
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
|
1045 if (HASBITS(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
|
1046 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1047 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1048 /* if an articulated part is being handled, deal with its parent vehicle */ |
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
|
1049 while (IsArticulatedPart(src)) src = src->Previous(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1050 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
|
1051 while (IsArticulatedPart(dst)) dst = dst->Previous(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1052 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1053 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1054 /* 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
|
1055 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
|
1056 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1057 /* locate the head of the two chains */ |
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
|
1058 Vehicle *src_head = src->First(); |
6150 | 1059 Vehicle *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
|
1060 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
|
1061 dst_head = dst->First(); |
6136 | 1062 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
|
1063 /* Now deal with articulated part of destination wagon */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1064 dst = GetLastEnginePart(dst); |
6136 | 1065 } else { |
1066 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
|
1067 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1068 |
7526
e463f6756541
(svn r11045) -Codechange: added a function to tell if a vehicle is the rear part of a dualheaded train engine
bjarni <bjarni@openttd.org>
parents:
7502
diff
changeset
|
1069 if (IsRearDualheaded(src)) return_cmd_error(STR_REAR_ENGINE_FOLLOW_FRONT_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
|
1070 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1071 /* when moving all wagons, we can't have the same src_head and dst_head */ |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
1072 if (HasBit(p2, 0) && 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
|
1073 |
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
|
1074 /* check if all vehicles in the source train are stopped inside a depot. */ |
0cc9c6c36c43
(svn r14083) -Fix [FS#1264, FS#2037, FS#2038, FS#2110]: Rewrite the autoreplace kernel.
frosch <frosch@openttd.org>
parents:
9923
diff
changeset
|
1075 int src_len = CheckTrainStoppedInDepot(src_head); |
0cc9c6c36c43
(svn r14083) -Fix [FS#1264, FS#2037, FS#2038, FS#2110]: Rewrite the autoreplace kernel.
frosch <frosch@openttd.org>
parents:
9923
diff
changeset
|
1076 if (src_len < 0) return_cmd_error(STR_881A_TRAINS_CAN_ONLY_BE_ALTERED); |
0cc9c6c36c43
(svn r14083) -Fix [FS#1264, FS#2037, FS#2038, FS#2110]: Rewrite the autoreplace kernel.
frosch <frosch@openttd.org>
parents:
9923
diff
changeset
|
1077 |
0cc9c6c36c43
(svn r14083) -Fix [FS#1264, FS#2037, FS#2038, FS#2110]: Rewrite the autoreplace kernel.
frosch <frosch@openttd.org>
parents:
9923
diff
changeset
|
1078 if ((flags & DC_AUTOREPLACE) == 0) { |
0cc9c6c36c43
(svn r14083) -Fix [FS#1264, FS#2037, FS#2038, FS#2110]: Rewrite the autoreplace kernel.
frosch <frosch@openttd.org>
parents:
9923
diff
changeset
|
1079 /* Check whether there are more than 'max_len' train units (articulated parts and rear heads do not count) in the new chain */ |
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
|
1080 int max_len = _settings_game.vehicle.mammoth_trains ? 100 : 10; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1081 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1082 /* check the destination row if the source and destination aren't 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
|
1083 if (src_head != dst_head) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1084 int dst_len = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1085 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1086 if (dst_head != NULL) { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1087 /* check if all vehicles in the dest train are stopped. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1088 dst_len = CheckTrainStoppedInDepot(dst_head); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1089 if (dst_len < 0) return_cmd_error(STR_881A_TRAINS_CAN_ONLY_BE_ALTERED); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1090 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1091 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1092 /* We are moving between rows, so only count the wagons from the source |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1093 * row that are being moved. */ |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
1094 if (HasBit(p2, 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
|
1095 const Vehicle *u; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1096 for (u = src_head; u != src && u != NULL; u = GetNextVehicle(u)) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1097 src_len--; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1098 } else { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1099 /* If moving only one vehicle, just count that. */ |
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 src_len = 1; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1101 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1102 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1103 if (src_len + dst_len > max_len) { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1104 /* Abort if we're adding too many wagons to a 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
|
1105 if (dst_head != NULL && IsFrontEngine(dst_head)) return_cmd_error(STR_8819_TRAIN_TOO_LONG); |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1106 /* Abort if we're making a train on a new row. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1107 if (dst_head == NULL && IsTrainEngine(src)) return_cmd_error(STR_8819_TRAIN_TOO_LONG); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1108 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1109 } else { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1110 /* Abort if we're creating a new train on an existing row. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1111 if (src_len > max_len && src == src_head && IsTrainEngine(GetNextVehicle(src_head))) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1112 return_cmd_error(STR_8819_TRAIN_TOO_LONG); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1113 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1114 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1115 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1116 /* moving a loco to a new line?, then we need to assign a unitnumber. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1117 if (dst == NULL && !IsFrontEngine(src) && IsTrainEngine(src)) { |
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
|
1118 UnitID unit_num = ((flags & DC_AUTOREPLACE) != 0 ? 0 : GetFreeUnitNumber(VEH_TRAIN)); |
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
|
1119 if (unit_num > _settings_game.vehicle.max_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
|
1120 return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1121 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1122 if (flags & DC_EXEC) src->unitnumber = unit_num; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1123 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1124 |
10178
3efef11a2488
(svn r14384) -Fix: Moving the first vehicle of a train elsewhere might require a new unitnumber for the remaining chain.
frosch <frosch@openttd.org>
parents:
10176
diff
changeset
|
1125 /* When we move the front vehicle, the second vehicle might need a unitnumber */ |
10190
f69fe8af0555
(svn r14403) -Fix (r14384): The condition was too restrictive.
frosch <frosch@openttd.org>
parents:
10188
diff
changeset
|
1126 if (!HasBit(p2, 0) && (IsFreeWagon(src) || (IsFrontEngine(src) && dst == NULL)) && (flags & DC_AUTOREPLACE) == 0) { |
10178
3efef11a2488
(svn r14384) -Fix: Moving the first vehicle of a train elsewhere might require a new unitnumber for the remaining chain.
frosch <frosch@openttd.org>
parents:
10176
diff
changeset
|
1127 Vehicle *second = GetNextUnit(src); |
3efef11a2488
(svn r14384) -Fix: Moving the first vehicle of a train elsewhere might require a new unitnumber for the remaining chain.
frosch <frosch@openttd.org>
parents:
10176
diff
changeset
|
1128 if (second != NULL && IsTrainEngine(second) && GetFreeUnitNumber(VEH_TRAIN) > _settings_game.vehicle.max_trains) { |
3efef11a2488
(svn r14384) -Fix: Moving the first vehicle of a train elsewhere might require a new unitnumber for the remaining chain.
frosch <frosch@openttd.org>
parents:
10176
diff
changeset
|
1129 return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
3efef11a2488
(svn r14384) -Fix: Moving the first vehicle of a train elsewhere might require a new unitnumber for the remaining chain.
frosch <frosch@openttd.org>
parents:
10176
diff
changeset
|
1130 } |
3efef11a2488
(svn r14384) -Fix: Moving the first vehicle of a train elsewhere might require a new unitnumber for the remaining chain.
frosch <frosch@openttd.org>
parents:
10176
diff
changeset
|
1131 } |
3efef11a2488
(svn r14384) -Fix: Moving the first vehicle of a train elsewhere might require a new unitnumber for the remaining chain.
frosch <frosch@openttd.org>
parents:
10176
diff
changeset
|
1132 |
8162
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1133 /* |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1134 * Check whether the vehicles in the source chain are in the destination |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1135 * chain. This can easily be done by checking whether the first vehicle |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1136 * of the source chain is in the destination chain as the Next/Previous |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1137 * pointers always make a doubly linked list of it where the assumption |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1138 * v->Next()->Previous() == v holds (assuming v->Next() != NULL). |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1139 */ |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1140 bool src_in_dst = false; |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1141 for (Vehicle *v = dst_head; !src_in_dst && v != NULL; v = v->Next()) src_in_dst = v == src; |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1142 |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1143 /* |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1144 * If the source chain is in the destination chain then the user is |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1145 * only reordering the vehicles, thus not attaching a new vehicle. |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1146 * Therefor the 'allow wagon attach' callback does not need to be |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1147 * called. If it would be called strange things would happen because |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1148 * one 'attaches' an already 'attached' vehicle causing more trouble |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1149 * than it actually solves (infinite loops and such). |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1150 */ |
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
|
1151 if (dst_head != NULL && !src_in_dst && (flags & DC_AUTOREPLACE) == 0) { |
8162
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1152 /* |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1153 * When performing the 'allow wagon attach' callback, we have to check |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1154 * that for each and every wagon, not only the first one. This means |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1155 * that we have to test one wagon, attach it to the train and then test |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1156 * the next wagon till we have reached the end. We have to restore it |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1157 * to the state it was before we 'tried' attaching the train when the |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1158 * attaching fails or succeeds because we are not 'only' doing this |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1159 * in the DC_EXEC state. |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1160 */ |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1161 Vehicle *dst_tail = dst_head; |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1162 while (dst_tail->Next() != NULL) dst_tail = dst_tail->Next(); |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1163 |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1164 Vehicle *orig_tail = dst_tail; |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1165 Vehicle *next_to_attach = src; |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1166 Vehicle *src_previous = src->Previous(); |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1167 |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1168 while (next_to_attach != NULL) { |
10188
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1169 /* Don't check callback for articulated or rear dual headed parts */ |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1170 if (!IsArticulatedPart(next_to_attach) && !IsRearDualheaded(next_to_attach)) { |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1171 /* Back up and clear the first_engine data to avoid using wagon override group */ |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1172 EngineID first_engine = next_to_attach->u.rail.first_engine; |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1173 next_to_attach->u.rail.first_engine = INVALID_ENGINE; |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1174 |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1175 uint16 callback = GetVehicleCallbackParent(CBID_TRAIN_ALLOW_WAGON_ATTACH, 0, 0, dst_head->engine_type, next_to_attach, dst_head); |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1176 |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1177 /* Restore original first_engine data */ |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1178 next_to_attach->u.rail.first_engine = first_engine; |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1179 |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1180 if (callback != CALLBACK_FAILED) { |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1181 StringID error = STR_NULL; |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1182 |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1183 if (callback == 0xFD) error = STR_INCOMPATIBLE_RAIL_TYPES; |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1184 if (callback < 0xFD) error = GetGRFStringID(GetEngineGRFID(dst_head->engine_type), 0xD000 + callback); |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1185 |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1186 if (error != STR_NULL) { |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1187 /* |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1188 * The attaching is not allowed. In this case 'next_to_attach' |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1189 * can contain some vehicles of the 'source' and the destination |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1190 * train can have some too. We 'just' add the to-be added wagons |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1191 * to the chain and then split it where it was previously |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1192 * separated, i.e. the tail of the original destination train. |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1193 * Furthermore the 'previous' link of the original source vehicle needs |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1194 * to be restored, otherwise the train goes missing in the depot. |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1195 */ |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1196 dst_tail->SetNext(next_to_attach); |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1197 orig_tail->SetNext(NULL); |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1198 if (src_previous != NULL) src_previous->SetNext(src); |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1199 |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1200 return_cmd_error(error); |
4bbb0f16ef39
(svn r14401) -Fix (r11724): Don't check articulated parts or rear multihead parts for callback 1D when moving a chain of wagons.
peter1138 <peter1138@openttd.org>
parents:
10186
diff
changeset
|
1201 } |
8162
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1202 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1203 } |
8162
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1204 |
8168
e321f51fe381
(svn r11731) -Fix [FS#1582]: Clear sprite override data before performing NewGRF wagon attach callback. This stopped
peter1138 <peter1138@openttd.org>
parents:
8162
diff
changeset
|
1205 /* Only check further wagons if told to move the chain */ |
e321f51fe381
(svn r11731) -Fix [FS#1582]: Clear sprite override data before performing NewGRF wagon attach callback. This stopped
peter1138 <peter1138@openttd.org>
parents:
8162
diff
changeset
|
1206 if (!HasBit(p2, 0)) break; |
e321f51fe381
(svn r11731) -Fix [FS#1582]: Clear sprite override data before performing NewGRF wagon attach callback. This stopped
peter1138 <peter1138@openttd.org>
parents:
8162
diff
changeset
|
1207 |
8162
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1208 /* |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1209 * Adding a next wagon to the chain so we can test the other wagons. |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1210 * First 'take' the first wagon from 'next_to_attach' and move it |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1211 * to the next wagon. Then add that to the tail of the destination |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1212 * train and update the tail with the new vehicle. |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1213 */ |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1214 Vehicle *to_add = next_to_attach; |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1215 next_to_attach = next_to_attach->Next(); |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1216 |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1217 to_add->SetNext(NULL); |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1218 dst_tail->SetNext(to_add); |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1219 dst_tail = dst_tail->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
|
1220 } |
8162
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1221 |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1222 /* |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1223 * When we reach this the attaching is allowed. It also means that the |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1224 * chain of vehicles to attach is empty, so we do not need to merge that. |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1225 * This means only the splitting needs to be done. |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1226 * Furthermore the 'previous' link of the original source vehicle needs |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1227 * to be restored, otherwise the train goes missing in the depot. |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1228 */ |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1229 orig_tail->SetNext(NULL); |
e77c1af20217
(svn r11724) -Fix: make it impossible (for users) to circumvent the length checking of the NewGRF 'allow wagon attach' callback by moving several wagons at a time.
rubidium <rubidium@openttd.org>
parents:
8157
diff
changeset
|
1230 if (src_previous != NULL) src_previous->SetNext(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
|
1231 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1232 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1233 /* 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
|
1234 if (flags & DC_EXEC) { |
6643
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6608
diff
changeset
|
1235 /* If we move the front Engine and if the second vehicle is not an engine |
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6608
diff
changeset
|
1236 add the whole vehicle to the DEFAULT_GROUP */ |
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6608
diff
changeset
|
1237 if (IsFrontEngine(src) && !IsDefaultGroupID(src->group_id)) { |
7529
d334553f6db4
(svn r11048) -Fix [FS#1206]: several cases where (re)moving eninges on a train would corrupt the vehicle counts for the groups.
rubidium <rubidium@openttd.org>
parents:
7526
diff
changeset
|
1238 Vehicle *v = GetNextVehicle(src); |
d334553f6db4
(svn r11048) -Fix [FS#1206]: several cases where (re)moving eninges on a train would corrupt the vehicle counts for the groups.
rubidium <rubidium@openttd.org>
parents:
7526
diff
changeset
|
1239 |
d334553f6db4
(svn r11048) -Fix [FS#1206]: several cases where (re)moving eninges on a train would corrupt the vehicle counts for the groups.
rubidium <rubidium@openttd.org>
parents:
7526
diff
changeset
|
1240 if (v != NULL && IsTrainEngine(v)) { |
d334553f6db4
(svn r11048) -Fix [FS#1206]: several cases where (re)moving eninges on a train would corrupt the vehicle counts for the groups.
rubidium <rubidium@openttd.org>
parents:
7526
diff
changeset
|
1241 v->group_id = src->group_id; |
d334553f6db4
(svn r11048) -Fix [FS#1206]: several cases where (re)moving eninges on a train would corrupt the vehicle counts for the groups.
rubidium <rubidium@openttd.org>
parents:
7526
diff
changeset
|
1242 src->group_id = DEFAULT_GROUP; |
6643
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6608
diff
changeset
|
1243 } |
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6608
diff
changeset
|
1244 } |
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6608
diff
changeset
|
1245 |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
1246 if (HasBit(p2, 0)) { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1247 /* unlink ALL wagons */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1248 if (src != src_head) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1249 Vehicle *v = src_head; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1250 while (GetNextVehicle(v) != src) v = GetNextVehicle(v); |
7493
2068a51c2e6c
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium <rubidium@openttd.org>
parents:
7492
diff
changeset
|
1251 GetLastEnginePart(v)->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
|
1252 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1253 InvalidateWindowData(WC_VEHICLE_DEPOT, src_head->tile); // We removed a line |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1254 src_head = NULL; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1255 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1256 } else { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1257 /* if moving within the same chain, dont use dst_head as it may get invalidated */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1258 if (src_head == dst_head) dst_head = NULL; |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1259 /* unlink single wagon from linked 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
|
1260 src_head = UnlinkWagon(src, src_head); |
7493
2068a51c2e6c
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium <rubidium@openttd.org>
parents:
7492
diff
changeset
|
1261 GetLastEnginePart(src)->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
|
1262 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1263 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1264 if (dst == NULL) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1265 /* We make a new line in the depot, so we know already that we invalidate the window data */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1266 InvalidateWindowData(WC_VEHICLE_DEPOT, 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
|
1267 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1268 /* move the train to an empty line. for locomotives, we set the type to TS_Front. for wagons, 4. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1269 if (IsTrainEngine(src)) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1270 if (!IsFrontEngine(src)) { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1271 /* setting the type to 0 also involves setting up the orders field. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1272 SetFrontEngine(src); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1273 assert(src->orders == NULL); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1274 src->num_orders = 0; |
6643
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6608
diff
changeset
|
1275 |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
1276 /* Decrease the engines number of the src engine_type */ |
6643
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6608
diff
changeset
|
1277 if (!IsDefaultGroupID(src->group_id) && IsValidGroupID(src->group_id)) { |
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6608
diff
changeset
|
1278 GetGroup(src->group_id)->num_engines[src->engine_type]--; |
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6608
diff
changeset
|
1279 } |
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6608
diff
changeset
|
1280 |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
1281 /* If we move an engine to a new line affect it to the DEFAULT_GROUP */ |
6643
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6608
diff
changeset
|
1282 src->group_id = DEFAULT_GROUP; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1283 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1284 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1285 SetFreeWagon(src); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1286 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1287 dst_head = src; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1288 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1289 if (IsFrontEngine(src)) { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1290 /* the vehicle was previously a loco. need to free the order list and delete vehicle windows etc. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1291 DeleteWindowById(WC_VEHICLE_VIEW, src->index); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1292 DeleteVehicleOrders(src); |
7529
d334553f6db4
(svn r11048) -Fix [FS#1206]: several cases where (re)moving eninges on a train would corrupt the vehicle counts for the groups.
rubidium <rubidium@openttd.org>
parents:
7526
diff
changeset
|
1293 RemoveVehicleFromGroup(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
|
1294 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1295 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1296 if (IsFrontEngine(src) || IsFreeWagon(src)) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1297 InvalidateWindowData(WC_VEHICLE_DEPOT, 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
|
1298 ClearFrontEngine(src); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1299 ClearFreeWagon(src); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1300 src->unitnumber = 0; // doesn't occupy a unitnumber anymore. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1301 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1302 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1303 /* link in the wagon(s) in the chain. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1304 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1305 Vehicle *v; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1306 |
8695
9ee0730039f4
(svn r12368) -Codechange: use explicit body for loops and conditions and remove -Wno-empty-body from the configure script
smatz <smatz@openttd.org>
parents:
8667
diff
changeset
|
1307 for (v = src; GetNextVehicle(v) != NULL; v = GetNextVehicle(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
|
1308 GetLastEnginePart(v)->SetNext(dst->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
|
1309 } |
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
|
1310 dst->SetNext(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
|
1311 } |
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
|
1312 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1313 if (src->u.rail.other_multiheaded_part != NULL) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1314 if (src->u.rail.other_multiheaded_part == src_head) { |
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
|
1315 src_head = src_head->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
|
1316 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1317 AddWagonToConsist(src->u.rail.other_multiheaded_part, src); |
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1320 /* If there is an engine behind first_engine we moved away, it should become new first_engine |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1321 * To do this, CmdMoveRailVehicle must be called once more |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1322 * we can't loop forever here because next time we reach this line we will have a front engine */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1323 if (src_head != NULL && !IsFrontEngine(src_head) && IsTrainEngine(src_head)) { |
6643
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6608
diff
changeset
|
1324 /* As in CmdMoveRailVehicle src_head->group_id will be equal to DEFAULT_GROUP |
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6608
diff
changeset
|
1325 * we need to save the group and reaffect it to src_head */ |
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6608
diff
changeset
|
1326 const GroupID tmp_g = src_head->group_id; |
10499
45ca88a8de7d
(svn r14754) -Codechange: get rid of _cmd_text and just pass it as (optional) parameter.
rubidium <rubidium@openttd.org>
parents:
10493
diff
changeset
|
1327 CmdMoveRailVehicle(0, flags, src_head->index | (INVALID_VEHICLE << 16), 1, text); |
6643
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6608
diff
changeset
|
1328 SetTrainGroupID(src_head, tmp_g); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1329 src_head = NULL; // don't do anything more to this train since the new call will 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
|
1330 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1331 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1332 if (src_head != NULL) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1333 NormaliseTrainConsist(src_head); |
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
|
1334 TrainConsistChanged(src_head, false); |
6643
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6608
diff
changeset
|
1335 UpdateTrainGroupID(src_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
|
1336 if (IsFrontEngine(src_head)) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1337 /* Update the refit button and window */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1338 InvalidateWindow(WC_VEHICLE_REFIT, src_head->index); |
8350
8cde0dcc6818
(svn r11916) -Codechange: use enums from VehicleViewWindowWidgets instead of constants
smatz <smatz@openttd.org>
parents:
8344
diff
changeset
|
1339 InvalidateWindowWidget(WC_VEHICLE_VIEW, src_head->index, VVW_WIDGET_REFIT_VEH); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1340 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1341 /* Update the depot window */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1342 InvalidateWindow(WC_VEHICLE_DEPOT, src_head->tile); |
6150 | 1343 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1344 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1345 if (dst_head != NULL) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1346 NormaliseTrainConsist(dst_head); |
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
|
1347 TrainConsistChanged(dst_head, false); |
6643
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6608
diff
changeset
|
1348 UpdateTrainGroupID(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
|
1349 if (IsFrontEngine(dst_head)) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1350 /* Update the refit button and window */ |
8350
8cde0dcc6818
(svn r11916) -Codechange: use enums from VehicleViewWindowWidgets instead of constants
smatz <smatz@openttd.org>
parents:
8344
diff
changeset
|
1351 InvalidateWindowWidget(WC_VEHICLE_VIEW, dst_head->index, VVW_WIDGET_REFIT_VEH); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1352 InvalidateWindow(WC_VEHICLE_REFIT, dst_head->index); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1353 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1354 /* Update the depot window */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1355 InvalidateWindow(WC_VEHICLE_DEPOT, dst_head->tile); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1356 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1357 |
9297
add307f2e6ea
(svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium <rubidium@openttd.org>
parents:
9274
diff
changeset
|
1358 InvalidateWindowClassesData(WC_TRAINS_LIST, 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
|
1359 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1360 |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
1361 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
|
1362 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1363 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1364 /** Sell a (single) train wagon/engine. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1365 * @param tile unused |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1366 * @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
|
1367 * @param p1 the wagon/engine index |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1368 * @param p2 the selling mode |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1369 * - p2 = 0: only sell the single dragged wagon/engine (and any belonging rear-engines) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1370 * - p2 = 1: sell the vehicle and all vehicles following it in the chain |
8969
01cc3ee6ecb1
(svn r12761) -Codechange: lots of minor whitespace coding style fixes around operators.
rubidium <rubidium@openttd.org>
parents:
8962
diff
changeset
|
1371 * if the wagon is dragged, don't delete the possibly belonging rear-engine to some 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
|
1372 * - p2 = 2: when selling attached locos, rearrange all vehicles after it to separate lines; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1373 * all wagons of the same type will go on the same line. Used by the AI currently |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1374 */ |
10499
45ca88a8de7d
(svn r14754) -Codechange: get rid of _cmd_text and just pass it as (optional) parameter.
rubidium <rubidium@openttd.org>
parents:
10493
diff
changeset
|
1375 CommandCost CmdSellRailWagon(TileIndex tile, uint32 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
|
1376 { |
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
|
1377 /* 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
|
1378 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
|
1379 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1380 if (!IsValidVehicleID(p1) || p2 > 2) return CMD_ERROR; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1381 |
6150 | 1382 Vehicle *v = GetVehicle(p1); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1383 |
6259
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
1384 if (v->type != VEH_TRAIN || !CheckOwnership(v->owner)) 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
|
1385 |
7695
3d5b53da1837
(svn r11229) -Fix [FS#1307]: one could sell vehicles that were crashed in a depot, which would still yield money.
rubidium <rubidium@openttd.org>
parents:
7642
diff
changeset
|
1386 if (HASBITS(v->vehstatus, VS_CRASHED)) return_cmd_error(STR_CAN_T_SELL_DESTROYED_VEHICLE); |
3d5b53da1837
(svn r11229) -Fix [FS#1307]: one could sell vehicles that were crashed in a depot, which would still yield money.
rubidium <rubidium@openttd.org>
parents:
7642
diff
changeset
|
1387 |
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
|
1388 while (IsArticulatedPart(v)) v = v->Previous(); |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
1389 Vehicle *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
|
1390 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1391 /* make sure the vehicle is stopped in 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
|
1392 if (CheckTrainStoppedInDepot(first) < 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1393 return_cmd_error(STR_881A_TRAINS_CAN_ONLY_BE_ALTERED); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1394 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1395 |
7526
e463f6756541
(svn r11045) -Codechange: added a function to tell if a vehicle is the rear part of a dualheaded train engine
bjarni <bjarni@openttd.org>
parents:
7502
diff
changeset
|
1396 if (IsRearDualheaded(v)) return_cmd_error(STR_REAR_ENGINE_FOLLOW_FRONT_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
|
1397 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1398 if (flags & DC_EXEC) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1399 if (v == first && IsFrontEngine(first)) { |
9274
85a62fb8608f
(svn r13140) -Codechange: move the gui-list-sorting out of window_gui.h so window_gui.h only needs to be included in *_gui.cpp.
rubidium <rubidium@openttd.org>
parents:
9234
diff
changeset
|
1400 DeleteWindowById(WC_VEHICLE_VIEW, first->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
|
1401 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1402 InvalidateWindow(WC_VEHICLE_DEPOT, first->tile); |
9297
add307f2e6ea
(svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium <rubidium@openttd.org>
parents:
9274
diff
changeset
|
1403 InvalidateWindowClassesData(WC_TRAINS_LIST, 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
|
1404 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1405 |
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
|
1406 CommandCost cost(EXPENSES_NEW_VEHICLES); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1407 switch (p2) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1408 case 0: case 2: { /* Delete given wagon */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1409 bool switch_engine = false; // update second wagon to engine? |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1410 byte ori_subtype = v->subtype; // backup subtype of deleted wagon in case DeleteVehicle() changes |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1411 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1412 /* 1. Delete the engine, if it is dualheaded also delete the matching |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1413 * rear engine of the loco (from the point of deletion onwards) */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1414 Vehicle *rear = (IsMultiheaded(v) && |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1415 IsTrainEngine(v)) ? v->u.rail.other_multiheaded_part : NULL; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1416 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1417 if (rear != NULL) { |
6990
a19700261804
(svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium <rubidium@openttd.org>
parents:
6980
diff
changeset
|
1418 cost.AddCost(-rear->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
|
1419 if (flags & DC_EXEC) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1420 UnlinkWagon(rear, first); |
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
|
1421 delete rear; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1422 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1423 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1424 |
10192
1f525fa5fca8
(svn r14405) -Fix [FS#2289]: Correct handling of selling free wagons while the following vehicle is an engine (i.e. a new train is created).
frosch <frosch@openttd.org>
parents:
10190
diff
changeset
|
1425 /* 2. We are selling the front vehicle, some special action might be required |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1426 * here, so take attention */ |
10192
1f525fa5fca8
(svn r14405) -Fix [FS#2289]: Correct handling of selling free wagons while the following vehicle is an engine (i.e. a new train is created).
frosch <frosch@openttd.org>
parents:
10190
diff
changeset
|
1427 if (v == first) { |
6150 | 1428 Vehicle *new_f = GetNextVehicle(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
|
1429 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1430 /* 2.2 If there are wagons present after the deleted front engine, check |
6322
c0b713064125
(svn r9277) -Fix [FS#685]: shared orders got messed up when the 'first' trains got removed in the depot.
rubidium <rubidium@openttd.org>
parents:
6316
diff
changeset
|
1431 * if the second wagon (which will be first) is an engine. If it is one, |
c0b713064125
(svn r9277) -Fix [FS#685]: shared orders got messed up when the 'first' trains got removed in the depot.
rubidium <rubidium@openttd.org>
parents:
6316
diff
changeset
|
1432 * promote it as a new train, retaining the unitnumber, orders */ |
c0b713064125
(svn r9277) -Fix [FS#685]: shared orders got messed up when the 'first' trains got removed in the depot.
rubidium <rubidium@openttd.org>
parents:
6316
diff
changeset
|
1433 if (new_f != NULL && IsTrainEngine(new_f)) { |
10192
1f525fa5fca8
(svn r14405) -Fix [FS#2289]: Correct handling of selling free wagons while the following vehicle is an engine (i.e. a new train is created).
frosch <frosch@openttd.org>
parents:
10190
diff
changeset
|
1434 if (IsTrainEngine(first)) { |
1f525fa5fca8
(svn r14405) -Fix [FS#2289]: Correct handling of selling free wagons while the following vehicle is an engine (i.e. a new train is created).
frosch <frosch@openttd.org>
parents:
10190
diff
changeset
|
1435 /* Let the new front engine take over the setup of the old engine */ |
1f525fa5fca8
(svn r14405) -Fix [FS#2289]: Correct handling of selling free wagons while the following vehicle is an engine (i.e. a new train is created).
frosch <frosch@openttd.org>
parents:
10190
diff
changeset
|
1436 switch_engine = true; |
1f525fa5fca8
(svn r14405) -Fix [FS#2289]: Correct handling of selling free wagons while the following vehicle is an engine (i.e. a new train is created).
frosch <frosch@openttd.org>
parents:
10190
diff
changeset
|
1437 |
1f525fa5fca8
(svn r14405) -Fix [FS#2289]: Correct handling of selling free wagons while the following vehicle is an engine (i.e. a new train is created).
frosch <frosch@openttd.org>
parents:
10190
diff
changeset
|
1438 if (flags & DC_EXEC) { |
1f525fa5fca8
(svn r14405) -Fix [FS#2289]: Correct handling of selling free wagons while the following vehicle is an engine (i.e. a new train is created).
frosch <frosch@openttd.org>
parents:
10190
diff
changeset
|
1439 /* Make sure the group counts stay correct. */ |
1f525fa5fca8
(svn r14405) -Fix [FS#2289]: Correct handling of selling free wagons while the following vehicle is an engine (i.e. a new train is created).
frosch <frosch@openttd.org>
parents:
10190
diff
changeset
|
1440 new_f->group_id = first->group_id; |
1f525fa5fca8
(svn r14405) -Fix [FS#2289]: Correct handling of selling free wagons while the following vehicle is an engine (i.e. a new train is created).
frosch <frosch@openttd.org>
parents:
10190
diff
changeset
|
1441 first->group_id = DEFAULT_GROUP; |
1f525fa5fca8
(svn r14405) -Fix [FS#2289]: Correct handling of selling free wagons while the following vehicle is an engine (i.e. a new train is created).
frosch <frosch@openttd.org>
parents:
10190
diff
changeset
|
1442 |
1f525fa5fca8
(svn r14405) -Fix [FS#2289]: Correct handling of selling free wagons while the following vehicle is an engine (i.e. a new train is created).
frosch <frosch@openttd.org>
parents:
10190
diff
changeset
|
1443 /* Copy orders (by sharing) */ |
1f525fa5fca8
(svn r14405) -Fix [FS#2289]: Correct handling of selling free wagons while the following vehicle is an engine (i.e. a new train is created).
frosch <frosch@openttd.org>
parents:
10190
diff
changeset
|
1444 new_f->orders = first->orders; |
1f525fa5fca8
(svn r14405) -Fix [FS#2289]: Correct handling of selling free wagons while the following vehicle is an engine (i.e. a new train is created).
frosch <frosch@openttd.org>
parents:
10190
diff
changeset
|
1445 new_f->num_orders = first->num_orders; |
1f525fa5fca8
(svn r14405) -Fix [FS#2289]: Correct handling of selling free wagons while the following vehicle is an engine (i.e. a new train is created).
frosch <frosch@openttd.org>
parents:
10190
diff
changeset
|
1446 new_f->AddToShared(first); |
1f525fa5fca8
(svn r14405) -Fix [FS#2289]: Correct handling of selling free wagons while the following vehicle is an engine (i.e. a new train is created).
frosch <frosch@openttd.org>
parents:
10190
diff
changeset
|
1447 DeleteVehicleOrders(first); |
1f525fa5fca8
(svn r14405) -Fix [FS#2289]: Correct handling of selling free wagons while the following vehicle is an engine (i.e. a new train is created).
frosch <frosch@openttd.org>
parents:
10190
diff
changeset
|
1448 |
1f525fa5fca8
(svn r14405) -Fix [FS#2289]: Correct handling of selling free wagons while the following vehicle is an engine (i.e. a new train is created).
frosch <frosch@openttd.org>
parents:
10190
diff
changeset
|
1449 /* Copy other important data from the front engine */ |
1f525fa5fca8
(svn r14405) -Fix [FS#2289]: Correct handling of selling free wagons while the following vehicle is an engine (i.e. a new train is created).
frosch <frosch@openttd.org>
parents:
10190
diff
changeset
|
1450 new_f->CopyVehicleConfigAndStatistics(first); |
1f525fa5fca8
(svn r14405) -Fix [FS#2289]: Correct handling of selling free wagons while the following vehicle is an engine (i.e. a new train is created).
frosch <frosch@openttd.org>
parents:
10190
diff
changeset
|
1451 |
1f525fa5fca8
(svn r14405) -Fix [FS#2289]: Correct handling of selling free wagons while the following vehicle is an engine (i.e. a new train is created).
frosch <frosch@openttd.org>
parents:
10190
diff
changeset
|
1452 /* If we deleted a window then open a new one for the 'new' train */ |
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
|
1453 if (IsLocalCompany() && w != NULL) ShowVehicleViewWindow(new_f); |
10192
1f525fa5fca8
(svn r14405) -Fix [FS#2289]: Correct handling of selling free wagons while the following vehicle is an engine (i.e. a new train is created).
frosch <frosch@openttd.org>
parents:
10190
diff
changeset
|
1454 } |
1f525fa5fca8
(svn r14405) -Fix [FS#2289]: Correct handling of selling free wagons while the following vehicle is an engine (i.e. a new train is created).
frosch <frosch@openttd.org>
parents:
10190
diff
changeset
|
1455 } else { |
1f525fa5fca8
(svn r14405) -Fix [FS#2289]: Correct handling of selling free wagons while the following vehicle is an engine (i.e. a new train is created).
frosch <frosch@openttd.org>
parents:
10190
diff
changeset
|
1456 /* We are selling a free wagon, and construct a new train at the same time. |
1f525fa5fca8
(svn r14405) -Fix [FS#2289]: Correct handling of selling free wagons while the following vehicle is an engine (i.e. a new train is created).
frosch <frosch@openttd.org>
parents:
10190
diff
changeset
|
1457 * This needs lots of extra checks (e.g. train limit), which are done by first moving |
1f525fa5fca8
(svn r14405) -Fix [FS#2289]: Correct handling of selling free wagons while the following vehicle is an engine (i.e. a new train is created).
frosch <frosch@openttd.org>
parents:
10190
diff
changeset
|
1458 * the remaining vehicles to a new row */ |
1f525fa5fca8
(svn r14405) -Fix [FS#2289]: Correct handling of selling free wagons while the following vehicle is an engine (i.e. a new train is created).
frosch <frosch@openttd.org>
parents:
10190
diff
changeset
|
1459 cost.AddCost(DoCommand(0, new_f->index | INVALID_VEHICLE << 16, 1, flags, CMD_MOVE_RAIL_VEHICLE)); |
1f525fa5fca8
(svn r14405) -Fix [FS#2289]: Correct handling of selling free wagons while the following vehicle is an engine (i.e. a new train is created).
frosch <frosch@openttd.org>
parents:
10190
diff
changeset
|
1460 if (cost.Failed()) return cost; |
1f525fa5fca8
(svn r14405) -Fix [FS#2289]: Correct handling of selling free wagons while the following vehicle is an engine (i.e. a new train is created).
frosch <frosch@openttd.org>
parents:
10190
diff
changeset
|
1461 } |
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 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1464 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1465 /* 3. Delete the requested wagon */ |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
1466 cost.AddCost(-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
|
1467 if (flags & DC_EXEC) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1468 first = UnlinkWagon(v, first); |
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
|
1469 delete 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
|
1470 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1471 /* 4 If the second wagon was an engine, update it to front_engine |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
1472 * which UnlinkWagon() has changed to TS_Free_Car */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1473 if (switch_engine) SetFrontEngine(first); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1474 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1475 /* 5. If the train still exists, update its acceleration, window, etc. */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1476 if (first != NULL) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1477 NormaliseTrainConsist(first); |
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
|
1478 TrainConsistChanged(first, false); |
6643
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6608
diff
changeset
|
1479 UpdateTrainGroupID(first); |
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
|
1480 if (IsFrontEngine(first)) InvalidateWindow(WC_VEHICLE_REFIT, first->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
|
1481 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1482 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1483 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1484 /* (6.) Borked AI. If it sells an engine it expects all wagons lined |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1485 * up on a new line to be added to the newly built loco. Replace it is. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1486 * Totally braindead cause building a new engine adds all loco-less |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1487 * engines to its train anyways */ |
8612
3171ca9f0252
(svn r12194) -Codechange: apply coding style on enum TrainSubtype
smatz <smatz@openttd.org>
parents:
8607
diff
changeset
|
1488 if (p2 == 2 && HasBit(ori_subtype, TS_FRONT)) { |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
1489 for (v = first; v != NULL;) { |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
1490 Vehicle *tmp = GetNextVehicle(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
|
1491 DoCommand(v->tile, v->index | INVALID_VEHICLE << 16, 0, DC_EXEC, CMD_MOVE_RAIL_VEHICLE); |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
1492 v = tmp; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1493 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1494 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1495 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1496 } break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1497 case 1: { /* Delete wagon and all wagons after it given certain criteria */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1498 /* Start deleting every vehicle after the selected one |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1499 * If we encounter a matching rear-engine to a front-engine |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1500 * earlier in the chain (before deletion), leave it alone */ |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
1501 for (Vehicle *tmp; v != NULL; v = tmp) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1502 tmp = GetNextVehicle(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1503 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1504 if (IsMultiheaded(v)) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1505 if (IsTrainEngine(v)) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1506 /* We got a front engine of a multiheaded set. Now we will sell the rear end too */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1507 Vehicle *rear = v->u.rail.other_multiheaded_part; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1508 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1509 if (rear != NULL) { |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
1510 cost.AddCost(-rear->value); |
6785
a2a5b482c84f
(svn r10023) -Fix (r3218): When selling trains, if there were no wagons between multiheaded
maedhros <maedhros@openttd.org>
parents:
6784
diff
changeset
|
1511 |
a2a5b482c84f
(svn r10023) -Fix (r3218): When selling trains, if there were no wagons between multiheaded
maedhros <maedhros@openttd.org>
parents:
6784
diff
changeset
|
1512 /* If this is a multiheaded vehicle with nothing |
a2a5b482c84f
(svn r10023) -Fix (r3218): When selling trains, if there were no wagons between multiheaded
maedhros <maedhros@openttd.org>
parents:
6784
diff
changeset
|
1513 * between the parts, tmp will be pointing to the |
a2a5b482c84f
(svn r10023) -Fix (r3218): When selling trains, if there were no wagons between multiheaded
maedhros <maedhros@openttd.org>
parents:
6784
diff
changeset
|
1514 * rear part, which is unlinked from the train and |
a2a5b482c84f
(svn r10023) -Fix (r3218): When selling trains, if there were no wagons between multiheaded
maedhros <maedhros@openttd.org>
parents:
6784
diff
changeset
|
1515 * deleted here. However, because tmp has already |
a2a5b482c84f
(svn r10023) -Fix (r3218): When selling trains, if there were no wagons between multiheaded
maedhros <maedhros@openttd.org>
parents:
6784
diff
changeset
|
1516 * been set it needs to be updated now so that the |
a2a5b482c84f
(svn r10023) -Fix (r3218): When selling trains, if there were no wagons between multiheaded
maedhros <maedhros@openttd.org>
parents:
6784
diff
changeset
|
1517 * loop never sees the rear part. */ |
a2a5b482c84f
(svn r10023) -Fix (r3218): When selling trains, if there were no wagons between multiheaded
maedhros <maedhros@openttd.org>
parents:
6784
diff
changeset
|
1518 if (tmp == rear) tmp = GetNextVehicle(tmp); |
a2a5b482c84f
(svn r10023) -Fix (r3218): When selling trains, if there were no wagons between multiheaded
maedhros <maedhros@openttd.org>
parents:
6784
diff
changeset
|
1519 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1520 if (flags & DC_EXEC) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1521 first = UnlinkWagon(rear, first); |
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
|
1522 delete rear; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1523 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1524 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1525 } else if (v->u.rail.other_multiheaded_part != NULL) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1526 /* The front to this engine is earlier in this train. Do nothing */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1527 continue; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1528 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1529 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1530 |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
1531 cost.AddCost(-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
|
1532 if (flags & DC_EXEC) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1533 first = UnlinkWagon(v, first); |
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
|
1534 delete 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
|
1535 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1536 } |
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 /* 3. If it is still a valid train after selling, update its acceleration and cached values */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1539 if (flags & DC_EXEC && first != NULL) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1540 NormaliseTrainConsist(first); |
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
|
1541 TrainConsistChanged(first, false); |
6643
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6608
diff
changeset
|
1542 UpdateTrainGroupID(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
|
1543 InvalidateWindow(WC_VEHICLE_REFIT, first->index); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1544 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1545 } break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1546 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1547 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
|
1548 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1549 |
6558
2fc024ee8217
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium <rubidium@openttd.org>
parents:
6554
diff
changeset
|
1550 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
|
1551 { |
6558
2fc024ee8217
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium <rubidium@openttd.org>
parents:
6554
diff
changeset
|
1552 #define MKIT(a, b, c, d) ((a & 0xFF) << 24) | ((b & 0xFF) << 16) | ((c & 0xFF) << 8) | ((d & 0xFF) << 0) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1553 static const uint32 _delta_xy_table[8] = { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1554 MKIT(3, 3, -1, -1), |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1555 MKIT(3, 7, -1, -3), |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1556 MKIT(3, 3, -1, -1), |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1557 MKIT(7, 3, -3, -1), |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1558 MKIT(3, 3, -1, -1), |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1559 MKIT(3, 7, -1, -3), |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1560 MKIT(3, 3, -1, -1), |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1561 MKIT(7, 3, -3, -1), |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1562 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1563 #undef MKIT |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1564 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1565 uint32 x = _delta_xy_table[direction]; |
6558
2fc024ee8217
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium <rubidium@openttd.org>
parents:
6554
diff
changeset
|
1566 this->x_offs = GB(x, 0, 8); |
2fc024ee8217
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium <rubidium@openttd.org>
parents:
6554
diff
changeset
|
1567 this->y_offs = GB(x, 8, 8); |
8793
27556e5b9388
(svn r12531) -Codechange: Rename some variables for consistency.
frosch <frosch@openttd.org>
parents:
8786
diff
changeset
|
1568 this->x_extent = GB(x, 16, 8); |
27556e5b9388
(svn r12531) -Codechange: Rename some variables for consistency.
frosch <frosch@openttd.org>
parents:
8786
diff
changeset
|
1569 this->y_extent = GB(x, 24, 8); |
27556e5b9388
(svn r12531) -Codechange: Rename some variables for consistency.
frosch <frosch@openttd.org>
parents:
8786
diff
changeset
|
1570 this->z_extent = 6; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1571 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1572 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1573 static void UpdateVarsAfterSwap(Vehicle *v) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1574 { |
6558
2fc024ee8217
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium <rubidium@openttd.org>
parents:
6554
diff
changeset
|
1575 v->UpdateDeltaXY(v->direction); |
7134
e1c4f52f82cd
(svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium <rubidium@openttd.org>
parents:
7109
diff
changeset
|
1576 v->cur_image = v->GetImage(v->direction); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1577 BeginVehicleMove(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1578 VehiclePositionChanged(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1579 EndVehicleMove(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1580 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1581 |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
1582 static inline void SetLastSpeed(Vehicle *v, int 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
|
1583 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1584 int old = v->u.rail.last_speed; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1585 if (spd != old) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1586 v->u.rail.last_speed = spd; |
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
|
1587 if (_settings_client.gui.vehicle_speed || (old == 0) != (spd == 0)) { |
8350
8cde0dcc6818
(svn r11916) -Codechange: use enums from VehicleViewWindowWidgets instead of constants
smatz <smatz@openttd.org>
parents:
8344
diff
changeset
|
1588 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
1589 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1590 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1591 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1592 |
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
|
1593 /** Mark a train as stuck and stop it if it isn't stopped right now. */ |
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
|
1594 static void MarkTrainAsStuck(Vehicle *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
|
1595 { |
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
|
1596 if (!HasBit(v->u.rail.flags, VRF_TRAIN_STUCK)) { |
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
|
1597 /* It is the first time the problem occured, set the "train stuck" flag. */ |
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
|
1598 SetBit(v->u.rail.flags, VRF_TRAIN_STUCK); |
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
|
1599 v->load_unload_time_rem = 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
|
1600 |
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
|
1601 /* 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
|
1602 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
|
1603 v->subspeed = 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
|
1604 SetLastSpeed(v, 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
|
1605 |
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
|
1606 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
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
|
1607 } |
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
|
1608 } |
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
|
1609 |
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
|
1610 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
|
1611 { |
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
|
1612 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
|
1613 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
|
1614 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1615 /* Clear the flags */ |
7929
4d13dbed828c
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7928
diff
changeset
|
1616 ClrBit(*swap_flag1, VRF_GOINGUP); |
4d13dbed828c
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7928
diff
changeset
|
1617 ClrBit(*swap_flag1, VRF_GOINGDOWN); |
4d13dbed828c
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7928
diff
changeset
|
1618 ClrBit(*swap_flag2, VRF_GOINGUP); |
4d13dbed828c
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7928
diff
changeset
|
1619 ClrBit(*swap_flag2, VRF_GOINGDOWN); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1620 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1621 /* Reverse the rail-flags (if needed) */ |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
1622 if (HasBit(flag1, VRF_GOINGUP)) { |
7931
44ff7a6d801f
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7929
diff
changeset
|
1623 SetBit(*swap_flag2, VRF_GOINGDOWN); |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
1624 } else if (HasBit(flag1, VRF_GOINGDOWN)) { |
7931
44ff7a6d801f
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7929
diff
changeset
|
1625 SetBit(*swap_flag2, VRF_GOINGUP); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1626 } |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
1627 if (HasBit(flag2, VRF_GOINGUP)) { |
7931
44ff7a6d801f
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7929
diff
changeset
|
1628 SetBit(*swap_flag1, VRF_GOINGDOWN); |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
1629 } else if (HasBit(flag2, VRF_GOINGDOWN)) { |
7931
44ff7a6d801f
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7929
diff
changeset
|
1630 SetBit(*swap_flag1, VRF_GOINGUP); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1631 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1632 } |
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 static void ReverseTrainSwapVeh(Vehicle *v, int l, int r) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1635 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1636 Vehicle *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
|
1637 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1638 /* 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
|
1639 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
|
1640 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
|
1641 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1642 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
|
1643 /* 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
|
1644 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1645 uint16 tmp = (a->vehstatus & ~VS_HIDDEN) | (b->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
|
1646 b->vehstatus = (b->vehstatus & ~VS_HIDDEN) | (a->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
|
1647 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
|
1648 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1649 |
5733 | 1650 Swap(a->u.rail.track, b->u.rail.track); |
1651 Swap(a->direction, b->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
|
1652 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1653 /* toggle direction */ |
5993
2498be7c7e94
(svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium <rubidium@openttd.org>
parents:
5992
diff
changeset
|
1654 if (a->u.rail.track != TRACK_BIT_DEPOT) a->direction = ReverseDir(a->direction); |
2498be7c7e94
(svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium <rubidium@openttd.org>
parents:
5992
diff
changeset
|
1655 if (b->u.rail.track != TRACK_BIT_DEPOT) b->direction = ReverseDir(b->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
|
1656 |
5733 | 1657 Swap(a->x_pos, b->x_pos); |
1658 Swap(a->y_pos, b->y_pos); | |
1659 Swap(a->tile, b->tile); | |
1660 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
|
1661 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1662 SwapTrainFlags(&a->u.rail.flags, &b->u.rail.flags); |
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 /* update other vars */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1665 UpdateVarsAfterSwap(a); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1666 UpdateVarsAfterSwap(b); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1667 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1668 /* call the proper EnterTile function unless we are in a wormhole */ |
5993
2498be7c7e94
(svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium <rubidium@openttd.org>
parents:
5992
diff
changeset
|
1669 if (a->u.rail.track != TRACK_BIT_WORMHOLE) VehicleEnterTile(a, a->tile, a->x_pos, a->y_pos); |
2498be7c7e94
(svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium <rubidium@openttd.org>
parents:
5992
diff
changeset
|
1670 if (b->u.rail.track != TRACK_BIT_WORMHOLE) VehicleEnterTile(b, b->tile, b->x_pos, b->y_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
|
1671 } else { |
5993
2498be7c7e94
(svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium <rubidium@openttd.org>
parents:
5992
diff
changeset
|
1672 if (a->u.rail.track != TRACK_BIT_DEPOT) a->direction = ReverseDir(a->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
|
1673 UpdateVarsAfterSwap(a); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1674 |
5993
2498be7c7e94
(svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium <rubidium@openttd.org>
parents:
5992
diff
changeset
|
1675 if (a->u.rail.track != TRACK_BIT_WORMHOLE) VehicleEnterTile(a, a->tile, a->x_pos, a->y_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
|
1676 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1677 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1678 /* Update train's power incase tiles were different rail type */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1679 TrainPowerChanged(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1680 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1681 |
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
|
1682 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1683 /** |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1684 * 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
|
1685 * @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
|
1686 * @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
|
1687 */ |
9775
c3caa51b9888
(svn r13912) -Codechange: remove some casts by returning the proper type instead of void*.
rubidium <rubidium@openttd.org>
parents:
9774
diff
changeset
|
1688 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
|
1689 { |
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
|
1690 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
|
1691 } |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1692 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1693 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1694 /** |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1695 * 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
|
1696 * @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
|
1697 * @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
|
1698 * @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
|
1699 */ |
9775
c3caa51b9888
(svn r13912) -Codechange: remove some casts by returning the proper type instead of void*.
rubidium <rubidium@openttd.org>
parents:
9774
diff
changeset
|
1700 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
|
1701 { |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1702 /* not a train || not front engine || 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
|
1703 if (v->type != VEH_TRAIN || !IsFrontEngine(v) || v->vehstatus & VS_CRASHED) return 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
|
1704 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1705 TileIndex tile = *(TileIndex*)data; |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1706 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1707 if (TrainApproachingCrossingTile(v) != tile) return 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
|
1708 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1709 return v; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1710 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1711 |
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
|
1712 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1713 /** |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1714 * 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
|
1715 * @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
|
1716 * @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
|
1717 * @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
|
1718 */ |
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
|
1719 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
|
1720 { |
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
|
1721 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
|
1722 |
8598
ef2c93a9589d
(svn r12179) -Codechange: use GetCrossingRailTrack() and GetCrossingRailAxis() to improve code readability
smatz <smatz@openttd.org>
parents:
8597
diff
changeset
|
1723 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
|
1724 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
|
1725 |
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
|
1726 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
|
1727 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1728 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
|
1729 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
|
1730 |
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
|
1731 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
|
1732 } |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1733 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1734 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1735 /** |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1736 * 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
|
1737 * @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
|
1738 * @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
|
1739 * @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
|
1740 */ |
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
|
1741 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
|
1742 { |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1743 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
|
1744 |
9824
fe3562a51648
(svn r13966) -Codechange [YAPP]: Bar level crossings upon path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9822
diff
changeset
|
1745 /* train on crossing || train approaching crossing || reserved */ |
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
|
1746 bool new_state = HasVehicleOnPos(tile, NULL, &TrainOnTileEnum) || TrainApproachingCrossing(tile) || GetCrossingReservation(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
|
1747 |
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
|
1748 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
|
1749 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
|
1750 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
|
1751 } |
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
|
1752 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
|
1753 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
|
1754 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1755 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1756 |
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
|
1757 |
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 /** |
8356
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1759 * 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
|
1760 * @param tile tile with crossing |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1761 * @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
|
1762 */ |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1763 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
|
1764 { |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1765 if (!IsCrossingBarred(tile)) { |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1766 BarCrossing(tile); |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1767 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
|
1768 MarkTileDirtyByTile(tile); |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1769 } |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1770 } |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1771 |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1772 |
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1773 /** |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1774 * 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
|
1775 * 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
|
1776 * @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
|
1777 */ |
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
|
1778 static void AdvanceWagonsBeforeSwap(Vehicle *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
|
1779 { |
6150 | 1780 Vehicle *base = 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
|
1781 Vehicle *first = base; // first vehicle to move |
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
|
1782 Vehicle *last = GetLastVehicleInChain(v); // last vehicle to move |
6150 | 1783 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
|
1784 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1785 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
|
1786 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
|
1787 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
|
1788 |
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
|
1789 int differential = base->u.rail.cached_veh_length - last->u.rail.cached_veh_length; |
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
|
1790 |
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
|
1791 /* 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
|
1792 * negative differential will be handled in AdvanceWagonsAfterSwap() */ |
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
|
1793 for (int i = 0; i < differential; i++) TrainController(first, last->Next(), false); |
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
|
1794 |
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
|
1795 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
|
1796 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
|
1797 } |
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
|
1798 } |
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
|
1799 |
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
|
1800 |
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
|
1801 /** |
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
|
1802 * 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
|
1803 * 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
|
1804 * @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
|
1805 */ |
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
|
1806 static void AdvanceWagonsAfterSwap(Vehicle *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
|
1807 { |
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
|
1808 /* first of all, fix the situation when the train was entering 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
|
1809 Vehicle *dep = v; // last vehicle in front of just left 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
|
1810 while (dep->Next() != NULL && (dep->u.rail.track == TRACK_BIT_DEPOT || dep->Next()->u.rail.track != TRACK_BIT_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
|
1811 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
|
1812 } |
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
|
1813 |
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
|
1814 Vehicle *leave = dep->Next(); // first vehicle in a depot we are leaving 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
|
1815 |
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
|
1816 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
|
1817 /* '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
|
1818 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
|
1819 |
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
|
1820 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
|
1821 leave->vehstatus &= ~VS_HIDDEN; // move it out of the depot |
9224
c8a0fa0e208a
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz <smatz@openttd.org>
parents:
9222
diff
changeset
|
1822 leave->u.rail.track = TrackToTrackBits(GetRailDepotTrack(leave->tile)); |
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
|
1823 for (int i = 0; i >= d; i--) TrainController(leave, NULL, false); // maybe move it, and maybe let another wagon leave |
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
|
1824 } |
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
|
1825 } 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
|
1826 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
|
1827 } |
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
|
1828 |
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
|
1829 Vehicle *base = 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
|
1830 Vehicle *first = base; // first vehicle to move |
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
|
1831 Vehicle *last = GetLastVehicleInChain(v); // last vehicle to move |
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
|
1832 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
|
1833 |
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
|
1834 /* we have to make sure all wagons that leave a depot because of train reversing are moved coorectly |
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
|
1835 * they have already correct spacing, so we have to make sure they are moved how they should */ |
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
|
1836 bool nomove = (dep == NULL); // if there is no vehicle leaving a depot, limit the number of wagons moved immediatelly |
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
|
1837 |
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
|
1838 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
|
1839 /* we reached vehicle (originally) in front of a depot, stop 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
|
1840 * (we would move wagons that are alredy moved with new wagon length) */ |
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
|
1841 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
|
1842 |
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
|
1843 /* 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
|
1844 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
|
1845 |
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
|
1846 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
|
1847 first = first->Next(); |
6150 | 1848 |
1849 int differential = last->u.rail.cached_veh_length - base->u.rail.cached_veh_length; | |
8712
b5b3d75eb7db
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
smatz <smatz@openttd.org>
parents:
8710
diff
changeset
|
1850 |
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
|
1851 /* 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
|
1852 for (int i = 0; i < differential; i++) TrainController(first, (nomove ? last->Next() : NULL), false); |
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
|
1853 |
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
|
1854 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
|
1855 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
|
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 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1858 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1859 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1860 static void ReverseTrainDirection(Vehicle *v) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1861 { |
8961
b33bcd7fa037
(svn r12753) -Codechange: do not use IsDepotTypeTile() where simpler function can be used
smatz <smatz@openttd.org>
parents:
8954
diff
changeset
|
1862 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
|
1863 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
|
1864 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1865 |
9819
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1866 /* Clear path reservation in front. */ |
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1867 FreeTrainTrackReservation(v); |
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1868 |
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 /* 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
|
1870 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
|
1871 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1872 /* count number of vehicles */ |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
1873 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
|
1874 |
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
|
1875 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
|
1876 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1877 /* swap start<>end, start+1<>end-1, ... */ |
6150 | 1878 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
|
1879 do { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1880 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
|
1881 } 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
|
1882 |
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
|
1883 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
|
1884 |
8961
b33bcd7fa037
(svn r12753) -Codechange: do not use IsDepotTypeTile() where simpler function can be used
smatz <smatz@openttd.org>
parents:
8954
diff
changeset
|
1885 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
|
1886 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
|
1887 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1888 |
8938
46aa51321117
(svn r12711) -Codechange: remove unneeded loops
glx <glx@openttd.org>
parents:
8928
diff
changeset
|
1889 ToggleBit(v->u.rail.flags, VRF_TOGGLE_REVERSE); |
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
|
1890 |
7929
4d13dbed828c
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7928
diff
changeset
|
1891 ClrBit(v->u.rail.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
|
1892 |
8667
4e73621c3950
(svn r12332) -Fix (r12331): Invalidate cached data and update image after setting flag.
peter1138 <peter1138@openttd.org>
parents:
8666
diff
changeset
|
1893 /* recalculate cached data */ |
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
|
1894 TrainConsistChanged(v, true); |
8667
4e73621c3950
(svn r12332) -Fix (r12331): Invalidate cached data and update image after setting flag.
peter1138 <peter1138@openttd.org>
parents:
8666
diff
changeset
|
1895 |
4e73621c3950
(svn r12332) -Fix (r12331): Invalidate cached data and update image after setting flag.
peter1138 <peter1138@openttd.org>
parents:
8666
diff
changeset
|
1896 /* update all images */ |
4e73621c3950
(svn r12332) -Fix (r12331): Invalidate cached data and update image after setting flag.
peter1138 <peter1138@openttd.org>
parents:
8666
diff
changeset
|
1897 for (Vehicle *u = v; u != NULL; u = u->Next()) u->cur_image = u->GetImage(u->direction); |
4e73621c3950
(svn r12332) -Fix (r12331): Invalidate cached data and update image after setting flag.
peter1138 <peter1138@openttd.org>
parents:
8666
diff
changeset
|
1898 |
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
|
1899 /* 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
|
1900 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
|
1901 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1902 /* 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
|
1903 crossing = TrainApproachingCrossingTile(v); |
8356
68587b4684d2
(svn r11922) -Codechange: use MaybeBarCrossingWithSound() to bar crossing with sound
smatz <smatz@openttd.org>
parents:
8350
diff
changeset
|
1904 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
|
1905 |
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1906 /* If we are inside a depot after reversing, don't bother with path reserving. */ |
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
|
1907 if (v->u.rail.track & TRACK_BIT_DEPOT) { |
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
|
1908 /* Can't be stuck here as inside a depot is always a safe tile. */ |
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
|
1909 if (HasBit(v->u.rail.flags, VRF_TRAIN_STUCK)) InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
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
|
1910 ClrBit(v->u.rail.flags, VRF_TRAIN_STUCK); |
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
|
1911 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
|
1912 } |
9819
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1913 |
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1914 /* 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
|
1915 * tunnels/bridges that is needed for UpdateSignalsOnSegment. */ |
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1916 DiagDirection dir = TrainExitDir(v->direction, v->u.rail.track); |
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1917 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
|
1918 |
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1919 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
|
1920 /* 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
|
1921 * 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
|
1922 bool first_tile_okay = !(IsTileType(v->tile, MP_RAILWAY) && |
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1923 HasSignalOnTrackdir(v->tile, GetVehicleTrackdir(v)) && |
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1924 !IsPbsSignal(GetSignalType(v->tile, FindFirstTrack(v->u.rail.track)))); |
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1925 |
9874
f6aeb086fbba
(svn r14021) -Fix (r13957) [YAPP]: Overbuilding station tiles with non-track tiles could produce stale reservations. (michi_cc)
smatz <smatz@openttd.org>
parents:
9857
diff
changeset
|
1926 if (IsRailwayStationTile(v->tile)) SetRailwayStationPlatformReservation(v->tile, TrackdirToExitdir(GetVehicleTrackdir(v)), 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
|
1927 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
|
1928 /* 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
|
1929 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
|
1930 } 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
|
1931 /* 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
|
1932 MarkTrainAsStuck(v); |
9819
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1933 } |
ec8a4c799a44
(svn r13961) -Add [YAPP]: Handle train reversing. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9818
diff
changeset
|
1934 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1935 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1936 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1937 /** Reverse train. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1938 * @param tile unused |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1939 * @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
|
1940 * @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
|
1941 * @param p2 if true, reverse a unit in a train (needs to be in a depot) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1942 */ |
10499
45ca88a8de7d
(svn r14754) -Codechange: get rid of _cmd_text and just pass it as (optional) parameter.
rubidium <rubidium@openttd.org>
parents:
10493
diff
changeset
|
1943 CommandCost CmdReverseTrainDirection(TileIndex tile, uint32 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
|
1944 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1945 if (!IsValidVehicleID(p1)) return CMD_ERROR; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1946 |
6150 | 1947 Vehicle *v = GetVehicle(p1); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1948 |
6259
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
1949 if (v->type != VEH_TRAIN || !CheckOwnership(v->owner)) 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
|
1950 |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
1951 if (p2 != 0) { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1952 /* 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
|
1953 |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
1954 if (IsMultiheaded(v) || HasBit(EngInfo(v->engine_type)->callbackmask, CBM_VEHICLE_ARTIC_ENGINE)) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1955 return_cmd_error(STR_ONLY_TURN_SINGLE_UNIT); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1956 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1957 |
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
|
1958 Vehicle *front = v->First(); |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1959 /* make sure the vehicle is stopped in 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
|
1960 if (CheckTrainStoppedInDepot(front) < 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1961 return_cmd_error(STR_881A_TRAINS_CAN_ONLY_BE_ALTERED); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1962 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1963 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1964 if (flags & DC_EXEC) { |
7932
712f252f0d4d
(svn r11485) -Codechange: Remove the doubled function ToggleBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7931
diff
changeset
|
1965 ToggleBit(v->u.rail.flags, VRF_REVERSE_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
|
1966 InvalidateWindow(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
|
1967 InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1968 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1969 } 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
|
1970 /* turn the whole train around */ |
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
|
1971 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
|
1972 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1973 if (flags & DC_EXEC) { |
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
|
1974 if (_settings_game.vehicle.realistic_acceleration && v->cur_speed != 0) { |
7932
712f252f0d4d
(svn r11485) -Codechange: Remove the doubled function ToggleBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7931
diff
changeset
|
1975 ToggleBit(v->u.rail.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
|
1976 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1977 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
|
1978 SetLastSpeed(v, 0); |
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
|
1979 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
|
1980 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
|
1981 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1982 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1983 } |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
1984 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
|
1985 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1986 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1987 /** Force a train through a 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
|
1988 * @param tile unused |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
1989 * @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
|
1990 * @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
|
1991 * @param p2 unused |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1992 */ |
10499
45ca88a8de7d
(svn r14754) -Codechange: get rid of _cmd_text and just pass it as (optional) parameter.
rubidium <rubidium@openttd.org>
parents:
10493
diff
changeset
|
1993 CommandCost CmdForceTrainProceed(TileIndex tile, uint32 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
|
1994 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1995 if (!IsValidVehicleID(p1)) return CMD_ERROR; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1996 |
6150 | 1997 Vehicle *v = GetVehicle(p1); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1998 |
6259
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
1999 if (v->type != VEH_TRAIN || !CheckOwnership(v->owner)) 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
|
2000 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2001 if (flags & DC_EXEC) v->u.rail.force_proceed = 0x50; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2002 |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
2003 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
|
2004 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2005 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2006 /** Refits a train to the specified 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
|
2007 * @param tile unused |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2008 * @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
|
2009 * @param p1 vehicle ID of the train to refit |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2010 * param p2 various bitstuffed elements |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2011 * - p2 = (bit 0-7) - the new cargo type to refit to |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2012 * - p2 = (bit 8-15) - the new cargo subtype to refit to |
6546
0f78a0fe6568
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros <maedhros@openttd.org>
parents:
6502
diff
changeset
|
2013 * - p2 = (bit 16) - refit only this vehicle |
0f78a0fe6568
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros <maedhros@openttd.org>
parents:
6502
diff
changeset
|
2014 * @return cost of refit or 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
|
2015 */ |
10499
45ca88a8de7d
(svn r14754) -Codechange: get rid of _cmd_text and just pass it as (optional) parameter.
rubidium <rubidium@openttd.org>
parents:
10493
diff
changeset
|
2016 CommandCost CmdRefitRailVehicle(TileIndex tile, uint32 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
|
2017 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2018 CargoID new_cid = GB(p2, 0, 8); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2019 byte new_subtype = GB(p2, 8, 8); |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
2020 bool only_this = HasBit(p2, 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
|
2021 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2022 if (!IsValidVehicleID(p1)) return CMD_ERROR; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2023 |
6150 | 2024 Vehicle *v = GetVehicle(p1); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2025 |
6259
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
2026 if (v->type != VEH_TRAIN || !CheckOwnership(v->owner)) 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
|
2027 if (CheckTrainStoppedInDepot(v) < 0) return_cmd_error(STR_TRAIN_MUST_BE_STOPPED); |
8145
7f916a303303
(svn r11707) -Fix: do not allow refitting flooded (destroyed) vehicles
smatz <smatz@openttd.org>
parents:
8144
diff
changeset
|
2028 if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_CAN_T_REFIT_DESTROYED_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
|
2029 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2030 /* Check cargo */ |
6316
8ecb7b1dea16
(svn r9259) -Codechange: NUM_CARGO isn't a valid cargo type...
peter1138 <peter1138@openttd.org>
parents:
6303
diff
changeset
|
2031 if (new_cid >= NUM_CARGO) 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
|
2032 |
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
|
2033 CommandCost cost(EXPENSES_TRAIN_RUN); |
6150 | 2034 uint num = 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
|
2035 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2036 do { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2037 /* XXX: We also refit all the attached wagons en-masse if they |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2038 * can be refitted. This is how TTDPatch does it. TODO: Have |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2039 * some nice [Refit] button near each wagon. --pasky */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2040 if (!CanRefitTo(v->engine_type, new_cid)) continue; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2041 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2042 if (v->cargo_cap != 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2043 uint16 amount = CALLBACK_FAILED; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2044 |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
2045 if (HasBit(EngInfo(v->engine_type)->callbackmask, CBM_VEHICLE_REFIT_CAPACITY)) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2046 /* Back up the vehicle's 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
|
2047 CargoID temp_cid = 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
|
2048 byte temp_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
|
2049 v->cargo_type = new_cid; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2050 v->cargo_subtype = new_subtype; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2051 /* Check the refit capacity callback */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2052 amount = GetVehicleCallback(CBID_VEHICLE_REFIT_CAPACITY, 0, 0, v->engine_type, v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2053 /* Restore the original 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
|
2054 v->cargo_type = temp_cid; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2055 v->cargo_subtype = temp_subtype; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2056 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2057 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2058 if (amount == CALLBACK_FAILED) { // callback failed or not used, use default |
6150 | 2059 const RailVehicleInfo *rvi = RailVehInfo(v->engine_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
|
2060 CargoID old_cid = rvi->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
|
2061 /* normally, the capacity depends on the cargo type, a rail vehicle can |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2062 * carry twice as much mail/goods as normal cargo, and four times as |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2063 * many passengers |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2064 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2065 amount = rvi->capacity; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2066 switch (old_cid) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2067 case CT_PASSENGERS: break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2068 case CT_MAIL: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2069 case CT_GOODS: amount *= 2; break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2070 default: amount *= 4; break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2071 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2072 switch (new_cid) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2073 case CT_PASSENGERS: break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2074 case CT_MAIL: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2075 case CT_GOODS: amount /= 2; break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2076 default: amount /= 4; break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2077 } |
6150 | 2078 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2079 |
10328
049acde11ee2
(svn r14578) -Fix (r2389, r10811)[FS#Vikthor]: Allow capacity callbacks (15, 36) to return zero capacity.
frosch <frosch@openttd.org>
parents:
10314
diff
changeset
|
2080 if (new_cid != v->cargo_type) { |
049acde11ee2
(svn r14578) -Fix (r2389, r10811)[FS#Vikthor]: Allow capacity callbacks (15, 36) to return zero capacity.
frosch <frosch@openttd.org>
parents:
10314
diff
changeset
|
2081 cost.AddCost(GetRefitCost(v->engine_type)); |
049acde11ee2
(svn r14578) -Fix (r2389, r10811)[FS#Vikthor]: Allow capacity callbacks (15, 36) to return zero capacity.
frosch <frosch@openttd.org>
parents:
10314
diff
changeset
|
2082 } |
049acde11ee2
(svn r14578) -Fix (r2389, r10811)[FS#Vikthor]: Allow capacity callbacks (15, 36) to return zero capacity.
frosch <frosch@openttd.org>
parents:
10314
diff
changeset
|
2083 |
049acde11ee2
(svn r14578) -Fix (r2389, r10811)[FS#Vikthor]: Allow capacity callbacks (15, 36) to return zero capacity.
frosch <frosch@openttd.org>
parents:
10314
diff
changeset
|
2084 num += amount; |
049acde11ee2
(svn r14578) -Fix (r2389, r10811)[FS#Vikthor]: Allow capacity callbacks (15, 36) to return zero capacity.
frosch <frosch@openttd.org>
parents:
10314
diff
changeset
|
2085 if (flags & DC_EXEC) { |
049acde11ee2
(svn r14578) -Fix (r2389, r10811)[FS#Vikthor]: Allow capacity callbacks (15, 36) to return zero capacity.
frosch <frosch@openttd.org>
parents:
10314
diff
changeset
|
2086 v->cargo.Truncate((v->cargo_type == new_cid) ? amount : 0); |
049acde11ee2
(svn r14578) -Fix (r2389, r10811)[FS#Vikthor]: Allow capacity callbacks (15, 36) to return zero capacity.
frosch <frosch@openttd.org>
parents:
10314
diff
changeset
|
2087 v->cargo_type = new_cid; |
049acde11ee2
(svn r14578) -Fix (r2389, r10811)[FS#Vikthor]: Allow capacity callbacks (15, 36) to return zero capacity.
frosch <frosch@openttd.org>
parents:
10314
diff
changeset
|
2088 v->cargo_cap = amount; |
049acde11ee2
(svn r14578) -Fix (r2389, r10811)[FS#Vikthor]: Allow capacity callbacks (15, 36) to return zero capacity.
frosch <frosch@openttd.org>
parents:
10314
diff
changeset
|
2089 v->cargo_subtype = new_subtype; |
049acde11ee2
(svn r14578) -Fix (r2389, r10811)[FS#Vikthor]: Allow capacity callbacks (15, 36) to return zero capacity.
frosch <frosch@openttd.org>
parents:
10314
diff
changeset
|
2090 InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
049acde11ee2
(svn r14578) -Fix (r2389, r10811)[FS#Vikthor]: Allow capacity callbacks (15, 36) to return zero capacity.
frosch <frosch@openttd.org>
parents:
10314
diff
changeset
|
2091 InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
049acde11ee2
(svn r14578) -Fix (r2389, r10811)[FS#Vikthor]: Allow capacity callbacks (15, 36) to return zero capacity.
frosch <frosch@openttd.org>
parents:
10314
diff
changeset
|
2092 InvalidateWindowClassesData(WC_TRAINS_LIST, 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
|
2093 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2094 } |
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
|
2095 } while ((v = v->Next()) != NULL && !only_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
|
2096 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2097 _returned_refit_capacity = num; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2098 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2099 /* Update the train's cached variables */ |
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
|
2100 if (flags & DC_EXEC) TrainConsistChanged(GetVehicle(p1)->First(), 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
|
2101 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2102 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
|
2103 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2104 |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6247
diff
changeset
|
2105 struct TrainFindDepotData { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2106 uint best_length; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2107 TileIndex tile; |
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
|
2108 Owner 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
|
2109 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2110 * true if reversing is necessary for the train to get to this depot |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2111 * This value is unused when new depot finding and NPF are both disabled |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2112 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2113 bool reverse; |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6247
diff
changeset
|
2114 }; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2115 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2116 static bool NtpCallbFindDepot(TileIndex tile, TrainFindDepotData *tfdd, int track, uint length) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2117 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2118 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
|
2119 IsTileOwner(tile, tfdd->owner) && |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2120 IsRailDepot(tile)) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2121 /* approximate number of tiles by dividing by DIAG_FACTOR */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2122 tfdd->best_length = length / DIAG_FACTOR; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2123 tfdd->tile = tile; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2124 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
|
2125 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2126 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2127 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
|
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 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2130 /** returns the tile of a depot to goto to. The given vehicle must not be |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2131 * crashed! */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2132 static TrainFindDepotData FindClosestTrainDepot(Vehicle *v, int max_distance) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2133 { |
6150 | 2134 assert(!(v->vehstatus & VS_CRASHED)); |
2135 | |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2136 TrainFindDepotData tfdd; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2137 tfdd.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
|
2138 tfdd.reverse = false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2139 |
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
|
2140 if (IsRailDepotTile(v->tile)) { |
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
|
2141 tfdd.tile = v->tile; |
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
|
2142 tfdd.best_length = 0; |
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
|
2143 return tfdd; |
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
|
2144 } |
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
|
2145 |
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
|
2146 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
|
2147 if (IsRailDepotTile(origin.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
|
2148 tfdd.tile = origin.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
|
2149 tfdd.best_length = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2150 return tfdd; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2151 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2152 |
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
|
2153 tfdd.best_length = UINT_MAX; |
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
|
2154 |
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
|
2155 uint8 pathfinder = _settings_game.pf.pathfinder_for_trains; |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2156 if ((_settings_game.pf.reserve_paths || HasReservedTracks(v->tile, v->u.rail.track)) && pathfinder == VPF_NTP) pathfinder = VPF_NPF; |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2157 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2158 switch (pathfinder) { |
8554
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2159 case VPF_YAPF: { /* YAPF */ |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2160 bool found = YapfFindNearestRailDepotTwoWay(v, max_distance, NPF_INFINITE_PENALTY, &tfdd.tile, &tfdd.reverse); |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2161 tfdd.best_length = found ? max_distance / 2 : UINT_MAX; // some fake distance or NOT_FOUND |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2162 } break; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2163 |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2164 case VPF_NPF: { /* NPF */ |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2165 const Vehicle *last = GetLastVehicleInChain(v); |
8554
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2166 Trackdir trackdir = GetVehicleTrackdir(v); |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2167 Trackdir trackdir_rev = ReverseTrackdir(GetVehicleTrackdir(last)); |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2168 |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2169 assert(trackdir != INVALID_TRACKDIR); |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2170 NPFFoundTargetData ftd = NPFRouteToDepotBreadthFirstTwoWay(v->tile, trackdir, false, last->tile, trackdir_rev, false, TRANSPORT_RAIL, 0, v->owner, v->u.rail.compatible_railtypes, NPF_INFINITE_PENALTY); |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2171 if (ftd.best_bird_dist == 0) { |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2172 /* Found target */ |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2173 tfdd.tile = ftd.node.tile; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2174 /* Our caller expects a number of tiles, so we just approximate that |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2175 * number by this. It might not be completely what we want, but it will |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2176 * work for now :-) We can possibly change this when the old pathfinder |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2177 * is removed. */ |
8554
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2178 tfdd.best_length = ftd.best_path_dist / NPF_TILE_LENGTH; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2179 if (NPFGetFlag(&ftd.node, NPF_FLAG_REVERSE)) tfdd.reverse = true; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2180 } |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2181 } break; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2182 |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2183 default: |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2184 case VPF_NTP: { /* NTP */ |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2185 /* search in the forward direction first. */ |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2186 DiagDirection i = TrainExitDir(v->direction, v->u.rail.track); |
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
|
2187 NewTrainPathfind(v->tile, 0, v->u.rail.compatible_railtypes, i, (NTPEnumProc*)NtpCallbFindDepot, &tfdd); |
8554
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2188 if (tfdd.best_length == UINT_MAX){ |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2189 tfdd.reverse = true; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2190 /* search in backwards direction */ |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2191 i = TrainExitDir(ReverseDir(v->direction), v->u.rail.track); |
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
|
2192 NewTrainPathfind(v->tile, 0, v->u.rail.compatible_railtypes, i, (NTPEnumProc*)NtpCallbFindDepot, &tfdd); |
8554
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2193 } |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2194 } 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
|
2195 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2196 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2197 return tfdd; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2198 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2199 |
8890
b1d45af72e04
(svn r12657) -Codechange: add 'FindClosestDepot' to the vehicle class.
rubidium <rubidium@openttd.org>
parents:
8862
diff
changeset
|
2200 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
|
2201 { |
b1d45af72e04
(svn r12657) -Codechange: add 'FindClosestDepot' to the vehicle class.
rubidium <rubidium@openttd.org>
parents:
8862
diff
changeset
|
2202 TrainFindDepotData tfdd = FindClosestTrainDepot(this, 0); |
10236
59398a628f10
(svn r14464) -Codechange: replace (uint)-1 with UINT_MAX (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10214
diff
changeset
|
2203 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
|
2204 |
b1d45af72e04
(svn r12657) -Codechange: add 'FindClosestDepot' to the vehicle class.
rubidium <rubidium@openttd.org>
parents:
8862
diff
changeset
|
2205 if (location != NULL) *location = tfdd.tile; |
b1d45af72e04
(svn r12657) -Codechange: add 'FindClosestDepot' to the vehicle class.
rubidium <rubidium@openttd.org>
parents:
8862
diff
changeset
|
2206 if (destination != NULL) *destination = GetDepotByTile(tfdd.tile)->index; |
b1d45af72e04
(svn r12657) -Codechange: add 'FindClosestDepot' to the vehicle class.
rubidium <rubidium@openttd.org>
parents:
8862
diff
changeset
|
2207 if (reverse != NULL) *reverse = tfdd.reverse; |
b1d45af72e04
(svn r12657) -Codechange: add 'FindClosestDepot' to the vehicle class.
rubidium <rubidium@openttd.org>
parents:
8862
diff
changeset
|
2208 |
b1d45af72e04
(svn r12657) -Codechange: add 'FindClosestDepot' to the vehicle class.
rubidium <rubidium@openttd.org>
parents:
8862
diff
changeset
|
2209 return true; |
b1d45af72e04
(svn r12657) -Codechange: add 'FindClosestDepot' to the vehicle class.
rubidium <rubidium@openttd.org>
parents:
8862
diff
changeset
|
2210 } |
b1d45af72e04
(svn r12657) -Codechange: add 'FindClosestDepot' to the vehicle class.
rubidium <rubidium@openttd.org>
parents:
8862
diff
changeset
|
2211 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2212 /** Send a train to a depot |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2213 * @param tile unused |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2214 * @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
|
2215 * @param p1 train to send to the depot |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2216 * @param p2 various bitmasked elements |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2217 * - p2 bit 0-3 - DEPOT_ flags (see vehicle.h) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2218 * - p2 bit 8-10 - VLW flag (for mass goto depot) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2219 */ |
10499
45ca88a8de7d
(svn r14754) -Codechange: get rid of _cmd_text and just pass it as (optional) parameter.
rubidium <rubidium@openttd.org>
parents:
10493
diff
changeset
|
2220 CommandCost CmdSendTrainToDepot(TileIndex tile, uint32 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
|
2221 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2222 if (p2 & DEPOT_MASS_SEND) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2223 /* Mass goto depot requested */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2224 if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR; |
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
|
2225 return SendAllVehiclesToDepot(VEH_TRAIN, flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), p1); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2226 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2227 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2228 if (!IsValidVehicleID(p1)) return CMD_ERROR; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2229 |
6150 | 2230 Vehicle *v = GetVehicle(p1); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2231 |
8891
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8890
diff
changeset
|
2232 if (v->type != VEH_TRAIN) return CMD_ERROR; |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8890
diff
changeset
|
2233 |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8890
diff
changeset
|
2234 return v->SendToDepot(flags, (DepotCommand)(p2 & DEPOT_COMMAND_MASK)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2235 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2236 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2237 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6176
diff
changeset
|
2238 void OnTick_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
|
2239 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2240 _age_cargo_skip_counter = (_age_cargo_skip_counter == 0) ? 184 : (_age_cargo_skip_counter - 1); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2241 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2242 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2243 static const int8 _vehicle_smoke_pos[8] = { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2244 1, 1, 1, 0, -1, -1, -1, 0 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2245 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2246 |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2247 static void HandleLocomotiveSmokeCloud(const Vehicle *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
|
2248 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2249 bool sound = false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2250 |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2251 if (v->vehstatus & VS_TRAIN_SLOWING || v->load_unload_time_rem != 0 || v->cur_speed < 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
|
2252 return; |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2253 } |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2254 |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2255 const 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
|
2256 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2257 do { |
5823 | 2258 const RailVehicleInfo *rvi = RailVehInfo(v->engine_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
|
2259 int effect_offset = GB(v->u.rail.cached_vis_effect, 0, 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
|
2260 byte effect_type = GB(v->u.rail.cached_vis_effect, 4, 2); |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
2261 bool disable_effect = HasBit(v->u.rail.cached_vis_effect, 6); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2262 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2263 /* no smoke? */ |
5868
941f6c5a4668
(svn r8455) -Codechange: Give a more meaningful name (railveh_type)to member flags of RailVehInfo, as well as changing the code to reflect the fact that it was not a flag but rather a one value only variable. Doing so, some evaluations have been simplified.
belugas <belugas@openttd.org>
parents:
5858
diff
changeset
|
2264 if ((rvi->railveh_type == RAILVEH_WAGON && effect_type == 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
|
2265 disable_effect || |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2266 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
|
2267 continue; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2268 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2269 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2270 /* No smoke in depots or tunnels */ |
8961
b33bcd7fa037
(svn r12753) -Codechange: do not use IsDepotTypeTile() where simpler function can be used
smatz <smatz@openttd.org>
parents:
8954
diff
changeset
|
2271 if (IsRailDepotTile(v->tile) || IsTunnelTile(v->tile)) continue; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2272 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2273 /* No sparks for electric vehicles on nonelectrified tracks */ |
6154 | 2274 if (!HasPowerOnRail(v->u.rail.railtype, GetTileRailType(v->tile))) continue; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2275 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2276 if (effect_type == 0) { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2277 /* Use default effect type for engine class. */ |
5823 | 2278 effect_type = rvi->engclass; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2279 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2280 effect_type--; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2281 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2282 |
6150 | 2283 int x = _vehicle_smoke_pos[v->direction] * effect_offset; |
2284 int y = _vehicle_smoke_pos[(v->direction + 2) % 8] * effect_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
|
2285 |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
2286 if (HasBit(v->u.rail.flags, VRF_REVERSE_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
|
2287 x = -x; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2288 y = -y; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2289 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2290 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2291 switch (effect_type) { |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2292 case 0: |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2293 /* steam smoke. */ |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2294 if (GB(v->tick_counter, 0, 4) == 0) { |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2295 CreateEffectVehicleRel(v, x, y, 10, EV_STEAM_SMOKE); |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2296 sound = true; |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2297 } |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2298 break; |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2299 |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2300 case 1: |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2301 /* diesel smoke */ |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2302 if (u->cur_speed <= 40 && Chance16(15, 128)) { |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2303 CreateEffectVehicleRel(v, 0, 0, 10, EV_DIESEL_SMOKE); |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2304 sound = true; |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2305 } |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2306 break; |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2307 |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2308 case 2: |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2309 /* blue spark */ |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2310 if (GB(v->tick_counter, 0, 2) == 0 && Chance16(1, 45)) { |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2311 CreateEffectVehicleRel(v, 0, 0, 10, EV_ELECTRIC_SPARK); |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2312 sound = true; |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2313 } |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2314 break; |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2315 |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2316 default: |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2317 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
|
2318 } |
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
|
2319 } 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
|
2320 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2321 if (sound) PlayVehicleSound(u, VSE_TRAIN_EFFECT); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2322 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2323 |
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
|
2324 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
|
2325 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2326 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
|
2327 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
|
2328 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
|
2329 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
|
2330 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
|
2331 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
|
2332 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2333 |
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
|
2334 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
|
2335 |
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
|
2336 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
|
2337 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
|
2338 } |
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
|
2339 |
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
|
2340 /** Check if the train is on the last reserved tile and try to extend the path then. */ |
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
|
2341 static void CheckNextTrainTile(Vehicle *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
|
2342 { |
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
|
2343 /* 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
|
2344 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
|
2345 |
10102
48223ebc995c
(svn r14284) -Fix (r13958): Trains would not look ahead and extend their reservation on a waypoint tile in all cases.
michi_cc <michi_cc@openttd.org>
parents:
10083
diff
changeset
|
2346 /* Exit if we reached our destination depot or are inside a depot. */ |
48223ebc995c
(svn r14284) -Fix (r13958): Trains would not look ahead and extend their reservation on a waypoint tile in all cases.
michi_cc <michi_cc@openttd.org>
parents:
10083
diff
changeset
|
2347 if ((v->tile == v->dest_tile && v->current_order.IsType(OT_GOTO_DEPOT)) || v->u.rail.track & TRACK_BIT_DEPOT) 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
|
2348 /* Exit if we are on a station tile and are going to stop. */ |
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
|
2349 if (IsRailwayStationTile(v->tile) && v->current_order.ShouldStopAtStation(v, GetStationIndex(v->tile))) 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
|
2350 /* Exit if the current order doesn't have a destination, but the train has orders. */ |
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
|
2351 if ((v->current_order.IsType(OT_NOTHING) || v->current_order.IsType(OT_LEAVESTATION)) && v->num_orders > 0) 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
|
2352 |
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
|
2353 Trackdir td = GetVehicleTrackdir(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
|
2354 |
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
|
2355 /* 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
|
2356 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
|
2357 !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
|
2358 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
|
2359 |
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
|
2360 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
|
2361 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
|
2362 |
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
|
2363 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
|
2364 /* 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
|
2365 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
|
2366 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
|
2367 /* 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
|
2368 TrackBits tracks = 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
|
2369 if (_settings_game.pf.pathfinder_for_trains != VPF_NTP && _settings_game.pf.forbid_90_deg) { |
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
|
2370 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
|
2371 } |
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
|
2372 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
|
2373 } |
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
|
2374 } |
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
|
2375 } |
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
|
2376 } |
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
|
2377 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2378 static bool CheckTrainStayInDepot(Vehicle *v) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2379 { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2380 /* bail out if not all wagons are in the same depot or not in a depot at all */ |
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
|
2381 for (const Vehicle *u = v; u != NULL; u = u->Next()) { |
5993
2498be7c7e94
(svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium <rubidium@openttd.org>
parents:
5992
diff
changeset
|
2382 if (u->u.rail.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
|
2383 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2384 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2385 /* if the train got no power, then keep it in 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
|
2386 if (v->u.rail.cached_power == 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2387 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
|
2388 InvalidateWindow(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
|
2389 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
|
2390 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2391 |
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
|
2392 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
|
2393 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2394 if (v->u.rail.force_proceed == 0) { |
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
|
2395 /* force proceed was not pressed */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2396 if (++v->load_unload_time_rem < 37) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2397 InvalidateWindowClasses(WC_TRAINS_LIST); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2398 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
|
2399 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2400 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2401 v->load_unload_time_rem = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2402 |
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
|
2403 seg_state = _settings_game.pf.reserve_paths ? SIGSEG_PBS : UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR, v->owner); |
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
|
2404 if (seg_state == SIGSEG_FULL || GetDepotWaypointReservation(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
|
2405 /* Full and no PBS signal in block or depot reserved, can't exit. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2406 InvalidateWindowClasses(WC_TRAINS_LIST); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2407 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
|
2408 } |
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
|
2409 } 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
|
2410 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
|
2411 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2412 |
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
|
2413 /* Only leave when we can reserve a path to our destination. */ |
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
|
2414 if (seg_state == SIGSEG_PBS && !TryPathReserve(v) && v->u.rail.force_proceed == 0) { |
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
|
2415 /* No path and no force proceed. */ |
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
|
2416 InvalidateWindowClasses(WC_TRAINS_LIST); |
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
|
2417 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
|
2418 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
|
2419 } |
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
|
2420 |
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
|
2421 SetDepotWaypointReservation(v->tile, 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
|
2422 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
|
2423 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2424 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
|
2425 InvalidateWindowClasses(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
|
2426 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
|
2427 |
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
|
2428 v->u.rail.track = TRACK_BIT_X; |
c44c070c5032
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents:
5584
diff
changeset
|
2429 if (v->direction & 2) v->u.rail.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
|
2430 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2431 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
|
2432 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
|
2433 |
6558
2fc024ee8217
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium <rubidium@openttd.org>
parents:
6554
diff
changeset
|
2434 v->UpdateDeltaXY(v->direction); |
7134
e1c4f52f82cd
(svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium <rubidium@openttd.org>
parents:
7109
diff
changeset
|
2435 v->cur_image = v->GetImage(v->direction); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2436 VehiclePositionChanged(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
|
2437 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
|
2438 UpdateTrainAcceleration(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2439 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
|
2440 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2441 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
|
2442 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2443 |
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
|
2444 /** Clear the reservation of a tile that was just left by a wagon on track_dir. */ |
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
|
2445 static void ClearPathReservation(const Vehicle *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
|
2446 { |
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
|
2447 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
|
2448 |
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
|
2449 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
|
2450 /* 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
|
2451 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
|
2452 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
|
2453 |
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
|
2454 if (!HasVehicleOnTunnelBridge(tile, end, v)) { |
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
|
2455 /* 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
|
2456 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
|
2457 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
|
2458 |
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
|
2459 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
|
2460 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
|
2461 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
|
2462 } |
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
|
2463 } |
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
|
2464 } |
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
|
2465 } else if (IsRailwayStationTile(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
|
2466 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
|
2467 /* 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
|
2468 * 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
|
2469 if (!IsCompatibleTrainStationTile(new_tile, 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
|
2470 SetRailwayStationPlatformReservation(tile, ReverseDiagDir(dir), false); |
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
|
2471 } |
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
|
2472 } 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
|
2473 /* 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
|
2474 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
|
2475 } |
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
|
2476 } |
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
|
2477 |
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
|
2478 /** Free the reserved path in front of a 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
|
2479 void FreeTrainTrackReservation(const Vehicle *v, TileIndex origin, Trackdir orig_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
|
2480 { |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2481 assert(IsFrontEngine(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
|
2482 |
0e5451814e50
(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 TileIndex tile = origin != INVALID_TILE ? origin : v->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
|
2484 Trackdir td = orig_td != INVALID_TRACKDIR ? orig_td : GetVehicleTrackdir(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
|
2485 bool free_tile = tile != v->tile || !(IsRailwayStationTile(v->tile) || IsTileType(v->tile, MP_TUNNELBRIDGE)); |
9974
8823db05b70c
(svn r14131) -Fix (r13952) [FS#2250]: The reservation of adjacent stations was sometimes not freed correctly. (michi_cc)
frosch <frosch@openttd.org>
parents:
9973
diff
changeset
|
2486 StationID station_id = IsRailwayStationTile(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
|
2487 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2488 /* 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
|
2489 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
|
2490 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2491 CFollowTrackRail ft(v, GetRailTypeInfo(v->u.rail.railtype)->compatible_railtypes); |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2492 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
|
2493 tile = ft.m_new_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
|
2494 TrackdirBits bits = (TrackdirBits)(ft.m_new_td_bits & (GetReservedTrackbits(tile) * 0x101)); |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2495 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
|
2496 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
|
2497 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2498 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
|
2499 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2500 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
|
2501 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
|
2502 /* 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
|
2503 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
|
2504 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
|
2505 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2506 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
|
2507 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
|
2508 /* 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
|
2509 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
|
2510 } 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
|
2511 /* 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
|
2512 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
|
2513 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
|
2514 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2515 } 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
|
2516 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
|
2517 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2518 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2519 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2520 /* 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
|
2521 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
|
2522 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2523 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
|
2524 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2525 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2526 |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2527 /** Check for station tiles */ |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6247
diff
changeset
|
2528 struct TrainTrackFollowerData { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2529 TileIndex dest_coords; |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2530 StationID station_index; ///< station index we're heading for |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2531 uint best_bird_dist; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2532 uint best_track_dist; |
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
|
2533 TrackdirByte best_track; |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6247
diff
changeset
|
2534 }; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2535 |
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
|
2536 static bool NtpCallbFindStation(TileIndex tile, TrainTrackFollowerData *ttfd, Trackdir track, uint 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
|
2537 { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2538 /* heading for nowhere? */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2539 if (ttfd->dest_coords == 0) 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
|
2540 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2541 /* did we reach the final 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
|
2542 if ((ttfd->station_index == INVALID_STATION && tile == ttfd->dest_coords) || ( |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2543 IsTileType(tile, MP_STATION) && |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2544 IsRailwayStation(tile) && |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2545 GetStationIndex(tile) == ttfd->station_index |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2546 )) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2547 /* We do not check for dest_coords if we have a station_index, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2548 * because in that case the dest_coords are just an |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2549 * approximation of where the station is */ |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2550 |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2551 /* found 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
|
2552 ttfd->best_track = track; |
6303
a2428077ccb4
(svn r9146) -Fix [NTP][FS#676](r6800): "Train is lost" message is generated incorrectly. Forgot to set the best bird distance to zero in case we found the destination to indicate success. (de_zeurkous)
KUDr <KUDr@openttd.org>
parents:
6263
diff
changeset
|
2553 ttfd->best_bird_dist = 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
|
2554 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
|
2555 } else { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2556 /* didn't find station, keep track of the best path so far. */ |
6150 | 2557 uint dist = DistanceManhattan(tile, ttfd->dest_coords); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2558 if (dist < ttfd->best_bird_dist) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2559 ttfd->best_bird_dist = dist; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2560 ttfd->best_track = track; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2561 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2562 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
|
2563 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2564 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2565 |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
2566 static void FillWithStationData(TrainTrackFollowerData *fd, const Vehicle *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
|
2567 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2568 fd->dest_coords = v->dest_tile; |
8840
c3d2f0eb69a1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium <rubidium@openttd.org>
parents:
8836
diff
changeset
|
2569 fd->station_index = v->current_order.IsType(OT_GOTO_STATION) ? v->current_order.GetDestination() : INVALID_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
|
2570 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2571 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2572 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
|
2573 {{ 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
|
2574 {{ 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
|
2575 {{ 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
|
2576 {{ 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
|
2577 {{ 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
|
2578 {{ 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
|
2579 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2580 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2581 static const byte _search_directions[6][4] = { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2582 { 0, 9, 2, 9 }, ///< track 1 |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2583 { 9, 1, 9, 3 }, ///< track 2 |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2584 { 9, 0, 3, 9 }, ///< track upper |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2585 { 1, 9, 9, 2 }, ///< track lower |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2586 { 3, 2, 9, 9 }, ///< track left |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
2587 { 9, 9, 1, 0 }, ///< track 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
|
2588 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2589 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2590 static const byte _pick_track_table[6] = {1, 3, 2, 2, 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
|
2591 |
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
|
2592 /** |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2593 * 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
|
2594 * |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2595 * @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
|
2596 * @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
|
2597 * @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
|
2598 * @param tracks Usable tracks on the new 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
|
2599 * @param path_not_found [out] Set to false if the pathfinder couldn't find a way to the 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
|
2600 * @param 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
|
2601 * @param dest [out] |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2602 * @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
|
2603 */ |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2604 static Track DoTrainPathfind(Vehicle* v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_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
|
2605 { |
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
|
2606 Track best_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
|
2607 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2608 #ifdef PF_BENCHMARK |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2609 TIC() |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2610 #endif |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2611 |
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
|
2612 if (path_not_found) *path_not_found = 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
|
2613 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2614 uint8 pathfinder = _settings_game.pf.pathfinder_for_trains; |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2615 if (do_track_reservation && pathfinder == VPF_NTP) pathfinder = VPF_NPF; |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2616 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2617 switch (pathfinder) { |
8554
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2618 case VPF_YAPF: { /* YAPF */ |
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
|
2619 Trackdir trackdir = YapfChooseRailTrack(v, tile, enterdir, tracks, path_not_found, do_track_reservation, dest); |
8554
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2620 if (trackdir != INVALID_TRACKDIR) { |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2621 best_track = TrackdirToTrack(trackdir); |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2622 } else { |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2623 best_track = FindFirstTrack(tracks); |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2624 } |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2625 } break; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2626 |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2627 case VPF_NPF: { /* NPF */ |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2628 void *perf = NpfBeginInterval(); |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2629 |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2630 NPFFindStationOrTileData fstd; |
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
|
2631 NPFFillWithOrderData(&fstd, v, 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
|
2632 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2633 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
|
2634 assert(IsValidTrackdir(origin.trackdir)); |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2635 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2636 NPFFoundTargetData ftd = NPFRouteToStationOrTile(origin.tile, origin.trackdir, true, &fstd, TRANSPORT_RAIL, 0, v->owner, v->u.rail.compatible_railtypes); |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2637 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2638 if (dest != NULL) { |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2639 dest->tile = ftd.node.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
|
2640 dest->trackdir = (Trackdir)ftd.node.direction; |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2641 dest->okay = ftd.res_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
|
2642 } |
8554
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2643 |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2644 if (ftd.best_trackdir == INVALID_TRACKDIR) { |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2645 /* We are already at our target. Just do something |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2646 * @todo maybe display error? |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2647 * @todo: go straight ahead if possible? */ |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2648 best_track = FindFirstTrack(tracks); |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2649 } else { |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2650 /* If ftd.best_bird_dist is 0, we found our target and ftd.best_trackdir contains |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2651 * the direction we need to take to get there, if ftd.best_bird_dist is not 0, |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2652 * we did not find our target, but ftd.best_trackdir contains the direction leading |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2653 * to the tile closest to our target. */ |
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
|
2654 if (ftd.best_bird_dist != 0 && path_not_found != NULL) *path_not_found = true; |
8554
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2655 /* Discard enterdir information, making it a normal track */ |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2656 best_track = TrackdirToTrack(ftd.best_trackdir); |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2657 } |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2658 |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2659 int time = NpfEndInterval(perf); |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2660 DEBUG(yapf, 4, "[NPFT] %d us - %d rounds - %d open - %d closed -- ", time, 0, _aystar_stats_open_size, _aystar_stats_closed_size); |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2661 } break; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2662 |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2663 default: |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2664 case VPF_NTP: { /* NTP */ |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2665 void *perf = NpfBeginInterval(); |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2666 |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2667 TrainTrackFollowerData fd; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2668 FillWithStationData(&fd, v); |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2669 |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2670 /* New train pathfinding */ |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2671 fd.best_bird_dist = UINT_MAX; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2672 fd.best_track_dist = UINT_MAX; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2673 fd.best_track = INVALID_TRACKDIR; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2674 |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2675 NewTrainPathfind(tile - TileOffsByDiagDir(enterdir), v->dest_tile, |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2676 v->u.rail.compatible_railtypes, enterdir, (NTPEnumProc*)NtpCallbFindStation, &fd); |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2677 |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2678 /* check whether the path was found or only 'guessed' */ |
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
|
2679 if (fd.best_bird_dist != 0 && path_not_found != NULL) *path_not_found = true; |
8554
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2680 |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2681 if (fd.best_track == INVALID_TRACKDIR) { |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2682 /* blaha */ |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2683 best_track = FindFirstTrack(tracks); |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2684 } else { |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2685 best_track = TrackdirToTrack(fd.best_track); |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2686 } |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2687 |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2688 int time = NpfEndInterval(perf); |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2689 DEBUG(yapf, 4, "[NTPT] %d us - %d rounds - %d open - %d closed -- ", time, 0, 0, 0); |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2690 } 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
|
2691 } |
8554
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
2692 |
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
|
2693 #ifdef PF_BENCHMARK |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2694 TOC("PF time = ", 1) |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2695 #endif |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2696 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2697 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
|
2698 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2699 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2700 /** |
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
|
2701 * 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
|
2702 * 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
|
2703 * @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
|
2704 */ |
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
|
2705 static PBSTileInfo ExtendTrainReservation(const Vehicle *v, TrackBits *new_tracks, DiagDirection *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
|
2706 { |
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
|
2707 bool no_90deg_turns = _settings_game.pf.pathfinder_for_trains != VPF_NTP && _settings_game.pf.forbid_90_deg; |
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
|
2708 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
|
2709 |
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
|
2710 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
|
2711 |
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
|
2712 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
|
2713 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
|
2714 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
|
2715 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
|
2716 /* 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
|
2717 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
|
2718 } |
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
|
2719 |
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
|
2720 if (no_90deg_turns) { |
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
|
2721 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
|
2722 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
|
2723 } |
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
|
2724 |
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
|
2725 /* Station, depot or waypoint are a possible target. */ |
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
|
2726 bool target_seen = ft.m_is_station || (IsTileType(ft.m_new_tile, MP_RAILWAY) && !IsPlainRailTile(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
|
2727 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
|
2728 /* 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
|
2729 * 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
|
2730 * 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
|
2731 * 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
|
2732 * 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
|
2733 * 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
|
2734 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
|
2735 |
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
|
2736 /* 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
|
2737 * 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
|
2738 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
|
2739 |
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
|
2740 /* Choice found, path valid but not okay. Save info about the choice tile as well. */ |
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
|
2741 if (new_tracks) *new_tracks = TrackdirBitsToTrackBits(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
|
2742 if (enterdir) *enterdir = ft.m_exitdir; |
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
|
2743 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
|
2744 } |
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
|
2745 |
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
|
2746 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
|
2747 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
|
2748 |
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
|
2749 if (IsSafeWaitingPosition(v, tile, cur_td, true, no_90deg_turns)) { |
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
|
2750 bool wp_free = IsWaitingPositionFree(v, tile, cur_td, no_90deg_turns); |
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
|
2751 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
|
2752 /* 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
|
2753 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
|
2754 } |
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
|
2755 |
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
|
2756 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
|
2757 } |
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
|
2758 |
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
|
2759 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
|
2760 /* 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
|
2761 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
|
2762 } |
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
|
2763 |
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
|
2764 /* 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
|
2765 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
|
2766 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
|
2767 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
|
2768 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
|
2769 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
|
2770 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
|
2771 |
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
|
2772 if (no_90deg_turns) { |
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
|
2773 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
|
2774 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
|
2775 } |
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
|
2776 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
|
2777 |
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
|
2778 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
|
2779 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
|
2780 |
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
|
2781 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
|
2782 } |
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
|
2783 |
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
|
2784 /* 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
|
2785 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
|
2786 } |
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
|
2787 |
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
|
2788 /** |
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
|
2789 * 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
|
2790 * 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
|
2791 * |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2792 * @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
|
2793 * @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
|
2794 * @param td The trackdir 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
|
2795 * @param override_tailtype Whether all physically compatible railtypes should be followed. |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2796 * @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
|
2797 */ |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2798 static bool TryReserveSafeTrack(const Vehicle* v, TileIndex tile, Trackdir td, bool override_tailtype) |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2799 { |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2800 if (_settings_game.pf.pathfinder_for_trains == VPF_YAPF) { |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2801 return YapfRailFindNearestSafeTile(v, tile, td, override_tailtype); |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2802 } 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
|
2803 return NPFRouteToSafeTile(v, tile, td, override_tailtype).res_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
|
2804 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2805 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2806 |
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
|
2807 /** This class will save the current order of a vehicle and restore it on destruction. */ |
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2808 class VehicleOrderSaver |
9812
861a72996945
(svn r13954) -Codechange [YAPP]: On reserving a path that ends at the destination, the path could end at a non-safe tile. In this case, extend the reservation based on the next vehicle orders. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9811
diff
changeset
|
2809 { |
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
|
2810 private: |
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
|
2811 Vehicle *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
|
2812 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
|
2813 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
|
2814 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
|
2815 VehicleOrderID index; |
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
|
2816 |
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
|
2817 public: |
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
|
2818 VehicleOrderSaver(Vehicle *_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
|
2819 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
|
2820 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
|
2821 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
|
2822 old_last_station_visited(_v->last_station_visited), |
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
|
2823 index(_v->cur_order_index) |
10251
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2824 { |
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
|
2825 } |
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
|
2826 |
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
|
2827 ~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
|
2828 { |
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
|
2829 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
|
2830 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
|
2831 this->v->last_station_visited = this->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
|
2832 } |
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
|
2833 |
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
|
2834 /** |
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
|
2835 * Set the current vehicle order to the next order in the order list. |
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
|
2836 * @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
|
2837 */ |
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
|
2838 bool SwitchToNextOrder() |
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
|
2839 { |
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
|
2840 ++this->index; |
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
|
2841 |
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
|
2842 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
|
2843 /* Wrap around. */ |
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
|
2844 if (this->index >= this->v->num_orders) this->index = 0; |
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
|
2845 |
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
|
2846 Order *order = GetVehicleOrder(this->v, this->index); |
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
|
2847 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
|
2848 |
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
|
2849 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
|
2850 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
|
2851 /* 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
|
2852 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
|
2853 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
|
2854 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
|
2855 this->v->current_order = *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
|
2856 UpdateOrderDest(this->v, 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
|
2857 return true; |
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
|
2858 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
|
2859 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
|
2860 if (next != INVALID_VEH_ORDER_ID) { |
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
|
2861 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
|
2862 /* 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
|
2863 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
|
2864 } |
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
|
2865 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
|
2866 } |
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
|
2867 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
|
2868 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
|
2869 } |
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
|
2870 /* 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
|
2871 * 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
|
2872 ++this->index; |
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
|
2873 } while (this->index != this->v->cur_order_index); |
10251
b799a50c1992
(svn r14482) -Codechange: Use a class for saving the current train order when extending the reserved path beyond the current destination during pathfinding.
michi_cc <michi_cc@openttd.org>
parents:
10236
diff
changeset
|
2874 |
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
|
2875 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
|
2876 } |
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
|
2877 }; |
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
|
2878 |
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
|
2879 /* choose a 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
|
2880 static Track ChooseTrainTrack(Vehicle* v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool force_res, bool *got_reservation, bool mark_stuck) |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2881 { |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2882 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
|
2883 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
|
2884 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
|
2885 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2886 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
|
2887 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2888 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
|
2889 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2890 /* 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
|
2891 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
|
2892 /* 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
|
2893 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
|
2894 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2895 /* 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
|
2896 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
|
2897 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
|
2898 /* 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
|
2899 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
|
2900 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
|
2901 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
|
2902 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
|
2903 } 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
|
2904 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
|
2905 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2906 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
|
2907 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2908 |
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
|
2909 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
|
2910 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
|
2911 if (do_track_reservation) { |
9822
d61801babe63
(svn r13964) -Codechange [YAPP]: Check if a train needs servicing when reserving the next path segment. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9821
diff
changeset
|
2912 /* Check if the train needs service here, so it has a chance to always find a depot. |
d61801babe63
(svn r13964) -Codechange [YAPP]: Check if a train needs servicing when reserving the next path segment. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9821
diff
changeset
|
2913 * Also check if the current order is a service order so we don't reserve a path to |
d61801babe63
(svn r13964) -Codechange [YAPP]: Check if a train needs servicing when reserving the next path segment. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9821
diff
changeset
|
2914 * the destination but instead to the next one if service isn't needed. */ |
d61801babe63
(svn r13964) -Codechange [YAPP]: Check if a train needs servicing when reserving the next path segment. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9821
diff
changeset
|
2915 CheckIfTrainNeedsService(v); |
d61801babe63
(svn r13964) -Codechange [YAPP]: Check if a train needs servicing when reserving the next path segment. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9821
diff
changeset
|
2916 if (v->current_order.IsType(OT_DUMMY) || v->current_order.IsType(OT_CONDITIONAL) || v->current_order.IsType(OT_GOTO_DEPOT)) ProcessOrders(v); |
9817
c7c20be56cee
(svn r13959) -Codechange [YAPP]: Try to extend a train reservation as far as possible and only call into the pathfinder on track choices. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9816
diff
changeset
|
2917 |
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
|
2918 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
|
2919 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
|
2920 /* 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
|
2921 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
|
2922 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
|
2923 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
|
2924 } |
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
|
2925 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2926 |
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
|
2927 /* 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
|
2928 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
|
2929 |
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
|
2930 /* 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
|
2931 * 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
|
2932 * 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
|
2933 * 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
|
2934 * 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
|
2935 * order list itself is empty. */ |
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
|
2936 if (!v->current_order.IsType(OT_GOTO_DEPOT) && ( |
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
|
2937 v->current_order.IsType(OT_GOTO_STATION) ? |
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
|
2938 IsRailwayStationTile(v->tile) && v->current_order.GetDestination() == GetStationIndex(v->tile) : |
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
|
2939 v->tile == v->dest_tile)) { |
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
|
2940 orders.SwitchToNextOrder(); |
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
|
2941 } |
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
|
2942 |
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
|
2943 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
|
2944 /* Pathfinders are able to tell that route was only 'guessed'. */ |
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
|
2945 bool path_not_found = 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
|
2946 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
|
2947 |
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
|
2948 Track next_track = DoTrainPathfind(v, new_tile, dest_enterdir, tracks, &path_not_found, do_track_reservation, &res_dest); |
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
|
2949 if (new_tile == tile) best_track = next_track; |
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
|
2950 |
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
|
2951 /* handle "path not found" state */ |
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
|
2952 if (path_not_found) { |
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
|
2953 /* PF didn't find the route */ |
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
|
2954 if (!HasBit(v->u.rail.flags, VRF_NO_PATH_TO_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
|
2955 /* it is first time the problem occurred, set the "path not found" flag */ |
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
|
2956 SetBit(v->u.rail.flags, VRF_NO_PATH_TO_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
|
2957 /* and notify user about the event */ |
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
|
2958 if (_settings_client.gui.lost_train_warn && v->owner == _local_company) { |
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
|
2959 SetDParam(0, v->unitnumber); |
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
|
2960 AddNewsItem( |
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
|
2961 STR_TRAIN_IS_LOST, |
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
|
2962 NS_ADVICE, |
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
|
2963 v->index, |
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
|
2964 0); |
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
|
2965 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2966 } |
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
|
2967 } else { |
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
|
2968 /* route found, is the train marked with "path not found" flag? */ |
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
|
2969 if (HasBit(v->u.rail.flags, VRF_NO_PATH_TO_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
|
2970 /* clear the flag as the PF's problem was solved */ |
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
|
2971 ClrBit(v->u.rail.flags, VRF_NO_PATH_TO_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
|
2972 /* can we also delete the "News" item somehow? */ |
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
|
2973 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2974 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2975 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2976 |
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
|
2977 /* 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
|
2978 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
|
2979 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2980 /* 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
|
2981 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
|
2982 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
|
2983 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
|
2984 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
|
2985 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2986 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
2987 /* 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
|
2988 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
|
2989 /* 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
|
2990 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
|
2991 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
|
2992 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
|
2993 best_track = FindFirstTrack(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
|
2994 TryReserveRailTrack(v->tile, TrackdirToTrack(GetVehicleTrackdir(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
|
2995 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
|
2996 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
|
2997 } 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
|
2998 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
|
2999 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
|
3000 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
3001 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
|
3002 } |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
3003 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
3004 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
|
3005 |
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
|
3006 /* 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
|
3007 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
|
3008 /* 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
|
3009 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
|
3010 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
|
3011 TrackBits reachable = TrackdirBitsToTrackBits((TrackdirBits)(GetTileTrackStatus(next_tile, TRANSPORT_RAIL, 0))) & DiagdirReachesTracks(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
|
3012 if (_settings_game.pf.pathfinder_for_trains != VPF_NTP && _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
|
3013 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
|
3014 } |
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
|
3015 |
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
|
3016 /* Get next order with destination. */ |
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
|
3017 if (orders.SwitchToNextOrder()) { |
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
|
3018 PBSTileInfo 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
|
3019 DoTrainPathfind(v, next_tile, exitdir, reachable, NULL, true, &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
|
3020 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
|
3021 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
|
3022 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
|
3023 /* 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
|
3024 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
|
3025 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
|
3026 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
|
3027 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
|
3028 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
|
3029 } |
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
|
3030 } |
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
|
3031 /* 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
|
3032 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
|
3033 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
|
3034 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
|
3035 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
|
3036 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
|
3037 } |
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
|
3038 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
|
3039 } |
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
|
3040 |
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
|
3041 TryReserveRailTrack(v->tile, TrackdirToTrack(GetVehicleTrackdir(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
|
3042 |
0e5451814e50
(svn r13952) -Add [YAPP]: Trains now reserve paths trough PBS signals. Bump savegame version. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9809
diff
changeset
|
3043 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
|
3044 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3045 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
|
3046 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3047 |
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
|
3048 /** |
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
|
3049 * 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
|
3050 * |
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
|
3051 * @param v The vehicle |
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
|
3052 * @return True if a path could be reserved |
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
|
3053 */ |
9828
bd4952303db6
(svn r13971) -Fix [YAPP]: segfault due to mixed up variables (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9824
diff
changeset
|
3054 bool TryPathReserve(Vehicle *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
|
3055 { |
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
|
3056 assert(v->type == VEH_TRAIN && IsFrontEngine(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
|
3057 |
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
|
3058 /* 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
|
3059 * 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
|
3060 * inside the depot, a depot reservation can never be ours. */ |
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
|
3061 if (v->u.rail.track & TRACK_BIT_DEPOT) { |
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
|
3062 if (GetDepotWaypointReservation(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
|
3063 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
|
3064 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
|
3065 } 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
|
3066 /* 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
|
3067 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
|
3068 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
|
3069 } |
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
|
3070 } |
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
|
3071 |
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
|
3072 /* Special check if we are in front of a two-sided conventional signal. */ |
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
|
3073 DiagDirection dir = TrainExitDir(v->direction, v->u.rail.track); |
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
|
3074 TileIndex next_tile = TileAddByDiagDir(v->tile, dir); |
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
|
3075 if (IsTileType(next_tile, MP_RAILWAY) && HasReservedTracks(next_tile, DiagdirReachesTracks(dir))) { |
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
|
3076 /* Can have only one reserved 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
|
3077 Trackdir td = FindFirstTrackdir((TrackdirBits)(GetReservedTrackbits(next_tile) * 0x101 & DiagdirReachesTrackdirs(dir))); |
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
|
3078 if (HasSignalOnTrackdir(next_tile, td) && HasSignalOnTrackdir(next_tile, ReverseTrackdir(td)) && |
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
|
3079 !IsPbsSignal(GetSignalType(next_tile, TrackdirToTrack(td)))) { |
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
|
3080 /* Signal already reserved, is not ours. */ |
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
|
3081 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
|
3082 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
|
3083 } |
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
|
3084 } |
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
|
3085 |
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
|
3086 bool other_train = false; |
9831
7c2cb1b0402d
(svn r13974) -Fix [YAPP]: A train crash could lead to stale reservations. (michi_cc)
frosch <frosch@openttd.org>
parents:
9828
diff
changeset
|
3087 PBSTileInfo origin = FollowTrainReservation(v, &other_train); |
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
|
3088 /* 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
|
3089 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
|
3090 /* Can't be stuck then. */ |
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
|
3091 if (HasBit(v->u.rail.flags, VRF_TRAIN_STUCK)) InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
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
|
3092 ClrBit(v->u.rail.flags, VRF_TRAIN_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
|
3093 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
|
3094 } |
9831
7c2cb1b0402d
(svn r13974) -Fix [YAPP]: A train crash could lead to stale reservations. (michi_cc)
frosch <frosch@openttd.org>
parents:
9828
diff
changeset
|
3095 /* The path we are driving on is alread blocked by some other train. |
7c2cb1b0402d
(svn r13974) -Fix [YAPP]: A train crash could lead to stale reservations. (michi_cc)
frosch <frosch@openttd.org>
parents:
9828
diff
changeset
|
3096 * This can only happen when tracks and signals are changed. A crash |
7c2cb1b0402d
(svn r13974) -Fix [YAPP]: A train crash could lead to stale reservations. (michi_cc)
frosch <frosch@openttd.org>
parents:
9828
diff
changeset
|
3097 * is probably imminent, don't do any further reservation because |
7c2cb1b0402d
(svn r13974) -Fix [YAPP]: A train crash could lead to stale reservations. (michi_cc)
frosch <frosch@openttd.org>
parents:
9828
diff
changeset
|
3098 * it might cause stale reservations. */ |
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
|
3099 if (other_train && v->tile != origin.tile) { |
9831
7c2cb1b0402d
(svn r13974) -Fix [YAPP]: A train crash could lead to stale reservations. (michi_cc)
frosch <frosch@openttd.org>
parents:
9828
diff
changeset
|
3100 if (mark_as_stuck) MarkTrainAsStuck(v); |
7c2cb1b0402d
(svn r13974) -Fix [YAPP]: A train crash could lead to stale reservations. (michi_cc)
frosch <frosch@openttd.org>
parents:
9828
diff
changeset
|
3101 return false; |
7c2cb1b0402d
(svn r13974) -Fix [YAPP]: A train crash could lead to stale reservations. (michi_cc)
frosch <frosch@openttd.org>
parents:
9828
diff
changeset
|
3102 } |
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
|
3103 |
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
|
3104 /* If we are in a depot, tentativly reserve the depot. */ |
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
|
3105 if (v->u.rail.track & TRACK_BIT_DEPOT) { |
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
|
3106 SetDepotWaypointReservation(v->tile, 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
|
3107 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
|
3108 } |
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
|
3109 |
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
|
3110 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
|
3111 TileIndex new_tile = TileAddByDiagDir(origin.tile, exitdir); |
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
|
3112 TrackBits reachable = TrackdirBitsToTrackBits((TrackdirBits)GetTileTrackStatus(new_tile, TRANSPORT_RAIL, 0) & DiagdirReachesTrackdirs(exitdir)); |
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
|
3113 |
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
|
3114 if (_settings_game.pf.pathfinder_for_trains != VPF_NTP && _settings_game.pf.forbid_90_deg) reachable &= ~TrackCrossesTracks(TrackdirToTrack(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
|
3115 |
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
|
3116 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
|
3117 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
|
3118 |
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
|
3119 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
|
3120 /* Free the depot reservation as well. */ |
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
|
3121 if (v->u.rail.track & TRACK_BIT_DEPOT) SetDepotWaypointReservation(v->tile, 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
|
3122 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
|
3123 } |
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
|
3124 |
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
|
3125 if (HasBit(v->u.rail.flags, VRF_TRAIN_STUCK)) InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
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
|
3126 ClrBit(v->u.rail.flags, VRF_TRAIN_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
|
3127 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
|
3128 } |
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
|
3129 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3130 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3131 static bool CheckReverseTrain(Vehicle *v) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3132 { |
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
|
3133 if (_settings_game.difficulty.line_reverse_mode != 0 || |
5993
2498be7c7e94
(svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium <rubidium@openttd.org>
parents:
5992
diff
changeset
|
3134 v->u.rail.track == TRACK_BIT_DEPOT || v->u.rail.track == TRACK_BIT_WORMHOLE || |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
3135 !(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
|
3136 return false; |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
3137 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3138 |
6150 | 3139 uint reverse_best = 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
|
3140 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3141 assert(v->u.rail.track); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3142 |
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
|
3143 switch (_settings_game.pf.pathfinder_for_trains) { |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
3144 case VPF_YAPF: /* YAPF */ |
8554
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3145 reverse_best = YapfCheckReverseTrain(v); |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
3146 break; |
8554
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3147 |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3148 case VPF_NPF: { /* NPF */ |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3149 NPFFindStationOrTileData fstd; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3150 NPFFoundTargetData ftd; |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
3151 Vehicle *last = GetLastVehicleInChain(v); |
8554
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3152 |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3153 NPFFillWithOrderData(&fstd, v); |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3154 |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3155 Trackdir trackdir = GetVehicleTrackdir(v); |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3156 Trackdir trackdir_rev = ReverseTrackdir(GetVehicleTrackdir(last)); |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3157 assert(trackdir != INVALID_TRACKDIR); |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3158 assert(trackdir_rev != INVALID_TRACKDIR); |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3159 |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3160 ftd = NPFRouteToStationOrTileTwoWay(v->tile, trackdir, false, last->tile, trackdir_rev, false, &fstd, TRANSPORT_RAIL, 0, v->owner, v->u.rail.compatible_railtypes); |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3161 if (ftd.best_bird_dist != 0) { |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3162 /* We didn't find anything, just keep on going straight ahead */ |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3163 reverse_best = false; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3164 } else { |
8554
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3165 if (NPFGetFlag(&ftd.node, NPF_FLAG_REVERSE)) { |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3166 reverse_best = true; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3167 } else { |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3168 reverse_best = false; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3169 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3170 } |
8554
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3171 } break; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3172 |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3173 default: |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3174 case VPF_NTP: { /* NTP */ |
10441
cccbefb54c81
(svn r14695) -Cleanup: When NTP is not active there is no need to set up TrainTrackFollowerData.
frosch <frosch@openttd.org>
parents:
10343
diff
changeset
|
3175 TrainTrackFollowerData fd; |
cccbefb54c81
(svn r14695) -Cleanup: When NTP is not active there is no need to set up TrainTrackFollowerData.
frosch <frosch@openttd.org>
parents:
10343
diff
changeset
|
3176 FillWithStationData(&fd, v); |
cccbefb54c81
(svn r14695) -Cleanup: When NTP is not active there is no need to set up TrainTrackFollowerData.
frosch <frosch@openttd.org>
parents:
10343
diff
changeset
|
3177 |
8794
0a524ed2b87b
(svn r12532) -Cleanup: Replace two tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8793
diff
changeset
|
3178 int i = _search_directions[FindFirstTrack(v->u.rail.track)][DirToDiagDir(v->direction)]; |
0a524ed2b87b
(svn r12532) -Cleanup: Replace two tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8793
diff
changeset
|
3179 |
8554
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3180 int best_track = -1; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3181 uint reverse = 0; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3182 uint best_bird_dist = 0; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3183 uint best_track_dist = 0; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3184 |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3185 for (;;) { |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3186 fd.best_bird_dist = UINT_MAX; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3187 fd.best_track_dist = UINT_MAX; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3188 |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3189 NewTrainPathfind(v->tile, v->dest_tile, v->u.rail.compatible_railtypes, (DiagDirection)(reverse ^ i), (NTPEnumProc*)NtpCallbFindStation, &fd); |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3190 |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3191 if (best_track != -1) { |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3192 if (best_bird_dist != 0) { |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3193 if (fd.best_bird_dist != 0) { |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3194 /* neither reached the destination, pick the one with the smallest bird dist */ |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3195 if (fd.best_bird_dist > best_bird_dist) goto bad; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3196 if (fd.best_bird_dist < best_bird_dist) goto good; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3197 } else { |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3198 /* we found the destination for the first time */ |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3199 goto good; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3200 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3201 } else { |
8554
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3202 if (fd.best_bird_dist != 0) { |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3203 /* didn't find destination, but we've found the destination previously */ |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3204 goto bad; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3205 } else { |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3206 /* both old & new reached the destination, compare track length */ |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3207 if (fd.best_track_dist > best_track_dist) goto bad; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3208 if (fd.best_track_dist < best_track_dist) goto good; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3209 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3210 } |
8554
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3211 |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3212 /* if we reach this position, there's two paths of equal value so far. |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3213 * pick one randomly. */ |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3214 int r = GB(Random(), 0, 8); |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3215 if (_pick_track_table[i] == (v->direction & 3)) r += 80; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3216 if (_pick_track_table[best_track] == (v->direction & 3)) r -= 80; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3217 if (r <= 127) goto bad; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3218 } |
8554
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3219 good:; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3220 best_track = i; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3221 best_bird_dist = fd.best_bird_dist; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3222 best_track_dist = fd.best_track_dist; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3223 reverse_best = reverse; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3224 bad:; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3225 if (reverse != 0) break; |
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3226 reverse = 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
|
3227 } |
8554
9bf902b801c6
(svn r12132) -Cleanup: convert pathfinder selection from if/else to switch/case at many places
smatz <smatz@openttd.org>
parents:
8553
diff
changeset
|
3228 } 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
|
3229 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3230 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3231 return reverse_best != 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3232 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3233 |
8827
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8794
diff
changeset
|
3234 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
|
3235 { |
8830
981a95f3204d
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents:
8827
diff
changeset
|
3236 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
|
3237 |
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
|
3238 const Station *st = GetStation(station); |
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
|
3239 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
|
3240 /* The destination station has no trainstation tiles. */ |
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
|
3241 this->cur_order_index++; |
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
|
3242 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
|
3243 } |
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
|
3244 |
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
|
3245 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
|
3246 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3247 |
6553
733ef9947fe2
(svn r9755) -Codechange: refactor some more of the begin loading stuff.
rubidium <rubidium@openttd.org>
parents:
6552
diff
changeset
|
3248 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
|
3249 { |
6553
733ef9947fe2
(svn r9755) -Codechange: refactor some more of the begin loading stuff.
rubidium <rubidium@openttd.org>
parents:
6552
diff
changeset
|
3250 Vehicle *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
|
3251 do { |
7134
e1c4f52f82cd
(svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium <rubidium@openttd.org>
parents:
7109
diff
changeset
|
3252 v->cur_image = v->GetImage(v->direction); |
8317
7ce2445db70c
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz <smatz@openttd.org>
parents:
8312
diff
changeset
|
3253 MarkSingleVehicleDirty(v); |
7492
09743324277c
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium <rubidium@openttd.org>
parents:
7488
diff
changeset
|
3254 } 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
|
3255 |
733ef9947fe2
(svn r9755) -Codechange: refactor some more of the begin loading stuff.
rubidium <rubidium@openttd.org>
parents:
6552
diff
changeset
|
3256 /* need to update acceleration and cached values since the goods on the train changed. */ |
733ef9947fe2
(svn r9755) -Codechange: refactor some more of the begin loading stuff.
rubidium <rubidium@openttd.org>
parents:
6552
diff
changeset
|
3257 TrainCargoChanged(this); |
733ef9947fe2
(svn r9755) -Codechange: refactor some more of the begin loading stuff.
rubidium <rubidium@openttd.org>
parents:
6552
diff
changeset
|
3258 UpdateTrainAcceleration(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
|
3259 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3260 |
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
|
3261 /** |
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
|
3262 * This function looks at the vehicle and updates it's speed (cur_speed |
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
|
3263 * and subspeed) variables. Furthermore, it returns the distance that |
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
|
3264 * the train can drive this tick. This distance is expressed as 256 * n, |
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
|
3265 * where n is the number of straight (long) tracks the train can |
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
|
3266 * traverse. This means that moving along a straight track costs 256 |
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
|
3267 * "speed" and a diagonal track costs 192 "speed". |
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
|
3268 * @param v The vehicle to update the speed of. |
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
|
3269 * @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
|
3270 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3271 static int UpdateTrainSpeed(Vehicle *v) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3272 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3273 uint accel; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3274 |
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
|
3275 if (v->vehstatus & VS_STOPPED || HasBit(v->u.rail.flags, VRF_REVERSING) || HasBit(v->u.rail.flags, VRF_TRAIN_STUCK)) { |
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
|
3276 if (_settings_game.vehicle.realistic_acceleration) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3277 accel = GetTrainAcceleration(v, AM_BRAKE) * 2; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3278 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3279 accel = v->acceleration * -2; |
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 } else { |
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
|
3282 if (_settings_game.vehicle.realistic_acceleration) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3283 accel = GetTrainAcceleration(v, AM_ACCEL); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3284 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3285 accel = v->acceleration; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3286 } |
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 |
6150 | 3289 uint spd = v->subspeed + accel * 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
|
3290 v->subspeed = (byte)spd; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3291 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3292 int tempmax = v->max_speed; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3293 if (v->cur_speed > v->max_speed) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3294 tempmax = v->cur_speed - (v->cur_speed / 10) - 1; |
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
|
3295 v->cur_speed = spd = Clamp(v->cur_speed + ((int)spd >> 8), 0, tempmax); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3296 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3297 |
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
|
3298 /* Scale speed by 3/4. Previously this was only done when the train was |
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
|
3299 * facing diagonally and would apply to however many moves the train made |
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
|
3300 * regardless the of direction actually moved in. Now it is always scaled, |
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
|
3301 * 256 spd is used to go straight and 192 is used to go diagonally |
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
|
3302 * (3/4 of 256). This results in the same effect, but without the error the |
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
|
3303 * previous method caused. |
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
|
3304 * |
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
|
3305 * The scaling is done in this direction and not by multiplying the amount |
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
|
3306 * to be subtracted by 4/3 so that the leftover speed can be saved in a |
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
|
3307 * byte in v->progress. |
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
|
3308 */ |
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
|
3309 int scaled_spd = spd * 3 >> 2; |
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
|
3310 |
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
|
3311 scaled_spd += v->progress; |
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
|
3312 v->progress = 0; // set later in TrainLocoHandler or TrainController |
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
|
3313 return scaled_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
|
3314 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3315 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3316 static void TrainEnterStation(Vehicle *v, StationID station) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3317 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3318 v->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
|
3319 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3320 /* check if a train ever visited this station before */ |
6150 | 3321 Station *st = GetStation(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
|
3322 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
|
3323 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
|
3324 SetDParam(0, st->index); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3325 AddNewsItem( |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3326 STR_8801_CITIZENS_CELEBRATE_FIRST, |
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
|
3327 v->owner == _local_company ? NS_ARRIVAL_COMPANY : NS_ARRIVAL_OTHER, |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3328 v->index, |
10123
57aa34285d05
(svn r14307) -Fix: when deleting a station, remove news items regarding it
smatz <smatz@openttd.org>
parents:
10103
diff
changeset
|
3329 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
|
3330 ); |
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 |
6550
2fa52ce08b41
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium <rubidium@openttd.org>
parents:
6546
diff
changeset
|
3333 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
|
3334 |
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
|
3335 StationAnimationTrigger(st, v->tile, STAT_ANIM_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
|
3336 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3337 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3338 static byte AfterSetTrainPos(Vehicle *v, bool 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
|
3339 { |
6150 | 3340 byte old_z = v->z_pos; |
7079
85d64732a312
(svn r10344) -Fix (r10317): confusion between TRACK_n and TRACK_BIT_n stopped NW/SE slopes being picked up, and compare middle of tile against current z, not previous.
peter1138 <peter1138@openttd.org>
parents:
7070
diff
changeset
|
3341 v->z_pos = GetSlopeZ(v->x_pos, v->y_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
|
3342 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3343 if (new_tile) { |
7929
4d13dbed828c
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7928
diff
changeset
|
3344 ClrBit(v->u.rail.flags, VRF_GOINGUP); |
4d13dbed828c
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7928
diff
changeset
|
3345 ClrBit(v->u.rail.flags, VRF_GOINGDOWN); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3346 |
7079
85d64732a312
(svn r10344) -Fix (r10317): confusion between TRACK_n and TRACK_BIT_n stopped NW/SE slopes being picked up, and compare middle of tile against current z, not previous.
peter1138 <peter1138@openttd.org>
parents:
7070
diff
changeset
|
3347 if (v->u.rail.track == TRACK_BIT_X || v->u.rail.track == TRACK_BIT_Y) { |
85d64732a312
(svn r10344) -Fix (r10317): confusion between TRACK_n and TRACK_BIT_n stopped NW/SE slopes being picked up, and compare middle of tile against current z, not previous.
peter1138 <peter1138@openttd.org>
parents:
7070
diff
changeset
|
3348 /* Any track that isn't TRACK_BIT_X or TRACK_BIT_Y cannot be sloped. |
7052
19f74693bbc9
(svn r10317) -Fix [FS#786]: acceleration not calculated properly when a train goes up a hill between tunnels.
rubidium <rubidium@openttd.org>
parents:
7024
diff
changeset
|
3349 * To check whether the current tile is sloped, and in which |
19f74693bbc9
(svn r10317) -Fix [FS#786]: acceleration not calculated properly when a train goes up a hill between tunnels.
rubidium <rubidium@openttd.org>
parents:
7024
diff
changeset
|
3350 * direction it is sloped, we get the 'z' at the center of |
19f74693bbc9
(svn r10317) -Fix [FS#786]: acceleration not calculated properly when a train goes up a hill between tunnels.
rubidium <rubidium@openttd.org>
parents:
7024
diff
changeset
|
3351 * the tile (middle_z) and the edge of the tile (old_z), |
19f74693bbc9
(svn r10317) -Fix [FS#786]: acceleration not calculated properly when a train goes up a hill between tunnels.
rubidium <rubidium@openttd.org>
parents:
7024
diff
changeset
|
3352 * which we then can compare. */ |
19f74693bbc9
(svn r10317) -Fix [FS#786]: acceleration not calculated properly when a train goes up a hill between tunnels.
rubidium <rubidium@openttd.org>
parents:
7024
diff
changeset
|
3353 static const int HALF_TILE_SIZE = TILE_SIZE / 2; |
19f74693bbc9
(svn r10317) -Fix [FS#786]: acceleration not calculated properly when a train goes up a hill between tunnels.
rubidium <rubidium@openttd.org>
parents:
7024
diff
changeset
|
3354 static const int INV_TILE_SIZE_MASK = ~(TILE_SIZE - 1); |
19f74693bbc9
(svn r10317) -Fix [FS#786]: acceleration not calculated properly when a train goes up a hill between tunnels.
rubidium <rubidium@openttd.org>
parents:
7024
diff
changeset
|
3355 |
19f74693bbc9
(svn r10317) -Fix [FS#786]: acceleration not calculated properly when a train goes up a hill between tunnels.
rubidium <rubidium@openttd.org>
parents:
7024
diff
changeset
|
3356 byte middle_z = GetSlopeZ((v->x_pos & INV_TILE_SIZE_MASK) | HALF_TILE_SIZE, (v->y_pos & INV_TILE_SIZE_MASK) | HALF_TILE_SIZE); |
19f74693bbc9
(svn r10317) -Fix [FS#786]: acceleration not calculated properly when a train goes up a hill between tunnels.
rubidium <rubidium@openttd.org>
parents:
7024
diff
changeset
|
3357 |
19f74693bbc9
(svn r10317) -Fix [FS#786]: acceleration not calculated properly when a train goes up a hill between tunnels.
rubidium <rubidium@openttd.org>
parents:
7024
diff
changeset
|
3358 /* For some reason tunnel tiles are always given as sloped :( |
19f74693bbc9
(svn r10317) -Fix [FS#786]: acceleration not calculated properly when a train goes up a hill between tunnels.
rubidium <rubidium@openttd.org>
parents:
7024
diff
changeset
|
3359 * But they are not sloped... */ |
7079
85d64732a312
(svn r10344) -Fix (r10317): confusion between TRACK_n and TRACK_BIT_n stopped NW/SE slopes being picked up, and compare middle of tile against current z, not previous.
peter1138 <peter1138@openttd.org>
parents:
7070
diff
changeset
|
3360 if (middle_z != v->z_pos && !IsTunnelTile(TileVirtXY(v->x_pos, v->y_pos))) { |
7931
44ff7a6d801f
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7929
diff
changeset
|
3361 SetBit(v->u.rail.flags, (middle_z > old_z) ? VRF_GOINGUP : VRF_GOINGDOWN); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3362 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3363 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3364 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3365 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3366 VehiclePositionChanged(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3367 EndVehicleMove(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3368 return 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
|
3369 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3370 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3371 static const Direction _new_vehicle_direction_table[11] = { |
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
|
3372 DIR_N , DIR_NW, DIR_W , INVALID_DIR, |
c44c070c5032
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents:
5584
diff
changeset
|
3373 DIR_NE, DIR_N , DIR_SW, INVALID_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
|
3374 DIR_E , DIR_SE, DIR_S |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3375 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3376 |
8607
3f393a55911b
(svn r12189) -Codechange: mark some functions in train_cmd.cpp inline (called once or very short)
smatz <smatz@openttd.org>
parents:
8606
diff
changeset
|
3377 static inline Direction GetNewVehicleDirectionByTile(TileIndex new_tile, TileIndex old_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
|
3378 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3379 uint offs = (TileY(new_tile) - TileY(old_tile) + 1) * 4 + |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3380 TileX(new_tile) - TileX(old_tile) + 1; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3381 assert(offs < 11); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3382 return _new_vehicle_direction_table[offs]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3383 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3384 |
8607
3f393a55911b
(svn r12189) -Codechange: mark some functions in train_cmd.cpp inline (called once or very short)
smatz <smatz@openttd.org>
parents:
8606
diff
changeset
|
3385 static inline int GetDirectionToVehicle(const Vehicle *v, int x, int 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
|
3386 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3387 byte offs; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3388 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3389 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
|
3390 if (x >= 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3391 offs = (x > 2) ? 0 : 1; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3392 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3393 offs = (x < -2) ? 2 : 1; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3394 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3395 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3396 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
|
3397 if (y >= 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3398 offs += ((y > 2) ? 0 : 1) * 4; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3399 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3400 offs += ((y < -2) ? 2 : 1) * 4; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3401 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3402 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3403 assert(offs < 11); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3404 return _new_vehicle_direction_table[offs]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3405 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3406 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3407 /* Check if the vehicle is compatible with the specified tile */ |
8607
3f393a55911b
(svn r12189) -Codechange: mark some functions in train_cmd.cpp inline (called once or very short)
smatz <smatz@openttd.org>
parents:
8606
diff
changeset
|
3408 static inline bool CheckCompatibleRail(const Vehicle *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
|
3409 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3410 return |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3411 IsTileOwner(tile, 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
|
3412 !IsFrontEngine(v) || |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
3413 HasBit(v->u.rail.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
|
3414 ); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3415 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3416 |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6247
diff
changeset
|
3417 struct RailtypeSlowdownParams { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3418 byte small_turn, large_turn; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3419 byte z_up; // fraction to remove when moving up |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3420 byte z_down; // fraction to remove when moving down |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6247
diff
changeset
|
3421 }; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3422 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3423 static const RailtypeSlowdownParams _railtype_slowdown[] = { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3424 // normal accel |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
3425 {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
|
3426 {256 / 4, 256 / 2, 256 / 4, 2}, ///< electrified |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
3427 {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
|
3428 {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
|
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 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
3431 /** Modify the speed of the vehicle due to a turn */ |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
3432 static inline void AffectSpeedByDirChange(Vehicle *v, Direction new_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
|
3433 { |
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
|
3434 if (_settings_game.vehicle.realistic_acceleration) 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
|
3435 |
6150 | 3436 DirDiff diff = DirDifference(v->direction, new_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
|
3437 if (diff == DIRDIFF_SAME) return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3438 |
6150 | 3439 const RailtypeSlowdownParams *rsp = &_railtype_slowdown[v->u.rail.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
|
3440 v->cur_speed -= (diff == DIRDIFF_45RIGHT || diff == DIRDIFF_45LEFT ? rsp->small_turn : rsp->large_turn) * v->cur_speed >> 8; |
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 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
3443 /** Modify the speed of the vehicle due to a change in altitude */ |
8607
3f393a55911b
(svn r12189) -Codechange: mark some functions in train_cmd.cpp inline (called once or very short)
smatz <smatz@openttd.org>
parents:
8606
diff
changeset
|
3444 static inline void AffectSpeedByZChange(Vehicle *v, byte old_z) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3445 { |
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
|
3446 if (old_z == v->z_pos || _settings_game.vehicle.realistic_acceleration) 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
|
3447 |
6150 | 3448 const RailtypeSlowdownParams *rsp = &_railtype_slowdown[v->u.rail.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
|
3449 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3450 if (old_z < v->z_pos) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3451 v->cur_speed -= (v->cur_speed * rsp->z_up >> 8); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3452 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3453 uint16 spd = v->cur_speed + rsp->z_down; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3454 if (spd <= v->max_speed) v->cur_speed = spd; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3455 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3456 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3457 |
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
|
3458 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
|
3459 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3460 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
|
3461 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
|
3462 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
|
3463 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
|
3464 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
|
3465 /* 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
|
3466 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
|
3467 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3468 } |
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
|
3469 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
|
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3472 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3473 static void SetVehicleCrashed(Vehicle *v) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3474 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3475 if (v->u.rail.crash_anim_pos != 0) return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3476 |
9811
84013100eac2
(svn r13953) -Add [YAPP]: Free track reservations of crashed trains. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9810
diff
changeset
|
3477 /* Free a possible path reservation and try to mark all tiles occupied by the train reserved. */ |
84013100eac2
(svn r13953) -Add [YAPP]: Free track reservations of crashed trains. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9810
diff
changeset
|
3478 if (IsFrontEngine(v)) { |
84013100eac2
(svn r13953) -Add [YAPP]: Free track reservations of crashed trains. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9810
diff
changeset
|
3479 /* Remove all reservations, also the ones currently under the train |
84013100eac2
(svn r13953) -Add [YAPP]: Free track reservations of crashed trains. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9810
diff
changeset
|
3480 * and any railway station paltform reservation. */ |
84013100eac2
(svn r13953) -Add [YAPP]: Free track reservations of crashed trains. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9810
diff
changeset
|
3481 FreeTrainTrackReservation(v); |
84013100eac2
(svn r13953) -Add [YAPP]: Free track reservations of crashed trains. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9810
diff
changeset
|
3482 for (const Vehicle *u = v; u != NULL; u = u->Next()) { |
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
|
3483 ClearPathReservation(u, u->tile, GetVehicleTrackdir(u)); |
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
|
3484 if (IsTileType(u->tile, MP_TUNNELBRIDGE)) { |
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
|
3485 /* 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
|
3486 * if the train has just entered the wormhole. */ |
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
|
3487 SetTunnelBridgeReservation(GetOtherTunnelBridgeEnd(u->tile), false); |
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
|
3488 } |
9811
84013100eac2
(svn r13953) -Add [YAPP]: Free track reservations of crashed trains. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9810
diff
changeset
|
3489 } |
84013100eac2
(svn r13953) -Add [YAPP]: Free track reservations of crashed trains. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9810
diff
changeset
|
3490 } |
84013100eac2
(svn r13953) -Add [YAPP]: Free track reservations of crashed trains. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9810
diff
changeset
|
3491 |
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
|
3492 /* we may need to update crossing we were approaching */ |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3493 TileIndex crossing = TrainApproachingCrossingTile(v); |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3494 |
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 v->u.rail.crash_anim_pos++; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3496 |
8350
8cde0dcc6818
(svn r11916) -Codechange: use enums from VehicleViewWindowWidgets instead of constants
smatz <smatz@openttd.org>
parents:
8344
diff
changeset
|
3497 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
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
|
3498 InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
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
|
3499 |
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
|
3500 if (v->u.rail.track == TRACK_BIT_DEPOT) { |
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
|
3501 InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
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
|
3502 } |
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
|
3503 |
9297
add307f2e6ea
(svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium <rubidium@openttd.org>
parents:
9274
diff
changeset
|
3504 InvalidateWindowClassesData(WC_TRAINS_LIST, 0); |
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
|
3505 |
9321
14dc836cfed7
(svn r13205) -Codechange: Remove unnecessary code-style-buggering-up macro.
peter1138 <peter1138@openttd.org>
parents:
9297
diff
changeset
|
3506 for (; v != NULL; v = v->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
|
3507 v->vehstatus |= VS_CRASHED; |
8317
7ce2445db70c
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz <smatz@openttd.org>
parents:
8312
diff
changeset
|
3508 MarkSingleVehicleDirty(v); |
9321
14dc836cfed7
(svn r13205) -Codechange: Remove unnecessary code-style-buggering-up macro.
peter1138 <peter1138@openttd.org>
parents:
9297
diff
changeset
|
3509 } |
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
|
3510 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
3511 /* must be updated after the train has been marked crashed */ |
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
|
3512 if (crossing != INVALID_TILE) UpdateLevelCrossing(crossing); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3513 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3514 |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
3515 static uint CountPassengersInTrain(const Vehicle *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
|
3516 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3517 uint num = 0; |
9321
14dc836cfed7
(svn r13205) -Codechange: Remove unnecessary code-style-buggering-up macro.
peter1138 <peter1138@openttd.org>
parents:
9297
diff
changeset
|
3518 |
14dc836cfed7
(svn r13205) -Codechange: Remove unnecessary code-style-buggering-up macro.
peter1138 <peter1138@openttd.org>
parents:
9297
diff
changeset
|
3519 for (; v != NULL; v = v->Next()) { |
7010
f0f87c5a431e
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium <rubidium@openttd.org>
parents:
7002
diff
changeset
|
3520 if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) num += v->cargo.Count(); |
9321
14dc836cfed7
(svn r13205) -Codechange: Remove unnecessary code-style-buggering-up macro.
peter1138 <peter1138@openttd.org>
parents:
9297
diff
changeset
|
3521 } |
14dc836cfed7
(svn r13205) -Codechange: Remove unnecessary code-style-buggering-up macro.
peter1138 <peter1138@openttd.org>
parents:
9297
diff
changeset
|
3522 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3523 return num; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3524 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3525 |
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
|
3526 struct TrainCollideChecker { |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
3527 Vehicle *v; ///< vehicle we are testing for collision |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
3528 uint num; ///< number of dead 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
|
3529 }; |
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
|
3530 |
9775
c3caa51b9888
(svn r13912) -Codechange: remove some casts by returning the proper type instead of void*.
rubidium <rubidium@openttd.org>
parents:
9774
diff
changeset
|
3531 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
|
3532 { |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
3533 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
|
3534 |
8281
a3736272d02a
(svn r11845) -Codechange: simplify train collision detection a bit
smatz <smatz@openttd.org>
parents:
8271
diff
changeset
|
3535 if (v->type != VEH_TRAIN) return NULL; |
a3736272d02a
(svn r11845) -Codechange: simplify train collision detection a bit
smatz <smatz@openttd.org>
parents:
8271
diff
changeset
|
3536 |
a3736272d02a
(svn r11845) -Codechange: simplify train collision detection a bit
smatz <smatz@openttd.org>
parents:
8271
diff
changeset
|
3537 /* get first vehicle now to make most usual checks faster */ |
a3736272d02a
(svn r11845) -Codechange: simplify train collision detection a bit
smatz <smatz@openttd.org>
parents:
8271
diff
changeset
|
3538 Vehicle *coll = v->First(); |
a3736272d02a
(svn r11845) -Codechange: simplify train collision detection a bit
smatz <smatz@openttd.org>
parents:
8271
diff
changeset
|
3539 |
8312
f6764781d2eb
(svn r11877) -Fix: another way to crash competitors' train in a station
smatz <smatz@openttd.org>
parents:
8305
diff
changeset
|
3540 /* can't collide with own wagons && can't crash in depot && the same height level */ |
f6764781d2eb
(svn r11877) -Fix: another way to crash competitors' train in a station
smatz <smatz@openttd.org>
parents:
8305
diff
changeset
|
3541 if (coll != tcc->v && v->u.rail.track != TRACK_BIT_DEPOT && abs(v->z_pos - tcc->v->z_pos) < 6) { |
f6764781d2eb
(svn r11877) -Fix: another way to crash competitors' train in a station
smatz <smatz@openttd.org>
parents:
8305
diff
changeset
|
3542 int x_diff = v->x_pos - tcc->v->x_pos; |
f6764781d2eb
(svn r11877) -Fix: another way to crash competitors' train in a station
smatz <smatz@openttd.org>
parents:
8305
diff
changeset
|
3543 int y_diff = v->y_pos - tcc->v->y_pos; |
f6764781d2eb
(svn r11877) -Fix: another way to crash competitors' train in a station
smatz <smatz@openttd.org>
parents:
8305
diff
changeset
|
3544 |
f6764781d2eb
(svn r11877) -Fix: another way to crash competitors' train in a station
smatz <smatz@openttd.org>
parents:
8305
diff
changeset
|
3545 /* needed to disable possible crash of competitor train in station by building diagonal track at its end */ |
f6764781d2eb
(svn r11877) -Fix: another way to crash competitors' train in a station
smatz <smatz@openttd.org>
parents:
8305
diff
changeset
|
3546 if (x_diff * x_diff + y_diff * y_diff > 25) return NULL; |
f6764781d2eb
(svn r11877) -Fix: another way to crash competitors' train in a station
smatz <smatz@openttd.org>
parents:
8305
diff
changeset
|
3547 |
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
|
3548 if (!(tcc->v->vehstatus & VS_CRASHED)) { |
8312
f6764781d2eb
(svn r11877) -Fix: another way to crash competitors' train in a station
smatz <smatz@openttd.org>
parents:
8305
diff
changeset
|
3549 /* two drivers + passengers killed in train tcc->v (if it was not crashed already) */ |
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
|
3550 tcc->num += 2 + CountPassengersInTrain(tcc->v); |
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
|
3551 SetVehicleCrashed(tcc->v); |
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
|
3552 } |
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
|
3553 |
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
|
3554 if (!(coll->vehstatus & VS_CRASHED)) { |
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
|
3555 /* two drivers + passengers killed in train coll (if it was not crashed already) */ |
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
|
3556 tcc->num += 2 + CountPassengersInTrain(coll); |
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
|
3557 SetVehicleCrashed(coll); |
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
|
3558 } |
9833
80c1295b64df
(svn r13976) -Fix (r13953) [YAPP]: A crashing train could sometimes free the reservation of another train. (assisted by michi_cc)
frosch <frosch@openttd.org>
parents:
9831
diff
changeset
|
3559 |
80c1295b64df
(svn r13976) -Fix (r13953) [YAPP]: A crashing train could sometimes free the reservation of another train. (assisted by michi_cc)
frosch <frosch@openttd.org>
parents:
9831
diff
changeset
|
3560 /* Try to reserve all tiles directly under the crashed trains. |
80c1295b64df
(svn r13976) -Fix (r13953) [YAPP]: A crashing train could sometimes free the reservation of another train. (assisted by michi_cc)
frosch <frosch@openttd.org>
parents:
9831
diff
changeset
|
3561 * As there might be more than two trains involved, we have to do that for all vehicles */ |
80c1295b64df
(svn r13976) -Fix (r13953) [YAPP]: A crashing train could sometimes free the reservation of another train. (assisted by michi_cc)
frosch <frosch@openttd.org>
parents:
9831
diff
changeset
|
3562 const Vehicle *u; |
80c1295b64df
(svn r13976) -Fix (r13953) [YAPP]: A crashing train could sometimes free the reservation of another train. (assisted by michi_cc)
frosch <frosch@openttd.org>
parents:
9831
diff
changeset
|
3563 FOR_ALL_VEHICLES(u) { |
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
|
3564 if (u->type == VEH_TRAIN && HASBITS(u->vehstatus, VS_CRASHED) && (u->u.rail.track & TRACK_BIT_DEPOT) == TRACK_BIT_NONE) { |
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
|
3565 TrackBits trackbits = u->u.rail.track; |
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
|
3566 if ((trackbits & TRACK_BIT_WORMHOLE) == TRACK_BIT_WORMHOLE) { |
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
|
3567 /* Vehicle is inside a wormhole, v->u.rail.track contains no useful value then. */ |
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
|
3568 trackbits |= DiagDirToDiagTrackBits(GetTunnelBridgeDirection(u->tile)); |
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
|
3569 } |
9857
5b6c8f8f755d
(svn r14001) -Fix (r13989): reading wrong variable, train crash on bridge crashes game
smatz <smatz@openttd.org>
parents:
9845
diff
changeset
|
3570 TryReserveRailTrack(u->tile, TrackBitsToTrack(trackbits)); |
9833
80c1295b64df
(svn r13976) -Fix (r13953) [YAPP]: A crashing train could sometimes free the reservation of another train. (assisted by michi_cc)
frosch <frosch@openttd.org>
parents:
9831
diff
changeset
|
3571 } |
80c1295b64df
(svn r13976) -Fix (r13953) [YAPP]: A crashing train could sometimes free the reservation of another train. (assisted by michi_cc)
frosch <frosch@openttd.org>
parents:
9831
diff
changeset
|
3572 } |
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
|
3573 } |
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
|
3574 |
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
|
3575 return NULL; |
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
|
3576 } |
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
|
3577 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
3578 /** |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3579 * 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
|
3580 * 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
|
3581 * 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
|
3582 * plays a sound. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3583 */ |
10282
9f1f7dad1803
(svn r14521) -Fix [FS#2378]: fast trains could continue to move after a crash
glx <glx@openttd.org>
parents:
10261
diff
changeset
|
3584 static bool CheckTrainCollision(Vehicle *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
|
3585 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3586 /* can't collide in depot */ |
10282
9f1f7dad1803
(svn r14521) -Fix [FS#2378]: fast trains could continue to move after a crash
glx <glx@openttd.org>
parents:
10261
diff
changeset
|
3587 if (v->u.rail.track == TRACK_BIT_DEPOT) return false; |
5993
2498be7c7e94
(svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium <rubidium@openttd.org>
parents:
5992
diff
changeset
|
3588 |
2498be7c7e94
(svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium <rubidium@openttd.org>
parents:
5992
diff
changeset
|
3589 assert(v->u.rail.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
|
3590 |
6150 | 3591 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
|
3592 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
|
3593 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
|
3594 |
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
|
3595 /* find colliding vehicles */ |
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
|
3596 if (v->u.rail.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
|
3597 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
|
3598 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
|
3599 } 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
|
3600 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
|
3601 } |
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
|
3602 |
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
|
3603 /* 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
|
3604 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
|
3605 |
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
|
3606 SetDParam(0, tcc.num); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3607 AddNewsItem(STR_8868_TRAIN_CRASH_DIE_IN_FIREBALL, |
9234
02827bf3dc03
(svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium <rubidium@openttd.org>
parents:
9224
diff
changeset
|
3608 NS_ACCIDENT_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
|
3609 v->index, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3610 0 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3611 ); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3612 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3613 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
|
3614 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
|
3615 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
|
3616 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3617 |
9775
c3caa51b9888
(svn r13912) -Codechange: remove some casts by returning the proper type instead of void*.
rubidium <rubidium@openttd.org>
parents:
9774
diff
changeset
|
3618 static Vehicle *CheckVehicleAtSignal(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
|
3619 { |
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
|
3620 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
|
3621 |
9774
693c49258e17
(svn r13911) -Fix (r13806): do not consider crashed train as waiting at signal, v->direction doesn't have to match track anyway
smatz <smatz@openttd.org>
parents:
9738
diff
changeset
|
3622 /* front engine of a train, not inside wormhole or depot, not crashed */ |
693c49258e17
(svn r13911) -Fix (r13806): do not consider crashed train as waiting at signal, v->direction doesn't have to match track anyway
smatz <smatz@openttd.org>
parents:
9738
diff
changeset
|
3623 if (v->type == VEH_TRAIN && IsFrontEngine(v) && (v->u.rail.track & TRACK_BIT_MASK) != 0 && !(v->vehstatus & VS_CRASHED)) { |
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
|
3624 if (v->cur_speed <= 5 && TrainExitDir(v->direction, v->u.rail.track) == exitdir) return 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
|
3625 } |
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
|
3626 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3627 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
|
3628 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3629 |
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
|
3630 static void TrainController(Vehicle *v, Vehicle *nomove, bool update_image) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3631 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3632 Vehicle *prev; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3633 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3634 /* 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
|
3635 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
|
3636 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
|
3637 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
|
3638 BeginVehicleMove(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3639 |
6153 | 3640 GetNewVehiclePosResult gp = GetNewVehiclePos(v); |
5993
2498be7c7e94
(svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium <rubidium@openttd.org>
parents:
5992
diff
changeset
|
3641 if (v->u.rail.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
|
3642 /* Not inside tunnel */ |
6152 | 3643 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
|
3644 /* Staying in the old tile */ |
5993
2498be7c7e94
(svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium <rubidium@openttd.org>
parents:
5992
diff
changeset
|
3645 if (v->u.rail.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
|
3646 /* 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
|
3647 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
|
3648 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
|
3649 } 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
|
3650 /* 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
|
3651 |
5668
3d6d9bff3dd8
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents:
5651
diff
changeset
|
3652 if (IsFrontEngine(v) && !TrainCheckIfLineEnds(v)) return; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3653 |
6150 | 3654 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
|
3655 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
|
3656 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
|
3657 } |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
3658 if (HasBit(r, VETS_ENTERED_STATION)) { |
5991
1b793d99b5ba
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium <rubidium@openttd.org>
parents:
5944
diff
changeset
|
3659 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
|
3660 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3661 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3662 |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8832
diff
changeset
|
3663 if (v->current_order.IsType(OT_LEAVESTATION)) { |
6263
715aa17970ab
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni <bjarni@openttd.org>
parents:
6259
diff
changeset
|
3664 v->current_order.Free(); |
8350
8cde0dcc6818
(svn r11916) -Codechange: use enums from VehicleViewWindowWidgets instead of constants
smatz <smatz@openttd.org>
parents:
8344
diff
changeset
|
3665 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3666 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3667 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3668 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3669 /* 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
|
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 /* Determine what direction we're entering the new tile from */ |
6151 | 3672 Direction dir = GetNewVehicleDirectionByTile(gp.new_tile, gp.old_tile); |
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
|
3673 enterdir = DirToDiagDir(dir); |
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
|
3674 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
|
3675 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3676 /* 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
|
3677 * 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
|
3678 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
|
3679 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
|
3680 |
0a524ed2b87b
(svn r12532) -Cleanup: Replace two tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8793
diff
changeset
|
3681 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
|
3682 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
|
3683 |
9e46ac001a8c
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch <frosch@openttd.org>
parents:
8614
diff
changeset
|
3684 TrackBits bits = TrackdirBitsToTrackBits(trackdirbits); |
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
|
3685 if (_settings_game.pf.pathfinder_for_trains != VPF_NTP && _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
|
3686 /* 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
|
3687 * can be switched on halfway a turn */ |
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
|
3688 bits &= ~TrackCrossesTracks(FindFirstTrack(v->u.rail.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
|
3689 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3690 |
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
|
3691 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
|
3692 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3693 /* Check if the new tile contrains tracks that are compatible |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3694 * 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
|
3695 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
|
3696 |
6150 | 3697 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
|
3698 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
|
3699 /* 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
|
3700 * 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
|
3701 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
|
3702 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
|
3703 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3704 /* Check if it's a red signal and that force proceed is not clicked. */ |
8616
9e46ac001a8c
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch <frosch@openttd.org>
parents:
8614
diff
changeset
|
3705 if (red_signals & chosen_track && v->u.rail.force_proceed == 0) { |
9e46ac001a8c
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch <frosch@openttd.org>
parents:
8614
diff
changeset
|
3706 /* 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
|
3707 Trackdir i = FindFirstTrackdir(trackdirbits); |
6151 | 3708 |
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
|
3709 /* Don't handle stuck trains here. */ |
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
|
3710 if (HasBit(v->u.rail.flags, VRF_TRAIN_STUCK)) return; |
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
|
3711 |
6151 | 3712 if (!HasSignalOnTrackdir(gp.new_tile, ReverseTrackdir(i))) { |
3713 v->cur_speed = 0; | |
3714 v->subspeed = 0; | |
3715 v->progress = 255 - 100; | |
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
|
3716 if (++v->load_unload_time_rem < _settings_game.pf.wait_oneway_signal * 20) return; |
6151 | 3717 } else if (HasSignalOnTrackdir(gp.new_tile, i)) { |
3718 v->cur_speed = 0; | |
3719 v->subspeed = 0; | |
6491
696f0e1b046e
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium <rubidium@openttd.org>
parents:
6490
diff
changeset
|
3720 v->progress = 255 - 10; |
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
|
3721 if (++v->load_unload_time_rem < _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
|
3722 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
|
3723 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
|
3724 |
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
|
3725 exitdir = ReverseDiagDir(exitdir); |
6151 | 3726 |
3727 /* check if a train is waiting on the other side */ | |
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
|
3728 if (!HasVehicleOnPos(o_tile, &exitdir, &CheckVehicleAtSignal)) return; |
6151 | 3729 } |
3730 } | |
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
|
3731 |
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
|
3732 /* If we would reverse but are currently in a PBS block and |
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
|
3733 * reversing of stuck trains is disabled, don't reverse. */ |
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
|
3734 if (_settings_game.pf.wait_for_pbs_path == 255 && UpdateSignalsOnSegment(v->tile, enterdir, v->owner) == SIGSEG_PBS) { |
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
|
3735 v->load_unload_time_rem = 0; |
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
|
3736 return; |
7ad7c8e6ca13
(svn r13962) -Codechange [YAPP]: Do not reverse in front of red signals when inside a PBS block and reversing of stuck trains is disabled. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9819
diff
changeset
|
3737 } |
6151 | 3738 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
|
3739 } 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
|
3740 TryReserveRailTrack(gp.new_tile, TrackBitsToTrack(chosen_track)); |
6151 | 3741 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3742 } 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
|
3743 static const TrackBits _matching_tracks[8] = { |
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
|
3744 TRACK_BIT_LEFT | TRACK_BIT_RIGHT, TRACK_BIT_X, |
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
|
3745 TRACK_BIT_UPPER | TRACK_BIT_LOWER, 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
|
3746 TRACK_BIT_LEFT | TRACK_BIT_RIGHT, TRACK_BIT_X, |
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
|
3747 TRACK_BIT_UPPER | TRACK_BIT_LOWER, 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
|
3748 }; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3749 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3750 /* The wagon is active, simply follow the prev vehicle. */ |
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
|
3751 chosen_track = (TrackBits)(byte)(_matching_tracks[GetDirectionToVehicle(prev, gp.x, gp.y)] & 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
|
3752 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3753 |
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
|
3754 /* 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
|
3755 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
|
3756 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
|
3757 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
|
3758 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
|
3759 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3760 /* Update XY to reflect the entrance to the new tile, and select the direction to use */ |
6150 | 3761 const byte *b = _initial_tile_subcoord[FIND_FIRST_BIT(chosen_track)][enterdir]; |
3762 gp.x = (gp.x & ~0xF) | b[0]; | |
3763 gp.y = (gp.y & ~0xF) | b[1]; | |
3764 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
|
3765 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3766 /* Call the landscape function and tell it that the vehicle entered the tile */ |
6150 | 3767 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
|
3768 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
|
3769 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
|
3770 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3771 |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
3772 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
|
3773 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
|
3774 Trackdir tdir = TrackDirectionToTrackdir(track, chosen_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
|
3775 if (IsFrontEngine(v) && HasPbsSignalOnTrackdir(gp.new_tile, tdir)) { |
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
|
3776 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
|
3777 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
|
3778 } |
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
|
3779 |
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
|
3780 /* Clear any track reservation when the last vehicle leaves the tile */ |
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
|
3781 if (v->Next() == NULL) ClearPathReservation(v, v->tile, GetVehicleTrackdir(v)); |
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
|
3782 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3783 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
|
3784 |
6154 | 3785 if (GetTileRailType(gp.new_tile) != GetTileRailType(gp.old_tile)) { |
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
|
3786 TrainPowerChanged(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
|
3787 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3788 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3789 v->u.rail.track = chosen_track; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3790 assert(v->u.rail.track); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3791 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3792 |
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
|
3793 /* We need to update signal status, but after the vehicle position hash |
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
|
3794 * has been updated by AfterSetTrainPos() */ |
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
|
3795 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
|
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 if (prev == NULL) AffectSpeedByDirChange(v, chosen_dir); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3798 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3799 v->direction = chosen_dir; |
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
|
3800 |
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
|
3801 if (IsFrontEngine(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
|
3802 v->load_unload_time_rem = 0; |
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
|
3803 |
9824
fe3562a51648
(svn r13966) -Codechange [YAPP]: Bar level crossings upon path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9822
diff
changeset
|
3804 /* If we are approching a crossing that is reserved, play the sound now. */ |
fe3562a51648
(svn r13966) -Codechange [YAPP]: Bar level crossings upon path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9822
diff
changeset
|
3805 TileIndex crossing = TrainApproachingCrossingTile(v); |
fe3562a51648
(svn r13966) -Codechange [YAPP]: Bar level crossings upon path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9822
diff
changeset
|
3806 if (crossing != INVALID_TILE && GetCrossingReservation(crossing)) SndPlayTileFx(SND_0E_LEVEL_CROSSING, crossing); |
fe3562a51648
(svn r13966) -Codechange [YAPP]: Bar level crossings upon path reservation. (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9822
diff
changeset
|
3807 |
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
|
3808 /* 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
|
3809 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
|
3810 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3811 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3812 } else { |
8143
1c7033494d92
(svn r11705) -Fix [FS#1557]: trains could have sprites with wrong direction when reversing, also was inconsistent with save/load process (possible desyncs)
smatz <smatz@openttd.org>
parents:
8140
diff
changeset
|
3813 /* In a tunnel or on a bridge |
1c7033494d92
(svn r11705) -Fix [FS#1557]: trains could have sprites with wrong direction when reversing, also was inconsistent with save/load process (possible desyncs)
smatz <smatz@openttd.org>
parents:
8140
diff
changeset
|
3814 * - for tunnels, only the part when the vehicle is not visible (part of enter/exit tile too) |
1c7033494d92
(svn r11705) -Fix [FS#1557]: trains could have sprites with wrong direction when reversing, also was inconsistent with save/load process (possible desyncs)
smatz <smatz@openttd.org>
parents:
8140
diff
changeset
|
3815 * - for bridges, only the middle part - without the bridge heads */ |
6141 | 3816 if (!(v->vehstatus & VS_HIDDEN)) { |
3817 v->cur_speed = | |
8491
cf57eb06b4d9
(svn r12066) -Codechange: Rename GetBridge for the more common GetBridgeSpec
belugas <belugas@openttd.org>
parents:
8482
diff
changeset
|
3818 min(v->cur_speed, GetBridgeSpec(GetBridgeType(v->tile))->speed); |
6141 | 3819 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3820 |
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
|
3821 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
|
3822 /* Perform look-ahead on tunnel exit. */ |
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
|
3823 if (IsFrontEngine(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
|
3824 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
|
3825 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
|
3826 } |
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
|
3827 } 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
|
3828 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
|
3829 v->y_pos = gp.y; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3830 VehiclePositionChanged(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3831 if (!(v->vehstatus & VS_HIDDEN)) EndVehicleMove(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3832 continue; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3833 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3834 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3835 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3836 /* 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
|
3837 v->UpdateDeltaXY(v->direction); |
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
|
3838 if (update_image) v->cur_image = v->GetImage(v->direction); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3839 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3840 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
|
3841 v->y_pos = gp.y; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3842 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3843 /* update the Z position of the vehicle */ |
6150 | 3844 byte old_z = AfterSetTrainPos(v, (gp.new_tile != gp.old_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
|
3845 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3846 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
|
3847 /* 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
|
3848 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
|
3849 } |
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
|
3850 |
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
|
3851 if (update_signals_crossing) { |
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
|
3852 if (IsFrontEngine(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
|
3853 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
|
3854 /* 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
|
3855 * 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
|
3856 * 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
|
3857 * 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
|
3858 * 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
|
3859 * 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
|
3860 * 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
|
3861 * the problem. */ |
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
|
3862 if ((!HasReservedTracks(gp.new_tile, v->u.rail.track) && |
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
|
3863 !TryReserveRailTrack(gp.new_tile, FindFirstTrack(v->u.rail.track))) || |
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
|
3864 !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
|
3865 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
|
3866 } |
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
|
3867 } |
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
|
3868 } |
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
|
3869 |
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
|
3870 /* 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
|
3871 * (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
|
3872 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
|
3873 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
|
3874 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
|
3875 } |
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
|
3876 } |
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
|
3877 |
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
|
3878 /* Do not check on every tick to save some computing time. */ |
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
|
3879 if (IsFrontEngine(v) && 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
|
3880 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3881 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3882 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3883 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
|
3884 /* 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
|
3885 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
|
3886 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3887 reverse_train_direction: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3888 v->load_unload_time_rem = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3889 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
|
3890 v->subspeed = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3891 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
|
3892 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3893 |
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
|
3894 /** 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
|
3895 * @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
|
3896 * @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
|
3897 * @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
|
3898 */ |
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
|
3899 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
|
3900 { |
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
|
3901 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
|
3902 |
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
|
3903 if (v->type == VEH_TRAIN && (v->vehstatus & VS_CRASHED) != 0) { |
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
|
3904 if ((v->u.rail.track & TRACK_BIT_WORMHOLE) == TRACK_BIT_WORMHOLE) { |
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
|
3905 /* Vehicle is inside a wormhole, v->u.rail.track contains no useful value then. */ |
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
|
3906 *trackbits |= DiagDirToDiagTrackBits(GetTunnelBridgeDirection(v->tile)); |
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
|
3907 } else { |
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
|
3908 *trackbits |= v->u.rail.track; |
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
|
3909 } |
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
|
3910 } |
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
|
3911 |
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
|
3912 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
|
3913 } |
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
|
3914 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3915 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3916 * 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
|
3917 * 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
|
3918 * 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
|
3919 * 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
|
3920 * @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
|
3921 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3922 static void DeleteLastWagon(Vehicle *v) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3923 { |
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
|
3924 Vehicle *first = v->First(); |
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
|
3925 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3926 /* 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
|
3927 * *u is then the one-before-last wagon, and *v the last |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3928 * one which will physicially be removed */ |
6150 | 3929 Vehicle *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
|
3930 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
|
3931 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
|
3932 |
10493
5531e81401ee
(svn r14748) -Codechange: unduplicate window updating when deleting vehicles.
rubidium <rubidium@openttd.org>
parents:
10492
diff
changeset
|
3933 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
|
3934 /* Recalculate cached train properties */ |
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
|
3935 TrainConsistChanged(first, 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
|
3936 /* 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
|
3937 * if v == first, then it is updated in PreDestructor() */ |
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
|
3938 if (first->u.rail.track == TRACK_BIT_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
|
3939 InvalidateWindow(WC_VEHICLE_DEPOT, first->tile); |
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
|
3940 } |
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
|
3941 } |
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
|
3942 |
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
|
3943 /* 'v' shouldn't be accessed after it has been deleted */ |
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
|
3944 TrackBits trackbits = v->u.rail.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
|
3945 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
|
3946 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
|
3947 |
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
|
3948 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
|
3949 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
|
3950 |
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
|
3951 if ((trackbits & TRACK_BIT_WORMHOLE) == TRACK_BIT_WORMHOLE) { |
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
|
3952 /* Vehicle is inside a wormhole, v->u.rail.track contains no useful value then. */ |
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
|
3953 trackbits |= DiagDirToDiagTrackBits(GetTunnelBridgeDirection(tile)); |
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
|
3954 } |
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
|
3955 |
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
|
3956 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
|
3957 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
|
3958 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
|
3959 |
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
|
3960 /* 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
|
3961 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
|
3962 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
|
3963 |
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
|
3964 /* 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
|
3965 assert(TRACK_BEGIN == TRACK_X && TRACK_Y == TRACK_BEGIN + 1); |
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
|
3966 for (Track t = TRACK_BEGIN; t < TRACK_END; t++) { |
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
|
3967 if (HasBit(remaining_trackbits, t)) { |
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
|
3968 TryReserveRailTrack(tile, t); |
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
|
3969 } |
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
|
3970 } |
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
|
3971 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3972 |
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
|
3973 /* 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
|
3974 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
|
3975 |
8257
38d56fa7b6f7
(svn r11821) -Fix (r11802): 'optimization assert' when removing crashed wagon in some cases
smatz <smatz@openttd.org>
parents:
8256
diff
changeset
|
3976 /* 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
|
3977 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
|
3978 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
|
3979 } 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
|
3980 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
|
3981 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3982 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3983 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3984 static void ChangeTrainDirRandomly(Vehicle *v) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3985 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3986 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
|
3987 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
|
3988 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3989 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3990 do { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3991 /* 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
|
3992 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
|
3993 v->direction = ChangeDir(v->direction, delta[GB(Random(), 0, 2)]); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3994 BeginVehicleMove(v); |
6558
2fc024ee8217
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium <rubidium@openttd.org>
parents:
6554
diff
changeset
|
3995 v->UpdateDeltaXY(v->direction); |
7134
e1c4f52f82cd
(svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium <rubidium@openttd.org>
parents:
7109
diff
changeset
|
3996 v->cur_image = v->GetImage(v->direction); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3997 /* Refrain from updating the z position of the vehicle when on |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
3998 * a bridge, because AfterSetTrainPos will put the vehicle under |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
3999 * the bridge in that case */ |
5993
2498be7c7e94
(svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium <rubidium@openttd.org>
parents:
5992
diff
changeset
|
4000 if (v->u.rail.track != TRACK_BIT_WORMHOLE) AfterSetTrainPos(v, 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
|
4001 } |
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
|
4002 } 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
|
4003 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4004 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4005 static void HandleCrashedTrain(Vehicle *v) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4006 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4007 int state = ++v->u.rail.crash_anim_pos; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4008 |
5993
2498be7c7e94
(svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium <rubidium@openttd.org>
parents:
5992
diff
changeset
|
4009 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
|
4010 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
|
4011 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4012 |
6150 | 4013 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
|
4014 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
|
4015 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
|
4016 |
6150 | 4017 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
|
4018 do { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4019 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
|
4020 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
|
4021 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4022 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
|
4023 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
|
4024 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
|
4025 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
|
4026 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
|
4027 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4028 } |
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
|
4029 } 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
|
4030 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4031 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4032 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
|
4033 |
8969
01cc3ee6ecb1
(svn r12761) -Codechange: lots of minor whitespace coding style fixes around operators.
rubidium <rubidium@openttd.org>
parents:
8962
diff
changeset
|
4034 if (state >= 4440 && !(v->tick_counter & 0x1F)) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4035 DeleteLastWagon(v); |
6643
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6608
diff
changeset
|
4036 InvalidateWindow(WC_REPLACE_VEHICLE, (v->group_id << 16) | VEH_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
|
4037 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4038 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4039 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4040 static void HandleBrokenTrain(Vehicle *v) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4041 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4042 if (v->breakdown_ctr != 1) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4043 v->breakdown_ctr = 1; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4044 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
|
4045 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4046 if (v->breakdowns_since_last_service != 255) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4047 v->breakdowns_since_last_service++; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4048 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4049 InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4050 InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4051 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4052 if (!PlayVehicleSound(v, VSE_BREAKDOWN)) { |
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
|
4053 SndPlayVehicleFx((_settings_game.game_creation.landscape != LT_TOYLAND) ? |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4054 SND_10_TRAIN_BREAKDOWN : SND_3A_COMEDY_BREAKDOWN_2, v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4055 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4056 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4057 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
|
4058 Vehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE); |
9008
bc4efc6bfe0d
(svn r12803) -Cleanup: rename SpecialVehicle to EffectVehicle to have a uniform naming of the thing instead of using both names for the same thing.
rubidium <rubidium@openttd.org>
parents:
9003
diff
changeset
|
4059 if (u != NULL) u->u.effect.animation_state = v->breakdown_delay * 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
|
4060 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4061 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4062 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4063 if (!(v->tick_counter & 3)) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4064 if (!--v->breakdown_delay) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4065 v->breakdown_ctr = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4066 InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4067 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4068 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4069 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4070 |
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
|
4071 /** 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
|
4072 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
|
4073 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
|
4074 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4075 |
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
|
4076 |
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
|
4077 /** |
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
|
4078 * 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
|
4079 * |
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
|
4080 * @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
|
4081 * @param signal not line end, just a red signal |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
4082 * @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
|
4083 */ |
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
|
4084 static bool TrainApproachingLineEnd(Vehicle *v, bool signal) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4085 { |
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
|
4086 /* Calc position within the current tile */ |
6150 | 4087 uint x = v->x_pos & 0xF; |
4088 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
|
4089 |
8312
f6764781d2eb
(svn r11877) -Fix: another way to crash competitors' train in a station
smatz <smatz@openttd.org>
parents:
8305
diff
changeset
|
4090 /* 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
|
4091 * 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
|
4092 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
|
4093 case DIR_N : x = ~x + ~y + 25; 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
|
4094 case DIR_NW: x = y; /* FALLTHROUGH */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4095 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
|
4096 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
|
4097 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
|
4098 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
|
4099 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
|
4100 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
|
4101 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4102 |
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
|
4103 /* do not reverse when approaching red signal */ |
10287
0c7e03c29975
(svn r14526) -Fix [FS#2379]: make sure trains stop at the end of a station; a 3/8th length train did stop 2/8th of it's length too early causing a 63/8th long train not to fit in a 4 tile station.
rubidium <rubidium@openttd.org>
parents:
10282
diff
changeset
|
4104 if (!signal && x + (v->u.rail.cached_veh_length + 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
|
4105 /* 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
|
4106 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
|
4107 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
|
4108 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
|
4109 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4110 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
4111 /* 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
|
4112 v->vehstatus |= VS_TRAIN_SLOWING; |
6150 | 4113 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
|
4114 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
|
4115 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4116 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
|
4117 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4118 |
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
|
4119 |
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
|
4120 /** |
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
|
4121 * 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
|
4122 * @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
|
4123 * @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
|
4124 */ |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
4125 static bool TrainCanLeaveTile(const Vehicle *v) |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
4126 { |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
4127 /* Exit if inside a tunnel/bridge or a depot */ |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
4128 if (v->u.rail.track == TRACK_BIT_WORMHOLE || v->u.rail.track == TRACK_BIT_DEPOT) 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
|
4129 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
4130 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
|
4131 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
4132 /* 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
|
4133 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
|
4134 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
|
4135 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
|
4136 } |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
4137 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
4138 /* 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
|
4139 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
|
4140 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
|
4141 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
|
4142 } |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
4143 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
4144 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
|
4145 } |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
4146 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
4147 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
4148 /** |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
4149 * 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
|
4150 * (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
|
4151 * @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
|
4152 * @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
|
4153 * @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
|
4154 */ |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
4155 static TileIndex TrainApproachingCrossingTile(const Vehicle *v) |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
4156 { |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
4157 assert(IsFrontEngine(v)); |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
4158 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
|
4159 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
4160 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
|
4161 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
4162 DiagDirection dir = TrainExitDir(v->direction, v->u.rail.track); |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
4163 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
|
4164 |
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
|
4165 /* 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
|
4166 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
|
4167 !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
|
4168 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
|
4169 } |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
4170 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
4171 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
|
4172 } |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
4173 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
4174 |
6ed81efdeff6
(svn r11900) -Fix: set correctly crossing state after train reversal, train leaving crossing, train crash
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
4175 /** |
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
|
4176 * 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
|
4177 * |
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
|
4178 * @param v vehicle we are checking |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
4179 * @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
|
4180 */ |
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
|
4181 static bool TrainCheckIfLineEnds(Vehicle *v) |
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
|
4182 { |
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
|
4183 /* 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
|
4184 |
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
|
4185 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
|
4186 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
|
4187 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
|
4188 |
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
|
4189 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
|
4190 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
|
4191 } 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
|
4192 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
|
4193 } |
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
|
4194 |
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
|
4195 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
|
4196 |
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
|
4197 /* Determine the non-diagonal direction in which we will exit this tile */ |
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
|
4198 DiagDirection dir = TrainExitDir(v->direction, v->u.rail.track); |
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
|
4199 /* 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
|
4200 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
|
4201 |
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
|
4202 /* 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
|
4203 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
|
4204 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
|
4205 |
0a524ed2b87b
(svn r12532) -Cleanup: Replace two tables of magic values with already existing functions.
frosch <frosch@openttd.org>
parents:
8793
diff
changeset
|
4206 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
|
4207 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
|
4208 |
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
|
4209 /* 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
|
4210 |
8482
dd2dbdff6d0d
(svn r12057) -Fix: slowdown train when approaching 90deg turn when 90deg turns are forbidden
smatz <smatz@openttd.org>
parents:
8467
diff
changeset
|
4211 /* 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
|
4212 TrackBits bits = TrackdirBitsToTrackBits(trackdirbits); |
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
|
4213 if (_settings_game.pf.pathfinder_for_trains != VPF_NTP && _settings_game.pf.forbid_90_deg) { |
8482
dd2dbdff6d0d
(svn r12057) -Fix: slowdown train when approaching 90deg turn when 90deg turns are forbidden
smatz <smatz@openttd.org>
parents:
8467
diff
changeset
|
4214 bits &= ~TrackCrossesTracks(FindFirstTrack(v->u.rail.track)); |
dd2dbdff6d0d
(svn r12057) -Fix: slowdown train when approaching 90deg turn when 90deg turns are forbidden
smatz <smatz@openttd.org>
parents:
8467
diff
changeset
|
4215 } |
dd2dbdff6d0d
(svn r12057) -Fix: slowdown train when approaching 90deg turn when 90deg turns are forbidden
smatz <smatz@openttd.org>
parents:
8467
diff
changeset
|
4216 |
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
|
4217 /* 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
|
4218 if (bits == TRACK_BIT_NONE || !CheckCompatibleRail(v, tile)) { |
8305
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
4219 return TrainApproachingLineEnd(v, false); |
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
4220 } |
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
|
4221 |
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
|
4222 /* approaching red signal */ |
8616
9e46ac001a8c
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch <frosch@openttd.org>
parents:
8614
diff
changeset
|
4223 if ((trackdirbits & red_signals) != 0) return TrainApproachingLineEnd(v, true); |
8305
1e1e16a1129c
(svn r11870) -Fix: slow down train when approaching tile we can't enter in more cases
smatz <smatz@openttd.org>
parents:
8302
diff
changeset
|
4224 |
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
|
4225 /* 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
|
4226 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
|
4227 |
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
|
4228 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
|
4229 } |
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
|
4230 |
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
|
4231 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4232 static void TrainLocoHandler(Vehicle *v, bool mode) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4233 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4234 /* 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
|
4235 if (v->vehstatus & VS_CRASHED) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4236 if (!mode) HandleCrashedTrain(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4237 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4238 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4239 |
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
|
4240 if (v->u.rail.force_proceed != 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
|
4241 v->u.rail.force_proceed--; |
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
|
4242 ClrBit(v->u.rail.flags, VRF_TRAIN_STUCK); |
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
|
4243 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
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
|
4244 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4245 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4246 /* train is broken down? */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4247 if (v->breakdown_ctr != 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4248 if (v->breakdown_ctr <= 2) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4249 HandleBrokenTrain(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4250 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4251 } |
9000
75ae4890d738
(svn r12795) -Fix [FS#1938]: vehicles could break down during loading and keep loading. The intention of the break down code is not to break down when having zero speed, therefor break downs now do not happen when loading.
rubidium <rubidium@openttd.org>
parents:
8969
diff
changeset
|
4252 if (!v->current_order.IsType(OT_LOADING)) v->breakdown_ctr--; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4253 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4254 |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
4255 if (HasBit(v->u.rail.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
|
4256 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
|
4257 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4258 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4259 /* exit if train is stopped */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4260 if (v->vehstatus & VS_STOPPED && v->cur_speed == 0) return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4261 |
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
|
4262 bool valid_order = v->current_order.IsValid() && 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
|
4263 if (ProcessOrders(v) && CheckReverseTrain(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
|
4264 v->load_unload_time_rem = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4265 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
|
4266 v->subspeed = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4267 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
|
4268 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4269 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4270 |
6594
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6593
diff
changeset
|
4271 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
|
4272 |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8832
diff
changeset
|
4273 if (v->current_order.IsType(OT_LOADING)) 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
|
4274 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4275 if (CheckTrainStayInDepot(v)) return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4276 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4277 if (!mode) HandleLocomotiveSmokeCloud(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4278 |
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
|
4279 /* We had no order but have an order now, do 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
|
4280 if (!valid_order && v->current_order.IsValid()) { |
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
|
4281 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
|
4282 } |
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
|
4283 |
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
|
4284 /* Handle stuck trains. */ |
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
|
4285 if (!mode && HasBit(v->u.rail.flags, VRF_TRAIN_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
|
4286 ++v->load_unload_time_rem; |
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
|
4287 |
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
|
4288 /* Should we try reversing this tick if 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
|
4289 bool turn_around = v->load_unload_time_rem % (_settings_game.pf.wait_for_pbs_path * DAY_TICKS) == 0 && _settings_game.pf.wait_for_pbs_path < 255; |
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
|
4290 |
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
|
4291 if (!turn_around && v->load_unload_time_rem % _settings_game.pf.path_backoff_interval != 0 && v->u.rail.force_proceed == 0) return; |
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
|
4292 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
|
4293 /* 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
|
4294 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
|
4295 |
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
|
4296 if (HasBit(v->u.rail.flags, VRF_TRAIN_STUCK) && v->load_unload_time_rem > 2 * _settings_game.pf.wait_for_pbs_path * DAY_TICKS) { |
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
|
4297 /* Show message to player. */ |
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
|
4298 if (_settings_client.gui.lost_train_warn && v->owner == _local_company) { |
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
|
4299 SetDParam(0, v->unitnumber); |
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
|
4300 AddNewsItem( |
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
|
4301 STR_TRAIN_IS_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
|
4302 NS_ADVICE, |
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
|
4303 v->index, |
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
|
4304 0); |
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
|
4305 } |
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
|
4306 v->load_unload_time_rem = 0; |
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
|
4307 } |
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
|
4308 /* Exit if force proceed not pressed, else reset stuck flag anyway. */ |
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
|
4309 if (v->u.rail.force_proceed == 0) return; |
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
|
4310 ClrBit(v->u.rail.flags, VRF_TRAIN_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
|
4311 v->load_unload_time_rem = 0; |
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
|
4312 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
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
|
4313 } |
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
|
4314 } |
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
|
4315 |
6150 | 4316 int j = UpdateTrainSpeed(v); |
8426
916b061b84a0
(svn r11996) -Fix [FS#1706]: update train statusbar when stopping from zero speed
smatz <smatz@openttd.org>
parents:
8390
diff
changeset
|
4317 |
916b061b84a0
(svn r11996) -Fix [FS#1706]: update train statusbar when stopping from zero speed
smatz <smatz@openttd.org>
parents:
8390
diff
changeset
|
4318 /* we need to invalidate the widget if we are stopping from 'Stopping 0 km/h' to 'Stopped' */ |
916b061b84a0
(svn r11996) -Fix [FS#1706]: update train statusbar when stopping from zero speed
smatz <smatz@openttd.org>
parents:
8390
diff
changeset
|
4319 if (v->cur_speed == 0 && v->u.rail.last_speed == 0 && v->vehstatus & VS_STOPPED) { |
916b061b84a0
(svn r11996) -Fix [FS#1706]: update train statusbar when stopping from zero speed
smatz <smatz@openttd.org>
parents:
8390
diff
changeset
|
4320 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
916b061b84a0
(svn r11996) -Fix [FS#1706]: update train statusbar when stopping from zero speed
smatz <smatz@openttd.org>
parents:
8390
diff
changeset
|
4321 } |
916b061b84a0
(svn r11996) -Fix [FS#1706]: update train statusbar when stopping from zero speed
smatz <smatz@openttd.org>
parents:
8390
diff
changeset
|
4322 |
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
|
4323 int adv_spd = (v->direction & 1) ? 192 : 256; |
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
|
4324 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
|
4325 /* if the vehicle has speed 0, update the last_speed field. */ |
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
|
4326 if (v->cur_speed == 0) SetLastSpeed(v, v->cur_speed); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4327 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4328 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
|
4329 /* Loop until the train has finished moving. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4330 do { |
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
|
4331 j -= adv_spd; |
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
|
4332 TrainController(v, NULL, true); |
10282
9f1f7dad1803
(svn r14521) -Fix [FS#2378]: fast trains could continue to move after a crash
glx <glx@openttd.org>
parents:
10261
diff
changeset
|
4333 /* Don't continue to move if the train crashed. */ |
9f1f7dad1803
(svn r14521) -Fix [FS#2378]: fast trains could continue to move after a crash
glx <glx@openttd.org>
parents:
10261
diff
changeset
|
4334 if (CheckTrainCollision(v)) break; |
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
|
4335 /* 192 spd used for going straight, 256 for going diagonally. */ |
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
|
4336 adv_spd = (v->direction & 1) ? 192 : 256; |
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
|
4337 } while (j >= adv_spd); |
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
|
4338 SetLastSpeed(v, v->cur_speed); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4339 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4340 |
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
|
4341 if (v->progress == 0) v->progress = j; // Save unused spd for next time, if TrainController didn't set progress |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4342 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4343 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4344 |
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
|
4345 |
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
|
4346 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
|
4347 { |
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
|
4348 Money cost = 0; |
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
|
4349 const Vehicle *v = this; |
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
|
4350 |
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
|
4351 do { |
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
|
4352 const RailVehicleInfo *rvi = RailVehInfo(v->engine_type); |
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
|
4353 |
8622
8cccfd1e3607
(svn r12205) -Codechange: rename RailVehicleInfo::running_cost_base to running_cost, inline with other vehicle types (It is the factor, not the base)
peter1138 <peter1138@openttd.org>
parents:
8620
diff
changeset
|
4354 byte cost_factor = GetVehicleProperty(v, 0x0D, rvi->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
|
4355 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
|
4356 |
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
|
4357 /* Halve running cost for multiheaded parts */ |
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
|
4358 if (IsMultiheaded(v)) cost_factor /= 2; |
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
|
4359 |
8626
e6ad3a9cdfcb
(svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138 <peter1138@openttd.org>
parents:
8622
diff
changeset
|
4360 cost += cost_factor * GetPriceByIndex(rvi->running_cost_class); |
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
|
4361 } while ((v = GetNextVehicle(v)) != NULL); |
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
|
4362 |
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
|
4363 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
|
4364 } |
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
|
4365 |
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
|
4366 |
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
|
4367 void 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
|
4368 { |
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
|
4369 if (_age_cargo_skip_counter == 0) this->cargo.AgeCargo(); |
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
|
4370 |
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
|
4371 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
|
4372 |
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
|
4373 if (IsFrontEngine(this)) { |
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
|
4374 if (!(this->vehstatus & VS_STOPPED)) this->running_ticks++; |
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
|
4375 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
|
4376 |
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
|
4377 TrainLocoHandler(this, 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
|
4378 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
4379 /* make sure vehicle wasn't deleted. */ |
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
|
4380 if (this->type == VEH_TRAIN && IsFrontEngine(this)) |
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
|
4381 TrainLocoHandler(this, true); |
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
|
4382 } else if (IsFreeWagon(this) && HASBITS(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
|
4383 /* Delete flooded standalone wagon chain */ |
10492
28fa021b003c
(svn r14747) -Codechange: remove DeleteVehicleChain in favour of the vehicle destructor as that was already doing the same for a few vehicle types.
rubidium <rubidium@openttd.org>
parents:
10488
diff
changeset
|
4384 if (++this->u.rail.crash_anim_pos >= 4400) delete 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
|
4385 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4386 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4387 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4388 static void CheckIfTrainNeedsService(Vehicle *v) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4389 { |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
4390 static const uint MAX_ACCEPTABLE_DEPOT_DIST = 16; |
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
4391 |
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
|
4392 if (_settings_game.vehicle.servint_trains == 0 || !v->NeedsAutomaticServicing()) return; |
7502
2250b8ea9466
(svn r11017) -Codechange: unify determining whether a vehicle needs/can be service a little more.
rubidium <rubidium@openttd.org>
parents:
7497
diff
changeset
|
4393 if (v->IsInDepot()) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4394 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
|
4395 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4396 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4397 |
6150 | 4398 TrainFindDepotData tfdd = FindClosestTrainDepot(v, MAX_ACCEPTABLE_DEPOT_DIST); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4399 /* Only go to the depot if it is not too far out of our way. */ |
10236
59398a628f10
(svn r14464) -Codechange: replace (uint)-1 with UINT_MAX (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10214
diff
changeset
|
4400 if (tfdd.best_length == UINT_MAX || tfdd.best_length > MAX_ACCEPTABLE_DEPOT_DIST) { |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8832
diff
changeset
|
4401 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
|
4402 /* 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
|
4403 * 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
|
4404 * schedule? */ |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8832
diff
changeset
|
4405 v->current_order.MakeDummy(); |
8350
8cde0dcc6818
(svn r11916) -Codechange: use enums from VehicleViewWindowWidgets instead of constants
smatz <smatz@openttd.org>
parents:
8344
diff
changeset
|
4406 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4407 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4408 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4409 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4410 |
8850
4859a9c43de3
(svn r12605) -Cleanup: variable scope and coding style in train*
smatz <smatz@openttd.org>
parents:
8843
diff
changeset
|
4411 const Depot *depot = GetDepotByTile(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
|
4412 |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8832
diff
changeset
|
4413 if (v->current_order.IsType(OT_GOTO_DEPOT) && |
8840
c3d2f0eb69a1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium <rubidium@openttd.org>
parents:
8836
diff
changeset
|
4414 v->current_order.GetDestination() != depot->index && |
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
|
4415 !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
|
4416 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4417 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4418 |
8853
02787d6f3834
(svn r12615) -Codechange: rename some enums related to depot orders to make it more clear that they are no loading/unloading flags. Also add more type strictness.
rubidium <rubidium@openttd.org>
parents:
8850
diff
changeset
|
4419 v->current_order.MakeGoToDepot(depot->index, 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
|
4420 v->dest_tile = tfdd.tile; |
8350
8cde0dcc6818
(svn r11916) -Codechange: use enums from VehicleViewWindowWidgets instead of constants
smatz <smatz@openttd.org>
parents:
8344
diff
changeset
|
4421 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4422 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4423 |
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
|
4424 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
|
4425 { |
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
|
4426 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
|
4427 |
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
|
4428 if (IsFrontEngine(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
|
4429 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
|
4430 AgeVehicle(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
|
4431 |
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
|
4432 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
|
4433 |
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
|
4434 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
|
4435 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4436 /* update destination */ |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8832
diff
changeset
|
4437 if (this->current_order.IsType(OT_GOTO_STATION)) { |
8840
c3d2f0eb69a1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium <rubidium@openttd.org>
parents:
8836
diff
changeset
|
4438 TileIndex tile = GetStation(this->current_order.GetDestination())->train_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
|
4439 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
|
4440 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4441 |
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
|
4442 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
|
4443 /* running costs */ |
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
|
4444 CommandCost cost(EXPENSES_TRAIN_RUN, this->GetRunningCost() * this->running_ticks / (364 * DAY_TICKS)); |
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
|
4445 |
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
|
4446 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
|
4447 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
|
4448 |
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
|
4449 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
|
4450 |
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
|
4451 InvalidateWindow(WC_VEHICLE_DETAILS, this->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
|
4452 InvalidateWindowClasses(WC_TRAINS_LIST); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4453 } |
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
|
4454 } else if (IsTrainEngine(this)) { |
7024
ffcf8db1b498
(svn r10288) -Fix [FS#202]: also age engines that aren't front-engines (based on a patch by kaan)
truelight <truelight@openttd.org>
parents:
7023
diff
changeset
|
4455 /* Also age engines that aren't front engines */ |
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
|
4456 AgeVehicle(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
|
4457 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4458 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4459 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6176
diff
changeset
|
4460 void TrainsYearlyLoop() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4461 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4462 Vehicle *v; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4463 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4464 FOR_ALL_VEHICLES(v) { |
6259
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
4465 if (v->type == VEH_TRAIN && IsFrontEngine(v)) { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
4466 /* show warning if train is not generating enough income last 2 years (corresponds to a red icon in the vehicle list) */ |
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
|
4467 if (_settings_client.gui.train_income_warn && v->owner == _local_company && v->age >= 730 && v->GetDisplayProfitThisYear() < 0) { |
8614
36bb76188638
(svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
smatz <smatz@openttd.org>
parents:
8612
diff
changeset
|
4468 SetDParam(1, v->GetDisplayProfitThisYear()); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4469 SetDParam(0, v->unitnumber); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4470 AddNewsItem( |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4471 STR_TRAIN_IS_UNPROFITABLE, |
9234
02827bf3dc03
(svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium <rubidium@openttd.org>
parents:
9224
diff
changeset
|
4472 NS_ADVICE, |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4473 v->index, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4474 0); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4475 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4476 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4477 v->profit_last_year = v->profit_this_year; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4478 v->profit_this_year = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4479 InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4480 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4481 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4482 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4483 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4484 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6176
diff
changeset
|
4485 void InitializeTrains() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4486 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4487 _age_cargo_skip_counter = 1; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4488 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4489 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4490 /* |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4491 * Link front and rear multiheaded engines to each other |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4492 * This is done when loading a savegame |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4493 */ |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6176
diff
changeset
|
4494 void ConnectMultiheadedTrains() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4495 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4496 Vehicle *v; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4497 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4498 FOR_ALL_VEHICLES(v) { |
6259
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
4499 if (v->type == VEH_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
|
4500 v->u.rail.other_multiheaded_part = NULL; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4501 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4502 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4503 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4504 FOR_ALL_VEHICLES(v) { |
10173
513fed326ea2
(svn r14366) -Fix (r14362): Match multiheaded parts starting from the first vehicle in a chain.
frosch <frosch@openttd.org>
parents:
10170
diff
changeset
|
4505 if (v->type == VEH_TRAIN && (IsFrontEngine(v) || IsFreeWagon(v))) { |
10170
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4506 /* Two ways to associate multiheaded parts to each other: |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4507 * sequential-matching: Trains shall be arranged to look like <..>..<..>..<..>.. |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4508 * bracket-matching: Free vehicle chains shall be arranged to look like ..<..<..>..<..>..>.. |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4509 * |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4510 * Note: Old savegames might contain chains which do not comply with these rules, e.g. |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4511 * - the front and read parts have invalid orders |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4512 * - different engine types might be combined |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4513 * - there might be different amounts of front and rear parts. |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4514 * |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4515 * Note: The multiheaded parts need to be matched exactly like they are matched on the server, else desyncs will occur. |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4516 * This is why two matching strategies are needed. |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4517 */ |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4518 |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4519 bool sequential_matching = IsFrontEngine(v); |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4520 |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4521 for (Vehicle *u = v; u != NULL; u = GetNextVehicle(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
|
4522 if (u->u.rail.other_multiheaded_part != NULL) continue; // we already linked this one |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4523 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4524 if (IsMultiheaded(u)) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4525 if (!IsTrainEngine(u)) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4526 /* we got a rear car without a front car. We will convert it to a front one */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4527 SetTrainEngine(u); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4528 u->spritenum--; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4529 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4530 |
10170
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4531 /* Find a matching back part */ |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4532 EngineID eid = u->engine_type; |
6150 | 4533 Vehicle *w; |
10170
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4534 if (sequential_matching) { |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4535 for (w = GetNextVehicle(u); w != NULL; w = GetNextVehicle(w)) { |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4536 if (w->engine_type != eid || w->u.rail.other_multiheaded_part != NULL || !IsMultiheaded(w)) continue; |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4537 |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4538 /* we found a car to partner with this engine. Now we will make sure it face the right way */ |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4539 if (IsTrainEngine(w)) { |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4540 ClearTrainEngine(w); |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4541 w->spritenum++; |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4542 } |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4543 break; |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4544 } |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4545 } else { |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4546 uint stack_pos = 0; |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4547 for (w = GetNextVehicle(u); w != NULL; w = GetNextVehicle(w)) { |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4548 if (w->engine_type != eid || w->u.rail.other_multiheaded_part != NULL || !IsMultiheaded(w)) continue; |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4549 |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4550 if (IsTrainEngine(w)) { |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4551 stack_pos++; |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4552 } else { |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4553 if (stack_pos == 0) break; |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4554 stack_pos--; |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4555 } |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4556 } |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4557 } |
888c46c8f633
(svn r14362) -Fix (r3403): Also connect multiheaded parts in free wagon chains.
frosch <frosch@openttd.org>
parents:
10123
diff
changeset
|
4558 |
6150 | 4559 if (w != NULL) { |
4560 w->u.rail.other_multiheaded_part = u; | |
4561 u->u.rail.other_multiheaded_part = w; | |
4562 } else { | |
4563 /* we got a front car and no rear cars. We will fake this one for forget that it should have been multiheaded */ | |
4564 ClearMultiheaded(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
|
4565 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4566 } |
9321
14dc836cfed7
(svn r13205) -Codechange: Remove unnecessary code-style-buggering-up macro.
peter1138 <peter1138@openttd.org>
parents:
9297
diff
changeset
|
4567 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4568 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4569 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4570 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4571 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6407
diff
changeset
|
4572 /** |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4573 * Converts all trains to the new subtype format introduced in savegame 16.2 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4574 * It also links multiheaded engines or make them forget they are multiheaded if no suitable partner is found |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4575 */ |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6176
diff
changeset
|
4576 void ConvertOldMultiheadToNew() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4577 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4578 Vehicle *v; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4579 FOR_ALL_VEHICLES(v) { |
6259
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
4580 if (v->type == VEH_TRAIN) { |
7931
44ff7a6d801f
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7929
diff
changeset
|
4581 SetBit(v->subtype, 7); // indicates that it's the old format and needs to be converted in the next loop |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4582 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4583 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4584 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4585 FOR_ALL_VEHICLES(v) { |
6259
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
4586 if (v->type == VEH_TRAIN) { |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
4587 if (HasBit(v->subtype, 7) && ((v->subtype & ~0x80) == 0 || (v->subtype & ~0x80) == 4)) { |
9321
14dc836cfed7
(svn r13205) -Codechange: Remove unnecessary code-style-buggering-up macro.
peter1138 <peter1138@openttd.org>
parents:
9297
diff
changeset
|
4588 for (Vehicle *u = v; 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
|
4589 const RailVehicleInfo *rvi = 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
|
4590 |
7929
4d13dbed828c
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7928
diff
changeset
|
4591 ClrBit(u->subtype, 7); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4592 switch (u->subtype) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4593 case 0: /* TS_Front_Engine */ |
5868
941f6c5a4668
(svn r8455) -Codechange: Give a more meaningful name (railveh_type)to member flags of RailVehInfo, as well as changing the code to reflect the fact that it was not a flag but rather a one value only variable. Doing so, some evaluations have been simplified.
belugas <belugas@openttd.org>
parents:
5858
diff
changeset
|
4594 if (rvi->railveh_type == RAILVEH_MULTIHEAD) SetMultiheaded(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
|
4595 SetFrontEngine(u); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4596 SetTrainEngine(u); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4597 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4598 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4599 case 1: /* TS_Artic_Part */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4600 u->subtype = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4601 SetArticulatedPart(u); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4602 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4603 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4604 case 2: /* TS_Not_First */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4605 u->subtype = 0; |
5868
941f6c5a4668
(svn r8455) -Codechange: Give a more meaningful name (railveh_type)to member flags of RailVehInfo, as well as changing the code to reflect the fact that it was not a flag but rather a one value only variable. Doing so, some evaluations have been simplified.
belugas <belugas@openttd.org>
parents:
5858
diff
changeset
|
4606 if (rvi->railveh_type == RAILVEH_WAGON) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4607 // normal wagon |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4608 SetTrainWagon(u); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4609 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4610 } |
5868
941f6c5a4668
(svn r8455) -Codechange: Give a more meaningful name (railveh_type)to member flags of RailVehInfo, as well as changing the code to reflect the fact that it was not a flag but rather a one value only variable. Doing so, some evaluations have been simplified.
belugas <belugas@openttd.org>
parents:
5858
diff
changeset
|
4611 if (rvi->railveh_type == RAILVEH_MULTIHEAD && rvi->image_index == u->spritenum - 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
|
4612 // rear end of a multiheaded engine |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4613 SetMultiheaded(u); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4614 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4615 } |
5868
941f6c5a4668
(svn r8455) -Codechange: Give a more meaningful name (railveh_type)to member flags of RailVehInfo, as well as changing the code to reflect the fact that it was not a flag but rather a one value only variable. Doing so, some evaluations have been simplified.
belugas <belugas@openttd.org>
parents:
5858
diff
changeset
|
4616 if (rvi->railveh_type == RAILVEH_MULTIHEAD) SetMultiheaded(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
|
4617 SetTrainEngine(u); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4618 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4619 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4620 case 4: /* TS_Free_Car */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4621 u->subtype = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4622 SetTrainWagon(u); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4623 SetFreeWagon(u); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4624 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4625 default: NOT_REACHED(); break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4626 } |
9321
14dc836cfed7
(svn r13205) -Codechange: Remove unnecessary code-style-buggering-up macro.
peter1138 <peter1138@openttd.org>
parents:
9297
diff
changeset
|
4627 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4628 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4629 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4630 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
4631 } |