mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-05 22:04:57 +00:00
(svn r18687) -Add [NoAI]: AIEngine::IsBuildable to check if you can build a certain engine.
-Change: AIEngine::IsValidEngine will now also return true when you have at least one vehicle of that type even if you can't build it anymore.
This commit is contained in:
parent
ea75e7da60
commit
fe67e85700
@ -91,3 +91,162 @@ AIVehicle.SkipToVehicleOrder <- function(vehicle_id, order_position)
|
||||
{
|
||||
return AIOrder.SkipToOrder(vehicle_id, order_position);
|
||||
}
|
||||
|
||||
AIEngine.IsValidEngine <- function(engine_id)
|
||||
{
|
||||
return AIEngine.IsBuildable(engine_id);
|
||||
}
|
||||
|
||||
AIEngine._GetName <- AIEngine.GetName;
|
||||
AIEngine.GetName <- function(engine_id)
|
||||
{
|
||||
if (!AIEngine.IsBuildable(engine_id)) return null;
|
||||
return AIEngine._GetName(engine_id);
|
||||
}
|
||||
|
||||
AIEngine._GetCargoType <- AIEngine.GetCargoType;
|
||||
AIEngine.GetCargoType <- function(engine_id)
|
||||
{
|
||||
if (!AIEngine.IsBuildable(engine_id)) return 255;
|
||||
return AIEngine._GetCargoType(engine_id);
|
||||
}
|
||||
|
||||
AIEngine._CanRefitCargo <- AIEngine.CanRefitCargo;
|
||||
AIEngine.CanRefitCargo <- function(engine_id, cargo_id)
|
||||
{
|
||||
if (!AIEngine.IsBuildable(engine_id)) return false;
|
||||
return AIEngine._CanRefitCargo(engine_id, cargo_id);
|
||||
}
|
||||
|
||||
AIEngine._CanPullCargo <- AIEngine.CanPullCargo;
|
||||
AIEngine.CanPullCargo <- function(engine_id, cargo_id)
|
||||
{
|
||||
if (!AIEngine.IsBuildable(engine_id)) return false;
|
||||
return AIEngine._CanPullCargo(engine_id, cargo_id);
|
||||
}
|
||||
|
||||
AIEngine._GetCapacity <- AIEngine.GetCapacity;
|
||||
AIEngine.GetCapacity <- function(engine_id)
|
||||
{
|
||||
if (!AIEngine.IsBuildable(engine_id)) return -1;
|
||||
return AIEngine._GetCapacity(engine_id);
|
||||
}
|
||||
|
||||
AIEngine._GetReliability <- AIEngine.GetReliability;
|
||||
AIEngine.GetReliability <- function(engine_id)
|
||||
{
|
||||
if (!AIEngine.IsBuildable(engine_id)) return -1;
|
||||
return AIEngine._GetReliability(engine_id);
|
||||
}
|
||||
|
||||
AIEngine._GetMaxSpeed <- AIEngine.GetMaxSpeed;
|
||||
AIEngine.GetMaxSpeed <- function(engine_id)
|
||||
{
|
||||
if (!AIEngine.IsBuildable(engine_id)) return -1;
|
||||
return AIEngine._GetMaxSpeed(engine_id);
|
||||
}
|
||||
|
||||
AIEngine._GetPrice <- AIEngine.GetPrice;
|
||||
AIEngine.GetPrice <- function(engine_id)
|
||||
{
|
||||
if (!AIEngine.IsBuildable(engine_id)) return -1;
|
||||
return AIEngine._GetPrice(engine_id);
|
||||
}
|
||||
|
||||
AIEngine._GetMaxAge <- AIEngine.GetMaxAge;
|
||||
AIEngine.GetMaxAge <- function(engine_id)
|
||||
{
|
||||
if (!AIEngine.IsBuildable(engine_id)) return -1;
|
||||
return AIEngine._GetMaxAge(engine_id);
|
||||
}
|
||||
|
||||
AIEngine._GetRunningCost <- AIEngine.GetRunningCost;
|
||||
AIEngine.GetRunningCost <- function(engine_id)
|
||||
{
|
||||
if (!AIEngine.IsBuildable(engine_id)) return -1;
|
||||
return AIEngine._GetRunningCost(engine_id);
|
||||
}
|
||||
|
||||
AIEngine._GetPower <- AIEngine.GetPower;
|
||||
AIEngine.GetPower <- function(engine_id)
|
||||
{
|
||||
if (!AIEngine.IsBuildable(engine_id)) return -1;
|
||||
return AIEngine._GetPower(engine_id);
|
||||
}
|
||||
|
||||
AIEngine._GetWeight <- AIEngine.GetWeight;
|
||||
AIEngine.GetWeight <- function(engine_id)
|
||||
{
|
||||
if (!AIEngine.IsBuildable(engine_id)) return -1;
|
||||
return AIEngine._GetWeight(engine_id);
|
||||
}
|
||||
|
||||
AIEngine._GetMaxTractiveEffort <- AIEngine.GetMaxTractiveEffort;
|
||||
AIEngine.GetMaxTractiveEffort <- function(engine_id)
|
||||
{
|
||||
if (!AIEngine.IsBuildable(engine_id)) return -1;
|
||||
return AIEngine._GetMaxTractiveEffort(engine_id);
|
||||
}
|
||||
|
||||
AIEngine._GetDesignDate <- AIEngine.GetDesignDate;
|
||||
AIEngine.GetDesignDate <- function(engine_id)
|
||||
{
|
||||
if (!AIEngine.IsBuildable(engine_id)) return -1;
|
||||
return AIEngine._GetDesignDate(engine_id);
|
||||
}
|
||||
|
||||
AIEngine._GetVehicleType <- AIEngine.GetVehicleType;
|
||||
AIEngine.GetVehicleType <- function(engine_id)
|
||||
{
|
||||
if (!AIEngine.IsBuildable(engine_id)) return AIVehicle.VT_INVALID;
|
||||
return AIEngine._GetVehicleType(engine_id);
|
||||
}
|
||||
|
||||
AIEngine._IsWagon <- AIEngine.IsWagon;
|
||||
AIEngine.IsWagon <- function(engine_id)
|
||||
{
|
||||
if (!AIEngine.IsBuildable(engine_id)) return false;
|
||||
return AIEngine._IsWagon(engine_id);
|
||||
}
|
||||
|
||||
AIEngine._CanRunOnRail <- AIEngine.CanRunOnRail;
|
||||
AIEngine.CanRunOnRail <- function(engine_id, track_rail_type)
|
||||
{
|
||||
if (!AIEngine.IsBuildable(engine_id)) return false;
|
||||
return AIEngine._CanRunOnRail(engine_id, track_rail_type);
|
||||
}
|
||||
|
||||
AIEngine._HasPowerOnRail <- AIEngine.HasPowerOnRail;
|
||||
AIEngine.HasPowerOnRail <- function(engine_id, track_rail_type)
|
||||
{
|
||||
if (!AIEngine.IsBuildable(engine_id)) return false;
|
||||
return AIEngine._HasPowerOnRail(engine_id, track_rail_type);
|
||||
}
|
||||
|
||||
AIEngine._GetRoadType <- AIEngine.GetRoadType;
|
||||
AIEngine.GetRoadType <- function(engine_id)
|
||||
{
|
||||
if (!AIEngine.IsBuildable(engine_id)) return AIRoad.ROADTYPE_INVALID;
|
||||
return AIEngine._GetRoadType(engine_id);
|
||||
}
|
||||
|
||||
AIEngine._GetRailType <- AIEngine.GetRailType;
|
||||
AIEngine.GetRailType <- function(engine_id)
|
||||
{
|
||||
if (!AIEngine.IsBuildable(engine_id)) return AIRail.RAILTYPE_INVALID;
|
||||
return AIEngine._GetRailType(engine_id);
|
||||
}
|
||||
|
||||
AIEngine._IsArticulated <- AIEngine.IsArticulated;
|
||||
AIEngine.IsArticulated <- function(engine_id)
|
||||
{
|
||||
if (!AIEngine.IsBuildable(engine_id)) return false;
|
||||
return AIEngine._IsArticulated(engine_id);
|
||||
}
|
||||
|
||||
AIEngine._GetPlaneType <- AIEngine.GetPlaneType;
|
||||
AIEngine.GetPlaneType <- function(engine_id)
|
||||
{
|
||||
if (!AIEngine.IsBuildable(engine_id)) return -1;
|
||||
return AIEngine._GetPlaneType(engine_id);
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
* API additions:
|
||||
* \li AIBaseStation
|
||||
* \li AIBuoyList
|
||||
* \li AIEngine::IsBuildable
|
||||
* \li AIEventCompanyAskMerger
|
||||
* \li AIIndustry::GetLastMonthTransportedPercentage
|
||||
* \li AIOrder::AIOF_GOTO_NEAREST_DEPOT
|
||||
@ -81,6 +82,10 @@
|
||||
* For GetCargoType the first most used cargo type is returned.
|
||||
* \li AIIndustryType::GetConstructionCost() now returns -1 if the industry is
|
||||
* neither buildable nor prospectable.
|
||||
* \li AIEngine::IsValidEngine will now return true if you have at least one
|
||||
* vehicle of that type in your company, regardless if it's still buildable
|
||||
* or not. AIEngine::IsBuildable returns only true when you can actually
|
||||
* build an engine.
|
||||
*
|
||||
* \b 0.7.5
|
||||
*
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "ai_engine.hpp"
|
||||
#include "ai_cargo.hpp"
|
||||
#include "../../company_func.h"
|
||||
#include "../../company_base.h"
|
||||
#include "../../strings_func.h"
|
||||
#include "../../settings_type.h"
|
||||
#include "../../rail.h"
|
||||
@ -20,6 +21,13 @@
|
||||
#include "table/strings.h"
|
||||
|
||||
/* static */ bool AIEngine::IsValidEngine(EngineID engine_id)
|
||||
{
|
||||
const Engine *e = ::Engine::GetIfValid(engine_id);
|
||||
return e != NULL && (HasBit(e->company_avail, _current_company) || ::Company::Get(_current_company)->num_engines[engine_id] > 0);
|
||||
|
||||
}
|
||||
|
||||
/* static */ bool AIEngine::IsBuildable(EngineID engine_id)
|
||||
{
|
||||
const Engine *e = ::Engine::GetIfValid(engine_id);
|
||||
return e != NULL && HasBit(e->company_avail, _current_company);
|
||||
|
@ -26,12 +26,20 @@ public:
|
||||
static const char *GetClassName() { return "AIEngine"; }
|
||||
|
||||
/**
|
||||
* Checks whether the given engine type is valid and buildable by you.
|
||||
* Checks whether the given engine type is valid. An engine is valid if you
|
||||
* have at least one vehicle of this engine or it's currently buildable.
|
||||
* @param engine_id The engine to check.
|
||||
* @return True if and only if the engine type is valid.
|
||||
*/
|
||||
static bool IsValidEngine(EngineID engine_id);
|
||||
|
||||
/**
|
||||
* Checks whether the given engine type is buildable by you.
|
||||
* @param engine_id The engine to check.
|
||||
* @return True if and only if the engine type is buildable.
|
||||
*/
|
||||
static bool IsBuildable(EngineID engine_id);
|
||||
|
||||
/**
|
||||
* Get the name of an engine.
|
||||
* @param engine_id The engine to get the name of.
|
||||
|
@ -27,6 +27,7 @@ void SQAIEngine_Register(Squirrel *engine)
|
||||
SQAIEngine.AddConstructor<void (AIEngine::*)(), 1>(engine, "x");
|
||||
|
||||
SQAIEngine.DefSQStaticMethod(engine, &AIEngine::IsValidEngine, "IsValidEngine", 2, ".i");
|
||||
SQAIEngine.DefSQStaticMethod(engine, &AIEngine::IsBuildable, "IsBuildable", 2, ".i");
|
||||
SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetName, "GetName", 2, ".i");
|
||||
SQAIEngine.DefSQStaticMethod(engine, &AIEngine::GetCargoType, "GetCargoType", 2, ".i");
|
||||
SQAIEngine.DefSQStaticMethod(engine, &AIEngine::CanRefitCargo, "CanRefitCargo", 3, ".ii");
|
||||
|
@ -114,7 +114,7 @@
|
||||
/* static */ bool AIGroup::SetAutoReplace(GroupID group_id, EngineID engine_id_old, EngineID engine_id_new)
|
||||
{
|
||||
EnforcePrecondition(false, IsValidGroup(group_id) || group_id == GROUP_ALL);
|
||||
EnforcePrecondition(false, AIEngine::IsValidEngine(engine_id_new));
|
||||
EnforcePrecondition(false, AIEngine::IsBuildable(engine_id_new));
|
||||
|
||||
return AIObject::DoCommand(0, group_id << 16, (engine_id_new << 16) | engine_id_old, CMD_SET_AUTOREPLACE);
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ public:
|
||||
* @param engine_id_old The engine id to start replacing.
|
||||
* @param engine_id_new The engine id to replace with.
|
||||
* @pre IsValidGroup(group_id) || group_id == GROUP_ALL.
|
||||
* @pre AIEngine.IsValidEngine(engine_id_new).
|
||||
* @pre AIEngine.IsBuildable(engine_id_new).
|
||||
* @note To stop autoreplacing engine_id_old, call StopAutoReplace(group_id, engine_id_old).
|
||||
*/
|
||||
static bool SetAutoReplace(GroupID group_id, EngineID engine_id_old, EngineID engine_id_new);
|
||||
|
@ -64,7 +64,7 @@
|
||||
|
||||
/* static */ VehicleID AIVehicle::BuildVehicle(TileIndex depot, EngineID engine_id)
|
||||
{
|
||||
EnforcePrecondition(INVALID_VEHICLE, AIEngine::IsValidEngine(engine_id));
|
||||
EnforcePrecondition(INVALID_VEHICLE, AIEngine::IsBuildable(engine_id));
|
||||
|
||||
::VehicleType type = ::Engine::Get(engine_id)->type;
|
||||
|
||||
|
@ -300,7 +300,7 @@ public:
|
||||
* @param engine_id The engine to use for this vehicle.
|
||||
* @pre The tile at depot has a depot that can build the engine and
|
||||
* is owned by you.
|
||||
* @pre IsValidEngine(engine_id).
|
||||
* @pre AIEngine::IsBuildable(engine_id).
|
||||
* @exception AIVehicle::ERR_VEHICLE_TOO_MANY
|
||||
* @exception AIVehicle::ERR_VEHICLE_BUILD_DISABLED
|
||||
* @exception AIVehicle::ERR_VEHICLE_WRONG_DEPOT
|
||||
|
Loading…
Reference in New Issue
Block a user