author | rubidium |
Mon, 07 Apr 2008 18:29:12 +0000 | |
branch | noai |
changeset 10087 | 0cb23b9abbf7 |
parent 9837 | c9ec4f82e0d0 |
child 10187 | d5a6eba5af45 |
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" |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
9 |
#include "../../depot.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_type.h" |
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
|
16 |
#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
|
17 |
#include "table/strings.h" |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
18 |
|
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
|
19 |
/* 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
|
20 |
{ |
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
|
21 |
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
|
22 |
} |
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
23 |
|
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
|
24 |
/* 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
|
25 |
{ |
10087
0cb23b9abbf7
(svn r12611) [NoAI] -Codechange: use EnforcePrecondition where possible in AIVehicle. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
26 |
EnforcePrecondition(false, AIEngine::IsValidEngine(engine_id)); |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
27 |
|
9560
ff2dde050a4c
(svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents:
9516
diff
changeset
|
28 |
/* Reset the internal NewVehicleID in case we are in TestMode */ |
ff2dde050a4c
(svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents:
9516
diff
changeset
|
29 |
AIObject::SetNewVehicleID(0); |
ff2dde050a4c
(svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents:
9516
diff
changeset
|
30 |
|
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
31 |
bool ret; |
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
32 |
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
|
33 |
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
|
34 |
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
|
35 |
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
|
36 |
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
|
37 |
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
|
38 |
} |
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
39 |
|
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
|
40 |
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
|
41 |
} |
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
42 |
|
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
|
43 |
/* 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
|
44 |
{ |
10087
0cb23b9abbf7
(svn r12611) [NoAI] -Codechange: use EnforcePrecondition where possible in AIVehicle. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
45 |
EnforcePrecondition(false, IsValidVehicle(vehicle_id)); |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
46 |
|
9560
ff2dde050a4c
(svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents:
9516
diff
changeset
|
47 |
/* Reset the internal NewVehicleID in case we are in TestMode */ |
ff2dde050a4c
(svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents:
9516
diff
changeset
|
48 |
AIObject::SetNewVehicleID(0); |
ff2dde050a4c
(svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents:
9516
diff
changeset
|
49 |
|
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
|
50 |
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
|
51 |
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
|
52 |
} |
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
53 |
|
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
|
54 |
/* 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
|
55 |
{ |
10087
0cb23b9abbf7
(svn r12611) [NoAI] -Codechange: use EnforcePrecondition where possible in AIVehicle. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
56 |
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
|
57 |
|
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
58 |
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
|
59 |
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
|
60 |
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
|
61 |
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
|
62 |
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
|
63 |
default: return false; |
9491
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 |
|
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
67 |
|
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
|
68 |
/* 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
|
69 |
{ |
10087
0cb23b9abbf7
(svn r12611) [NoAI] -Codechange: use EnforcePrecondition where possible in AIVehicle. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
70 |
EnforcePrecondition(false, IsValidVehicle(vehicle_id)); |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
71 |
|
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
72 |
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
|
73 |
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
|
74 |
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
|
75 |
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
|
76 |
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
|
77 |
default: return false; |
9491
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 |
} |
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
80 |
|
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
|
81 |
/* 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
|
82 |
{ |
10087
0cb23b9abbf7
(svn r12611) [NoAI] -Codechange: use EnforcePrecondition where possible in AIVehicle. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
83 |
EnforcePrecondition(false, IsValidVehicle(vehicle_id)); |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
84 |
|
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
85 |
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
|
86 |
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
|
87 |
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
|
88 |
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
|
89 |
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
|
90 |
default: return false; |
9491
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 |
} |
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
93 |
|
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
|
94 |
/* 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
|
95 |
{ |
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
|
96 |
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
|
97 |
return ::GetVehicle(vehicle_id)->IsInDepot(); |
196a08fbfeb6
(svn r11289) [NoAI] -Add [FS#1346]: added AIVehicle::Is(Stopped)InDepot() (dihedral)
truelight
parents:
9706
diff
changeset
|
98 |
} |
196a08fbfeb6
(svn r11289) [NoAI] -Add [FS#1346]: added AIVehicle::Is(Stopped)InDepot() (dihedral)
truelight
parents:
9706
diff
changeset
|
99 |
|
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
|
100 |
/* 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
|
101 |
{ |
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
|
102 |
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
|
103 |
return ::GetVehicle(vehicle_id)->IsStoppedInDepot(); |
196a08fbfeb6
(svn r11289) [NoAI] -Add [FS#1346]: added AIVehicle::Is(Stopped)InDepot() (dihedral)
truelight
parents:
9706
diff
changeset
|
104 |
} |
196a08fbfeb6
(svn r11289) [NoAI] -Add [FS#1346]: added AIVehicle::Is(Stopped)InDepot() (dihedral)
truelight
parents:
9706
diff
changeset
|
105 |
|
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
|
106 |
/* 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
|
107 |
{ |
10087
0cb23b9abbf7
(svn r12611) [NoAI] -Codechange: use EnforcePrecondition where possible in AIVehicle. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
108 |
EnforcePrecondition(false, IsValidVehicle(vehicle_id)); |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
109 |
|
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
110 |
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
|
111 |
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
|
112 |
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
|
113 |
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
|
114 |
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
|
115 |
default: return false; |
9491
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 |
} |
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
118 |
|
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
|
119 |
/* static */ bool AIVehicle::SkipToVehicleOrder(VehicleID vehicle_id, uint32 order_id) |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
120 |
{ |
10087
0cb23b9abbf7
(svn r12611) [NoAI] -Codechange: use EnforcePrecondition where possible in AIVehicle. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
121 |
EnforcePrecondition(false, AIOrder::IsValidVehicleOrder(vehicle_id, order_id)); |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
122 |
|
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
|
123 |
return AIObject::DoCommand(0, vehicle_id, order_id, CMD_SKIP_TO_ORDER); |
9491
351239ad524c
(svn r9361) [NoAI] -Add: some function to find, build and sell road vehicles.
rubidium
parents:
diff
changeset
|
124 |
} |
9615
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
125 |
|
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
|
126 |
/* 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
|
127 |
{ |
10087
0cb23b9abbf7
(svn r12611) [NoAI] -Codechange: use EnforcePrecondition where possible in AIVehicle. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
128 |
EnforcePrecondition(false, IsValidVehicle(vehicle_id)); |
0cb23b9abbf7
(svn r12611) [NoAI] -Codechange: use EnforcePrecondition where possible in AIVehicle. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
129 |
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
|
130 |
|
e1b5f29cc6f9
(svn r10940) [NoAI] -Add: added AIVehicle::GetName and AIVehicle::SetName to set vehicle names
truelight
parents:
9691
diff
changeset
|
131 |
_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
|
132 |
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
|
133 |
} |
e1b5f29cc6f9
(svn r10940) [NoAI] -Add: added AIVehicle::GetName and AIVehicle::SetName to set vehicle names
truelight
parents:
9691
diff
changeset
|
134 |
|
9637
9f78a12a4f53
(svn r10528) [NoAI] -Codechange: mark in comment static members as such in .cpp files
truelight
parents:
9626
diff
changeset
|
135 |
/* 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
|
136 |
{ |
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
|
137 |
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
|
138 |
|
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
139 |
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
|
140 |
} |
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
141 |
|
9637
9f78a12a4f53
(svn r10528) [NoAI] -Codechange: mark in comment static members as such in .cpp files
truelight
parents:
9626
diff
changeset
|
142 |
/* 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
|
143 |
{ |
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
|
144 |
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
|
145 |
|
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
146 |
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
|
147 |
} |
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
148 |
|
9637
9f78a12a4f53
(svn r10528) [NoAI] -Codechange: mark in comment static members as such in .cpp files
truelight
parents:
9626
diff
changeset
|
149 |
/* 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
|
150 |
{ |
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
|
151 |
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
|
152 |
|
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
153 |
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
|
154 |
} |
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
155 |
|
9699
e1b5f29cc6f9
(svn r10940) [NoAI] -Add: added AIVehicle::GetName and AIVehicle::SetName to set vehicle names
truelight
parents:
9691
diff
changeset
|
156 |
/* 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
|
157 |
{ |
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
|
158 |
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
|
159 |
|
e1b5f29cc6f9
(svn r10940) [NoAI] -Add: added AIVehicle::GetName and AIVehicle::SetName to set vehicle names
truelight
parents:
9691
diff
changeset
|
160 |
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
|
161 |
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
|
162 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
163 |
::SetDParam(0, vehicle_id); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
164 |
::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
|
165 |
return vehicle_name; |
e1b5f29cc6f9
(svn r10940) [NoAI] -Add: added AIVehicle::GetName and AIVehicle::SetName to set vehicle names
truelight
parents:
9691
diff
changeset
|
166 |
} |
e1b5f29cc6f9
(svn r10940) [NoAI] -Add: added AIVehicle::GetName and AIVehicle::SetName to set vehicle names
truelight
parents:
9691
diff
changeset
|
167 |
|
9637
9f78a12a4f53
(svn r10528) [NoAI] -Codechange: mark in comment static members as such in .cpp files
truelight
parents:
9626
diff
changeset
|
168 |
/* 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
|
169 |
{ |
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
|
170 |
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
|
171 |
|
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
172 |
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
|
173 |
} |
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
174 |
|
9637
9f78a12a4f53
(svn r10528) [NoAI] -Codechange: mark in comment static members as such in .cpp files
truelight
parents:
9626
diff
changeset
|
175 |
/* 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
|
176 |
{ |
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
|
177 |
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
|
178 |
|
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
179 |
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
|
180 |
} |
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
181 |
|
9733
49e424cd4edd
(svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents:
9732
diff
changeset
|
182 |
/* 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
|
183 |
{ |
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
|
184 |
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
|
185 |
|
49e424cd4edd
(svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents:
9732
diff
changeset
|
186 |
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
|
187 |
} |
49e424cd4edd
(svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents:
9732
diff
changeset
|
188 |
|
9637
9f78a12a4f53
(svn r10528) [NoAI] -Codechange: mark in comment static members as such in .cpp files
truelight
parents:
9626
diff
changeset
|
189 |
/* static */ int32 AIVehicle::GetAgeLeft(VehicleID vehicle_id) |
9615
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
190 |
{ |
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
|
191 |
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
|
192 |
|
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
193 |
return ::GetVehicle(vehicle_id)->max_age - ::GetVehicle(vehicle_id)->age; |
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
194 |
} |
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
195 |
|
9637
9f78a12a4f53
(svn r10528) [NoAI] -Codechange: mark in comment static members as such in .cpp files
truelight
parents:
9626
diff
changeset
|
196 |
/* static */ int32 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
|
197 |
{ |
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
|
198 |
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
|
199 |
|
9732 | 200 |
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
|
201 |
} |
f809cdc8e360
(svn r9782) [NoAI] -Add: add information functions to AIVehicle, like the valuators of AIVehicleList
truelight
parents:
9560
diff
changeset
|
202 |
|
9637
9f78a12a4f53
(svn r10528) [NoAI] -Codechange: mark in comment static members as such in .cpp files
truelight
parents:
9626
diff
changeset
|
203 |
/* static */ int32 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
|
204 |
{ |
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
|
205 |
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
|
206 |
|
9732 | 207 |
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
|
208 |
} |
9684
623970482fb2
(svn r10633) [NoAI] -Add: added GetVehicleType and AIVehicle::VehicleType
truelight
parents:
9672
diff
changeset
|
209 |
|
623970482fb2
(svn r10633) [NoAI] -Add: added GetVehicleType and AIVehicle::VehicleType
truelight
parents:
9672
diff
changeset
|
210 |
/* static */ AIVehicle::VehicleType AIVehicle::GetVehicleType(VehicleID vehicle_id) |
623970482fb2
(svn r10633) [NoAI] -Add: added GetVehicleType and AIVehicle::VehicleType
truelight
parents:
9672
diff
changeset
|
211 |
{ |
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
|
212 |
if (!IsValidVehicle(vehicle_id)) return VEHICLE_INVALID; |
9684
623970482fb2
(svn r10633) [NoAI] -Add: added GetVehicleType and AIVehicle::VehicleType
truelight
parents:
9672
diff
changeset
|
213 |
|
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
|
214 |
switch (::GetVehicle(vehicle_id)->type) { |
9684
623970482fb2
(svn r10633) [NoAI] -Add: added GetVehicleType and AIVehicle::VehicleType
truelight
parents:
9672
diff
changeset
|
215 |
case VEH_ROAD: return VEHICLE_ROAD; |
623970482fb2
(svn r10633) [NoAI] -Add: added GetVehicleType and AIVehicle::VehicleType
truelight
parents:
9672
diff
changeset
|
216 |
case VEH_TRAIN: return VEHICLE_RAIL; |
623970482fb2
(svn r10633) [NoAI] -Add: added GetVehicleType and AIVehicle::VehicleType
truelight
parents:
9672
diff
changeset
|
217 |
case VEH_SHIP: return VEHICLE_WATER; |
623970482fb2
(svn r10633) [NoAI] -Add: added GetVehicleType and AIVehicle::VehicleType
truelight
parents:
9672
diff
changeset
|
218 |
case VEH_AIRCRAFT: return VEHICLE_AIR; |
623970482fb2
(svn r10633) [NoAI] -Add: added GetVehicleType and AIVehicle::VehicleType
truelight
parents:
9672
diff
changeset
|
219 |
default: return VEHICLE_INVALID; |
623970482fb2
(svn r10633) [NoAI] -Add: added GetVehicleType and AIVehicle::VehicleType
truelight
parents:
9672
diff
changeset
|
220 |
} |
623970482fb2
(svn r10633) [NoAI] -Add: added GetVehicleType and AIVehicle::VehicleType
truelight
parents:
9672
diff
changeset
|
221 |
} |
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
|
222 |