author | tron |
Mon, 14 Nov 2005 19:48:04 +0000 | |
changeset 2639 | eeaefdabfdfd |
parent 2637 | 722dae65c4a8 |
child 2662 | 8b46824bd821 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1883
diff
changeset
|
4 |
#include "openttd.h" |
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
5 |
#include "debug.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2150
diff
changeset
|
6 |
#include "functions.h" |
2561
233dafd7cf6c
(svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents:
2552
diff
changeset
|
7 |
#include "gui.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
495
diff
changeset
|
8 |
#include "table/strings.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
593
diff
changeset
|
9 |
#include "map.h" |
1209
2e00193652b2
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1208
diff
changeset
|
10 |
#include "tile.h" |
0 | 11 |
#include "vehicle.h" |
12 |
#include "command.h" |
|
13 |
#include "pathfind.h" |
|
1247 | 14 |
#include "npf.h" |
0 | 15 |
#include "station.h" |
16 |
#include "table/train_cmd.h" |
|
17 |
#include "news.h" |
|
18 |
#include "engine.h" |
|
19 |
#include "player.h" |
|
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
308
diff
changeset
|
20 |
#include "sound.h" |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
21 |
#include "depot.h" |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
22 |
#include "debug.h" |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1531
diff
changeset
|
23 |
#include "waypoint.h" |
1752
d65cd19f7117
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1698
diff
changeset
|
24 |
#include "vehicle_gui.h" |
0 | 25 |
|
1766
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
26 |
#define IS_FIRSTHEAD_SPRITE(spritenum) \ |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
27 |
(is_custom_sprite(spritenum) ? IS_CUSTOM_FIRSTHEAD_SPRITE(spritenum) : _engine_sprite_add[spritenum] == 0) |
0 | 28 |
|
742
c71e6120b789
(svn r1198) -Fix: [ 1087701 ] It is no longer possible to crash trains of other
truelight
parents:
737
diff
changeset
|
29 |
static bool TrainCheckIfLineEnds(Vehicle *v); |
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
30 |
static void TrainController(Vehicle *v); |
0 | 31 |
|
32 |
static const byte _vehicle_initial_x_fract[4] = {10,8,4,8}; |
|
33 |
static const byte _vehicle_initial_y_fract[4] = {8,4,8,10}; |
|
34 |
static const byte _state_dir_table[4] = { 0x20, 8, 0x10, 4 }; |
|
35 |
||
1905
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
36 |
/** |
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
37 |
* Recalculates the cached weight of a train and its vehicles. Should be called each time the cargo on |
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
38 |
* the consist changes. |
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
39 |
* @param v First vehicle of the consist. |
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
40 |
*/ |
2639 | 41 |
void TrainCargoChanged(Vehicle* v) |
42 |
{ |
|
1905
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
43 |
Vehicle *u; |
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
44 |
uint16 weight = 0; |
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
45 |
|
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
46 |
for (u = v; u != NULL; u = u->next) { |
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
47 |
const RailVehicleInfo *rvi = RailVehInfo(u->engine_type); |
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
48 |
uint16 vweight = 0; |
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
49 |
|
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
50 |
vweight += (_cargoc.weights[u->cargo_type] * u->cargo_count) / 16; |
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
51 |
|
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
52 |
// Vehicle weight is not added for articulated parts. |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
53 |
if (u->subtype != TS_Artic_Part) { |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
54 |
// vehicle weight is the sum of the weight of the vehicle and the weight of its cargo |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
55 |
vweight += rvi->weight; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
56 |
|
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
57 |
// powered wagons have extra weight added |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
58 |
if (HASBIT(u->u.rail.flags, VRF_POWEREDWAGON)) |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
59 |
vweight += RailVehInfo(v->engine_type)->pow_wag_weight; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
60 |
} |
1905
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
61 |
|
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
62 |
// consist weight is the sum of the weight of all vehicles in the consist |
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
63 |
weight += vweight; |
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
64 |
|
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
65 |
// store vehicle weight in cache |
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
66 |
u->u.rail.cached_veh_weight = vweight; |
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
67 |
}; |
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
68 |
|
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
69 |
// store consist weight in cache |
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
70 |
v->u.rail.cached_weight = weight; |
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
71 |
} |
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
72 |
|
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
73 |
/** |
1917
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
74 |
* Recalculates the cached stuff of a train. Should be called each time a vehicle is added |
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
75 |
* to/removed from the chain, and when the game is loaded. |
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
76 |
* Note: this needs to be called too for 'wagon chains' (in the depot, without an engine) |
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
77 |
* @param v First vehicle of the chain. |
1905
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
78 |
*/ |
2639 | 79 |
void TrainConsistChanged(Vehicle* v) |
80 |
{ |
|
1917
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
81 |
const RailVehicleInfo *rvi_v; |
1905
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
82 |
Vehicle *u; |
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
83 |
uint16 max_speed = 0xFFFF; |
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
84 |
uint32 power = 0; |
1917
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
85 |
EngineID first_engine; |
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
86 |
|
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
87 |
assert(v->type == VEH_Train); |
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
88 |
|
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
89 |
assert(v->subtype == TS_Front_Engine || v->subtype == TS_Free_Car); |
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
90 |
|
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
91 |
rvi_v = RailVehInfo(v->engine_type); |
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
92 |
first_engine = (v->subtype == TS_Front_Engine) ? v->engine_type : INVALID_VEHICLE; |
2587
31647a23da0b
(svn r3124) Alter train loading/unloading time to use the actual length of the train instead of the number of wagons. The actual length is cached in the first vehicle of the train.
peter1138
parents:
2574
diff
changeset
|
93 |
v->u.rail.cached_total_length = 0; |
1905
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
94 |
|
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
95 |
for (u = v; u != NULL; u = u->next) { |
1908
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1905
diff
changeset
|
96 |
const RailVehicleInfo *rvi_u = RailVehInfo(u->engine_type); |
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
97 |
uint16 veh_len; |
1908
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1905
diff
changeset
|
98 |
|
1917
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
99 |
// update the 'first engine' |
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
100 |
u->u.rail.first_engine = (v == u) ? INVALID_VEHICLE : first_engine; |
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
101 |
|
2595
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
102 |
if (rvi_u->visual_effect != 0) { |
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
103 |
u->u.rail.cached_vis_effect = rvi_u->visual_effect; |
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
104 |
} else { |
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
105 |
if (rvi_u->flags & RVI_WAGON || u->subtype == TS_Artic_Part) { |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
106 |
// Wagons and articulated parts have no effect by default |
2595
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
107 |
u->u.rail.cached_vis_effect = 0x40; |
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
108 |
} else if (rvi_u->engclass == 0) { |
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
109 |
// Steam is offset by -4 units |
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
110 |
u->u.rail.cached_vis_effect = 4; |
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
111 |
} else { |
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
112 |
// Diesel fumes and sparks come from the centre |
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
113 |
u->u.rail.cached_vis_effect = 8; |
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
114 |
} |
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
115 |
} |
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
116 |
|
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
117 |
if (u->subtype != TS_Artic_Part) { |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
118 |
// power is the sum of the powers of all engines and powered wagons in the consist |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
119 |
power += rvi_u->power; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
120 |
|
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
121 |
// check if its a powered wagon |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
122 |
CLRBIT(u->u.rail.flags, VRF_POWEREDWAGON); |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
123 |
if ((rvi_v->pow_wag_power != 0) && (rvi_u->flags & RVI_WAGON) && UsesWagonOverride(u)) { |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
124 |
if (HASBIT(rvi_u->callbackmask, CBM_WAGON_POWER)) { |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
125 |
uint16 callback = GetCallBackResult(CBID_WAGON_POWER, u->engine_type, u); |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
126 |
|
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
127 |
if (callback != CALLBACK_FAILED) |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
128 |
u->u.rail.cached_vis_effect = callback; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
129 |
} |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
130 |
|
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
131 |
if (u->u.rail.cached_vis_effect < 0x40) { |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
132 |
/* wagon is powered */ |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
133 |
SETBIT(u->u.rail.flags, VRF_POWEREDWAGON); // cache 'powered' status |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
134 |
power += rvi_v->pow_wag_power; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
135 |
} |
2595
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
136 |
} |
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
137 |
|
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
138 |
// max speed is the minimum of the speed limits of all vehicles in the consist |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
139 |
if (!(rvi_u->flags & RVI_WAGON) || _patches.wagon_speed_limits) |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
140 |
if (rvi_u->max_speed != 0 && !UsesWagonOverride(u)) |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
141 |
max_speed = min(rvi_u->max_speed, max_speed); |
1908
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1905
diff
changeset
|
142 |
} |
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1905
diff
changeset
|
143 |
|
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
144 |
// check the vehicle length (callback) |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
145 |
veh_len = CALLBACK_FAILED; |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
146 |
if (HASBIT(rvi_u->callbackmask, CBM_VEH_LENGTH)) |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
147 |
veh_len = GetCallBackResult(CBID_VEH_LENGTH, u->engine_type, u); |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
148 |
if (veh_len == CALLBACK_FAILED) |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
149 |
veh_len = rvi_u->shorten_factor; |
1934
b27bc12822cd
(svn r2440) - Fix: [newgrf] Fix the spritesorter to handle overlapping sprites properly, this fixes display problems with really short wagons. (algorithm by patchman, ported by therax)
hackykid
parents:
1927
diff
changeset
|
150 |
veh_len = 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 |
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
151 |
u->u.rail.cached_veh_length = 8 - veh_len; |
2587
31647a23da0b
(svn r3124) Alter train loading/unloading time to use the actual length of the train instead of the number of wagons. The actual length is cached in the first vehicle of the train.
peter1138
parents:
2574
diff
changeset
|
152 |
v->u.rail.cached_total_length += u->u.rail.cached_veh_length; |
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
153 |
|
1905
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
154 |
}; |
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
155 |
|
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
156 |
// store consist weight/max speed in cache |
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
157 |
v->u.rail.cached_max_speed = max_speed; |
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
158 |
v->u.rail.cached_power = power; |
1908
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1905
diff
changeset
|
159 |
|
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1905
diff
changeset
|
160 |
// recalculate cached weights too (we do this *after* the rest, so it is known which wagons are powered and need extra weight added) |
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1905
diff
changeset
|
161 |
TrainCargoChanged(v); |
1905
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
162 |
} |
1247 | 163 |
|
164 |
/* These two arrays are used for realistic acceleration. XXX: How should they |
|
165 |
* be interpreted? */ |
|
1179
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
166 |
static const byte _curve_neighbours45[8][2] = { |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
167 |
{7, 1}, |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
168 |
{0, 2}, |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
169 |
{1, 3}, |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
170 |
{2, 4}, |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
171 |
{3, 5}, |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
172 |
{4, 6}, |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
173 |
{5, 7}, |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
174 |
{6, 0}, |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
175 |
}; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
176 |
|
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
177 |
static const byte _curve_neighbours90[8][2] = { |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
178 |
{6, 2}, |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
179 |
{7, 3}, |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
180 |
{0, 4}, |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
181 |
{1, 5}, |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
182 |
{2, 6}, |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
183 |
{3, 7}, |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
184 |
{4, 0}, |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
185 |
{5, 1}, |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
186 |
}; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
187 |
|
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
188 |
enum AccelType { |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
189 |
AM_ACCEL, |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
190 |
AM_BRAKE |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
191 |
}; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
192 |
|
2630 | 193 |
static bool TrainShouldStop(const Vehicle* v, TileIndex tile) |
1236
928560eaf613
(svn r1740) -Fix: [ 1112342 ] Realistic acceleration works properly with TTDPatch non-stop handling behaviour
celestar
parents:
1235
diff
changeset
|
194 |
{ |
2630 | 195 |
const Order* o = &v->current_order; |
196 |
||
1236
928560eaf613
(svn r1740) -Fix: [ 1112342 ] Realistic acceleration works properly with TTDPatch non-stop handling behaviour
celestar
parents:
1235
diff
changeset
|
197 |
assert(v->type == VEH_Train); |
928560eaf613
(svn r1740) -Fix: [ 1112342 ] Realistic acceleration works properly with TTDPatch non-stop handling behaviour
celestar
parents:
1235
diff
changeset
|
198 |
assert(IsTileType(v->tile, MP_STATION)); |
928560eaf613
(svn r1740) -Fix: [ 1112342 ] Realistic acceleration works properly with TTDPatch non-stop handling behaviour
celestar
parents:
1235
diff
changeset
|
199 |
//When does a train drive through a station |
928560eaf613
(svn r1740) -Fix: [ 1112342 ] Realistic acceleration works properly with TTDPatch non-stop handling behaviour
celestar
parents:
1235
diff
changeset
|
200 |
//first we deal with the "new nonstop handling" |
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
201 |
if (_patches.new_nonstop && o->flags & OF_NON_STOP && |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2044
diff
changeset
|
202 |
_m[tile].m2 == o->station ) |
1236
928560eaf613
(svn r1740) -Fix: [ 1112342 ] Realistic acceleration works properly with TTDPatch non-stop handling behaviour
celestar
parents:
1235
diff
changeset
|
203 |
return false; |
928560eaf613
(svn r1740) -Fix: [ 1112342 ] Realistic acceleration works properly with TTDPatch non-stop handling behaviour
celestar
parents:
1235
diff
changeset
|
204 |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2044
diff
changeset
|
205 |
if (v->last_station_visited == _m[tile].m2) |
1236
928560eaf613
(svn r1740) -Fix: [ 1112342 ] Realistic acceleration works properly with TTDPatch non-stop handling behaviour
celestar
parents:
1235
diff
changeset
|
206 |
return false; |
928560eaf613
(svn r1740) -Fix: [ 1112342 ] Realistic acceleration works properly with TTDPatch non-stop handling behaviour
celestar
parents:
1235
diff
changeset
|
207 |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2044
diff
changeset
|
208 |
if (_m[tile].m2 != o->station && |
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
209 |
(o->flags & OF_NON_STOP || _patches.new_nonstop)) |
1236
928560eaf613
(svn r1740) -Fix: [ 1112342 ] Realistic acceleration works properly with TTDPatch non-stop handling behaviour
celestar
parents:
1235
diff
changeset
|
210 |
return false; |
928560eaf613
(svn r1740) -Fix: [ 1112342 ] Realistic acceleration works properly with TTDPatch non-stop handling behaviour
celestar
parents:
1235
diff
changeset
|
211 |
|
928560eaf613
(svn r1740) -Fix: [ 1112342 ] Realistic acceleration works properly with TTDPatch non-stop handling behaviour
celestar
parents:
1235
diff
changeset
|
212 |
return true; |
928560eaf613
(svn r1740) -Fix: [ 1112342 ] Realistic acceleration works properly with TTDPatch non-stop handling behaviour
celestar
parents:
1235
diff
changeset
|
213 |
} |
928560eaf613
(svn r1740) -Fix: [ 1112342 ] Realistic acceleration works properly with TTDPatch non-stop handling behaviour
celestar
parents:
1235
diff
changeset
|
214 |
|
1179
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
215 |
//new acceleration |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
216 |
static int GetTrainAcceleration(Vehicle *v, bool mode) |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
217 |
{ |
1531 | 218 |
const Vehicle *u; |
1179
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
219 |
int num = 0; //number of vehicles, change this into the number of axles later |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
220 |
int power = 0; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
221 |
int mass = 0; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
222 |
int max_speed = 2000; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
223 |
int area = 120; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
224 |
int friction = 35; //[1e-3] |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
225 |
int drag_coeff = 20; //[1e-4] |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
226 |
int incl = 0; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
227 |
int resistance; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
228 |
int speed = v->cur_speed; //[mph] |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
229 |
int force = 0x3FFFFFFF; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
230 |
int pos = 0; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
231 |
int lastpos = -1; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
232 |
int curvecount[2] = {0, 0}; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
233 |
int sum = 0; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
234 |
int numcurve = 0; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
235 |
|
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
236 |
speed *= 10; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
237 |
speed /= 16; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
238 |
|
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
239 |
//first find the curve speed limit |
1531 | 240 |
for (u = v; u->next != NULL; u = u->next, pos++) { |
1179
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
241 |
int dir = u->direction; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
242 |
int ndir = u->next->direction; |
1531 | 243 |
int i; |
1179
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
244 |
|
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
245 |
for (i = 0; i < 2; i++) { |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
246 |
if ( _curve_neighbours45[dir][i] == ndir) { |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
247 |
curvecount[i]++; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
248 |
if (lastpos != -1) { |
1531 | 249 |
numcurve++; |
250 |
sum += pos - lastpos; |
|
1179
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
251 |
if (pos - lastpos == 1) { |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
252 |
max_speed = 88; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
253 |
} |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
254 |
} |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
255 |
lastpos = pos; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
256 |
} |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
257 |
} |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
258 |
|
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
259 |
//if we have a 90 degree turn, fix the speed limit to 60 |
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
260 |
if (_curve_neighbours90[dir][0] == ndir || |
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
261 |
_curve_neighbours90[dir][1] == ndir) { |
1179
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
262 |
max_speed = 61; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
263 |
} |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
264 |
} |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
265 |
|
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
266 |
if (numcurve > 0) sum /= numcurve; |
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
267 |
|
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
268 |
if ((curvecount[0] != 0 || curvecount[1] != 0) && max_speed > 88) { |
1179
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
269 |
int total = curvecount[0] + curvecount[1]; |
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
270 |
|
1179
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
271 |
if (curvecount[0] == 1 && curvecount[1] == 1) { |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
272 |
max_speed = 0xFFFF; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
273 |
} else if (total > 1) { |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
274 |
max_speed = 232 - (13 - clamp(sum, 1, 12)) * (13 - clamp(sum, 1, 12)); |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
275 |
} |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
276 |
} |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
277 |
|
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
278 |
max_speed += (max_speed / 2) * v->u.rail.railtype; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
279 |
|
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
280 |
if (IsTileType(v->tile, MP_STATION) && v->subtype == TS_Front_Engine) { |
1236
928560eaf613
(svn r1740) -Fix: [ 1112342 ] Realistic acceleration works properly with TTDPatch non-stop handling behaviour
celestar
parents:
1235
diff
changeset
|
281 |
if (TrainShouldStop(v, v->tile)) { |
1179
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
282 |
int station_length = 0; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
283 |
TileIndex tile = v->tile; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
284 |
int delta_v; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
285 |
|
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
286 |
max_speed = 120; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
287 |
do { |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
288 |
station_length++; |
1531 | 289 |
tile = TILE_ADD(tile, TileOffsByDir(v->direction / 2)); |
1685
46783dea9b44
(svn r2189) Introduce and use IsCompatibleTrainStationTile()
tron
parents:
1684
diff
changeset
|
290 |
} while (IsCompatibleTrainStationTile(tile, v->tile)); |
1179
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
291 |
|
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
292 |
delta_v = v->cur_speed / (station_length + 1); |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
293 |
if (v->max_speed > (v->cur_speed - delta_v)) |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
294 |
max_speed = v->cur_speed - (delta_v / 10); |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
295 |
|
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
296 |
max_speed = max(max_speed, 25 * station_length); |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
297 |
} |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
298 |
} |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
299 |
|
1905
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
300 |
mass = v->u.rail.cached_weight; |
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
301 |
power = v->u.rail.cached_power * 746; |
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
302 |
max_speed = min(max_speed, v->u.rail.cached_max_speed); |
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
303 |
|
1179
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
304 |
for (u = v; u != NULL; u = u->next) { |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
305 |
num++; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
306 |
drag_coeff += 3; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
307 |
|
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
308 |
if (u->u.rail.track == 0x80) |
1882
f7d54d723d71
(svn r2388) - Fix: [realistic accel] Very slow trains no longer get an increase in maximum speed when part of them is in a depot.
hackykid
parents:
1859
diff
changeset
|
309 |
max_speed = min(61, max_speed); |
1179
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
310 |
|
1683
697f47e2bb59
(svn r2187) Implement a slightly better workaround than r1588 did. (Joint effort with Celestar)
tron
parents:
1681
diff
changeset
|
311 |
if (HASBIT(u->u.rail.flags, VRF_GOINGUP)) { |
1905
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
312 |
incl += u->u.rail.cached_veh_weight * 60; //3% slope, quite a bit actually |
1683
697f47e2bb59
(svn r2187) Implement a slightly better workaround than r1588 did. (Joint effort with Celestar)
tron
parents:
1681
diff
changeset
|
313 |
} else if (HASBIT(u->u.rail.flags, VRF_GOINGDOWN)) { |
1905
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
314 |
incl -= u->u.rail.cached_veh_weight * 60; |
1179
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
315 |
} |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
316 |
} |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
317 |
|
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
318 |
v->max_speed = max_speed; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
319 |
|
2519
beb11a5ac48c
(svn r3048) Replace 0/1/2 by RAILTYPE_RAIL/MONO/MAGLEV where appropriate
tron
parents:
2510
diff
changeset
|
320 |
if (v->u.rail.railtype != RAILTYPE_MAGLEV) { |
1179
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
321 |
resistance = 13 * mass / 10; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
322 |
resistance += 60 * num; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
323 |
resistance += friction * mass * speed / 1000; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
324 |
resistance += (area * drag_coeff * speed * speed) / 10000; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
325 |
} else |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
326 |
resistance = (area * (drag_coeff / 2) * speed * speed) / 10000; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
327 |
resistance += incl; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
328 |
resistance *= 4; //[N] |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
329 |
|
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
330 |
if (speed > 0) { |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
331 |
switch (v->u.rail.railtype) { |
2519
beb11a5ac48c
(svn r3048) Replace 0/1/2 by RAILTYPE_RAIL/MONO/MAGLEV where appropriate
tron
parents:
2510
diff
changeset
|
332 |
case RAILTYPE_RAIL: |
beb11a5ac48c
(svn r3048) Replace 0/1/2 by RAILTYPE_RAIL/MONO/MAGLEV where appropriate
tron
parents:
2510
diff
changeset
|
333 |
case RAILTYPE_MONO: |
1179
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
334 |
force = power / speed; //[N] |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
335 |
force *= 22; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
336 |
force /= 10; |
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
337 |
break; |
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
338 |
|
2519
beb11a5ac48c
(svn r3048) Replace 0/1/2 by RAILTYPE_RAIL/MONO/MAGLEV where appropriate
tron
parents:
2510
diff
changeset
|
339 |
case RAILTYPE_MAGLEV: |
1179
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
340 |
force = power / 25; |
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
341 |
break; |
1179
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
342 |
} |
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
343 |
} else { |
1179
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
344 |
//"kickoff" acceleration |
1969
b7d014a74c0a
(svn r2475) -Fix: [ 1214982 & 1217473 ] realistic acceleration problem. (glx)
celestar
parents:
1961
diff
changeset
|
345 |
force = (mass * 8) + resistance; |
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
346 |
} |
1179
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
347 |
|
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
348 |
if (force <= 0) force = 10000; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
349 |
|
2519
beb11a5ac48c
(svn r3048) Replace 0/1/2 by RAILTYPE_RAIL/MONO/MAGLEV where appropriate
tron
parents:
2510
diff
changeset
|
350 |
if (v->u.rail.railtype != RAILTYPE_MAGLEV) force = min(force, mass * 10 * 200); |
1179
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
351 |
|
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
352 |
if (mode == AM_ACCEL) { |
1684
3b2df64cc706
(svn r2188) Revert r2185, because trains always accerlated (Requested by Celestar)
tron
parents:
1683
diff
changeset
|
353 |
return (force - resistance) / (mass * 4); |
1179
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
354 |
} else { |
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
355 |
return min((-force - resistance) / (mass * 4), 10000 / (mass * 4)); |
1179
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
356 |
} |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
357 |
} |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
358 |
|
0 | 359 |
void UpdateTrainAcceleration(Vehicle *v) |
360 |
{ |
|
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
361 |
uint power = 0; |
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
362 |
uint weight = 0; |
0 | 363 |
|
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1064
diff
changeset
|
364 |
assert(v->subtype == TS_Front_Engine); |
0 | 365 |
|
1905
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
366 |
weight = v->u.rail.cached_weight; |
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
367 |
power = v->u.rail.cached_power; |
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
368 |
v->max_speed = v->u.rail.cached_max_speed; |
0 | 369 |
|
370 |
assert(weight != 0); |
|
371 |
||
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
372 |
v->acceleration = clamp(power / weight * 4, 1, 255); |
0 | 373 |
} |
374 |
||
1475 | 375 |
int GetTrainImage(const Vehicle *v, byte direction) |
0 | 376 |
{ |
377 |
int img = v->spritenum; |
|
378 |
int base; |
|
379 |
||
380 |
if (is_custom_sprite(img)) { |
|
1766
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
381 |
base = GetCustomVehicleSprite(v, direction + 4 * IS_CUSTOM_SECONDHEAD_SPRITE(img)); |
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
382 |
if (base != 0) return base; |
2464
e3054f0f0627
(svn r2990) Remove _engine_original_sprites and replace all uses with references to our (new) original engine/vehicle tables.
peter1138
parents:
2463
diff
changeset
|
383 |
img = orig_rail_vehicle_info[v->engine_type].image_index; |
0 | 384 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
385 |
|
0 | 386 |
base = _engine_sprite_base[img] + ((direction + _engine_sprite_add[img]) & _engine_sprite_and[img]); |
387 |
||
2639 | 388 |
if (v->cargo_count >= v->cargo_cap / 2) base += _wagon_full_adder[img]; |
0 | 389 |
return base; |
390 |
} |
|
391 |
||
2570
f86c326fda65
(svn r3107) -NewGRF: Move train y-position offset adjustment to remove code duplication, and make it apply only to vehicles with a custom image.
peter1138
parents:
2564
diff
changeset
|
392 |
extern int _traininfo_vehicle_pitch; |
f86c326fda65
(svn r3107) -NewGRF: Move train y-position offset adjustment to remove code duplication, and make it apply only to vehicles with a custom image.
peter1138
parents:
2564
diff
changeset
|
393 |
|
2477
225b2916fe2a
(svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents:
2475
diff
changeset
|
394 |
void DrawTrainEngine(int x, int y, EngineID engine, uint32 image_ormod) |
0 | 395 |
{ |
540
2987d7976ea2
(svn r924) Use RailVehInfo() instead of &_rail_vehicle_info[]
tron
parents:
534
diff
changeset
|
396 |
const RailVehicleInfo *rvi = RailVehInfo(engine); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
397 |
|
0 | 398 |
int img = rvi->image_index; |
399 |
uint32 image = 0; |
|
400 |
||
401 |
if (is_custom_sprite(img)) { |
|
358
da81e0ef68cf
(svn r546) -newgrf: Use GetCustomVehicleIcon() for fetching sprites for vehicle selection dialogs. (Idea by octo, done by pasky).
darkvater
parents:
337
diff
changeset
|
402 |
image = GetCustomVehicleIcon(engine, 6); |
2570
f86c326fda65
(svn r3107) -NewGRF: Move train y-position offset adjustment to remove code duplication, and make it apply only to vehicles with a custom image.
peter1138
parents:
2564
diff
changeset
|
403 |
if (image == 0) { |
f86c326fda65
(svn r3107) -NewGRF: Move train y-position offset adjustment to remove code duplication, and make it apply only to vehicles with a custom image.
peter1138
parents:
2564
diff
changeset
|
404 |
img = orig_rail_vehicle_info[engine].image_index; |
f86c326fda65
(svn r3107) -NewGRF: Move train y-position offset adjustment to remove code duplication, and make it apply only to vehicles with a custom image.
peter1138
parents:
2564
diff
changeset
|
405 |
} else { |
f86c326fda65
(svn r3107) -NewGRF: Move train y-position offset adjustment to remove code duplication, and make it apply only to vehicles with a custom image.
peter1138
parents:
2564
diff
changeset
|
406 |
y += _traininfo_vehicle_pitch; |
f86c326fda65
(svn r3107) -NewGRF: Move train y-position offset adjustment to remove code duplication, and make it apply only to vehicles with a custom image.
peter1138
parents:
2564
diff
changeset
|
407 |
} |
0 | 408 |
} |
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
409 |
if (image == 0) { |
0 | 410 |
image = (6 & _engine_sprite_and[img]) + _engine_sprite_base[img]; |
411 |
} |
|
412 |
||
413 |
if (rvi->flags & RVI_MULTIHEAD) { |
|
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
414 |
DrawSprite(image | image_ormod, x - 14, y); |
0 | 415 |
x += 15; |
416 |
image = 0; |
|
417 |
if (is_custom_sprite(img)) { |
|
358
da81e0ef68cf
(svn r546) -newgrf: Use GetCustomVehicleIcon() for fetching sprites for vehicle selection dialogs. (Idea by octo, done by pasky).
darkvater
parents:
337
diff
changeset
|
418 |
image = GetCustomVehicleIcon(engine, 2); |
2464
e3054f0f0627
(svn r2990) Remove _engine_original_sprites and replace all uses with references to our (new) original engine/vehicle tables.
peter1138
parents:
2463
diff
changeset
|
419 |
if (image == 0) img = orig_rail_vehicle_info[engine].image_index; |
0 | 420 |
} |
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
421 |
if (image == 0) { |
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
422 |
image = |
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
423 |
((6 + _engine_sprite_add[img + 1]) & _engine_sprite_and[img + 1]) + |
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
424 |
_engine_sprite_base[img + 1]; |
0 | 425 |
} |
426 |
} |
|
427 |
DrawSprite(image | image_ormod, x, y); |
|
428 |
} |
|
429 |
||
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
430 |
static uint CountArticulatedParts(const RailVehicleInfo *rvi, EngineID engine_type) |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
431 |
{ |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
432 |
uint16 callback; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
433 |
uint i; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
434 |
|
2639 | 435 |
if (!HASBIT(rvi->callbackmask, CBM_ARTIC_ENGINE)) return 0; |
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
436 |
|
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
437 |
for (i = 1; i < 10; i++) { |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
438 |
callback = GetCallBackResult(CBID_ARTIC_ENGINE + (i << 8), engine_type, NULL); |
2639 | 439 |
if (callback == CALLBACK_FAILED || callback == 0xFF) break; |
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
440 |
} |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
441 |
|
2608
c98436848294
(svn r3145) Fix two off-by-one errors in building articulated rail vehicles.
peter1138
parents:
2607
diff
changeset
|
442 |
return i - 1; |
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
443 |
} |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
444 |
|
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
445 |
static void AddArticulatedParts(const RailVehicleInfo *rvi, Vehicle **vl) |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
446 |
{ |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
447 |
const RailVehicleInfo *rvi_artic; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
448 |
EngineID engine_type; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
449 |
Vehicle *v = vl[0]; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
450 |
Vehicle *u = v; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
451 |
uint16 callback; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
452 |
bool flip_image; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
453 |
uint i; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
454 |
|
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
455 |
if (!HASBIT(rvi->callbackmask, CBM_ARTIC_ENGINE)) |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
456 |
return; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
457 |
|
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
458 |
for (i = 1; i < 10; i++) { |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
459 |
callback = GetCallBackResult(CBID_ARTIC_ENGINE + (i << 8), v->engine_type, NULL); |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
460 |
if (callback == CALLBACK_FAILED || callback == 0xFF) |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
461 |
return; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
462 |
|
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
463 |
u->next = vl[i]; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
464 |
u = u->next; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
465 |
|
2608
c98436848294
(svn r3145) Fix two off-by-one errors in building articulated rail vehicles.
peter1138
parents:
2607
diff
changeset
|
466 |
engine_type = GB(callback, 0, 7); |
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
467 |
flip_image = HASBIT(callback, 7); |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
468 |
rvi_artic = RailVehInfo(engine_type); |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
469 |
|
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
470 |
// get common values from first engine |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
471 |
u->direction = v->direction; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
472 |
u->owner = v->owner; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
473 |
u->tile = v->tile; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
474 |
u->x_pos = v->x_pos; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
475 |
u->y_pos = v->y_pos; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
476 |
u->z_pos = v->z_pos; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
477 |
u->z_height = v->z_height; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
478 |
u->u.rail.track = v->u.rail.track; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
479 |
u->u.rail.railtype = v->u.rail.railtype; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
480 |
u->build_year = v->build_year; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
481 |
u->vehstatus = v->vehstatus & ~VS_STOPPED; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
482 |
u->u.rail.first_engine = v->engine_type; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
483 |
|
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
484 |
// get more settings from rail vehicle info |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
485 |
u->spritenum = rvi_artic->image_index; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
486 |
if (flip_image) u->spritenum++; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
487 |
u->cargo_type = rvi_artic->cargo_type; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
488 |
u->cargo_cap = rvi_artic->capacity; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
489 |
u->max_speed = 0; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
490 |
u->max_age = 0; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
491 |
u->engine_type = engine_type; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
492 |
u->value = 0; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
493 |
u->type = VEH_Train; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
494 |
u->subtype = TS_Artic_Part; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
495 |
u->cur_image = 0xAC2; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
496 |
|
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
497 |
VehiclePositionChanged(u); |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
498 |
} |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
499 |
} |
0 | 500 |
|
2477
225b2916fe2a
(svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents:
2475
diff
changeset
|
501 |
static int32 CmdBuildRailWagon(EngineID engine, TileIndex tile, uint32 flags) |
0 | 502 |
{ |
503 |
int32 value; |
|
504 |
const RailVehicleInfo *rvi; |
|
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
505 |
uint num_vehicles; |
0 | 506 |
|
889
64d2f7d5f02b
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
882
diff
changeset
|
507 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
64d2f7d5f02b
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
882
diff
changeset
|
508 |
|
540
2987d7976ea2
(svn r924) Use RailVehInfo() instead of &_rail_vehicle_info[]
tron
parents:
534
diff
changeset
|
509 |
rvi = RailVehInfo(engine); |
0 | 510 |
value = (rvi->base_cost * _price.build_railwagon) >> 8; |
511 |
||
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
512 |
num_vehicles = 1 + CountArticulatedParts(rvi, engine); |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
513 |
|
0 | 514 |
if (!(flags & DC_QUERY_COST)) { |
2609
3a734c4531ff
(svn r3146) Avoid use of variable size declared arrays when allocating articulated rail vehicles.
peter1138
parents:
2608
diff
changeset
|
515 |
Vehicle *vl[11]; // Allow for wagon and upto 10 artic parts. |
2639 | 516 |
Vehicle* v; |
517 |
int x; |
|
518 |
int y; |
|
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
519 |
|
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
520 |
if (!AllocateVehicles(vl, num_vehicles)) |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
521 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
0 | 522 |
|
523 |
if (flags & DC_EXEC) { |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
524 |
Vehicle *u, *w; |
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
525 |
uint dir; |
0 | 526 |
|
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
527 |
v = vl[0]; |
2639 | 528 |
v->spritenum = rvi->image_index; |
0 | 529 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
530 |
u = NULL; |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
531 |
|
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
532 |
FOR_ALL_VEHICLES(w) { |
1986
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1980
diff
changeset
|
533 |
if (w->type == VEH_Train && w->tile == tile && |
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1064
diff
changeset
|
534 |
w->subtype == TS_Free_Car && w->engine_type == engine) { |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
535 |
u = GetLastVehicleInChain(w); |
0 | 536 |
break; |
537 |
} |
|
538 |
} |
|
539 |
||
540 |
v->engine_type = engine; |
|
541 |
||
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
542 |
dir = GB(_m[tile].m5, 0, 2); |
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
543 |
|
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
544 |
v->direction = dir * 2 + 1; |
1986
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1980
diff
changeset
|
545 |
v->tile = tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
546 |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1935
diff
changeset
|
547 |
x = TileX(tile) * TILE_SIZE | _vehicle_initial_x_fract[dir]; |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1935
diff
changeset
|
548 |
y = TileY(tile) * TILE_SIZE | _vehicle_initial_y_fract[dir]; |
0 | 549 |
|
550 |
v->x_pos = x; |
|
551 |
v->y_pos = y; |
|
552 |
v->z_pos = GetSlopeZ(x,y); |
|
553 |
v->owner = _current_player; |
|
554 |
v->z_height = 6; |
|
555 |
v->u.rail.track = 0x80; |
|
556 |
v->vehstatus = VS_HIDDEN | VS_DEFPAL; |
|
557 |
||
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1064
diff
changeset
|
558 |
v->subtype = TS_Free_Car; |
0 | 559 |
if (u != NULL) { |
560 |
u->next = v; |
|
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1064
diff
changeset
|
561 |
v->subtype = TS_Not_First; |
0 | 562 |
} |
563 |
||
564 |
v->cargo_type = rvi->cargo_type; |
|
565 |
v->cargo_cap = rvi->capacity; |
|
566 |
v->value = value; |
|
567 |
// v->day_counter = 0; |
|
568 |
||
2639 | 569 |
v->u.rail.railtype = GetEngine(engine)->railtype; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
570 |
|
0 | 571 |
v->build_year = _cur_year; |
572 |
v->type = VEH_Train; |
|
573 |
v->cur_image = 0xAC2; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
574 |
|
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
575 |
AddArticulatedParts(rvi, vl); |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
576 |
|
0 | 577 |
_new_wagon_id = v->index; |
2564 | 578 |
_new_vehicle_id = v->index; |
0 | 579 |
|
580 |
VehiclePositionChanged(v); |
|
1917
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
581 |
TrainConsistChanged(GetFirstVehicleInChain(v)); |
0 | 582 |
|
583 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
584 |
} |
|
585 |
} |
|
586 |
||
587 |
return value; |
|
588 |
} |
|
589 |
||
590 |
// Move all free vehicles in the depot to the train |
|
2630 | 591 |
static void NormalizeTrainVehInDepot(const Vehicle* u) |
0 | 592 |
{ |
2630 | 593 |
const Vehicle* v; |
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
594 |
|
0 | 595 |
FOR_ALL_VEHICLES(v) { |
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1064
diff
changeset
|
596 |
if (v->type == VEH_Train && v->subtype == TS_Free_Car && |
0 | 597 |
v->tile == u->tile && |
598 |
v->u.rail.track == 0x80) { |
|
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
599 |
if (DoCommandByTile(0, v->index | (u->index << 16), 1, DC_EXEC, |
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
600 |
CMD_MOVE_RAIL_VEHICLE) == CMD_ERROR) |
0 | 601 |
break; |
602 |
} |
|
603 |
} |
|
604 |
} |
|
605 |
||
606 |
static const byte _railveh_score[] = { |
|
607 |
1, 4, 7, 19, 20, 30, 31, 19, |
|
608 |
20, 21, 22, 10, 11, 30, 31, 32, |
|
609 |
33, 34, 35, 29, 45, 32, 50, 40, |
|
610 |
41, 51, 52, 0, 0, 0, 0, 0, |
|
611 |
0, 0, 0, 0, 0, 0, 0, 0, |
|
612 |
0, 0, 0, 0, 0, 0, 0, 0, |
|
613 |
0, 0, 0, 0, 0, 0, 60, 62, |
|
614 |
63, 0, 0, 0, 0, 0, 0, 0, |
|
615 |
0, 0, 0, 0, 0, 0, 0, 0, |
|
616 |
0, 0, 0, 0, 0, 0, 0, 0, |
|
617 |
0, 0, 0, 0, 70, 71, 72, 73, |
|
618 |
74, 0, 0, 0, 0, 0, 0, 0, |
|
619 |
0, 0, 0, 0, 0, 0, 0, 0, |
|
620 |
0, 0, 0, 0, 0, 0, 0, 0, |
|
621 |
0, 0, 0, 0, |
|
622 |
}; |
|
623 |
||
624 |
||
2630 | 625 |
static int32 EstimateTrainCost(const RailVehicleInfo* rvi) |
0 | 626 |
{ |
627 |
return (rvi->base_cost * (_price.build_railvehicle >> 3)) >> 5; |
|
628 |
} |
|
629 |
||
1109
ecb98f43ba2c
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1103
diff
changeset
|
630 |
void AddRearEngineToMultiheadedTrain(Vehicle *v, Vehicle *u, bool building) |
1060
ae9a2238bd80
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1057
diff
changeset
|
631 |
{ |
ae9a2238bd80
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1057
diff
changeset
|
632 |
u->direction = v->direction; |
ae9a2238bd80
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1057
diff
changeset
|
633 |
u->owner = v->owner; |
ae9a2238bd80
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1057
diff
changeset
|
634 |
u->tile = v->tile; |
ae9a2238bd80
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1057
diff
changeset
|
635 |
u->x_pos = v->x_pos; |
ae9a2238bd80
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1057
diff
changeset
|
636 |
u->y_pos = v->y_pos; |
ae9a2238bd80
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1057
diff
changeset
|
637 |
u->z_pos = v->z_pos; |
ae9a2238bd80
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1057
diff
changeset
|
638 |
u->z_height = 6; |
ae9a2238bd80
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1057
diff
changeset
|
639 |
u->u.rail.track = 0x80; |
ae9a2238bd80
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1057
diff
changeset
|
640 |
u->vehstatus = v->vehstatus & ~VS_STOPPED; |
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1064
diff
changeset
|
641 |
u->subtype = TS_Not_First; |
1060
ae9a2238bd80
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1057
diff
changeset
|
642 |
u->spritenum = v->spritenum + 1; |
ae9a2238bd80
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1057
diff
changeset
|
643 |
u->cargo_type = v->cargo_type; |
ae9a2238bd80
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1057
diff
changeset
|
644 |
u->cargo_cap = v->cargo_cap; |
ae9a2238bd80
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1057
diff
changeset
|
645 |
u->u.rail.railtype = v->u.rail.railtype; |
ae9a2238bd80
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1057
diff
changeset
|
646 |
if (building) v->next = u; |
ae9a2238bd80
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1057
diff
changeset
|
647 |
u->engine_type = v->engine_type; |
ae9a2238bd80
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1057
diff
changeset
|
648 |
u->build_year = v->build_year; |
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
649 |
if (building) v->value >>= 1; |
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
650 |
u->value = v->value; |
1060
ae9a2238bd80
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1057
diff
changeset
|
651 |
u->type = VEH_Train; |
ae9a2238bd80
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1057
diff
changeset
|
652 |
u->cur_image = 0xAC2; |
ae9a2238bd80
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1057
diff
changeset
|
653 |
VehiclePositionChanged(u); |
ae9a2238bd80
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1057
diff
changeset
|
654 |
} |
ae9a2238bd80
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1057
diff
changeset
|
655 |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
656 |
/** Build a railroad vehicle. |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
657 |
* @param x,y tile coordinates (depot) where rail-vehicle is built |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
658 |
* @param p1 engine type id |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
659 |
* @param p2 bit 0 build only one engine, even if it is a dualheaded engine. |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
660 |
p2 bit 1 prevents any free cars from being added to the train |
0 | 661 |
*/ |
662 |
int32 CmdBuildRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
663 |
{ |
|
664 |
const RailVehicleInfo *rvi; |
|
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
665 |
int value; |
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
666 |
Vehicle *v; |
1282
ea2ae881814c
(svn r1786) -Fix: unitnumber is increased to 16bit, so now you can have up to 5000
truelight
parents:
1266
diff
changeset
|
667 |
UnitID unit_num; |
0 | 668 |
Engine *e; |
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
669 |
TileIndex tile = TileVirtXY(x, y); |
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
670 |
uint num_vehicles; |
0 | 671 |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
672 |
/* Check if the engine-type is valid (for the player) */ |
1197 | 673 |
if (!IsEngineBuildable(p1, VEH_Train)) return CMD_ERROR; |
1196
67f7f3017d99
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1192
diff
changeset
|
674 |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
675 |
/* Check if the train is actually being built in a depot belonging |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
676 |
* to the player. Doesn't matter if only the cost is queried */ |
1443
2b8e1b123d91
(svn r1947) As in r1946, permit DC_QUERY_COST even on non-depot tiles - so that it works for the ai_new. It is de iure not a bug yet but let's be safe against future annoying headaches. Signed-Off-By: TrueLight
pasky
parents:
1438
diff
changeset
|
677 |
if (!(flags & DC_QUERY_COST)) { |
2b8e1b123d91
(svn r1947) As in r1946, permit DC_QUERY_COST even on non-depot tiles - so that it works for the ai_new. It is de iure not a bug yet but let's be safe against future annoying headaches. Signed-Off-By: TrueLight
pasky
parents:
1438
diff
changeset
|
678 |
if (!IsTileDepotType(tile, TRANSPORT_RAIL)) return CMD_ERROR; |
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1895
diff
changeset
|
679 |
if (!IsTileOwner(tile, _current_player)) return CMD_ERROR; |
1443
2b8e1b123d91
(svn r1947) As in r1946, permit DC_QUERY_COST even on non-depot tiles - so that it works for the ai_new. It is de iure not a bug yet but let's be safe against future annoying headaches. Signed-Off-By: TrueLight
pasky
parents:
1438
diff
changeset
|
680 |
} |
1221
ce638de43f3a
(svn r1725) - Fix: now trains can only be built in depots and you have to own the depot too (hacked client protection)
bjarni
parents:
1214
diff
changeset
|
681 |
|
0 | 682 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
683 |
||
540
2987d7976ea2
(svn r924) Use RailVehInfo() instead of &_rail_vehicle_info[]
tron
parents:
534
diff
changeset
|
684 |
rvi = RailVehInfo(p1); |
2244 | 685 |
e = GetEngine(p1); |
686 |
||
687 |
/* Check if depot and new engine uses the same kind of tracks */ |
|
688 |
if (!IsCompatibleRail(e->railtype, GetRailType(tile))) return CMD_ERROR; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
689 |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
690 |
if (rvi->flags & RVI_WAGON) return CmdBuildRailWagon(p1, tile, flags); |
0 | 691 |
|
692 |
value = EstimateTrainCost(rvi); |
|
2261
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2244
diff
changeset
|
693 |
|
2244 | 694 |
//make sure we only pay for half a dualheaded engine if we only requested half of it |
695 |
if (rvi->flags&RVI_MULTIHEAD && HASBIT(p2,0)) |
|
696 |
value /= 2; |
|
2261
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2244
diff
changeset
|
697 |
|
2610
73831453cfbc
(svn r3147) Fix crash when building dual-head rail vehicles...
peter1138
parents:
2609
diff
changeset
|
698 |
num_vehicles = (rvi->flags & RVI_MULTIHEAD && !HASBIT(p2, 0)) ? 2 : 1; |
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
699 |
num_vehicles += CountArticulatedParts(rvi, p1); |
0 | 700 |
|
701 |
if (!(flags & DC_QUERY_COST)) { |
|
2609
3a734c4531ff
(svn r3146) Avoid use of variable size declared arrays when allocating articulated rail vehicles.
peter1138
parents:
2608
diff
changeset
|
702 |
Vehicle *vl[12]; // Allow for upto 10 artic parts and dual-heads |
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
703 |
if (!AllocateVehicles(vl, num_vehicles) || IsOrderPoolFull()) |
0 | 704 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
705 |
||
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
706 |
v = vl[0]; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
707 |
|
0 | 708 |
unit_num = GetFreeUnitNumber(VEH_Train); |
709 |
if (unit_num > _patches.max_trains) |
|
710 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
|
711 |
||
712 |
if (flags & DC_EXEC) { |
|
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
713 |
uint dir; |
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
714 |
|
0 | 715 |
v->unitnumber = unit_num; |
716 |
||
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
717 |
dir = GB(_m[tile].m5, 0, 2); |
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
718 |
|
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
719 |
v->direction = dir * 2 + 1; |
1986
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1980
diff
changeset
|
720 |
v->tile = tile; |
0 | 721 |
v->owner = _current_player; |
722 |
v->x_pos = (x |= _vehicle_initial_x_fract[dir]); |
|
723 |
v->y_pos = (y |= _vehicle_initial_y_fract[dir]); |
|
724 |
v->z_pos = GetSlopeZ(x,y); |
|
725 |
v->z_height = 6; |
|
726 |
v->u.rail.track = 0x80; |
|
727 |
v->vehstatus = VS_HIDDEN | VS_STOPPED | VS_DEFPAL; |
|
728 |
v->spritenum = rvi->image_index; |
|
729 |
v->cargo_type = rvi->cargo_type; |
|
730 |
v->cargo_cap = rvi->capacity; |
|
731 |
v->max_speed = rvi->max_speed; |
|
732 |
v->value = value; |
|
1266
eccd576e322f
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1247
diff
changeset
|
733 |
v->last_station_visited = INVALID_STATION; |
0 | 734 |
v->dest_tile = 0; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
735 |
|
2477
225b2916fe2a
(svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents:
2475
diff
changeset
|
736 |
v->engine_type = p1; |
0 | 737 |
|
738 |
v->reliability = e->reliability; |
|
739 |
v->reliability_spd_dec = e->reliability_spd_dec; |
|
740 |
v->max_age = e->lifelength * 366; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
741 |
|
0 | 742 |
v->string_id = STR_SV_TRAIN_NAME; |
743 |
v->u.rail.railtype = e->railtype; |
|
744 |
_new_train_id = v->index; |
|
2564 | 745 |
_new_vehicle_id = v->index; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
746 |
|
0 | 747 |
v->service_interval = _patches.servint_trains; |
748 |
v->date_of_last_service = _date; |
|
749 |
v->build_year = _cur_year; |
|
750 |
v->type = VEH_Train; |
|
751 |
v->cur_image = 0xAC2; |
|
752 |
||
2617
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2612
diff
changeset
|
753 |
v->u.rail.shortest_platform[0] = 255; |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2612
diff
changeset
|
754 |
v->u.rail.shortest_platform[1] = 0; |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2612
diff
changeset
|
755 |
|
0 | 756 |
VehiclePositionChanged(v); |
757 |
||
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
758 |
if (rvi->flags & RVI_MULTIHEAD && !HASBIT(p2, 0)) { |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
759 |
AddRearEngineToMultiheadedTrain(vl[0], vl[1], true); |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
760 |
} else { |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
761 |
AddArticulatedParts(rvi, vl); |
2244 | 762 |
} |
0 | 763 |
|
1905
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
764 |
TrainConsistChanged(v); |
0 | 765 |
UpdateTrainAcceleration(v); |
2244 | 766 |
|
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
767 |
if (!HASBIT(p2, 1)) { // check if the cars should be added to the new vehicle |
2244 | 768 |
NormalizeTrainVehInDepot(v); |
769 |
} |
|
0 | 770 |
|
771 |
InvalidateWindow(WC_VEHICLE_DEPOT, tile); |
|
588 | 772 |
RebuildVehicleLists(); |
0 | 773 |
InvalidateWindow(WC_COMPANY, v->owner); |
2618
9691753519ac
(svn r3156) -Fix: removed some cases where autoreplace windows were redrawn when nothing was changed
bjarni
parents:
2617
diff
changeset
|
774 |
if (IsLocalPlayer()) { |
9691753519ac
(svn r3156) -Fix: removed some cases where autoreplace windows were redrawn when nothing was changed
bjarni
parents:
2617
diff
changeset
|
775 |
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Train); // updates the replace Train window |
9691753519ac
(svn r3156) -Fix: removed some cases where autoreplace windows were redrawn when nothing was changed
bjarni
parents:
2617
diff
changeset
|
776 |
} |
0 | 777 |
} |
778 |
} |
|
779 |
_cmd_build_rail_veh_score = _railveh_score[p1]; |
|
1128
ca7f860db7ac
(svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents:
1109
diff
changeset
|
780 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
781 |
return value; |
0 | 782 |
} |
783 |
||
784 |
||
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1935
diff
changeset
|
785 |
/* Check if all the wagons of the given train are in a depot, returns the |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1935
diff
changeset
|
786 |
* number of cars (including loco) then. If not, sets the error message to |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1935
diff
changeset
|
787 |
* STR_881A_TRAINS_CAN_ONLY_BE_ALTERED and returns -1 */ |
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
788 |
int CheckTrainStoppedInDepot(const Vehicle *v) |
0 | 789 |
{ |
790 |
int count; |
|
791 |
TileIndex tile = v->tile; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
792 |
|
0 | 793 |
/* check if stopped in a depot */ |
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
794 |
if (!IsTileDepotType(tile, TRANSPORT_RAIL) || v->cur_speed != 0) { |
0 | 795 |
_error_message = STR_881A_TRAINS_CAN_ONLY_BE_ALTERED; |
796 |
return -1; |
|
797 |
} |
|
798 |
||
799 |
count = 0; |
|
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
800 |
for (; v != NULL; v = v->next) { |
0 | 801 |
count++; |
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
802 |
if (v->u.rail.track != 0x80 || v->tile != tile || |
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
803 |
(v->subtype == TS_Front_Engine && !(v->vehstatus & VS_STOPPED))) { |
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
804 |
_error_message = STR_881A_TRAINS_CAN_ONLY_BE_ALTERED; |
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
805 |
return -1; |
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
806 |
} |
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
807 |
} |
0 | 808 |
|
809 |
return count; |
|
810 |
} |
|
811 |
||
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
812 |
/** |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
813 |
* Unlink a rail wagon from the consist. |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
814 |
* @param v Vehicle to remove. |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
815 |
* @param first The first vehicle of the consist. |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
816 |
* @return The first vehicle of the consist. |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
817 |
*/ |
0 | 818 |
static Vehicle *UnlinkWagon(Vehicle *v, Vehicle *first) |
819 |
{ |
|
1766
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
820 |
Vehicle *u; |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
821 |
|
0 | 822 |
// unlinking the first vehicle of the chain? |
823 |
if (v == first) { |
|
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
824 |
v = GetNextVehicle(v); |
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
825 |
if (v == NULL) return NULL; |
1766
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
826 |
|
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1064
diff
changeset
|
827 |
v->subtype = TS_Free_Car; |
0 | 828 |
return v; |
829 |
} |
|
1766
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
830 |
|
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
831 |
for (u = first; GetNextVehicle(u) != v; u = GetNextVehicle(u)) {} |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
832 |
GetLastEnginePart(u)->next = GetNextVehicle(v); |
1766
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
833 |
return first; |
0 | 834 |
} |
835 |
||
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
836 |
static Vehicle *FindGoodVehiclePos(const Vehicle *src) |
0 | 837 |
{ |
838 |
Vehicle *dst; |
|
2477
225b2916fe2a
(svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents:
2475
diff
changeset
|
839 |
EngineID eng = src->engine_type; |
0 | 840 |
TileIndex tile = src->tile; |
841 |
||
842 |
FOR_ALL_VEHICLES(dst) { |
|
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
843 |
if (dst->type == VEH_Train && dst->subtype == TS_Free_Car && |
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
844 |
dst->tile == tile) { |
0 | 845 |
// check so all vehicles in the line have the same engine. |
846 |
Vehicle *v = dst; |
|
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
847 |
|
0 | 848 |
while (v->engine_type == eng) { |
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
849 |
v = v->next; |
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
850 |
if (v == NULL) return dst; |
0 | 851 |
} |
852 |
} |
|
853 |
} |
|
854 |
||
855 |
return NULL; |
|
856 |
} |
|
857 |
||
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
858 |
/** Move a rail vehicle around inside the depot. |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
859 |
* @param x,y unused |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
860 |
* @param p1 various bitstuffed elements |
2639 | 861 |
* - p1 (bit 0 - 15) source vehicle index |
862 |
* - p1 (bit 16 - 31) what wagon to put the source wagon AFTER, XXX - INVALID_VEHICLE to make a new line |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
863 |
* @param p2 (bit 0) move all vehicles following the source vehicle |
0 | 864 |
*/ |
865 |
int32 CmdMoveRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
866 |
{ |
|
2484
0e45d70ae908
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents:
2482
diff
changeset
|
867 |
VehicleID s = GB(p1, 0, 16); |
0e45d70ae908
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents:
2482
diff
changeset
|
868 |
VehicleID d = GB(p1, 16, 16); |
0 | 869 |
Vehicle *src, *dst, *src_head, *dst_head; |
870 |
bool is_loco; |
|
871 |
||
2484
0e45d70ae908
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents:
2482
diff
changeset
|
872 |
if (!IsVehicleIndex(s)) return CMD_ERROR; |
0e45d70ae908
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents:
2482
diff
changeset
|
873 |
|
0e45d70ae908
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents:
2482
diff
changeset
|
874 |
src = GetVehicle(s); |
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1236
diff
changeset
|
875 |
|
0 | 876 |
if (src->type != VEH_Train) return CMD_ERROR; |
877 |
||
1766
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
878 |
is_loco = !(RailVehInfo(src->engine_type)->flags & RVI_WAGON) && IS_FIRSTHEAD_SPRITE(src->spritenum); |
0 | 879 |
|
880 |
// if nothing is selected as destination, try and find a matching vehicle to drag to. |
|
2484
0e45d70ae908
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents:
2482
diff
changeset
|
881 |
if (d == INVALID_VEHICLE) { |
0 | 882 |
dst = NULL; |
883 |
if (!is_loco) dst = FindGoodVehiclePos(src); |
|
884 |
} else { |
|
2484
0e45d70ae908
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents:
2482
diff
changeset
|
885 |
dst = GetVehicle(d); |
0 | 886 |
} |
887 |
||
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
888 |
// if an articulated part is being handled, deal with its parent vehicle |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
889 |
while (src->subtype == TS_Artic_Part) src = GetPrevVehicleInChain(src); |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
890 |
if (dst != NULL) { |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
891 |
while (dst->subtype == TS_Artic_Part) dst = GetPrevVehicleInChain(dst); |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
892 |
} |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
893 |
|
0 | 894 |
// don't move the same vehicle.. |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
895 |
if (src == dst) return 0; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
896 |
|
0 | 897 |
/* the player must be the owner */ |
2639 | 898 |
if (!CheckOwnership(src->owner) || (dst != NULL && !CheckOwnership(dst->owner))) |
0 | 899 |
return CMD_ERROR; |
900 |
||
901 |
/* locate the head of the two chains */ |
|
902 |
src_head = GetFirstVehicleInChain(src); |
|
903 |
dst_head = NULL; |
|
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
904 |
if (dst != NULL) { |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
905 |
dst_head = GetFirstVehicleInChain(dst); |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
906 |
// Now deal with articulated part of destination wagon |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
907 |
dst = GetLastEnginePart(dst); |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
908 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
909 |
|
1601
83fbe3bfb847
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1554
diff
changeset
|
910 |
/* clear the ->first cache */ |
83fbe3bfb847
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1554
diff
changeset
|
911 |
{ |
83fbe3bfb847
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1554
diff
changeset
|
912 |
Vehicle *u; |
83fbe3bfb847
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1554
diff
changeset
|
913 |
|
83fbe3bfb847
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1554
diff
changeset
|
914 |
for (u = src_head; u != NULL; u = u->next) u->first = NULL; |
83fbe3bfb847
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1554
diff
changeset
|
915 |
for (u = dst_head; u != NULL; u = u->next) u->first = NULL; |
83fbe3bfb847
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1554
diff
changeset
|
916 |
} |
83fbe3bfb847
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1554
diff
changeset
|
917 |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
918 |
/* check if all vehicles in the source train are stopped inside a depot */ |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
919 |
if (CheckTrainStoppedInDepot(src_head) < 0) return CMD_ERROR; |
0 | 920 |
|
921 |
/* check if all the vehicles in the dest train are stopped, |
|
922 |
* and that the length of the dest train is no longer than XXX vehicles */ |
|
923 |
if (dst_head != NULL) { |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
924 |
int num = CheckTrainStoppedInDepot(dst_head); |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
925 |
if (num < 0) return CMD_ERROR; |
0 | 926 |
|
1766
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
927 |
if (num > (_patches.mammoth_trains ? 100 : 9) && dst_head->subtype == TS_Front_Engine ) |
0 | 928 |
return_cmd_error(STR_8819_TRAIN_TOO_LONG); |
929 |
||
930 |
// if it's a multiheaded vehicle we're dragging to, drag to the vehicle before.. |
|
1766
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
931 |
while (IS_CUSTOM_SECONDHEAD_SPRITE(dst->spritenum) || ( |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
932 |
!is_custom_sprite(dst->spritenum) && _engine_sprite_add[dst->spritenum] != 0) |
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
933 |
) { |
0 | 934 |
Vehicle *v = GetPrevVehicleInChain(dst); |
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
935 |
if (v == NULL || src == v) break; |
0 | 936 |
dst = v; |
937 |
} |
|
938 |
||
939 |
assert(dst_head->tile == src_head->tile); |
|
940 |
} |
|
941 |
||
942 |
// when moving all wagons, we can't have the same src_head and dst_head |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
943 |
if (HASBIT(p2, 0) && src_head == dst_head) return 0; |
0 | 944 |
|
945 |
// moving a loco to a new line?, then we need to assign a unitnumber. |
|
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1064
diff
changeset
|
946 |
if (dst == NULL && src->subtype != TS_Front_Engine && is_loco) { |
1282
ea2ae881814c
(svn r1786) -Fix: unitnumber is increased to 16bit, so now you can have up to 5000
truelight
parents:
1266
diff
changeset
|
947 |
UnitID unit_num = GetFreeUnitNumber(VEH_Train); |
0 | 948 |
if (unit_num > _patches.max_trains) |
949 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
|
950 |
||
951 |
if (flags & DC_EXEC) |
|
952 |
src->unitnumber = unit_num; |
|
953 |
} |
|
954 |
||
955 |
||
956 |
/* do it? */ |
|
957 |
if (flags & DC_EXEC) { |
|
2607
9915a4829de8
(svn r3144) -Fix: a new train is now made if the front unit is an engine and the former front engine is moved away (Meush)
bjarni
parents:
2602
diff
changeset
|
958 |
Vehicle *new_front = GetNextVehicle(src); //used if next in line should make a train on it's own |
9915a4829de8
(svn r3144) -Fix: a new train is now made if the front unit is an engine and the former front engine is moved away (Meush)
bjarni
parents:
2602
diff
changeset
|
959 |
bool make_new_front = src->subtype == TS_Front_Engine; |
9915a4829de8
(svn r3144) -Fix: a new train is now made if the front unit is an engine and the former front engine is moved away (Meush)
bjarni
parents:
2602
diff
changeset
|
960 |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
961 |
if (HASBIT(p2, 0)) { |
0 | 962 |
// unlink ALL wagons |
963 |
if (src != src_head) { |
|
964 |
Vehicle *v = src_head; |
|
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
965 |
while (GetNextVehicle(v) != src) v = GetNextVehicle(v); |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
966 |
GetLastEnginePart(v)->next = NULL; |
1917
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
967 |
} else { |
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
968 |
src_head = NULL; |
0 | 969 |
} |
970 |
} else { |
|
1921
c20a59372a23
(svn r2427) - Fix: CmdMoveRailVehice; Prevent possible assertion failure when moving vehicles within one chain.
hackykid
parents:
1917
diff
changeset
|
971 |
// if moving within the same chain, dont use dst_head as it may get invalidated |
c20a59372a23
(svn r2427) - Fix: CmdMoveRailVehice; Prevent possible assertion failure when moving vehicles within one chain.
hackykid
parents:
1917
diff
changeset
|
972 |
if (src_head == dst_head) |
c20a59372a23
(svn r2427) - Fix: CmdMoveRailVehice; Prevent possible assertion failure when moving vehicles within one chain.
hackykid
parents:
1917
diff
changeset
|
973 |
dst_head = NULL; |
0 | 974 |
// unlink single wagon from linked list |
1917
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
975 |
src_head = UnlinkWagon(src, src_head); |
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
976 |
GetLastEnginePart(src)->next = NULL; |
0 | 977 |
} |
978 |
||
979 |
if (dst == NULL) { |
|
980 |
// move the train to an empty line. for locomotives, we set the type to 0. for wagons, 4. |
|
981 |
if (is_loco) { |
|
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1064
diff
changeset
|
982 |
if (src->subtype != TS_Front_Engine) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
954
diff
changeset
|
983 |
// setting the type to 0 also involves setting up the orders field. |
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1064
diff
changeset
|
984 |
src->subtype = TS_Front_Engine; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
954
diff
changeset
|
985 |
assert(src->orders == NULL); |
0 | 986 |
src->num_orders = 0; |
987 |
} |
|
988 |
} else { |
|
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1064
diff
changeset
|
989 |
src->subtype = TS_Free_Car; |
0 | 990 |
} |
1917
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
991 |
dst_head = src; |
0 | 992 |
} else { |
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1064
diff
changeset
|
993 |
if (src->subtype == TS_Front_Engine) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
954
diff
changeset
|
994 |
// the vehicle was previously a loco. need to free the order list and delete vehicle windows etc. |
0 | 995 |
DeleteWindowById(WC_VEHICLE_VIEW, src->index); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
954
diff
changeset
|
996 |
DeleteVehicleOrders(src); |
0 | 997 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
998 |
|
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1064
diff
changeset
|
999 |
src->subtype = TS_Not_First; |
0 | 1000 |
src->unitnumber = 0; // doesn't occupy a unitnumber anymore. |
1001 |
||
1002 |
// link in the wagon(s) in the chain. |
|
1003 |
{ |
|
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
1004 |
Vehicle *v; |
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
1005 |
|
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
1006 |
for (v = src; GetNextVehicle(v) != NULL; v = GetNextVehicle(v)); |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
1007 |
GetLastEnginePart(v)->next = dst->next; |
0 | 1008 |
} |
1009 |
dst->next = src; |
|
1010 |
} |
|
1011 |
||
2607
9915a4829de8
(svn r3144) -Fix: a new train is now made if the front unit is an engine and the former front engine is moved away (Meush)
bjarni
parents:
2602
diff
changeset
|
1012 |
/* If there is an engine behind first_engine we moved away, it should become new first_engine |
9915a4829de8
(svn r3144) -Fix: a new train is now made if the front unit is an engine and the former front engine is moved away (Meush)
bjarni
parents:
2602
diff
changeset
|
1013 |
* To do this, CmdMoveRailVehicle must be called once more |
9915a4829de8
(svn r3144) -Fix: a new train is now made if the front unit is an engine and the former front engine is moved away (Meush)
bjarni
parents:
2602
diff
changeset
|
1014 |
* since we set p2 to a condition that makes the statement false, we can't loop forever with this one */ |
9915a4829de8
(svn r3144) -Fix: a new train is now made if the front unit is an engine and the former front engine is moved away (Meush)
bjarni
parents:
2602
diff
changeset
|
1015 |
if (make_new_front && new_front != NULL && !(HASBIT(p2, 0))) { |
9915a4829de8
(svn r3144) -Fix: a new train is now made if the front unit is an engine and the former front engine is moved away (Meush)
bjarni
parents:
2602
diff
changeset
|
1016 |
if (!(RailVehInfo(new_front->engine_type)->flags & RVI_WAGON)) { |
9915a4829de8
(svn r3144) -Fix: a new train is now made if the front unit is an engine and the former front engine is moved away (Meush)
bjarni
parents:
2602
diff
changeset
|
1017 |
CmdMoveRailVehicle(x, y, flags, new_front->index | (INVALID_VEHICLE << 16), 1); |
9915a4829de8
(svn r3144) -Fix: a new train is now made if the front unit is an engine and the former front engine is moved away (Meush)
bjarni
parents:
2602
diff
changeset
|
1018 |
} |
9915a4829de8
(svn r3144) -Fix: a new train is now made if the front unit is an engine and the former front engine is moved away (Meush)
bjarni
parents:
2602
diff
changeset
|
1019 |
} |
9915a4829de8
(svn r3144) -Fix: a new train is now made if the front unit is an engine and the former front engine is moved away (Meush)
bjarni
parents:
2602
diff
changeset
|
1020 |
|
1917
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
1021 |
if (src_head) { |
1905
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
1022 |
TrainConsistChanged(src_head); |
1917
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
1023 |
if (src_head->subtype == TS_Front_Engine) { |
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
1024 |
UpdateTrainAcceleration(src_head); |
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
1025 |
InvalidateWindow(WC_VEHICLE_DETAILS, src_head->index); |
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
1026 |
/* Update the refit button and window */ |
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
1027 |
InvalidateWindow(WC_VEHICLE_REFIT, src_head->index); |
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
1028 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, src_head->index, 12); |
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
1029 |
} |
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
1030 |
/* Update the depot window */ |
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
1031 |
InvalidateWindow(WC_VEHICLE_DEPOT, src_head->tile); |
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
1032 |
}; |
0 | 1033 |
|
1034 |
if (dst_head) { |
|
1917
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
1035 |
TrainConsistChanged(dst_head); |
1905
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
1036 |
if (dst_head->subtype == TS_Front_Engine) { |
0 | 1037 |
UpdateTrainAcceleration(dst_head); |
1917
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
1038 |
InvalidateWindow(WC_VEHICLE_DETAILS, dst_head->index); |
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
1039 |
/* Update the refit button and window */ |
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
1040 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, dst_head->index, 12); |
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
1041 |
InvalidateWindow(WC_VEHICLE_REFIT, dst_head->index); |
1905
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
1042 |
} |
1917
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
1043 |
/* Update the depot window */ |
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
1044 |
InvalidateWindow(WC_VEHICLE_DEPOT, dst_head->tile); |
0 | 1045 |
} |
1046 |
||
737
05082439a150
(svn r1189) Fix vehicle list update glitch when moving waggons in depots
tron
parents:
715
diff
changeset
|
1047 |
RebuildVehicleLists(); |
0 | 1048 |
} |
1049 |
||
1050 |
return 0; |
|
1051 |
} |
|
1052 |
||
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1053 |
/** Start/Stop a train. |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1054 |
* @param x,y unused |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1055 |
* @param p1 train to start/stop |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1056 |
* @param p2 unused |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1057 |
*/ |
0 | 1058 |
int32 CmdStartStopTrain(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
1059 |
{ |
|
1060 |
Vehicle *v; |
|
1061 |
||
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1236
diff
changeset
|
1062 |
if (!IsVehicleIndex(p1)) return CMD_ERROR; |
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1236
diff
changeset
|
1063 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
1064 |
v = GetVehicle(p1); |
0 | 1065 |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1066 |
if (v->type != VEH_Train || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 1067 |
|
1068 |
if (flags & DC_EXEC) { |
|
1069 |
v->u.rail.days_since_order_progr = 0; |
|
1070 |
v->vehstatus ^= VS_STOPPED; |
|
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
744
diff
changeset
|
1071 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1072 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
1073 |
} |
|
1074 |
return 0; |
|
1075 |
} |
|
1076 |
||
1766
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1077 |
/** |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1078 |
* Search for a matching rear-engine of a dual-headed train. |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1079 |
* Do this as if you would find matching parentheses. If a new |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1080 |
* engine is 'started', first 'close' that before 'closing' our |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1081 |
* searched engine |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1082 |
*/ |
2599
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2595
diff
changeset
|
1083 |
Vehicle *GetRearEngine(const Vehicle *v, EngineID engine) |
1766
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1084 |
{ |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1085 |
Vehicle *u; |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1086 |
int en_count = 1; |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1087 |
|
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1088 |
for (u = v->next; u != NULL; u = u->next) { |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1089 |
if (u->engine_type == engine) { // find matching engine |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1090 |
en_count += (IS_FIRSTHEAD_SPRITE(u->spritenum)) ? +1 : -1; |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1091 |
|
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1092 |
if (en_count == 0) return (Vehicle *)u; |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1093 |
} |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1094 |
} |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1095 |
return NULL; |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1096 |
} |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1097 |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1098 |
/** Sell a (single) train wagon/engine. |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1099 |
* @param x,y unused |
1766
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1100 |
* @param p1 the wagon/engine index |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1101 |
* @param p2 the selling mode |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1102 |
* - p2 = 0: only sell the single dragged wagon/engine (and any belonging rear-engines) |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1103 |
* - p2 = 1: sell the vehicle and all vehicles following it in the chain |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1104 |
if the wagon is dragged, don't delete the possibly belonging rear-engine to some front |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1105 |
* - p2 = 2: when selling attached locos, rearrange all vehicles after it to separate lines; |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1106 |
* all wagons of the same type will go on the same line. Used by the AI currently |
1766
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1107 |
*/ |
0 | 1108 |
int32 CmdSellRailWagon(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
1109 |
{ |
|
1766
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1110 |
Vehicle *v, *tmp, *first; |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1111 |
int32 cost = 0; |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1112 |
|
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1113 |
if (!IsVehicleIndex(p1) || p2 > 2) return CMD_ERROR; |
0 | 1114 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
1115 |
v = GetVehicle(p1); |
0 | 1116 |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1117 |
if (v->type != VEH_Train || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 1118 |
|
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1236
diff
changeset
|
1119 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1236
diff
changeset
|
1120 |
|
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
1121 |
while (v->subtype == TS_Artic_Part) v = GetPrevVehicleInChain(v); |
1766
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1122 |
first = GetFirstVehicleInChain(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
1123 |
|
0 | 1124 |
// make sure the vehicle is stopped in the depot |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1125 |
if (CheckTrainStoppedInDepot(first) < 0) return CMD_ERROR; |
0 | 1126 |
|
1842
fb9086b04740
(svn r2347) - Fix (regression): depot window did not get redrawn when a non-train-engine was sold.
Darkvater
parents:
1802
diff
changeset
|
1127 |
if (flags & DC_EXEC) { |
fb9086b04740
(svn r2347) - Fix (regression): depot window did not get redrawn when a non-train-engine was sold.
Darkvater
parents:
1802
diff
changeset
|
1128 |
if (v == first && first->subtype == TS_Front_Engine) { |
fb9086b04740
(svn r2347) - Fix (regression): depot window did not get redrawn when a non-train-engine was sold.
Darkvater
parents:
1802
diff
changeset
|
1129 |
DeleteWindowById(WC_VEHICLE_VIEW, first->index); |
2618
9691753519ac
(svn r3156) -Fix: removed some cases where autoreplace windows were redrawn when nothing was changed
bjarni
parents:
2617
diff
changeset
|
1130 |
} |
9691753519ac
(svn r3156) -Fix: removed some cases where autoreplace windows were redrawn when nothing was changed
bjarni
parents:
2617
diff
changeset
|
1131 |
if (IsLocalPlayer() && (p1 == 1 || !(RailVehInfo(v->engine_type)->flags & RVI_WAGON))) { |
1842
fb9086b04740
(svn r2347) - Fix (regression): depot window did not get redrawn when a non-train-engine was sold.
Darkvater
parents:
1802
diff
changeset
|
1132 |
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Train); |
fb9086b04740
(svn r2347) - Fix (regression): depot window did not get redrawn when a non-train-engine was sold.
Darkvater
parents:
1802
diff
changeset
|
1133 |
} |
0 | 1134 |
InvalidateWindow(WC_VEHICLE_DEPOT, first->tile); |
1779
25b3028dc97c
(svn r2283) - Fix (regression): [ 1197493 ] train_gui.c:1341: failed assertion ..., somehow RebuildVehicleList() got lost during the rewrite :P
Darkvater
parents:
1777
diff
changeset
|
1135 |
RebuildVehicleLists(); |
1766
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1136 |
} |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1137 |
|
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1138 |
switch (p2) { |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1139 |
case 0: case 2: { /* Delete given wagon */ |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1140 |
bool switch_engine = false; // update second wagon to engine? |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1141 |
byte ori_subtype = v->subtype; // backup subtype of deleted wagon in case DeleteVehicle() changes |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1142 |
|
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1143 |
/* 1. Delete the engine, if it is dualheaded also delete the matching |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1144 |
* rear engine of the loco (from the point of deletion onwards) */ |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1145 |
Vehicle *rear = (RailVehInfo(v->engine_type)->flags & RVI_MULTIHEAD) ? GetRearEngine(v, v->engine_type) : NULL; |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1146 |
if (rear != NULL) { |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1147 |
cost -= v->value; |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1148 |
if (flags & DC_EXEC) { |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1149 |
v = UnlinkWagon(rear, v); |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1150 |
DeleteVehicle(rear); |
0 | 1151 |
} |
1152 |
} |
|
1766
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1153 |
|
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1154 |
/* 2. We are selling the first engine, some special action might be required |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1155 |
* here, so take attention */ |
1770
18491bba9211
(svn r2274) - Codechange: some comments, parentheses and EngineID typedef for engine_type
Darkvater
parents:
1766
diff
changeset
|
1156 |
if ((flags & DC_EXEC) && v == first) { |
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
1157 |
Vehicle *new_f = GetNextVehicle(first); |
1766
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1158 |
|
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1159 |
/* 2.1 If the first wagon is sold, update the first-> pointers to NULL */ |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1160 |
for (tmp = first; tmp != NULL; tmp = tmp->next) tmp->first = NULL; |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1161 |
|
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1162 |
/* 2.2 If there are wagons present after the deleted front engine, check |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1163 |
* if the second wagon (which will be first) is an engine. If it is one, |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1164 |
* promote it as a new train, retaining the unitnumber, orders */ |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1165 |
if (new_f != NULL) { |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1166 |
if (!(RailVehInfo(new_f->engine_type)->flags & RVI_WAGON) && IS_FIRSTHEAD_SPRITE(new_f->spritenum)) { |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1167 |
switch_engine = true; |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1168 |
/* Copy important data from the front engine */ |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1169 |
new_f->unitnumber = first->unitnumber; |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1170 |
new_f->current_order = first->current_order; |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1171 |
new_f->cur_order_index = first->cur_order_index; |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1172 |
new_f->orders = first->orders; |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1173 |
new_f->num_orders = first->num_orders; |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1174 |
first->orders = NULL; // XXX - to not to delete the orders */ |
2425
e755ee29133a
(svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents:
2360
diff
changeset
|
1175 |
if (IsLocalPlayer()) ShowTrainViewWindow(new_f); |
1766
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1176 |
} |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1177 |
} |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1178 |
} |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1179 |
|
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1180 |
/* 3. Delete the requested wagon */ |
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1461
diff
changeset
|
1181 |
cost -= v->value; |
1766
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1182 |
if (flags & DC_EXEC) { |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1183 |
first = UnlinkWagon(v, first); |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1184 |
DeleteVehicle(v); |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1185 |
|
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1186 |
/* 4 If the second wagon was an engine, update it to front_engine |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1187 |
* which UnlinkWagon() has changed to TS_Free_Car */ |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1188 |
if (switch_engine) first->subtype = TS_Front_Engine; |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1189 |
|
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1190 |
/* 5. If the train still exists, update its acceleration, window, etc. */ |
1917
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
1191 |
if (first != NULL) { |
1905
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
1192 |
TrainConsistChanged(first); |
1917
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
1193 |
if (first->subtype == TS_Front_Engine) { |
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
1194 |
InvalidateWindow(WC_VEHICLE_DETAILS, first->index); |
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
1195 |
InvalidateWindow(WC_VEHICLE_REFIT, first->index); |
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
1196 |
UpdateTrainAcceleration(first); |
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
1197 |
} |
1766
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1198 |
} |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1199 |
|
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1200 |
|
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1201 |
/* (6.) Borked AI. If it sells an engine it expects all wagons lined |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1202 |
* up on a new line to be added to the newly built loco. Replace it is. |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1203 |
* Totally braindead cause building a new engine adds all loco-less |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1204 |
* engines to its train anyways */ |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1205 |
if (p2 == 2 && ori_subtype == TS_Front_Engine) { |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1206 |
for (v = first; v != NULL; v = tmp) { |
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
1207 |
tmp = GetNextVehicle(v); |
1766
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1208 |
DoCommandByTile(v->tile, v->index | INVALID_VEHICLE << 16, 0, DC_EXEC, CMD_MOVE_RAIL_VEHICLE); |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1209 |
} |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1210 |
} |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1211 |
} |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1212 |
} break; |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1213 |
case 1: { /* Delete wagon and all wagons after it given certain criteria */ |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1214 |
/* 1. Count the number for first and rear engines for dualheads |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1215 |
* to be able to deduce which ones go with which ones */ |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1216 |
int enf_count = 0; |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1217 |
int enr_count = 0; |
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
1218 |
for (tmp = first; tmp != NULL; tmp = GetNextVehicle(tmp)) { |
1766
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1219 |
if (RailVehInfo(tmp->engine_type)->flags & RVI_MULTIHEAD) |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1220 |
(IS_FIRSTHEAD_SPRITE(tmp->spritenum)) ? enf_count++ : enr_count++; |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1221 |
} |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1222 |
|
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1223 |
/* 2. Start deleting every vehicle after the selected one |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1224 |
* If we encounter a matching rear-engine to a front-engine |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1225 |
* earlier in the chain (before deletion), leave it alone */ |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1226 |
for (; v != NULL; v = tmp) { |
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
1227 |
tmp = GetNextVehicle(v); |
1766
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1228 |
|
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1229 |
if (RailVehInfo(v->engine_type)->flags & RVI_MULTIHEAD) { |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1230 |
if (IS_FIRSTHEAD_SPRITE(v->spritenum)) { |
2549 | 1231 |
/* Always delete newly encountered front-engines */ |
1766
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1232 |
enf_count--; |
2549 | 1233 |
} else if (enr_count > enf_count) { |
1234 |
/* More rear engines than front engines means this rear-engine does |
|
1235 |
* not belong to any front-engine; delete */ |
|
1236 |
enr_count--; |
|
1237 |
} else { |
|
1238 |
/* Otherwise leave it alone */ |
|
1239 |
continue; |
|
1240 |
} |
|
1766
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1241 |
} |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1242 |
|
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1243 |
cost -= v->value; |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1244 |
if (flags & DC_EXEC) { |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1245 |
first = UnlinkWagon(v, first); |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1246 |
DeleteVehicle(v); |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1247 |
} |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1248 |
} |
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1249 |
|
1905
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
1250 |
/* 3. If it is still a valid train after selling, update its acceleration and cached values */ |
1917
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
1251 |
if ((flags & DC_EXEC) && first != NULL) { |
1905
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
1252 |
TrainConsistChanged(first); |
1917
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
1253 |
if (first->subtype == TS_Front_Engine) |
03e113481a62
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1909
diff
changeset
|
1254 |
UpdateTrainAcceleration(first); |
1905
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
1255 |
} |
1766
8cdb302ae946
(svn r2270) - Fix/Codechange: fix up selling rail vehicles. Try to be smart about it. When selling dual-headed trains, also sell the rear end; if the now-first wagon is an engine, make it a train. When selling the whole train, try to leave dual-headed setups intact
Darkvater
parents:
1758
diff
changeset
|
1256 |
} break; |
0 | 1257 |
} |
1258 |
return cost; |
|
1259 |
} |
|
1260 |
||
1261 |
static void UpdateTrainDeltaXY(Vehicle *v, int direction) |
|
1262 |
{ |
|
1263 |
#define MKIT(a,b,c,d) ((a&0xFF)<<24) | ((b&0xFF)<<16) | ((c&0xFF)<<8) | ((d&0xFF)<<0) |
|
1264 |
static const uint32 _delta_xy_table[8] = { |
|
1265 |
MKIT(3, 3, -1, -1), |
|
1266 |
MKIT(3, 7, -1, -3), |
|
1267 |
MKIT(3, 3, -1, -1), |
|
1268 |
MKIT(7, 3, -3, -1), |
|
1269 |
MKIT(3, 3, -1, -1), |
|
1270 |
MKIT(3, 7, -1, -3), |
|
1271 |
MKIT(3, 3, -1, -1), |
|
1272 |
MKIT(7, 3, -3, -1), |
|
1273 |
}; |
|
1274 |
#undef MKIT |
|
1275 |
||
1276 |
uint32 x = _delta_xy_table[direction]; |
|
1277 |
||
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
1278 |
v->x_offs = GB(x, 0, 8); |
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
1279 |
v->y_offs = GB(x, 8, 8); |
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
1280 |
v->sprite_width = GB(x, 16, 8); |
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
1281 |
v->sprite_height = GB(x, 24, 8); |
0 | 1282 |
} |
1283 |
||
1284 |
static void UpdateVarsAfterSwap(Vehicle *v) |
|
1285 |
{ |
|
1286 |
UpdateTrainDeltaXY(v, v->direction); |
|
1287 |
v->cur_image = GetTrainImage(v, v->direction); |
|
1288 |
BeginVehicleMove(v); |
|
1289 |
VehiclePositionChanged(v); |
|
1290 |
EndVehicleMove(v); |
|
1291 |
} |
|
1292 |
||
2639 | 1293 |
static void SetLastSpeed(Vehicle* v, int spd) |
1294 |
{ |
|
0 | 1295 |
int old = v->u.rail.last_speed; |
1296 |
if (spd != old) { |
|
1297 |
v->u.rail.last_speed = spd; |
|
1298 |
if (_patches.vehicle_speed || !old != !spd) |
|
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
744
diff
changeset
|
1299 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1300 |
} |
1301 |
} |
|
1302 |
||
954
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1303 |
static void SwapTrainFlags(byte *swap_flag1, byte *swap_flag2) |
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1304 |
{ |
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1305 |
byte flag1, flag2; |
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1306 |
|
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1307 |
flag1 = *swap_flag1; |
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1308 |
flag2 = *swap_flag2; |
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1309 |
|
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1310 |
/* Clear the flags */ |
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1311 |
CLRBIT(*swap_flag1, VRF_GOINGUP); |
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1312 |
CLRBIT(*swap_flag1, VRF_GOINGDOWN); |
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1313 |
CLRBIT(*swap_flag2, VRF_GOINGUP); |
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1314 |
CLRBIT(*swap_flag2, VRF_GOINGDOWN); |
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1315 |
|
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1316 |
/* Reverse the rail-flags (if needed) */ |
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1317 |
if (HASBIT(flag1, VRF_GOINGUP)) { |
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1318 |
SETBIT(*swap_flag2, VRF_GOINGDOWN); |
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1319 |
} else if (HASBIT(flag1, VRF_GOINGDOWN)) { |
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1320 |
SETBIT(*swap_flag2, VRF_GOINGUP); |
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1321 |
} |
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1322 |
if (HASBIT(flag2, VRF_GOINGUP)) { |
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1323 |
SETBIT(*swap_flag1, VRF_GOINGDOWN); |
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1324 |
} else if (HASBIT(flag2, VRF_GOINGDOWN)) { |
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1325 |
SETBIT(*swap_flag1, VRF_GOINGUP); |
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1326 |
} |
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1327 |
} |
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1328 |
|
0 | 1329 |
static void ReverseTrainSwapVeh(Vehicle *v, int l, int r) |
1330 |
{ |
|
1331 |
Vehicle *a, *b; |
|
1332 |
||
1333 |
/* locate vehicles to swap */ |
|
2549 | 1334 |
for (a = v; l != 0; l--) a = a->next; |
1335 |
for (b = v; r != 0; r--) b = b->next; |
|
0 | 1336 |
|
1337 |
if (a != b) { |
|
1338 |
/* swap the hidden bits */ |
|
1339 |
{ |
|
1340 |
uint16 tmp = (a->vehstatus & ~VS_HIDDEN) | (b->vehstatus&VS_HIDDEN); |
|
1341 |
b->vehstatus = (b->vehstatus & ~VS_HIDDEN) | (a->vehstatus&VS_HIDDEN); |
|
1342 |
a->vehstatus = tmp; |
|
1343 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
1344 |
|
0 | 1345 |
/* swap variables */ |
1346 |
swap_byte(&a->u.rail.track, &b->u.rail.track); |
|
1347 |
swap_byte(&a->direction, &b->direction); |
|
1348 |
||
1349 |
/* toggle direction */ |
|
1350 |
if (!(a->u.rail.track & 0x80)) a->direction ^= 4; |
|
1351 |
if (!(b->u.rail.track & 0x80)) b->direction ^= 4; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
1352 |
|
0 | 1353 |
/* swap more variables */ |
1174
6a5e747f3ba6
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1151
diff
changeset
|
1354 |
swap_int32(&a->x_pos, &b->x_pos); |
6a5e747f3ba6
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1151
diff
changeset
|
1355 |
swap_int32(&a->y_pos, &b->y_pos); |
0 | 1356 |
swap_tile(&a->tile, &b->tile); |
1357 |
swap_byte(&a->z_pos, &b->z_pos); |
|
1358 |
||
954
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1359 |
SwapTrainFlags(&a->u.rail.flags, &b->u.rail.flags); |
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1360 |
|
0 | 1361 |
/* update other vars */ |
1362 |
UpdateVarsAfterSwap(a); |
|
1363 |
UpdateVarsAfterSwap(b); |
|
1554
79809a004e97
(svn r2058) -Fix: hopefully this fixes the reverse-train-in-depot-bugs (plural)
truelight
parents:
1552
diff
changeset
|
1364 |
|
79809a004e97
(svn r2058) -Fix: hopefully this fixes the reverse-train-in-depot-bugs (plural)
truelight
parents:
1552
diff
changeset
|
1365 |
VehicleEnterTile(a, a->tile, a->x_pos, a->y_pos); |
79809a004e97
(svn r2058) -Fix: hopefully this fixes the reverse-train-in-depot-bugs (plural)
truelight
parents:
1552
diff
changeset
|
1366 |
VehicleEnterTile(b, b->tile, b->x_pos, b->y_pos); |
0 | 1367 |
} else { |
1368 |
if (!(a->u.rail.track & 0x80)) a->direction ^= 4; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
1369 |
UpdateVarsAfterSwap(a); |
1554
79809a004e97
(svn r2058) -Fix: hopefully this fixes the reverse-train-in-depot-bugs (plural)
truelight
parents:
1552
diff
changeset
|
1370 |
|
79809a004e97
(svn r2058) -Fix: hopefully this fixes the reverse-train-in-depot-bugs (plural)
truelight
parents:
1552
diff
changeset
|
1371 |
VehicleEnterTile(a, a->tile, a->x_pos, a->y_pos); |
0 | 1372 |
} |
1373 |
} |
|
1374 |
||
744
ee33af65c436
(svn r1200) -Fix: Fixed bug pointed out by Tron: when a train is on the
truelight
parents:
743
diff
changeset
|
1375 |
/* Check if the vehicle is a train and is on the tile we are testing */ |
ee33af65c436
(svn r1200) -Fix: Fixed bug pointed out by Tron: when a train is on the
truelight
parents:
743
diff
changeset
|
1376 |
static void *TestTrainOnCrossing(Vehicle *v, void *data) |
ee33af65c436
(svn r1200) -Fix: Fixed bug pointed out by Tron: when a train is on the
truelight
parents:
743
diff
changeset
|
1377 |
{ |
2639 | 1378 |
if (v->tile != *(const TileIndex*)data || v->type != VEH_Train) return NULL; |
744
ee33af65c436
(svn r1200) -Fix: Fixed bug pointed out by Tron: when a train is on the
truelight
parents:
743
diff
changeset
|
1379 |
return v; |
ee33af65c436
(svn r1200) -Fix: Fixed bug pointed out by Tron: when a train is on the
truelight
parents:
743
diff
changeset
|
1380 |
} |
ee33af65c436
(svn r1200) -Fix: Fixed bug pointed out by Tron: when a train is on the
truelight
parents:
743
diff
changeset
|
1381 |
|
1103
530d0a75f91c
(svn r1604) Fix: [ 1105112 ] Destroyed train locks crossings
dominik
parents:
1095
diff
changeset
|
1382 |
static void DisableTrainCrossing(TileIndex tile) |
530d0a75f91c
(svn r1604) Fix: [ 1105112 ] Destroyed train locks crossings
dominik
parents:
1095
diff
changeset
|
1383 |
{ |
2639 | 1384 |
if (IsTileType(tile, MP_STREET) && |
1385 |
IsLevelCrossing(tile) && |
|
1386 |
VehicleFromPos(tile, &tile, TestTrainOnCrossing) == NULL && // empty? |
|
1387 |
GB(_m[tile].m5, 2, 1) != 0) { // Lights on? |
|
1388 |
SB(_m[tile].m5, 2, 1, 0); // Switch lights off |
|
1389 |
MarkTileDirtyByTile(tile); |
|
1103
530d0a75f91c
(svn r1604) Fix: [ 1105112 ] Destroyed train locks crossings
dominik
parents:
1095
diff
changeset
|
1390 |
} |
530d0a75f91c
(svn r1604) Fix: [ 1105112 ] Destroyed train locks crossings
dominik
parents:
1095
diff
changeset
|
1391 |
} |
530d0a75f91c
(svn r1604) Fix: [ 1105112 ] Destroyed train locks crossings
dominik
parents:
1095
diff
changeset
|
1392 |
|
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1393 |
/** |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1394 |
* Advances wagons for train reversing, needed for variable length wagons. |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1395 |
* Needs to be called once before the train is reversed, and once after it. |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1396 |
* @param v First vehicle in chain |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1397 |
* @param before Set to true for the call before reversing, false otherwise |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1398 |
*/ |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1399 |
static void AdvanceWagons(Vehicle *v, bool before) |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1400 |
{ |
2639 | 1401 |
Vehicle* base; |
1402 |
Vehicle* first; |
|
1403 |
int length; |
|
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1404 |
|
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1405 |
base = v; |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1406 |
first = base->next; |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1407 |
length = CountVehiclesInChain(v); |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1408 |
|
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1409 |
while (length > 2) { |
2639 | 1410 |
Vehicle* last; |
1411 |
int differential; |
|
1412 |
int i; |
|
1413 |
||
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1414 |
// find pairwise matching wagon |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1415 |
// start<>end, start+1<>end-1, ... */ |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1416 |
last = first; |
2639 | 1417 |
for (i = length - 3; i > 0; i--) last = last->next; |
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1418 |
|
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1419 |
differential = last->u.rail.cached_veh_length - base->u.rail.cached_veh_length; |
2639 | 1420 |
if (before) differential *= -1; |
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1421 |
|
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1422 |
if (differential > 0) { |
2639 | 1423 |
Vehicle* tempnext; |
1424 |
||
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1425 |
// disconnect last car to make sure only this subset moves |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1426 |
tempnext = last->next; |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1427 |
last->next = NULL; |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1428 |
|
2639 | 1429 |
for (i = 0; i < differential; i++) TrainController(first); |
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1430 |
|
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1431 |
last->next = tempnext; |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1432 |
} |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1433 |
|
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1434 |
base = first; |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1435 |
first = first->next; |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1436 |
length -= 2; |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1437 |
} |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1438 |
} |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1439 |
|
2630 | 1440 |
static TileIndex GetVehicleTileOutOfTunnel(const Vehicle* v, bool reverse) |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1441 |
{ |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1442 |
TileIndex tile; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1443 |
byte direction = (!reverse) ? DirToDiagdir(v->direction) : ReverseDiagdir(v->direction >> 1); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1444 |
TileIndexDiff delta = TileOffsByDir(direction); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1445 |
|
2639 | 1446 |
if (v->u.rail.track != 0x40) return v->tile; |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1447 |
|
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1448 |
for (tile = v->tile;; tile += delta) { |
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2484
diff
changeset
|
1449 |
if (IsTunnelTile(tile) && GB(_m[tile].m5, 0, 2) != direction && GetTileZ(tile) == v->z_pos) |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1450 |
break; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1451 |
} |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1452 |
return tile; |
2182 | 1453 |
} |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1454 |
|
0 | 1455 |
static void ReverseTrainDirection(Vehicle *v) |
1456 |
{ |
|
1457 |
int l = 0, r = -1; |
|
1458 |
Vehicle *u; |
|
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1459 |
TileIndex tile; |
2115
99198b563a9c
(svn r2625) - Fix: [pbs] Store the end of a train's reserved path explicitly. Prevents trains from unreserving eachothers paths in some cases.
hackykid
parents:
2049
diff
changeset
|
1460 |
Trackdir trackdir; |
99198b563a9c
(svn r2625) - Fix: [pbs] Store the end of a train's reserved path explicitly. Prevents trains from unreserving eachothers paths in some cases.
hackykid
parents:
2049
diff
changeset
|
1461 |
TileIndex pbs_end_tile = v->u.rail.pbs_end_tile; // these may be changed, and we may need |
99198b563a9c
(svn r2625) - Fix: [pbs] Store the end of a train's reserved path explicitly. Prevents trains from unreserving eachothers paths in some cases.
hackykid
parents:
2049
diff
changeset
|
1462 |
Trackdir pbs_end_trackdir = v->u.rail.pbs_end_trackdir; // the old values, so cache them |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1463 |
|
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1464 |
u = GetLastVehicleInChain(v); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1465 |
tile = GetVehicleTileOutOfTunnel(u, false); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1466 |
trackdir = ReverseTrackdir(GetVehicleTrackdir(u)); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1467 |
|
2115
99198b563a9c
(svn r2625) - Fix: [pbs] Store the end of a train's reserved path explicitly. Prevents trains from unreserving eachothers paths in some cases.
hackykid
parents:
2049
diff
changeset
|
1468 |
if (PBSTileReserved(tile) & (1 << TrackdirToTrack(trackdir))) { |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1469 |
NPFFindStationOrTileData fstd; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1470 |
NPFFoundTargetData ftd; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1471 |
|
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1472 |
NPFFillWithOrderData(&fstd, v); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1473 |
|
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1474 |
tile = GetVehicleTileOutOfTunnel(u, true); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1475 |
|
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1476 |
DEBUG(pbs, 2) ("pbs: (%i) choose reverse (RV), tile:%x, trackdir:%i",v->unitnumber, u->tile, trackdir); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1477 |
ftd = NPFRouteToStationOrTile(tile, trackdir, &fstd, TRANSPORT_RAIL, v->owner, v->u.rail.railtype, PBS_MODE_ANY); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1478 |
|
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1479 |
if (ftd.best_trackdir == 0xFF) { |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1480 |
DEBUG(pbs, 0) ("pbs: (%i) no nodes encountered (RV)", v->unitnumber); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1481 |
CLRBIT(v->u.rail.flags, VRF_REVERSING); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1482 |
return; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1483 |
} |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1484 |
|
2639 | 1485 |
// we found a way out of the pbs block |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1486 |
if (NPFGetFlag(&ftd.node, NPF_FLAG_PBS_EXIT)) { |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1487 |
if (NPFGetFlag(&ftd.node, NPF_FLAG_PBS_BLOCKED)) { |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1488 |
CLRBIT(v->u.rail.flags, VRF_REVERSING); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1489 |
return; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1490 |
} |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1491 |
} |
2115
99198b563a9c
(svn r2625) - Fix: [pbs] Store the end of a train's reserved path explicitly. Prevents trains from unreserving eachothers paths in some cases.
hackykid
parents:
2049
diff
changeset
|
1492 |
|
99198b563a9c
(svn r2625) - Fix: [pbs] Store the end of a train's reserved path explicitly. Prevents trains from unreserving eachothers paths in some cases.
hackykid
parents:
2049
diff
changeset
|
1493 |
v->u.rail.pbs_end_tile = ftd.node.tile; |
99198b563a9c
(svn r2625) - Fix: [pbs] Store the end of a train's reserved path explicitly. Prevents trains from unreserving eachothers paths in some cases.
hackykid
parents:
2049
diff
changeset
|
1494 |
v->u.rail.pbs_end_trackdir = ftd.node.direction; |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1495 |
} |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1496 |
|
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1497 |
tile = GetVehicleTileOutOfTunnel(v, false); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1498 |
trackdir = GetVehicleTrackdir(v); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1499 |
|
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1500 |
if (v->u.rail.pbs_status == PBS_STAT_HAS_PATH) { |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1501 |
TileIndex tile = AddTileIndexDiffCWrap(v->tile, TileIndexDiffCByDir(TrackdirToExitdir(trackdir))); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1502 |
uint32 ts; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1503 |
assert(tile != INVALID_TILE); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1504 |
ts = GetTileTrackStatus(tile, TRANSPORT_RAIL); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1505 |
ts &= TrackdirReachesTrackdirs(trackdir); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1506 |
assert(ts != 0 && KillFirstBit2x64(ts) == 0); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1507 |
trackdir = FindFirstBit2x64(ts); |
2115
99198b563a9c
(svn r2625) - Fix: [pbs] Store the end of a train's reserved path explicitly. Prevents trains from unreserving eachothers paths in some cases.
hackykid
parents:
2049
diff
changeset
|
1508 |
PBSClearPath(tile, trackdir, pbs_end_tile, pbs_end_trackdir); |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1509 |
v->u.rail.pbs_status = PBS_STAT_NONE; |
2115
99198b563a9c
(svn r2625) - Fix: [pbs] Store the end of a train's reserved path explicitly. Prevents trains from unreserving eachothers paths in some cases.
hackykid
parents:
2049
diff
changeset
|
1510 |
} else if (PBSTileReserved(tile) & (1 << TrackdirToTrack(trackdir))) { |
99198b563a9c
(svn r2625) - Fix: [pbs] Store the end of a train's reserved path explicitly. Prevents trains from unreserving eachothers paths in some cases.
hackykid
parents:
2049
diff
changeset
|
1511 |
PBSClearPath(tile, trackdir, pbs_end_tile, pbs_end_trackdir); |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1512 |
if (v->u.rail.track != 0x40) |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1513 |
PBSReserveTrack(tile, trackdir & 7); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1514 |
}; |
0 | 1515 |
|
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
1516 |
if (IsTileDepotType(v->tile, TRANSPORT_RAIL)) |
0 | 1517 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
1518 |
||
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1519 |
|
743
da4d304b52d2
(svn r1199) -Fix: [ 958098 ] No longer road/rail crossing signals hang when a train
truelight
parents:
742
diff
changeset
|
1520 |
/* Check if we were approaching a rail/road-crossing */ |
da4d304b52d2
(svn r1199) -Fix: [ 958098 ] No longer road/rail crossing signals hang when a train
truelight
parents:
742
diff
changeset
|
1521 |
{ |
da4d304b52d2
(svn r1199) -Fix: [ 958098 ] No longer road/rail crossing signals hang when a train
truelight
parents:
742
diff
changeset
|
1522 |
TileIndex tile = v->tile; |
da4d304b52d2
(svn r1199) -Fix: [ 958098 ] No longer road/rail crossing signals hang when a train
truelight
parents:
742
diff
changeset
|
1523 |
int t; |
1459
19333d7f99b3
(svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents:
1455
diff
changeset
|
1524 |
/* Determine the diagonal direction in which we will exit this tile */ |
743
da4d304b52d2
(svn r1199) -Fix: [ 958098 ] No longer road/rail crossing signals hang when a train
truelight
parents:
742
diff
changeset
|
1525 |
t = v->direction >> 1; |
da4d304b52d2
(svn r1199) -Fix: [ 958098 ] No longer road/rail crossing signals hang when a train
truelight
parents:
742
diff
changeset
|
1526 |
if (!(v->direction & 1) && v->u.rail.track != _state_dir_table[t]) { |
da4d304b52d2
(svn r1199) -Fix: [ 958098 ] No longer road/rail crossing signals hang when a train
truelight
parents:
742
diff
changeset
|
1527 |
t = (t - 1) & 3; |
da4d304b52d2
(svn r1199) -Fix: [ 958098 ] No longer road/rail crossing signals hang when a train
truelight
parents:
742
diff
changeset
|
1528 |
} |
da4d304b52d2
(svn r1199) -Fix: [ 958098 ] No longer road/rail crossing signals hang when a train
truelight
parents:
742
diff
changeset
|
1529 |
/* Calculate next tile */ |
900 | 1530 |
tile += TileOffsByDir(t); |
1103
530d0a75f91c
(svn r1604) Fix: [ 1105112 ] Destroyed train locks crossings
dominik
parents:
1095
diff
changeset
|
1531 |
|
530d0a75f91c
(svn r1604) Fix: [ 1105112 ] Destroyed train locks crossings
dominik
parents:
1095
diff
changeset
|
1532 |
/* Check if the train left a rail/road-crossing */ |
530d0a75f91c
(svn r1604) Fix: [ 1105112 ] Destroyed train locks crossings
dominik
parents:
1095
diff
changeset
|
1533 |
DisableTrainCrossing(tile); |
743
da4d304b52d2
(svn r1199) -Fix: [ 958098 ] No longer road/rail crossing signals hang when a train
truelight
parents:
742
diff
changeset
|
1534 |
} |
da4d304b52d2
(svn r1199) -Fix: [ 958098 ] No longer road/rail crossing signals hang when a train
truelight
parents:
742
diff
changeset
|
1535 |
|
0 | 1536 |
// count number of vehicles |
1537 |
u = v; |
|
1538 |
do r++; while ( (u = u->next) != NULL ); |
|
1539 |
||
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1540 |
AdvanceWagons(v, true); |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1541 |
|
0 | 1542 |
/* swap start<>end, start+1<>end-1, ... */ |
1543 |
do { |
|
1544 |
ReverseTrainSwapVeh(v, l++, r--); |
|
1545 |
} while (l <= r); |
|
1546 |
||
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1547 |
AdvanceWagons(v, false); |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
1548 |
|
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
1549 |
if (IsTileDepotType(v->tile, TRANSPORT_RAIL)) |
0 | 1550 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
1551 |
||
954
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1552 |
CLRBIT(v->u.rail.flags, VRF_REVERSING); |
0 | 1553 |
} |
1554 |
||
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1555 |
/** Reverse train. |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1556 |
* @param x,y unused |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1557 |
* @param p1 train to reverse |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1558 |
* @param p2 unused |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1559 |
*/ |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1560 |
int32 CmdReverseTrainDirection(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
0 | 1561 |
{ |
1562 |
Vehicle *v; |
|
1563 |
||
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1236
diff
changeset
|
1564 |
if (!IsVehicleIndex(p1)) return CMD_ERROR; |
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1236
diff
changeset
|
1565 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
1566 |
v = GetVehicle(p1); |
0 | 1567 |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1568 |
if (v->type != VEH_Train || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 1569 |
|
1570 |
_error_message = STR_EMPTY; |
|
1571 |
||
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
1572 |
// if (v->u.rail.track & 0x80 || IsTileDepotType(v->tile, TRANSPORT_RAIL)) |
0 | 1573 |
// return CMD_ERROR; |
1574 |
||
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1575 |
if (v->u.rail.crash_anim_pos != 0 || v->breakdown_ctr != 0) return CMD_ERROR; |
0 | 1576 |
|
1577 |
if (flags & DC_EXEC) { |
|
1578 |
if (_patches.realistic_acceleration && v->cur_speed != 0) { |
|
954
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
1579 |
TOGGLEBIT(v->u.rail.flags, VRF_REVERSING); |
0 | 1580 |
} else { |
1581 |
v->cur_speed = 0; |
|
1582 |
SetLastSpeed(v, 0); |
|
1583 |
ReverseTrainDirection(v); |
|
1584 |
} |
|
1585 |
} |
|
1586 |
return 0; |
|
1587 |
} |
|
1588 |
||
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1589 |
/** Force a train through a red signal |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1590 |
* @param x,y unused |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1591 |
* @param p1 train to ignore the red signal |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1592 |
* @param p2 unused |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1593 |
*/ |
0 | 1594 |
int32 CmdForceTrainProceed(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
1595 |
{ |
|
1596 |
Vehicle *v; |
|
1597 |
||
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1236
diff
changeset
|
1598 |
if (!IsVehicleIndex(p1)) return CMD_ERROR; |
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1236
diff
changeset
|
1599 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
1600 |
v = GetVehicle(p1); |
0 | 1601 |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1602 |
if (v->type != VEH_Train || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 1603 |
|
2639 | 1604 |
if (flags & DC_EXEC) v->u.rail.force_proceed = 0x50; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
1605 |
|
0 | 1606 |
return 0; |
1607 |
} |
|
1608 |
||
1802
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1794
diff
changeset
|
1609 |
/** Refits a train to the specified cargo type. |
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1794
diff
changeset
|
1610 |
* @param x,y unused |
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1794
diff
changeset
|
1611 |
* @param p1 vehicle ID of the train to refit |
2244 | 1612 |
* @param p2 the new cargo type to refit to (p2 & 0xFF) |
1802
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1794
diff
changeset
|
1613 |
*/ |
0 | 1614 |
int32 CmdRefitRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
1615 |
{ |
|
2635 | 1616 |
CargoID new_cid = GB(p2, 0, 8); |
0 | 1617 |
Vehicle *v; |
1618 |
int32 cost; |
|
1619 |
uint num; |
|
842 | 1620 |
|
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1236
diff
changeset
|
1621 |
if (!IsVehicleIndex(p1)) return CMD_ERROR; |
915 | 1622 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
1623 |
v = GetVehicle(p1); |
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1236
diff
changeset
|
1624 |
|
1802
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1794
diff
changeset
|
1625 |
if (v->type != VEH_Train || !CheckOwnership(v->owner)) return CMD_ERROR; |
2244 | 1626 |
if (CheckTrainStoppedInDepot(v) < 0) return_cmd_error(STR_TRAIN_MUST_BE_STOPPED); |
1802
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1794
diff
changeset
|
1627 |
|
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1794
diff
changeset
|
1628 |
/* Check cargo */ |
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1794
diff
changeset
|
1629 |
if (new_cid > NUM_CARGO) return CMD_ERROR; |
0 | 1630 |
|
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1236
diff
changeset
|
1631 |
SET_EXPENSES_TYPE(EXPENSES_TRAIN_RUN); |
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1236
diff
changeset
|
1632 |
|
0 | 1633 |
cost = 0; |
1634 |
num = 0; |
|
915 | 1635 |
|
0 | 1636 |
do { |
491
6527219352cd
(svn r773) When refitting a train engine, refit also all the attached wagons which can be refitted (applicable to DBSetXL, as shown in http://pasky.or.cz/~pasky/dev/openttd/screenshots/wagrefit.png). This is how TTDPatch does it, pointed out by Bjarni.
pasky
parents:
445
diff
changeset
|
1637 |
/* XXX: We also refit all the attached wagons en-masse if they |
6527219352cd
(svn r773) When refitting a train engine, refit also all the attached wagons which can be refitted (applicable to DBSetXL, as shown in http://pasky.or.cz/~pasky/dev/openttd/screenshots/wagrefit.png). This is how TTDPatch does it, pointed out by Bjarni.
pasky
parents:
445
diff
changeset
|
1638 |
* can be refitted. This is how TTDPatch does it. TODO: Have |
6527219352cd
(svn r773) When refitting a train engine, refit also all the attached wagons which can be refitted (applicable to DBSetXL, as shown in http://pasky.or.cz/~pasky/dev/openttd/screenshots/wagrefit.png). This is how TTDPatch does it, pointed out by Bjarni.
pasky
parents:
445
diff
changeset
|
1639 |
* some nice [Refit] button near each wagon. --pasky */ |
1802
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1794
diff
changeset
|
1640 |
if (!CanRefitTo(v, new_cid)) continue; |
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1794
diff
changeset
|
1641 |
|
1859
870dcb6fd65b
(svn r2365) - Change: [refitting] Make refitting capacities for trains newgrf compatible. Train vehicles can now carry twice as much mail/goods as other cargo, and four times as much passengers.
hackykid
parents:
1842
diff
changeset
|
1642 |
if (v->cargo_cap != 0) { |
2463
db029c987bc7
(svn r2989) - Make engine/vehicle information tables constant. Duplicate them so NewGRF data can be loaded without wiping out the default data.
peter1138
parents:
2456
diff
changeset
|
1643 |
const RailVehicleInfo *rvi = RailVehInfo(v->engine_type); |
1895
0d499b71a782
(svn r2401) - Fix: [newgrf] Finish up callback mechanism, implement 'refit capacity' callback slightly more correct.
hackykid
parents:
1891
diff
changeset
|
1644 |
uint16 amount = CALLBACK_FAILED; |
0d499b71a782
(svn r2401) - Fix: [newgrf] Finish up callback mechanism, implement 'refit capacity' callback slightly more correct.
hackykid
parents:
1891
diff
changeset
|
1645 |
|
0d499b71a782
(svn r2401) - Fix: [newgrf] Finish up callback mechanism, implement 'refit capacity' callback slightly more correct.
hackykid
parents:
1891
diff
changeset
|
1646 |
if (HASBIT(rvi->callbackmask, CBM_REFIT_CAP)) { |
0d499b71a782
(svn r2401) - Fix: [newgrf] Finish up callback mechanism, implement 'refit capacity' callback slightly more correct.
hackykid
parents:
1891
diff
changeset
|
1647 |
/* Check the 'refit capacity' callback */ |
0d499b71a782
(svn r2401) - Fix: [newgrf] Finish up callback mechanism, implement 'refit capacity' callback slightly more correct.
hackykid
parents:
1891
diff
changeset
|
1648 |
CargoID temp_cid = v->cargo_type; |
0d499b71a782
(svn r2401) - Fix: [newgrf] Finish up callback mechanism, implement 'refit capacity' callback slightly more correct.
hackykid
parents:
1891
diff
changeset
|
1649 |
v->cargo_type = new_cid; |
0d499b71a782
(svn r2401) - Fix: [newgrf] Finish up callback mechanism, implement 'refit capacity' callback slightly more correct.
hackykid
parents:
1891
diff
changeset
|
1650 |
amount = GetCallBackResult(CBID_REFIT_CAP, v->engine_type, v); |
0d499b71a782
(svn r2401) - Fix: [newgrf] Finish up callback mechanism, implement 'refit capacity' callback slightly more correct.
hackykid
parents:
1891
diff
changeset
|
1651 |
v->cargo_type = temp_cid; |
0d499b71a782
(svn r2401) - Fix: [newgrf] Finish up callback mechanism, implement 'refit capacity' callback slightly more correct.
hackykid
parents:
1891
diff
changeset
|
1652 |
} |
0d499b71a782
(svn r2401) - Fix: [newgrf] Finish up callback mechanism, implement 'refit capacity' callback slightly more correct.
hackykid
parents:
1891
diff
changeset
|
1653 |
|
0d499b71a782
(svn r2401) - Fix: [newgrf] Finish up callback mechanism, implement 'refit capacity' callback slightly more correct.
hackykid
parents:
1891
diff
changeset
|
1654 |
if (amount == CALLBACK_FAILED) { // callback failed or not used, use default |
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1882
diff
changeset
|
1655 |
CargoID old_cid = rvi->cargo_type; |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1882
diff
changeset
|
1656 |
/* normally, the capacity depends on the cargo type, a rail vehicle |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1882
diff
changeset
|
1657 |
* can carry twice as much mail/goods as normal cargo, |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1882
diff
changeset
|
1658 |
* and four times as much passengers */ |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1882
diff
changeset
|
1659 |
amount = rvi->capacity; |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1882
diff
changeset
|
1660 |
(old_cid == CT_PASSENGERS) || |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1882
diff
changeset
|
1661 |
(amount <<= 1, old_cid == CT_MAIL || old_cid == CT_GOODS) || |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1882
diff
changeset
|
1662 |
(amount <<= 1, true); |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1882
diff
changeset
|
1663 |
(new_cid == CT_PASSENGERS) || |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1882
diff
changeset
|
1664 |
(amount >>= 1, new_cid == CT_MAIL || new_cid == CT_GOODS) || |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1882
diff
changeset
|
1665 |
(amount >>= 1, true); |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1882
diff
changeset
|
1666 |
}; |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1882
diff
changeset
|
1667 |
|
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1882
diff
changeset
|
1668 |
if (amount != 0) { |
2639 | 1669 |
if (new_cid != v->cargo_type) cost += _price.build_railvehicle >> 8; |
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1882
diff
changeset
|
1670 |
num += amount; |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1882
diff
changeset
|
1671 |
if (flags & DC_EXEC) { |
2244 | 1672 |
v->cargo_count = 0; |
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1882
diff
changeset
|
1673 |
v->cargo_type = new_cid; |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1882
diff
changeset
|
1674 |
v->cargo_cap = amount; |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1882
diff
changeset
|
1675 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1882
diff
changeset
|
1676 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1882
diff
changeset
|
1677 |
} |
0 | 1678 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
1679 |
} |
2244 | 1680 |
} while ( (v=v->next) != NULL ); |
0 | 1681 |
|
1682 |
_returned_refit_amount = num; |
|
1683 |
||
1684 |
return cost; |
|
1685 |
} |
|
1686 |
||
1687 |
typedef struct TrainFindDepotData { |
|
1688 |
uint best_length; |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1969
diff
changeset
|
1689 |
TileIndex tile; |
2475 | 1690 |
PlayerID owner; |
1777
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1770
diff
changeset
|
1691 |
/** |
2639 | 1692 |
* true if reversing is necessary for the train to get to this depot |
1693 |
* This value is unused when new depot finding and NPF are both disabled |
|
1777
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1770
diff
changeset
|
1694 |
*/ |
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1770
diff
changeset
|
1695 |
bool reverse; |
0 | 1696 |
} TrainFindDepotData; |
1697 |
||
2125
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2115
diff
changeset
|
1698 |
static bool NtpCallbFindDepot(TileIndex tile, TrainFindDepotData *tfdd, int track, uint length) |
0 | 1699 |
{ |
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1895
diff
changeset
|
1700 |
if (IsTileType(tile, MP_RAILWAY) && IsTileOwner(tile, tfdd->owner)) { |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2044
diff
changeset
|
1701 |
if ((_m[tile].m5 & ~0x3) == 0xC0) { |
2125
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2115
diff
changeset
|
1702 |
tfdd->best_length = length; |
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2115
diff
changeset
|
1703 |
tfdd->tile = tile; |
0 | 1704 |
return true; |
1705 |
} |
|
1706 |
} |
|
1707 |
||
2125
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2115
diff
changeset
|
1708 |
return false; |
0 | 1709 |
} |
1710 |
||
1758
2158a0938e45
(svn r2262) - Fix: Assertion when vehicle in a depot wants to do pathfinding.
matthijs
parents:
1757
diff
changeset
|
1711 |
// returns the tile of a depot to goto to. The given vehicle must not be |
2158a0938e45
(svn r2262) - Fix: Assertion when vehicle in a depot wants to do pathfinding.
matthijs
parents:
1757
diff
changeset
|
1712 |
// crashed! |
308
8088f72d10f5
(svn r314) -Fix: [982611] Pathfinding bug; train likes the roundabout. If train needs servicing it will now look 16 tiles along the track instead of 12 tiles manhattan style (blathijs)
darkvater
parents:
300
diff
changeset
|
1713 |
static TrainFindDepotData FindClosestTrainDepot(Vehicle *v) |
0 | 1714 |
{ |
1715 |
int i; |
|
1716 |
TrainFindDepotData tfdd; |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1969
diff
changeset
|
1717 |
TileIndex tile = v->tile; |
0 | 1718 |
|
1758
2158a0938e45
(svn r2262) - Fix: Assertion when vehicle in a depot wants to do pathfinding.
matthijs
parents:
1757
diff
changeset
|
1719 |
assert(!(v->vehstatus & VS_CRASHED)); |
2158a0938e45
(svn r2262) - Fix: Assertion when vehicle in a depot wants to do pathfinding.
matthijs
parents:
1757
diff
changeset
|
1720 |
|
308
8088f72d10f5
(svn r314) -Fix: [982611] Pathfinding bug; train likes the roundabout. If train needs servicing it will now look 16 tiles along the track instead of 12 tiles manhattan style (blathijs)
darkvater
parents:
300
diff
changeset
|
1721 |
tfdd.owner = v->owner; |
8088f72d10f5
(svn r314) -Fix: [982611] Pathfinding bug; train likes the roundabout. If train needs servicing it will now look 16 tiles along the track instead of 12 tiles manhattan style (blathijs)
darkvater
parents:
300
diff
changeset
|
1722 |
tfdd.best_length = (uint)-1; |
1777
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1770
diff
changeset
|
1723 |
tfdd.reverse = false; |
308
8088f72d10f5
(svn r314) -Fix: [982611] Pathfinding bug; train likes the roundabout. If train needs servicing it will now look 16 tiles along the track instead of 12 tiles manhattan style (blathijs)
darkvater
parents:
300
diff
changeset
|
1724 |
|
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
1725 |
if (IsTileDepotType(tile, TRANSPORT_RAIL)){ |
308
8088f72d10f5
(svn r314) -Fix: [982611] Pathfinding bug; train likes the roundabout. If train needs servicing it will now look 16 tiles along the track instead of 12 tiles manhattan style (blathijs)
darkvater
parents:
300
diff
changeset
|
1726 |
tfdd.tile = tile; |
8088f72d10f5
(svn r314) -Fix: [982611] Pathfinding bug; train likes the roundabout. If train needs servicing it will now look 16 tiles along the track instead of 12 tiles manhattan style (blathijs)
darkvater
parents:
300
diff
changeset
|
1727 |
tfdd.best_length = 0; |
8088f72d10f5
(svn r314) -Fix: [982611] Pathfinding bug; train likes the roundabout. If train needs servicing it will now look 16 tiles along the track instead of 12 tiles manhattan style (blathijs)
darkvater
parents:
300
diff
changeset
|
1728 |
return tfdd; |
8088f72d10f5
(svn r314) -Fix: [982611] Pathfinding bug; train likes the roundabout. If train needs servicing it will now look 16 tiles along the track instead of 12 tiles manhattan style (blathijs)
darkvater
parents:
300
diff
changeset
|
1729 |
} |
0 | 1730 |
|
2549 | 1731 |
if (v->u.rail.track == 0x40) tile = GetVehicleOutOfTunnelTile(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
1732 |
|
1247 | 1733 |
if (_patches.new_pathfinding_all) { |
1734 |
NPFFoundTargetData ftd; |
|
1777
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1770
diff
changeset
|
1735 |
Vehicle* last = GetLastVehicleInChain(v); |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1935
diff
changeset
|
1736 |
Trackdir trackdir = GetVehicleTrackdir(v); |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1935
diff
changeset
|
1737 |
Trackdir trackdir_rev = ReverseTrackdir(GetVehicleTrackdir(last)); |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1935
diff
changeset
|
1738 |
|
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1935
diff
changeset
|
1739 |
assert (trackdir != INVALID_TRACKDIR); |
2006
9d5d7fd428c2
(svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents:
1998
diff
changeset
|
1740 |
ftd = NPFRouteToDepotBreadthFirstTwoWay(v->tile, trackdir, last->tile, trackdir_rev, TRANSPORT_RAIL, v->owner, v->u.rail.railtype, NPF_INFINITE_PENALTY); |
1247 | 1741 |
if (ftd.best_bird_dist == 0) { |
1742 |
/* Found target */ |
|
1743 |
tfdd.tile = ftd.node.tile; |
|
1675
dd557a4d108d
(svn r2179) - Fix: [ 1121437, 1114228 ] Vehicles not entering depots for auto servicing.
matthijs
parents:
1615
diff
changeset
|
1744 |
/* Our caller expects a number of tiles, so we just approximate that |
dd557a4d108d
(svn r2179) - Fix: [ 1121437, 1114228 ] Vehicles not entering depots for auto servicing.
matthijs
parents:
1615
diff
changeset
|
1745 |
* number by this. It might not be completely what we want, but it will |
dd557a4d108d
(svn r2179) - Fix: [ 1121437, 1114228 ] Vehicles not entering depots for auto servicing.
matthijs
parents:
1615
diff
changeset
|
1746 |
* work for now :-) We can possibly change this when the old pathfinder |
dd557a4d108d
(svn r2179) - Fix: [ 1121437, 1114228 ] Vehicles not entering depots for auto servicing.
matthijs
parents:
1615
diff
changeset
|
1747 |
* is removed. */ |
1777
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1770
diff
changeset
|
1748 |
tfdd.best_length = ftd.best_path_dist / NPF_TILE_LENGTH; |
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1770
diff
changeset
|
1749 |
if (NPFGetFlag(&ftd.node, NPF_FLAG_REVERSE)) |
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1770
diff
changeset
|
1750 |
tfdd.reverse = true; |
1247 | 1751 |
} |
0 | 1752 |
} else { |
1753 |
// search in the forward direction first. |
|
1754 |
i = v->direction >> 1; |
|
2639 | 1755 |
if (!(v->direction & 1) && v->u.rail.track != _state_dir_table[i]) i = (i - 1) & 3; |
2125
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2115
diff
changeset
|
1756 |
NewTrainPathfind(tile, 0, i, (NTPEnumProc*)NtpCallbFindDepot, &tfdd); |
308
8088f72d10f5
(svn r314) -Fix: [982611] Pathfinding bug; train likes the roundabout. If train needs servicing it will now look 16 tiles along the track instead of 12 tiles manhattan style (blathijs)
darkvater
parents:
300
diff
changeset
|
1757 |
if (tfdd.best_length == (uint)-1){ |
1777
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1770
diff
changeset
|
1758 |
tfdd.reverse = true; |
308
8088f72d10f5
(svn r314) -Fix: [982611] Pathfinding bug; train likes the roundabout. If train needs servicing it will now look 16 tiles along the track instead of 12 tiles manhattan style (blathijs)
darkvater
parents:
300
diff
changeset
|
1759 |
// search in backwards direction |
8088f72d10f5
(svn r314) -Fix: [982611] Pathfinding bug; train likes the roundabout. If train needs servicing it will now look 16 tiles along the track instead of 12 tiles manhattan style (blathijs)
darkvater
parents:
300
diff
changeset
|
1760 |
i = (v->direction^4) >> 1; |
2639 | 1761 |
if (!(v->direction & 1) && v->u.rail.track != _state_dir_table[i]) i = (i - 1) & 3; |
2125
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2115
diff
changeset
|
1762 |
NewTrainPathfind(tile, 0, i, (NTPEnumProc*)NtpCallbFindDepot, &tfdd); |
308
8088f72d10f5
(svn r314) -Fix: [982611] Pathfinding bug; train likes the roundabout. If train needs servicing it will now look 16 tiles along the track instead of 12 tiles manhattan style (blathijs)
darkvater
parents:
300
diff
changeset
|
1763 |
} |
0 | 1764 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
1765 |
|
308
8088f72d10f5
(svn r314) -Fix: [982611] Pathfinding bug; train likes the roundabout. If train needs servicing it will now look 16 tiles along the track instead of 12 tiles manhattan style (blathijs)
darkvater
parents:
300
diff
changeset
|
1766 |
return tfdd; |
0 | 1767 |
} |
1768 |
||
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1769 |
/** Send a train to a depot |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1770 |
* @param x,y unused |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1771 |
* @param p1 train to send to the depot |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1772 |
* @param p2 unused |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1773 |
*/ |
1794
24b4239f2090
(svn r2298) - CodeChange: removed CmdAbuses: CmdSetTownNameType(), CmdStartNewGame(), CmdCreateScenario(), CmdSetNewLandscapeType() and CmdGenRandomNewGame().
Darkvater
parents:
1790
diff
changeset
|
1774 |
int32 CmdSendTrainToDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
0 | 1775 |
{ |
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1236
diff
changeset
|
1776 |
Vehicle *v; |
308
8088f72d10f5
(svn r314) -Fix: [982611] Pathfinding bug; train likes the roundabout. If train needs servicing it will now look 16 tiles along the track instead of 12 tiles manhattan style (blathijs)
darkvater
parents:
300
diff
changeset
|
1777 |
TrainFindDepotData tfdd; |
0 | 1778 |
|
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1236
diff
changeset
|
1779 |
if (!IsVehicleIndex(p1)) return CMD_ERROR; |
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1236
diff
changeset
|
1780 |
|
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1236
diff
changeset
|
1781 |
v = GetVehicle(p1); |
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1236
diff
changeset
|
1782 |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1783 |
if (v->type != VEH_Train || !CheckOwnership(v->owner)) return CMD_ERROR; |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1784 |
|
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1779
diff
changeset
|
1785 |
if (v->vehstatus & VS_CRASHED) return CMD_ERROR; |
1757
89f63a75ffd2
(svn r2261) - Fix: When crashed vehicles try to find a depot for servicing, openttd asserts.
matthijs
parents:
1752
diff
changeset
|
1786 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1787 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
0 | 1788 |
if (flags & DC_EXEC) { |
1615
24c6310f887b
(svn r2119) - Fix: [ 1172878 ] Trains "Go to depot" button: click twice skip to next order (patch by Loic GUILLOUX). I also added short explanation of OF_/OFB_ difference to order.h.
pasky
parents:
1601
diff
changeset
|
1789 |
if (HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) { |
0 | 1790 |
v->u.rail.days_since_order_progr = 0; |
1791 |
v->cur_order_index++; |
|
1792 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
1793 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1794 |
v->current_order.type = OT_DUMMY; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1795 |
v->current_order.flags = 0; |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
744
diff
changeset
|
1796 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1797 |
} |
1798 |
return 0; |
|
1799 |
} |
|
1800 |
||
308
8088f72d10f5
(svn r314) -Fix: [982611] Pathfinding bug; train likes the roundabout. If train needs servicing it will now look 16 tiles along the track instead of 12 tiles manhattan style (blathijs)
darkvater
parents:
300
diff
changeset
|
1801 |
tfdd = FindClosestTrainDepot(v); |
8088f72d10f5
(svn r314) -Fix: [982611] Pathfinding bug; train likes the roundabout. If train needs servicing it will now look 16 tiles along the track instead of 12 tiles manhattan style (blathijs)
darkvater
parents:
300
diff
changeset
|
1802 |
if (tfdd.best_length == (uint)-1) |
0 | 1803 |
return_cmd_error(STR_883A_UNABLE_TO_FIND_ROUTE_TO); |
1804 |
||
1805 |
if (flags & DC_EXEC) { |
|
308
8088f72d10f5
(svn r314) -Fix: [982611] Pathfinding bug; train likes the roundabout. If train needs servicing it will now look 16 tiles along the track instead of 12 tiles manhattan style (blathijs)
darkvater
parents:
300
diff
changeset
|
1806 |
v->dest_tile = tfdd.tile; |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1807 |
v->current_order.type = OT_GOTO_DEPOT; |
1520
d88442095697
(svn r2024) -Fix: [autoreplace] reverted all changes involving v->set_for_replacement as they caused desyncs.
bjarni
parents:
1507
diff
changeset
|
1808 |
v->current_order.flags = OF_NON_STOP | OF_FULL_LOAD; |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
1809 |
v->current_order.station = GetDepotByTile(tfdd.tile)->index; |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
744
diff
changeset
|
1810 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
1777
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1770
diff
changeset
|
1811 |
/* If there is no depot in front, reverse automatically */ |
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1770
diff
changeset
|
1812 |
if (tfdd.reverse) |
f703cf05b5b9
(svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents:
1770
diff
changeset
|
1813 |
DoCommandByTile(v->tile, v->index, 0, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION); |
0 | 1814 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
1815 |
|
0 | 1816 |
return 0; |
1817 |
} |
|
1818 |
||
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1784
diff
changeset
|
1819 |
/** Change the service interval for trains. |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1784
diff
changeset
|
1820 |
* @param x,y unused |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1784
diff
changeset
|
1821 |
* @param p1 vehicle ID that is being service-interval-changed |
1790
47963a0cfca3
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1786
diff
changeset
|
1822 |
* @param p2 new service interval |
0 | 1823 |
*/ |
1824 |
int32 CmdChangeTrainServiceInt(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
1825 |
{ |
|
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1236
diff
changeset
|
1826 |
Vehicle *v; |
1790
47963a0cfca3
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1786
diff
changeset
|
1827 |
uint16 serv_int = GetServiceIntervalClamped(p2); /* Double check the service interval from the user-input */ |
47963a0cfca3
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1786
diff
changeset
|
1828 |
|
47963a0cfca3
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1786
diff
changeset
|
1829 |
if (serv_int != p2 || !IsVehicleIndex(p1)) return CMD_ERROR; |
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1236
diff
changeset
|
1830 |
|
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1236
diff
changeset
|
1831 |
v = GetVehicle(p1); |
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1236
diff
changeset
|
1832 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1784
diff
changeset
|
1833 |
if (v->type != VEH_Train || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 1834 |
|
1835 |
if (flags & DC_EXEC) { |
|
1790
47963a0cfca3
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1786
diff
changeset
|
1836 |
v->service_interval = serv_int; |
0 | 1837 |
InvalidateWindowWidget(WC_VEHICLE_DETAILS, v->index, 8); |
1838 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
1839 |
|
0 | 1840 |
return 0; |
1841 |
} |
|
1842 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1087
diff
changeset
|
1843 |
void OnTick_Train(void) |
0 | 1844 |
{ |
1845 |
_age_cargo_skip_counter = (_age_cargo_skip_counter == 0) ? 184 : (_age_cargo_skip_counter - 1); |
|
1846 |
} |
|
1847 |
||
2595
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
1848 |
static const int8 _vehicle_smoke_pos[8] = { |
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
1849 |
1, 1, 1, 0, -1, -1, -1, 0 |
0 | 1850 |
}; |
1851 |
||
2630 | 1852 |
static void HandleLocomotiveSmokeCloud(const Vehicle* v) |
0 | 1853 |
{ |
2630 | 1854 |
const Vehicle* u; |
0 | 1855 |
|
1856 |
if (v->vehstatus & VS_TRAIN_SLOWING || v->load_unload_time_rem != 0 || v->cur_speed < 2) |
|
1857 |
return; |
|
1858 |
||
1859 |
u = v; |
|
1860 |
||
1861 |
do { |
|
2477
225b2916fe2a
(svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents:
2475
diff
changeset
|
1862 |
EngineID engtype = v->engine_type; |
2595
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
1863 |
int effect_offset = GB(v->u.rail.cached_vis_effect, 0, 4) - 8; |
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
1864 |
byte effect_type = GB(v->u.rail.cached_vis_effect, 4, 2); |
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
1865 |
bool disable_effect = HASBIT(v->u.rail.cached_vis_effect, 6); |
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
1866 |
int x, y; |
0 | 1867 |
|
1868 |
// no smoke? |
|
2595
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
1869 |
if ((RailVehInfo(engtype)->flags & RVI_WAGON && effect_type == 0) || |
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
1870 |
disable_effect || |
2519
beb11a5ac48c
(svn r3048) Replace 0/1/2 by RAILTYPE_RAIL/MONO/MAGLEV where appropriate
tron
parents:
2510
diff
changeset
|
1871 |
GetEngine(engtype)->railtype > RAILTYPE_RAIL || |
2639 | 1872 |
v->vehstatus & VS_HIDDEN || |
1873 |
v->u.rail.track & 0xC0) { |
|
0 | 1874 |
continue; |
2639 | 1875 |
} |
0 | 1876 |
|
2612
eccc835aaa44
(svn r3150) Unify some code duplication in HandleLocomotiveSmokeCloud()
peter1138
parents:
2610
diff
changeset
|
1877 |
// No smoke in depots or tunnels |
eccc835aaa44
(svn r3150) Unify some code duplication in HandleLocomotiveSmokeCloud()
peter1138
parents:
2610
diff
changeset
|
1878 |
if (IsTileDepotType(v->tile, TRANSPORT_RAIL) || IsTunnelTile(v->tile)) |
eccc835aaa44
(svn r3150) Unify some code duplication in HandleLocomotiveSmokeCloud()
peter1138
parents:
2610
diff
changeset
|
1879 |
continue; |
eccc835aaa44
(svn r3150) Unify some code duplication in HandleLocomotiveSmokeCloud()
peter1138
parents:
2610
diff
changeset
|
1880 |
|
2595
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
1881 |
if (effect_type == 0) { |
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
1882 |
// Use default effect type for engine class. |
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
1883 |
effect_type = RailVehInfo(engtype)->engclass; |
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
1884 |
} else { |
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
1885 |
effect_type--; |
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
1886 |
} |
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
1887 |
|
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
1888 |
x = _vehicle_smoke_pos[v->direction] * effect_offset; |
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
1889 |
y = _vehicle_smoke_pos[(v->direction + 2) % 8] * effect_offset; |
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
1890 |
|
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
1891 |
switch (effect_type) { |
0 | 1892 |
case 0: |
1893 |
// steam smoke. |
|
2612
eccc835aaa44
(svn r3150) Unify some code duplication in HandleLocomotiveSmokeCloud()
peter1138
parents:
2610
diff
changeset
|
1894 |
if (GB(v->tick_counter, 0, 4) == 0) { |
2595
1c5db200577c
(svn r3132) -NewGRF: support positioning of rail vehicle visual effects.
peter1138
parents:
2587
diff
changeset
|
1895 |
CreateEffectVehicleRel(v, x, y, 10, EV_STEAM_SMOKE); |
0 | 1896 |
} |
1897 |
break; |
|
1898 |
||
1899 |
case 1: |
|
1900 |
// diesel smoke |
|
2637
722dae65c4a8
(svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents:
2635
diff
changeset
|
1901 |
if (u->cur_speed <= 40 && CHANCE16(15, 128)) { |
1359
52782e5cf7c9
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1337
diff
changeset
|
1902 |
CreateEffectVehicleRel(v, 0, 0, 10, EV_DIESEL_SMOKE); |
0 | 1903 |
} |
1904 |
break; |
|
1905 |
||
1906 |
case 2: |
|
1907 |
// blue spark |
|
2637
722dae65c4a8
(svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents:
2635
diff
changeset
|
1908 |
if (GB(v->tick_counter, 0, 2) == 0 && CHANCE16(1, 45)) { |
1359
52782e5cf7c9
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1337
diff
changeset
|
1909 |
CreateEffectVehicleRel(v, 0, 0, 10, EV_ELECTRIC_SPARK); |
0 | 1910 |
} |
1911 |
break; |
|
1912 |
} |
|
2637
722dae65c4a8
(svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents:
2635
diff
changeset
|
1913 |
} while ((v = v->next) != NULL); |
0 | 1914 |
} |
1915 |
||
2549 | 1916 |
static void TrainPlayLeaveStationSound(const Vehicle* v) |
0 | 1917 |
{ |
541 | 1918 |
static const SoundFx sfx[] = { |
1919 |
SND_04_TRAIN, |
|
1920 |
SND_0A_TRAIN_HORN, |
|
1921 |
SND_0A_TRAIN_HORN |
|
1922 |
}; |
|
1923 |
||
2477
225b2916fe2a
(svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents:
2475
diff
changeset
|
1924 |
EngineID engtype = v->engine_type; |
0 | 1925 |
|
1926
530480d14685
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1925
diff
changeset
|
1926 |
switch (GetEngine(engtype)->railtype) { |
2519
beb11a5ac48c
(svn r3048) Replace 0/1/2 by RAILTYPE_RAIL/MONO/MAGLEV where appropriate
tron
parents:
2510
diff
changeset
|
1927 |
case RAILTYPE_RAIL: |
540
2987d7976ea2
(svn r924) Use RailVehInfo() instead of &_rail_vehicle_info[]
tron
parents:
534
diff
changeset
|
1928 |
SndPlayVehicleFx(sfx[RailVehInfo(engtype)->engclass], v); |
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
308
diff
changeset
|
1929 |
break; |
2519
beb11a5ac48c
(svn r3048) Replace 0/1/2 by RAILTYPE_RAIL/MONO/MAGLEV where appropriate
tron
parents:
2510
diff
changeset
|
1930 |
|
beb11a5ac48c
(svn r3048) Replace 0/1/2 by RAILTYPE_RAIL/MONO/MAGLEV where appropriate
tron
parents:
2510
diff
changeset
|
1931 |
case RAILTYPE_MONO: |
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
308
diff
changeset
|
1932 |
SndPlayVehicleFx(SND_47_MAGLEV_2, v); |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
308
diff
changeset
|
1933 |
break; |
2519
beb11a5ac48c
(svn r3048) Replace 0/1/2 by RAILTYPE_RAIL/MONO/MAGLEV where appropriate
tron
parents:
2510
diff
changeset
|
1934 |
|
beb11a5ac48c
(svn r3048) Replace 0/1/2 by RAILTYPE_RAIL/MONO/MAGLEV where appropriate
tron
parents:
2510
diff
changeset
|
1935 |
case RAILTYPE_MAGLEV: |
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
308
diff
changeset
|
1936 |
SndPlayVehicleFx(SND_41_MAGLEV, v); |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
308
diff
changeset
|
1937 |
break; |
0 | 1938 |
} |
1939 |
} |
|
1940 |
||
1941 |
static bool CheckTrainStayInDepot(Vehicle *v) |
|
1942 |
{ |
|
1943 |
Vehicle *u; |
|
495
6b3e2b4fa7c9
(svn r785) -Fix: A train can leave and enter the same depot at the same time, then the trai simply got stuck
tron
parents:
491
diff
changeset
|
1944 |
|
6b3e2b4fa7c9
(svn r785) -Fix: A train can leave and enter the same depot at the same time, then the trai simply got stuck
tron
parents:
491
diff
changeset
|
1945 |
// bail out if not all wagons are in the same depot or not in a depot at all |
2639 | 1946 |
for (u = v; u != NULL; u = u->next) { |
1947 |
if (u->u.rail.track != 0x80 || u->tile != v->tile) return false; |
|
1948 |
} |
|
0 | 1949 |
|
1950 |
if (v->u.rail.force_proceed == 0) { |
|
2634
0df9396b0067
(svn r3176) Use proper types, not some variants of int
tron
parents:
2630
diff
changeset
|
1951 |
Trackdir trackdir = GetVehicleTrackdir(v); |
0df9396b0067
(svn r3176) Use proper types, not some variants of int
tron
parents:
2630
diff
changeset
|
1952 |
|
1151
06c115ce7b7a
(svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents:
1137
diff
changeset
|
1953 |
if (++v->load_unload_time_rem < 37) { |
06c115ce7b7a
(svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents:
1137
diff
changeset
|
1954 |
InvalidateWindowClasses(WC_TRAINS_LIST); |
0 | 1955 |
return true; |
1151
06c115ce7b7a
(svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents:
1137
diff
changeset
|
1956 |
} |
06c115ce7b7a
(svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents:
1137
diff
changeset
|
1957 |
|
0 | 1958 |
v->load_unload_time_rem = 0; |
1959 |
||
2164
5523a9711651
(svn r2674) - CodeChange: [pbs] Generalise the PSBISPbsDepot function so it can check if an arbitrary junction is a pbs junction. Preparations for making pbs more safe.
hackykid
parents:
2163
diff
changeset
|
1960 |
if (PBSIsPbsSegment(v->tile, trackdir)) { |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1961 |
NPFFindStationOrTileData fstd; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1962 |
NPFFoundTargetData ftd; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1963 |
|
2639 | 1964 |
if (PBSTileUnavail(v->tile) & (1 << trackdir)) return true; |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1965 |
|
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1966 |
NPFFillWithOrderData(&fstd, v); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1967 |
|
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1968 |
DEBUG(pbs, 2) ("pbs: (%i) choose depot (DP), tile:%x, trackdir:%i",v->unitnumber, v->tile, trackdir); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1969 |
ftd = NPFRouteToStationOrTile(v->tile, trackdir, &fstd, TRANSPORT_RAIL, v->owner, v->u.rail.railtype, PBS_MODE_GREEN); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1970 |
|
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1971 |
// we found a way out of the pbs block |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1972 |
if (NPFGetFlag(&ftd.node, NPF_FLAG_PBS_EXIT)) { |
2639 | 1973 |
if (NPFGetFlag(&ftd.node, NPF_FLAG_PBS_BLOCKED) || NPFGetFlag(&ftd.node, NPF_FLAG_PBS_RED)) { |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1974 |
return true; |
2639 | 1975 |
} else { |
2115
99198b563a9c
(svn r2625) - Fix: [pbs] Store the end of a train's reserved path explicitly. Prevents trains from unreserving eachothers paths in some cases.
hackykid
parents:
2049
diff
changeset
|
1976 |
v->u.rail.pbs_end_tile = ftd.node.tile; |
99198b563a9c
(svn r2625) - Fix: [pbs] Store the end of a train's reserved path explicitly. Prevents trains from unreserving eachothers paths in some cases.
hackykid
parents:
2049
diff
changeset
|
1977 |
v->u.rail.pbs_end_trackdir = ftd.node.direction; |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1978 |
goto green; |
2115
99198b563a9c
(svn r2625) - Fix: [pbs] Store the end of a train's reserved path explicitly. Prevents trains from unreserving eachothers paths in some cases.
hackykid
parents:
2049
diff
changeset
|
1979 |
} |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1980 |
} |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1981 |
} |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1982 |
|
1151
06c115ce7b7a
(svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents:
1137
diff
changeset
|
1983 |
if (UpdateSignalsOnSegment(v->tile, v->direction)) { |
06c115ce7b7a
(svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents:
1137
diff
changeset
|
1984 |
InvalidateWindowClasses(WC_TRAINS_LIST); |
0 | 1985 |
return true; |
1151
06c115ce7b7a
(svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents:
1137
diff
changeset
|
1986 |
} |
0 | 1987 |
} |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1988 |
green: |
578
1e66514eb621
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
555
diff
changeset
|
1989 |
VehicleServiceInDepot(v); |
1151
06c115ce7b7a
(svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents:
1137
diff
changeset
|
1990 |
InvalidateWindowClasses(WC_TRAINS_LIST); |
0 | 1991 |
TrainPlayLeaveStationSound(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
1992 |
|
0 | 1993 |
v->u.rail.track = 1; |
2639 | 1994 |
if (v->direction & 2) v->u.rail.track = 2; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
1995 |
|
0 | 1996 |
v->vehstatus &= ~VS_HIDDEN; |
1997 |
v->cur_speed = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
1998 |
|
0 | 1999 |
UpdateTrainDeltaXY(v, v->direction); |
2000 |
v->cur_image = GetTrainImage(v, v->direction); |
|
2001 |
VehiclePositionChanged(v); |
|
2002 |
UpdateSignalsOnSegment(v->tile, v->direction); |
|
2003 |
UpdateTrainAcceleration(v); |
|
2004 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
2005 |
||
2006 |
return false; |
|
2007 |
} |
|
2008 |
||
1247 | 2009 |
/* Check for station tiles */ |
0 | 2010 |
typedef struct TrainTrackFollowerData { |
2011 |
TileIndex dest_coords; |
|
1551
b1c7df6daa63
(svn r2055) -CodeChange: Begun introducting StationID
celestar
parents:
1542
diff
changeset
|
2012 |
StationID station_index; // station index we're heading for |
0 | 2013 |
uint best_bird_dist; |
2014 |
uint best_track_dist; |
|
2015 |
byte best_track; |
|
2016 |
} TrainTrackFollowerData; |
|
2017 |
||
2125
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2115
diff
changeset
|
2018 |
static bool NtpCallbFindStation(TileIndex tile, TrainTrackFollowerData *ttfd, int track, uint length) |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1969
diff
changeset
|
2019 |
{ |
0 | 2020 |
// heading for nowhere? |
2021 |
if (ttfd->dest_coords == 0) |
|
2022 |
return false; |
|
2023 |
||
2024 |
// did we reach the final station? |
|
2044
df63b9a7dec3
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2032
diff
changeset
|
2025 |
if ((ttfd->station_index == INVALID_STATION && tile == ttfd->dest_coords) || |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2044
diff
changeset
|
2026 |
(IsTileType(tile, MP_STATION) && IS_BYTE_INSIDE(_m[tile].m5, 0, 8) && _m[tile].m2 == ttfd->station_index)) { |
2044
df63b9a7dec3
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2032
diff
changeset
|
2027 |
/* We do not check for dest_coords if we have a station_index, |
df63b9a7dec3
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2032
diff
changeset
|
2028 |
* because in that case the dest_coords are just an |
df63b9a7dec3
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2032
diff
changeset
|
2029 |
* approximation of where the station is */ |
0 | 2030 |
// found station |
2125
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2115
diff
changeset
|
2031 |
ttfd->best_track = track; |
0 | 2032 |
return true; |
2033 |
} else { |
|
2034 |
uint dist; |
|
2035 |
||
2125
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2115
diff
changeset
|
2036 |
// didn't find station, keep track of the best path so far. |
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1237
diff
changeset
|
2037 |
dist = DistanceManhattan(tile, ttfd->dest_coords); |
0 | 2038 |
if (dist < ttfd->best_bird_dist) { |
2039 |
ttfd->best_bird_dist = dist; |
|
2125
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2115
diff
changeset
|
2040 |
ttfd->best_track = track; |
0 | 2041 |
} |
2042 |
return false; |
|
2043 |
} |
|
2044 |
} |
|
2045 |
||
2630 | 2046 |
static void FillWithStationData(TrainTrackFollowerData* fd, const Vehicle* v) |
0 | 2047 |
{ |
2639 | 2048 |
fd->dest_coords = v->dest_tile; |
2049 |
if (v->current_order.type == OT_GOTO_STATION) { |
|
2050 |
fd->station_index = v->current_order.station; |
|
2051 |
} else { |
|
2052 |
fd->station_index = INVALID_STATION; |
|
2053 |
} |
|
0 | 2054 |
} |
2055 |
||
2056 |
static const byte _initial_tile_subcoord[6][4][3] = { |
|
2057 |
{{ 15, 8, 1 },{ 0, 0, 0 },{ 0, 8, 5 },{ 0, 0, 0 }}, |
|
2058 |
{{ 0, 0, 0 },{ 8, 0, 3 },{ 0, 0, 0 },{ 8,15, 7 }}, |
|
2059 |
{{ 0, 0, 0 },{ 7, 0, 2 },{ 0, 7, 6 },{ 0, 0, 0 }}, |
|
2060 |
{{ 15, 8, 2 },{ 0, 0, 0 },{ 0, 0, 0 },{ 8,15, 6 }}, |
|
2061 |
{{ 15, 7, 0 },{ 8, 0, 4 },{ 0, 0, 0 },{ 0, 0, 0 }}, |
|
2062 |
{{ 0, 0, 0 },{ 0, 0, 0 },{ 0, 8, 4 },{ 7,15, 0 }}, |
|
2063 |
}; |
|
2064 |
||
2065 |
static const uint32 _reachable_tracks[4] = { |
|
2066 |
0x10091009, |
|
2067 |
0x00160016, |
|
2068 |
0x05200520, |
|
2069 |
0x2A002A00, |
|
2070 |
}; |
|
2071 |
||
2072 |
static const byte _search_directions[6][4] = { |
|
2073 |
{ 0, 9, 2, 9 }, // track 1 |
|
2074 |
{ 9, 1, 9, 3 }, // track 2 |
|
2075 |
{ 9, 0, 3, 9 }, // track upper |
|
2076 |
{ 1, 9, 9, 2 }, // track lower |
|
2077 |
{ 3, 2, 9, 9 }, // track left |
|
2078 |
{ 9, 9, 1, 0 }, // track right |
|
2079 |
}; |
|
2080 |
||
2081 |
static const byte _pick_track_table[6] = {1, 3, 2, 2, 0, 0}; |
|
1247 | 2082 |
#if PF_BENCHMARK |
2044
df63b9a7dec3
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2032
diff
changeset
|
2083 |
#if !defined(_MSC_VER) |
2482
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2477
diff
changeset
|
2084 |
unsigned int _rdtsc() |
1247 | 2085 |
{ |
2639 | 2086 |
unsigned int high, low; |
2087 |
||
2088 |
__asm__ __volatile__ ("rdtsc" : "=a" (low), "=d" (high)); |
|
2089 |
return low; |
|
1247 | 2090 |
} |
2044
df63b9a7dec3
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2032
diff
changeset
|
2091 |
#else |
2482
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2477
diff
changeset
|
2092 |
#ifndef _M_AMD64 |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2477
diff
changeset
|
2093 |
static unsigned int _declspec(naked) _rdtsc(void) |
2044
df63b9a7dec3
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2032
diff
changeset
|
2094 |
{ |
df63b9a7dec3
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2032
diff
changeset
|
2095 |
_asm { |
df63b9a7dec3
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2032
diff
changeset
|
2096 |
rdtsc |
df63b9a7dec3
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2032
diff
changeset
|
2097 |
ret |
df63b9a7dec3
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2032
diff
changeset
|
2098 |
} |
df63b9a7dec3
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2032
diff
changeset
|
2099 |
} |
1247 | 2100 |
#endif |
2044
df63b9a7dec3
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2032
diff
changeset
|
2101 |
#endif |
2482
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2477
diff
changeset
|
2102 |
#endif |
2044
df63b9a7dec3
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2032
diff
changeset
|
2103 |
|
1247 | 2104 |
|
0 | 2105 |
|
2106 |
/* choose a track */ |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1969
diff
changeset
|
2107 |
static byte ChooseTrainTrack(Vehicle *v, TileIndex tile, int enterdir, TrackdirBits trackdirbits) |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
2108 |
{ |
0 | 2109 |
TrainTrackFollowerData fd; |
2110 |
uint best_track; |
|
1247 | 2111 |
#if PF_BENCHMARK |
2482
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2477
diff
changeset
|
2112 |
int time = _rdtsc(); |
0 | 2113 |
static float f; |
2114 |
#endif |
|
2115 |
||
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1935
diff
changeset
|
2116 |
assert( (trackdirbits & ~0x3F) == 0); |
0 | 2117 |
|
1247 | 2118 |
/* quick return in case only one possible track is available */ |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1935
diff
changeset
|
2119 |
if (KILL_FIRST_BIT(trackdirbits) == 0) |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1935
diff
changeset
|
2120 |
return FIND_FIRST_BIT(trackdirbits); |
0 | 2121 |
|
1247 | 2122 |
if (_patches.new_pathfinding_all) { /* Use a new pathfinding for everything */ |
2123 |
NPFFindStationOrTileData fstd; |
|
2124 |
NPFFoundTargetData ftd; |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1935
diff
changeset
|
2125 |
Trackdir trackdir; |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2126 |
uint16 pbs_tracks; |
1247 | 2127 |
|
2128 |
NPFFillWithOrderData(&fstd, v); |
|
2129 |
/* The enterdir for the new tile, is the exitdir for the old tile */ |
|
1752
d65cd19f7117
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1698
diff
changeset
|
2130 |
trackdir = GetVehicleTrackdir(v); |
1247 | 2131 |
assert(trackdir != 0xff); |
2132 |
||
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2133 |
pbs_tracks = PBSTileReserved(tile); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2134 |
pbs_tracks |= pbs_tracks << 8; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2135 |
pbs_tracks &= TrackdirReachesTrackdirs(trackdir); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2136 |
if (pbs_tracks || (v->u.rail.pbs_status == PBS_STAT_NEED_PATH)) { |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2137 |
DEBUG(pbs, 2) ("pbs: (%i) choosefromblock, tile_org:%x tile_dst:%x trackdir:%i pbs_tracks:%i",v->unitnumber, tile,tile - TileOffsByDir(enterdir), trackdir, pbs_tracks); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2138 |
// clear the currently planned path |
2115
99198b563a9c
(svn r2625) - Fix: [pbs] Store the end of a train's reserved path explicitly. Prevents trains from unreserving eachothers paths in some cases.
hackykid
parents:
2049
diff
changeset
|
2139 |
if (v->u.rail.pbs_status != PBS_STAT_NEED_PATH) PBSClearPath(tile, FindFirstBit2x64(pbs_tracks), v->u.rail.pbs_end_tile, v->u.rail.pbs_end_trackdir); |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2140 |
|
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2141 |
// try to find a route to a green exit signal |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2142 |
ftd = NPFRouteToStationOrTile(tile - TileOffsByDir(enterdir), trackdir, &fstd, TRANSPORT_RAIL, v->owner, v->u.rail.railtype, PBS_MODE_ANY); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2143 |
|
2115
99198b563a9c
(svn r2625) - Fix: [pbs] Store the end of a train's reserved path explicitly. Prevents trains from unreserving eachothers paths in some cases.
hackykid
parents:
2049
diff
changeset
|
2144 |
v->u.rail.pbs_end_tile = ftd.node.tile; |
99198b563a9c
(svn r2625) - Fix: [pbs] Store the end of a train's reserved path explicitly. Prevents trains from unreserving eachothers paths in some cases.
hackykid
parents:
2049
diff
changeset
|
2145 |
v->u.rail.pbs_end_trackdir = ftd.node.direction; |
99198b563a9c
(svn r2625) - Fix: [pbs] Store the end of a train's reserved path explicitly. Prevents trains from unreserving eachothers paths in some cases.
hackykid
parents:
2049
diff
changeset
|
2146 |
|
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2147 |
} else |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2148 |
ftd = NPFRouteToStationOrTile(tile - TileOffsByDir(enterdir), trackdir, &fstd, TRANSPORT_RAIL, v->owner, v->u.rail.railtype, PBS_MODE_NONE); |
1698
3f979f9ecf6c
(svn r2202) - Fix: [NPF] When a vehicle could not reach its target, it would choose a random direction. It will now try to get as close as possible.
matthijs
parents:
1685
diff
changeset
|
2149 |
|
3f979f9ecf6c
(svn r2202) - Fix: [NPF] When a vehicle could not reach its target, it would choose a random direction. It will now try to get as close as possible.
matthijs
parents:
1685
diff
changeset
|
2150 |
if (ftd.best_trackdir == 0xff) { |
3f979f9ecf6c
(svn r2202) - Fix: [NPF] When a vehicle could not reach its target, it would choose a random direction. It will now try to get as close as possible.
matthijs
parents:
1685
diff
changeset
|
2151 |
/* We are already at our target. Just do something */ |
1247 | 2152 |
//TODO: maybe display error? |
2153 |
//TODO: go straight ahead if possible? |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1935
diff
changeset
|
2154 |
best_track = FIND_FIRST_BIT(trackdirbits); |
0 | 2155 |
} else { |
1698
3f979f9ecf6c
(svn r2202) - Fix: [NPF] When a vehicle could not reach its target, it would choose a random direction. It will now try to get as close as possible.
matthijs
parents:
1685
diff
changeset
|
2156 |
/* If ftd.best_bird_dist is 0, we found our target and ftd.best_trackdir contains |
3f979f9ecf6c
(svn r2202) - Fix: [NPF] When a vehicle could not reach its target, it would choose a random direction. It will now try to get as close as possible.
matthijs
parents:
1685
diff
changeset
|
2157 |
the direction we need to take to get there, if ftd.best_bird_dist is not 0, |
3f979f9ecf6c
(svn r2202) - Fix: [NPF] When a vehicle could not reach its target, it would choose a random direction. It will now try to get as close as possible.
matthijs
parents:
1685
diff
changeset
|
2158 |
we did not find our target, but ftd.best_trackdir contains the direction leading |
3f979f9ecf6c
(svn r2202) - Fix: [NPF] When a vehicle could not reach its target, it would choose a random direction. It will now try to get as close as possible.
matthijs
parents:
1685
diff
changeset
|
2159 |
to the tile closest to our target. */ |
1247 | 2160 |
/* Discard enterdir information, making it a normal track */ |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2161 |
best_track = TrackdirToTrack(ftd.best_trackdir); |
0 | 2162 |
} |
2163 |
} else { |
|
1247 | 2164 |
FillWithStationData(&fd, v); |
2165 |
||
2044
df63b9a7dec3
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2032
diff
changeset
|
2166 |
/* New train pathfinding */ |
df63b9a7dec3
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2032
diff
changeset
|
2167 |
fd.best_bird_dist = (uint)-1; |
df63b9a7dec3
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2032
diff
changeset
|
2168 |
fd.best_track_dist = (uint)-1; |
df63b9a7dec3
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2032
diff
changeset
|
2169 |
fd.best_track = 0xFF; |
df63b9a7dec3
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2032
diff
changeset
|
2170 |
|
2125
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2115
diff
changeset
|
2171 |
NewTrainPathfind(tile - TileOffsByDir(enterdir), v->dest_tile, |
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2115
diff
changeset
|
2172 |
enterdir, (NTPEnumProc*)NtpCallbFindStation, &fd); |
2044
df63b9a7dec3
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2032
diff
changeset
|
2173 |
|
df63b9a7dec3
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2032
diff
changeset
|
2174 |
if (fd.best_track == 0xff) { |
df63b9a7dec3
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2032
diff
changeset
|
2175 |
// blaha |
df63b9a7dec3
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2032
diff
changeset
|
2176 |
best_track = FIND_FIRST_BIT(trackdirbits); |
1247 | 2177 |
} else { |
2044
df63b9a7dec3
(svn r2553) - Fix: [pathfinding] Remove old-old train pathfinder. Enhanced old pathfinder.
ludde
parents:
2032
diff
changeset
|
2178 |
best_track = fd.best_track & 7; |
1247 | 2179 |
} |
0 | 2180 |
} |
2181 |
||
1247 | 2182 |
#if PF_BENCHMARK |
2482
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2477
diff
changeset
|
2183 |
time = _rdtsc() - time; |
0 | 2184 |
f = f * 0.99 + 0.01 * time; |
2185 |
printf("PF time = %d %f\n", time, f); |
|
2186 |
#endif |
|
2187 |
||
2188 |
return best_track; |
|
2189 |
} |
|
2190 |
||
2191 |
||
2192 |
static bool CheckReverseTrain(Vehicle *v) |
|
2193 |
{ |
|
2194 |
TrainTrackFollowerData fd; |
|
2195 |
int i, r; |
|
2196 |
int best_track; |
|
2197 |
uint best_bird_dist = 0; |
|
2198 |
uint best_track_dist = 0; |
|
2199 |
uint reverse, reverse_best; |
|
2200 |
||
2201 |
if (_opt.diff.line_reverse_mode != 0 || |
|
2202 |
v->u.rail.track & 0xC0 || |
|
2203 |
!(v->direction & 1)) |
|
2204 |
return false; |
|
2205 |
||
2206 |
FillWithStationData(&fd, v); |
|
2207 |
||
2208 |
best_track = -1; |
|
2209 |
reverse_best = reverse = 0; |
|
2210 |
||
2211 |
assert(v->u.rail.track); |
|
2212 |
||
2213 |
i = _search_directions[FIND_FIRST_BIT(v->u.rail.track)][v->direction>>1]; |
|
2214 |
||
1247 | 2215 |
if (_patches.new_pathfinding_all) { /* Use a new pathfinding for everything */ |
2216 |
NPFFindStationOrTileData fstd; |
|
2217 |
NPFFoundTargetData ftd; |
|
2218 |
byte trackdir, trackdir_rev; |
|
2219 |
Vehicle* last = GetLastVehicleInChain(v); |
|
2220 |
||
2221 |
NPFFillWithOrderData(&fstd, v); |
|
2222 |
||
1752
d65cd19f7117
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1698
diff
changeset
|
2223 |
trackdir = GetVehicleTrackdir(v); |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1935
diff
changeset
|
2224 |
trackdir_rev = ReverseTrackdir(GetVehicleTrackdir(last)); |
1247 | 2225 |
assert(trackdir != 0xff); |
2226 |
assert(trackdir_rev != 0xff); |
|
2227 |
||
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2228 |
ftd = NPFRouteToStationOrTileTwoWay(v->tile, trackdir, last->tile, trackdir_rev, &fstd, TRANSPORT_RAIL, v->owner, v->u.rail.railtype, PBS_MODE_NONE); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2229 |
|
1247 | 2230 |
if (ftd.best_bird_dist != 0) { |
2231 |
/* We didn't find anything, just keep on going straight ahead */ |
|
2232 |
reverse_best = false; |
|
2233 |
} else { |
|
1461
699c4d46f59e
(svn r1965) - Fix: [NPF] Forgot to update one line where NPFGetFlag() should have been used two commits ago.
matthijs
parents:
1459
diff
changeset
|
2234 |
if (NPFGetFlag(&ftd.node, NPF_FLAG_REVERSE)) |
1247 | 2235 |
reverse_best = true; |
2236 |
else |
|
2237 |
reverse_best = false; |
|
2238 |
} |
|
2239 |
} else { |
|
2240 |
while(true) { |
|
2241 |
fd.best_bird_dist = (uint)-1; |
|
2242 |
fd.best_track_dist = (uint)-1; |
|
2243 |
||
2125
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2115
diff
changeset
|
2244 |
NewTrainPathfind(v->tile, v->dest_tile, reverse ^ i, (NTPEnumProc*)NtpCallbFindStation, &fd); |
1247 | 2245 |
|
2246 |
if (best_track != -1) { |
|
2247 |
if (best_bird_dist != 0) { |
|
2248 |
if (fd.best_bird_dist != 0) { |
|
2249 |
/* neither reached the destination, pick the one with the smallest bird dist */ |
|
2250 |
if (fd.best_bird_dist > best_bird_dist) goto bad; |
|
2251 |
if (fd.best_bird_dist < best_bird_dist) goto good; |
|
2252 |
} else { |
|
2253 |
/* we found the destination for the first time */ |
|
2254 |
goto good; |
|
2255 |
} |
|
0 | 2256 |
} else { |
1247 | 2257 |
if (fd.best_bird_dist != 0) { |
2258 |
/* didn't find destination, but we've found the destination previously */ |
|
2259 |
goto bad; |
|
2260 |
} else { |
|
2261 |
/* both old & new reached the destination, compare track length */ |
|
2262 |
if (fd.best_track_dist > best_track_dist) goto bad; |
|
2263 |
if (fd.best_track_dist < best_track_dist) goto good; |
|
2264 |
} |
|
0 | 2265 |
} |
1247 | 2266 |
|
2267 |
/* if we reach this position, there's two paths of equal value so far. |
|
2268 |
* pick one randomly. */ |
|
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
2269 |
r = GB(Random(), 0, 8); |
1247 | 2270 |
if (_pick_track_table[i] == (v->direction & 3)) r += 80; |
2271 |
if (_pick_track_table[best_track] == (v->direction & 3)) r -= 80; |
|
2272 |
if (r <= 127) goto bad; |
|
0 | 2273 |
} |
1247 | 2274 |
good:; |
2275 |
best_track = i; |
|
2276 |
best_bird_dist = fd.best_bird_dist; |
|
2277 |
best_track_dist = fd.best_track_dist; |
|
2278 |
reverse_best = reverse; |
|
2279 |
bad:; |
|
2280 |
if (reverse != 0) |
|
2281 |
break; |
|
2282 |
reverse = 2; |
|
0 | 2283 |
} |
2284 |
} |
|
2285 |
||
2286 |
return reverse_best != 0; |
|
2287 |
} |
|
2288 |
||
2289 |
static bool ProcessTrainOrder(Vehicle *v) |
|
2290 |
{ |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
954
diff
changeset
|
2291 |
const Order *order; |
0 | 2292 |
bool result; |
2293 |
||
2294 |
// These are un-interruptible |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
2295 |
if (v->current_order.type >= OT_GOTO_DEPOT && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
2296 |
v->current_order.type <= OT_LEAVESTATION) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
954
diff
changeset
|
2297 |
// Let a depot order in the orderlist interrupt. |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
2298 |
if (v->current_order.type != OT_GOTO_DEPOT || |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
2299 |
!(v->current_order.flags & OF_UNLOAD)) |
0 | 2300 |
return false; |
2301 |
} |
|
2302 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
2303 |
if (v->current_order.type == OT_GOTO_DEPOT && |
2214
056bbc3c8236
(svn r2732) -Codechange: Cleaned the order flags some more. Hit some inconsistencies while trying to locate bug 1244167
celestar
parents:
2186
diff
changeset
|
2304 |
(v->current_order.flags & (OF_PART_OF_ORDERS | OF_SERVICE_IF_NEEDED)) == (OF_PART_OF_ORDERS | OF_SERVICE_IF_NEEDED) && |
1520
d88442095697
(svn r2024) -Fix: [autoreplace] reverted all changes involving v->set_for_replacement as they caused desyncs.
bjarni
parents:
1507
diff
changeset
|
2305 |
!VehicleNeedsService(v)) { |
0 | 2306 |
v->cur_order_index++; |
2307 |
} |
|
2308 |
||
395
788a9bba0889
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
358
diff
changeset
|
2309 |
// check if we've reached the waypoint? |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
2310 |
if (v->current_order.type == OT_GOTO_WAYPOINT && v->tile == v->dest_tile) { |
0 | 2311 |
v->cur_order_index++; |
2312 |
} |
|
2313 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
2314 |
// check if we've reached a non-stop station while TTDPatch nonstop is enabled.. |
2549 | 2315 |
if (_patches.new_nonstop && |
2316 |
v->current_order.flags & OF_NON_STOP && |
|
2317 |
IsTileType(v->tile, MP_STATION) && |
|
2318 |
v->current_order.station == _m[v->tile].m2) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
2319 |
v->cur_order_index++; |
0 | 2320 |
} |
2321 |
||
2322 |
// Get the current order |
|
2639 | 2323 |
if (v->cur_order_index >= v->num_orders) v->cur_order_index = 0; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
954
diff
changeset
|
2324 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
954
diff
changeset
|
2325 |
order = GetVehicleOrder(v, v->cur_order_index); |
0 | 2326 |
|
2327 |
// If no order, do nothing. |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
954
diff
changeset
|
2328 |
if (order == NULL) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
2329 |
v->current_order.type = OT_NOTHING; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
2330 |
v->current_order.flags = 0; |
0 | 2331 |
v->dest_tile = 0; |
2332 |
return false; |
|
2333 |
} |
|
2334 |
||
2335 |
// If it is unchanged, keep it. |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
954
diff
changeset
|
2336 |
if (order->type == v->current_order.type && |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
954
diff
changeset
|
2337 |
order->flags == v->current_order.flags && |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
954
diff
changeset
|
2338 |
order->station == v->current_order.station) |
0 | 2339 |
return false; |
2340 |
||
2341 |
// Otherwise set it, and determine the destination tile. |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
954
diff
changeset
|
2342 |
v->current_order = *order; |
0 | 2343 |
|
2344 |
v->dest_tile = 0; |
|
2345 |
||
2617
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2612
diff
changeset
|
2346 |
// store the station length if no shorter station was visited this order round |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2612
diff
changeset
|
2347 |
if (v->cur_order_index == 0) { |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2612
diff
changeset
|
2348 |
if (v->u.rail.shortest_platform[1] != 0 && v->u.rail.shortest_platform[1] != 255) { |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2612
diff
changeset
|
2349 |
// we went though a whole round of orders without interruptions, so we store the length of the shortest station |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2612
diff
changeset
|
2350 |
v->u.rail.shortest_platform[0] = v->u.rail.shortest_platform[1]; |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2612
diff
changeset
|
2351 |
} |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2612
diff
changeset
|
2352 |
// all platforms are shorter than 255, so now we can find the shortest in the next order round. They might have changed size |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2612
diff
changeset
|
2353 |
v->u.rail.shortest_platform[1] = 255; |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2612
diff
changeset
|
2354 |
} |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2612
diff
changeset
|
2355 |
|
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2612
diff
changeset
|
2356 |
if (v->last_station_visited != INVALID_STATION) { |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2612
diff
changeset
|
2357 |
Station *st = GetStation(v->last_station_visited); |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2612
diff
changeset
|
2358 |
if (TileBelongsToRailStation(st, v->tile)) { |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2612
diff
changeset
|
2359 |
byte length = GetStationPlatforms(st, v->tile); |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2612
diff
changeset
|
2360 |
|
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2612
diff
changeset
|
2361 |
if (length < v->u.rail.shortest_platform[1]) { |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2612
diff
changeset
|
2362 |
v->u.rail.shortest_platform[1] = length; |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2612
diff
changeset
|
2363 |
} |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2612
diff
changeset
|
2364 |
} |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2612
diff
changeset
|
2365 |
} |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2612
diff
changeset
|
2366 |
|
0 | 2367 |
result = false; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
954
diff
changeset
|
2368 |
switch (order->type) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
954
diff
changeset
|
2369 |
case OT_GOTO_STATION: |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
954
diff
changeset
|
2370 |
if (order->station == v->last_station_visited) |
1266
eccd576e322f
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1247
diff
changeset
|
2371 |
v->last_station_visited = INVALID_STATION; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
954
diff
changeset
|
2372 |
v->dest_tile = GetStation(order->station)->xy; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
954
diff
changeset
|
2373 |
result = CheckReverseTrain(v); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
954
diff
changeset
|
2374 |
break; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
954
diff
changeset
|
2375 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
954
diff
changeset
|
2376 |
case OT_GOTO_DEPOT: |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
2377 |
v->dest_tile = GetDepot(order->station)->xy; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
954
diff
changeset
|
2378 |
result = CheckReverseTrain(v); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
954
diff
changeset
|
2379 |
break; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
954
diff
changeset
|
2380 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
954
diff
changeset
|
2381 |
case OT_GOTO_WAYPOINT: |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1531
diff
changeset
|
2382 |
v->dest_tile = GetWaypoint(order->station)->xy; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
954
diff
changeset
|
2383 |
result = CheckReverseTrain(v); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
954
diff
changeset
|
2384 |
break; |
0 | 2385 |
} |
2386 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
954
diff
changeset
|
2387 |
InvalidateVehicleOrder(v); |
0 | 2388 |
|
2389 |
return result; |
|
2390 |
} |
|
2391 |
||
2392 |
static void MarkTrainDirty(Vehicle *v) |
|
2393 |
{ |
|
2394 |
do { |
|
2395 |
v->cur_image = GetTrainImage(v, v->direction); |
|
2396 |
MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1); |
|
2639 | 2397 |
} while ((v = v->next) != NULL); |
0 | 2398 |
} |
2399 |
||
2400 |
static void HandleTrainLoading(Vehicle *v, bool mode) |
|
2401 |
{ |
|
2639 | 2402 |
if (v->current_order.type == OT_NOTHING) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
2403 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
2404 |
if (v->current_order.type != OT_DUMMY) { |
2639 | 2405 |
if (v->current_order.type != OT_LOADING) return; |
2406 |
if (mode) return; |
|
0 | 2407 |
|
2408 |
// don't mark the train as lost if we're loading on the final station. |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
2409 |
if (v->current_order.flags & OF_NON_STOP) |
0 | 2410 |
v->u.rail.days_since_order_progr = 0; |
2411 |
||
2639 | 2412 |
if (--v->load_unload_time_rem) return; |
0 | 2413 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
2414 |
if (v->current_order.flags & OF_FULL_LOAD && CanFillVehicle(v)) { |
882
64665fd87871
(svn r1367) -Fix: Full-Loading trains no longer get "lost" after a while (Hackykid)
matthijs
parents:
842
diff
changeset
|
2415 |
v->u.rail.days_since_order_progr = 0; /* Prevent a train lost message for full loading trains */ |
0 | 2416 |
SET_EXPENSES_TYPE(EXPENSES_TRAIN_INC); |
2417 |
if (LoadUnloadVehicle(v)) { |
|
2418 |
InvalidateWindow(WC_TRAINS_LIST, v->owner); |
|
2419 |
MarkTrainDirty(v); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
2420 |
|
1905
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
2421 |
// need to update acceleration and cached values since the goods on the train changed. |
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
2422 |
TrainCargoChanged(v); |
0 | 2423 |
UpdateTrainAcceleration(v); |
2424 |
} |
|
2425 |
return; |
|
2426 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
2427 |
|
0 | 2428 |
TrainPlayLeaveStationSound(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
2429 |
|
0 | 2430 |
{ |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
2431 |
Order b = v->current_order; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
2432 |
v->current_order.type = OT_LEAVESTATION; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
2433 |
v->current_order.flags = 0; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
2434 |
|
0 | 2435 |
// If this was not the final order, don't remove it from the list. |
2639 | 2436 |
if (!(b.flags & OF_NON_STOP)) return; |
0 | 2437 |
} |
2438 |
} |
|
2439 |
||
2440 |
v->u.rail.days_since_order_progr = 0; |
|
2441 |
v->cur_order_index++; |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
954
diff
changeset
|
2442 |
InvalidateVehicleOrder(v); |
0 | 2443 |
} |
2444 |
||
2445 |
static int UpdateTrainSpeed(Vehicle *v) |
|
2446 |
{ |
|
2447 |
uint spd; |
|
2448 |
uint accel; |
|
2449 |
||
954
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
2450 |
if (v->vehstatus & VS_STOPPED || HASBIT(v->u.rail.flags, VRF_REVERSING)) { |
2639 | 2451 |
if (_patches.realistic_acceleration) { |
1179
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
2452 |
accel = GetTrainAcceleration(v, AM_BRAKE) * 2; |
2639 | 2453 |
} else { |
1179
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
2454 |
accel = v->acceleration * -2; |
2639 | 2455 |
} |
0 | 2456 |
} else { |
2639 | 2457 |
if (_patches.realistic_acceleration) { |
1179
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
2458 |
accel = GetTrainAcceleration(v, AM_ACCEL); |
2639 | 2459 |
} else { |
1179
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
2460 |
accel = v->acceleration; |
2639 | 2461 |
} |
0 | 2462 |
} |
2463 |
||
2464 |
spd = v->subspeed + accel * 2; |
|
2465 |
v->subspeed = (byte)spd; |
|
1179
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
2466 |
{ |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
2467 |
int tempmax = v->max_speed; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
2468 |
if (v->cur_speed > v->max_speed) |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
2469 |
tempmax = v->cur_speed - (v->cur_speed / 10) - 1; |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
2470 |
v->cur_speed = spd = clamp(v->cur_speed + ((int)spd >> 8), 0, tempmax); |
ce0a75460808
(svn r1681) -Feature: New realistic acceleration.
celestar
parents:
1174
diff
changeset
|
2471 |
} |
0 | 2472 |
|
2473 |
if (!(v->direction & 1)) spd = spd * 3 >> 2; |
|
2474 |
||
2475 |
spd += v->progress; |
|
2476 |
v->progress = (byte)spd; |
|
2477 |
return (spd >> 8); |
|
2478 |
} |
|
2479 |
||
1551
b1c7df6daa63
(svn r2055) -CodeChange: Begun introducting StationID
celestar
parents:
1542
diff
changeset
|
2480 |
static void TrainEnterStation(Vehicle *v, StationID station) |
0 | 2481 |
{ |
2482 |
Station *st; |
|
2483 |
uint32 flags; |
|
2484 |
||
2485 |
v->last_station_visited = station; |
|
2486 |
||
2487 |
/* check if a train ever visited this station before */ |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
2488 |
st = GetStation(station); |
0 | 2489 |
if (!(st->had_vehicle_of_type & HVOT_TRAIN)) { |
2490 |
st->had_vehicle_of_type |= HVOT_TRAIN; |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
2491 |
SetDParam(0, st->index); |
0 | 2492 |
flags = (v->owner == _local_player) ? NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ARRIVAL_PLAYER, 0) : NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ARRIVAL_OTHER, 0); |
2493 |
AddNewsItem( |
|
2494 |
STR_8801_CITIZENS_CELEBRATE_FIRST, |
|
2495 |
flags, |
|
2496 |
v->index, |
|
2497 |
0); |
|
2498 |
} |
|
2499 |
||
2500 |
// Did we reach the final destination? |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
2501 |
if (v->current_order.type == OT_GOTO_STATION && |
1552
1da3dae846b7
(svn r2056) -Fix: [ 1166999 ] Strange cast removed. Thanks Tron
celestar
parents:
1551
diff
changeset
|
2502 |
v->current_order.station == station) { |
0 | 2503 |
// Yeah, keep the load/unload flags |
2504 |
// Non Stop now means if the order should be increased. |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
2505 |
v->current_order.type = OT_LOADING; |
1935
164d58b9137c
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1934
diff
changeset
|
2506 |
v->current_order.flags &= OF_FULL_LOAD | OF_UNLOAD | OF_TRANSFER; |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
2507 |
v->current_order.flags |= OF_NON_STOP; |
0 | 2508 |
} else { |
2509 |
// No, just do a simple load |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
2510 |
v->current_order.type = OT_LOADING; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
2511 |
v->current_order.flags = 0; |
0 | 2512 |
} |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
2513 |
v->current_order.station = 0; |
0 | 2514 |
|
2515 |
SET_EXPENSES_TYPE(EXPENSES_TRAIN_INC); |
|
2516 |
if (LoadUnloadVehicle(v) != 0) { |
|
2517 |
InvalidateWindow(WC_TRAINS_LIST, v->owner); |
|
2518 |
MarkTrainDirty(v); |
|
1905
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
2519 |
TrainCargoChanged(v); |
0 | 2520 |
UpdateTrainAcceleration(v); |
2521 |
} |
|
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
744
diff
changeset
|
2522 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 2523 |
} |
2524 |
||
954
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
2525 |
static byte AfterSetTrainPos(Vehicle *v, bool new_tile) |
0 | 2526 |
{ |
2527 |
byte new_z, old_z; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
2528 |
|
0 | 2529 |
// need this hint so it returns the right z coordinate on bridges. |
2530 |
_get_z_hint = v->z_pos; |
|
2531 |
new_z = GetSlopeZ(v->x_pos, v->y_pos); |
|
2532 |
_get_z_hint = 0; |
|
2533 |
||
2534 |
old_z = v->z_pos; |
|
2535 |
v->z_pos = new_z; |
|
2536 |
||
954
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
2537 |
if (new_tile) { |
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
2538 |
CLRBIT(v->u.rail.flags, VRF_GOINGUP); |
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
2539 |
CLRBIT(v->u.rail.flags, VRF_GOINGDOWN); |
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
2540 |
|
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
2541 |
if (new_z != old_z) { |
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
2542 |
TileIndex tile = TileVirtXY(v->x_pos, v->y_pos); |
1683
697f47e2bb59
(svn r2187) Implement a slightly better workaround than r1588 did. (Joint effort with Celestar)
tron
parents:
1681
diff
changeset
|
2543 |
|
697f47e2bb59
(svn r2187) Implement a slightly better workaround than r1588 did. (Joint effort with Celestar)
tron
parents:
1681
diff
changeset
|
2544 |
// XXX workaround, whole UP/DOWN detection needs overhaul |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2044
diff
changeset
|
2545 |
if (!IsTileType(tile, MP_TUNNELBRIDGE) || (_m[tile].m5 & 0x80) != 0) |
1683
697f47e2bb59
(svn r2187) Implement a slightly better workaround than r1588 did. (Joint effort with Celestar)
tron
parents:
1681
diff
changeset
|
2546 |
SETBIT(v->u.rail.flags, (new_z > old_z) ? VRF_GOINGUP : VRF_GOINGDOWN); |
954
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
2547 |
} |
0 | 2548 |
} |
2549 |
||
2550 |
VehiclePositionChanged(v); |
|
2551 |
EndVehicleMove(v); |
|
2552 |
return old_z; |
|
2553 |
} |
|
2554 |
||
2555 |
static const byte _new_vehicle_direction_table[11] = { |
|
2556 |
0, 7, 6, 0, |
|
2557 |
1, 0, 5, 0, |
|
2558 |
2, 3, 4, |
|
2559 |
}; |
|
2560 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1969
diff
changeset
|
2561 |
static int GetNewVehicleDirectionByTile(TileIndex new_tile, TileIndex old_tile) |
0 | 2562 |
{ |
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
2563 |
uint offs = (TileY(new_tile) - TileY(old_tile) + 1) * 4 + |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
2564 |
TileX(new_tile) - TileX(old_tile) + 1; |
0 | 2565 |
assert(offs < 11); |
2566 |
return _new_vehicle_direction_table[offs]; |
|
2567 |
} |
|
2568 |
||
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2425
diff
changeset
|
2569 |
static int GetNewVehicleDirection(const Vehicle *v, int x, int y) |
0 | 2570 |
{ |
2571 |
uint offs = (y - v->y_pos + 1) * 4 + (x - v->x_pos + 1); |
|
2572 |
assert(offs < 11); |
|
2573 |
return _new_vehicle_direction_table[offs]; |
|
2574 |
} |
|
2575 |
||
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2425
diff
changeset
|
2576 |
static int GetDirectionToVehicle(const Vehicle *v, int x, int y) |
0 | 2577 |
{ |
2578 |
byte offs; |
|
2579 |
||
2580 |
x -= v->x_pos; |
|
2581 |
if (x >= 0) { |
|
2582 |
offs = (x > 2) ? 0 : 1; |
|
2583 |
} else { |
|
2584 |
offs = (x < -2) ? 2 : 1; |
|
2585 |
} |
|
2586 |
||
2587 |
y -= v->y_pos; |
|
2588 |
if (y >= 0) { |
|
2589 |
offs += ((y > 2) ? 0 : 1) * 4; |
|
2590 |
} else { |
|
2591 |
offs += ((y < -2) ? 2 : 1) * 4; |
|
2592 |
} |
|
2593 |
||
2594 |
assert(offs < 11); |
|
2595 |
return _new_vehicle_direction_table[offs]; |
|
2596 |
} |
|
2597 |
||
2598 |
/* Check if the vehicle is compatible with the specified tile */ |
|
1048 | 2599 |
static bool CheckCompatibleRail(const Vehicle *v, TileIndex tile) |
0 | 2600 |
{ |
1214
8262981ac274
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1209
diff
changeset
|
2601 |
switch (GetTileType(tile)) { |
1048 | 2602 |
case MP_RAILWAY: |
2603 |
case MP_STATION: |
|
2604 |
// normal tracks, jump to owner check |
|
2605 |
break; |
|
2606 |
||
2607 |
case MP_TUNNELBRIDGE: |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2044
diff
changeset
|
2608 |
if ((_m[tile].m5 & 0xC0) == 0xC0) { // is bridge middle part? |
1192
2649bd4e556a
(svn r1696) Use GetTileSlope() instead of FindLandscapeHeightByTile() where it is sufficient. FindLandscapeHeightByTile() uses GetTileSlope() internally and adds some more info, which is discarded in these cases.
tron
parents:
1179
diff
changeset
|
2609 |
uint height; |
2649bd4e556a
(svn r1696) Use GetTileSlope() instead of FindLandscapeHeightByTile() where it is sufficient. FindLandscapeHeightByTile() uses GetTileSlope() internally and adds some more info, which is discarded in these cases.
tron
parents:
1179
diff
changeset
|
2610 |
uint tileh = GetTileSlope(tile, &height); |
1048 | 2611 |
|
2612 |
// correct Z position of a train going under a bridge on slopes |
|
1394
79cb56d80a3a
(svn r1898) Remove some unused macros from macros.h and move some others to more appropriate headers
tron
parents:
1387
diff
changeset
|
2613 |
if (CorrectZ(tileh)) height += 8; |
1192
2649bd4e556a
(svn r1696) Use GetTileSlope() instead of FindLandscapeHeightByTile() where it is sufficient. FindLandscapeHeightByTile() uses GetTileSlope() internally and adds some more info, which is discarded in these cases.
tron
parents:
1179
diff
changeset
|
2614 |
|
2649bd4e556a
(svn r1696) Use GetTileSlope() instead of FindLandscapeHeightByTile() where it is sufficient. FindLandscapeHeightByTile() uses GetTileSlope() internally and adds some more info, which is discarded in these cases.
tron
parents:
1179
diff
changeset
|
2615 |
if (v->z_pos != height) return true; // train is going over bridge |
1048 | 2616 |
} |
2617 |
break; |
|
2618 |
||
2619 |
case MP_STREET: |
|
2360
4e4ebe18e448
(svn r2886) Rename the "owner" attribute to "m1", because when it stores an owner it is accessed by [GS]etOwner anyway and when it doesn't store an owner, but arbitrary data, accessing a field called "owner" is confusing.
tron
parents:
2261
diff
changeset
|
2620 |
// tracks over roads, do owner check of tracks |
1048 | 2621 |
return |
2510
0008aad5d311
(svn r3036) Use IsCompatibleRail() to check the rail type of level crossings (not a fix, because the old == method works so far)
tron
parents:
2493
diff
changeset
|
2622 |
IsTileOwner(tile, v->owner) && ( |
0008aad5d311
(svn r3036) Use IsCompatibleRail() to check the rail type of level crossings (not a fix, because the old == method works so far)
tron
parents:
2493
diff
changeset
|
2623 |
v->subtype != TS_Front_Engine || |
0008aad5d311
(svn r3036) Use IsCompatibleRail() to check the rail type of level crossings (not a fix, because the old == method works so far)
tron
parents:
2493
diff
changeset
|
2624 |
IsCompatibleRail(v->u.rail.railtype, GB(_m[tile].m4, 0, 4)) |
0008aad5d311
(svn r3036) Use IsCompatibleRail() to check the rail type of level crossings (not a fix, because the old == method works so far)
tron
parents:
2493
diff
changeset
|
2625 |
); |
1048 | 2626 |
|
2627 |
default: |
|
2628 |
return true; |
|
2629 |
} |
|
2630 |
||
2631 |
return |
|
2549 | 2632 |
IsTileOwner(tile, v->owner) && ( |
2633 |
v->subtype != TS_Front_Engine || |
|
2634 |
IsCompatibleRail(v->u.rail.railtype, GetRailType(tile)) |
|
2635 |
); |
|
0 | 2636 |
} |
2637 |
||
2638 |
typedef struct { |
|
2639 |
byte small_turn, large_turn; |
|
2640 |
byte z_up; // fraction to remove when moving up |
|
2641 |
byte z_down; // fraction to remove when moving down |
|
2642 |
} RailtypeSlowdownParams; |
|
2643 |
||
2644 |
static const RailtypeSlowdownParams _railtype_slowdown[3] = { |
|
2645 |
// normal accel |
|
2646 |
{256/4, 256/2, 256/4, 2}, // normal |
|
2647 |
{256/4, 256/2, 256/4, 2}, // monorail |
|
2648 |
{0, 256/2, 256/4, 2}, // maglev |
|
2649 |
}; |
|
2650 |
||
2651 |
/* Modify the speed of the vehicle due to a turn */ |
|
2652 |
static void AffectSpeedByDirChange(Vehicle *v, byte new_dir) |
|
2653 |
{ |
|
2654 |
byte diff; |
|
2655 |
const RailtypeSlowdownParams *rsp; |
|
2656 |
||
2657 |
if (_patches.realistic_acceleration || (diff = (v->direction - new_dir) & 7) == 0) |
|
2658 |
return; |
|
2659 |
||
2660 |
rsp = &_railtype_slowdown[v->u.rail.railtype]; |
|
2661 |
v->cur_speed -= ((diff == 1 || diff == 7) ? rsp->small_turn : rsp->large_turn) * v->cur_speed >> 8; |
|
2662 |
} |
|
2663 |
||
2664 |
/* Modify the speed of the vehicle due to a change in altitude */ |
|
2665 |
static void AffectSpeedByZChange(Vehicle *v, byte old_z) |
|
2666 |
{ |
|
2667 |
const RailtypeSlowdownParams *rsp; |
|
2639 | 2668 |
if (old_z == v->z_pos || _patches.realistic_acceleration) return; |
0 | 2669 |
|
2670 |
rsp = &_railtype_slowdown[v->u.rail.railtype]; |
|
2671 |
||
2672 |
if (old_z < v->z_pos) { |
|
2673 |
v->cur_speed -= (v->cur_speed * rsp->z_up >> 8); |
|
2674 |
} else { |
|
2675 |
uint16 spd = v->cur_speed + rsp->z_down; |
|
2639 | 2676 |
if (spd <= v->max_speed) v->cur_speed = spd; |
0 | 2677 |
} |
2678 |
} |
|
2679 |
||
2680 |
static const byte _otherside_signal_directions[14] = { |
|
2681 |
1, 3, 1, 3, 5, 3, 0, 0, |
|
2682 |
5, 7, 7, 5, 7, 1, |
|
2683 |
}; |
|
2684 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1969
diff
changeset
|
2685 |
static void TrainMovedChangeSignals(TileIndex tile, int dir) |
0 | 2686 |
{ |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2044
diff
changeset
|
2687 |
if (IsTileType(tile, MP_RAILWAY) && (_m[tile].m5 & 0xC0) == 0x40) { |
2639 | 2688 |
uint i = FindFirstBit2x64((_m[tile].m5 + (_m[tile].m5 << 8)) & _reachable_tracks[dir]); |
0 | 2689 |
UpdateSignalsOnSegment(tile, _otherside_signal_directions[i]); |
2690 |
} |
|
2691 |
} |
|
2692 |
||
2693 |
||
2694 |
typedef struct TrainCollideChecker { |
|
1434
e3f4a55b8bcc
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
tron
parents:
1432
diff
changeset
|
2695 |
const Vehicle *v; |
e3f4a55b8bcc
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
tron
parents:
1432
diff
changeset
|
2696 |
const Vehicle *v_skip; |
0 | 2697 |
} TrainCollideChecker; |
2698 |
||
1434
e3f4a55b8bcc
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
tron
parents:
1432
diff
changeset
|
2699 |
static void *FindTrainCollideEnum(Vehicle *v, void *data) |
0 | 2700 |
{ |
1434
e3f4a55b8bcc
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
tron
parents:
1432
diff
changeset
|
2701 |
const TrainCollideChecker* tcc = data; |
e3f4a55b8bcc
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
tron
parents:
1432
diff
changeset
|
2702 |
|
e3f4a55b8bcc
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
tron
parents:
1432
diff
changeset
|
2703 |
if (v != tcc->v && |
e3f4a55b8bcc
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
tron
parents:
1432
diff
changeset
|
2704 |
v != tcc->v_skip && |
e3f4a55b8bcc
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
tron
parents:
1432
diff
changeset
|
2705 |
v->type == VEH_Train && |
e3f4a55b8bcc
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
tron
parents:
1432
diff
changeset
|
2706 |
v->u.rail.track != 0x80 && |
e3f4a55b8bcc
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
tron
parents:
1432
diff
changeset
|
2707 |
myabs(v->z_pos - tcc->v->z_pos) <= 6 && |
e3f4a55b8bcc
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
tron
parents:
1432
diff
changeset
|
2708 |
myabs(v->x_pos - tcc->v->x_pos) < 6 && |
e3f4a55b8bcc
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
tron
parents:
1432
diff
changeset
|
2709 |
myabs(v->y_pos - tcc->v->y_pos) < 6) { |
e3f4a55b8bcc
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
tron
parents:
1432
diff
changeset
|
2710 |
return v; |
e3f4a55b8bcc
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
tron
parents:
1432
diff
changeset
|
2711 |
} else { |
e3f4a55b8bcc
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
tron
parents:
1432
diff
changeset
|
2712 |
return NULL; |
e3f4a55b8bcc
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
tron
parents:
1432
diff
changeset
|
2713 |
} |
0 | 2714 |
} |
2715 |
||
2716 |
static void SetVehicleCrashed(Vehicle *v) |
|
2717 |
{ |
|
2718 |
Vehicle *u; |
|
2719 |
||
2720 |
if (v->u.rail.crash_anim_pos != 0) |
|
2721 |
return; |
|
2722 |
||
2723 |
v->u.rail.crash_anim_pos++; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
2724 |
|
0 | 2725 |
u = v; |
2726 |
BEGIN_ENUM_WAGONS(v) |
|
2727 |
v->vehstatus |= VS_CRASHED; |
|
2728 |
END_ENUM_WAGONS(v) |
|
2729 |
||
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
744
diff
changeset
|
2730 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, u->index, STATUS_BAR); |
0 | 2731 |
} |
2732 |
||
2549 | 2733 |
static uint CountPassengersInTrain(const Vehicle* v) |
0 | 2734 |
{ |
2549 | 2735 |
uint num = 0; |
0 | 2736 |
BEGIN_ENUM_WAGONS(v) |
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1064
diff
changeset
|
2737 |
if (v->cargo_type == CT_PASSENGERS) num += v->cargo_count; |
0 | 2738 |
END_ENUM_WAGONS(v) |
2739 |
return num; |
|
2740 |
} |
|
2741 |
||
22 | 2742 |
/* |
1434
e3f4a55b8bcc
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
tron
parents:
1432
diff
changeset
|
2743 |
* Checks whether the specified train has a collision with another vehicle. If |
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1064
diff
changeset
|
2744 |
* so, destroys this vehicle, and the other vehicle if its subtype is 0 (TS_Front_Engine). |
22 | 2745 |
* Reports the incident in a flashy news item, modifies station ratings and |
2746 |
* plays a sound. |
|
2747 |
*/ |
|
0 | 2748 |
static void CheckTrainCollision(Vehicle *v) |
2749 |
{ |
|
2750 |
TrainCollideChecker tcc; |
|
1434
e3f4a55b8bcc
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
tron
parents:
1432
diff
changeset
|
2751 |
Vehicle *coll; |
e3f4a55b8bcc
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
tron
parents:
1432
diff
changeset
|
2752 |
Vehicle *realcoll; |
2639 | 2753 |
uint num; |
0 | 2754 |
|
2755 |
/* can't collide in depot */ |
|
2639 | 2756 |
if (v->u.rail.track == 0x80) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
2757 |
|
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
2758 |
assert(v->u.rail.track == 0x40 || TileVirtXY(v->x_pos, v->y_pos) == v->tile); |
0 | 2759 |
|
2760 |
tcc.v = v; |
|
2761 |
tcc.v_skip = v->next; |
|
2762 |
||
2763 |
/* find colliding vehicle */ |
|
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
2764 |
realcoll = VehicleFromPos(TileVirtXY(v->x_pos, v->y_pos), &tcc, FindTrainCollideEnum); |
2639 | 2765 |
if (realcoll == NULL) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
2766 |
|
1434
e3f4a55b8bcc
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
tron
parents:
1432
diff
changeset
|
2767 |
coll = GetFirstVehicleInChain(realcoll); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
2768 |
|
0 | 2769 |
/* it can't collide with its own wagons */ |
1434
e3f4a55b8bcc
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
tron
parents:
1432
diff
changeset
|
2770 |
if (v == coll || |
e3f4a55b8bcc
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
tron
parents:
1432
diff
changeset
|
2771 |
(v->u.rail.track & 0x40 && (v->direction & 2) != (realcoll->direction & 2))) |
0 | 2772 |
return; |
2773 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
2774 |
//two drivers + passangers killed in train v |
0 | 2775 |
num = 2 + CountPassengersInTrain(v); |
1434
e3f4a55b8bcc
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
tron
parents:
1432
diff
changeset
|
2776 |
if (!(coll->vehstatus & VS_CRASHED)) |
0 | 2777 |
//two drivers + passangers killed in train coll (if it was not crashed already) |
2778 |
num += 2 + CountPassengersInTrain(coll); |
|
2779 |
||
2780 |
SetVehicleCrashed(v); |
|
2639 | 2781 |
if (coll->subtype == TS_Front_Engine) SetVehicleCrashed(coll); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
2782 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
2783 |
SetDParam(0, num); |
0 | 2784 |
AddNewsItem(STR_8868_TRAIN_CRASH_DIE_IN_FIREBALL, |
1434
e3f4a55b8bcc
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
tron
parents:
1432
diff
changeset
|
2785 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_VEHICLE, NT_ACCIDENT, 0), |
0 | 2786 |
v->index, |
1434
e3f4a55b8bcc
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
tron
parents:
1432
diff
changeset
|
2787 |
0 |
e3f4a55b8bcc
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
tron
parents:
1432
diff
changeset
|
2788 |
); |
0 | 2789 |
|
2790 |
ModifyStationRatingAround(v->tile, v->owner, -160, 30); |
|
541 | 2791 |
SndPlayVehicleFx(SND_13_BIG_CRASH, v); |
0 | 2792 |
} |
2793 |
||
1432
768af765b5be
(svn r1936) End some void-pointer-as-int-abuse; this also fixes a latent bug where a TileIndex was only 24bit wide (on 32bit architectures)
tron
parents:
1431
diff
changeset
|
2794 |
typedef struct VehicleAtSignalData { |
768af765b5be
(svn r1936) End some void-pointer-as-int-abuse; this also fixes a latent bug where a TileIndex was only 24bit wide (on 32bit architectures)
tron
parents:
1431
diff
changeset
|
2795 |
TileIndex tile; |
768af765b5be
(svn r1936) End some void-pointer-as-int-abuse; this also fixes a latent bug where a TileIndex was only 24bit wide (on 32bit architectures)
tron
parents:
1431
diff
changeset
|
2796 |
byte direction; |
768af765b5be
(svn r1936) End some void-pointer-as-int-abuse; this also fixes a latent bug where a TileIndex was only 24bit wide (on 32bit architectures)
tron
parents:
1431
diff
changeset
|
2797 |
} VehicleAtSignalData; |
768af765b5be
(svn r1936) End some void-pointer-as-int-abuse; this also fixes a latent bug where a TileIndex was only 24bit wide (on 32bit architectures)
tron
parents:
1431
diff
changeset
|
2798 |
|
0 | 2799 |
static void *CheckVehicleAtSignal(Vehicle *v, void *data) |
2800 |
{ |
|
1432
768af765b5be
(svn r1936) End some void-pointer-as-int-abuse; this also fixes a latent bug where a TileIndex was only 24bit wide (on 32bit architectures)
tron
parents:
1431
diff
changeset
|
2801 |
const VehicleAtSignalData* vasd = data; |
768af765b5be
(svn r1936) End some void-pointer-as-int-abuse; this also fixes a latent bug where a TileIndex was only 24bit wide (on 32bit architectures)
tron
parents:
1431
diff
changeset
|
2802 |
|
768af765b5be
(svn r1936) End some void-pointer-as-int-abuse; this also fixes a latent bug where a TileIndex was only 24bit wide (on 32bit architectures)
tron
parents:
1431
diff
changeset
|
2803 |
if (v->type == VEH_Train && v->subtype == TS_Front_Engine && |
768af765b5be
(svn r1936) End some void-pointer-as-int-abuse; this also fixes a latent bug where a TileIndex was only 24bit wide (on 32bit architectures)
tron
parents:
1431
diff
changeset
|
2804 |
v->tile == vasd->tile) { |
768af765b5be
(svn r1936) End some void-pointer-as-int-abuse; this also fixes a latent bug where a TileIndex was only 24bit wide (on 32bit architectures)
tron
parents:
1431
diff
changeset
|
2805 |
byte diff = (v->direction - vasd->direction + 2) & 7; |
768af765b5be
(svn r1936) End some void-pointer-as-int-abuse; this also fixes a latent bug where a TileIndex was only 24bit wide (on 32bit architectures)
tron
parents:
1431
diff
changeset
|
2806 |
|
0 | 2807 |
if (diff == 2 || (v->cur_speed <= 5 && diff <= 4)) |
1432
768af765b5be
(svn r1936) End some void-pointer-as-int-abuse; this also fixes a latent bug where a TileIndex was only 24bit wide (on 32bit architectures)
tron
parents:
1431
diff
changeset
|
2808 |
return v; |
0 | 2809 |
} |
1432
768af765b5be
(svn r1936) End some void-pointer-as-int-abuse; this also fixes a latent bug where a TileIndex was only 24bit wide (on 32bit architectures)
tron
parents:
1431
diff
changeset
|
2810 |
return NULL; |
0 | 2811 |
} |
2812 |
||
2813 |
static void TrainController(Vehicle *v) |
|
2814 |
{ |
|
1961
60efcaa14311
(svn r2467) - Fix: [newgrf] Prevent trains with shorter wagons breaking apart when reversing in some cases. (Therax)
hackykid
parents:
1942
diff
changeset
|
2815 |
Vehicle *prev; |
0 | 2816 |
GetNewVehiclePosResult gp; |
2817 |
uint32 r, tracks,ts; |
|
1247 | 2818 |
int i, enterdir, newdir, dir; |
0 | 2819 |
byte chosen_dir; |
2820 |
byte chosen_track; |
|
2821 |
byte old_z; |
|
2822 |
||
22 | 2823 |
/* For every vehicle after and including the given vehicle */ |
1961
60efcaa14311
(svn r2467) - Fix: [newgrf] Prevent trains with shorter wagons breaking apart when reversing in some cases. (Therax)
hackykid
parents:
1942
diff
changeset
|
2824 |
for (prev = GetPrevVehicleInChain(v); v != NULL; prev = v, v = v->next) { |
0 | 2825 |
BeginVehicleMove(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
2826 |
|
0 | 2827 |
if (v->u.rail.track != 0x40) { |
22 | 2828 |
/* Not inside tunnel */ |
0 | 2829 |
if (GetNewVehiclePos(v, &gp)) { |
22 | 2830 |
/* Staying in the old tile */ |
0 | 2831 |
if (v->u.rail.track == 0x80) { |
2832 |
/* inside depot */ |
|
2833 |
gp.x = v->x_pos; |
|
2834 |
gp.y = v->y_pos; |
|
2835 |
} else { |
|
22 | 2836 |
/* is not inside depot */ |
742
c71e6120b789
(svn r1198) -Fix: [ 1087701 ] It is no longer possible to crash trains of other
truelight
parents:
737
diff
changeset
|
2837 |
|
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2838 |
if ((prev == NULL) && (!TrainCheckIfLineEnds(v))) |
742
c71e6120b789
(svn r1198) -Fix: [ 1087701 ] It is no longer possible to crash trains of other
truelight
parents:
737
diff
changeset
|
2839 |
return; |
c71e6120b789
(svn r1198) -Fix: [ 1087701 ] It is no longer possible to crash trains of other
truelight
parents:
737
diff
changeset
|
2840 |
|
0 | 2841 |
r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y); |
1247 | 2842 |
if (r & 0x8) { |
2843 |
//debug("%x & 0x8", r); |
|
0 | 2844 |
goto invalid_rail; |
1247 | 2845 |
} |
0 | 2846 |
if (r & 0x2) { |
2847 |
TrainEnterStation(v, r >> 8); |
|
2848 |
return; |
|
2849 |
} |
|
2850 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
2851 |
if (v->current_order.type == OT_LEAVESTATION) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
2852 |
v->current_order.type = OT_NOTHING; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
2853 |
v->current_order.flags = 0; |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
744
diff
changeset
|
2854 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 2855 |
} |
2856 |
} |
|
2857 |
} else { |
|
2858 |
/* A new tile is about to be entered. */ |
|
2859 |
||
1247 | 2860 |
byte bits; |
0 | 2861 |
/* Determine what direction we're entering the new tile from */ |
2862 |
dir = GetNewVehicleDirectionByTile(gp.new_tile, gp.old_tile); |
|
1247 | 2863 |
enterdir = dir >> 1; |
2864 |
assert(enterdir==0 || enterdir==1 || enterdir==2 || enterdir==3); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
2865 |
|
0 | 2866 |
/* Get the status of the tracks in the new tile and mask |
2867 |
* away the bits that aren't reachable. */ |
|
1247 | 2868 |
ts = GetTileTrackStatus(gp.new_tile, TRANSPORT_RAIL) & _reachable_tracks[enterdir]; |
0 | 2869 |
|
2870 |
/* Combine the from & to directions. |
|
2871 |
* Now, the lower byte contains the track status, and the byte at bit 16 contains |
|
2872 |
* the signal status. */ |
|
2873 |
tracks = ts|(ts >> 8); |
|
1247 | 2874 |
bits = tracks & 0xFF; |
2875 |
if (_patches.new_pathfinding_all && _patches.forbid_90_deg && prev == NULL) |
|
2876 |
/* We allow wagons to make 90 deg turns, because forbid_90_deg |
|
2877 |
* can be switched on halfway a turn */ |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1935
diff
changeset
|
2878 |
bits &= ~TrackCrossesTracks(FIND_FIRST_BIT(v->u.rail.track)); |
1247 | 2879 |
|
2880 |
if ( bits == 0) { |
|
2881 |
//debug("%x == 0", bits); |
|
0 | 2882 |
goto invalid_rail; |
1247 | 2883 |
} |
0 | 2884 |
|
2885 |
/* Check if the new tile contrains tracks that are compatible |
|
2886 |
* with the current train, if not, bail out. */ |
|
1247 | 2887 |
if (!CheckCompatibleRail(v, gp.new_tile)) { |
2888 |
//debug("!CheckCompatibleRail(%p, %x)", v, gp.new_tile); |
|
0 | 2889 |
goto invalid_rail; |
1247 | 2890 |
} |
0 | 2891 |
|
2892 |
if (prev == NULL) { |
|
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2893 |
byte trackdir; |
0 | 2894 |
/* Currently the locomotive is active. Determine which one of the |
2895 |
* available tracks to choose */ |
|
1247 | 2896 |
chosen_track = 1 << ChooseTrainTrack(v, gp.new_tile, enterdir, bits); |
2897 |
assert(chosen_track & tracks); |
|
0 | 2898 |
|
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2899 |
trackdir = TrackEnterdirToTrackdir(FIND_FIRST_BIT(chosen_track), enterdir); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2900 |
assert(trackdir != 0xff); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2901 |
|
2451
f7d6ed0f564d
(svn r2977) - CodeChange: [pbs] Use a check to see if a rail segment is a pbs segment, instead of letting the pathfinder determine this.
hackykid
parents:
2441
diff
changeset
|
2902 |
if (PBSIsPbsSignal(gp.new_tile,trackdir) && PBSIsPbsSegment(gp.new_tile,trackdir)) { |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2903 |
// encountered a pbs signal, and possible a pbs block |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2904 |
DEBUG(pbs, 3) ("pbs: (%i) arrive AT signal, tile:%x pbs_stat:%i",v->unitnumber, gp.new_tile, v->u.rail.pbs_status); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2905 |
|
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2906 |
if (v->u.rail.pbs_status == PBS_STAT_NONE) { |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2907 |
// we havent planned a path already, so try to find one now |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2908 |
NPFFindStationOrTileData fstd; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2909 |
NPFFoundTargetData ftd; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2910 |
|
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2911 |
NPFFillWithOrderData(&fstd, v); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2912 |
|
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2913 |
DEBUG(pbs, 2) ("pbs: (%i) choose signal (TC), tile:%x, trackdir:%i",v->unitnumber, gp.new_tile, trackdir); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2914 |
ftd = NPFRouteToStationOrTile(gp.new_tile, trackdir, &fstd, TRANSPORT_RAIL, v->owner, v->u.rail.railtype, PBS_MODE_GREEN); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2915 |
|
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2916 |
if (v->u.rail.force_proceed != 0) |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2917 |
goto green_light; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2918 |
|
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2919 |
if (ftd.best_trackdir == 0xFF) |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2920 |
goto red_light; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2921 |
|
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2922 |
// we found a way out of the pbs block |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2923 |
if (NPFGetFlag(&ftd.node, NPF_FLAG_PBS_EXIT)) { |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2924 |
if (NPFGetFlag(&ftd.node, NPF_FLAG_PBS_BLOCKED) || NPFGetFlag(&ftd.node, NPF_FLAG_PBS_RED)) |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2925 |
goto red_light; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2926 |
else { |
2115
99198b563a9c
(svn r2625) - Fix: [pbs] Store the end of a train's reserved path explicitly. Prevents trains from unreserving eachothers paths in some cases.
hackykid
parents:
2049
diff
changeset
|
2927 |
v->u.rail.pbs_end_tile = ftd.node.tile; |
99198b563a9c
(svn r2625) - Fix: [pbs] Store the end of a train's reserved path explicitly. Prevents trains from unreserving eachothers paths in some cases.
hackykid
parents:
2049
diff
changeset
|
2928 |
v->u.rail.pbs_end_trackdir = ftd.node.direction; |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2929 |
goto green_light; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2930 |
} |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2931 |
|
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2932 |
}; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2933 |
|
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2934 |
} else { |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2935 |
// we have already planned a path through this pbs block |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2936 |
// on entering the block, we reset our status |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2937 |
v->u.rail.pbs_status = PBS_STAT_NONE; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2938 |
goto green_light; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2939 |
}; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2940 |
DEBUG(pbs, 3) ("pbs: (%i) no green light found, or was no pbs-block",v->unitnumber); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2941 |
}; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2942 |
|
0 | 2943 |
/* Check if it's a red signal and that force proceed is not clicked. */ |
2944 |
if ( (tracks>>16)&chosen_track && v->u.rail.force_proceed == 0) goto red_light; |
|
2945 |
} else { |
|
2946 |
static byte _matching_tracks[8] = {0x30, 1, 0xC, 2, 0x30, 1, 0xC, 2}; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
2947 |
|
0 | 2948 |
/* The wagon is active, simply follow the prev vehicle. */ |
1247 | 2949 |
chosen_track = (byte)(_matching_tracks[GetDirectionToVehicle(prev, gp.x, gp.y)] & bits); |
0 | 2950 |
} |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2951 |
green_light: |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2952 |
if (v->next == NULL) |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2953 |
PBSClearTrack(gp.old_tile, FIND_FIRST_BIT(v->u.rail.track)); |
0 | 2954 |
|
2955 |
/* make sure chosen track is a valid track */ |
|
2956 |
assert(chosen_track==1 || chosen_track==2 || chosen_track==4 || chosen_track==8 || chosen_track==16 || chosen_track==32); |
|
2957 |
||
2958 |
/* Update XY to reflect the entrance to the new tile, and select the direction to use */ |
|
2959 |
{ |
|
1247 | 2960 |
const byte *b = _initial_tile_subcoord[FIND_FIRST_BIT(chosen_track)][enterdir]; |
0 | 2961 |
gp.x = (gp.x & ~0xF) | b[0]; |
2962 |
gp.y = (gp.y & ~0xF) | b[1]; |
|
2963 |
chosen_dir = b[2]; |
|
2964 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
2965 |
|
0 | 2966 |
/* Call the landscape function and tell it that the vehicle entered the tile */ |
2967 |
r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y); |
|
1247 | 2968 |
if (r&0x8){ |
2969 |
//debug("%x & 0x8", r); |
|
0 | 2970 |
goto invalid_rail; |
1247 | 2971 |
} |
0 | 2972 |
|
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1064
diff
changeset
|
2973 |
if (v->subtype == TS_Front_Engine) v->load_unload_time_rem = 0; |
0 | 2974 |
|
2975 |
if (!(r&0x4)) { |
|
2976 |
v->tile = gp.new_tile; |
|
2977 |
v->u.rail.track = chosen_track; |
|
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
2978 |
assert(v->u.rail.track); |
0 | 2979 |
} |
2980 |
||
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1064
diff
changeset
|
2981 |
if (v->subtype == TS_Front_Engine) |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2982 |
TrainMovedChangeSignals(gp.new_tile, enterdir); |
0 | 2983 |
|
22 | 2984 |
/* Signals can only change when the first |
2985 |
* (above) or the last vehicle moves. */ |
|
0 | 2986 |
if (v->next == NULL) |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2987 |
TrainMovedChangeSignals(gp.old_tile, (enterdir) ^ 2); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
2988 |
|
0 | 2989 |
if (prev == NULL) { |
2990 |
AffectSpeedByDirChange(v, chosen_dir); |
|
2991 |
} |
|
2992 |
||
2993 |
v->direction = chosen_dir; |
|
2994 |
} |
|
2995 |
} else { |
|
2996 |
/* in tunnel */ |
|
2997 |
GetNewVehiclePos(v, &gp); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
2998 |
|
2125
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2115
diff
changeset
|
2999 |
// Check if to exit the tunnel... |
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2115
diff
changeset
|
3000 |
if (!IsTunnelTile(gp.new_tile) || |
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2115
diff
changeset
|
3001 |
!(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y)&0x4) ) { |
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2115
diff
changeset
|
3002 |
v->x_pos = gp.x; |
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2115
diff
changeset
|
3003 |
v->y_pos = gp.y; |
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2115
diff
changeset
|
3004 |
VehiclePositionChanged(v); |
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2115
diff
changeset
|
3005 |
continue; |
0 | 3006 |
} |
3007 |
} |
|
3008 |
||
3009 |
/* update image of train, as well as delta XY */ |
|
1247 | 3010 |
newdir = GetNewVehicleDirection(v, gp.x, gp.y); |
3011 |
UpdateTrainDeltaXY(v, newdir); |
|
3012 |
v->cur_image = GetTrainImage(v, newdir); |
|
0 | 3013 |
|
3014 |
v->x_pos = gp.x; |
|
3015 |
v->y_pos = gp.y; |
|
3016 |
||
3017 |
/* update the Z position of the vehicle */ |
|
954
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
3018 |
old_z = AfterSetTrainPos(v, (gp.new_tile != gp.old_tile)); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
3019 |
|
0 | 3020 |
if (prev == NULL) { |
22 | 3021 |
/* This is the first vehicle in the train */ |
0 | 3022 |
AffectSpeedByZChange(v, old_z); |
3023 |
} |
|
3024 |
} |
|
1438 | 3025 |
return; |
0 | 3026 |
|
3027 |
invalid_rail: |
|
22 | 3028 |
/* We've reached end of line?? */ |
2639 | 3029 |
if (prev != NULL) error("!Disconnecting train"); |
0 | 3030 |
goto reverse_train_direction; |
3031 |
||
3032 |
red_light: { |
|
22 | 3033 |
/* We're in front of a red signal ?? */ |
0 | 3034 |
/* find the first set bit in ts. need to do it in 2 steps, since |
3035 |
* FIND_FIRST_BIT only handles 6 bits at a time. */ |
|
3036 |
i = FindFirstBit2x64(ts); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
3037 |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2044
diff
changeset
|
3038 |
if (!(_m[gp.new_tile].m3 & SignalAgainstTrackdir(i))) { |
0 | 3039 |
v->cur_speed = 0; |
3040 |
v->subspeed = 0; |
|
3041 |
v->progress = 255-100; |
|
3042 |
if (++v->load_unload_time_rem < _patches.wait_oneway_signal * 20) |
|
3043 |
return; |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2044
diff
changeset
|
3044 |
} else if (_m[gp.new_tile].m3 & SignalAlongTrackdir(i)){ |
0 | 3045 |
v->cur_speed = 0; |
3046 |
v->subspeed = 0; |
|
3047 |
v->progress = 255-10; |
|
3048 |
if (++v->load_unload_time_rem < _patches.wait_twoway_signal * 73) { |
|
1432
768af765b5be
(svn r1936) End some void-pointer-as-int-abuse; this also fixes a latent bug where a TileIndex was only 24bit wide (on 32bit architectures)
tron
parents:
1431
diff
changeset
|
3049 |
TileIndex o_tile = gp.new_tile + TileOffsByDir(enterdir); |
1507
18cb39ddddfd
(svn r2011) - Fix: [ 1162209 ] Fix OS/2 build (orudge) #2
darkvater
parents:
1475
diff
changeset
|
3050 |
VehicleAtSignalData vasd; |
18cb39ddddfd
(svn r2011) - Fix: [ 1162209 ] Fix OS/2 build (orudge) #2
darkvater
parents:
1475
diff
changeset
|
3051 |
vasd.tile = o_tile; |
18cb39ddddfd
(svn r2011) - Fix: [ 1162209 ] Fix OS/2 build (orudge) #2
darkvater
parents:
1475
diff
changeset
|
3052 |
vasd.direction = dir ^ 4; |
1432
768af765b5be
(svn r1936) End some void-pointer-as-int-abuse; this also fixes a latent bug where a TileIndex was only 24bit wide (on 32bit architectures)
tron
parents:
1431
diff
changeset
|
3053 |
|
0 | 3054 |
/* check if a train is waiting on the other side */ |
1432
768af765b5be
(svn r1936) End some void-pointer-as-int-abuse; this also fixes a latent bug where a TileIndex was only 24bit wide (on 32bit architectures)
tron
parents:
1431
diff
changeset
|
3055 |
if (VehicleFromPos(o_tile, &vasd, CheckVehicleAtSignal) == NULL) |
0 | 3056 |
return; |
3057 |
} |
|
3058 |
} |
|
3059 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
3060 |
|
0 | 3061 |
reverse_train_direction: |
3062 |
v->load_unload_time_rem = 0; |
|
3063 |
v->cur_speed = 0; |
|
3064 |
v->subspeed = 0; |
|
3065 |
ReverseTrainDirection(v); |
|
3066 |
} |
|
3067 |
||
1430
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1418
diff
changeset
|
3068 |
extern TileIndex CheckTunnelBusy(TileIndex tile, uint *length); |
98 | 3069 |
|
1418
f71b68950a6f
(svn r1922) - Fix: Disappearing of crashed trains inside tunnels were not checked properly.
Darkvater
parents:
1394
diff
changeset
|
3070 |
/** |
f71b68950a6f
(svn r1922) - Fix: Disappearing of crashed trains inside tunnels were not checked properly.
Darkvater
parents:
1394
diff
changeset
|
3071 |
* Deletes/Clears the last wagon of a crashed train. It takes the engine of the |
f71b68950a6f
(svn r1922) - Fix: Disappearing of crashed trains inside tunnels were not checked properly.
Darkvater
parents:
1394
diff
changeset
|
3072 |
* train, then goes to the last wagon and deletes that. Each call to this function |
f71b68950a6f
(svn r1922) - Fix: Disappearing of crashed trains inside tunnels were not checked properly.
Darkvater
parents:
1394
diff
changeset
|
3073 |
* will remove the last wagon of a crashed train. If this wagon was on a crossing, |
f71b68950a6f
(svn r1922) - Fix: Disappearing of crashed trains inside tunnels were not checked properly.
Darkvater
parents:
1394
diff
changeset
|
3074 |
* or inside a tunnel, recalculate the signals as they might need updating |
f71b68950a6f
(svn r1922) - Fix: Disappearing of crashed trains inside tunnels were not checked properly.
Darkvater
parents:
1394
diff
changeset
|
3075 |
* @param v the @Vehicle of which last wagon is to be removed |
f71b68950a6f
(svn r1922) - Fix: Disappearing of crashed trains inside tunnels were not checked properly.
Darkvater
parents:
1394
diff
changeset
|
3076 |
*/ |
0 | 3077 |
static void DeleteLastWagon(Vehicle *v) |
3078 |
{ |
|
3079 |
Vehicle *u = v; |
|
1418
f71b68950a6f
(svn r1922) - Fix: Disappearing of crashed trains inside tunnels were not checked properly.
Darkvater
parents:
1394
diff
changeset
|
3080 |
|
f71b68950a6f
(svn r1922) - Fix: Disappearing of crashed trains inside tunnels were not checked properly.
Darkvater
parents:
1394
diff
changeset
|
3081 |
/* Go to the last wagon and delete the link pointing there |
f71b68950a6f
(svn r1922) - Fix: Disappearing of crashed trains inside tunnels were not checked properly.
Darkvater
parents:
1394
diff
changeset
|
3082 |
* *u is then the one-before-last wagon, and *v the last |
f71b68950a6f
(svn r1922) - Fix: Disappearing of crashed trains inside tunnels were not checked properly.
Darkvater
parents:
1394
diff
changeset
|
3083 |
* one which will physicially be removed */ |
1434
e3f4a55b8bcc
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
tron
parents:
1432
diff
changeset
|
3084 |
for (; v->next != NULL; v = v->next) u = v; |
0 | 3085 |
u->next = NULL; |
3086 |
||
3087 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
3088 |
DeleteWindowById(WC_VEHICLE_VIEW, v->index); |
|
588 | 3089 |
RebuildVehicleLists(); |
0 | 3090 |
InvalidateWindow(WC_COMPANY, v->owner); |
3091 |
||
3092 |
BeginVehicleMove(v); |
|
3093 |
EndVehicleMove(v); |
|
3094 |
DeleteVehicle(v); |
|
3095 |
||
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3096 |
// clear up reserved pbs tracks |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3097 |
if (PBSTileReserved(v->tile) & v->u.rail.track) { |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3098 |
if (v == u) { |
2115
99198b563a9c
(svn r2625) - Fix: [pbs] Store the end of a train's reserved path explicitly. Prevents trains from unreserving eachothers paths in some cases.
hackykid
parents:
2049
diff
changeset
|
3099 |
PBSClearPath(v->tile, FIND_FIRST_BIT(v->u.rail.track), v->u.rail.pbs_end_tile, v->u.rail.pbs_end_trackdir); |
99198b563a9c
(svn r2625) - Fix: [pbs] Store the end of a train's reserved path explicitly. Prevents trains from unreserving eachothers paths in some cases.
hackykid
parents:
2049
diff
changeset
|
3100 |
PBSClearPath(v->tile, FIND_FIRST_BIT(v->u.rail.track) + 8, v->u.rail.pbs_end_tile, v->u.rail.pbs_end_trackdir); |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3101 |
}; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3102 |
if (v->tile != u->tile) { |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3103 |
PBSClearTrack(v->tile, FIND_FIRST_BIT(v->u.rail.track)); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3104 |
}; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3105 |
} |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3106 |
|
1418
f71b68950a6f
(svn r1922) - Fix: Disappearing of crashed trains inside tunnels were not checked properly.
Darkvater
parents:
1394
diff
changeset
|
3107 |
if (!(v->u.rail.track & 0xC0)) |
f71b68950a6f
(svn r1922) - Fix: Disappearing of crashed trains inside tunnels were not checked properly.
Darkvater
parents:
1394
diff
changeset
|
3108 |
SetSignalsOnBothDir(v->tile, FIND_FIRST_BIT(v->u.rail.track)); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
3109 |
|
1434
e3f4a55b8bcc
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
tron
parents:
1432
diff
changeset
|
3110 |
/* Check if the wagon was on a road/rail-crossing and disable it if no |
e3f4a55b8bcc
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
tron
parents:
1432
diff
changeset
|
3111 |
* others are on it */ |
1103
530d0a75f91c
(svn r1604) Fix: [ 1105112 ] Destroyed train locks crossings
dominik
parents:
1095
diff
changeset
|
3112 |
DisableTrainCrossing(v->tile); |
530d0a75f91c
(svn r1604) Fix: [ 1105112 ] Destroyed train locks crossings
dominik
parents:
1095
diff
changeset
|
3113 |
|
1418
f71b68950a6f
(svn r1922) - Fix: Disappearing of crashed trains inside tunnels were not checked properly.
Darkvater
parents:
1394
diff
changeset
|
3114 |
if (v->u.rail.track == 0x40) { // inside a tunnel |
1430
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1418
diff
changeset
|
3115 |
TileIndex endtile = CheckTunnelBusy(v->tile, NULL); |
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1418
diff
changeset
|
3116 |
|
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1418
diff
changeset
|
3117 |
if (endtile == INVALID_TILE) // tunnel is busy (error returned) |
1418
f71b68950a6f
(svn r1922) - Fix: Disappearing of crashed trains inside tunnels were not checked properly.
Darkvater
parents:
1394
diff
changeset
|
3118 |
return; |
f71b68950a6f
(svn r1922) - Fix: Disappearing of crashed trains inside tunnels were not checked properly.
Darkvater
parents:
1394
diff
changeset
|
3119 |
|
1431
37f7348421d0
(svn r1935) Missing braces; while here turn the ifs into a single switch
tron
parents:
1430
diff
changeset
|
3120 |
switch (v->direction) { |
37f7348421d0
(svn r1935) Missing braces; while here turn the ifs into a single switch
tron
parents:
1430
diff
changeset
|
3121 |
case 1: |
37f7348421d0
(svn r1935) Missing braces; while here turn the ifs into a single switch
tron
parents:
1430
diff
changeset
|
3122 |
case 5: |
37f7348421d0
(svn r1935) Missing braces; while here turn the ifs into a single switch
tron
parents:
1430
diff
changeset
|
3123 |
SetSignalsOnBothDir(v->tile, 0); |
37f7348421d0
(svn r1935) Missing braces; while here turn the ifs into a single switch
tron
parents:
1430
diff
changeset
|
3124 |
SetSignalsOnBothDir(endtile, 0); |
37f7348421d0
(svn r1935) Missing braces; while here turn the ifs into a single switch
tron
parents:
1430
diff
changeset
|
3125 |
break; |
37f7348421d0
(svn r1935) Missing braces; while here turn the ifs into a single switch
tron
parents:
1430
diff
changeset
|
3126 |
|
37f7348421d0
(svn r1935) Missing braces; while here turn the ifs into a single switch
tron
parents:
1430
diff
changeset
|
3127 |
case 3: |
37f7348421d0
(svn r1935) Missing braces; while here turn the ifs into a single switch
tron
parents:
1430
diff
changeset
|
3128 |
case 7: |
37f7348421d0
(svn r1935) Missing braces; while here turn the ifs into a single switch
tron
parents:
1430
diff
changeset
|
3129 |
SetSignalsOnBothDir(v->tile, 1); |
37f7348421d0
(svn r1935) Missing braces; while here turn the ifs into a single switch
tron
parents:
1430
diff
changeset
|
3130 |
SetSignalsOnBothDir(endtile, 1); |
37f7348421d0
(svn r1935) Missing braces; while here turn the ifs into a single switch
tron
parents:
1430
diff
changeset
|
3131 |
break; |
37f7348421d0
(svn r1935) Missing braces; while here turn the ifs into a single switch
tron
parents:
1430
diff
changeset
|
3132 |
|
37f7348421d0
(svn r1935) Missing braces; while here turn the ifs into a single switch
tron
parents:
1430
diff
changeset
|
3133 |
default: |
37f7348421d0
(svn r1935) Missing braces; while here turn the ifs into a single switch
tron
parents:
1430
diff
changeset
|
3134 |
break; |
37f7348421d0
(svn r1935) Missing braces; while here turn the ifs into a single switch
tron
parents:
1430
diff
changeset
|
3135 |
} |
98 | 3136 |
} |
0 | 3137 |
} |
3138 |
||
3139 |
static void ChangeTrainDirRandomly(Vehicle *v) |
|
3140 |
{ |
|
3141 |
static int8 _random_dir_change[4] = { -1, 0, 0, 1}; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
3142 |
|
0 | 3143 |
do { |
98 | 3144 |
//I need to buffer the train direction |
288
72ca19a694dd
(svn r294) -Fix: autorail always builds rail, instead of occasional rail removal (on pressing hotkey after pressing 'bulldozer')
darkvater
parents:
244
diff
changeset
|
3145 |
if (!(v->u.rail.track & 0x40)) |
2635 | 3146 |
v->direction = (v->direction + _random_dir_change[GB(Random(), 0, 2)]) & 7; |
0 | 3147 |
if (!(v->vehstatus & VS_HIDDEN)) { |
3148 |
BeginVehicleMove(v); |
|
3149 |
UpdateTrainDeltaXY(v, v->direction); |
|
3150 |
v->cur_image = GetTrainImage(v, v->direction); |
|
954
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
3151 |
AfterSetTrainPos(v, false); |
0 | 3152 |
} |
3153 |
} while ( (v=v->next) != NULL); |
|
3154 |
} |
|
3155 |
||
3156 |
static void HandleCrashedTrain(Vehicle *v) |
|
3157 |
{ |
|
3158 |
int state = ++v->u.rail.crash_anim_pos, index; |
|
3159 |
uint32 r; |
|
3160 |
Vehicle *u; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
3161 |
|
2639 | 3162 |
if (state == 4 && v->u.rail.track != 0x40) { |
1359
52782e5cf7c9
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1337
diff
changeset
|
3163 |
CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE); |
0 | 3164 |
} |
3165 |
||
2637
722dae65c4a8
(svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents:
2635
diff
changeset
|
3166 |
if (state <= 200 && CHANCE16R(1, 7, r)) { |
0 | 3167 |
index = (r * 10 >> 16); |
3168 |
||
3169 |
u = v; |
|
3170 |
do { |
|
3171 |
if (--index < 0) { |
|
1137
bce056e230ce
(svn r1638) -Fix: Train crashes should no longer desync the game. This is more of a
celestar
parents:
1132
diff
changeset
|
3172 |
r = Random(); |
0 | 3173 |
|
3174 |
CreateEffectVehicleRel(u, |
|
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2135
diff
changeset
|
3175 |
GB(r, 8, 3) + 2, |
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2135
diff
changeset
|
3176 |
GB(r, 16, 3) + 2, |
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2135
diff
changeset
|
3177 |
GB(r, 0, 3) + 5, |
1359
52782e5cf7c9
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1337
diff
changeset
|
3178 |
EV_EXPLOSION_SMALL); |
0 | 3179 |
break; |
3180 |
} |
|
3181 |
} while ( (u=u->next) != NULL); |
|
3182 |
} |
|
3183 |
||
3184 |
if (state <= 240 && !(v->tick_counter&3)) { |
|
3185 |
ChangeTrainDirRandomly(v); |
|
3186 |
} |
|
3187 |
||
1128
ca7f860db7ac
(svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents:
1109
diff
changeset
|
3188 |
if (state >= 4440 && !(v->tick_counter&0x1F)) { |
0 | 3189 |
DeleteLastWagon(v); |
1128
ca7f860db7ac
(svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents:
1109
diff
changeset
|
3190 |
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Train); |
ca7f860db7ac
(svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents:
1109
diff
changeset
|
3191 |
} |
0 | 3192 |
} |
3193 |
||
3194 |
static void HandleBrokenTrain(Vehicle *v) |
|
3195 |
{ |
|
3196 |
if (v->breakdown_ctr != 1) { |
|
3197 |
v->breakdown_ctr = 1; |
|
3198 |
v->cur_speed = 0; |
|
3199 |
||
3200 |
if (v->breakdowns_since_last_service != 255) |
|
3201 |
v->breakdowns_since_last_service++; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
3202 |
|
0 | 3203 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
3204 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
3205 |
|
541 | 3206 |
SndPlayVehicleFx((_opt.landscape != LT_CANDY) ? |
3207 |
SND_10_TRAIN_BREAKDOWN : SND_3A_COMEDY_BREAKDOWN_2, v); |
|
0 | 3208 |
|
3209 |
if (!(v->vehstatus & VS_HIDDEN)) { |
|
3210 |
Vehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE); |
|
2549 | 3211 |
if (u != NULL) u->u.special.unk0 = v->breakdown_delay * 2; |
0 | 3212 |
} |
3213 |
} |
|
3214 |
||
3215 |
if (!(v->tick_counter & 3)) { |
|
3216 |
if (!--v->breakdown_delay) { |
|
3217 |
v->breakdown_ctr = 0; |
|
3218 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
|
3219 |
} |
|
3220 |
} |
|
3221 |
} |
|
3222 |
||
3223 |
static const byte _breakdown_speeds[16] = { |
|
3224 |
225, 210, 195, 180, 165, 150, 135, 120, 105, 90, 75, 60, 45, 30, 15, 15 |
|
3225 |
}; |
|
3226 |
||
742
c71e6120b789
(svn r1198) -Fix: [ 1087701 ] It is no longer possible to crash trains of other
truelight
parents:
737
diff
changeset
|
3227 |
static bool TrainCheckIfLineEnds(Vehicle *v) |
0 | 3228 |
{ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1969
diff
changeset
|
3229 |
TileIndex tile; |
0 | 3230 |
uint x,y; |
2484
0e45d70ae908
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents:
2482
diff
changeset
|
3231 |
uint16 break_speed; |
0 | 3232 |
int t; |
3233 |
uint32 ts; |
|
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3234 |
byte trackdir; |
0 | 3235 |
|
2484
0e45d70ae908
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents:
2482
diff
changeset
|
3236 |
t = v->breakdown_ctr; |
0e45d70ae908
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents:
2482
diff
changeset
|
3237 |
if (t > 1) { |
0 | 3238 |
v->vehstatus |= VS_TRAIN_SLOWING; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
3239 |
|
2484
0e45d70ae908
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents:
2482
diff
changeset
|
3240 |
break_speed = _breakdown_speeds[GB(~t, 4, 4)]; |
0e45d70ae908
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents:
2482
diff
changeset
|
3241 |
if (break_speed < v->cur_speed) v->cur_speed = break_speed; |
0 | 3242 |
} else { |
3243 |
v->vehstatus &= ~VS_TRAIN_SLOWING; |
|
3244 |
} |
|
3245 |
||
2639 | 3246 |
if (v->u.rail.track & 0x40) return true; // exit if inside a tunnel |
3247 |
if (v->u.rail.track & 0x80) return true; // exit if inside a depot |
|
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3248 |
|
0 | 3249 |
tile = v->tile; |
3250 |
||
3251 |
// tunnel entrance? |
|
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
3252 |
if (IsTunnelTile(tile) && GB(_m[tile].m5, 0, 2) * 2 + 1 == v->direction) |
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
3253 |
return true; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
3254 |
|
0 | 3255 |
// depot? |
742
c71e6120b789
(svn r1198) -Fix: [ 1087701 ] It is no longer possible to crash trains of other
truelight
parents:
737
diff
changeset
|
3256 |
/* XXX -- When enabled, this makes it possible to crash trains of others |
c71e6120b789
(svn r1198) -Fix: [ 1087701 ] It is no longer possible to crash trains of other
truelight
parents:
737
diff
changeset
|
3257 |
(by building a depot right against a station) */ |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2044
diff
changeset
|
3258 |
/* if (IsTileType(tile, MP_RAILWAY) && (_m[tile].m5 & 0xFC) == 0xC0) |
742
c71e6120b789
(svn r1198) -Fix: [ 1087701 ] It is no longer possible to crash trains of other
truelight
parents:
737
diff
changeset
|
3259 |
return true;*/ |
0 | 3260 |
|
22 | 3261 |
/* Determine the non-diagonal direction in which we will exit this tile */ |
0 | 3262 |
t = v->direction >> 1; |
3263 |
if (!(v->direction & 1) && v->u.rail.track != _state_dir_table[t]) { |
|
3264 |
t = (t - 1) & 3; |
|
3265 |
} |
|
22 | 3266 |
/* Calculate next tile */ |
900 | 3267 |
tile += TileOffsByDir(t); |
22 | 3268 |
// determine the track status on the next tile. |
1151
06c115ce7b7a
(svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents:
1137
diff
changeset
|
3269 |
ts = GetTileTrackStatus(tile, TRANSPORT_RAIL) & _reachable_tracks[t]; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
3270 |
|
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3271 |
// if there are tracks on the new tile, pick one (trackdir will only be used when its a signal tile, in which case only 1 trackdir is accessible for us) |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3272 |
if (ts & TRACKDIR_BIT_MASK) |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3273 |
trackdir = FindFirstBit2x64(ts & TRACKDIR_BIT_MASK); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3274 |
else |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3275 |
trackdir = INVALID_TRACKDIR; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3276 |
|
22 | 3277 |
/* Calc position within the current tile ?? */ |
0 | 3278 |
x = v->x_pos & 0xF; |
3279 |
y = v->y_pos & 0xF; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
3280 |
|
2639 | 3281 |
switch (v->direction) { |
0 | 3282 |
case 0: |
3283 |
x = (~x) + (~y) + 24; |
|
3284 |
break; |
|
3285 |
case 7: |
|
3286 |
x = y; |
|
3287 |
/* fall through */ |
|
3288 |
case 1: |
|
3289 |
x = (~x) + 16; |
|
3290 |
break; |
|
3291 |
case 2: |
|
3292 |
x = (~x) + y + 8; |
|
3293 |
break; |
|
3294 |
case 3: |
|
3295 |
x = y; |
|
3296 |
break; |
|
3297 |
case 4: |
|
3298 |
x = x + y - 8; |
|
3299 |
break; |
|
3300 |
case 6: |
|
3301 |
x = (~y) + x + 8; |
|
3302 |
break; |
|
3303 |
} |
|
3304 |
||
2484
0e45d70ae908
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents:
2482
diff
changeset
|
3305 |
if (GB(ts, 0, 16) != 0) { |
742
c71e6120b789
(svn r1198) -Fix: [ 1087701 ] It is no longer possible to crash trains of other
truelight
parents:
737
diff
changeset
|
3306 |
/* If we approach a rail-piece which we can't enter, don't enter it! */ |
c71e6120b789
(svn r1198) -Fix: [ 1087701 ] It is no longer possible to crash trains of other
truelight
parents:
737
diff
changeset
|
3307 |
if (x + 4 > 15 && !CheckCompatibleRail(v, tile)) { |
c71e6120b789
(svn r1198) -Fix: [ 1087701 ] It is no longer possible to crash trains of other
truelight
parents:
737
diff
changeset
|
3308 |
v->cur_speed = 0; |
c71e6120b789
(svn r1198) -Fix: [ 1087701 ] It is no longer possible to crash trains of other
truelight
parents:
737
diff
changeset
|
3309 |
ReverseTrainDirection(v); |
c71e6120b789
(svn r1198) -Fix: [ 1087701 ] It is no longer possible to crash trains of other
truelight
parents:
737
diff
changeset
|
3310 |
return false; |
c71e6120b789
(svn r1198) -Fix: [ 1087701 ] It is no longer possible to crash trains of other
truelight
parents:
737
diff
changeset
|
3311 |
} |
0 | 3312 |
if ((ts &= (ts >> 16)) == 0) { |
3313 |
// make a rail/road crossing red |
|
1927
1181e7652e2f
(svn r2433) - CodeChange: unmagicify all road/train crossings with IsLevelCrossing() function (peter1138)
Darkvater
parents:
1926
diff
changeset
|
3314 |
if (IsTileType(tile, MP_STREET) && IsLevelCrossing(tile)) { |
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2484
diff
changeset
|
3315 |
if (GB(_m[tile].m5, 2, 1) == 0) { |
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2484
diff
changeset
|
3316 |
SB(_m[tile].m5, 2, 1, 1); |
541 | 3317 |
SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v); |
0 | 3318 |
MarkTileDirtyByTile(tile); |
3319 |
} |
|
3320 |
} |
|
742
c71e6120b789
(svn r1198) -Fix: [ 1087701 ] It is no longer possible to crash trains of other
truelight
parents:
737
diff
changeset
|
3321 |
return true; |
0 | 3322 |
} |
3323 |
} else if (x + 4 > 15) { |
|
3324 |
v->cur_speed = 0; |
|
3325 |
ReverseTrainDirection(v); |
|
742
c71e6120b789
(svn r1198) -Fix: [ 1087701 ] It is no longer possible to crash trains of other
truelight
parents:
737
diff
changeset
|
3326 |
return false; |
0 | 3327 |
} |
3328 |
||
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3329 |
if (v->u.rail.pbs_status == PBS_STAT_HAS_PATH) |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3330 |
return true; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3331 |
|
2451
f7d6ed0f564d
(svn r2977) - CodeChange: [pbs] Use a check to see if a rail segment is a pbs segment, instead of letting the pathfinder determine this.
hackykid
parents:
2441
diff
changeset
|
3332 |
if ((trackdir != INVALID_TRACKDIR) && (PBSIsPbsSignal(tile,trackdir) && PBSIsPbsSegment(tile,trackdir)) && !(IsTileType(v->tile, MP_STATION) && (v->current_order.station == _m[v->tile].m2))) { |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3333 |
NPFFindStationOrTileData fstd; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3334 |
NPFFoundTargetData ftd; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3335 |
|
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3336 |
NPFFillWithOrderData(&fstd, v); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3337 |
|
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3338 |
DEBUG(pbs, 2) ("pbs: (%i) choose signal (CEOL), tile:%x trackdir:%i", v->unitnumber, tile, trackdir); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3339 |
ftd = NPFRouteToStationOrTile(tile, trackdir, &fstd, TRANSPORT_RAIL, v->owner, v->u.rail.railtype, PBS_MODE_GREEN); |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3340 |
|
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3341 |
if (ftd.best_trackdir != 0xFF && NPFGetFlag(&ftd.node, NPF_FLAG_PBS_EXIT)) { |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3342 |
if (!(NPFGetFlag(&ftd.node, NPF_FLAG_PBS_BLOCKED) || NPFGetFlag(&ftd.node, NPF_FLAG_PBS_RED))) { |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3343 |
v->u.rail.pbs_status = PBS_STAT_HAS_PATH; |
2115
99198b563a9c
(svn r2625) - Fix: [pbs] Store the end of a train's reserved path explicitly. Prevents trains from unreserving eachothers paths in some cases.
hackykid
parents:
2049
diff
changeset
|
3344 |
v->u.rail.pbs_end_tile = ftd.node.tile; |
99198b563a9c
(svn r2625) - Fix: [pbs] Store the end of a train's reserved path explicitly. Prevents trains from unreserving eachothers paths in some cases.
hackykid
parents:
2049
diff
changeset
|
3345 |
v->u.rail.pbs_end_trackdir = ftd.node.direction; |
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3346 |
return true; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3347 |
} |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3348 |
}; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3349 |
}; |
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
3350 |
|
0 | 3351 |
// slow down |
3352 |
v->vehstatus |= VS_TRAIN_SLOWING; |
|
2484
0e45d70ae908
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents:
2482
diff
changeset
|
3353 |
break_speed = _breakdown_speeds[x & 0xF]; |
0e45d70ae908
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents:
2482
diff
changeset
|
3354 |
if (!(v->direction&1)) break_speed >>= 1; |
0e45d70ae908
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents:
2482
diff
changeset
|
3355 |
if (break_speed < v->cur_speed) v->cur_speed = break_speed; |
742
c71e6120b789
(svn r1198) -Fix: [ 1087701 ] It is no longer possible to crash trains of other
truelight
parents:
737
diff
changeset
|
3356 |
|
c71e6120b789
(svn r1198) -Fix: [ 1087701 ] It is no longer possible to crash trains of other
truelight
parents:
737
diff
changeset
|
3357 |
return true; |
0 | 3358 |
} |
3359 |
||
3360 |
static void TrainLocoHandler(Vehicle *v, bool mode) |
|
3361 |
{ |
|
3362 |
int j; |
|
3363 |
||
3364 |
/* train has crashed? */ |
|
3365 |
if (v->u.rail.crash_anim_pos != 0) { |
|
3366 |
if (!mode) HandleCrashedTrain(v); |
|
3367 |
return; |
|
3368 |
} |
|
3369 |
||
3370 |
if (v->u.rail.force_proceed != 0) |
|
3371 |
v->u.rail.force_proceed--; |
|
3372 |
||
3373 |
/* train is broken down? */ |
|
3374 |
if (v->breakdown_ctr != 0) { |
|
3375 |
if (v->breakdown_ctr <= 2) { |
|
3376 |
HandleBrokenTrain(v); |
|
3377 |
return; |
|
3378 |
} |
|
3379 |
v->breakdown_ctr--; |
|
3380 |
} |
|
3381 |
||
954
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
926
diff
changeset
|
3382 |
if (HASBIT(v->u.rail.flags, VRF_REVERSING) && v->cur_speed == 0) { |
0 | 3383 |
ReverseTrainDirection(v); |
3384 |
} |
|
3385 |
||
3386 |
/* exit if train is stopped */ |
|
3387 |
if (v->vehstatus & VS_STOPPED && v->cur_speed == 0) |
|
3388 |
return; |
|
3389 |
||
3390 |
||
3391 |
if (ProcessTrainOrder(v)) { |
|
3392 |
v->load_unload_time_rem = 0; |
|
3393 |
v->cur_speed = 0; |
|
3394 |
v->subspeed = 0; |
|
3395 |
ReverseTrainDirection(v); |
|
3396 |
return; |
|
3397 |
} |
|
3398 |
||
3399 |
HandleTrainLoading(v, mode); |
|
3400 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
3401 |
if (v->current_order.type == OT_LOADING) |
0 | 3402 |
return; |
3403 |
||
3404 |
if (CheckTrainStayInDepot(v)) |
|
3405 |
return; |
|
3406 |
||
3407 |
if (!mode) HandleLocomotiveSmokeCloud(v); |
|
3408 |
||
3409 |
j = UpdateTrainSpeed(v); |
|
3410 |
if (j == 0) { |
|
3411 |
// if the vehicle has speed 0, update the last_speed field. |
|
3412 |
if (v->cur_speed != 0) |
|
3413 |
return; |
|
3414 |
} else { |
|
3415 |
TrainCheckIfLineEnds(v); |
|
3416 |
||
3417 |
do { |
|
3418 |
TrainController(v); |
|
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1921
diff
changeset
|
3419 |
CheckTrainCollision(v); |
0 | 3420 |
if (v->cur_speed <= 0x100) |
3421 |
break; |
|
3422 |
} while (--j != 0); |
|
3423 |
} |
|
3424 |
||
3425 |
SetLastSpeed(v, v->cur_speed); |
|
3426 |
} |
|
3427 |
||
3428 |
||
3429 |
void Train_Tick(Vehicle *v) |
|
3430 |
{ |
|
3431 |
if (_age_cargo_skip_counter == 0 && v->cargo_days != 0xff) |
|
3432 |
v->cargo_days++; |
|
3433 |
||
3434 |
v->tick_counter++; |
|
3435 |
||
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1064
diff
changeset
|
3436 |
if (v->subtype == TS_Front_Engine) { |
0 | 3437 |
TrainLocoHandler(v, false); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
3438 |
|
0 | 3439 |
// make sure vehicle wasn't deleted. |
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1064
diff
changeset
|
3440 |
if (v->type == VEH_Train && v->subtype == TS_Front_Engine) |
0 | 3441 |
TrainLocoHandler(v, true); |
1132
71a2168ceee1
(svn r1633) -Fix: [1040119] Flood and wagons in depot
darkvater
parents:
1128
diff
changeset
|
3442 |
} else if (v->subtype == TS_Free_Car && HASBITS(v->vehstatus, VS_CRASHED)) { |
71a2168ceee1
(svn r1633) -Fix: [1040119] Flood and wagons in depot
darkvater
parents:
1128
diff
changeset
|
3443 |
// Delete flooded standalone wagon |
71a2168ceee1
(svn r1633) -Fix: [1040119] Flood and wagons in depot
darkvater
parents:
1128
diff
changeset
|
3444 |
if (++v->u.rail.crash_anim_pos >= 4400) |
71a2168ceee1
(svn r1633) -Fix: [1040119] Flood and wagons in depot
darkvater
parents:
1128
diff
changeset
|
3445 |
DeleteVehicle(v); |
0 | 3446 |
} |
3447 |
} |
|
3448 |
||
3449 |
||
3450 |
static const byte _depot_track_ind[4] = {0,1,0,1}; |
|
3451 |
||
715
28dd55cc55ae
(svn r1167) Feature: Added the possibility to add validation functions to NewsItems. This is now done for "Train in depot" messages. Before displaying such a message, it checks if the train really still is in the depot. Can be applied to other news items as well.
dominik
parents:
679
diff
changeset
|
3452 |
// Validation for the news item "Train is waiting in depot" |
1095 | 3453 |
static bool ValidateTrainInDepot( uint data_a, uint data_b ) |
715
28dd55cc55ae
(svn r1167) Feature: Added the possibility to add validation functions to NewsItems. This is now done for "Train in depot" messages. Before displaying such a message, it checks if the train really still is in the depot. Can be applied to other news items as well.
dominik
parents:
679
diff
changeset
|
3454 |
{ |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
3455 |
Vehicle *v = GetVehicle(data_a); |
1064
2242cd7419bb
(svn r1565) -Fix: [ 1104969 ] Aircraft in hangar messages are now revalidated before
celestar
parents:
1060
diff
changeset
|
3456 |
return (v->u.rail.track == 0x80 && (v->vehstatus | VS_STOPPED)); |
715
28dd55cc55ae
(svn r1167) Feature: Added the possibility to add validation functions to NewsItems. This is now done for "Train in depot" messages. Before displaying such a message, it checks if the train really still is in the depot. Can be applied to other news items as well.
dominik
parents:
679
diff
changeset
|
3457 |
} |
28dd55cc55ae
(svn r1167) Feature: Added the possibility to add validation functions to NewsItems. This is now done for "Train in depot" messages. Before displaying such a message, it checks if the train really still is in the depot. Can be applied to other news items as well.
dominik
parents:
679
diff
changeset
|
3458 |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1969
diff
changeset
|
3459 |
void TrainEnterDepot(Vehicle *v, TileIndex tile) |
0 | 3460 |
{ |
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2484
diff
changeset
|
3461 |
SetSignalsOnBothDir(tile, _depot_track_ind[GB(_m[tile].m5, 0, 2)]); |
0 | 3462 |
|
2639 | 3463 |
if (v->subtype != TS_Front_Engine) v = GetFirstVehicleInChain(v); |
0 | 3464 |
|
578
1e66514eb621
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
555
diff
changeset
|
3465 |
VehicleServiceInDepot(v); |
1e66514eb621
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
555
diff
changeset
|
3466 |
|
0 | 3467 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
3468 |
||
3469 |
v->load_unload_time_rem = 0; |
|
3470 |
v->cur_speed = 0; |
|
3471 |
||
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
410
diff
changeset
|
3472 |
TriggerVehicle(v, VEHICLE_TRIGGER_DEPOT); |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
410
diff
changeset
|
3473 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
3474 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
3475 |
Order t; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
3476 |
|
0 | 3477 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
3478 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
3479 |
t = v->current_order; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
3480 |
v->current_order.type = OT_DUMMY; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
3481 |
v->current_order.flags = 0; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
3482 |
|
1530
2b46869fc0d4
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1520
diff
changeset
|
3483 |
if (HASBIT(t.flags, OFB_PART_OF_ORDERS)) { // Part of the orderlist? |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
3484 |
v->u.rail.days_since_order_progr = 0; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
3485 |
v->cur_order_index++; |
1530
2b46869fc0d4
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1520
diff
changeset
|
3486 |
} else if (HASBIT(t.flags, OFB_HALT_IN_DEPOT)) { // User initiated? |
0 | 3487 |
v->vehstatus |= VS_STOPPED; |
3488 |
if (v->owner == _local_player) { |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
3489 |
SetDParam(0, v->unitnumber); |
715
28dd55cc55ae
(svn r1167) Feature: Added the possibility to add validation functions to NewsItems. This is now done for "Train in depot" messages. Before displaying such a message, it checks if the train really still is in the depot. Can be applied to other news items as well.
dominik
parents:
679
diff
changeset
|
3490 |
AddValidatedNewsItem( |
0 | 3491 |
STR_8814_TRAIN_IS_WAITING_IN_DEPOT, |
3492 |
NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), |
|
3493 |
v->index, |
|
715
28dd55cc55ae
(svn r1167) Feature: Added the possibility to add validation functions to NewsItems. This is now done for "Train in depot" messages. Before displaying such a message, it checks if the train really still is in the depot. Can be applied to other news items as well.
dominik
parents:
679
diff
changeset
|
3494 |
0, |
28dd55cc55ae
(svn r1167) Feature: Added the possibility to add validation functions to NewsItems. This is now done for "Train in depot" messages. Before displaying such a message, it checks if the train really still is in the depot. Can be applied to other news items as well.
dominik
parents:
679
diff
changeset
|
3495 |
ValidateTrainInDepot); |
0 | 3496 |
} |
3497 |
} |
|
3498 |
} |
|
1151
06c115ce7b7a
(svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents:
1137
diff
changeset
|
3499 |
InvalidateWindowClasses(WC_TRAINS_LIST); |
0 | 3500 |
} |
3501 |
||
3502 |
static void CheckIfTrainNeedsService(Vehicle *v) |
|
3503 |
{ |
|
2630 | 3504 |
const Depot* depot; |
308
8088f72d10f5
(svn r314) -Fix: [982611] Pathfinding bug; train likes the roundabout. If train needs servicing it will now look 16 tiles along the track instead of 12 tiles manhattan style (blathijs)
darkvater
parents:
300
diff
changeset
|
3505 |
TrainFindDepotData tfdd; |
0 | 3506 |
|
2639 | 3507 |
if (PBSTileReserved(v->tile) & v->u.rail.track) return; |
3508 |
if (v->u.rail.pbs_status == PBS_STAT_HAS_PATH) return; |
|
3509 |
if (_patches.servint_trains == 0) return; |
|
3510 |
if (!VehicleNeedsService(v)) return; |
|
3511 |
if (v->vehstatus & VS_STOPPED) return; |
|
3512 |
if (_patches.gotodepot && VehicleHasDepotOrders(v)) return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
3513 |
|
0 | 3514 |
// Don't interfere with a depot visit scheduled by the user, or a |
3515 |
// depot visit by the order list. |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
3516 |
if (v->current_order.type == OT_GOTO_DEPOT && |
1530
2b46869fc0d4
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1520
diff
changeset
|
3517 |
(v->current_order.flags & (OF_HALT_IN_DEPOT | OF_PART_OF_ORDERS)) != 0) |
0 | 3518 |
return; |
3519 |
||
308
8088f72d10f5
(svn r314) -Fix: [982611] Pathfinding bug; train likes the roundabout. If train needs servicing it will now look 16 tiles along the track instead of 12 tiles manhattan style (blathijs)
darkvater
parents:
300
diff
changeset
|
3520 |
tfdd = FindClosestTrainDepot(v); |
8088f72d10f5
(svn r314) -Fix: [982611] Pathfinding bug; train likes the roundabout. If train needs servicing it will now look 16 tiles along the track instead of 12 tiles manhattan style (blathijs)
darkvater
parents:
300
diff
changeset
|
3521 |
/* Only go to the depot if it is not too far out of our way. */ |
8088f72d10f5
(svn r314) -Fix: [982611] Pathfinding bug; train likes the roundabout. If train needs servicing it will now look 16 tiles along the track instead of 12 tiles manhattan style (blathijs)
darkvater
parents:
300
diff
changeset
|
3522 |
if (tfdd.best_length == (uint)-1 || tfdd.best_length > 16 ) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
3523 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
308
8088f72d10f5
(svn r314) -Fix: [982611] Pathfinding bug; train likes the roundabout. If train needs servicing it will now look 16 tiles along the track instead of 12 tiles manhattan style (blathijs)
darkvater
parents:
300
diff
changeset
|
3524 |
/* If we were already heading for a depot but it has |
8088f72d10f5
(svn r314) -Fix: [982611] Pathfinding bug; train likes the roundabout. If train needs servicing it will now look 16 tiles along the track instead of 12 tiles manhattan style (blathijs)
darkvater
parents:
300
diff
changeset
|
3525 |
* suddenly moved farther away, we continue our normal |
8088f72d10f5
(svn r314) -Fix: [982611] Pathfinding bug; train likes the roundabout. If train needs servicing it will now look 16 tiles along the track instead of 12 tiles manhattan style (blathijs)
darkvater
parents:
300
diff
changeset
|
3526 |
* schedule? */ |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
3527 |
v->current_order.type = OT_DUMMY; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
3528 |
v->current_order.flags = 0; |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
744
diff
changeset
|
3529 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 3530 |
} |
3531 |
return; |
|
3532 |
} |
|
3533 |
||
308
8088f72d10f5
(svn r314) -Fix: [982611] Pathfinding bug; train likes the roundabout. If train needs servicing it will now look 16 tiles along the track instead of 12 tiles manhattan style (blathijs)
darkvater
parents:
300
diff
changeset
|
3534 |
depot = GetDepotByTile(tfdd.tile); |
0 | 3535 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
3536 |
if (v->current_order.type == OT_GOTO_DEPOT && |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
3537 |
v->current_order.station != depot->index && |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
3538 |
!CHANCE16(3,16)) |
0 | 3539 |
return; |
3540 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
3541 |
v->current_order.type = OT_GOTO_DEPOT; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
3542 |
v->current_order.flags = OF_NON_STOP; |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
3543 |
v->current_order.station = depot->index; |
308
8088f72d10f5
(svn r314) -Fix: [982611] Pathfinding bug; train likes the roundabout. If train needs servicing it will now look 16 tiles along the track instead of 12 tiles manhattan style (blathijs)
darkvater
parents:
300
diff
changeset
|
3544 |
v->dest_tile = tfdd.tile; |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
744
diff
changeset
|
3545 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 3546 |
} |
3547 |
||
1790
47963a0cfca3
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1786
diff
changeset
|
3548 |
int32 GetTrainRunningCost(const Vehicle *v) |
0 | 3549 |
{ |
3550 |
int32 cost = 0; |
|
3551 |
||
3552 |
do { |
|
540
2987d7976ea2
(svn r924) Use RailVehInfo() instead of &_rail_vehicle_info[]
tron
parents:
534
diff
changeset
|
3553 |
const RailVehicleInfo *rvi = RailVehInfo(v->engine_type); |
0 | 3554 |
if (rvi->running_cost_base) |
3555 |
cost += rvi->running_cost_base * _price.running_rail[rvi->engclass]; |
|
3556 |
} while ( (v=v->next) != NULL ); |
|
3557 |
||
3558 |
return cost; |
|
3559 |
} |
|
3560 |
||
3561 |
void OnNewDay_Train(Vehicle *v) |
|
3562 |
{ |
|
3563 |
TileIndex tile; |
|
3564 |
||
3565 |
if ((++v->day_counter & 7) == 0) |
|
3566 |
DecreaseVehicleValue(v); |
|
3567 |
||
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1064
diff
changeset
|
3568 |
if (v->subtype == TS_Front_Engine) { |
0 | 3569 |
CheckVehicleBreakdown(v); |
3570 |
AgeVehicle(v); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
3571 |
|
0 | 3572 |
CheckIfTrainNeedsService(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
3573 |
|
0 | 3574 |
// check if train hasn't advanced in its order list for a set number of days |
1057
df5d21eec8bb
(svn r1558) -Fix: [ 1104350 ] Crashed trains do not initiate the lost vehicle
Celestar
parents:
1053
diff
changeset
|
3575 |
if (_patches.lost_train_days && v->num_orders && !(v->vehstatus & (VS_STOPPED | VS_CRASHED) ) && ++v->u.rail.days_since_order_progr >= _patches.lost_train_days && v->owner == _local_player) { |
0 | 3576 |
v->u.rail.days_since_order_progr = 0; |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
3577 |
SetDParam(0, v->unitnumber); |
0 | 3578 |
AddNewsItem( |
3579 |
STR_TRAIN_IS_LOST, |
|
3580 |
NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), |
|
3581 |
v->index, |
|
3582 |
0); |
|
3583 |
} |
|
3584 |
||
1053
8d90844ddc2e
(svn r1554) -Fix: [ 1103187 ] Order Check messages are now validated before
celestar
parents:
1049
diff
changeset
|
3585 |
CheckOrders(v->index, OC_INIT); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
3586 |
|
0 | 3587 |
/* update destination */ |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
3588 |
if (v->current_order.type == OT_GOTO_STATION && |
2639 | 3589 |
(tile = GetStation(v->current_order.station)->train_tile) != 0) { |
3590 |
v->dest_tile = tile; |
|
3591 |
} |
|
0 | 3592 |
|
3593 |
if ((v->vehstatus & VS_STOPPED) == 0) { |
|
3594 |
/* running costs */ |
|
3595 |
int32 cost = GetTrainRunningCost(v) / 364; |
|
3596 |
||
3597 |
v->profit_this_year -= cost >> 8; |
|
3598 |
||
3599 |
SET_EXPENSES_TYPE(EXPENSES_TRAIN_RUN); |
|
3600 |
SubtractMoneyFromPlayerFract(v->owner, cost); |
|
3601 |
||
3602 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1151
06c115ce7b7a
(svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents:
1137
diff
changeset
|
3603 |
InvalidateWindowClasses(WC_TRAINS_LIST); |
0 | 3604 |
} |
3605 |
} |
|
3606 |
} |
|
3607 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1087
diff
changeset
|
3608 |
void TrainsYearlyLoop(void) |
0 | 3609 |
{ |
3610 |
Vehicle *v; |
|
3611 |
||
3612 |
FOR_ALL_VEHICLES(v) { |
|
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1064
diff
changeset
|
3613 |
if (v->type == VEH_Train && v->subtype == TS_Front_Engine) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
166
diff
changeset
|
3614 |
|
0 | 3615 |
// show warning if train is not generating enough income last 2 years (corresponds to a red icon in the vehicle list) |
3616 |
if (_patches.train_income_warn && v->owner == _local_player && v->age >= 730 && v->profit_this_year < 0) { |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
3617 |
SetDParam(1, v->profit_this_year); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
3618 |
SetDParam(0, v->unitnumber); |
0 | 3619 |
AddNewsItem( |
3620 |
STR_TRAIN_IS_UNPROFITABLE, |
|
3621 |
NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), |
|
3622 |
v->index, |
|
3623 |
0); |
|
3624 |
} |
|
3625 |
||
3626 |
v->profit_last_year = v->profit_this_year; |
|
3627 |
v->profit_this_year = 0; |
|
3628 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
3629 |
} |
|
3630 |
} |
|
3631 |
} |
|
3632 |
||
3633 |
void HandleClickOnTrain(Vehicle *v) |
|
3634 |
{ |
|
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1064
diff
changeset
|
3635 |
if (v->subtype != TS_Front_Engine) v = GetFirstVehicleInChain(v); |
0 | 3636 |
ShowTrainViewWindow(v); |
3637 |
} |
|
3638 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1087
diff
changeset
|
3639 |
void InitializeTrains(void) |
0 | 3640 |
{ |
3641 |
_age_cargo_skip_counter = 1; |
|
3642 |
} |