Skip to content

Commit

Permalink
Merge pull request #547 from Wargus/clean_up
Browse files Browse the repository at this point in the history
Clean up
  • Loading branch information
Jarod42 authored Oct 21, 2023
2 parents 5900ba0 + b9d4311 commit 355c04f
Show file tree
Hide file tree
Showing 46 changed files with 634 additions and 628 deletions.
3 changes: 2 additions & 1 deletion src/action/action_build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ enum {
order->Range = builder.Type->RepairRange;
} else {
// If building inside, but be next to stop
if (building.BoolFlag[SHOREBUILDING_INDEX].value && builder.Type->UnitType == UnitTypeLand) {
if (building.BoolFlag[SHOREBUILDING_INDEX].value
&& builder.Type->MoveType == EMovement::Land) {
// Peon won't dive :-)
order->Range = 1;
}
Expand Down
8 changes: 4 additions & 4 deletions src/action/action_built.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,11 @@ static void Finish(COrder_Built &order, CUnit &unit)
player.Notify(ColorGreen, unit.tilePos, _("New %s done"), type.Name.c_str());
if (&player == ThisPlayer) {
if (type.MapSound.Ready.Sound) {
PlayUnitSound(unit, VoiceReady);
PlayUnitSound(unit, EUnitVoice::Ready);
} else if (worker) {
PlayUnitSound(*worker, VoiceWorkCompleted);
PlayUnitSound(*worker, EUnitVoice::WorkCompleted);
} else {
PlayUnitSound(unit, VoiceBuilding);
PlayUnitSound(unit, EUnitVoice::Building);
}
}

Expand Down Expand Up @@ -285,7 +285,7 @@ void COrder_Built::Execute(CUnit &unit) /* override */
// Check if we should make some random noise
// IMPORTANT: this is local randomization, do not use the SyncRand function!
if (unit.Frame == 0 && unit.Player == ThisPlayer && GameCycle % 150 == 0 && (MyRand() % 3) == 0) {
PlayUnitSound(unit, VoiceBuilding, true);
PlayUnitSound(unit, EUnitVoice::Building, true);
}

// Check if building ready. Note we can both build and repair.
Expand Down
8 changes: 5 additions & 3 deletions src/action/action_follow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,11 @@ void COrder_Follow::Execute(CUnit &unit) /* override */
}

if (dest.NewOrder == nullptr
|| (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)) {
|| (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->MoveType != EMovement::Land)) {
this->Finished = true;
return ;
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/action/action_move.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ int DoActionMove(CUnit &unit)
break;
}

if (unit.Type->UnitType == UnitTypeNaval) { // Boat (un)docking?
if (unit.Type->MoveType == EMovement::Naval) { // Boat (un)docking?
bool foundCoast = false;

for (int i = 0; i < unit.Type->TileWidth && !foundCoast; i++) {
Expand All @@ -220,7 +220,7 @@ int DoActionMove(CUnit &unit)
}
if (foundCoast) {
// Should play, even if unit already speaking
PlayUnitSound(unit, VoiceDocking, true);
PlayUnitSound(unit, EUnitVoice::Docking, true);
}
}
Vec2i pos = unit.tilePos + posd;
Expand Down Expand Up @@ -295,7 +295,7 @@ void COrder_Move::Execute(CUnit &unit) /* override */

case PF_WAIT:
{
const CUnit *blocker = UnitOnMapTile(this->goalPos, unit.Type->UnitType);
const CUnit *blocker = UnitOnMapTile(this->goalPos, unit.Type->MoveType);
if (blocker) {
const int distToBlocker = MapDistanceBetweenTypes(*(unit.Type), unit.tilePos, *(blocker->Type), blocker->tilePos);
if (distToBlocker == 1 && (unit.IsEnemy(*blocker) || blocker->Moving == 0)) {
Expand Down
4 changes: 2 additions & 2 deletions src/action/action_train.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ static bool CanHandleOrder(const CUnit &unit, COrder *order)
if (order->Action == UnitAction::Attack && !unit.Type->CanAttack) {
return false;
}
if (order->Action == UnitAction::Board && unit.Type->UnitType != UnitTypeLand) {
if (order->Action == UnitAction::Board && unit.Type->MoveType != EMovement::Land) {
return false;
}
return true;
Expand Down Expand Up @@ -238,7 +238,7 @@ void COrder_Train::Execute(CUnit &unit) /* override */
DropOutOnSide(*newUnit, LookingW, &unit);
player.Notify(ColorGreen, newUnit->tilePos, _("New %s ready"), nType.Name.c_str());
if (&player == ThisPlayer) {
PlayUnitSound(*newUnit, VoiceReady);
PlayUnitSound(*newUnit, EUnitVoice::Ready);
}
if (unit.Player->AiEnabled) {
AiTrainingComplete(unit, *newUnit);
Expand Down
4 changes: 2 additions & 2 deletions src/ai/ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ void AiHelpMe(const CUnit *attacker, CUnit &defender)
defender.tilePos.y);

// Don't send help to scouts (zeppelin,eye of vision).
if (!defender.Type->CanAttack && defender.Type->UnitType == UnitTypeFly) {
if (!defender.Type->CanAttack && defender.Type->MoveType == EMovement::Fly) {
return;
}
// Summoned unit, don't help
Expand Down Expand Up @@ -833,7 +833,7 @@ static void AiMoveUnitInTheWay(CUnit &unit)
}
const CUnitType &blockertype = *blocker.Type;

if (blockertype.UnitType != unittype.UnitType) {
if (blockertype.MoveType != unittype.MoveType) {
continue;
}

Expand Down
11 changes: 4 additions & 7 deletions src/ai/ai_force.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ void AiForce::Attack(const Vec2i &pos)
Vec2i goalPos(pos);

const bool isNaval = ranges::any_of(this->Units, [](const CUnit *unit) {
return unit->Type->UnitType == UnitTypeNaval && unit->Type->CanAttack;
return unit->Type->MoveType == EMovement::Naval && unit->Type->CanAttack;
});
const bool isTransporter = ranges::any_of(this->Units, [](const CUnit *unit) {
return unit->Type->CanTransport() && unit->IsAgressive() == false;
Expand Down Expand Up @@ -1000,12 +1000,9 @@ void AiForce::Update()
}

if (State == AiForceAttackingState::Attacking && idleUnits.size() == this->Size()) {
const bool isNaval = ranges::find_if(this->Units,
[](const CUnit *unit) {
return unit->Type->UnitType == UnitTypeNaval
&& unit->Type->CanAttack;
})
!= this->Units.end();
const bool isNaval = ranges::any_of(this->Units, [](const CUnit *unit) {
return unit->Type->MoveType == EMovement::Naval && unit->Type->CanAttack;
});
const CUnit *unit = nullptr;
if (isNaval) {
AiForceEnemyFinder<AIATTACK_ALLMAP>(*this, &unit);
Expand Down
14 changes: 7 additions & 7 deletions src/ai/ai_plan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class _EnemyOnMapTile
|| unit->CurrentAction() == UnitAction::Die) {
return;
}
if (unit->Type->UnitType == UnitTypeFly && unit->IsAgressive() == false) {
if (unit->Type->MoveType == EMovement::Fly && unit->IsAgressive() == false) {
return;
}
if (pos.x < unit->tilePos.x || pos.x >= unit->tilePos.x + type.TileWidth
Expand Down Expand Up @@ -189,7 +189,7 @@ bool AiFindWall(AiForce *force)
// Next best choice is any land unit. Otherwise just use the first.
CUnit *unit = force->Units[0];
for (CUnit *aiunit : force->Units) {
if (aiunit->Type->UnitType == UnitTypeLand) {
if (aiunit->Type->MoveType == EMovement::Land) {
unit = aiunit;
if (aiunit->Type->Missile.Missile->Range == 1) {
break;
Expand Down Expand Up @@ -374,7 +374,7 @@ bool AiForce::PlanAttack()
// Find a land unit of the force.
// FIXME: if force is split over different places -> broken
CUnit *landUnit = nullptr;
if (auto it = ranges::find_if(Units, CUnitTypeFinder(UnitTypeLand)); it == Units.end()) {
if (auto it = ranges::find_if(Units, CUnitTypeFinder(EMovement::Land)); it == Units.end()) {
DebugPrint("%d: No land unit in force\n", player.Index);
return false;
} else {
Expand Down Expand Up @@ -472,14 +472,14 @@ static std::pair<CUnit *, Vec2i> GetBestExplorer(const AiExplorationRequest &req
}
const CUnitType &type = *unit->Type;

if (type.UnitType != UnitTypeFly) {
if (type.MoveType != EMovement::Fly) {
if (flyeronly) {
continue;
}
if ((request.Mask & MapFieldLandUnit) && type.UnitType != UnitTypeLand) {
if ((request.Mask & MapFieldLandUnit) && type.MoveType != EMovement::Land) {
continue;
}
if ((request.Mask & MapFieldSeaUnit) && type.UnitType != UnitTypeNaval) {
if ((request.Mask & MapFieldSeaUnit) && type.MoveType != EMovement::Naval) {
continue;
}
} else {
Expand All @@ -488,7 +488,7 @@ static std::pair<CUnit *, Vec2i> GetBestExplorer(const AiExplorationRequest &req

const int sqDistance = SquareDistance(unit->tilePos, *pos);
if (bestSquareDistance == -1 || sqDistance <= bestSquareDistance
|| (bestunit->Type->UnitType != UnitTypeFly && type.UnitType == UnitTypeFly)) {
|| (bestunit->Type->MoveType != EMovement::Fly && type.MoveType == EMovement::Fly)) {
bestSquareDistance = sqDistance;
bestunit = unit;
}
Expand Down
17 changes: 5 additions & 12 deletions src/ai/ai_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -940,18 +940,11 @@ static bool AiAssignHarvesterFromUnit(CUnit &unit, int resource)

for (const CUnitType *type : UnitTypes) {
if (type && type->GivesResource == resource) {
switch (type->UnitType) {
case UnitTypeLand:
exploremask |= MapFieldLandUnit;
break;
case UnitTypeFly:
exploremask |= MapFieldAirUnit;
break;
case UnitTypeNaval:
exploremask |= MapFieldSeaUnit;
break;
default:
Assert(0);
switch (type->MoveType) {
case EMovement::Land: exploremask |= MapFieldLandUnit; break;
case EMovement::Fly: exploremask |= MapFieldAirUnit; break;
case EMovement::Naval: exploremask |= MapFieldSeaUnit; break;
default: Assert(0);
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/animation/animation_ifvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#include <sstream>

//IfVar compare types
enum EIfVarBinOp {
enum class EIfVarBinOp {
IF_GREATER_EQUAL = 1,
IF_GREATER,
IF_LESS_EQUAL,
Expand Down Expand Up @@ -115,16 +115,16 @@ void CAnimation_IfVar::Init(std::string_view s, lua_State *) /* override */
EIfVarBinOp type = static_cast<EIfVarBinOp>(to_number(op));

switch (type) {
case IF_GREATER_EQUAL: this->binOpFunc = binOpGreaterEqual; break;
case IF_GREATER: this->binOpFunc = binOpGreater; break;
case IF_LESS_EQUAL: this->binOpFunc = binOpLessEqual; break;
case IF_LESS: this->binOpFunc = binOpLess; break;
case IF_EQUAL: this->binOpFunc = binOpEqual; break;
case IF_NOT_EQUAL: this->binOpFunc = binOpNotEqual; break;
case IF_AND: this->binOpFunc = binOpAnd; break;
case IF_OR: this->binOpFunc = binOpOr; break;
case IF_XOR: this->binOpFunc = binOpXor; break;
case IF_NOT: this->binOpFunc = binOpNot; break;
case EIfVarBinOp::IF_GREATER_EQUAL: this->binOpFunc = binOpGreaterEqual; break;
case EIfVarBinOp::IF_GREATER: this->binOpFunc = binOpGreater; break;
case EIfVarBinOp::IF_LESS_EQUAL: this->binOpFunc = binOpLessEqual; break;
case EIfVarBinOp::IF_LESS: this->binOpFunc = binOpLess; break;
case EIfVarBinOp::IF_EQUAL: this->binOpFunc = binOpEqual; break;
case EIfVarBinOp::IF_NOT_EQUAL: this->binOpFunc = binOpNotEqual; break;
case EIfVarBinOp::IF_AND: this->binOpFunc = binOpAnd; break;
case EIfVarBinOp::IF_OR: this->binOpFunc = binOpOr; break;
case EIfVarBinOp::IF_XOR: this->binOpFunc = binOpXor; break;
case EIfVarBinOp::IF_NOT: this->binOpFunc = binOpNot; break;
default: this->binOpFunc = returnFalse; break;
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/animation/animation_spawnmissile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@

#include <sstream>

namespace
{
//SpawnMissile flags
enum SpawnMissile_Flags
{
SM_None = 0, /// Clears all flags
SM_Damage = 1, /// Missile deals damage to units
SM_ToTarget = 2, /// Missile is directed to unit's target
SM_Pixel = 4, /// Missile's offsets are calculated in pixels rather than tiles
SM_RelTarget = 8, /// All calculations are relative to unit's target
SM_Ranged = 16, /// Missile can't be shot if current range between unit and it's target
/// is bigger than unit's attack range
SM_SetDirection = 32 /// Missile takes the same direction as spawner
};
}


void CAnimation_SpawnMissile::Action(CUnit &unit, int &/*move*/, int /*scale*/) const /* override */
{
Assert(unit.Anim.Anim == this);
Expand Down
11 changes: 11 additions & 0 deletions src/animation/animation_spawnunit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@

#include <sstream>

namespace
{
enum SpawnUnit_Flags
{
SU_None = 0, /// Clears all flags
SU_Summoned = 1, /// Unit is marked as "summoned"
SU_JoinToAIForce = 2 /// Unit is included into spawner's AI force, if available
};
}


void CAnimation_SpawnUnit::Action(CUnit &unit, int &/*move*/, int /*scale*/) const /* override */
{
Assert(unit.Anim.Anim == this);
Expand Down
4 changes: 2 additions & 2 deletions src/editor/editloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ static void EditorUndoAction()

switch (action.Type) {
case EditorActionType::PlaceUnit: {
CUnit *unit = UnitOnMapTile(action.tilePos, action.UnitType->UnitType);
CUnit *unit = UnitOnMapTile(action.tilePos, action.UnitType->MoveType);
EditorActionRemoveUnit(*unit);
break;
}
Expand All @@ -392,7 +392,7 @@ static void EditorRedoAction()
break;

case EditorActionType::RemoveUnit: {
CUnit *unit = UnitOnMapTile(action.tilePos, action.UnitType->UnitType);
CUnit *unit = UnitOnMapTile(action.tilePos, action.UnitType->MoveType);
EditorActionRemoveUnit(*unit);
break;
}
Expand Down
12 changes: 0 additions & 12 deletions src/include/animation/animation_spawnmissile.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,6 @@
#include <string>
#include "animation.h"

//SpawnMissile flags
enum SpawnMissile_Flags {
SM_None = 0, /// Clears all flags
SM_Damage = 1, /// Missile deals damage to units
SM_ToTarget = 2, /// Missile is directed to unit's target
SM_Pixel = 4, /// Missile's offsets are calculated in pixels rather than tiles
SM_RelTarget = 8, /// All calculations are relative to unit's target
SM_Ranged = 16, /// Missile can't be shot if current range between unit and it's target
/// is bigger than unit's attack range
SM_SetDirection = 32 /// Missile takes the same direction as spawner
};

class CAnimation_SpawnMissile : public CAnimation
{
public:
Expand Down
7 changes: 0 additions & 7 deletions src/include/animation/animation_spawnunit.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@
#include <string>
#include "animation.h"

//SpawnUnit flags
enum SpawnUnit_Flags {
SU_None = 0, /// Clears all flags
SU_Summoned = 1, /// Unit is marked as "summoned"
SU_JoinToAIForce = 2 /// Unit is included into spawner's AI force, if available
};

class CAnimation_SpawnUnit : public CAnimation
{
public:
Expand Down
Loading

0 comments on commit 355c04f

Please sign in to comment.