Skip to content

Commit

Permalink
Merge pull request #673 from Wargus/cleanup
Browse files Browse the repository at this point in the history
Cleanup
  • Loading branch information
Jarod42 committed May 9, 2024
2 parents f95bf2b + dab1c2c commit 9dfb6ab
Show file tree
Hide file tree
Showing 37 changed files with 442 additions and 386 deletions.
2 changes: 1 addition & 1 deletion src/action/action_build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ static bool CheckLimit(const CUnit &unit, const CUnitType &type)
}

// Check if hiting any limits for the building.
if (player.CheckLimits(type) < 0) {
if (player.CheckLimits(type) != ECheckLimit::Ok) {
player.Notify(ColorYellow, unit.tilePos, _("Can't build more units %s"), type.Name.c_str());
isOk = false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/action/action_built.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ static void Finish(COrder_Built &order, CUnit &unit)

// If we can harvest from the new building, do it.
if (worker->Type->ResInfo[type.GivesResource]) {
CommandResource(*worker, unit, 0);
CommandResource(*worker, unit, EFlushMode::Off);
}
// If we can reurn goods to a new depot, do it.
if (worker->CurrentResource && worker->ResourcesHeld > 0 && type.CanStore[worker->CurrentResource]) {
CommandReturnGoods(*worker, &unit, 0);
CommandReturnGoods(*worker, &unit, EFlushMode::Off);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/action/action_still.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ static bool MoveRandomly(CUnit &unit)
auto newPos = pos + Vec2i(std::clamp(vec.x, (short)-1, (short)1), std::clamp(vec.y, (short)-1, (short)1));
Map.Clamp(newPos);
if (newPos.x || newPos.y) {
CommandMove(unit, newPos, FlushCommands);
CommandMove(unit, newPos, EFlushMode::On);
return true;
}
}
Expand All @@ -211,7 +211,7 @@ static bool MoveRandomly(CUnit &unit)
UnmarkUnitFieldFlags(unit);
if (UnitCanBeAt(unit, pos)) {
MarkUnitFieldFlags(unit);
CommandMove(unit, pos, FlushCommands);
CommandMove(unit, pos, EFlushMode::On);
return true;
}
MarkUnitFieldFlags(unit);
Expand Down Expand Up @@ -295,7 +295,7 @@ bool AutoRepair(CUnit &unit)
}

//Command* will clear unit.SavedOrder
CommandRepair(unit, invalidPos, repairedUnit, FlushCommands);
CommandRepair(unit, invalidPos, repairedUnit, EFlushMode::On);
if (savedOrder != nullptr) {
unit.SavedOrder = std::move(savedOrder);
}
Expand Down Expand Up @@ -373,7 +373,7 @@ bool AutoAttack(CUnit &unit)
savedOrder = unit.CurrentOrder()->Clone();
}
// Weak goal, can choose other unit, come back after attack
CommandAttack(unit, goal->tilePos, nullptr, FlushCommands);
CommandAttack(unit, goal->tilePos, nullptr, EFlushMode::On);

if (savedOrder != nullptr) {
unit.SavedOrder = std::move(savedOrder);
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 @@ -196,9 +196,9 @@ void COrder_Train::Execute(CUnit &unit) /* override */
this->Ticks = std::min(this->Ticks, cost);

// Check if enough supply available.
const int food = player.CheckLimits(nType);
if (food < 0) {
if (food == -3 && unit.Player->AiEnabled) {
const ECheckLimit food = player.CheckLimits(nType);
if (food != ECheckLimit::Ok) {
if (food == ECheckLimit::InsufficientSupply && unit.Player->AiEnabled) {
AiNeedMoreSupply(*unit.Player);
}
unit.Wait = CYCLES_PER_SECOND / 6;
Expand Down
2 changes: 1 addition & 1 deletion src/action/action_upgradeto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static int TransformUnitIntoType(CUnit &unit, const CUnitType &newtype)
for (int i = 0; i < MaxCosts; ++i) {
if (player.MaxResources[i] != -1) {
player.MaxResources[i] += newtype.Stats[player.Index].Storing[i] - oldtype.Stats[player.Index].Storing[i];
player.SetResource(i, player.StoredResources[i], STORE_BUILDING);
player.SetResource(i, player.StoredResources[i], EStoreType::Building);
}
}

Expand Down
89 changes: 44 additions & 45 deletions src/action/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ static void ReleaseOrders(CUnit &unit)
** Get next free order slot.
**
** @param unit pointer to unit.
** @param flush if true, flush order queue.
** @param flush if On, flush order queue.
**
** @return Pointer to next free order slot.
*/
static std::unique_ptr<COrder> *GetNextOrder(CUnit &unit, int flush)
static std::unique_ptr<COrder> *GetNextOrder(CUnit &unit, EFlushMode flush)
{
if (flush) {
if (flush == EFlushMode::On) {
// empty command queue
ReleaseOrders(unit);
}
Expand Down Expand Up @@ -160,7 +160,7 @@ static bool IsUnitValidForNetwork(const CUnit &unit)
void CommandStopUnit(CUnit &unit)
{
// Ignore that the unit could be removed.
auto *order = GetNextOrder(unit, FlushCommands); // Flush them.
auto *order = GetNextOrder(unit, EFlushMode::On); // Flush them.
Assert(order);
*order = COrder::NewActionStill();

Expand All @@ -172,9 +172,9 @@ void CommandStopUnit(CUnit &unit)
** Stand ground.
**
** @param unit pointer to unit.
** @param flush if true, flush command queue.
** @param flush If On, flush command queue.
*/
void CommandStandGround(CUnit &unit, int flush)
void CommandStandGround(CUnit &unit, EFlushMode flush)
{
std::unique_ptr<COrder> *order = nullptr;

Expand All @@ -196,9 +196,9 @@ void CommandStandGround(CUnit &unit, int flush)
**
** @param unit pointer to unit.
** @param dest unit to follow
** @param flush if true, flush command queue.
** @param flush If On, flush command queue.
*/
void CommandDefend(CUnit &unit, CUnit &dest, int flush)
void CommandDefend(CUnit &unit, CUnit &dest, EFlushMode flush)
{
if (IsUnitValidForNetwork(unit) == false) {
return ;
Expand All @@ -223,9 +223,9 @@ void CommandDefend(CUnit &unit, CUnit &dest, int flush)
**
** @param unit pointer to unit.
** @param dest unit to be followed
** @param flush if true, flush command queue.
** @param flush If On, flush command queue.
*/
void CommandFollow(CUnit &unit, CUnit &dest, int flush)
void CommandFollow(CUnit &unit, CUnit &dest, EFlushMode flush)
{
if (IsUnitValidForNetwork(unit) == false) {
return ;
Expand All @@ -250,9 +250,9 @@ void CommandFollow(CUnit &unit, CUnit &dest, int flush)
**
** @param unit pointer to unit.
** @param pos map position to move to.
** @param flush if true, flush command queue.
** @param flush If On, flush command queue.
*/
void CommandMove(CUnit &unit, const Vec2i &pos, int flush)
void CommandMove(CUnit &unit, const Vec2i &pos, EFlushMode flush)
{
Assert(Map.Info.IsPointOnMap(pos));

Expand Down Expand Up @@ -280,9 +280,9 @@ void CommandMove(CUnit &unit, const Vec2i &pos, int flush)
** @param unit pointer to unit.
** @param pos map position to repair.
** @param dest or unit to be repaired. FIXME: not supported
** @param flush if true, flush command queue.
** @param flush If On, flush command queue.
*/
void CommandRepair(CUnit &unit, const Vec2i &pos, CUnit *dest, int flush)
void CommandRepair(CUnit &unit, const Vec2i &pos, CUnit *dest, EFlushMode flush)
{
if (IsUnitValidForNetwork(unit) == false) {
return ;
Expand Down Expand Up @@ -326,9 +326,9 @@ void CommandAutoRepair(CUnit &unit, int on)
** @param unit pointer to unit.
** @param pos map position to attack.
** @param target or unit to be attacked.
** @param flush if true, flush command queue.
** @param flush If On, flush command queue.
*/
void CommandAttack(CUnit &unit, const Vec2i &pos, CUnit *target, int flush)
void CommandAttack(CUnit &unit, const Vec2i &pos, CUnit *target, EFlushMode flush)
{
Assert(Map.Info.IsPointOnMap(pos));
if (IsUnitValidForNetwork(unit) == false) {
Expand Down Expand Up @@ -359,9 +359,9 @@ void CommandAttack(CUnit &unit, const Vec2i &pos, CUnit *target, int flush)
**
** @param unit pointer to unit.
** @param pos map position to fire on.
** @param flush if true, flush command queue.
** @param flush If On, flush command queue.
*/
void CommandAttackGround(CUnit &unit, const Vec2i &pos, int flush)
void CommandAttackGround(CUnit &unit, const Vec2i &pos, EFlushMode flush)
{
Assert(Map.Info.IsPointOnMap(pos));

Expand Down Expand Up @@ -390,9 +390,9 @@ void CommandAttackGround(CUnit &unit, const Vec2i &pos, int flush)
**
** @param unit pointer to unit.
** @param pos map position to patrol between.
** @param flush if true, flush command queue.
** @param flush If On, flush command queue.
*/
void CommandPatrolUnit(CUnit &unit, const Vec2i &pos, int flush)
void CommandPatrolUnit(CUnit &unit, const Vec2i &pos, EFlushMode flush)
{
Assert(Map.Info.IsPointOnMap(pos));

Expand Down Expand Up @@ -433,9 +433,9 @@ void CommandPatrolUnit(CUnit &unit, const Vec2i &pos, int flush)
**
** @param unit pointer to unit.
** @param dest unit to be boarded.
** @param flush if true, flush command queue.
** @param flush If On, flush command queue.
*/
void CommandBoard(CUnit &unit, CUnit &dest, int flush)
void CommandBoard(CUnit &unit, CUnit &dest, EFlushMode flush)
{
if (IsUnitValidForNetwork(unit) == false) {
return ;
Expand Down Expand Up @@ -464,9 +464,9 @@ void CommandBoard(CUnit &unit, CUnit &dest, int flush)
** @param unit pointer to unit.
** @param pos map position to unload.
** @param what unit to be unloaded, nullptr for all.
** @param flush if true, flush command queue.
** @param flush If On, flush command queue.
*/
void CommandUnload(CUnit &unit, const Vec2i &pos, CUnit *what, int flush)
void CommandUnload(CUnit &unit, const Vec2i &pos, CUnit *what, EFlushMode flush)
{
if (IsUnitValidForNetwork(unit) == false) {
return ;
Expand All @@ -486,9 +486,9 @@ void CommandUnload(CUnit &unit, const Vec2i &pos, CUnit *what, int flush)
** @param unit pointer to unit.
** @param pos map position to build.
** @param what Unit type to build.
** @param flush if true, flush command queue.
** @param flush If On, flush command queue.
*/
void CommandBuildBuilding(CUnit &unit, const Vec2i &pos, CUnitType &what, int flush)
void CommandBuildBuilding(CUnit &unit, const Vec2i &pos, CUnitType &what, EFlushMode flush)
{
if (IsUnitValidForNetwork(unit) == false) {
return ;
Expand All @@ -512,9 +512,9 @@ void CommandBuildBuilding(CUnit &unit, const Vec2i &pos, CUnitType &what, int fl
** Send a unit exploring
**
** @param unit pointer to unit.
** @param flush if true, flush command queue.
** @param flush If On, flush command queue.
*/
void CommandExplore(CUnit &unit, int flush)
void CommandExplore(CUnit &unit, EFlushMode flush)
{
if (IsUnitValidForNetwork(unit) == false) {
return ;
Expand Down Expand Up @@ -557,9 +557,9 @@ void CommandDismiss(CUnit &unit)
**
** @param unit pointer to unit.
** @param pos map position for harvest.
** @param flush if true, flush command queue.
** @param flush If On, flush command queue.
*/
void CommandResourceLoc(CUnit &unit, const Vec2i &pos, int flush)
void CommandResourceLoc(CUnit &unit, const Vec2i &pos, EFlushMode flush)
{
if (IsUnitValidForNetwork(unit) == false) {
return ;
Expand Down Expand Up @@ -588,9 +588,9 @@ void CommandResourceLoc(CUnit &unit, const Vec2i &pos, int flush)
**
** @param unit pointer to unit.
** @param dest destination unit.
** @param flush if true, flush command queue.
** @param flush If On, flush command queue.
*/
void CommandResource(CUnit &unit, CUnit &dest, int flush)
void CommandResource(CUnit &unit, CUnit &dest, EFlushMode flush)
{
if (IsUnitValidForNetwork(unit) == false) {
return ;
Expand Down Expand Up @@ -622,9 +622,9 @@ void CommandResource(CUnit &unit, CUnit &dest, int flush)
**
** @param unit pointer to unit.
** @param depot bring goods to this depot.
** @param flush if true, flush command queue.
** @param flush If On, flush command queue.
*/
void CommandReturnGoods(CUnit &unit, CUnit *depot, int flush)
void CommandReturnGoods(CUnit &unit, CUnit *depot, EFlushMode flush)
{
if (IsUnitValidForNetwork(unit) == false) {
return ;
Expand Down Expand Up @@ -654,16 +654,16 @@ void CommandReturnGoods(CUnit &unit, CUnit *depot, int flush)
**
** @param unit pointer to unit.
** @param type unit type to train.
** @param flush if true, flush command queue.
** @param flush If On, flush command queue.
*/
void CommandTrainUnit(CUnit &unit, CUnitType &type, int)
void CommandTrainUnit(CUnit &unit, CUnitType &type, EFlushMode)
{
if (IsUnitValidForNetwork(unit) == false) {
return ;
}
// Check if enough resources remains? (NETWORK!)
// FIXME: wrong if append to message queue!!!
if (unit.Player->CheckLimits(type) < 0
if (unit.Player->CheckLimits(type) != ECheckLimit::Ok
|| unit.Player->CheckUnitType(type)) {
return;
}
Expand All @@ -673,8 +673,7 @@ void CommandTrainUnit(CUnit &unit, CUnitType &type, int)
return;
}

const int noFlushCommands = 0;
auto *order = GetNextOrder(unit, noFlushCommands);
auto *order = GetNextOrder(unit, EFlushMode::Off);

if (order == nullptr) {
return;
Expand Down Expand Up @@ -734,9 +733,9 @@ void CommandCancelTraining(CUnit &unit, int slot, const CUnitType *type)
**
** @param unit pointer to unit.
** @param type upgrade to type
** @param flush if true, flush command queue.
** @param flush If On, flush command queue.
*/
void CommandUpgradeTo(CUnit &unit, CUnitType &type, int flush, bool instant)
void CommandUpgradeTo(CUnit &unit, CUnitType &type, EFlushMode flush, bool instant)
{
if (IsUnitValidForNetwork(unit) == false) {
return ;
Expand Down Expand Up @@ -795,9 +794,9 @@ void CommandCancelUpgradeTo(CUnit &unit)
**
** @param unit pointer to unit.
** @param what what to research.
** @param flush if true, flush command queue.
** @param flush If On, flush command queue.
*/
void CommandResearch(CUnit &unit, CUpgrade &what, int flush)
void CommandResearch(CUnit &unit, CUpgrade &what, EFlushMode flush)
{
if (IsUnitValidForNetwork(unit) == false) {
return ;
Expand Down Expand Up @@ -839,9 +838,9 @@ void CommandCancelResearch(CUnit &unit)
** @param pos map position to spell cast on.
** @param dest Spell cast on unit (if exist).
** @param spell Spell type pointer.
** @param flush If true, flush command queue.
** @param flush If On, flush command queue.
*/
void CommandSpellCast(CUnit &unit, const Vec2i &pos, CUnit *dest, const SpellType &spell, int flush, bool isAutocast)
void CommandSpellCast(CUnit &unit, const Vec2i &pos, CUnit *dest, const SpellType &spell, EFlushMode flush, bool isAutocast)
{
DebugPrint(": %d casts %s at %d %d on %d\n",
UnitNumber(unit),
Expand Down
4 changes: 2 additions & 2 deletions src/ai/ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ void AiHelpMe(const CUnit *attacker, CUnit &defender)
}

if (shouldAttack) {
CommandAttack(*aiunit, attacker->tilePos, const_cast<CUnit *>(attacker), FlushCommands);
CommandAttack(*aiunit, attacker->tilePos, const_cast<CUnit *>(attacker), EFlushMode::On);
auto savedOrder = COrder::NewActionAttack(*aiunit, attacker->tilePos);

if (aiunit->CanStoreOrder(savedOrder.get())) {
Expand Down Expand Up @@ -899,7 +899,7 @@ static void AiMoveUnitInTheWay(CUnit &unit)
savedOrder = unit.CurrentOrder()->Clone();
}
}
CommandMove(*movableunits[index], movablepos[index], FlushCommands);
CommandMove(*movableunits[index], movablepos[index], EFlushMode::On);
if (savedOrder != nullptr) {
unit.SavedOrder = std::move(savedOrder);
}
Expand Down
Loading

0 comments on commit 9dfb6ab

Please sign in to comment.