mirror of https://github.com/OpenTTD/OpenTTD
(svn r17898) -Fix: [NoAI] Improve behaviour of (AIEngine|AIEventEnginePreview)::GetCargoType() and AIEngine::CanRefitCargo() wrt. articulated vehicles.
parent
83894809d0
commit
d01f5e9e7e
|
@ -42,10 +42,18 @@
|
||||||
{
|
{
|
||||||
if (!IsValidEngine(engine_id)) return CT_INVALID;
|
if (!IsValidEngine(engine_id)) return CT_INVALID;
|
||||||
|
|
||||||
const Engine *e = ::Engine::Get(engine_id);
|
CargoArray cap = ::GetCapacityOfArticulatedParts(engine_id);
|
||||||
if (!e->CanCarryCargo()) return CT_INVALID;
|
|
||||||
|
|
||||||
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)
|
/* static */ bool AIEngine::CanRefitCargo(EngineID engine_id, CargoID cargo_id)
|
||||||
|
@ -53,8 +61,7 @@
|
||||||
if (!IsValidEngine(engine_id)) return false;
|
if (!IsValidEngine(engine_id)) return false;
|
||||||
if (!AICargo::IsValidCargo(cargo_id)) return false;
|
if (!AICargo::IsValidCargo(cargo_id)) return false;
|
||||||
|
|
||||||
if (GetCargoType(engine_id) == cargo_id) return true;
|
return HasBit(::GetUnionOfArticulatedRefitMasks(engine_id, true), cargo_id);
|
||||||
return ::CanRefitTo(engine_id, cargo_id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ bool AIEngine::CanPullCargo(EngineID engine_id, CargoID cargo_id)
|
/* static */ bool AIEngine::CanPullCargo(EngineID engine_id, CargoID cargo_id)
|
||||||
|
|
|
@ -41,8 +41,8 @@ public:
|
||||||
static char *GetName(EngineID engine_id);
|
static char *GetName(EngineID engine_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the cargo-type of an engine. In case it can transport 2 cargos, it
|
* Get the cargo-type of an engine. In case it can transport multiple cargos, it
|
||||||
* returns the first.
|
* returns the first/main.
|
||||||
* @param engine_id The engine to get the cargo-type of.
|
* @param engine_id The engine to get the cargo-type of.
|
||||||
* @pre IsValidEngine(engine_id).
|
* @pre IsValidEngine(engine_id).
|
||||||
* @return The cargo-type of the engine.
|
* @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
|
* 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.
|
* 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 engine_id The engine to check for refitting.
|
||||||
* @param cargo_id The cargo to check for refitting.
|
* @param cargo_id The cargo to check for refitting.
|
||||||
* @pre IsValidEngine(engine_id).
|
* @pre IsValidEngine(engine_id).
|
||||||
|
@ -75,8 +77,8 @@ public:
|
||||||
static bool CanPullCargo(EngineID engine_id, CargoID cargo_id);
|
static bool CanPullCargo(EngineID engine_id, CargoID cargo_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the capacity of an engine. In case it can transport 2 cargos, it
|
* Get the capacity of an engine. In case it can transport multiple cargos, it
|
||||||
* returns the first.
|
* returns the first/main.
|
||||||
* @param engine_id The engine to get the capacity of.
|
* @param engine_id The engine to get the capacity of.
|
||||||
* @pre IsValidEngine(engine_id).
|
* @pre IsValidEngine(engine_id).
|
||||||
* @return The capacity of the engine.
|
* @return The capacity of the engine.
|
||||||
|
|
|
@ -30,9 +30,18 @@ char *AIEventEnginePreview::GetName()
|
||||||
|
|
||||||
CargoID AIEventEnginePreview::GetCargoType()
|
CargoID AIEventEnginePreview::GetCargoType()
|
||||||
{
|
{
|
||||||
const Engine *e = ::Engine::Get(this->engine);
|
CargoArray cap = ::GetCapacityOfArticulatedParts(this->engine);
|
||||||
if (!e->CanCarryCargo()) return CT_INVALID;
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 AIEventEnginePreview::GetCapacity()
|
int32 AIEventEnginePreview::GetCapacity()
|
||||||
|
|
|
@ -238,15 +238,15 @@ public:
|
||||||
char *GetName();
|
char *GetName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the cargo-type of the offered engine. In case it can transport 2 cargos, it
|
* Get the cargo-type of the offered engine. In case it can transport multiple cargos, it
|
||||||
* returns the first.
|
* returns the first/main.
|
||||||
* @return The cargo-type of the engine.
|
* @return The cargo-type of the engine.
|
||||||
*/
|
*/
|
||||||
CargoID GetCargoType();
|
CargoID GetCargoType();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the capacity of the offered engine. In case it can transport 2 cargos, it
|
* Get the capacity of the offered engine. In case it can transport multiple cargos, it
|
||||||
* returns the first.
|
* returns the first/main.
|
||||||
* @return The capacity of the engine.
|
* @return The capacity of the engine.
|
||||||
*/
|
*/
|
||||||
int32 GetCapacity();
|
int32 GetCapacity();
|
||||||
|
|
Loading…
Reference in New Issue