author | rubidium |
Mon, 31 Mar 2008 00:17:39 +0000 | |
changeset 8786 | 1823ff88a054 |
parent 8626 | 9781464622be |
child 8827 | 730524764a69 |
permissions | -rw-r--r-- |
3959 | 1 |
/* $Id$ */ |
2 |
||
6417 | 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" |
8786
1823ff88a054
(svn r12490) -Codechange: rename engine.h to engine_func.h and remove unneeded inclusions of engine.h and/or replace them with engine_type.h.
rubidium
parents:
8626
diff
changeset
|
9 |
#include "engine_func.h" |
8116
8da76dcb3287
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
7548
diff
changeset
|
10 |
#include "economy_func.h" |
3959 | 11 |
|
6857
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6773
diff
changeset
|
12 |
enum RoadVehicleSubType { |
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6773
diff
changeset
|
13 |
RVST_FRONT, |
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6773
diff
changeset
|
14 |
RVST_ARTIC_PART, |
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6773
diff
changeset
|
15 |
}; |
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 |
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
|
18 |
{ |
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6773
diff
changeset
|
19 |
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
|
20 |
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
|
21 |
} |
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 |
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
|
24 |
{ |
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6773
diff
changeset
|
25 |
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
|
26 |
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
|
27 |
} |
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 |
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
|
30 |
{ |
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6773
diff
changeset
|
31 |
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
|
32 |
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
|
33 |
} |
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 |
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
|
36 |
{ |
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6773
diff
changeset
|
37 |
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
|
38 |
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
|
39 |
} |
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 |
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
|
42 |
{ |
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6773
diff
changeset
|
43 |
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
|
44 |
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
|
45 |
} |
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 |
|
5786
9bbd2d7f2a30
(svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents:
5475
diff
changeset
|
48 |
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
|
49 |
|
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
|
50 |
|
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 |
* 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
|
53 |
* 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
|
54 |
* 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
|
55 |
* 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
|
56 |
* |
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 |
* 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
|
58 |
*/ |
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 |
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
|
60 |
/** 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
|
61 |
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
|
62 |
|
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 |
/** 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
|
64 |
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
|
65 |
|
6563
fed2a162046b
(svn r9765) -Codechange: constify some class functions.
rubidium
parents:
6562
diff
changeset
|
66 |
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
|
67 |
void MarkDirty(); |
6558
c88e142f896e
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents:
6553
diff
changeset
|
68 |
void UpdateDeltaXY(Direction direction); |
6563
fed2a162046b
(svn r9765) -Codechange: constify some class functions.
rubidium
parents:
6562
diff
changeset
|
69 |
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
|
70 |
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
|
71 |
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
|
72 |
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
|
73 |
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
|
74 |
int GetDisplayMaxSpeed() const { return this->max_speed * 10 / 32; } |
8626
9781464622be
(svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents:
8467
diff
changeset
|
75 |
Money GetRunningCost() const { return RoadVehInfo(this->engine_type)->running_cost * GetPriceByIndex(RoadVehInfo(this->engine_type)->running_cost_class); } |
7490
bb27d92565d3
(svn r11001) -Codechange: unify the way to determine whether a vehicle is in a depot.
rubidium
parents:
7488
diff
changeset
|
76 |
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
|
77 |
void Tick(); |
8467
605661f3a91c
(svn r12037) -Codechange: replace OnNewDay_(Aircraft|RoadVeh|Ship|Train) with an OnNewDay method in the Vehicle class
glx
parents:
8211
diff
changeset
|
78 |
void OnNewDay(); |
6552
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
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 */ |