(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:
@@ -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
|
||||
|
Reference in New Issue
Block a user