From 8fbf9d05dd48d609a773ed353d43556df6f8ab0d Mon Sep 17 00:00:00 2001 From: Jarod42 Date: Thu, 26 Oct 2023 12:58:14 +0200 Subject: [PATCH] Use `std::vector` for `AiForce::CountTypes()`. --- src/ai/ai_force.cpp | 12 +++++------- src/ai/ai_local.h | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) 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();