author | rubidium |
Wed, 07 May 2008 21:45:27 +0000 | |
changeset 10457 | ea18877d8eba |
parent 10429 | 1b99254f9607 |
child 10834 | d73509f48135 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
10429
1b99254f9607
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
10390
diff
changeset
|
3 |
/** @file articulated_vehicles.cpp Implementation of articulated vehicles. */ |
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6903
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1883
diff
changeset
|
6 |
#include "openttd.h" |
7268
9c77f6baef3b
(svn r10008) -Codechange: Move a couple of functions related to articulated vehicles to a file of their own.
maedhros
parents:
7267
diff
changeset
|
7 |
#include "articulated_vehicles.h" |
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
8 |
#include "train.h" |
7353
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
9 |
#include "roadveh.h" |
2982
286f69caaf05
(svn r3557) - NewGRF: move callback enums to a new file as more than just engines will use them
peter1138
parents:
2970
diff
changeset
|
10 |
#include "newgrf_callbacks.h" |
2962
dbd168a4703a
(svn r3524) - Split newgrf features from engine.[ch] into newgrf_engine.[ch], and add the new files to project files.
peter1138
parents:
2952
diff
changeset
|
11 |
#include "newgrf_engine.h" |
8640
1e93b81e96d2
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8627
diff
changeset
|
12 |
#include "vehicle_func.h" |
0 | 13 |
|
8091
f24d360b6ba1
(svn r11122) -Fix [FS#1234]: crash when building a NewGRF vehicle when the articulated build vehicle callback returneed a different value for the purchase window than the normal build. Thanks for Dalestan and _minime_ for pointers to possible causes.
rubidium
parents:
8089
diff
changeset
|
14 |
uint CountArticulatedParts(EngineID engine_type, bool purchase_window) |
2602
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
15 |
{ |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8138
diff
changeset
|
16 |
if (!HasBit(EngInfo(engine_type)->callbackmask, CBM_VEHICLE_ARTIC_ENGINE)) return 0; |
6476 | 17 |
|
8091
f24d360b6ba1
(svn r11122) -Fix [FS#1234]: crash when building a NewGRF vehicle when the articulated build vehicle callback returneed a different value for the purchase window than the normal build. Thanks for Dalestan and _minime_ for pointers to possible causes.
rubidium
parents:
8089
diff
changeset
|
18 |
Vehicle *v = NULL;; |
f24d360b6ba1
(svn r11122) -Fix [FS#1234]: crash when building a NewGRF vehicle when the articulated build vehicle callback returneed a different value for the purchase window than the normal build. Thanks for Dalestan and _minime_ for pointers to possible causes.
rubidium
parents:
8089
diff
changeset
|
19 |
if (!purchase_window) { |
f24d360b6ba1
(svn r11122) -Fix [FS#1234]: crash when building a NewGRF vehicle when the articulated build vehicle callback returneed a different value for the purchase window than the normal build. Thanks for Dalestan and _minime_ for pointers to possible causes.
rubidium
parents:
8089
diff
changeset
|
20 |
v = new InvalidVehicle(); |
f24d360b6ba1
(svn r11122) -Fix [FS#1234]: crash when building a NewGRF vehicle when the articulated build vehicle callback returneed a different value for the purchase window than the normal build. Thanks for Dalestan and _minime_ for pointers to possible causes.
rubidium
parents:
8089
diff
changeset
|
21 |
v->engine_type = engine_type; |
f24d360b6ba1
(svn r11122) -Fix [FS#1234]: crash when building a NewGRF vehicle when the articulated build vehicle callback returneed a different value for the purchase window than the normal build. Thanks for Dalestan and _minime_ for pointers to possible causes.
rubidium
parents:
8089
diff
changeset
|
22 |
} |
f24d360b6ba1
(svn r11122) -Fix [FS#1234]: crash when building a NewGRF vehicle when the articulated build vehicle callback returneed a different value for the purchase window than the normal build. Thanks for Dalestan and _minime_ for pointers to possible causes.
rubidium
parents:
8089
diff
changeset
|
23 |
|
2602
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
24 |
uint i; |
8089
a172d415e963
(svn r11120) -Codechange: remove the arbitrary limit of 10 articulated parts for a vehicle.
rubidium
parents:
8024
diff
changeset
|
25 |
for (i = 1; i < MAX_UVALUE(EngineID); i++) { |
8091
f24d360b6ba1
(svn r11122) -Fix [FS#1234]: crash when building a NewGRF vehicle when the articulated build vehicle callback returneed a different value for the purchase window than the normal build. Thanks for Dalestan and _minime_ for pointers to possible causes.
rubidium
parents:
8089
diff
changeset
|
26 |
uint16 callback = GetVehicleCallback(CBID_VEHICLE_ARTIC_ENGINE, i, 0, engine_type, v); |
10287
dd14c80bad05
(svn r12819) -Codechange: handle more NewGRFs in the same way as TTDP does it, i.e. testing the low bits for 0xFF or 0 instead of all bits.
rubidium
parents:
9282
diff
changeset
|
27 |
if (callback == CALLBACK_FAILED || GB(callback, 0, 8) == 0xFF) break; |
2602
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
28 |
} |
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
29 |
|
8091
f24d360b6ba1
(svn r11122) -Fix [FS#1234]: crash when building a NewGRF vehicle when the articulated build vehicle callback returneed a different value for the purchase window than the normal build. Thanks for Dalestan and _minime_ for pointers to possible causes.
rubidium
parents:
8089
diff
changeset
|
30 |
delete v; |
f24d360b6ba1
(svn r11122) -Fix [FS#1234]: crash when building a NewGRF vehicle when the articulated build vehicle callback returneed a different value for the purchase window than the normal build. Thanks for Dalestan and _minime_ for pointers to possible causes.
rubidium
parents:
8089
diff
changeset
|
31 |
|
2608
f7f41be75b48
(svn r3145) Fix two off-by-one errors in building articulated rail vehicles.
peter1138
parents:
2607
diff
changeset
|
32 |
return i - 1; |
2602
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
33 |
} |
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
34 |
|
9055
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
35 |
|
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
36 |
uint16 *GetCapacityOfArticulatedParts(EngineID engine, VehicleType type) |
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
37 |
{ |
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
38 |
static uint16 capacity[NUM_CARGO]; |
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
39 |
memset(capacity, 0, sizeof(capacity)); |
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
40 |
|
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
41 |
if (type == VEH_TRAIN) { |
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
42 |
const RailVehicleInfo *rvi = RailVehInfo(engine); |
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
43 |
capacity[rvi->cargo_type] = rvi->capacity; |
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
44 |
if (rvi->railveh_type == RAILVEH_MULTIHEAD) capacity[rvi->cargo_type] += rvi->capacity; |
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
45 |
} else if (type == VEH_ROAD) { |
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
46 |
const RoadVehicleInfo *rvi = RoadVehInfo(engine); |
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
47 |
capacity[rvi->cargo_type] = rvi->capacity; |
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
48 |
} |
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
49 |
|
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
50 |
if (!HasBit(EngInfo(engine)->callbackmask, CBM_VEHICLE_ARTIC_ENGINE)) return capacity; |
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
51 |
|
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
52 |
for (uint i = 1; i < MAX_UVALUE(EngineID); i++) { |
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
53 |
uint16 callback = GetVehicleCallback(CBID_VEHICLE_ARTIC_ENGINE, i, 0, engine, NULL); |
10287
dd14c80bad05
(svn r12819) -Codechange: handle more NewGRFs in the same way as TTDP does it, i.e. testing the low bits for 0xFF or 0 instead of all bits.
rubidium
parents:
9282
diff
changeset
|
54 |
if (callback == CALLBACK_FAILED || GB(callback, 0, 8) == 0xFF) break; |
9055
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
55 |
|
10382
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10287
diff
changeset
|
56 |
EngineID artic_engine = GetNewEngineID(GetEngineGRF(engine), type, GB(callback, 0, 7)); |
9055
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
57 |
|
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
58 |
if (type == VEH_TRAIN) { |
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
59 |
const RailVehicleInfo *rvi = RailVehInfo(artic_engine); |
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
60 |
capacity[rvi->cargo_type] += GetEngineProperty(artic_engine, 0x14, rvi->capacity); |
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
61 |
} else if (type == VEH_ROAD) { |
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
62 |
const RoadVehicleInfo *rvi = RoadVehInfo(artic_engine); |
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
63 |
capacity[rvi->cargo_type] += GetEngineProperty(artic_engine, 0x0F, rvi->capacity); |
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
64 |
} |
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
65 |
} |
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
66 |
|
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
67 |
return capacity; |
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
68 |
} |
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
69 |
|
386250fe46b2
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
peter1138
parents:
8640
diff
changeset
|
70 |
|
7353
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
71 |
void AddArticulatedParts(Vehicle **vl, VehicleType type) |
2602
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
72 |
{ |
6476 | 73 |
const Vehicle *v = vl[0]; |
74 |
Vehicle *u = vl[0]; |
|
2602
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
75 |
|
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8138
diff
changeset
|
76 |
if (!HasBit(EngInfo(v->engine_type)->callbackmask, CBM_VEHICLE_ARTIC_ENGINE)) return; |
2602
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
77 |
|
8089
a172d415e963
(svn r11120) -Codechange: remove the arbitrary limit of 10 articulated parts for a vehicle.
rubidium
parents:
8024
diff
changeset
|
78 |
for (uint i = 1; i < MAX_UVALUE(EngineID); i++) { |
7711
66dffbd3b136
(svn r10493) -Codechange: update some callback ID enums to reflect their changed usage, add a few and update the comments.
rubidium
parents:
7353
diff
changeset
|
79 |
uint16 callback = GetVehicleCallback(CBID_VEHICLE_ARTIC_ENGINE, i, 0, v->engine_type, v); |
10287
dd14c80bad05
(svn r12819) -Codechange: handle more NewGRFs in the same way as TTDP does it, i.e. testing the low bits for 0xFF or 0 instead of all bits.
rubidium
parents:
9282
diff
changeset
|
80 |
if (callback == CALLBACK_FAILED || GB(callback, 0, 8) == 0xFF) return; |
2602
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
81 |
|
4831
327d181a60ee
(svn r6755) - Fix: Pass the newly created vehicle when checking for articulated engines. As this could result in more parts being added than previously counted, we check to see if we need to allocate more vehicles as we add parts.
peter1138
parents:
4806
diff
changeset
|
82 |
/* Attempt to use pre-allocated vehicles until they run out. This can happen |
327d181a60ee
(svn r6755) - Fix: Pass the newly created vehicle when checking for articulated engines. As this could result in more parts being added than previously counted, we check to see if we need to allocate more vehicles as we add parts.
peter1138
parents:
4806
diff
changeset
|
83 |
* if the callback returns different values depending on the cargo type. */ |
7988
6075538f6111
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium
parents:
7894
diff
changeset
|
84 |
u->SetNext(vl[i]); |
6075538f6111
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium
parents:
7894
diff
changeset
|
85 |
if (u->Next() == NULL) return; |
4831
327d181a60ee
(svn r6755) - Fix: Pass the newly created vehicle when checking for articulated engines. As this could result in more parts being added than previously counted, we check to see if we need to allocate more vehicles as we add parts.
peter1138
parents:
4806
diff
changeset
|
86 |
|
8014
ac6651f5cd39
(svn r11033) -Fix [FS#1184] (r11011): building articulated vehicles failed. Based on a patch by SmatZ.
rubidium
parents:
7988
diff
changeset
|
87 |
Vehicle *previous = u; |
7988
6075538f6111
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium
parents:
7894
diff
changeset
|
88 |
u = u->Next(); |
2602
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
89 |
|
10382
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10287
diff
changeset
|
90 |
EngineID engine_type = GetNewEngineID(GetEngineGRF(v->engine_type), type, GB(callback, 0, 7)); |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8138
diff
changeset
|
91 |
bool flip_image = HasBit(callback, 7); |
2602
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
92 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6903
diff
changeset
|
93 |
/* get common values from first engine */ |
2602
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
94 |
u->direction = v->direction; |
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
95 |
u->owner = v->owner; |
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
96 |
u->tile = v->tile; |
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
97 |
u->x_pos = v->x_pos; |
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
98 |
u->y_pos = v->y_pos; |
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
99 |
u->z_pos = v->z_pos; |
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
100 |
u->build_year = v->build_year; |
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
101 |
u->vehstatus = v->vehstatus & ~VS_STOPPED; |
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
102 |
|
3870
766d7bd6c299
(svn r4910) - NewGRF: add and initialize cargo subtype for vehicle visual variations
peter1138
parents:
3836
diff
changeset
|
103 |
u->cargo_subtype = 0; |
2602
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
104 |
u->max_speed = 0; |
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
105 |
u->max_age = 0; |
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
106 |
u->engine_type = engine_type; |
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
107 |
u->value = 0; |
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
108 |
u->subtype = 0; |
2602
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
109 |
u->cur_image = 0xAC2; |
2804
b932fe148d36
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2758
diff
changeset
|
110 |
u->random_bits = VehicleRandomBits(); |
2602
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
111 |
|
7353
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
112 |
switch (type) { |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
113 |
default: NOT_REACHED(); |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
114 |
|
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
115 |
case VEH_TRAIN: { |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
116 |
const RailVehicleInfo *rvi_artic = RailVehInfo(engine_type); |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
117 |
|
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
118 |
u = new (u) Train(); |
8024
1968f7c9a222
(svn r11047) -Fix (r11011) [FS#1205]: desync due to wrong cached vehicle length on articulated vehicle construction.
rubidium
parents:
8014
diff
changeset
|
119 |
previous->SetNext(u); |
7353
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
120 |
u->u.rail.track = v->u.rail.track; |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
121 |
u->u.rail.railtype = v->u.rail.railtype; |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
122 |
u->u.rail.first_engine = v->engine_type; |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
123 |
|
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
124 |
u->spritenum = rvi_artic->image_index; |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
125 |
u->cargo_type = rvi_artic->cargo_type; |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
126 |
u->cargo_cap = rvi_artic->capacity; |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
127 |
|
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
128 |
SetArticulatedPart(u); |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
129 |
} break; |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
130 |
|
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
131 |
case VEH_ROAD: { |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
132 |
const RoadVehicleInfo *rvi_artic = RoadVehInfo(engine_type); |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
133 |
|
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
134 |
u = new (u) RoadVehicle(); |
8024
1968f7c9a222
(svn r11047) -Fix (r11011) [FS#1205]: desync due to wrong cached vehicle length on articulated vehicle construction.
rubidium
parents:
8014
diff
changeset
|
135 |
previous->SetNext(u); |
7353
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
136 |
u->u.road.first_engine = v->engine_type; |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
137 |
u->u.road.cached_veh_length = GetRoadVehLength(u); |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
138 |
u->u.road.state = RVSB_IN_DEPOT; |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
139 |
|
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
140 |
u->u.road.roadtype = v->u.road.roadtype; |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
141 |
u->u.road.compatible_roadtypes = v->u.road.compatible_roadtypes; |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
142 |
|
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
143 |
u->spritenum = rvi_artic->image_index; |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
144 |
u->cargo_type = rvi_artic->cargo_type; |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
145 |
u->cargo_cap = rvi_artic->capacity; |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
146 |
|
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
147 |
SetRoadVehArticPart(u); |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
148 |
} break; |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
149 |
} |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
150 |
|
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
151 |
if (flip_image) u->spritenum++; |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7271
diff
changeset
|
152 |
|
2602
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
153 |
VehiclePositionChanged(u); |
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
154 |
} |
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2599
diff
changeset
|
155 |
} |