mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r17898) -Fix: [NoAI] Improve behaviour of (AIEngine|AIEventEnginePreview)::GetCargoType() and AIEngine::CanRefitCargo() wrt. articulated vehicles.
This commit is contained in:
parent
83894809d0
commit
d01f5e9e7e
|
@ -42,10 +42,18 @@
|
|||
{
|
||||
if (!IsValidEngine(engine_id)) return CT_INVALID;
|
||||
|
||||
const Engine *e = ::Engine::Get(engine_id);
|
||||
if (!e->CanCarryCargo()) return CT_INVALID;
|
||||
CargoArray cap = ::GetCapacityOfArticulatedParts(engine_id);
|
||||
|
||||
return e->GetDefaultCargoType();
|
||||
CargoID most_cargo = CT_INVALID;
|
||||
uint amount = 0;
|
||||
for (CargoID cid = 0; cid < NUM_CARGO; cid++) {
|
||||
if (cap[cid] > amount) {
|
||||
amount = cap[cid];
|
||||
most_cargo = cid;
|
||||
}
|
||||
}
|
||||
|
||||
return most_cargo;
|
||||
}
|
||||
|
||||
/* static */ bool AIEngine::CanRefitCargo(EngineID engine_id, CargoID cargo_id)
|
||||
|
@ -53,8 +61,7 @@
|
|||
if (!IsValidEngine(engine_id)) return false;
|
||||
if (!AICargo::IsValidCargo(cargo_id)) return false;
|
||||
|
||||
if (GetCargoType(engine_id) == cargo_id) return true;
|
||||
return ::CanRefitTo(engine_id, cargo_id);
|
||||
return HasBit(::GetUnionOfArticulatedRefitMasks(engine_id, true), cargo_id);
|
||||
}
|
||||
|
||||
/* static */ bool AIEngine::CanPullCargo(EngineID engine_id, CargoID cargo_id)
|
||||
|
|
|
@ -41,8 +41,8 @@ public:
|
|||
static char *GetName(EngineID engine_id);
|
||||
|
||||
/**
|
||||
* Get the cargo-type of an engine. In case it can transport 2 cargos, it
|
||||
* returns the first.
|
||||
* Get the cargo-type of an engine. In case it can transport multiple cargos, it
|
||||
* returns the first/main.
|
||||
* @param engine_id The engine to get the cargo-type of.
|
||||
* @pre IsValidEngine(engine_id).
|
||||
* @return The cargo-type of the engine.
|
||||
|
@ -52,6 +52,8 @@ public:
|
|||
/**
|
||||
* Check if the cargo of an engine can be refitted to your requested. If
|
||||
* the engine already allows this cargo, the function also returns true.
|
||||
* In case of articulated vehicles the function decides whether at least one
|
||||
* part can carry the cargo.
|
||||
* @param engine_id The engine to check for refitting.
|
||||
* @param cargo_id The cargo to check for refitting.
|
||||
* @pre IsValidEngine(engine_id).
|
||||
|
@ -75,8 +77,8 @@ public:
|
|||
static bool CanPullCargo(EngineID engine_id, CargoID cargo_id);
|
||||
|
||||
/**
|
||||
* Get the capacity of an engine. In case it can transport 2 cargos, it
|
||||
* returns the first.
|
||||
* Get the capacity of an engine. In case it can transport multiple cargos, it
|
||||
* returns the first/main.
|
||||
* @param engine_id The engine to get the capacity of.
|
||||
* @pre IsValidEngine(engine_id).
|
||||
* @return The capacity of the engine.
|
||||
|
|
|
@ -30,9 +30,18 @@ char *AIEventEnginePreview::GetName()
|
|||
|
||||
CargoID AIEventEnginePreview::GetCargoType()
|
||||
{
|
||||
const Engine *e = ::Engine::Get(this->engine);
|
||||
if (!e->CanCarryCargo()) return CT_INVALID;
|
||||
return e->GetDefaultCargoType();
|
||||
CargoArray cap = ::GetCapacityOfArticulatedParts(this->engine);
|
||||
|
||||
CargoID most_cargo = CT_INVALID;
|
||||
uint amount = 0;
|
||||
for (CargoID cid = 0; cid < NUM_CARGO; cid++) {
|
||||
if (cap[cid] > amount) {
|
||||
amount = cap[cid];
|
||||
most_cargo = cid;
|
||||
}
|
||||
}
|
||||
|
||||
return most_cargo;
|
||||
}
|
||||
|
||||
int32 AIEventEnginePreview::GetCapacity()
|
||||
|
|
|
@ -238,15 +238,15 @@ public:
|
|||
char *GetName();
|
||||
|
||||
/**
|
||||
* Get the cargo-type of the offered engine. In case it can transport 2 cargos, it
|
||||
* returns the first.
|
||||
* Get the cargo-type of the offered engine. In case it can transport multiple cargos, it
|
||||
* returns the first/main.
|
||||
* @return The cargo-type of the engine.
|
||||
*/
|
||||
CargoID GetCargoType();
|
||||
|
||||
/**
|
||||
* Get the capacity of the offered engine. In case it can transport 2 cargos, it
|
||||
* returns the first.
|
||||
* Get the capacity of the offered engine. In case it can transport multiple cargos, it
|
||||
* returns the first/main.
|
||||
* @return The capacity of the engine.
|
||||
*/
|
||||
int32 GetCapacity();
|
||||
|
|
Loading…
Reference in New Issue