author | truebrain |
Fri, 18 Jul 2008 10:15:16 +0000 | |
branch | noai |
changeset 11168 | 3842648184cd |
parent 11057 | 188a9ca6d8de |
permissions | -rw-r--r-- |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
1 |
/* $Id$ */ |
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
2 |
|
9833
89a64246458f
(svn r12496) [NoAI] -Documentation: give the .cpp files a nice uniform format too
truebrain
parents:
9806
diff
changeset
|
3 |
/** @file ai_vehicle.cpp Implementation of AIVehicle. */ |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
4 |
|
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
5 |
#include "ai_vehicle.hpp" |
9711
c8b427215c9d
(svn r11295) [NoAI] -Change [API CHANGE]: put Engine things in AIEngine, and rename functions as such. Most noticable: FindBestXXXVehicle -> FineBestXXXEngine
truelight
parents:
9709
diff
changeset
|
6 |
#include "ai_engine.hpp" |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
7 |
#include "ai_cargo.hpp" |
9706
8d8f719a4e69
(svn r11250) [NoAI] -Fix [API CHANGE]: SkipVehicleOrder always skipped to first vehicle order.. replaced with SkipToVehicleOrder, and added a param to specify to which order it should skip (dynaxo)
truelight
parents:
9699
diff
changeset
|
8 |
#include "ai_order.hpp" |
10339
ce6cd68d9eb8
(svn r12880) [NoAI] -Add: introduces ai_types.hpp, which has all NNNId like VehicleID. This simplifies the include-mess, and avoids including tons of _type.h for just a single typedef.
truebrain
parents:
10249
diff
changeset
|
9 |
#include "../../openttd.h" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
10 |
#include "../../player_func.h" |
9662
67a558a1aeb8
(svn r10574) [NoAI] -Fix: make a better BestVehicle detection for aircrafts
truelight
parents:
9654
diff
changeset
|
11 |
#include "../../aircraft.h" |
10087
0cb23b9abbf7
(svn r12611) [NoAI] -Codechange: use EnforcePrecondition where possible in AIVehicle. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
12 |
#include "../../string_func.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9711
diff
changeset
|
13 |
#include "../../strings_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9711
diff
changeset
|
14 |
#include "../../core/alloc_func.hpp" |
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
15 |
#include "../../command_func.h" |
9699
e1b5f29cc6f9
(svn r10940) [NoAI] -Add: added AIVehicle::GetName and AIVehicle::SetName to set vehicle names
truelight
parents:
9691
diff
changeset
|
16 |
#include "table/strings.h" |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
17 |
|
9497
f6678533ccba
(svn r9369) [NoAI] -Codechange: make some IsValidXXX() function static, so they can be used by the other classes without the need for an instance.
rubidium
parents:
9496
diff
changeset
|
18 |
/* static */ bool AIVehicle::IsValidVehicle(VehicleID vehicle_id) |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
19 |
{ |
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9733
diff
changeset
|
20 |
return ::IsValidVehicleID(vehicle_id) && ::GetVehicle(vehicle_id)->owner == _current_player && ::GetVehicle(vehicle_id)->IsPrimaryVehicle(); |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
21 |
} |
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
22 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
23 |
/* static */ VehicleID AIVehicle::BuildVehicle(TileIndex depot, EngineID engine_id) |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
24 |
{ |
10389
a922e7213c8a
(svn r12931) [NoAI] -Fix: AIVehicle::BuildVehicle() returned 'false' in some cases instead of INVALID_VEHICLE (Yexo)
truebrain
parents:
10339
diff
changeset
|
25 |
EnforcePrecondition(INVALID_VEHICLE, AIEngine::IsValidEngine(engine_id)); |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
26 |
|
9560
ff2dde050a4c
(svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents:
9516
diff
changeset
|
27 |
/* Reset the internal NewVehicleID in case we are in TestMode */ |
ff2dde050a4c
(svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents:
9516
diff
changeset
|
28 |
AIObject::SetNewVehicleID(0); |
ff2dde050a4c
(svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents:
9516
diff
changeset
|
29 |
|
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
30 |
bool ret; |
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
31 |
switch (::GetEngine(engine_id)->type) { |
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
32 |
case VEH_ROAD: ret = AIObject::DoCommand(depot, engine_id, 0, CMD_BUILD_ROAD_VEH); break; |
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
33 |
case VEH_TRAIN: ret = AIObject::DoCommand(depot, engine_id, 0, CMD_BUILD_RAIL_VEHICLE); break; |
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
34 |
case VEH_SHIP: ret = AIObject::DoCommand(depot, engine_id, 0, CMD_BUILD_SHIP); break; |
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
35 |
case VEH_AIRCRAFT: ret = AIObject::DoCommand(depot, engine_id, 0, CMD_BUILD_AIRCRAFT); break; |
9654
b836eb5c521f
(svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
9637
diff
changeset
|
36 |
default: NOT_REACHED(); return INVALID_VEHICLE; |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
37 |
} |
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
38 |
|
9496
05ebee9884b3
(svn r9368) [NoAI] -Fix: store _new_vehicle_id directly after successful handling the command in a per-AI-player-safe piece of memory, so we can restore the value when ever we want later in the process
truelight
parents:
9491
diff
changeset
|
39 |
return ret ? AIObject::GetNewVehicleID() : INVALID_VEHICLE; |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
40 |
} |
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
41 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
42 |
/* static */ VehicleID AIVehicle::CloneVehicle(TileIndex depot, VehicleID vehicle_id, bool share_orders) |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
43 |
{ |
10087
0cb23b9abbf7
(svn r12611) [NoAI] -Codechange: use EnforcePrecondition where possible in AIVehicle. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
44 |
EnforcePrecondition(false, IsValidVehicle(vehicle_id)); |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
45 |
|
9560
ff2dde050a4c
(svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents:
9516
diff
changeset
|
46 |
/* Reset the internal NewVehicleID in case we are in TestMode */ |
ff2dde050a4c
(svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents:
9516
diff
changeset
|
47 |
AIObject::SetNewVehicleID(0); |
ff2dde050a4c
(svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents:
9516
diff
changeset
|
48 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
49 |
bool ret = AIObject::DoCommand(depot, vehicle_id, share_orders, CMD_CLONE_VEHICLE); |
9496
05ebee9884b3
(svn r9368) [NoAI] -Fix: store _new_vehicle_id directly after successful handling the command in a per-AI-player-safe piece of memory, so we can restore the value when ever we want later in the process
truelight
parents:
9491
diff
changeset
|
50 |
return ret ? AIObject::GetNewVehicleID() : INVALID_VEHICLE; |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
51 |
} |
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
52 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
53 |
/* static */ bool AIVehicle::RefitVehicle(VehicleID vehicle_id, CargoID cargo) |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
54 |
{ |
10087
0cb23b9abbf7
(svn r12611) [NoAI] -Codechange: use EnforcePrecondition where possible in AIVehicle. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
55 |
EnforcePrecondition(false, IsValidVehicle(vehicle_id) && AICargo::IsValidCargo(cargo)); |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
56 |
|
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
57 |
switch (::GetVehicle(vehicle_id)->type) { |
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
58 |
case VEH_ROAD: return AIObject::DoCommand(0, vehicle_id, cargo, CMD_REFIT_ROAD_VEH); |
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
59 |
case VEH_TRAIN: return AIObject::DoCommand(0, vehicle_id, cargo, CMD_REFIT_RAIL_VEHICLE); |
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
60 |
case VEH_SHIP: return AIObject::DoCommand(0, vehicle_id, cargo, CMD_REFIT_SHIP); |
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
61 |
case VEH_AIRCRAFT: return AIObject::DoCommand(0, vehicle_id, cargo, CMD_REFIT_AIRCRAFT); |
9654
b836eb5c521f
(svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
9637
diff
changeset
|
62 |
default: return false; |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
63 |
} |
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
64 |
} |
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
65 |
|
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
66 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
67 |
/* static */ bool AIVehicle::SellVehicle(VehicleID vehicle_id) |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
68 |
{ |
10087
0cb23b9abbf7
(svn r12611) [NoAI] -Codechange: use EnforcePrecondition where possible in AIVehicle. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
69 |
EnforcePrecondition(false, IsValidVehicle(vehicle_id)); |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
70 |
|
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
71 |
switch (::GetVehicle(vehicle_id)->type) { |
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
72 |
case VEH_ROAD: return AIObject::DoCommand(0, vehicle_id, 0, CMD_SELL_ROAD_VEH); |
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
73 |
case VEH_TRAIN: return AIObject::DoCommand(0, vehicle_id, 0, CMD_SELL_RAIL_WAGON); |
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
74 |
case VEH_SHIP: return AIObject::DoCommand(0, vehicle_id, 0, CMD_SELL_SHIP); |
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
75 |
case VEH_AIRCRAFT: return AIObject::DoCommand(0, vehicle_id, 0, CMD_SELL_AIRCRAFT); |
9654
b836eb5c521f
(svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
9637
diff
changeset
|
76 |
default: return false; |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
77 |
} |
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
78 |
} |
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
79 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
80 |
/* static */ bool AIVehicle::SendVehicleToDepot(VehicleID vehicle_id) |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
81 |
{ |
10087
0cb23b9abbf7
(svn r12611) [NoAI] -Codechange: use EnforcePrecondition where possible in AIVehicle. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
82 |
EnforcePrecondition(false, IsValidVehicle(vehicle_id)); |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
83 |
|
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
84 |
switch (::GetVehicle(vehicle_id)->type) { |
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
85 |
case VEH_ROAD: return AIObject::DoCommand(0, vehicle_id, 0, CMD_SEND_ROADVEH_TO_DEPOT); |
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
86 |
case VEH_TRAIN: return AIObject::DoCommand(0, vehicle_id, 0, CMD_SEND_TRAIN_TO_DEPOT); |
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
87 |
case VEH_SHIP: return AIObject::DoCommand(0, vehicle_id, 0, CMD_SEND_SHIP_TO_DEPOT); |
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
88 |
case VEH_AIRCRAFT: return AIObject::DoCommand(0, vehicle_id, 0, CMD_SEND_AIRCRAFT_TO_HANGAR); |
9654
b836eb5c521f
(svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
9637
diff
changeset
|
89 |
default: return false; |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
90 |
} |
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
91 |
} |
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
92 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
93 |
/* static */ bool AIVehicle::IsInDepot(VehicleID vehicle_id) |
9709
196a08fbfeb6
(svn r11289) [NoAI] -Add [FS#1346]: added AIVehicle::Is(Stopped)InDepot() (dihedral)
truelight
parents:
9706
diff
changeset
|
94 |
{ |
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9733
diff
changeset
|
95 |
if (!IsValidVehicle(vehicle_id)) return false; |
9709
196a08fbfeb6
(svn r11289) [NoAI] -Add [FS#1346]: added AIVehicle::Is(Stopped)InDepot() (dihedral)
truelight
parents:
9706
diff
changeset
|
96 |
return ::GetVehicle(vehicle_id)->IsInDepot(); |
196a08fbfeb6
(svn r11289) [NoAI] -Add [FS#1346]: added AIVehicle::Is(Stopped)InDepot() (dihedral)
truelight
parents:
9706
diff
changeset
|
97 |
} |
196a08fbfeb6
(svn r11289) [NoAI] -Add [FS#1346]: added AIVehicle::Is(Stopped)InDepot() (dihedral)
truelight
parents:
9706
diff
changeset
|
98 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
99 |
/* static */ bool AIVehicle::IsStoppedInDepot(VehicleID vehicle_id) |
9709
196a08fbfeb6
(svn r11289) [NoAI] -Add [FS#1346]: added AIVehicle::Is(Stopped)InDepot() (dihedral)
truelight
parents:
9706
diff
changeset
|
100 |
{ |
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9733
diff
changeset
|
101 |
if (!IsValidVehicle(vehicle_id)) return false; |
9709
196a08fbfeb6
(svn r11289) [NoAI] -Add [FS#1346]: added AIVehicle::Is(Stopped)InDepot() (dihedral)
truelight
parents:
9706
diff
changeset
|
102 |
return ::GetVehicle(vehicle_id)->IsStoppedInDepot(); |
196a08fbfeb6
(svn r11289) [NoAI] -Add [FS#1346]: added AIVehicle::Is(Stopped)InDepot() (dihedral)
truelight
parents:
9706
diff
changeset
|
103 |
} |
196a08fbfeb6
(svn r11289) [NoAI] -Add [FS#1346]: added AIVehicle::Is(Stopped)InDepot() (dihedral)
truelight
parents:
9706
diff
changeset
|
104 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
105 |
/* static */ bool AIVehicle::StartStopVehicle(VehicleID vehicle_id) |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
106 |
{ |
10087
0cb23b9abbf7
(svn r12611) [NoAI] -Codechange: use EnforcePrecondition where possible in AIVehicle. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
107 |
EnforcePrecondition(false, IsValidVehicle(vehicle_id)); |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
108 |
|
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
109 |
switch (::GetVehicle(vehicle_id)->type) { |
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
110 |
case VEH_ROAD: return AIObject::DoCommand(0, vehicle_id, 0, CMD_START_STOP_ROADVEH); |
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
111 |
case VEH_TRAIN: return AIObject::DoCommand(0, vehicle_id, 0, CMD_START_STOP_TRAIN); |
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
112 |
case VEH_SHIP: return AIObject::DoCommand(0, vehicle_id, 0, CMD_START_STOP_SHIP); |
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
113 |
case VEH_AIRCRAFT: return AIObject::DoCommand(0, vehicle_id, 0, CMD_START_STOP_AIRCRAFT); |
9654
b836eb5c521f
(svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
9637
diff
changeset
|
114 |
default: return false; |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
115 |
} |
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
116 |
} |
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
117 |
|
11029
776c7cc8bda5
(svn r13585) [NoAI] -Add: possibility to get information/perform order changes based on the current order of a vehicle.
rubidium
parents:
11000
diff
changeset
|
118 |
/* static */ bool AIVehicle::SkipToVehicleOrder(VehicleID vehicle_id, AIOrder::OrderPosition order_position) |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
119 |
{ |
11029
776c7cc8bda5
(svn r13585) [NoAI] -Add: possibility to get information/perform order changes based on the current order of a vehicle.
rubidium
parents:
11000
diff
changeset
|
120 |
order_position = AIOrder::ResolveOrderPosition(vehicle_id, order_position); |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
121 |
|
11029
776c7cc8bda5
(svn r13585) [NoAI] -Add: possibility to get information/perform order changes based on the current order of a vehicle.
rubidium
parents:
11000
diff
changeset
|
122 |
EnforcePrecondition(false, AIOrder::IsValidVehicleOrder(vehicle_id, order_position)); |
776c7cc8bda5
(svn r13585) [NoAI] -Add: possibility to get information/perform order changes based on the current order of a vehicle.
rubidium
parents:
11000
diff
changeset
|
123 |
|
776c7cc8bda5
(svn r13585) [NoAI] -Add: possibility to get information/perform order changes based on the current order of a vehicle.
rubidium
parents:
11000
diff
changeset
|
124 |
return AIObject::DoCommand(0, vehicle_id, order_position, CMD_SKIP_TO_ORDER); |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
125 |
} |
9615
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
126 |
|
11168
3842648184cd
(svn r13726) [NoAI] -Add: AIVehicle::ReverseVehicle (Yexo)
truebrain
parents:
11057
diff
changeset
|
127 |
/* static */ bool AIVehicle::ReverseVehicle(VehicleID vehicle_id) |
3842648184cd
(svn r13726) [NoAI] -Add: AIVehicle::ReverseVehicle (Yexo)
truebrain
parents:
11057
diff
changeset
|
128 |
{ |
3842648184cd
(svn r13726) [NoAI] -Add: AIVehicle::ReverseVehicle (Yexo)
truebrain
parents:
11057
diff
changeset
|
129 |
EnforcePrecondition(false, IsValidVehicle(vehicle_id)); |
3842648184cd
(svn r13726) [NoAI] -Add: AIVehicle::ReverseVehicle (Yexo)
truebrain
parents:
11057
diff
changeset
|
130 |
EnforcePrecondition(false, GetVehicleType(vehicle_id) == VEHICLE_ROAD || GetVehicleType(vehicle_id) == VEHICLE_RAIL); |
3842648184cd
(svn r13726) [NoAI] -Add: AIVehicle::ReverseVehicle (Yexo)
truebrain
parents:
11057
diff
changeset
|
131 |
|
3842648184cd
(svn r13726) [NoAI] -Add: AIVehicle::ReverseVehicle (Yexo)
truebrain
parents:
11057
diff
changeset
|
132 |
switch (::GetVehicle(vehicle_id)->type) { |
3842648184cd
(svn r13726) [NoAI] -Add: AIVehicle::ReverseVehicle (Yexo)
truebrain
parents:
11057
diff
changeset
|
133 |
case VEH_ROAD: return AIObject::DoCommand(0, vehicle_id, 0, CMD_TURN_ROADVEH); |
3842648184cd
(svn r13726) [NoAI] -Add: AIVehicle::ReverseVehicle (Yexo)
truebrain
parents:
11057
diff
changeset
|
134 |
case VEH_TRAIN: return AIObject::DoCommand(0, vehicle_id, 0, CMD_REVERSE_TRAIN_DIRECTION); |
3842648184cd
(svn r13726) [NoAI] -Add: AIVehicle::ReverseVehicle (Yexo)
truebrain
parents:
11057
diff
changeset
|
135 |
default: NOT_REACHED(); |
3842648184cd
(svn r13726) [NoAI] -Add: AIVehicle::ReverseVehicle (Yexo)
truebrain
parents:
11057
diff
changeset
|
136 |
} |
3842648184cd
(svn r13726) [NoAI] -Add: AIVehicle::ReverseVehicle (Yexo)
truebrain
parents:
11057
diff
changeset
|
137 |
} |
3842648184cd
(svn r13726) [NoAI] -Add: AIVehicle::ReverseVehicle (Yexo)
truebrain
parents:
11057
diff
changeset
|
138 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
139 |
/* static */ bool AIVehicle::SetName(VehicleID vehicle_id, const char *name) |
9699
e1b5f29cc6f9
(svn r10940) [NoAI] -Add: added AIVehicle::GetName and AIVehicle::SetName to set vehicle names
truelight
parents:
9691
diff
changeset
|
140 |
{ |
10087
0cb23b9abbf7
(svn r12611) [NoAI] -Codechange: use EnforcePrecondition where possible in AIVehicle. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
141 |
EnforcePrecondition(false, IsValidVehicle(vehicle_id)); |
0cb23b9abbf7
(svn r12611) [NoAI] -Codechange: use EnforcePrecondition where possible in AIVehicle. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
142 |
EnforcePrecondition(false, !StrEmpty(name)); |
9699
e1b5f29cc6f9
(svn r10940) [NoAI] -Add: added AIVehicle::GetName and AIVehicle::SetName to set vehicle names
truelight
parents:
9691
diff
changeset
|
143 |
|
e1b5f29cc6f9
(svn r10940) [NoAI] -Add: added AIVehicle::GetName and AIVehicle::SetName to set vehicle names
truelight
parents:
9691
diff
changeset
|
144 |
_cmd_text = name; |
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
145 |
return AIObject::DoCommand(0, vehicle_id, 0, CMD_NAME_VEHICLE); |
9699
e1b5f29cc6f9
(svn r10940) [NoAI] -Add: added AIVehicle::GetName and AIVehicle::SetName to set vehicle names
truelight
parents:
9691
diff
changeset
|
146 |
} |
e1b5f29cc6f9
(svn r10940) [NoAI] -Add: added AIVehicle::GetName and AIVehicle::SetName to set vehicle names
truelight
parents:
9691
diff
changeset
|
147 |
|
9637
9f78a12a4f53
(svn r10528) [NoAI] -Codechange: mark in comment static members as such in .cpp files
truelight
parents:
9626
diff
changeset
|
148 |
/* static */ TileIndex AIVehicle::GetLocation(VehicleID vehicle_id) |
9615
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
149 |
{ |
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9733
diff
changeset
|
150 |
if (!IsValidVehicle(vehicle_id)) return INVALID_TILE; |
9615
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
151 |
|
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
152 |
return ::GetVehicle(vehicle_id)->tile; |
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
153 |
} |
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
154 |
|
9637
9f78a12a4f53
(svn r10528) [NoAI] -Codechange: mark in comment static members as such in .cpp files
truelight
parents:
9626
diff
changeset
|
155 |
/* static */ EngineID AIVehicle::GetEngineType(VehicleID vehicle_id) |
9615
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
156 |
{ |
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9733
diff
changeset
|
157 |
if (!IsValidVehicle(vehicle_id)) return INVALID_ENGINE; |
9615
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
158 |
|
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
159 |
return ::GetVehicle(vehicle_id)->engine_type; |
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
160 |
} |
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
161 |
|
9637
9f78a12a4f53
(svn r10528) [NoAI] -Codechange: mark in comment static members as such in .cpp files
truelight
parents:
9626
diff
changeset
|
162 |
/* static */ int32 AIVehicle::GetUnitNumber(VehicleID vehicle_id) |
9615
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
163 |
{ |
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9733
diff
changeset
|
164 |
if (!IsValidVehicle(vehicle_id)) return -1; |
9615
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
165 |
|
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
166 |
return ::GetVehicle(vehicle_id)->unitnumber; |
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
167 |
} |
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
168 |
|
9699
e1b5f29cc6f9
(svn r10940) [NoAI] -Add: added AIVehicle::GetName and AIVehicle::SetName to set vehicle names
truelight
parents:
9691
diff
changeset
|
169 |
/* static */ char *AIVehicle::GetName(VehicleID vehicle_id) |
e1b5f29cc6f9
(svn r10940) [NoAI] -Add: added AIVehicle::GetName and AIVehicle::SetName to set vehicle names
truelight
parents:
9691
diff
changeset
|
170 |
{ |
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9733
diff
changeset
|
171 |
if (!IsValidVehicle(vehicle_id)) return NULL; |
9699
e1b5f29cc6f9
(svn r10940) [NoAI] -Add: added AIVehicle::GetName and AIVehicle::SetName to set vehicle names
truelight
parents:
9691
diff
changeset
|
172 |
|
e1b5f29cc6f9
(svn r10940) [NoAI] -Add: added AIVehicle::GetName and AIVehicle::SetName to set vehicle names
truelight
parents:
9691
diff
changeset
|
173 |
static const int len = 64; |
e1b5f29cc6f9
(svn r10940) [NoAI] -Add: added AIVehicle::GetName and AIVehicle::SetName to set vehicle names
truelight
parents:
9691
diff
changeset
|
174 |
char *vehicle_name = MallocT<char>(len); |
e1b5f29cc6f9
(svn r10940) [NoAI] -Add: added AIVehicle::GetName and AIVehicle::SetName to set vehicle names
truelight
parents:
9691
diff
changeset
|
175 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
176 |
::SetDParam(0, vehicle_id); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
177 |
::GetString(vehicle_name, STR_VEHICLE_NAME, &vehicle_name[len - 1]); |
9699
e1b5f29cc6f9
(svn r10940) [NoAI] -Add: added AIVehicle::GetName and AIVehicle::SetName to set vehicle names
truelight
parents:
9691
diff
changeset
|
178 |
return vehicle_name; |
e1b5f29cc6f9
(svn r10940) [NoAI] -Add: added AIVehicle::GetName and AIVehicle::SetName to set vehicle names
truelight
parents:
9691
diff
changeset
|
179 |
} |
e1b5f29cc6f9
(svn r10940) [NoAI] -Add: added AIVehicle::GetName and AIVehicle::SetName to set vehicle names
truelight
parents:
9691
diff
changeset
|
180 |
|
9637
9f78a12a4f53
(svn r10528) [NoAI] -Codechange: mark in comment static members as such in .cpp files
truelight
parents:
9626
diff
changeset
|
181 |
/* static */ int32 AIVehicle::GetAge(VehicleID vehicle_id) |
9615
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
182 |
{ |
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9733
diff
changeset
|
183 |
if (!IsValidVehicle(vehicle_id)) return -1; |
9615
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
184 |
|
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
185 |
return ::GetVehicle(vehicle_id)->age; |
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
186 |
} |
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
187 |
|
9637
9f78a12a4f53
(svn r10528) [NoAI] -Codechange: mark in comment static members as such in .cpp files
truelight
parents:
9626
diff
changeset
|
188 |
/* static */ int32 AIVehicle::GetMaxAge(VehicleID vehicle_id) |
9615
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
189 |
{ |
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9733
diff
changeset
|
190 |
if (!IsValidVehicle(vehicle_id)) return -1; |
9615
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
191 |
|
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
192 |
return ::GetVehicle(vehicle_id)->max_age; |
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
193 |
} |
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
194 |
|
10187
d5a6eba5af45
(svn r12718) [NoAI] -Add: added AIVehicle::GetCurrentSpeed
truebrain
parents:
10087
diff
changeset
|
195 |
/* static */ int32 AIVehicle::GetAgeLeft(VehicleID vehicle_id) |
d5a6eba5af45
(svn r12718) [NoAI] -Add: added AIVehicle::GetCurrentSpeed
truebrain
parents:
10087
diff
changeset
|
196 |
{ |
d5a6eba5af45
(svn r12718) [NoAI] -Add: added AIVehicle::GetCurrentSpeed
truebrain
parents:
10087
diff
changeset
|
197 |
if (!IsValidVehicle(vehicle_id)) return -1; |
d5a6eba5af45
(svn r12718) [NoAI] -Add: added AIVehicle::GetCurrentSpeed
truebrain
parents:
10087
diff
changeset
|
198 |
|
d5a6eba5af45
(svn r12718) [NoAI] -Add: added AIVehicle::GetCurrentSpeed
truebrain
parents:
10087
diff
changeset
|
199 |
return ::GetVehicle(vehicle_id)->max_age - ::GetVehicle(vehicle_id)->age; |
d5a6eba5af45
(svn r12718) [NoAI] -Add: added AIVehicle::GetCurrentSpeed
truebrain
parents:
10087
diff
changeset
|
200 |
} |
d5a6eba5af45
(svn r12718) [NoAI] -Add: added AIVehicle::GetCurrentSpeed
truebrain
parents:
10087
diff
changeset
|
201 |
|
d5a6eba5af45
(svn r12718) [NoAI] -Add: added AIVehicle::GetCurrentSpeed
truebrain
parents:
10087
diff
changeset
|
202 |
/* static */ int32 AIVehicle::GetCurrentSpeed(VehicleID vehicle_id) |
d5a6eba5af45
(svn r12718) [NoAI] -Add: added AIVehicle::GetCurrentSpeed
truebrain
parents:
10087
diff
changeset
|
203 |
{ |
d5a6eba5af45
(svn r12718) [NoAI] -Add: added AIVehicle::GetCurrentSpeed
truebrain
parents:
10087
diff
changeset
|
204 |
if (!IsValidVehicle(vehicle_id)) return -1; |
d5a6eba5af45
(svn r12718) [NoAI] -Add: added AIVehicle::GetCurrentSpeed
truebrain
parents:
10087
diff
changeset
|
205 |
|
d5a6eba5af45
(svn r12718) [NoAI] -Add: added AIVehicle::GetCurrentSpeed
truebrain
parents:
10087
diff
changeset
|
206 |
return ::GetVehicle(vehicle_id)->GetDisplaySpeed(); |
d5a6eba5af45
(svn r12718) [NoAI] -Add: added AIVehicle::GetCurrentSpeed
truebrain
parents:
10087
diff
changeset
|
207 |
} |
d5a6eba5af45
(svn r12718) [NoAI] -Add: added AIVehicle::GetCurrentSpeed
truebrain
parents:
10087
diff
changeset
|
208 |
|
10999
f238f608f45c
(svn r13553) [NoAI] -Add: function to determine the state of a vehicle (running, manually stopped, broken down, crashed etc.).
rubidium
parents:
10668
diff
changeset
|
209 |
/* static */ AIVehicle::VehicleState AIVehicle::GetState(VehicleID vehicle_id) |
f238f608f45c
(svn r13553) [NoAI] -Add: function to determine the state of a vehicle (running, manually stopped, broken down, crashed etc.).
rubidium
parents:
10668
diff
changeset
|
210 |
{ |
f238f608f45c
(svn r13553) [NoAI] -Add: function to determine the state of a vehicle (running, manually stopped, broken down, crashed etc.).
rubidium
parents:
10668
diff
changeset
|
211 |
if (!IsValidVehicle(vehicle_id)) return AIVehicle::VS_INVALID; |
f238f608f45c
(svn r13553) [NoAI] -Add: function to determine the state of a vehicle (running, manually stopped, broken down, crashed etc.).
rubidium
parents:
10668
diff
changeset
|
212 |
|
f238f608f45c
(svn r13553) [NoAI] -Add: function to determine the state of a vehicle (running, manually stopped, broken down, crashed etc.).
rubidium
parents:
10668
diff
changeset
|
213 |
const Vehicle *v = ::GetVehicle(vehicle_id); |
f238f608f45c
(svn r13553) [NoAI] -Add: function to determine the state of a vehicle (running, manually stopped, broken down, crashed etc.).
rubidium
parents:
10668
diff
changeset
|
214 |
byte vehstatus = v->vehstatus; |
f238f608f45c
(svn r13553) [NoAI] -Add: function to determine the state of a vehicle (running, manually stopped, broken down, crashed etc.).
rubidium
parents:
10668
diff
changeset
|
215 |
|
f238f608f45c
(svn r13553) [NoAI] -Add: function to determine the state of a vehicle (running, manually stopped, broken down, crashed etc.).
rubidium
parents:
10668
diff
changeset
|
216 |
if (vehstatus & ::VS_CRASHED) return AIVehicle::VS_CRASHED; |
11000
51305152af09
(svn r13554) [NoAI] -Fix (r13553): do compile the right directory before commiting... otherwise you'll end up with committing compile errors :(
rubidium
parents:
10999
diff
changeset
|
217 |
if (v->breakdown_ctr != 0) return AIVehicle::VS_BROKEN; |
10999
f238f608f45c
(svn r13553) [NoAI] -Add: function to determine the state of a vehicle (running, manually stopped, broken down, crashed etc.).
rubidium
parents:
10668
diff
changeset
|
218 |
if (v->IsStoppedInDepot()) return AIVehicle::VS_IN_DEPOT; |
f238f608f45c
(svn r13553) [NoAI] -Add: function to determine the state of a vehicle (running, manually stopped, broken down, crashed etc.).
rubidium
parents:
10668
diff
changeset
|
219 |
if (vehstatus & ::VS_STOPPED) return AIVehicle::VS_STOPPED; |
f238f608f45c
(svn r13553) [NoAI] -Add: function to determine the state of a vehicle (running, manually stopped, broken down, crashed etc.).
rubidium
parents:
10668
diff
changeset
|
220 |
if (v->current_order.IsType(OT_LOADING)) return AIVehicle::VS_AT_STATION; |
f238f608f45c
(svn r13553) [NoAI] -Add: function to determine the state of a vehicle (running, manually stopped, broken down, crashed etc.).
rubidium
parents:
10668
diff
changeset
|
221 |
return AIVehicle::VS_RUNNING; |
f238f608f45c
(svn r13553) [NoAI] -Add: function to determine the state of a vehicle (running, manually stopped, broken down, crashed etc.).
rubidium
parents:
10668
diff
changeset
|
222 |
} |
f238f608f45c
(svn r13553) [NoAI] -Add: function to determine the state of a vehicle (running, manually stopped, broken down, crashed etc.).
rubidium
parents:
10668
diff
changeset
|
223 |
|
9733
49e424cd4edd
(svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents:
9732
diff
changeset
|
224 |
/* static */ Money AIVehicle::GetRunningCost(VehicleID vehicle_id) |
49e424cd4edd
(svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents:
9732
diff
changeset
|
225 |
{ |
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9733
diff
changeset
|
226 |
if (!IsValidVehicle(vehicle_id)) return -1; |
9733
49e424cd4edd
(svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents:
9732
diff
changeset
|
227 |
|
49e424cd4edd
(svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents:
9732
diff
changeset
|
228 |
return ::GetVehicle(vehicle_id)->GetRunningCost() >> 8; |
49e424cd4edd
(svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents:
9732
diff
changeset
|
229 |
} |
49e424cd4edd
(svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents:
9732
diff
changeset
|
230 |
|
10196
aecabd927420
(svn r12728) [NoAI] -Codechange: always let functions return Money when they return something that can be quantified as money.
rubidium
parents:
10189
diff
changeset
|
231 |
/* static */ Money AIVehicle::GetProfitThisYear(VehicleID vehicle_id) |
9615
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
232 |
{ |
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9733
diff
changeset
|
233 |
if (!IsValidVehicle(vehicle_id)) return -1; |
9615
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
234 |
|
9732 | 235 |
return ::GetVehicle(vehicle_id)->GetDisplayProfitThisYear(); |
9615
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
236 |
} |
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
237 |
|
10196
aecabd927420
(svn r12728) [NoAI] -Codechange: always let functions return Money when they return something that can be quantified as money.
rubidium
parents:
10189
diff
changeset
|
238 |
/* static */ Money AIVehicle::GetProfitLastYear(VehicleID vehicle_id) |
9615
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
239 |
{ |
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9733
diff
changeset
|
240 |
if (!IsValidVehicle(vehicle_id)) return -1; |
9615
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
241 |
|
9732 | 242 |
return ::GetVehicle(vehicle_id)->GetDisplayProfitLastYear(); |
9615
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
243 |
} |
9684
623970482fb2
(svn r10633) [NoAI] -Add: added GetVehicleType and AIVehicle::VehicleType
truelight
parents:
9672
diff
changeset
|
244 |
|
623970482fb2
(svn r10633) [NoAI] -Add: added GetVehicleType and AIVehicle::VehicleType
truelight
parents:
9672
diff
changeset
|
245 |
/* static */ AIVehicle::VehicleType AIVehicle::GetVehicleType(VehicleID vehicle_id) |
623970482fb2
(svn r10633) [NoAI] -Add: added GetVehicleType and AIVehicle::VehicleType
truelight
parents:
9672
diff
changeset
|
246 |
{ |
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9733
diff
changeset
|
247 |
if (!IsValidVehicle(vehicle_id)) return VEHICLE_INVALID; |
9684
623970482fb2
(svn r10633) [NoAI] -Add: added GetVehicleType and AIVehicle::VehicleType
truelight
parents:
9672
diff
changeset
|
248 |
|
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9733
diff
changeset
|
249 |
switch (::GetVehicle(vehicle_id)->type) { |
9684
623970482fb2
(svn r10633) [NoAI] -Add: added GetVehicleType and AIVehicle::VehicleType
truelight
parents:
9672
diff
changeset
|
250 |
case VEH_ROAD: return VEHICLE_ROAD; |
623970482fb2
(svn r10633) [NoAI] -Add: added GetVehicleType and AIVehicle::VehicleType
truelight
parents:
9672
diff
changeset
|
251 |
case VEH_TRAIN: return VEHICLE_RAIL; |
623970482fb2
(svn r10633) [NoAI] -Add: added GetVehicleType and AIVehicle::VehicleType
truelight
parents:
9672
diff
changeset
|
252 |
case VEH_SHIP: return VEHICLE_WATER; |
623970482fb2
(svn r10633) [NoAI] -Add: added GetVehicleType and AIVehicle::VehicleType
truelight
parents:
9672
diff
changeset
|
253 |
case VEH_AIRCRAFT: return VEHICLE_AIR; |
623970482fb2
(svn r10633) [NoAI] -Add: added GetVehicleType and AIVehicle::VehicleType
truelight
parents:
9672
diff
changeset
|
254 |
default: return VEHICLE_INVALID; |
623970482fb2
(svn r10633) [NoAI] -Add: added GetVehicleType and AIVehicle::VehicleType
truelight
parents:
9672
diff
changeset
|
255 |
} |
623970482fb2
(svn r10633) [NoAI] -Add: added GetVehicleType and AIVehicle::VehicleType
truelight
parents:
9672
diff
changeset
|
256 |
} |
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
257 |
|
10668
495789401303
(svn r13212) [NoAI] -Add: introducing the ability to build trams. Use AIRoad.SetCurrentRoadType to switch to Trams, than all AIRoad functions will produce tram-objects.
truebrain
parents:
10389
diff
changeset
|
258 |
/* static */ AIRoad::RoadType AIVehicle::GetRoadType(VehicleID vehicle_id) |
495789401303
(svn r13212) [NoAI] -Add: introducing the ability to build trams. Use AIRoad.SetCurrentRoadType to switch to Trams, than all AIRoad functions will produce tram-objects.
truebrain
parents:
10389
diff
changeset
|
259 |
{ |
495789401303
(svn r13212) [NoAI] -Add: introducing the ability to build trams. Use AIRoad.SetCurrentRoadType to switch to Trams, than all AIRoad functions will produce tram-objects.
truebrain
parents:
10389
diff
changeset
|
260 |
if (!IsValidVehicle(vehicle_id)) return AIRoad::ROADTYPE_INVALID; |
495789401303
(svn r13212) [NoAI] -Add: introducing the ability to build trams. Use AIRoad.SetCurrentRoadType to switch to Trams, than all AIRoad functions will produce tram-objects.
truebrain
parents:
10389
diff
changeset
|
261 |
if (GetVehicleType(vehicle_id) != VEHICLE_ROAD) return AIRoad::ROADTYPE_INVALID; |
495789401303
(svn r13212) [NoAI] -Add: introducing the ability to build trams. Use AIRoad.SetCurrentRoadType to switch to Trams, than all AIRoad functions will produce tram-objects.
truebrain
parents:
10389
diff
changeset
|
262 |
|
495789401303
(svn r13212) [NoAI] -Add: introducing the ability to build trams. Use AIRoad.SetCurrentRoadType to switch to Trams, than all AIRoad functions will produce tram-objects.
truebrain
parents:
10389
diff
changeset
|
263 |
return (AIRoad::RoadType)GetVehicle(vehicle_id)->u.road.roadtype; |
495789401303
(svn r13212) [NoAI] -Add: introducing the ability to build trams. Use AIRoad.SetCurrentRoadType to switch to Trams, than all AIRoad functions will produce tram-objects.
truebrain
parents:
10389
diff
changeset
|
264 |
} |
495789401303
(svn r13212) [NoAI] -Add: introducing the ability to build trams. Use AIRoad.SetCurrentRoadType to switch to Trams, than all AIRoad functions will produce tram-objects.
truebrain
parents:
10389
diff
changeset
|
265 |
|
10189
b18d1d5b047d
(svn r12720) [NoAI] -Add: functions to get the capacity/current load of a vehicle given a cargo type.
rubidium
parents:
10187
diff
changeset
|
266 |
/* static */ int32 AIVehicle::GetCapacity(VehicleID vehicle_id, CargoID cargo) |
b18d1d5b047d
(svn r12720) [NoAI] -Add: functions to get the capacity/current load of a vehicle given a cargo type.
rubidium
parents:
10187
diff
changeset
|
267 |
{ |
b18d1d5b047d
(svn r12720) [NoAI] -Add: functions to get the capacity/current load of a vehicle given a cargo type.
rubidium
parents:
10187
diff
changeset
|
268 |
if (!IsValidVehicle(vehicle_id)) return -1; |
b18d1d5b047d
(svn r12720) [NoAI] -Add: functions to get the capacity/current load of a vehicle given a cargo type.
rubidium
parents:
10187
diff
changeset
|
269 |
if (!AICargo::IsValidCargo(cargo)) return -1; |
b18d1d5b047d
(svn r12720) [NoAI] -Add: functions to get the capacity/current load of a vehicle given a cargo type.
rubidium
parents:
10187
diff
changeset
|
270 |
|
b18d1d5b047d
(svn r12720) [NoAI] -Add: functions to get the capacity/current load of a vehicle given a cargo type.
rubidium
parents:
10187
diff
changeset
|
271 |
uint32 amount = 0; |
b18d1d5b047d
(svn r12720) [NoAI] -Add: functions to get the capacity/current load of a vehicle given a cargo type.
rubidium
parents:
10187
diff
changeset
|
272 |
for (const Vehicle *v = ::GetVehicle(vehicle_id); v != NULL; v = v->Next()) { |
b18d1d5b047d
(svn r12720) [NoAI] -Add: functions to get the capacity/current load of a vehicle given a cargo type.
rubidium
parents:
10187
diff
changeset
|
273 |
if (v->cargo_type == cargo) amount += v->cargo_cap; |
b18d1d5b047d
(svn r12720) [NoAI] -Add: functions to get the capacity/current load of a vehicle given a cargo type.
rubidium
parents:
10187
diff
changeset
|
274 |
} |
b18d1d5b047d
(svn r12720) [NoAI] -Add: functions to get the capacity/current load of a vehicle given a cargo type.
rubidium
parents:
10187
diff
changeset
|
275 |
|
b18d1d5b047d
(svn r12720) [NoAI] -Add: functions to get the capacity/current load of a vehicle given a cargo type.
rubidium
parents:
10187
diff
changeset
|
276 |
return amount; |
b18d1d5b047d
(svn r12720) [NoAI] -Add: functions to get the capacity/current load of a vehicle given a cargo type.
rubidium
parents:
10187
diff
changeset
|
277 |
} |
b18d1d5b047d
(svn r12720) [NoAI] -Add: functions to get the capacity/current load of a vehicle given a cargo type.
rubidium
parents:
10187
diff
changeset
|
278 |
|
b18d1d5b047d
(svn r12720) [NoAI] -Add: functions to get the capacity/current load of a vehicle given a cargo type.
rubidium
parents:
10187
diff
changeset
|
279 |
/* static */ int32 AIVehicle::GetCargoLoad(VehicleID vehicle_id, CargoID cargo) |
b18d1d5b047d
(svn r12720) [NoAI] -Add: functions to get the capacity/current load of a vehicle given a cargo type.
rubidium
parents:
10187
diff
changeset
|
280 |
{ |
b18d1d5b047d
(svn r12720) [NoAI] -Add: functions to get the capacity/current load of a vehicle given a cargo type.
rubidium
parents:
10187
diff
changeset
|
281 |
if (!IsValidVehicle(vehicle_id)) return -1; |
b18d1d5b047d
(svn r12720) [NoAI] -Add: functions to get the capacity/current load of a vehicle given a cargo type.
rubidium
parents:
10187
diff
changeset
|
282 |
if (!AICargo::IsValidCargo(cargo)) return -1; |
b18d1d5b047d
(svn r12720) [NoAI] -Add: functions to get the capacity/current load of a vehicle given a cargo type.
rubidium
parents:
10187
diff
changeset
|
283 |
|
b18d1d5b047d
(svn r12720) [NoAI] -Add: functions to get the capacity/current load of a vehicle given a cargo type.
rubidium
parents:
10187
diff
changeset
|
284 |
uint32 amount = 0; |
b18d1d5b047d
(svn r12720) [NoAI] -Add: functions to get the capacity/current load of a vehicle given a cargo type.
rubidium
parents:
10187
diff
changeset
|
285 |
for (const Vehicle *v = ::GetVehicle(vehicle_id); v != NULL; v = v->Next()) { |
b18d1d5b047d
(svn r12720) [NoAI] -Add: functions to get the capacity/current load of a vehicle given a cargo type.
rubidium
parents:
10187
diff
changeset
|
286 |
if (v->cargo_type == cargo) amount += v->cargo.Count(); |
b18d1d5b047d
(svn r12720) [NoAI] -Add: functions to get the capacity/current load of a vehicle given a cargo type.
rubidium
parents:
10187
diff
changeset
|
287 |
} |
b18d1d5b047d
(svn r12720) [NoAI] -Add: functions to get the capacity/current load of a vehicle given a cargo type.
rubidium
parents:
10187
diff
changeset
|
288 |
|
b18d1d5b047d
(svn r12720) [NoAI] -Add: functions to get the capacity/current load of a vehicle given a cargo type.
rubidium
parents:
10187
diff
changeset
|
289 |
return amount; |
b18d1d5b047d
(svn r12720) [NoAI] -Add: functions to get the capacity/current load of a vehicle given a cargo type.
rubidium
parents:
10187
diff
changeset
|
290 |
} |
11057
188a9ca6d8de
(svn r13614) [NoAI] -Add: AIGroup which allows an AI to manage its vehicle in the context of groups.
rubidium
parents:
11029
diff
changeset
|
291 |
|
188a9ca6d8de
(svn r13614) [NoAI] -Add: AIGroup which allows an AI to manage its vehicle in the context of groups.
rubidium
parents:
11029
diff
changeset
|
292 |
/* static */ GroupID AIVehicle::GetGroupID(VehicleID vehicle_id) |
188a9ca6d8de
(svn r13614) [NoAI] -Add: AIGroup which allows an AI to manage its vehicle in the context of groups.
rubidium
parents:
11029
diff
changeset
|
293 |
{ |
188a9ca6d8de
(svn r13614) [NoAI] -Add: AIGroup which allows an AI to manage its vehicle in the context of groups.
rubidium
parents:
11029
diff
changeset
|
294 |
if (!IsValidVehicle(vehicle_id)) return ::INVALID_GROUP; |
188a9ca6d8de
(svn r13614) [NoAI] -Add: AIGroup which allows an AI to manage its vehicle in the context of groups.
rubidium
parents:
11029
diff
changeset
|
295 |
|
188a9ca6d8de
(svn r13614) [NoAI] -Add: AIGroup which allows an AI to manage its vehicle in the context of groups.
rubidium
parents:
11029
diff
changeset
|
296 |
return ::GetVehicle(vehicle_id)->group_id; |
188a9ca6d8de
(svn r13614) [NoAI] -Add: AIGroup which allows an AI to manage its vehicle in the context of groups.
rubidium
parents:
11029
diff
changeset
|
297 |
} |