@@ -73,7 +73,6 @@ CR_REG_METADATA(CCommandAI, (
73
73
CR_MEMBER(inCommand),
74
74
CR_MEMBER(repeatOrders),
75
75
CR_MEMBER(lastSelectedCommandPage),
76
- CR_MEMBER(unimportantMove),
77
76
CR_MEMBER(commandDeathDependences),
78
77
CR_MEMBER(targetLostTimer)
79
78
))
@@ -89,7 +88,6 @@ CCommandAI::CCommandAI():
89
88
inCommand(false ),
90
89
repeatOrders(false ),
91
90
lastSelectedCommandPage(0 ),
92
- unimportantMove(false ),
93
91
targetLostTimer(TARGET_LOST_TIMER)
94
92
{}
95
93
@@ -104,7 +102,6 @@ CCommandAI::CCommandAI(CUnit* owner):
104
102
inCommand(false ),
105
103
repeatOrders(false ),
106
104
lastSelectedCommandPage(0 ),
107
- unimportantMove(false ),
108
105
targetLostTimer(TARGET_LOST_TIMER)
109
106
{
110
107
{
@@ -1029,7 +1026,7 @@ void CCommandAI::GiveWaitCommand(const Command& c)
1029
1026
StopMove ();
1030
1027
inCommand = false ;
1031
1028
targetDied = false ;
1032
- unimportantMove = false ;
1029
+
1033
1030
commandQue.push_front (c);
1034
1031
return ;
1035
1032
}
@@ -1131,8 +1128,8 @@ void CCommandAI::ExecuteInsert(const Command& c, bool fromSynced)
1131
1128
if (!queue->empty () && (insertIt == queue->begin ())) {
1132
1129
inCommand = false ;
1133
1130
targetDied = false ;
1134
- unimportantMove = false ;
1135
- SetOrderTarget (NULL );
1131
+
1132
+ SetOrderTarget (nullptr );
1136
1133
const Command& cmd = queue->front ();
1137
1134
eoh->CommandFinished (*owner, cmd);
1138
1135
eventHandler.UnitCmdDone (owner, cmd);
@@ -1581,39 +1578,40 @@ void CCommandAI::FinishCommand()
1581
1578
assert (!commandQue.empty ());
1582
1579
1583
1580
const Command cmd = commandQue.front (); // cppcheck false positive, copy is needed here
1581
+
1584
1582
const bool dontRepeat = (cmd.options & INTERNAL_ORDER);
1583
+ const bool pushCommand = (cmd.GetID () != CMD_STOP && cmd.GetID () != CMD_PATROL && cmd.GetID () != CMD_SET_WANTED_MAX_SPEED);
1585
1584
1586
- if (repeatOrders
1587
- && !dontRepeat
1588
- && (cmd.GetID () != CMD_STOP)
1589
- && (cmd.GetID () != CMD_PATROL)
1590
- && (cmd.GetID () != CMD_SET_WANTED_MAX_SPEED)){
1585
+ if (repeatOrders && !dontRepeat && pushCommand)
1591
1586
commandQue.push_back (cmd);
1592
- }
1593
1587
1594
1588
commandQue.pop_front ();
1589
+
1595
1590
inCommand = false ;
1596
1591
targetDied = false ;
1597
- unimportantMove = false ;
1598
- SetOrderTarget (NULL );
1592
+
1593
+ SetOrderTarget (nullptr );
1599
1594
eoh->CommandFinished (*owner, cmd);
1600
1595
eventHandler.UnitCmdDone (owner, cmd);
1601
1596
ClearTargetLock (cmd);
1602
1597
1603
1598
if (commandQue.empty ()) {
1604
- if (! owner->group ) {
1599
+ if (owner->group == nullptr )
1605
1600
eoh->UnitIdle (*owner);
1606
- }
1601
+
1607
1602
eventHandler.UnitIdle (owner);
1608
1603
}
1609
1604
1610
1605
// avoid infinite loops
1611
- if (lastFinishCommand != gs->frameNum ) {
1612
- lastFinishCommand = gs->frameNum ;
1613
- if (!owner->IsStunned ()) {
1614
- SlowUpdate ();
1615
- }
1616
- }
1606
+ if (lastFinishCommand == gs->frameNum )
1607
+ return ;
1608
+
1609
+ lastFinishCommand = gs->frameNum ;
1610
+
1611
+ if (owner->IsStunned ())
1612
+ return ;
1613
+
1614
+ SlowUpdate ();
1617
1615
}
1618
1616
1619
1617
void CCommandAI::AddStockpileWeapon (CWeapon* weapon)
@@ -1692,13 +1690,15 @@ void CCommandAI::WeaponFired(CWeapon* weapon, const bool searchForNewTarget)
1692
1690
}
1693
1691
}
1694
1692
1695
- // when this fails, we need to take a copy at top instead of a reference
1693
+ // if this fails, we need to take a copy at top instead of a reference
1696
1694
assert (&c == &commandQue.front ());
1697
1695
1698
1696
eoh->WeaponFired (*owner, *(weapon->weaponDef ));
1699
- if (orderFinished) {
1700
- FinishCommand ();
1701
- }
1697
+
1698
+ if (!orderFinished)
1699
+ return ;
1700
+
1701
+ FinishCommand ();
1702
1702
}
1703
1703
1704
1704
void CCommandAI::PushOrUpdateReturnFight (const float3& cmdPos1, const float3& cmdPos2)
@@ -1750,7 +1750,7 @@ bool CCommandAI::HasMoreMoveCommands(bool skipFirstCmd) const
1750
1750
bool CCommandAI::SkipParalyzeTarget (const CUnit* target)
1751
1751
{
1752
1752
// check to see if we are about to paralyze a unit that is already paralyzed
1753
- if ((target == NULL ) || (owner->weapons .empty ()))
1753
+ if ((target == nullptr ) || (owner->weapons .empty ()))
1754
1754
return false ;
1755
1755
1756
1756
const CWeapon* w = owner->weapons .front ();
@@ -1765,31 +1765,33 @@ bool CCommandAI::SkipParalyzeTarget(const CUnit* target)
1765
1765
return false ;
1766
1766
}
1767
1767
1768
- bool CCommandAI::CanChangeFireState () {
1769
- const UnitDef* ud = owner->unitDef ;
1770
- const bool b = (!ud->weapons .empty () || ud->canKamikaze || ud->IsFactoryUnit ());
1771
-
1772
- return (ud->canFireControl && b);
1773
- }
1768
+ bool CCommandAI::CanChangeFireState () { return (owner->unitDef ->CanChangeFireState ()); }
1774
1769
1775
1770
1776
1771
void CCommandAI::StopAttackingAllyTeam (int ally)
1777
1772
{
1778
1773
std::vector<int > todel;
1779
1774
1780
1775
// erasing in the middle invalidates all iterators
1781
- for (CCommandQueue::iterator it = commandQue.begin (); it != commandQue.end (); ++it) {
1776
+ for (auto it = commandQue.begin (); it != commandQue.end (); ++it) {
1782
1777
const Command& c = *it;
1783
1778
1784
- if ((c.GetID () == CMD_FIGHT || c.GetID () == CMD_ATTACK) && c.params .size () == 1 ) {
1785
- const CUnit* target = unitHandler->GetUnit (c.params [0 ]);
1779
+ if (c.params .size () != 1 )
1780
+ continue ;
1781
+ if (c.GetID () != CMD_FIGHT && c.GetID () != CMD_ATTACK)
1782
+ continue ;
1786
1783
1787
- if (target && target->allyteam == ally) {
1788
- todel.push_back (it - commandQue.begin ());
1789
- }
1790
- }
1784
+ const CUnit* target = unitHandler->GetUnit (c.params [0 ]);
1785
+
1786
+ if (target == nullptr )
1787
+ continue ;
1788
+ if (target->allyteam != ally)
1789
+ continue ;
1790
+
1791
+ todel.push_back (it - commandQue.begin ());
1791
1792
}
1792
- for (std::vector<int >::reverse_iterator it = todel.rbegin (); it != todel.rend (); ++it) {
1793
+
1794
+ for (auto it = todel.rbegin (); it != todel.rend (); ++it) {
1793
1795
commandQue.erase (commandQue.begin () + *it);
1794
1796
}
1795
1797
}
0 commit comments