src/ai/api/ai_engine.cpp
author rubidium
Sun, 06 Apr 2008 12:26:40 +0000
branchnoai
changeset 9867 b7d9ffe24f81
parent 9837 c9ec4f82e0d0
child 10190 6e4a90ed8830
permissions -rw-r--r--
(svn r12589) [NoAI] -Add: GetLastError support for AIBridge.
9711
c8b427215c9d (svn r11295) [NoAI] -Change [API CHANGE]: put Engine things in AIEngine, and rename functions as such. Most noticable: FindBestXXXVehicle -> FineBestXXXEngine
truelight
parents:
diff changeset
     1
/* $Id$ */
c8b427215c9d (svn r11295) [NoAI] -Change [API CHANGE]: put Engine things in AIEngine, and rename functions as such. Most noticable: FindBestXXXVehicle -> FineBestXXXEngine
truelight
parents:
diff changeset
     2
9833
89a64246458f (svn r12496) [NoAI] -Documentation: give the .cpp files a nice uniform format too
truebrain
parents: 9809
diff changeset
     3
/** @file ai_engine.cpp Implementation of AIEngine. */
9711
c8b427215c9d (svn r11295) [NoAI] -Change [API CHANGE]: put Engine things in AIEngine, and rename functions as such. Most noticable: FindBestXXXVehicle -> FineBestXXXEngine
truelight
parents:
diff changeset
     4
c8b427215c9d (svn r11295) [NoAI] -Change [API CHANGE]: put Engine things in AIEngine, and rename functions as such. Most noticable: FindBestXXXVehicle -> FineBestXXXEngine
truelight
parents:
diff changeset
     5
#include "ai_engine.hpp"
c8b427215c9d (svn r11295) [NoAI] -Change [API CHANGE]: put Engine things in AIEngine, and rename functions as such. Most noticable: FindBestXXXVehicle -> FineBestXXXEngine
truelight
parents:
diff changeset
     6
#include "ai_cargo.hpp"
9724
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
     7
#include "../../player_func.h"
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
     8
#include "../../strings_func.h"
9733
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
     9
#include "../../roadveh.h"
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
    10
#include "../../train.h"
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
    11
#include "../../ship.h"
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
    12
#include "../../aircraft.h"
9809
9b21c21052fa (svn r12325) [NoAI] -Add: added AIEngine:CanRefitCargo()
truebrain
parents: 9804
diff changeset
    13
#include "../../cargotype.h"
9b21c21052fa (svn r12325) [NoAI] -Add: added AIEngine:CanRefitCargo()
truebrain
parents: 9804
diff changeset
    14
#include "../../vehicle_func.h"
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    15
#include "../../core/alloc_func.hpp"
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    16
#include "../../economy_func.h"
9724
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
    17
#include "../../core/bitmath_func.hpp"
9804
217f77b77400 (svn r12310) [NoAI] -Fix: make MaxSpeed for Aircrafts return the value divided by plane_speed (which in regression is now set to 1/2th)
truebrain
parents: 9736
diff changeset
    18
#include "../../settings_type.h"
9724
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
    19
#include "table/strings.h"
9711
c8b427215c9d (svn r11295) [NoAI] -Change [API CHANGE]: put Engine things in AIEngine, and rename functions as such. Most noticable: FindBestXXXVehicle -> FineBestXXXEngine
truelight
parents:
diff changeset
    20
c8b427215c9d (svn r11295) [NoAI] -Change [API CHANGE]: put Engine things in AIEngine, and rename functions as such. Most noticable: FindBestXXXVehicle -> FineBestXXXEngine
truelight
parents:
diff changeset
    21
/* static */ bool AIEngine::IsValidEngine(EngineID engine_id)
c8b427215c9d (svn r11295) [NoAI] -Change [API CHANGE]: put Engine things in AIEngine, and rename functions as such. Most noticable: FindBestXXXVehicle -> FineBestXXXEngine
truelight
parents:
diff changeset
    22
{
9736
183b38e0a480 (svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents: 9734
diff changeset
    23
	return ::IsEngineIndex(engine_id) && HasBit(::GetEngine(engine_id)->player_avail, _current_player);
9711
c8b427215c9d (svn r11295) [NoAI] -Change [API CHANGE]: put Engine things in AIEngine, and rename functions as such. Most noticable: FindBestXXXVehicle -> FineBestXXXEngine
truelight
parents:
diff changeset
    24
}
c8b427215c9d (svn r11295) [NoAI] -Change [API CHANGE]: put Engine things in AIEngine, and rename functions as such. Most noticable: FindBestXXXVehicle -> FineBestXXXEngine
truelight
parents:
diff changeset
    25
9713
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    26
/* static */ char *AIEngine::GetName(EngineID engine_id)
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    27
{
9736
183b38e0a480 (svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents: 9734
diff changeset
    28
	if (!IsValidEngine(engine_id)) return NULL;
9713
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    29
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    30
	static const int len = 64;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    31
	char *engine_name = MallocT<char>(len);
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    32
9724
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
    33
	::SetDParam(0, engine_id);
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
    34
	::GetString(engine_name, STR_ENGINE_NAME, &engine_name[len - 1]);
9713
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    35
	return engine_name;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    36
}
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    37
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    38
/* static */ CargoID AIEngine::GetCargoType(EngineID engine_id)
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    39
{
9736
183b38e0a480 (svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents: 9734
diff changeset
    40
	if (!IsValidEngine(engine_id)) return 0;
9713
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    41
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    42
	switch (::GetEngine(engine_id)->type) {
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    43
		case VEH_ROAD: {
9736
183b38e0a480 (svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents: 9734
diff changeset
    44
			const RoadVehicleInfo *vi = ::RoadVehInfo(engine_id);
9713
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    45
			return vi->cargo_type;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    46
		} break;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    47
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    48
		case VEH_TRAIN: {
9736
183b38e0a480 (svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents: 9734
diff changeset
    49
			const RailVehicleInfo *vi = ::RailVehInfo(engine_id);
9713
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    50
			return vi->cargo_type;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    51
		} break;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    52
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    53
		case VEH_SHIP: {
9736
183b38e0a480 (svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents: 9734
diff changeset
    54
			const ShipVehicleInfo *vi = ::ShipVehInfo(engine_id);
9713
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    55
			return vi->cargo_type;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    56
		} break;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    57
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    58
		case VEH_AIRCRAFT: {
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    59
			return CT_PASSENGERS;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    60
		} break;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    61
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    62
		default: NOT_REACHED();
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    63
	}
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    64
}
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    65
9809
9b21c21052fa (svn r12325) [NoAI] -Add: added AIEngine:CanRefitCargo()
truebrain
parents: 9804
diff changeset
    66
/* static */ bool AIEngine::CanRefitCargo(EngineID engine_id, CargoID cargo_id)
9b21c21052fa (svn r12325) [NoAI] -Add: added AIEngine:CanRefitCargo()
truebrain
parents: 9804
diff changeset
    67
{
9b21c21052fa (svn r12325) [NoAI] -Add: added AIEngine:CanRefitCargo()
truebrain
parents: 9804
diff changeset
    68
	if (!IsValidEngine(engine_id)) return false;
9b21c21052fa (svn r12325) [NoAI] -Add: added AIEngine:CanRefitCargo()
truebrain
parents: 9804
diff changeset
    69
	if (!AICargo::IsValidCargo(cargo_id)) return false;
9b21c21052fa (svn r12325) [NoAI] -Add: added AIEngine:CanRefitCargo()
truebrain
parents: 9804
diff changeset
    70
9b21c21052fa (svn r12325) [NoAI] -Add: added AIEngine:CanRefitCargo()
truebrain
parents: 9804
diff changeset
    71
	if (GetCargoType(engine_id) == cargo_id) return true;
9b21c21052fa (svn r12325) [NoAI] -Add: added AIEngine:CanRefitCargo()
truebrain
parents: 9804
diff changeset
    72
	if (cargo_id == CT_MAIL && ::GetEngine(engine_id)->type == VEH_AIRCRAFT) return true;
9b21c21052fa (svn r12325) [NoAI] -Add: added AIEngine:CanRefitCargo()
truebrain
parents: 9804
diff changeset
    73
	return ::CanRefitTo(engine_id, cargo_id);
9b21c21052fa (svn r12325) [NoAI] -Add: added AIEngine:CanRefitCargo()
truebrain
parents: 9804
diff changeset
    74
}
9b21c21052fa (svn r12325) [NoAI] -Add: added AIEngine:CanRefitCargo()
truebrain
parents: 9804
diff changeset
    75
9713
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    76
/* static */ uint32 AIEngine::GetCapacity(EngineID engine_id)
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    77
{
9736
183b38e0a480 (svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents: 9734
diff changeset
    78
	if (!IsValidEngine(engine_id)) return 0;
9713
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    79
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    80
	switch (::GetEngine(engine_id)->type) {
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    81
		case VEH_ROAD: {
9736
183b38e0a480 (svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents: 9734
diff changeset
    82
			const RoadVehicleInfo *vi = ::RoadVehInfo(engine_id);
9713
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    83
			return vi->capacity;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    84
		} break;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    85
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    86
		case VEH_TRAIN: {
9736
183b38e0a480 (svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents: 9734
diff changeset
    87
			const RailVehicleInfo *vi = ::RailVehInfo(engine_id);
9713
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    88
			return vi->capacity;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    89
		} break;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    90
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    91
		case VEH_SHIP: {
9736
183b38e0a480 (svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents: 9734
diff changeset
    92
			const ShipVehicleInfo *vi = ::ShipVehInfo(engine_id);
9713
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    93
			return vi->capacity;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    94
		} break;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    95
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    96
		case VEH_AIRCRAFT: {
9736
183b38e0a480 (svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents: 9734
diff changeset
    97
			const AircraftVehicleInfo *vi = ::AircraftVehInfo(engine_id);
9713
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    98
			return vi->passenger_capacity;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
    99
		} break;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   100
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   101
		default: NOT_REACHED();
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   102
	}
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   103
}
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   104
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   105
/* static */ uint32 AIEngine::GetReliability(EngineID engine_id)
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   106
{
9736
183b38e0a480 (svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents: 9734
diff changeset
   107
	if (!IsValidEngine(engine_id)) return 0;
9713
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   108
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   109
	return (::GetEngine(engine_id)->reliability * 100 >> 16);
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   110
}
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   111
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   112
/* static */ uint32 AIEngine::GetMaxSpeed(EngineID engine_id)
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   113
{
9736
183b38e0a480 (svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents: 9734
diff changeset
   114
	if (!IsValidEngine(engine_id)) return 0;
9713
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   115
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   116
	switch (::GetEngine(engine_id)->type) {
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   117
		case VEH_ROAD: {
9736
183b38e0a480 (svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents: 9734
diff changeset
   118
			const RoadVehicleInfo *vi = ::RoadVehInfo(engine_id);
9734
52d385b38d63 (svn r12213) [NoAI] -Fix: internal speeds for RoadVehicles and Ships are multiplied with 2 (Morloth)
truebrain
parents: 9733
diff changeset
   119
			/* Internal speeds are km/h * 2 */
52d385b38d63 (svn r12213) [NoAI] -Fix: internal speeds for RoadVehicles and Ships are multiplied with 2 (Morloth)
truebrain
parents: 9733
diff changeset
   120
			return vi->max_speed / 2;
9713
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   121
		} break;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   122
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   123
		case VEH_TRAIN: {
9736
183b38e0a480 (svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents: 9734
diff changeset
   124
			const RailVehicleInfo *vi = ::RailVehInfo(engine_id);
9713
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   125
			return vi->max_speed;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   126
		} break;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   127
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   128
		case VEH_SHIP: {
9736
183b38e0a480 (svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents: 9734
diff changeset
   129
			const ShipVehicleInfo *vi = ::ShipVehInfo(engine_id);
9734
52d385b38d63 (svn r12213) [NoAI] -Fix: internal speeds for RoadVehicles and Ships are multiplied with 2 (Morloth)
truebrain
parents: 9733
diff changeset
   130
			/* Internal speeds are km/h * 2 */
52d385b38d63 (svn r12213) [NoAI] -Fix: internal speeds for RoadVehicles and Ships are multiplied with 2 (Morloth)
truebrain
parents: 9733
diff changeset
   131
			return vi->max_speed / 2;
9713
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   132
		} break;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   133
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   134
		case VEH_AIRCRAFT: {
9736
183b38e0a480 (svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents: 9734
diff changeset
   135
			const AircraftVehicleInfo *vi = ::AircraftVehInfo(engine_id);
9804
217f77b77400 (svn r12310) [NoAI] -Fix: make MaxSpeed for Aircrafts return the value divided by plane_speed (which in regression is now set to 1/2th)
truebrain
parents: 9736
diff changeset
   136
			return vi->max_speed / _patches.plane_speed;
9713
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   137
		} break;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   138
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   139
		default: NOT_REACHED();
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   140
	}
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   141
}
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   142
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   143
/* static */ uint32 AIEngine::GetPrice(EngineID engine_id)
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   144
{
9736
183b38e0a480 (svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents: 9734
diff changeset
   145
	if (!IsValidEngine(engine_id)) return 0;
9713
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   146
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   147
	switch (::GetEngine(engine_id)->type) {
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   148
		case VEH_ROAD: {
9736
183b38e0a480 (svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents: 9734
diff changeset
   149
			const RoadVehicleInfo *vi = ::RoadVehInfo(engine_id);
9713
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   150
			return (_price.roadveh_base >> 3) * vi->base_cost >> 5;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   151
		} break;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   152
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   153
		case VEH_TRAIN: {
9736
183b38e0a480 (svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents: 9734
diff changeset
   154
			const RailVehicleInfo *vi = ::RailVehInfo(engine_id);
9713
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   155
			return (_price.build_railvehicle >> 3) * vi->base_cost >> 5;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   156
		} break;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   157
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   158
		case VEH_SHIP: {
9736
183b38e0a480 (svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents: 9734
diff changeset
   159
			const ShipVehicleInfo *vi = ::ShipVehInfo(engine_id);
9713
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   160
			return (_price.ship_base >> 3) * vi->base_cost >> 5;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   161
		} break;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   162
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   163
		case VEH_AIRCRAFT: {
9736
183b38e0a480 (svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents: 9734
diff changeset
   164
			const AircraftVehicleInfo *vi = ::AircraftVehInfo(engine_id);
9713
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   165
			return (_price.aircraft_base >> 3) * vi->base_cost >> 5;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   166
		} break;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   167
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   168
		default: NOT_REACHED();
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   169
	}
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   170
}
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   171
9733
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   172
/* static */ uint32 AIEngine::GetMaxAge(EngineID engine_id)
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   173
{
9736
183b38e0a480 (svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents: 9734
diff changeset
   174
	if (!IsValidEngine(engine_id)) return 0;
9733
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   175
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   176
	return ::GetEngine(engine_id)->lifelength * 366;
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   177
}
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   178
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   179
/* static */ Money AIEngine::GetRunningCost(EngineID engine_id)
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   180
{
9736
183b38e0a480 (svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents: 9734
diff changeset
   181
	if (!IsValidEngine(engine_id)) return 0;
9733
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   182
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   183
	/* We need to create an instance in order to obtain GetRunningCost.
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   184
	 *  This means we temporary allocate a vehicle in the pool, but
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   185
	 *  there is no other way.. */
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   186
	Vehicle *vehicle;
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   187
	switch (::GetEngine(engine_id)->type) {
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   188
		case VEH_ROAD: {
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   189
			vehicle = new RoadVehicle();
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   190
		} break;
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   191
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   192
		case VEH_TRAIN: {
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   193
			vehicle = new Train();
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   194
		} break;
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   195
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   196
		case VEH_SHIP: {
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   197
			vehicle = new Ship();
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   198
		} break;
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   199
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   200
		case VEH_AIRCRAFT: {
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   201
			vehicle = new Aircraft();
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   202
		} break;
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   203
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   204
		default: NOT_REACHED();
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   205
	}
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   206
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   207
	vehicle->engine_type = engine_id;
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   208
	Money runningCost = vehicle->GetRunningCost();
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   209
	delete vehicle;
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   210
	return runningCost >> 8;
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   211
}
49e424cd4edd (svn r12212) [NoAI] -Add: added AIEngine::GetMaxAge, AIEngine::GetRunningCost and AIVehicle::GetRunningCost (Morloth)
truebrain
parents: 9724
diff changeset
   212
9713
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   213
/* static */ AIVehicle::VehicleType AIEngine::GetVehicleType(EngineID engine_id)
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   214
{
9736
183b38e0a480 (svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents: 9734
diff changeset
   215
	if (!IsValidEngine(engine_id)) return AIVehicle::VEHICLE_INVALID;
9713
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   216
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   217
	switch (::GetEngine(engine_id)->type) {
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   218
		case VEH_ROAD:     return AIVehicle::VEHICLE_ROAD;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   219
		case VEH_TRAIN:    return AIVehicle::VEHICLE_RAIL;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   220
		case VEH_SHIP:     return AIVehicle::VEHICLE_WATER;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   221
		case VEH_AIRCRAFT: return AIVehicle::VEHICLE_AIR;
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   222
		default: NOT_REACHED();
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   223
	}
7cd214115969 (svn r11297) [NoAI] -Add: in AIEngine, added: GetName, GetCargoType, GetCapacity, GetReliability, GetMaxSpeed, GetVehicleType, and GetPrice (on request by Kilinich)
truelight
parents: 9711
diff changeset
   224
}