diff --git a/src/ai/ai_force.cpp b/src/ai/ai_force.cpp index 666dc8425b..c7a9d3da71 100644 --- a/src/ai/ai_force.cpp +++ b/src/ai/ai_force.cpp @@ -290,13 +290,14 @@ std::vector AiFindAvailableUnitTypeEquiv(const CUnitType &unittype) /* =========================== FORCES ========================== */ -void AiForce::CountTypes(unsigned int *counter, const size_t len) +std::vector AiForce::CountTypes() const { - memset(counter, 0, len); + std::vector res(UnitTypeMax + 1); for (CUnit* unit : Units) { - counter[UnitTypeEquivs[unit->Type->Slot]]++; + res[UnitTypeEquivs[unit->Type->Slot]]++; } + return res; } /** @@ -309,10 +310,7 @@ void AiForce::CountTypes(unsigned int *counter, const size_t len) bool AiForce::IsBelongsTo(const CUnitType &type) { bool flag = false; - unsigned int counter[UnitTypeMax + 1]; - - // Count units in force. - CountTypes(counter, sizeof(counter)); + auto counter = CountTypes(); // Look what should be in the force. Completed = true; diff --git a/src/ai/ai_local.h b/src/ai/ai_local.h index 8514378407..b37e1d38b4 100644 --- a/src/ai/ai_local.h +++ b/src/ai/ai_local.h @@ -166,7 +166,7 @@ class AiForce void Insert(CUnit &unit); private: - void CountTypes(unsigned int *counter, const size_t len); + std::vector CountTypes() const; bool IsBelongsTo(const CUnitType &type); void Update();