Skip to content

Commit

Permalink
Merge pull request #461 from Wargus/enum
Browse files Browse the repository at this point in the history
Replace some `enum` by `enum class`
  • Loading branch information
Jarod42 committed Aug 11, 2023
2 parents 8e9cdaf + 5545ef9 commit 5e13ae8
Show file tree
Hide file tree
Showing 63 changed files with 380 additions and 365 deletions.
18 changes: 9 additions & 9 deletions src/action/action_attack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ void AnimateActionAttack(CUnit &unit, COrder &order)

/* virtual */ void COrder_Attack::Save(CFile &file, const CUnit &unit) const
{
Assert(Action == UnitActionAttack || Action == UnitActionAttackGround);
Assert(Action == UnitAction::Attack || Action == UnitAction::AttackGround);

if (Action == UnitActionAttack) {
if (Action == UnitAction::Attack) {
file.printf("{\"action-attack\",");
} else {
file.printf("{\"action-attack-ground\",");
Expand Down Expand Up @@ -211,14 +211,14 @@ void AnimateActionAttack(CUnit &unit, COrder &order)

/* virtual */ bool COrder_Attack::IsValid() const
{
if (Action == UnitActionAttack) {
if (Action == UnitAction::Attack) {
if (this->HasGoal()) {
return this->GetGoal()->IsAliveOnMap();
} else {
return Map.Info.IsPointOnMap(this->goalPos);
}
} else {
Assert(Action == UnitActionAttackGround);
Assert(Action == UnitAction::AttackGround);
return Map.Info.IsPointOnMap(this->goalPos);
}
}
Expand Down Expand Up @@ -302,7 +302,7 @@ void AnimateActionAttack(CUnit &unit, COrder &order)
if (goal == attacker) {
return true;
}
if (goal->CurrentAction() == UnitActionAttack) {
if (goal->CurrentAction() == UnitAction::Attack) {
const COrder_Attack &order = *static_cast<COrder_Attack *>(goal->CurrentOrder());
if (order.GetGoal() == &unit) {
//we already fight with one of attackers;
Expand All @@ -328,7 +328,7 @@ bool COrder_Attack::IsMovingToAttackPos() const
bool COrder_Attack::IsAttackGroundOrWall() const
{
/// FIXME: Check if need to add this: (goal && goal->Type && goal->Type->BoolFlag[WALL_INDEX].value)
return (this->Action == UnitActionAttackGround || Map.WallOnMap(this->goalPos) ? true : false);
return (this->Action == UnitAction::AttackGround || Map.WallOnMap(this->goalPos) ? true : false);
}

CUnit *const COrder_Attack::BestTarget(const CUnit &unit, CUnit *const target1, CUnit *const target2) const
Expand All @@ -354,7 +354,7 @@ void COrder_Attack::OfferNewTarget(const CUnit &unit, CUnit *const target)
Assert(this->IsAutoTargeting() || unit.Player->AiEnabled);

/// if attacker cant't move (stand_ground, building, in a bunker or transport)
const bool immobile = (this->Action == UnitActionStandGround || unit.Removed || !unit.CanMove()) ? true : false;
const bool immobile = (this->Action == UnitAction::StandGround || unit.Removed || !unit.CanMove()) ? true : false;
if (immobile && !InAttackRange(unit, *target)) {
return;
}
Expand Down Expand Up @@ -383,7 +383,7 @@ bool COrder_Attack::CheckIfGoalValid(CUnit &unit)
CUnit *goal = this->GetGoal();

// Wall was destroyed
if (!goal && this->State & ATTACK_TARGET && this->Action != UnitActionAttackGround && !Map.WallOnMap(this->goalPos)) {
if (!goal && this->State & ATTACK_TARGET && this->Action != UnitAction::AttackGround && !Map.WallOnMap(this->goalPos)) {
return false;
}
// Position or valid target, it is ok.
Expand Down Expand Up @@ -485,7 +485,7 @@ bool COrder_Attack::AutoSelectTarget(CUnit &unit)
}

/// if attacker cant't move (stand_ground, building, in a bunker or transport)
const bool immobile = (this->Action == UnitActionStandGround || unit.Removed || !unit.CanMove()) ? true : false;
const bool immobile = (this->Action == UnitAction::StandGround || unit.Removed || !unit.CanMove()) ? true : false;
if (immobile) {
newTarget = AttackUnitsInRange(unit); // search for enemies only in attack range
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/action/action_build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ bool COrder_Build::BuildFromOutside(CUnit &unit) const
return false;
}

if (this->BuildingUnit->CurrentAction() == UnitActionBuilt) {
if (this->BuildingUnit->CurrentAction() == UnitAction::Built) {
COrder_Built &targetOrder = *static_cast<COrder_Built *>(this->BuildingUnit->CurrentOrder());
CUnit &goal = *const_cast<COrder_Build *>(this)->BuildingUnit;

Expand All @@ -427,7 +427,7 @@ bool COrder_Build::BuildFromOutside(CUnit &unit) const
if (unit.Anim.Unbreakable) {
return false;
}
return this->BuildingUnit->CurrentAction() != UnitActionBuilt;
return this->BuildingUnit->CurrentAction() != UnitAction::Built;
}

CUnit *COrder_Build::GetBuildingUnit() const
Expand Down Expand Up @@ -486,7 +486,7 @@ CUnit *COrder_Build::GetBuildingUnit() const

/* virtual */ void COrder_Build::Cancel(CUnit &unit)
{
if (this->State == State_BuildFromOutside && this->BuildingUnit != nullptr && this->BuildingUnit->CurrentAction() == UnitActionBuilt) {
if (this->State == State_BuildFromOutside && this->BuildingUnit != nullptr && this->BuildingUnit->CurrentAction() == UnitAction::Built) {
COrder_Built &targetOrder = *static_cast<COrder_Built *>(this->BuildingUnit->CurrentOrder());
targetOrder.Cancel(*this->BuildingUnit);
}
Expand Down
2 changes: 1 addition & 1 deletion src/action/action_built.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static void CancelBuilt(COrder_Built &order, CUnit *unit)
CUnit *worker = order.GetWorkerPtr();

// Drop out unit
if (worker != nullptr && worker->CurrentAction() == UnitActionBuild && !worker->CurrentOrder()->Finished) {
if (worker != nullptr && worker->CurrentAction() == UnitAction::Build && !worker->CurrentOrder()->Finished) {
worker->ClearAction();

DropOutOnSide(*worker, LookingW, unit);
Expand Down
8 changes: 4 additions & 4 deletions src/action/action_follow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ enum {
}

if (dest.NewOrder == nullptr
|| (dest.NewOrder->Action == UnitActionResource && !unit.Type->BoolFlag[HARVESTER_INDEX].value)
|| (dest.NewOrder->Action == UnitActionAttack && !unit.Type->CanAttack)
|| (dest.NewOrder->Action == UnitActionBoard && unit.Type->UnitType != UnitTypeLand)) {
|| (dest.NewOrder->Action == UnitAction::Resource && !unit.Type->BoolFlag[HARVESTER_INDEX].value)
|| (dest.NewOrder->Action == UnitAction::Attack && !unit.Type->CanAttack)
|| (dest.NewOrder->Action == UnitAction::Board && unit.Type->UnitType != UnitTypeLand)) {
this->Finished = true;
return ;
} else {
Expand Down Expand Up @@ -289,7 +289,7 @@ enum {
// If don't set the goal, the unit can than choose a
// better goal if moving nearer to enemy.
if (unit.Type->CanAttack
&& (!goal || goal->CurrentAction() == UnitActionAttack || goal->CurrentAction() == UnitActionStill)) {
&& (!goal || goal->CurrentAction() == UnitAction::Attack || goal->CurrentAction() == UnitAction::Still)) {
CUnit *target = AttackUnitsInReactRange(unit);
if (target) {
// Save current command to come back.
Expand Down
4 changes: 2 additions & 2 deletions src/action/action_repair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ bool SubRepairCosts(const CUnit &unit, CPlayer &player, CUnit &goal)
// Check if enough resources are available
for (int i = 1; i < MaxCosts; ++i) {
RepairCosts[i] = goal.Type->RepairCosts[i] *
(goal.CurrentAction() == UnitActionBuilt ? ResourcesMultiBuildersMultiplier : 1);
(goal.CurrentAction() == UnitAction::Built ? ResourcesMultiBuildersMultiplier : 1);
}
for (int i = 1; i < MaxCosts; ++i) {
if (!player.CheckResource(i, RepairCosts[i])) {
Expand All @@ -197,7 +197,7 @@ bool COrder_Repair::RepairUnit(const CUnit &unit, CUnit &goal)
{
CPlayer &player = *unit.Player;

if (goal.CurrentAction() == UnitActionBuilt) {
if (goal.CurrentAction() == UnitAction::Built) {
COrder_Built &order = *static_cast<COrder_Built *>(goal.CurrentOrder());

order.ProgressHp(goal, 100 * this->RepairCycle);
Expand Down
12 changes: 6 additions & 6 deletions src/action/action_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ int COrder_Resource::StartGathering(CUnit &unit)

// If resource is still under construction, wait!
if ((goal->Type->MaxOnBoard && goal->Resource.Active >= goal->Type->MaxOnBoard)
|| goal->CurrentAction() == UnitActionBuilt) {
|| goal->CurrentAction() == UnitAction::Built) {
// FIXME: Determine somehow when the resource will be free to use
// FIXME: Could we somehow find another resource? Think minerals
// FIXME: We should add a flag for that, and a limited range.
Expand Down Expand Up @@ -788,7 +788,7 @@ int COrder_Resource::GatherResource(CUnit &unit)
LoseResource(unit, *source);
for (CUnit *uins = source->Resource.Workers;
uins; uins = uins->NextWorker) {
if (uins != &unit && uins->CurrentOrder()->Action == UnitActionResource) {
if (uins != &unit && uins->CurrentOrder()->Action == UnitAction::Resource) {
COrder_Resource &order = *static_cast<COrder_Resource *>(uins->CurrentOrder());
if (!uins->Anim.Unbreakable && order.State == SUB_GATHER_RESOURCE) {
order.LoseResource(*uins, *source);
Expand Down Expand Up @@ -829,7 +829,7 @@ int GetNumWaitingWorkers(const CUnit &mine)
CUnit *worker = mine.Resource.Workers;

for (int i = 0; nullptr != worker; worker = worker->NextWorker, ++i) {
Assert(worker->CurrentAction() == UnitActionResource);
Assert(worker->CurrentAction() == UnitAction::Resource);
COrder_Resource &order = *static_cast<COrder_Resource *>(worker->CurrentOrder());

if (order.IsGatheringWaiting()) {
Expand Down Expand Up @@ -878,7 +878,7 @@ int COrder_Resource::StopGathering(CUnit &unit)
CUnit *worker = source->Resource.Workers;
CUnit *next = nullptr;
for (; nullptr != worker; worker = worker->NextWorker) {
Assert(worker->CurrentAction() == UnitActionResource);
Assert(worker->CurrentAction() == UnitAction::Resource);
COrder_Resource &order = *static_cast<COrder_Resource *>(worker->CurrentOrder());
if (worker != &unit && order.IsGatheringWaiting()) {
count++;
Expand Down Expand Up @@ -1019,7 +1019,7 @@ int COrder_Resource::MoveToDepot(CUnit &unit)
}

// If resource depot is still under construction, wait!
if (goal.CurrentAction() == UnitActionBuilt) {
if (goal.CurrentAction() == UnitAction::Built) {
unit.Wait = 10;
return 0;
}
Expand Down Expand Up @@ -1257,7 +1257,7 @@ bool COrder_Resource::ActionResourceInit(CUnit &unit)
if (goal && goal->IsAlive() == false) {
return false;
}
if (goal && goal->CurrentAction() != UnitActionBuilt) {
if (goal && goal->CurrentAction() != UnitAction::Built) {
unit.AssignWorkerToMine(*goal);
this->Resource.Mine = goal;
}
Expand Down
4 changes: 2 additions & 2 deletions src/action/action_spellcast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@

/* virtual */ bool COrder_SpellCast::IsValid() const
{
Assert(Action == UnitActionSpellCast);
Assert(Action == UnitAction::SpellCast);
if (this->HasGoal()) {
return this->GetGoal()->IsAliveOnMap();
} else {
Expand Down Expand Up @@ -395,7 +395,7 @@ bool COrder_SpellCast::SpellMoveToTarget(CUnit &unit)
}
}
}
if (!unit.ReCast && unit.CurrentAction() != UnitActionDie) {
if (!unit.ReCast && unit.CurrentAction() != UnitAction::Die) {
if (!unit.RestoreOrder()) {
this->Finished = true;
}
Expand Down
10 changes: 5 additions & 5 deletions src/action/action_still.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ enum {

/* virtual */ void COrder_Still::Save(CFile &file, const CUnit &unit) const
{
if (this->Action == UnitActionStill) {
if (this->Action == UnitAction::Still) {
file.printf("{\"action-still\",");
} else {
file.printf("{\"action-stand-ground\",");
Expand Down Expand Up @@ -102,7 +102,7 @@ enum {

/* virtual */ PixelPos COrder_Still::Show(const CViewport &, const PixelPos &lastScreenPos) const
{
if (this->Action == UnitActionStandGround) {
if (this->Action == UnitAction::StandGround) {
Video.FillCircleClip(ColorBlack, lastScreenPos, 2);
} else {
Video.FillCircleClip(ColorGray, lastScreenPos, 2);
Expand Down Expand Up @@ -368,7 +368,7 @@ bool AutoAttack(CUnit &unit)
}
COrder *savedOrder = nullptr;

if (unit.CurrentAction() == UnitActionStill) {
if (unit.CurrentAction() == UnitAction::Still) {
savedOrder = COrder::NewActionAttack(unit, unit.tilePos);
} else if (unit.CanStoreOrder(unit.CurrentOrder())) {
savedOrder = unit.CurrentOrder()->Clone();
Expand Down Expand Up @@ -404,7 +404,7 @@ bool AutoAttack(CUnit &unit)
return;
}
this->State = SUB_STILL_STANDBY;
this->Finished = (this->Action == UnitActionStill);
this->Finished = (this->Action == UnitAction::Still);

if (this->Sleep > 0) {
this->Sleep -= 1;
Expand All @@ -413,7 +413,7 @@ bool AutoAttack(CUnit &unit)
// sleep some time before trying again for automatic actions
this->Sleep = CYCLES_PER_SECOND / 2;

if (this->Action == UnitActionStandGround || unit.Removed || unit.CanMove() == false) {
if (this->Action == UnitAction::StandGround || unit.Removed || unit.CanMove() == false) {
if (unit.AutoCastSpell) {
this->AutoCastStand(unit);
}
Expand Down
6 changes: 3 additions & 3 deletions src/action/action_train.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static bool CanHandleOrder(const CUnit &unit, COrder *order)
if (order == nullptr) {
return false;
}
if (order->Action == UnitActionResource) {
if (order->Action == UnitAction::Resource) {
// Check if new unit can harvest.
if (!unit.Type->BoolFlag[HARVESTER_INDEX].value) {
return false;
Expand All @@ -156,10 +156,10 @@ static bool CanHandleOrder(const CUnit &unit, COrder *order)
}
return true;
}
if (order->Action == UnitActionAttack && !unit.Type->CanAttack) {
if (order->Action == UnitAction::Attack && !unit.Type->CanAttack) {
return false;
}
if (order->Action == UnitActionBoard && unit.Type->UnitType != UnitTypeLand) {
if (order->Action == UnitAction::Board && unit.Type->UnitType != UnitTypeLand) {
return false;
}
return true;
Expand Down
Loading

0 comments on commit 5e13ae8

Please sign in to comment.