Skip to content

Commit

Permalink
Merge pull request #553 from Wargus/clean_up
Browse files Browse the repository at this point in the history
Use `std::vector` for `AiForce::CountTypes()`.
  • Loading branch information
Jarod42 authored Nov 10, 2023
2 parents 6da5e26 + c60306f commit 28c03b7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions src/ai/ai_force.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,14 @@ std::vector<int> AiFindAvailableUnitTypeEquiv(const CUnitType &unittype)

/* =========================== FORCES ========================== */

void AiForce::CountTypes(unsigned int *counter, const size_t len)
std::vector<std::size_t> AiForce::CountTypes() const
{
memset(counter, 0, len);
std::vector<std::size_t> res(UnitTypeMax + 1);
for (CUnit* unit : Units)
{
counter[UnitTypeEquivs[unit->Type->Slot]]++;
res[UnitTypeEquivs[unit->Type->Slot]]++;
}
return res;
}

/**
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/ai/ai_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class AiForce
void Insert(CUnit &unit);

private:
void CountTypes(unsigned int *counter, const size_t len);
std::vector<std::size_t> CountTypes() const;
bool IsBelongsTo(const CUnitType &type);

void Update();
Expand Down

0 comments on commit 28c03b7

Please sign in to comment.