Skip to content

Commit 17d6135

Browse files
committed
refactor: Add convenience function to determine whether to defer commands
1 parent 06fa56b commit 17d6135

File tree

4 files changed

+40
-22
lines changed

4 files changed

+40
-22
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class JetAIUpdate : public AIUpdateInterface
131131
void positionLockon();
132132

133133
virtual Bool getTreatAsAircraftForLocoDistToGoal() const;
134+
virtual Bool shouldDeferCommand(const AICommandType commandType) const; ///< returns whether the specified command type should be deferred
134135
Bool isParkedAt(const Object* obj) const;
135136

136137
private:

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

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,18 +2316,8 @@ void JetAIUpdate::aiDoCommand(const AICommandParms* parms)
23162316
// note that we always store this, even if nothing will be "pending".
23172317
m_mostRecentCommand.store(*parms);
23182318

2319-
if (getFlag(TAKEOFF_IN_PROGRESS) || getFlag(LANDING_IN_PROGRESS))
2319+
if (shouldDeferCommand(parms->m_cmd))
23202320
{
2321-
// have to wait for takeoff or landing to complete, just store the sucker
2322-
setFlag(HAS_PENDING_COMMAND, true);
2323-
return;
2324-
}
2325-
2326-
if (parms->m_cmd == AICMD_IDLE && getStateMachine()->getCurrentStateID() == RELOAD_AMMO)
2327-
{
2328-
// uber-special-case... if we are told to idle, but are reloading ammo, ignore it for now,
2329-
// since we're already doing "nothing" and responding to this will cease our reload...
2330-
// don't just return, tho, in case we were (say) reloading during a guard stint.
23312321
setFlag(HAS_PENDING_COMMAND, true);
23322322
return;
23332323
}
@@ -2383,6 +2373,24 @@ void JetAIUpdate::aiDoCommand(const AICommandParms* parms)
23832373
AIUpdateInterface::aiDoCommand(parms);
23842374
}
23852375

2376+
//-------------------------------------------------------------------------------------------------
2377+
Bool JetAIUpdate::shouldDeferCommand(const AICommandType commandType) const
2378+
{
2379+
// Always defer commands received during takeoff or landing
2380+
if (getFlag(TAKEOFF_IN_PROGRESS) || getFlag(LANDING_IN_PROGRESS))
2381+
return true;
2382+
2383+
const StateID currentState = getStateMachine()->getCurrentStateID();
2384+
2385+
// uber-special-case... if we are told to idle, but are reloading ammo, ignore it for now,
2386+
// since we're already doing "nothing" and responding to this will cease our reload...
2387+
// don't just return, tho, in case we were (say) reloading during a guard stint.
2388+
if (commandType == AICMD_IDLE && currentState == RELOAD_AMMO)
2389+
return true;
2390+
2391+
return false;
2392+
}
2393+
23862394
//-------------------------------------------------------------------------------------------------
23872395
void JetAIUpdate::friend_setAllowAirLoco(Bool allowAirLoco)
23882396
{

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class JetAIUpdate : public AIUpdateInterface
140140
void positionLockon();
141141

142142
virtual Bool getTreatAsAircraftForLocoDistToGoal() const;
143+
virtual Bool shouldDeferCommand(const AICommandType commandType) const; ///< returns whether the specified command type should be deferred
143144
Bool isParkedAt(const Object* obj) const;
144145

145146
private:

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

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2543,18 +2543,8 @@ void JetAIUpdate::aiDoCommand(const AICommandParms* parms)
25432543
// note that we always store this, even if nothing will be "pending".
25442544
m_mostRecentCommand.store(*parms);
25452545

2546-
if (getFlag(TAKEOFF_IN_PROGRESS) || getFlag(LANDING_IN_PROGRESS))
2546+
if (shouldDeferCommand(parms->m_cmd))
25472547
{
2548-
// have to wait for takeoff or landing to complete, just store the sucker
2549-
setFlag(HAS_PENDING_COMMAND, true);
2550-
return;
2551-
}
2552-
2553-
if (parms->m_cmd == AICMD_IDLE && getStateMachine()->getCurrentStateID() == RELOAD_AMMO)
2554-
{
2555-
// uber-special-case... if we are told to idle, but are reloading ammo, ignore it for now,
2556-
// since we're already doing "nothing" and responding to this will cease our reload...
2557-
// don't just return, tho, in case we were (say) reloading during a guard stint.
25582548
setFlag(HAS_PENDING_COMMAND, true);
25592549
return;
25602550
}
@@ -2619,6 +2609,24 @@ void JetAIUpdate::aiDoCommand(const AICommandParms* parms)
26192609
AIUpdateInterface::aiDoCommand(parms);
26202610
}
26212611

2612+
//-------------------------------------------------------------------------------------------------
2613+
Bool JetAIUpdate::shouldDeferCommand(const AICommandType commandType) const
2614+
{
2615+
// Always defer commands received during takeoff or landing
2616+
if (getFlag(TAKEOFF_IN_PROGRESS) || getFlag(LANDING_IN_PROGRESS))
2617+
return true;
2618+
2619+
const StateID currentState = getStateMachine()->getCurrentStateID();
2620+
2621+
// uber-special-case... if we are told to idle, but are reloading ammo, ignore it for now,
2622+
// since we're already doing "nothing" and responding to this will cease our reload...
2623+
// don't just return, tho, in case we were (say) reloading during a guard stint.
2624+
if (commandType == AICMD_IDLE && currentState == RELOAD_AMMO)
2625+
return true;
2626+
2627+
return false;
2628+
}
2629+
26222630
//-------------------------------------------------------------------------------------------------
26232631
void JetAIUpdate::friend_setAllowAirLoco(Bool allowAirLoco)
26242632
{

0 commit comments

Comments
 (0)