src/roadveh.h
author rubidium
Thu, 27 Dec 2007 13:35:39 +0000
changeset 8144 65cec0877b78
parent 8116 8da76dcb3287
child 8211 29a8510dfd62
permissions -rw-r--r--
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
3959
48f178431701 (svn r5118) Add IsRoadVehInDepot{Stopped,}()
tron
parents:
diff changeset
     1
/* $Id$ */
48f178431701 (svn r5118) Add IsRoadVehInDepot{Stopped,}()
tron
parents:
diff changeset
     2
6417
7594fdb854fd (svn r9553) -Documentation: fix ambiguity issue.
rubidium
parents: 6393
diff changeset
     3
/** @file src/roadveh.h Road vehicle states */
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6259
diff changeset
     4
4666
172a0cdf28a6 (svn r6560) - Codechange: Minor fix; add missing #include guards and comments, and correct svn properties on bmp.[ch]
peter1138
parents: 4653
diff changeset
     5
#ifndef ROADVEH_H
172a0cdf28a6 (svn r6560) - Codechange: Minor fix; add missing #include guards and comments, and correct svn properties on bmp.[ch]
peter1138
parents: 4653
diff changeset
     6
#define ROADVEH_H
172a0cdf28a6 (svn r6560) - Codechange: Minor fix; add missing #include guards and comments, and correct svn properties on bmp.[ch]
peter1138
parents: 4653
diff changeset
     7
8144
65cec0877b78 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8116
diff changeset
     8
#include "vehicle_base.h"
7488
6f51ddf4c225 (svn r10999) -Codechange: unify the way the running cost of a vehicle is determined. Patch by nycom.
rubidium
parents: 7484
diff changeset
     9
#include "engine.h"
6f51ddf4c225 (svn r10999) -Codechange: unify the way the running cost of a vehicle is determined. Patch by nycom.
rubidium
parents: 7484
diff changeset
    10
#include "variables.h"
8116
8da76dcb3287 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 7548
diff changeset
    11
#include "economy_func.h"
3959
48f178431701 (svn r5118) Add IsRoadVehInDepot{Stopped,}()
tron
parents:
diff changeset
    12
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    13
enum RoadVehicleSubType {
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    14
	RVST_FRONT,
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    15
	RVST_ARTIC_PART,
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    16
};
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    17
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    18
static inline bool IsRoadVehFront(const Vehicle *v)
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    19
{
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    20
	assert(v->type == VEH_ROAD);
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    21
	return v->subtype == RVST_FRONT;
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    22
}
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    23
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    24
static inline void SetRoadVehFront(Vehicle *v)
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    25
{
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    26
	assert(v->type == VEH_ROAD);
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    27
	v->subtype = RVST_FRONT;
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    28
}
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    29
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    30
static inline bool IsRoadVehArticPart(const Vehicle *v)
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    31
{
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    32
	assert(v->type == VEH_ROAD);
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    33
	return v->subtype == RVST_ARTIC_PART;
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    34
}
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    35
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    36
static inline void SetRoadVehArticPart(Vehicle *v)
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    37
{
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    38
	assert(v->type == VEH_ROAD);
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    39
	v->subtype = RVST_ARTIC_PART;
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    40
}
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    41
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    42
static inline bool RoadVehHasArticPart(const Vehicle *v)
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    43
{
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    44
	assert(v->type == VEH_ROAD);
7492
35acee076719 (svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium
parents: 7490
diff changeset
    45
	return v->Next() != NULL && IsRoadVehArticPart(v->Next());
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    46
}
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    47
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    48
5786
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5475
diff changeset
    49
void CcBuildRoadVeh(bool success, TileIndex tile, uint32 p1, uint32 p2);
4666
172a0cdf28a6 (svn r6560) - Codechange: Minor fix; add missing #include guards and comments, and correct svn properties on bmp.[ch]
peter1138
parents: 4653
diff changeset
    50
6552
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6417
diff changeset
    51
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6417
diff changeset
    52
/**
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6417
diff changeset
    53
 * This class 'wraps' Vehicle; you do not actually instantiate this class.
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6417
diff changeset
    54
 * You create a Vehicle using AllocateVehicle, so it is added to the pool
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6417
diff changeset
    55
 * and you reinitialize that to a Train using:
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6417
diff changeset
    56
 *   v = new (v) RoadVehicle();
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6417
diff changeset
    57
 *
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6417
diff changeset
    58
 * As side-effect the vehicle type is set correctly.
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6417
diff changeset
    59
 */
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6417
diff changeset
    60
struct RoadVehicle : public Vehicle {
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6417
diff changeset
    61
	/** Initializes the Vehicle to a road vehicle */
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6417
diff changeset
    62
	RoadVehicle() { this->type = VEH_ROAD; }
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6417
diff changeset
    63
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6417
diff changeset
    64
	/** We want to 'destruct' the right class. */
7412
51db351a3313 (svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium
parents: 7318
diff changeset
    65
	virtual ~RoadVehicle() { this->PreDestructor(); }
6552
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6417
diff changeset
    66
6563
fed2a162046b (svn r9765) -Codechange: constify some class functions.
rubidium
parents: 6562
diff changeset
    67
	const char *GetTypeString() const { return "road vehicle"; }
6553
976a684212ad (svn r9755) -Codechange: refactor some more of the begin loading stuff.
rubidium
parents: 6552
diff changeset
    68
	void MarkDirty();
6558
c88e142f896e (svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents: 6553
diff changeset
    69
	void UpdateDeltaXY(Direction direction);
6563
fed2a162046b (svn r9765) -Codechange: constify some class functions.
rubidium
parents: 6562
diff changeset
    70
	ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_ROADVEH_INC : EXPENSES_ROADVEH_RUN; }
fed2a162046b (svn r9765) -Codechange: constify some class functions.
rubidium
parents: 6562
diff changeset
    71
	WindowClass GetVehicleListWindowClass() const { return WC_ROADVEH_LIST; }
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    72
	bool IsPrimaryVehicle() const { return IsRoadVehFront(this); }
7134
5b2d47128d05 (svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium
parents: 6857
diff changeset
    73
	int GetImage(Direction direction) const;
7477
ee28f55ab5e8 (svn r10984) -Codechange: unify the way one can get the current speed in the same forwat so we can display it.
rubidium
parents: 7412
diff changeset
    74
	int GetDisplaySpeed() const { return this->cur_speed * 10 / 32; }
7484
7734e4119e70 (svn r10995) -Codechange: unify the way to get the displayed maxium speed of a vehicle. Patch by nycom.
rubidium
parents: 7478
diff changeset
    75
	int GetDisplayMaxSpeed() const { return this->max_speed * 10 / 32; }
7488
6f51ddf4c225 (svn r10999) -Codechange: unify the way the running cost of a vehicle is determined. Patch by nycom.
rubidium
parents: 7484
diff changeset
    76
	Money GetRunningCost() const { return RoadVehInfo(this->engine_type)->running_cost * _price.roadveh_running; }
7490
bb27d92565d3 (svn r11001) -Codechange: unify the way to determine whether a vehicle is in a depot.
rubidium
parents: 7488
diff changeset
    77
	bool IsInDepot() const { return this->u.road.state == RVSB_IN_DEPOT; }
7135
3c1bcca0d6bb (svn r10409) -Codechange: replace (Aircraft|RoadVeh|Ship|Train)_Tick with a Tick method in the Vehicle class.
rubidium
parents: 7134
diff changeset
    78
	void Tick();
6552
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6417
diff changeset
    79
};
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6417
diff changeset
    80
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    81
byte GetRoadVehLength(const Vehicle *v);
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    82
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    83
void RoadVehUpdateCache(Vehicle *v);
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6773
diff changeset
    84
4666
172a0cdf28a6 (svn r6560) - Codechange: Minor fix; add missing #include guards and comments, and correct svn properties on bmp.[ch]
peter1138
parents: 4653
diff changeset
    85
#endif /* ROADVEH_H */