Skip to content

Commit

Permalink
Clean up:
Browse files Browse the repository at this point in the history
- Replace `size() == 0` by `empty()`
- Replace `v[v.size() - 1]` by `v.back()`
  • Loading branch information
Jarod42 committed Apr 30, 2024
1 parent cd1f04a commit fee78c1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/ai/ai_force.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,9 @@ bool AiForce::NewRallyPoint(const Vec2i &startPos, Vec2i *resultPos)

void AiForce::Attack(const Vec2i &pos)
{
bool isDefenceForce = false;
RemoveDeadUnit();

if (Units.size() == 0) {
if (Units.empty()) {
this->Attacking = false;
this->State = AiForceAttackingState::Waiting;
return;
Expand All @@ -424,7 +423,7 @@ void AiForce::Attack(const Vec2i &pos)
// Remember the original force position so we can return there after attack
if (this->Role == AiForceRole::Defend
|| (this->Role == AiForceRole::Attack && this->State == AiForceAttackingState::Waiting)) {
this->HomePos = this->Units[this->Units.size() - 1]->tilePos;
this->HomePos = this->Units.back()->tilePos;
}
this->Attacking = true;
}
Expand All @@ -436,6 +435,7 @@ void AiForce::Attack(const Vec2i &pos)
const bool isTransporter = ranges::any_of(this->Units, [](const CUnit *unit) {
return unit->Type->CanTransport() && unit->IsAgressive() == false;
});
bool isDefenceForce = false;
if (Map.Info.IsPointOnMap(goalPos) == false) {
/* Search in entire map */
const CUnit *enemy = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions src/unit/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ bool CBuildRestrictionHasUnit::Check(const CUnit *builder, const CUnitType &type
Vec2i pos2(0, 0);
CPlayer* player = builder != nullptr ? builder->Player : ThisPlayer;
int count = 0;
if (this->RestrictTypeOwner.size() == 0 || !this->RestrictTypeOwner.compare("self")) {
if (this->RestrictTypeOwner.empty() || !this->RestrictTypeOwner.compare("self")) {
count = player->GetUnitTotalCount(*this->RestrictType);
} else if (!this->RestrictTypeOwner.compare("allied")) {
count = player->GetUnitTotalCount(*this->RestrictType);
Expand Down Expand Up @@ -277,7 +277,7 @@ bool CBuildRestrictionSurroundedBy::Check(const CUnit *builder, const CUnitType
// unit has RestrictType or no RestrictType was set, but a RestrictTypeOwner
(this->RestrictType == unit->Type || (!this->RestrictType && this->RestrictTypeOwner.size() > 0)) &&
// RestrictTypeOwner is not set or unit belongs to a suitable player
(this->RestrictTypeOwner.size() == 0 ||
(this->RestrictTypeOwner.empty() ||
(!this->RestrictTypeOwner.compare("self") && builder->Player == unit->Player) ||
(!this->RestrictTypeOwner.compare("allied") && (builder->Player == unit->Player || builder->Player->IsAllied(*unit->Player))) ||
(!this->RestrictTypeOwner.compare("enemy") && builder->Player->IsEnemy(*unit->Player)))) {
Expand Down

0 comments on commit fee78c1

Please sign in to comment.