src/train.h
author celestar
Tue, 19 Jun 2007 07:21:01 +0000
branchgamebalance
changeset 9913 e79cd19772dd
parent 9912 1ac8aac92385
permissions -rw-r--r--
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
     1
/* $Id$ */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
     2
9908
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9895
diff changeset
     3
/** @file train.h */
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9895
diff changeset
     4
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
     5
#ifndef TRAIN_H
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
     6
#define TRAIN_H
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
     7
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
     8
#include "stdafx.h"
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
     9
#include "vehicle.h"
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    10
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    11
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    12
/*
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    13
 * enum to handle train subtypes
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    14
 * Do not access it directly unless you have to. Use the access functions below
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    15
 * This is an enum to tell what bit to access as it is a bitmask
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    16
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    17
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6030
diff changeset
    18
enum TrainSubtype {
9908
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9895
diff changeset
    19
	Train_Front             = 0, ///< Leading engine of a train
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9895
diff changeset
    20
	Train_Articulated_Part  = 1, ///< Articulated part of an engine
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9895
diff changeset
    21
	Train_Wagon             = 2, ///< Wagon
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9895
diff changeset
    22
	Train_Engine            = 3, ///< Engine, that can be front engines, but might be placed behind another engine
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9895
diff changeset
    23
	Train_Free_Wagon        = 4, ///< First in a wagon chain (in depot)
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9895
diff changeset
    24
	Train_Multiheaded       = 5, ///< Engine is a multiheaded
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6030
diff changeset
    25
};
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    26
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    27
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    28
/** Check if a vehicle is front engine
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    29
 * @param v vehicle to check
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    30
 * @return Returns true if vehicle is a front engine
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    31
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    32
static inline bool IsFrontEngine(const Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    33
{
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
    34
	assert(v->type == VEH_TRAIN);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    35
	return HASBIT(v->subtype, Train_Front);
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    36
}
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    37
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    38
/** Set front engine state
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    39
 * @param v vehicle to change
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    40
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    41
static inline void SetFrontEngine(Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    42
{
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
    43
	assert(v->type == VEH_TRAIN);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    44
	SETBIT(v->subtype, Train_Front);
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    45
}
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    46
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    47
/** Remove the front engine state
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    48
 * @param v vehicle to change
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    49
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    50
static inline void ClearFrontEngine(Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    51
{
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
    52
	assert(v->type == VEH_TRAIN);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    53
	CLRBIT(v->subtype, Train_Front);
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    54
}
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    55
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    56
/** Check if a vehicle is an articulated part of an engine
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    57
 * @param v vehicle to check
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    58
 * @return Returns true if vehicle is an articulated part
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    59
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    60
static inline bool IsArticulatedPart(const Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    61
{
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
    62
	assert(v->type == VEH_TRAIN);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    63
	return HASBIT(v->subtype, Train_Articulated_Part);
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    64
}
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    65
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    66
/** Set a vehicle to be an articulated part
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    67
 * @param v vehicle to change
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    68
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    69
static inline void SetArticulatedPart(Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    70
{
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
    71
	assert(v->type == VEH_TRAIN);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    72
	SETBIT(v->subtype, Train_Articulated_Part);
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    73
}
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    74
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    75
/** Clear a vehicle from being an articulated part
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    76
 * @param v vehicle to change
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    77
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    78
static inline void ClearArticulatedPart(Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    79
{
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
    80
	assert(v->type == VEH_TRAIN);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    81
	CLRBIT(v->subtype, Train_Articulated_Part);
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    82
}
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    83
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    84
/** Check if a vehicle is a wagon
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    85
 * @param v vehicle to check
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    86
 * @return Returns true if vehicle is a wagon
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    87
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    88
static inline bool IsTrainWagon(const Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    89
{
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
    90
	assert(v->type == VEH_TRAIN);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    91
	return HASBIT(v->subtype, Train_Wagon);
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    92
}
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    93
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    94
/** Set a vehicle to be a wagon
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    95
 * @param v vehicle to change
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    96
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    97
static inline void SetTrainWagon(Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    98
{
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
    99
	assert(v->type == VEH_TRAIN);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   100
	SETBIT(v->subtype, Train_Wagon);
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   101
}
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   102
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   103
/** Clear wagon property
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   104
 * @param v vehicle to change
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   105
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   106
static inline void ClearTrainWagon(Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   107
{
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   108
	assert(v->type == VEH_TRAIN);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   109
	CLRBIT(v->subtype, Train_Wagon);
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   110
}
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   111
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   112
/** Check if a vehicle is an engine (can be first in a train)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   113
 * @param v vehicle to check
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   114
 * @return Returns true if vehicle is an engine
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   115
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   116
static inline bool IsTrainEngine(const Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   117
{
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   118
	assert(v->type == VEH_TRAIN);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   119
	return HASBIT(v->subtype, Train_Engine);
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   120
}
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   121
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   122
/** Set engine status
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   123
 * @param v vehicle to change
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   124
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   125
static inline void SetTrainEngine(Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   126
{
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   127
	assert(v->type == VEH_TRAIN);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   128
	SETBIT(v->subtype, Train_Engine);
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   129
}
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   130
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   131
/** Clear engine status
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   132
 * @param v vehicle to change
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   133
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   134
static inline void ClearTrainEngine(Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   135
{
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   136
	assert(v->type == VEH_TRAIN);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   137
	CLRBIT(v->subtype, Train_Engine);
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   138
}
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   139
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   140
/** Check if a vehicle is a free wagon (got no engine in front of it)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   141
 * @param v vehicle to check
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   142
 * @return Returns true if vehicle is a free wagon
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   143
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   144
static inline bool IsFreeWagon(const Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   145
{
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   146
	assert(v->type == VEH_TRAIN);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   147
	return HASBIT(v->subtype, Train_Free_Wagon);
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   148
}
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   149
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   150
/** Set if a vehicle is a free wagon
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   151
 * @param v vehicle to change
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   152
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   153
static inline void SetFreeWagon(Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   154
{
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   155
	assert(v->type == VEH_TRAIN);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   156
	SETBIT(v->subtype, Train_Free_Wagon);
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   157
}
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   158
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   159
/** Clear a vehicle from being a free wagon
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   160
 * @param v vehicle to change
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   161
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   162
static inline void ClearFreeWagon(Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   163
{
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   164
	assert(v->type == VEH_TRAIN);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   165
	CLRBIT(v->subtype, Train_Free_Wagon);
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   166
}
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   167
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   168
/** Check if a vehicle is a multiheaded engine
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   169
 * @param v vehicle to check
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   170
 * @return Returns true if vehicle is a multiheaded engine
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   171
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   172
static inline bool IsMultiheaded(const Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   173
{
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   174
	assert(v->type == VEH_TRAIN);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   175
	return HASBIT(v->subtype, Train_Multiheaded);
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   176
}
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   177
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   178
/** Set if a vehicle is a multiheaded engine
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   179
 * @param v vehicle to change
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   180
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   181
static inline void SetMultiheaded(Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   182
{
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   183
	assert(v->type == VEH_TRAIN);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   184
	SETBIT(v->subtype, Train_Multiheaded);
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   185
}
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   186
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   187
/** Clear multiheaded engine property
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   188
 * @param v vehicle to change
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   189
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   190
static inline void ClearMultiheaded(Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   191
{
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   192
	assert(v->type == VEH_TRAIN);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   193
	CLRBIT(v->subtype, Train_Multiheaded);
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   194
}
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   195
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   196
/** Check if an engine has an articulated part.
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   197
 * @param v Vehicle.
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   198
 * @return True if the engine has an articulated part.
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   199
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   200
static inline bool EngineHasArticPart(const Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   201
{
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   202
	assert(v->type == VEH_TRAIN);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   203
	return (v->next != NULL && IsArticulatedPart(v->next));
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   204
}
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   205
4384
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   206
/**
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   207
 * Get the next part of a multi-part engine.
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   208
 * Will only work on a multi-part engine (EngineHasArticPart(v) == true),
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   209
 * Result is undefined for normal engine.
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   210
 */
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   211
static inline Vehicle *GetNextArticPart(const Vehicle *v)
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   212
{
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   213
	assert(EngineHasArticPart(v));
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   214
	return v->next;
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   215
}
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   216
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   217
/** Get the last part of a multi-part engine.
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   218
 * @param v Vehicle.
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   219
 * @return Last part of the engine.
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   220
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   221
static inline Vehicle *GetLastEnginePart(Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   222
{
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   223
	assert(v->type == VEH_TRAIN);
4384
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   224
	while (EngineHasArticPart(v)) v = GetNextArticPart(v);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   225
	return v;
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   226
}
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   227
4384
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   228
/** Get the next real (non-articulated part) vehicle in the consist.
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   229
 * @param v Vehicle.
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   230
 * @return Next vehicle in the consist.
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   231
 */
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   232
static inline Vehicle *GetNextVehicle(const Vehicle *v)
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   233
{
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   234
	assert(v->type == VEH_TRAIN);
4384
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   235
	while (EngineHasArticPart(v)) v = GetNextArticPart(v);
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   236
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   237
	/* v now contains the last artic part in the engine */
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   238
	return v->next;
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   239
}
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   240
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6030
diff changeset
   241
void ConvertOldMultiheadToNew();
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6030
diff changeset
   242
void ConnectMultiheadedTrains();
4737
e38af7736681 (svn r6649) - Codechange: Show more correct capacity of articulated wagons in the train purchase list.
peter1138
parents: 4653
diff changeset
   243
uint CountArticulatedParts(EngineID engine_type);
2855
950b5a56f9d5 (svn r3403) -Codechange: [multiheaded engines] the references between the front and rear engines are no longer saved
bjarni
parents: 2676
diff changeset
   244
4648
ab94e3a447a8 (svn r6524) -Code cleanup r6515: cleaned up the command to start/stop all vehicles in a depot.
bjarni
parents: 4640
diff changeset
   245
int CheckTrainInDepot(const Vehicle *v, bool needs_to_be_stopped);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5726
diff changeset
   246
void CcBuildLoco(bool success, TileIndex tile, uint32 p1, uint32 p2);
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5726
diff changeset
   247
void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2);
4653
091f530bae28 (svn r6529) -Fix r6513: [depot window] added missing switch in CcCloneVehicle()
bjarni
parents: 4648
diff changeset
   248
void CcCloneTrain(bool success, TileIndex tile, uint32 p1, uint32 p2);
4640
cabffc571e55 (svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents: 4384
diff changeset
   249
5316
b04421921eae (svn r7473) -Fix (r7269): Pass a cargo type to determine the freight weight
peter1138
parents: 5163
diff changeset
   250
byte FreightWagonMult(CargoID cargo);
5163
83acad83bbdd (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
   251
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9908
diff changeset
   252
/**
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9908
diff changeset
   253
 * This class 'wraps' Vehicle; you do not actually instantiate this class.
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9908
diff changeset
   254
 * You create a Vehicle using AllocateVehicle, so it is added to the pool
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9908
diff changeset
   255
 * and you reinitialize that to a Train using:
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9908
diff changeset
   256
 *   v = new (v) Train();
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9908
diff changeset
   257
 *
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9908
diff changeset
   258
 * As side-effect the vehicle type is set correctly.
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9908
diff changeset
   259
 */
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9908
diff changeset
   260
struct Train : public Vehicle {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9908
diff changeset
   261
	/** Initializes the Vehicle to a train */
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9908
diff changeset
   262
	Train() { this->type = VEH_TRAIN; }
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9908
diff changeset
   263
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9908
diff changeset
   264
	/** We want to 'destruct' the right class. */
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9908
diff changeset
   265
	virtual ~Train() {}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9908
diff changeset
   266
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9908
diff changeset
   267
	const char *GetTypeString() const { return "train"; }
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9908
diff changeset
   268
	void MarkDirty();
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9908
diff changeset
   269
	void UpdateDeltaXY(Direction direction);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9908
diff changeset
   270
	ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_TRAIN_INC : EXPENSES_TRAIN_RUN; }
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9908
diff changeset
   271
	WindowClass GetVehicleListWindowClass() const { return WC_TRAINS_LIST; }
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9908
diff changeset
   272
	void PlayLeaveStationSound() const;
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   273
	bool IsPrimaryVehicle() const { return IsFrontEngine(this); }
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   274
	bool HasFront() const { return true; }
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9908
diff changeset
   275
};
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9908
diff changeset
   276
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   277
#endif /* TRAIN_H */