src/train.h
author glx
Fri, 13 Jun 2008 15:43:39 +0000
branchnoai
changeset 10955 56b381e5253f
parent 10455 22c441f5adf9
permissions -rw-r--r--
(svn r13509) [NoAI] -Sync: with trunk r13472:13508.
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
10455
22c441f5adf9 (svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents: 10355
diff changeset
     3
/** @file train.h Base for the train class. */
9574
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 6574
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"
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
     9
#include "core/bitmath_func.hpp"
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    10
#include "vehicle_base.h"
2676
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
10142
56ee7da4ad56 (svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents: 9869
diff changeset
    13
/** enum to handle train subtypes
2676
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
 */
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    17
enum TrainSubtype {
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
    18
	TS_FRONT             = 0, ///< Leading engine of a train
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
    19
	TS_ARTICULATED_PART  = 1, ///< Articulated part of an engine
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
    20
	TS_WAGON             = 2, ///< Wagon
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
    21
	TS_ENGINE            = 3, ///< Engine, that can be front engines, but might be placed behind another engine
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
    22
	TS_FREE_WAGON        = 4, ///< First in a wagon chain (in depot)
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
    23
	TS_MULTIHEADED       = 5, ///< Engine is a multiheaded
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    24
};
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    25
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
/** 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
    28
 * @param v vehicle to check
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    29
 * @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
    30
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    31
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
    32
{
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9620
diff changeset
    33
	assert(v->type == VEH_TRAIN);
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
    34
	return HasBit(v->subtype, TS_FRONT);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    35
}
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
/** Set front engine state
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    38
 * @param v vehicle to change
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    39
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    40
static inline void SetFrontEngine(Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    41
{
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9620
diff changeset
    42
	assert(v->type == VEH_TRAIN);
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
    43
	SetBit(v->subtype, TS_FRONT);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    44
}
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
/** Remove the front engine state
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    47
 * @param v vehicle to change
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    48
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    49
static inline void ClearFrontEngine(Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    50
{
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9620
diff changeset
    51
	assert(v->type == VEH_TRAIN);
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
    52
	ClrBit(v->subtype, TS_FRONT);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    53
}
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
/** 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
    56
 * @param v vehicle to check
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    57
 * @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
    58
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    59
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
    60
{
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9620
diff changeset
    61
	assert(v->type == VEH_TRAIN);
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
    62
	return HasBit(v->subtype, TS_ARTICULATED_PART);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    63
}
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
/** 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
    66
 * @param v vehicle to change
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    67
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    68
static inline void SetArticulatedPart(Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    69
{
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9620
diff changeset
    70
	assert(v->type == VEH_TRAIN);
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
    71
	SetBit(v->subtype, TS_ARTICULATED_PART);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    72
}
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
/** 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
    75
 * @param v vehicle to change
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    76
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    77
static inline void ClearArticulatedPart(Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    78
{
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9620
diff changeset
    79
	assert(v->type == VEH_TRAIN);
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
    80
	ClrBit(v->subtype, TS_ARTICULATED_PART);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    81
}
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
/** 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
    84
 * @param v vehicle to check
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    85
 * @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
    86
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    87
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
    88
{
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9620
diff changeset
    89
	assert(v->type == VEH_TRAIN);
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
    90
	return HasBit(v->subtype, TS_WAGON);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    91
}
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
/** 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
    94
 * @param v vehicle to change
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    95
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    96
static inline void SetTrainWagon(Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
    97
{
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9620
diff changeset
    98
	assert(v->type == VEH_TRAIN);
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
    99
	SetBit(v->subtype, TS_WAGON);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   100
}
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
/** Clear wagon property
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   103
 * @param v vehicle to change
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   104
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   105
static inline void ClearTrainWagon(Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   106
{
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9620
diff changeset
   107
	assert(v->type == VEH_TRAIN);
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   108
	ClrBit(v->subtype, TS_WAGON);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   109
}
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
/** 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
   112
 * @param v vehicle to check
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   113
 * @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
   114
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   115
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
   116
{
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9620
diff changeset
   117
	assert(v->type == VEH_TRAIN);
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   118
	return HasBit(v->subtype, TS_ENGINE);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   119
}
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
/** Set engine status
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   122
 * @param v vehicle to change
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   123
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   124
static inline void SetTrainEngine(Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   125
{
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9620
diff changeset
   126
	assert(v->type == VEH_TRAIN);
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   127
	SetBit(v->subtype, TS_ENGINE);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   128
}
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
/** Clear engine status
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   131
 * @param v vehicle to change
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   132
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   133
static inline void ClearTrainEngine(Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   134
{
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9620
diff changeset
   135
	assert(v->type == VEH_TRAIN);
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   136
	ClrBit(v->subtype, TS_ENGINE);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   137
}
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
/** 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
   140
 * @param v vehicle to check
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   141
 * @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
   142
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   143
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
   144
{
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9620
diff changeset
   145
	assert(v->type == VEH_TRAIN);
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   146
	return HasBit(v->subtype, TS_FREE_WAGON);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   147
}
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
/** 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
   150
 * @param v vehicle to change
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   151
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   152
static inline void SetFreeWagon(Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   153
{
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9620
diff changeset
   154
	assert(v->type == VEH_TRAIN);
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   155
	SetBit(v->subtype, TS_FREE_WAGON);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   156
}
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
/** 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
   159
 * @param v vehicle to change
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   160
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   161
static inline void ClearFreeWagon(Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   162
{
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9620
diff changeset
   163
	assert(v->type == VEH_TRAIN);
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   164
	ClrBit(v->subtype, TS_FREE_WAGON);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   165
}
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
/** 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
   168
 * @param v vehicle to check
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   169
 * @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
   170
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   171
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
   172
{
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9620
diff changeset
   173
	assert(v->type == VEH_TRAIN);
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   174
	return HasBit(v->subtype, TS_MULTIHEADED);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   175
}
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
/** 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
   178
 * @param v vehicle to change
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   179
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   180
static inline void SetMultiheaded(Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   181
{
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9620
diff changeset
   182
	assert(v->type == VEH_TRAIN);
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   183
	SetBit(v->subtype, TS_MULTIHEADED);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   184
}
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
/** Clear multiheaded engine property
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   187
 * @param v vehicle to change
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   188
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   189
static inline void ClearMultiheaded(Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   190
{
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9620
diff changeset
   191
	assert(v->type == VEH_TRAIN);
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   192
	ClrBit(v->subtype, TS_MULTIHEADED);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   193
}
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
/** 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
   196
 * @param v Vehicle.
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   197
 * @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
   198
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   199
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
   200
{
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9620
diff changeset
   201
	assert(v->type == VEH_TRAIN);
9701
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9631
diff changeset
   202
	return (v->Next() != NULL && IsArticulatedPart(v->Next()));
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   203
}
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   204
4384
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   205
/**
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   206
 * Get the next part of a multi-part engine.
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   207
 * Will only work on a multi-part engine (EngineHasArticPart(v) == true),
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   208
 * Result is undefined for normal engine.
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   209
 */
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   210
static inline Vehicle *GetNextArticPart(const Vehicle *v)
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   211
{
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   212
	assert(EngineHasArticPart(v));
9701
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9631
diff changeset
   213
	return v->Next();
4384
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   214
}
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   215
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   216
/** 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
   217
 * @param v Vehicle.
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   218
 * @return Last part of the engine.
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   219
 */
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   220
static inline Vehicle *GetLastEnginePart(Vehicle *v)
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   221
{
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9620
diff changeset
   222
	assert(v->type == VEH_TRAIN);
4384
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   223
	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
   224
	return v;
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   225
}
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   226
9703
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   227
/** Tell if we are dealing with the rear end of a multiheaded engine.
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   228
 * @param v Vehicle.
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   229
 * @return True if the engine is the rear part of a dualheaded engine.
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   230
 */
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   231
static inline bool IsRearDualheaded(const Vehicle *v)
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   232
{
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   233
	assert(v->type == VEH_TRAIN);
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   234
	return (IsMultiheaded(v) && !IsTrainEngine(v));
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   235
}
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   236
4384
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   237
/** Get the next real (non-articulated part) vehicle in the consist.
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   238
 * @param v Vehicle.
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   239
 * @return Next vehicle in the consist.
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   240
 */
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   241
static inline Vehicle *GetNextVehicle(const Vehicle *v)
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   242
{
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9620
diff changeset
   243
	assert(v->type == VEH_TRAIN);
4384
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   244
	while (EngineHasArticPart(v)) v = GetNextArticPart(v);
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   245
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   246
	/* v now contains the last artic part in the engine */
9701
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9631
diff changeset
   247
	return v->Next();
4384
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   248
}
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 2855
diff changeset
   249
9703
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   250
/** Get the next real (non-articulated part and non rear part of dualheaded engine) vehicle in the consist.
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   251
 * @param v Vehicle.
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   252
 * @return Next vehicle in the consist.
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   253
 */
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   254
static inline Vehicle *GetNextUnit(Vehicle *v)
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   255
{
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   256
	assert(v->type == VEH_TRAIN);
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   257
	v = GetNextVehicle(v);
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   258
	if (v != NULL && IsRearDualheaded(v)) v = v->Next();
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   259
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   260
	return v;
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   261
}
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   262
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6030
diff changeset
   263
void ConvertOldMultiheadToNew();
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6030
diff changeset
   264
void ConnectMultiheadedTrains();
4737
e38af7736681 (svn r6649) - Codechange: Show more correct capacity of articulated wagons in the train purchase list.
peter1138
parents: 4653
diff changeset
   265
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
   266
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5726
diff changeset
   267
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
   268
void CcBuildWagon(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
   269
5316
b04421921eae (svn r7473) -Fix (r7269): Pass a cargo type to determine the freight weight
peter1138
parents: 5163
diff changeset
   270
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
   271
9701
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9631
diff changeset
   272
int CheckTrainInDepot(const Vehicle *v, bool needs_to_be_stopped);
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9631
diff changeset
   273
int CheckTrainStoppedInDepot(const Vehicle *v);
9826
9707ad4c9b60 (svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents: 9732
diff changeset
   274
void UpdateTrainAcceleration(Vehicle* v);
9701
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9631
diff changeset
   275
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9574
diff changeset
   276
/**
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9574
diff changeset
   277
 * This class 'wraps' Vehicle; you do not actually instantiate this class.
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9574
diff changeset
   278
 * You create a Vehicle using AllocateVehicle, so it is added to the pool
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9574
diff changeset
   279
 * and you reinitialize that to a Train using:
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9574
diff changeset
   280
 *   v = new (v) Train();
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9574
diff changeset
   281
 *
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9574
diff changeset
   282
 * As side-effect the vehicle type is set correctly.
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9574
diff changeset
   283
 */
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9574
diff changeset
   284
struct Train : public Vehicle {
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9574
diff changeset
   285
	/** Initializes the Vehicle to a train */
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9574
diff changeset
   286
	Train() { this->type = VEH_TRAIN; }
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9574
diff changeset
   287
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9574
diff changeset
   288
	/** We want to 'destruct' the right class. */
9701
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9631
diff changeset
   289
	virtual ~Train() { this->PreDestructor(); }
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9574
diff changeset
   290
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9574
diff changeset
   291
	const char *GetTypeString() const { return "train"; }
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9574
diff changeset
   292
	void MarkDirty();
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9574
diff changeset
   293
	void UpdateDeltaXY(Direction direction);
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9574
diff changeset
   294
	ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_TRAIN_INC : EXPENSES_TRAIN_RUN; }
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9574
diff changeset
   295
	void PlayLeaveStationSound() const;
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9620
diff changeset
   296
	bool IsPrimaryVehicle() const { return IsFrontEngine(this); }
10294
7798ae816af8 (svn r12826) [NoAI] -Sync: with trunk r12780:12824
glx
parents: 10142
diff changeset
   297
	SpriteID GetImage(Direction direction) const;
9703
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   298
	int GetDisplaySpeed() const { return this->u.rail.last_speed * 10 / 16; }
9701
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9631
diff changeset
   299
	int GetDisplayMaxSpeed() const { return this->u.rail.cached_max_speed * 10 / 16; }
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9631
diff changeset
   300
	Money GetRunningCost() const;
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9631
diff changeset
   301
	bool IsInDepot() const { return CheckTrainInDepot(this, false) != -1; }
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9631
diff changeset
   302
	bool IsStoppedInDepot() const { return CheckTrainStoppedInDepot(this) >= 0; }
9631
8a2d1c2ceb88 (svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents: 9625
diff changeset
   303
	void Tick();
9724
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
   304
	void OnNewDay();
9869
6404afe43575 (svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents: 9826
diff changeset
   305
	TileIndex GetOrderStationLocation(StationID station);
10142
56ee7da4ad56 (svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents: 9869
diff changeset
   306
	bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9574
diff changeset
   307
};
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9574
diff changeset
   308
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
diff changeset
   309
#endif /* TRAIN_H */