src/articulated_vehicles.cpp
author smatz
Sun, 17 Feb 2008 17:00:43 +0000
changeset 8586 cb0e7e00f1d2
parent 8559 e51166aff0b2
child 8786 1823ff88a054
permissions -rw-r--r--
(svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2182
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2182
diff changeset
     2
6775
82fc9e993a09 (svn r10011) -Fix (r10008): Set the right svn properties on articulated_vehicles.h and correct a file comment.
maedhros
parents: 6772
diff changeset
     3
/** @file articulated_vehicles.cpp */
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6407
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1883
diff changeset
     6
#include "openttd.h"
6772
8672ba1bebc9 (svn r10008) -Codechange: Move a couple of functions related to articulated vehicles to a file of their own.
maedhros
parents: 6771
diff changeset
     7
#include "articulated_vehicles.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
#include "engine.h"
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2666
diff changeset
     9
#include "train.h"
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
    10
#include "roadveh.h"
2982
eb7f50dcb249 (svn r3557) - NewGRF: move callback enums to a new file as more than just engines will use them
peter1138
parents: 2970
diff changeset
    11
#include "newgrf_callbacks.h"
2962
f0a49b646c48 (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
    12
#include "newgrf_engine.h"
8144
65cec0877b78 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8131
diff changeset
    13
#include "vehicle_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
    15
7595
9d645518f001 (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: 7593
diff changeset
    16
uint CountArticulatedParts(EngineID engine_type, bool purchase_window)
2602
1a6561c9a408 (svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents: 2599
diff changeset
    17
{
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7642
diff changeset
    18
	if (!HasBit(EngInfo(engine_type)->callbackmask, CBM_VEHICLE_ARTIC_ENGINE)) return 0;
6150
98af28cf9665 (svn r8893) -Fix
tron
parents: 6141
diff changeset
    19
7595
9d645518f001 (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: 7593
diff changeset
    20
	Vehicle *v = NULL;;
9d645518f001 (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: 7593
diff changeset
    21
	if (!purchase_window) {
9d645518f001 (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: 7593
diff changeset
    22
		v = new InvalidVehicle();
9d645518f001 (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: 7593
diff changeset
    23
		v->engine_type = engine_type;
9d645518f001 (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: 7593
diff changeset
    24
	}
9d645518f001 (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: 7593
diff changeset
    25
2602
1a6561c9a408 (svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents: 2599
diff changeset
    26
	uint i;
7593
9b4265a05063 (svn r11120) -Codechange: remove the arbitrary limit of 10 articulated parts for a vehicle.
rubidium
parents: 7528
diff changeset
    27
	for (i = 1; i < MAX_UVALUE(EngineID); i++) {
7595
9d645518f001 (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: 7593
diff changeset
    28
		uint16 callback = GetVehicleCallback(CBID_VEHICLE_ARTIC_ENGINE, i, 0, engine_type, v);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
    29
		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
    30
	}
1a6561c9a408 (svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents: 2599
diff changeset
    31
7595
9d645518f001 (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: 7593
diff changeset
    32
	delete v;
9d645518f001 (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: 7593
diff changeset
    33
2608
c98436848294 (svn r3145) Fix two off-by-one errors in building articulated rail vehicles.
peter1138
parents: 2607
diff changeset
    34
	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
    35
}
1a6561c9a408 (svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents: 2599
diff changeset
    36
8559
e51166aff0b2 (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: 8144
diff changeset
    37
e51166aff0b2 (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: 8144
diff changeset
    38
uint16 *GetCapacityOfArticulatedParts(EngineID engine, VehicleType type)
e51166aff0b2 (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: 8144
diff changeset
    39
{
e51166aff0b2 (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: 8144
diff changeset
    40
	static uint16 capacity[NUM_CARGO];
e51166aff0b2 (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: 8144
diff changeset
    41
	memset(capacity, 0, sizeof(capacity));
e51166aff0b2 (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: 8144
diff changeset
    42
e51166aff0b2 (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: 8144
diff changeset
    43
	if (type == VEH_TRAIN) {
e51166aff0b2 (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: 8144
diff changeset
    44
		const RailVehicleInfo *rvi = RailVehInfo(engine);
e51166aff0b2 (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: 8144
diff changeset
    45
		capacity[rvi->cargo_type] = rvi->capacity;
e51166aff0b2 (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: 8144
diff changeset
    46
		if (rvi->railveh_type == RAILVEH_MULTIHEAD) capacity[rvi->cargo_type] += rvi->capacity;
e51166aff0b2 (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: 8144
diff changeset
    47
	} else if (type == VEH_ROAD) {
e51166aff0b2 (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: 8144
diff changeset
    48
		const RoadVehicleInfo *rvi = RoadVehInfo(engine);
e51166aff0b2 (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: 8144
diff changeset
    49
		capacity[rvi->cargo_type] = rvi->capacity;
e51166aff0b2 (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: 8144
diff changeset
    50
	}
e51166aff0b2 (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: 8144
diff changeset
    51
e51166aff0b2 (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: 8144
diff changeset
    52
	if (!HasBit(EngInfo(engine)->callbackmask, CBM_VEHICLE_ARTIC_ENGINE)) return capacity;
e51166aff0b2 (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: 8144
diff changeset
    53
e51166aff0b2 (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: 8144
diff changeset
    54
	for (uint i = 1; i < MAX_UVALUE(EngineID); i++) {
e51166aff0b2 (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: 8144
diff changeset
    55
		uint16 callback = GetVehicleCallback(CBID_VEHICLE_ARTIC_ENGINE, i, 0, engine, NULL);
e51166aff0b2 (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: 8144
diff changeset
    56
		if (callback == CALLBACK_FAILED || callback == 0xFF) break;
e51166aff0b2 (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: 8144
diff changeset
    57
e51166aff0b2 (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: 8144
diff changeset
    58
		EngineID artic_engine = GetFirstEngineOfType(type) + GB(callback, 0, 7);
e51166aff0b2 (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: 8144
diff changeset
    59
e51166aff0b2 (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: 8144
diff changeset
    60
		if (type == VEH_TRAIN) {
e51166aff0b2 (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: 8144
diff changeset
    61
			const RailVehicleInfo *rvi = RailVehInfo(artic_engine);
e51166aff0b2 (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: 8144
diff changeset
    62
			capacity[rvi->cargo_type] += GetEngineProperty(artic_engine, 0x14, rvi->capacity);
e51166aff0b2 (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: 8144
diff changeset
    63
		} else if (type == VEH_ROAD) {
e51166aff0b2 (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: 8144
diff changeset
    64
			const RoadVehicleInfo *rvi = RoadVehInfo(artic_engine);
e51166aff0b2 (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: 8144
diff changeset
    65
			capacity[rvi->cargo_type] += GetEngineProperty(artic_engine, 0x0F, rvi->capacity);
e51166aff0b2 (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: 8144
diff changeset
    66
		}
e51166aff0b2 (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: 8144
diff changeset
    67
	}
e51166aff0b2 (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: 8144
diff changeset
    68
e51166aff0b2 (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: 8144
diff changeset
    69
	return capacity;
e51166aff0b2 (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: 8144
diff changeset
    70
}
e51166aff0b2 (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: 8144
diff changeset
    71
e51166aff0b2 (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: 8144
diff changeset
    72
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
    73
void AddArticulatedParts(Vehicle **vl, VehicleType type)
2602
1a6561c9a408 (svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents: 2599
diff changeset
    74
{
6150
98af28cf9665 (svn r8893) -Fix
tron
parents: 6141
diff changeset
    75
	const Vehicle *v = vl[0];
98af28cf9665 (svn r8893) -Fix
tron
parents: 6141
diff changeset
    76
	Vehicle *u = vl[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
    77
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7642
diff changeset
    78
	if (!HasBit(EngInfo(v->engine_type)->callbackmask, CBM_VEHICLE_ARTIC_ENGINE)) return;
2602
1a6561c9a408 (svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents: 2599
diff changeset
    79
7593
9b4265a05063 (svn r11120) -Codechange: remove the arbitrary limit of 10 articulated parts for a vehicle.
rubidium
parents: 7528
diff changeset
    80
	for (uint i = 1; i < MAX_UVALUE(EngineID); i++) {
7215
7f90af37655d (svn r10493) -Codechange: update some callback ID enums to reflect their changed usage, add a few and update the comments.
rubidium
parents: 6857
diff changeset
    81
		uint16 callback = GetVehicleCallback(CBID_VEHICLE_ARTIC_ENGINE, i, 0, v->engine_type, v);
3017
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 3008
diff changeset
    82
		if (callback == CALLBACK_FAILED || callback == 0xFF) return;
2602
1a6561c9a408 (svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents: 2599
diff changeset
    83
4831
ffc748f7e3e6 (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
    84
		/* Attempt to use pre-allocated vehicles until they run out. This can happen
ffc748f7e3e6 (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
    85
		 * if the callback returns different values depending on the cargo type. */
7492
35acee076719 (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: 7398
diff changeset
    86
		u->SetNext(vl[i]);
35acee076719 (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: 7398
diff changeset
    87
		if (u->Next() == NULL) return;
4831
ffc748f7e3e6 (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
    88
7518
75f9c0f2baf1 (svn r11033) -Fix [FS#1184] (r11011): building articulated vehicles failed. Based on a patch by SmatZ.
rubidium
parents: 7492
diff changeset
    89
		Vehicle *previous = u;
7492
35acee076719 (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: 7398
diff changeset
    90
		u = u->Next();
2602
1a6561c9a408 (svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents: 2599
diff changeset
    91
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
    92
		EngineID engine_type = GetFirstEngineOfType(type) + GB(callback, 0, 7);
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7642
diff changeset
    93
		bool flip_image = HasBit(callback, 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
    94
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6407
diff changeset
    95
		/* get common values from first engine */
2602
1a6561c9a408 (svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents: 2599
diff changeset
    96
		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
    97
		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
    98
		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
    99
		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
   100
		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
   101
		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
   102
		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
   103
		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
   104
3870
d9ebc4ea750a (svn r4910) - NewGRF: add and initialize cargo subtype for vehicle visual variations
peter1138
parents: 3836
diff changeset
   105
		u->cargo_subtype = 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
   106
		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
   107
		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
   108
		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
   109
		u->value = 0;
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2666
diff changeset
   110
		u->subtype = 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
   111
		u->cur_image = 0xAC2;
2804
ea4080819175 (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
   112
		u->random_bits = VehicleRandomBits();
2602
1a6561c9a408 (svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents: 2599
diff changeset
   113
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   114
		switch (type) {
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   115
			default: NOT_REACHED();
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   116
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   117
			case VEH_TRAIN: {
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   118
				const RailVehicleInfo *rvi_artic = RailVehInfo(engine_type);
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   119
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   120
				u = new (u) Train();
7528
fe994ed19d34 (svn r11047) -Fix (r11011) [FS#1205]: desync due to wrong cached vehicle length on articulated vehicle construction.
rubidium
parents: 7518
diff changeset
   121
				previous->SetNext(u);
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   122
				u->u.rail.track = v->u.rail.track;
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   123
				u->u.rail.railtype = v->u.rail.railtype;
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   124
				u->u.rail.first_engine = v->engine_type;
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   125
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   126
				u->spritenum = rvi_artic->image_index;
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   127
				u->cargo_type = rvi_artic->cargo_type;
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   128
				u->cargo_cap = rvi_artic->capacity;
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   129
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   130
				SetArticulatedPart(u);
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   131
			} break;
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   132
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   133
			case VEH_ROAD: {
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   134
				const RoadVehicleInfo *rvi_artic = RoadVehInfo(engine_type);
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   135
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   136
				u = new (u) RoadVehicle();
7528
fe994ed19d34 (svn r11047) -Fix (r11011) [FS#1205]: desync due to wrong cached vehicle length on articulated vehicle construction.
rubidium
parents: 7518
diff changeset
   137
				previous->SetNext(u);
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   138
				u->u.road.first_engine = v->engine_type;
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   139
				u->u.road.cached_veh_length = GetRoadVehLength(u);
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   140
				u->u.road.state = RVSB_IN_DEPOT;
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   141
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   142
				u->u.road.roadtype = v->u.road.roadtype;
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   143
				u->u.road.compatible_roadtypes = v->u.road.compatible_roadtypes;
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   144
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   145
				u->spritenum = rvi_artic->image_index;
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   146
				u->cargo_type = rvi_artic->cargo_type;
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   147
				u->cargo_cap = rvi_artic->capacity;
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   148
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   149
				SetRoadVehArticPart(u);
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   150
			} break;
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   151
		}
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   152
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   153
		if (flip_image) u->spritenum++;
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6775
diff changeset
   154
2602
1a6561c9a408 (svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents: 2599
diff changeset
   155
		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
   156
	}
1a6561c9a408 (svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents: 2599
diff changeset
   157
}