train.h
author bjarni
Sat, 12 Aug 2006 10:41:29 +0000
changeset 4251 e8f69de723e1
parent 2855 56c39efde08a
child 4384 7e0d3ed719d9
permissions -rw-r--r--
(svn r5853) -Fix: [elrails] FS#178 Electric Trains can leave Conventional Depot
now the user will get an error if he tries to start the train and the status bar will say "no power" instead of "stopped"
Electric trains already driving in and out of non-electrified depots will still do so, but you can't start new ones
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
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
     3
#ifndef TRAIN_H
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
     4
#define TRAIN_H
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
     5
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
     6
#include "stdafx.h"
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
     7
#include "vehicle.h"
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
     8
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
     9
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    10
/*
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    11
 * enum to handle train subtypes
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    12
 * 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
    13
 * 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
    14
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    15
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    16
typedef enum TrainSubtypes {
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    17
	Train_Front             = 0, // Leading engine of a train
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    18
	Train_Articulated_Part  = 1, // Articulated part of an engine
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    19
	Train_Wagon             = 2, // Wagon
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    20
	Train_Engine            = 3, // Engine, that can be front engines, but might be placed behind another engine
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    21
	Train_Free_Wagon        = 4, // First in a wagon chain (in depot)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    22
	Train_Multiheaded       = 5, // Engine is a multiheaded
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    23
} TrainSubtype;
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    24
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    25
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    26
/** 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
    27
 * @param v vehicle to check
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    28
 * @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
    29
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    30
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
    31
{
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    32
	return HASBIT(v->subtype, Train_Front);
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    33
}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    34
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    35
/** Set front engine state
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    36
 * @param v vehicle to change
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
static inline void SetFrontEngine(Vehicle *v)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    39
{
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    40
	SETBIT(v->subtype, Train_Front);
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
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    43
/** Remove the front engine state
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    44
 * @param v vehicle to change
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    45
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    46
static inline void ClearFrontEngine(Vehicle *v)
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
	CLRBIT(v->subtype, Train_Front);
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    49
}
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
/** 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
    52
 * @param v vehicle to check
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    53
 * @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
    54
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    55
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
    56
{
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    57
	return HASBIT(v->subtype, Train_Articulated_Part);
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    58
}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    59
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    60
/** 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
    61
 * @param v vehicle to change
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    62
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    63
static inline void SetArticulatedPart(Vehicle *v)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    64
{
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    65
	SETBIT(v->subtype, Train_Articulated_Part);
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
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    68
/** 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
    69
 * @param v vehicle to change
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    70
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    71
static inline void ClearArticulatedPart(Vehicle *v)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    72
{
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    73
	CLRBIT(v->subtype, Train_Articulated_Part);
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
/** 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
    77
 * @param v vehicle to check
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    78
 * @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
    79
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    80
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
    81
{
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    82
	return HASBIT(v->subtype, Train_Wagon);
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
/** 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
    86
 * @param v vehicle to change
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    87
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    88
static inline void SetTrainWagon(Vehicle *v)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    89
{
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    90
	SETBIT(v->subtype, Train_Wagon);
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    91
}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    92
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    93
/** Clear wagon property
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    94
 * @param v vehicle to change
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    95
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    96
static inline void ClearTrainWagon(Vehicle *v)
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
	CLRBIT(v->subtype, Train_Wagon);
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    99
}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   100
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   101
/** 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
   102
 * @param v vehicle to check
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   103
 * @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
   104
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   105
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
   106
{
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   107
	return HASBIT(v->subtype, Train_Engine);
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   108
}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   109
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   110
/** Set engine status
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   111
 * @param v vehicle to change
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
static inline void SetTrainEngine(Vehicle *v)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   114
{
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   115
	SETBIT(v->subtype, Train_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
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   118
/** Clear engine status
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   119
 * @param v vehicle to change
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   120
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   121
static inline void ClearTrainEngine(Vehicle *v)
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
	CLRBIT(v->subtype, Train_Engine);
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   124
}
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
/** 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
   127
 * @param v vehicle to check
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   128
 * @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
   129
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   130
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
   131
{
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   132
	return HASBIT(v->subtype, Train_Free_Wagon);
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   133
}
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
/** 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
   136
 * @param v vehicle to change
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   137
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   138
static inline void SetFreeWagon(Vehicle *v)
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
	SETBIT(v->subtype, Train_Free_Wagon);
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   141
}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   142
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   143
/** 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
   144
 * @param v vehicle to change
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   145
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   146
static inline void ClearFreeWagon(Vehicle *v)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   147
{
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   148
	CLRBIT(v->subtype, Train_Free_Wagon);
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
/** 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
   152
 * @param v vehicle to check
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   153
 * @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
   154
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   155
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
   156
{
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   157
	return HASBIT(v->subtype, Train_Multiheaded);
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
/** 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
   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 SetMultiheaded(Vehicle *v)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   164
{
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   165
	SETBIT(v->subtype, Train_Multiheaded);
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   166
}
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
/** Clear multiheaded engine property
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   169
 * @param v vehicle to change
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   170
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   171
static inline void ClearMultiheaded(Vehicle *v)
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
	CLRBIT(v->subtype, Train_Multiheaded);
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   174
}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   175
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   176
/** Get the next real (non-articulated part) vehicle in the consist.
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   177
 * @param v Vehicle.
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   178
 * @return Next vehicle in the consist.
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   179
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   180
static inline Vehicle *GetNextVehicle(const Vehicle *v)
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
	Vehicle *u = v->next;
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   183
	while (u != NULL && IsArticulatedPart(u)) {
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   184
		u = u->next;
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   185
	}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   186
	return u;
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
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   189
/** 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
   190
 * @param v Vehicle.
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   191
 * @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
   192
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   193
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
   194
{
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   195
	return (v->next != NULL && IsArticulatedPart(v->next));
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
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   198
/** 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
   199
 * @param v Vehicle.
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   200
 * @return Last part of the engine.
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   201
 */
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   202
static inline Vehicle *GetLastEnginePart(Vehicle *v)
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   203
{
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   204
	while (EngineHasArticPart(v)) v = v->next;
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   205
	return v;
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   206
}
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   207
2855
56c39efde08a (svn r3403) -Codechange: [multiheaded engines] the references between the front and rear engines are no longer saved
bjarni
parents: 2676
diff changeset
   208
void ConvertOldMultiheadToNew(void);
56c39efde08a (svn r3403) -Codechange: [multiheaded engines] the references between the front and rear engines are no longer saved
bjarni
parents: 2676
diff changeset
   209
void ConnectMultiheadedTrains(void);
56c39efde08a (svn r3403) -Codechange: [multiheaded engines] the references between the front and rear engines are no longer saved
bjarni
parents: 2676
diff changeset
   210
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   211
#endif /* TRAIN_H */