Skip to content

Commit bc21970

Browse files
committed
refactor: Add convenience function to determine whether command is a guard command
1 parent 4d6ad25 commit bc21970

File tree

4 files changed

+33
-27
lines changed

4 files changed

+33
-27
lines changed

Generals/Code/GameEngine/Include/GameLogic/Module/JetAIUpdate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ class JetAIUpdate : public AIUpdateInterface
133133
virtual Bool getTreatAsAircraftForLocoDistToGoal() const;
134134
virtual Bool shouldDeferCommand(const AICommandType commandType) const; ///< returns whether the specified command type should be deferred
135135
virtual Bool commandRequiresTakeoff(const AICommandParms* parms) const; ///< returns whether the specified command requires takeoff
136+
virtual Bool isGuardCommand(const AICommandType commandType) const; ///< returns whether the specified command type is a guard command
136137
Bool isParkedAt(const Object* obj) const;
137138

138139
private:

Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,19 +2334,7 @@ void JetAIUpdate::aiDoCommand(const AICommandParms* parms)
23342334
return;
23352335
}
23362336

2337-
switch (parms->m_cmd)
2338-
{
2339-
case AICMD_GUARD_POSITION:
2340-
case AICMD_GUARD_OBJECT:
2341-
case AICMD_GUARD_AREA:
2342-
case AICMD_HUNT:
2343-
setFlag(ALLOW_INTERRUPT_AND_RESUME_OF_CUR_STATE_FOR_RELOAD, true);
2344-
break;
2345-
default:
2346-
setFlag(ALLOW_INTERRUPT_AND_RESUME_OF_CUR_STATE_FOR_RELOAD, false);
2347-
break;
2348-
}
2349-
2337+
setFlag(ALLOW_INTERRUPT_AND_RESUME_OF_CUR_STATE_FOR_RELOAD, isGuardCommand(parms->m_cmd));
23502338
setFlag(HAS_PENDING_COMMAND, false);
23512339
AIUpdateInterface::aiDoCommand(parms);
23522340
}
@@ -2389,6 +2377,20 @@ Bool JetAIUpdate::commandRequiresTakeoff(const AICommandParms* parms) const
23892377
}
23902378
}
23912379

2380+
Bool JetAIUpdate::isGuardCommand(const AICommandType commandType) const
2381+
{
2382+
switch (commandType)
2383+
{
2384+
case AICMD_GUARD_AREA:
2385+
case AICMD_GUARD_OBJECT:
2386+
case AICMD_GUARD_POSITION:
2387+
case AICMD_HUNT:
2388+
return true;
2389+
default:
2390+
return false;
2391+
}
2392+
}
2393+
23922394
//-------------------------------------------------------------------------------------------------
23932395
void JetAIUpdate::friend_setAllowAirLoco(Bool allowAirLoco)
23942396
{

GeneralsMD/Code/GameEngine/Include/GameLogic/Module/JetAIUpdate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class JetAIUpdate : public AIUpdateInterface
142142
virtual Bool getTreatAsAircraftForLocoDistToGoal() const;
143143
virtual Bool shouldDeferCommand(const AICommandType commandType) const; ///< returns whether the specified command type should be deferred
144144
virtual Bool commandRequiresTakeoff(const AICommandParms* parms) const; ///< returns whether the specified command requires takeoff
145+
virtual Bool isGuardCommand(const AICommandType commandType) const; ///< returns whether the specified command type is a guard command
145146
Bool isParkedAt(const Object* obj) const;
146147

147148
private:

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2569,20 +2569,7 @@ void JetAIUpdate::aiDoCommand(const AICommandParms* parms)
25692569
return;
25702570
}
25712571

2572-
switch (parms->m_cmd)
2573-
{
2574-
case AICMD_GUARD_POSITION:
2575-
case AICMD_GUARD_OBJECT:
2576-
case AICMD_GUARD_AREA:
2577-
case AICMD_HUNT:
2578-
case AICMD_GUARD_RETALIATE:
2579-
setFlag(ALLOW_INTERRUPT_AND_RESUME_OF_CUR_STATE_FOR_RELOAD, true);
2580-
break;
2581-
default:
2582-
setFlag(ALLOW_INTERRUPT_AND_RESUME_OF_CUR_STATE_FOR_RELOAD, false);
2583-
break;
2584-
}
2585-
2572+
setFlag(ALLOW_INTERRUPT_AND_RESUME_OF_CUR_STATE_FOR_RELOAD, isGuardCommand(parms->m_cmd));
25862573
setFlag(HAS_PENDING_COMMAND, false);
25872574
AIUpdateInterface::aiDoCommand(parms);
25882575
}
@@ -2625,6 +2612,21 @@ Bool JetAIUpdate::commandRequiresTakeoff(const AICommandParms* parms) const
26252612
}
26262613
}
26272614

2615+
Bool JetAIUpdate::isGuardCommand(const AICommandType commandType) const
2616+
{
2617+
switch (commandType)
2618+
{
2619+
case AICMD_GUARD_AREA:
2620+
case AICMD_GUARD_OBJECT:
2621+
case AICMD_GUARD_POSITION:
2622+
case AICMD_GUARD_RETALIATE:
2623+
case AICMD_HUNT:
2624+
return true;
2625+
default:
2626+
return false;
2627+
}
2628+
}
2629+
26282630
//-------------------------------------------------------------------------------------------------
26292631
void JetAIUpdate::friend_setAllowAirLoco(Bool allowAirLoco)
26302632
{

0 commit comments

Comments
 (0)