author | rubidium |
Sun, 14 Dec 2008 16:56:28 +0000 | |
changeset 10422 | f5985144f4a6 |
parent 9935 | abf91482d3af |
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" |
9070
dd0121143eba
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
9043
diff
changeset
|
10 |
#include "engine_base.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 | 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 |
|
8890
8a0fa7ff70a0
(svn r12657) -Codechange: add 'FindClosestDepot' to the vehicle class.
rubidium
parents:
8827
diff
changeset
|
51 |
byte GetRoadVehLength(const Vehicle *v); |
8a0fa7ff70a0
(svn r12657) -Codechange: add 'FindClosestDepot' to the vehicle class.
rubidium
parents:
8827
diff
changeset
|
52 |
|
8a0fa7ff70a0
(svn r12657) -Codechange: add 'FindClosestDepot' to the vehicle class.
rubidium
parents:
8827
diff
changeset
|
53 |
void RoadVehUpdateCache(Vehicle *v); |
8a0fa7ff70a0
(svn r12657) -Codechange: add 'FindClosestDepot' to the vehicle class.
rubidium
parents:
8827
diff
changeset
|
54 |
|
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
|
55 |
|
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 |
* 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
|
58 |
* 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
|
59 |
* 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
|
60 |
* 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
|
61 |
* |
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 |
* 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
|
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 |
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
|
65 |
/** 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
|
66 |
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
|
67 |
|
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
|
68 |
/** 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
|
69 |
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
|
70 |
|
6563
fed2a162046b
(svn r9765) -Codechange: constify some class functions.
rubidium
parents:
6562
diff
changeset
|
71 |
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
|
72 |
void MarkDirty(); |
6558
c88e142f896e
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents:
6553
diff
changeset
|
73 |
void UpdateDeltaXY(Direction direction); |
6563
fed2a162046b
(svn r9765) -Codechange: constify some class functions.
rubidium
parents:
6562
diff
changeset
|
74 |
ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_ROADVEH_INC : EXPENSES_ROADVEH_RUN; } |
6857
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6773
diff
changeset
|
75 |
bool IsPrimaryVehicle() const { return IsRoadVehFront(this); } |
9022
8fa9e902b06e
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
peter1138
parents:
8890
diff
changeset
|
76 |
SpriteID 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
|
77 |
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
|
78 |
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
|
79 |
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
|
80 |
bool IsInDepot() const { return this->u.road.state == RVSB_IN_DEPOT; } |
9935
abf91482d3af
(svn r14090) -Fix: the vehicle window of articulated road vehicles would show the clone/refit button when the vehicle was not completely stopped in the depot.
rubidium
parents:
9070
diff
changeset
|
81 |
bool IsStoppedInDepot() const; |
7135
3c1bcca0d6bb
(svn r10409) -Codechange: replace (Aircraft|RoadVeh|Ship|Train)_Tick with a Tick method in the Vehicle class.
rubidium
parents:
7134
diff
changeset
|
82 |
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
|
83 |
void OnNewDay(); |
8827
730524764a69
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium
parents:
8786
diff
changeset
|
84 |
TileIndex GetOrderStationLocation(StationID station); |
8890
8a0fa7ff70a0
(svn r12657) -Codechange: add 'FindClosestDepot' to the vehicle class.
rubidium
parents:
8827
diff
changeset
|
85 |
bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse); |
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
|
86 |
}; |
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
|
87 |
|
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
|
88 |
#endif /* ROADVEH_H */ |