src/train.h
author peter1138
Tue, 12 Feb 2008 13:23:57 +0000
changeset 8544 47b99dc2da26
parent 8467 605661f3a91c
child 8612 21e2e71f3f4f
permissions -rw-r--r--
(svn r12122) -Codechange: Add framework for generic feature callbacks, along with some parts for AI use.
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
     1
/* $Id$ */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
     2
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6248
diff changeset
     3
/** @file train.h */
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6248
diff changeset
     4
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
     5
#ifndef TRAIN_H
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
     6
#define TRAIN_H
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
     7
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
     8
#include "stdafx.h"
8144
65cec0877b78 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 7931
diff changeset
     9
#include "core/bitmath_func.hpp"
65cec0877b78 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 7931
diff changeset
    10
#include "vehicle_base.h"
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    11
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    12
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    13
/*
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    14
 * enum to handle train subtypes
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    15
 * Do not access it directly unless you have to. Use the access functions below
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    16
 * This is an enum to tell what bit to access as it is a bitmask
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    17
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    18
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    19
enum TrainSubtype {
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6248
diff changeset
    20
	Train_Front             = 0, ///< Leading engine of a train
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6248
diff changeset
    21
	Train_Articulated_Part  = 1, ///< Articulated part of an engine
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6248
diff changeset
    22
	Train_Wagon             = 2, ///< Wagon
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6248
diff changeset
    23
	Train_Engine            = 3, ///< Engine, that can be front engines, but might be placed behind another engine
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6248
diff changeset
    24
	Train_Free_Wagon        = 4, ///< First in a wagon chain (in depot)
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6248
diff changeset
    25
	Train_Multiheaded       = 5, ///< Engine is a multiheaded
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    26
};
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    27
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    28
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    29
/** Check if a vehicle is front engine
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    30
 * @param v vehicle to check
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    31
 * @return Returns true if vehicle is a front engine
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    32
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    33
static inline bool IsFrontEngine(const Vehicle *v)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    34
{
6771
b58be16fb268 (svn r10007) -Codechange: Add some asserts to IsFrontEngine and friends to ensure that only trains use them.
maedhros
parents: 6593
diff changeset
    35
	assert(v->type == VEH_TRAIN);
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7548
diff changeset
    36
	return HasBit(v->subtype, Train_Front);
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    37
}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    38
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    39
/** Set front engine state
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    40
 * @param v vehicle to change
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    41
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    42
static inline void SetFrontEngine(Vehicle *v)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    43
{
6771
b58be16fb268 (svn r10007) -Codechange: Add some asserts to IsFrontEngine and friends to ensure that only trains use them.
maedhros
parents: 6593
diff changeset
    44
	assert(v->type == VEH_TRAIN);
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7929
diff changeset
    45
	SetBit(v->subtype, Train_Front);
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    46
}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    47
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    48
/** Remove the front engine state
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    49
 * @param v vehicle to change
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    50
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    51
static inline void ClearFrontEngine(Vehicle *v)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    52
{
6771
b58be16fb268 (svn r10007) -Codechange: Add some asserts to IsFrontEngine and friends to ensure that only trains use them.
maedhros
parents: 6593
diff changeset
    53
	assert(v->type == VEH_TRAIN);
7929
6c9b25842b0f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 7928
diff changeset
    54
	ClrBit(v->subtype, Train_Front);
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    55
}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    56
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    57
/** Check if a vehicle is an articulated part of an engine
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    58
 * @param v vehicle to check
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    59
 * @return Returns true if vehicle is an articulated part
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    60
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    61
static inline bool IsArticulatedPart(const Vehicle *v)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    62
{
6771
b58be16fb268 (svn r10007) -Codechange: Add some asserts to IsFrontEngine and friends to ensure that only trains use them.
maedhros
parents: 6593
diff changeset
    63
	assert(v->type == VEH_TRAIN);
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7548
diff changeset
    64
	return HasBit(v->subtype, Train_Articulated_Part);
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    65
}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    66
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    67
/** Set a vehicle to be an articulated part
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    68
 * @param v vehicle to change
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    69
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    70
static inline void SetArticulatedPart(Vehicle *v)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    71
{
6771
b58be16fb268 (svn r10007) -Codechange: Add some asserts to IsFrontEngine and friends to ensure that only trains use them.
maedhros
parents: 6593
diff changeset
    72
	assert(v->type == VEH_TRAIN);
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7929
diff changeset
    73
	SetBit(v->subtype, Train_Articulated_Part);
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    74
}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    75
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    76
/** Clear a vehicle from being an articulated part
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    77
 * @param v vehicle to change
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    78
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    79
static inline void ClearArticulatedPart(Vehicle *v)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    80
{
6771
b58be16fb268 (svn r10007) -Codechange: Add some asserts to IsFrontEngine and friends to ensure that only trains use them.
maedhros
parents: 6593
diff changeset
    81
	assert(v->type == VEH_TRAIN);
7929
6c9b25842b0f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 7928
diff changeset
    82
	ClrBit(v->subtype, Train_Articulated_Part);
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    83
}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    84
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    85
/** Check if a vehicle is a wagon
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    86
 * @param v vehicle to check
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    87
 * @return Returns true if vehicle is a wagon
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    88
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    89
static inline bool IsTrainWagon(const Vehicle *v)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    90
{
6771
b58be16fb268 (svn r10007) -Codechange: Add some asserts to IsFrontEngine and friends to ensure that only trains use them.
maedhros
parents: 6593
diff changeset
    91
	assert(v->type == VEH_TRAIN);
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7548
diff changeset
    92
	return HasBit(v->subtype, Train_Wagon);
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    93
}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    94
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    95
/** Set a vehicle to be a wagon
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    96
 * @param v vehicle to change
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    97
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    98
static inline void SetTrainWagon(Vehicle *v)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    99
{
6771
b58be16fb268 (svn r10007) -Codechange: Add some asserts to IsFrontEngine and friends to ensure that only trains use them.
maedhros
parents: 6593
diff changeset
   100
	assert(v->type == VEH_TRAIN);
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7929
diff changeset
   101
	SetBit(v->subtype, Train_Wagon);
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   102
}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   103
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   104
/** Clear wagon property
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   105
 * @param v vehicle to change
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   106
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   107
static inline void ClearTrainWagon(Vehicle *v)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   108
{
6771
b58be16fb268 (svn r10007) -Codechange: Add some asserts to IsFrontEngine and friends to ensure that only trains use them.
maedhros
parents: 6593
diff changeset
   109
	assert(v->type == VEH_TRAIN);
7929
6c9b25842b0f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 7928
diff changeset
   110
	ClrBit(v->subtype, Train_Wagon);
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   111
}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   112
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   113
/** Check if a vehicle is an engine (can be first in a train)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   114
 * @param v vehicle to check
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   115
 * @return Returns true if vehicle is an engine
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   116
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   117
static inline bool IsTrainEngine(const Vehicle *v)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   118
{
6771
b58be16fb268 (svn r10007) -Codechange: Add some asserts to IsFrontEngine and friends to ensure that only trains use them.
maedhros
parents: 6593
diff changeset
   119
	assert(v->type == VEH_TRAIN);
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7548
diff changeset
   120
	return HasBit(v->subtype, Train_Engine);
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   121
}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   122
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   123
/** Set engine status
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   124
 * @param v vehicle to change
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   125
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   126
static inline void SetTrainEngine(Vehicle *v)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   127
{
6771
b58be16fb268 (svn r10007) -Codechange: Add some asserts to IsFrontEngine and friends to ensure that only trains use them.
maedhros
parents: 6593
diff changeset
   128
	assert(v->type == VEH_TRAIN);
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7929
diff changeset
   129
	SetBit(v->subtype, Train_Engine);
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   130
}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   131
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   132
/** Clear engine status
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   133
 * @param v vehicle to change
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   134
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   135
static inline void ClearTrainEngine(Vehicle *v)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   136
{
6771
b58be16fb268 (svn r10007) -Codechange: Add some asserts to IsFrontEngine and friends to ensure that only trains use them.
maedhros
parents: 6593
diff changeset
   137
	assert(v->type == VEH_TRAIN);
7929
6c9b25842b0f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 7928
diff changeset
   138
	ClrBit(v->subtype, Train_Engine);
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   139
}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   140
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   141
/** Check if a vehicle is a free wagon (got no engine in front of it)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   142
 * @param v vehicle to check
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   143
 * @return Returns true if vehicle is a free wagon
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   144
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   145
static inline bool IsFreeWagon(const Vehicle *v)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   146
{
6771
b58be16fb268 (svn r10007) -Codechange: Add some asserts to IsFrontEngine and friends to ensure that only trains use them.
maedhros
parents: 6593
diff changeset
   147
	assert(v->type == VEH_TRAIN);
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7548
diff changeset
   148
	return HasBit(v->subtype, Train_Free_Wagon);
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   149
}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   150
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   151
/** Set if a vehicle is a free wagon
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   152
 * @param v vehicle to change
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   153
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   154
static inline void SetFreeWagon(Vehicle *v)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   155
{
6771
b58be16fb268 (svn r10007) -Codechange: Add some asserts to IsFrontEngine and friends to ensure that only trains use them.
maedhros
parents: 6593
diff changeset
   156
	assert(v->type == VEH_TRAIN);
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7929
diff changeset
   157
	SetBit(v->subtype, Train_Free_Wagon);
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   158
}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   159
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   160
/** Clear a vehicle from being a free wagon
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   161
 * @param v vehicle to change
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   162
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   163
static inline void ClearFreeWagon(Vehicle *v)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   164
{
6771
b58be16fb268 (svn r10007) -Codechange: Add some asserts to IsFrontEngine and friends to ensure that only trains use them.
maedhros
parents: 6593
diff changeset
   165
	assert(v->type == VEH_TRAIN);
7929
6c9b25842b0f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 7928
diff changeset
   166
	ClrBit(v->subtype, Train_Free_Wagon);
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   167
}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   168
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   169
/** Check if a vehicle is a multiheaded engine
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   170
 * @param v vehicle to check
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   171
 * @return Returns true if vehicle is a multiheaded engine
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   172
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   173
static inline bool IsMultiheaded(const Vehicle *v)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   174
{
6771
b58be16fb268 (svn r10007) -Codechange: Add some asserts to IsFrontEngine and friends to ensure that only trains use them.
maedhros
parents: 6593
diff changeset
   175
	assert(v->type == VEH_TRAIN);
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7548
diff changeset
   176
	return HasBit(v->subtype, Train_Multiheaded);
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   177
}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   178
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   179
/** Set if a vehicle is a multiheaded engine
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   180
 * @param v vehicle to change
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   181
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   182
static inline void SetMultiheaded(Vehicle *v)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   183
{
6771
b58be16fb268 (svn r10007) -Codechange: Add some asserts to IsFrontEngine and friends to ensure that only trains use them.
maedhros
parents: 6593
diff changeset
   184
	assert(v->type == VEH_TRAIN);
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7929
diff changeset
   185
	SetBit(v->subtype, Train_Multiheaded);
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   186
}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   187
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   188
/** Clear multiheaded engine property
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   189
 * @param v vehicle to change
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   190
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   191
static inline void ClearMultiheaded(Vehicle *v)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   192
{
6771
b58be16fb268 (svn r10007) -Codechange: Add some asserts to IsFrontEngine and friends to ensure that only trains use them.
maedhros
parents: 6593
diff changeset
   193
	assert(v->type == VEH_TRAIN);
7929
6c9b25842b0f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 7928
diff changeset
   194
	ClrBit(v->subtype, Train_Multiheaded);
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   195
}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   196
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   197
/** Check if an engine has an articulated part.
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   198
 * @param v Vehicle.
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   199
 * @return True if the engine has an articulated part.
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   200
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   201
static inline bool EngineHasArticPart(const Vehicle *v)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   202
{
6771
b58be16fb268 (svn r10007) -Codechange: Add some asserts to IsFrontEngine and friends to ensure that only trains use them.
maedhros
parents: 6593
diff changeset
   203
	assert(v->type == VEH_TRAIN);
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: 7490
diff changeset
   204
	return (v->Next() != NULL && IsArticulatedPart(v->Next()));
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   205
}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   206
4384
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   207
/**
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   208
 * Get the next part of a multi-part engine.
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   209
 * Will only work on a multi-part engine (EngineHasArticPart(v) == true),
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   210
 * Result is undefined for normal engine.
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   211
 */
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   212
static inline Vehicle *GetNextArticPart(const Vehicle *v)
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   213
{
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   214
	assert(EngineHasArticPart(v));
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: 7490
diff changeset
   215
	return v->Next();
4384
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   216
}
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   217
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   218
/** Get the last part of a multi-part engine.
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   219
 * @param v Vehicle.
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   220
 * @return Last part of the engine.
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   221
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   222
static inline Vehicle *GetLastEnginePart(Vehicle *v)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   223
{
6771
b58be16fb268 (svn r10007) -Codechange: Add some asserts to IsFrontEngine and friends to ensure that only trains use them.
maedhros
parents: 6593
diff changeset
   224
	assert(v->type == VEH_TRAIN);
4384
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   225
	while (EngineHasArticPart(v)) v = GetNextArticPart(v);
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   226
	return v;
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   227
}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   228
7526
27c4fbf8aef0 (svn r11045) -Codechange: added a function to tell if a vehicle is the rear part of a dualheaded train engine
bjarni
parents: 7492
diff changeset
   229
/** Tell if we are dealing with the rear end of a multiheaded engine.
27c4fbf8aef0 (svn r11045) -Codechange: added a function to tell if a vehicle is the rear part of a dualheaded train engine
bjarni
parents: 7492
diff changeset
   230
 * @param v Vehicle.
27c4fbf8aef0 (svn r11045) -Codechange: added a function to tell if a vehicle is the rear part of a dualheaded train engine
bjarni
parents: 7492
diff changeset
   231
 * @return True if the engine is the rear part of a dualheaded engine.
27c4fbf8aef0 (svn r11045) -Codechange: added a function to tell if a vehicle is the rear part of a dualheaded train engine
bjarni
parents: 7492
diff changeset
   232
 */
27c4fbf8aef0 (svn r11045) -Codechange: added a function to tell if a vehicle is the rear part of a dualheaded train engine
bjarni
parents: 7492
diff changeset
   233
static inline bool IsRearDualheaded(const Vehicle *v)
27c4fbf8aef0 (svn r11045) -Codechange: added a function to tell if a vehicle is the rear part of a dualheaded train engine
bjarni
parents: 7492
diff changeset
   234
{
27c4fbf8aef0 (svn r11045) -Codechange: added a function to tell if a vehicle is the rear part of a dualheaded train engine
bjarni
parents: 7492
diff changeset
   235
	assert(v->type == VEH_TRAIN);
27c4fbf8aef0 (svn r11045) -Codechange: added a function to tell if a vehicle is the rear part of a dualheaded train engine
bjarni
parents: 7492
diff changeset
   236
	return (IsMultiheaded(v) && !IsTrainEngine(v));
27c4fbf8aef0 (svn r11045) -Codechange: added a function to tell if a vehicle is the rear part of a dualheaded train engine
bjarni
parents: 7492
diff changeset
   237
}
27c4fbf8aef0 (svn r11045) -Codechange: added a function to tell if a vehicle is the rear part of a dualheaded train engine
bjarni
parents: 7492
diff changeset
   238
4384
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   239
/** Get the next real (non-articulated part) vehicle in the consist.
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   240
 * @param v Vehicle.
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   241
 * @return Next vehicle in the consist.
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   242
 */
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   243
static inline Vehicle *GetNextVehicle(const Vehicle *v)
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   244
{
6771
b58be16fb268 (svn r10007) -Codechange: Add some asserts to IsFrontEngine and friends to ensure that only trains use them.
maedhros
parents: 6593
diff changeset
   245
	assert(v->type == VEH_TRAIN);
4384
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   246
	while (EngineHasArticPart(v)) v = GetNextArticPart(v);
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   247
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   248
	/* v now contains the last artic part in the engine */
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: 7490
diff changeset
   249
	return v->Next();
4384
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   250
}
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   251
7527
a1d3a14ae669 (svn r11046) -Codechange: added function to get the next movable (non-articulated, non-read end of dualheaded engine) vehicle in a train
bjarni
parents: 7526
diff changeset
   252
/** Get the next real (non-articulated part and non rear part of dualheaded engine) vehicle in the consist.
a1d3a14ae669 (svn r11046) -Codechange: added function to get the next movable (non-articulated, non-read end of dualheaded engine) vehicle in a train
bjarni
parents: 7526
diff changeset
   253
 * @param v Vehicle.
a1d3a14ae669 (svn r11046) -Codechange: added function to get the next movable (non-articulated, non-read end of dualheaded engine) vehicle in a train
bjarni
parents: 7526
diff changeset
   254
 * @return Next vehicle in the consist.
a1d3a14ae669 (svn r11046) -Codechange: added function to get the next movable (non-articulated, non-read end of dualheaded engine) vehicle in a train
bjarni
parents: 7526
diff changeset
   255
 */
a1d3a14ae669 (svn r11046) -Codechange: added function to get the next movable (non-articulated, non-read end of dualheaded engine) vehicle in a train
bjarni
parents: 7526
diff changeset
   256
static inline Vehicle *GetNextUnit(Vehicle *v)
a1d3a14ae669 (svn r11046) -Codechange: added function to get the next movable (non-articulated, non-read end of dualheaded engine) vehicle in a train
bjarni
parents: 7526
diff changeset
   257
{
a1d3a14ae669 (svn r11046) -Codechange: added function to get the next movable (non-articulated, non-read end of dualheaded engine) vehicle in a train
bjarni
parents: 7526
diff changeset
   258
	assert(v->type == VEH_TRAIN);
a1d3a14ae669 (svn r11046) -Codechange: added function to get the next movable (non-articulated, non-read end of dualheaded engine) vehicle in a train
bjarni
parents: 7526
diff changeset
   259
	v = GetNextVehicle(v);
a1d3a14ae669 (svn r11046) -Codechange: added function to get the next movable (non-articulated, non-read end of dualheaded engine) vehicle in a train
bjarni
parents: 7526
diff changeset
   260
	if (v != NULL && IsRearDualheaded(v)) v = v->Next();
a1d3a14ae669 (svn r11046) -Codechange: added function to get the next movable (non-articulated, non-read end of dualheaded engine) vehicle in a train
bjarni
parents: 7526
diff changeset
   261
a1d3a14ae669 (svn r11046) -Codechange: added function to get the next movable (non-articulated, non-read end of dualheaded engine) vehicle in a train
bjarni
parents: 7526
diff changeset
   262
	return v;
a1d3a14ae669 (svn r11046) -Codechange: added function to get the next movable (non-articulated, non-read end of dualheaded engine) vehicle in a train
bjarni
parents: 7526
diff changeset
   263
}
a1d3a14ae669 (svn r11046) -Codechange: added function to get the next movable (non-articulated, non-read end of dualheaded engine) vehicle in a train
bjarni
parents: 7526
diff changeset
   264
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 5779
diff changeset
   265
void ConvertOldMultiheadToNew();
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 5779
diff changeset
   266
void ConnectMultiheadedTrains();
4737
287bc9b53ec9 (svn r6649) - Codechange: Show more correct capacity of articulated wagons in the train purchase list.
peter1138
parents: 4653
diff changeset
   267
uint CountArticulatedParts(EngineID engine_type);
2855
56c39efde08a (svn r3403) -Codechange: [multiheaded engines] the references between the front and rear engines are no longer saved
bjarni
parents: 2676
diff changeset
   268
4648
7bde2a5c36e8 (svn r6524) -Code cleanup r6515: cleaned up the command to start/stop all vehicles in a depot.
bjarni
parents: 4640
diff changeset
   269
int CheckTrainInDepot(const Vehicle *v, bool needs_to_be_stopped);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5475
diff changeset
   270
void CcBuildLoco(bool success, TileIndex tile, uint32 p1, uint32 p2);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5475
diff changeset
   271
void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2);
4640
4e380e2ecfa7 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4384
diff changeset
   272
5316
27fa85736f8a (svn r7473) -Fix (r7269): Pass a cargo type to determine the freight weight
peter1138
parents: 5163
diff changeset
   273
byte FreightWagonMult(CargoID cargo);
5163
459b243f8413 (svn r7269) -Feature: Add freight trains patch option. This option is a multiplier for the weight of cargo on freight trains, to simulate longer heavier trains. The default value of 1 behaves as before.
peter1138
parents: 4737
diff changeset
   274
7490
bb27d92565d3 (svn r11001) -Codechange: unify the way to determine whether a vehicle is in a depot.
rubidium
parents: 7488
diff changeset
   275
int CheckTrainInDepot(const Vehicle *v, bool needs_to_be_stopped);
bb27d92565d3 (svn r11001) -Codechange: unify the way to determine whether a vehicle is in a depot.
rubidium
parents: 7488
diff changeset
   276
int CheckTrainStoppedInDepot(const Vehicle *v);
bb27d92565d3 (svn r11001) -Codechange: unify the way to determine whether a vehicle is in a depot.
rubidium
parents: 7488
diff changeset
   277
6552
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6422
diff changeset
   278
/**
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6422
diff changeset
   279
 * This class 'wraps' Vehicle; you do not actually instantiate this class.
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6422
diff changeset
   280
 * You create a Vehicle using AllocateVehicle, so it is added to the pool
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6422
diff changeset
   281
 * and you reinitialize that to a Train using:
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6422
diff changeset
   282
 *   v = new (v) Train();
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6422
diff changeset
   283
 *
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6422
diff changeset
   284
 * As side-effect the vehicle type is set correctly.
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6422
diff changeset
   285
 */
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6422
diff changeset
   286
struct Train : public Vehicle {
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6422
diff changeset
   287
	/** Initializes the Vehicle to a train */
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6422
diff changeset
   288
	Train() { this->type = VEH_TRAIN; }
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6422
diff changeset
   289
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6422
diff changeset
   290
	/** We want to 'destruct' the right class. */
7412
51db351a3313 (svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium
parents: 7135
diff changeset
   291
	virtual ~Train() { this->PreDestructor(); }
6552
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6422
diff changeset
   292
6563
fed2a162046b (svn r9765) -Codechange: constify some class functions.
rubidium
parents: 6562
diff changeset
   293
	const char *GetTypeString() const { return "train"; }
6553
976a684212ad (svn r9755) -Codechange: refactor some more of the begin loading stuff.
rubidium
parents: 6552
diff changeset
   294
	void MarkDirty();
6558
c88e142f896e (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 6553
diff changeset
   295
	void UpdateDeltaXY(Direction direction);
6563
fed2a162046b (svn r9765) -Codechange: constify some class functions.
rubidium
parents: 6562
diff changeset
   296
	ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_TRAIN_INC : EXPENSES_TRAIN_RUN; }
fed2a162046b (svn r9765) -Codechange: constify some class functions.
rubidium
parents: 6562
diff changeset
   297
	WindowClass GetVehicleListWindowClass() const { return WC_TRAINS_LIST; }
6593
102aa05c5ca4 (svn r9807) -Codechange: unify playing of sound when vehicle has been loaded and leaves the station.
rubidium
parents: 6563
diff changeset
   298
	void PlayLeaveStationSound() const;
6773
bc98b0b16ec4 (svn r10009) -Codechange: Add and use Vehicle::IsPrimaryVehicle to replace individual checks depending on the vehicle type.
maedhros
parents: 6771
diff changeset
   299
	bool IsPrimaryVehicle() const { return IsFrontEngine(this); }
7134
5b2d47128d05 (svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium
parents: 6773
diff changeset
   300
	int GetImage(Direction direction) const;
7533
787277cc0908 (svn r11053) -Fix: train status bar flickering a lot when waiting at a signal.
rubidium
parents: 7527
diff changeset
   301
	int GetDisplaySpeed() const { return this->u.rail.last_speed * 10 / 16; }
7484
7734e4119e70 (svn r10995) -Codechange: unify the way to get the displayed maxium speed of a vehicle. Patch by nycom.
rubidium
parents: 7478
diff changeset
   302
	int GetDisplayMaxSpeed() const { return this->u.rail.cached_max_speed * 10 / 16; }
7488
6f51ddf4c225 (svn r10999) -Codechange: unify the way the running cost of a vehicle is determined. Patch by nycom.
rubidium
parents: 7484
diff changeset
   303
	Money GetRunningCost() const;
7490
bb27d92565d3 (svn r11001) -Codechange: unify the way to determine whether a vehicle is in a depot.
rubidium
parents: 7488
diff changeset
   304
	bool IsInDepot() const { return CheckTrainInDepot(this, false) != -1; }
bb27d92565d3 (svn r11001) -Codechange: unify the way to determine whether a vehicle is in a depot.
rubidium
parents: 7488
diff changeset
   305
	bool IsStoppedInDepot() const { return CheckTrainStoppedInDepot(this) >= 0; }
7135
3c1bcca0d6bb (svn r10409) -Codechange: replace (Aircraft|RoadVeh|Ship|Train)_Tick with a Tick method in the Vehicle class.
rubidium
parents: 7134
diff changeset
   306
	void Tick();
8467
605661f3a91c (svn r12037) -Codechange: replace OnNewDay_(Aircraft|RoadVeh|Ship|Train) with an OnNewDay method in the Vehicle class
glx
parents: 8144
diff changeset
   307
	void OnNewDay();
6552
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6422
diff changeset
   308
};
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6422
diff changeset
   309
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   310
#endif /* TRAIN_H */