summaryrefslogtreecommitdiff
path: root/src/ai
diff options
context:
space:
mode:
Diffstat (limited to 'src/ai')
-rw-r--r--src/ai/api/ai_engine.cpp17
-rw-r--r--src/ai/api/ai_engine.hpp10
-rw-r--r--src/ai/api/ai_event_types.cpp15
-rw-r--r--src/ai/api/ai_event_types.hpp8
4 files changed, 34 insertions, 16 deletions
diff --git a/src/ai/api/ai_engine.cpp b/src/ai/api/ai_engine.cpp
index 0be62af1f..00394444f 100644
--- a/src/ai/api/ai_engine.cpp
+++ b/src/ai/api/ai_engine.cpp
@@ -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);
+
+ 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 e->GetDefaultCargoType();
+ 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)
diff --git a/src/ai/api/ai_engine.hpp b/src/ai/api/ai_engine.hpp
index 5f5bed58e..3d213fd3e 100644
--- a/src/ai/api/ai_engine.hpp
+++ b/src/ai/api/ai_engine.hpp
@@ -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.
diff --git a/src/ai/api/ai_event_types.cpp b/src/ai/api/ai_event_types.cpp
index 4e214431d..d1e962c4c 100644
--- a/src/ai/api/ai_event_types.cpp
+++ b/src/ai/api/ai_event_types.cpp
@@ -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()
diff --git a/src/ai/api/ai_event_types.hpp b/src/ai/api/ai_event_types.hpp
index 774df7c44..a58fd0ebb 100644
--- a/src/ai/api/ai_event_types.hpp
+++ b/src/ai/api/ai_event_types.hpp
@@ -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();