Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

feat(gameengine): one guard radius per order, sized with the wheel

Olcay Seygan14b16e68bfe8
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a9b7433f2..0e9dd864b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -255,6 +255,7 @@ found and fixed — EA's own, not port damage.**
- A Chinook unloads its passengers one at a time, not stacked in one frame.
- Campaign reinforcements flown in by Chinook land again. That one-at-a-time unloading sent a mission's scripted Chinooks home with their cargo still aboard, so on the second American mission the dozers announced at the docks never got off, and neither did the next one.
- A guarding unit no longer fights itself between returning to post and shooting back.
+- Guard covers the circle you choose. How far a guard reached used to come from each unit's own eyesight, so Rangers and Missile Defenders posted on the same spot held circles of 180 and 270 and a raider standing between the two was only shot by half the group. Now one guard order gives the whole group one circle, the widest any of them had. Roll the mouse wheel while the guard key or the guard button is armed and the circle grows or shrinks before you click, drawn on the ground under the pointer as you go. Select a guarding group and its circle is drawn round the post, and every unit of yours on guard carries the guard badge over its head, selected or not.
- A unit sent out to answer a shot, whose target then died, is supposed to walk home. When that walk cannot start, because the unit cannot move or the pathfinder has no way back, the failure was taken to mean someone was still in range, and the unit went back into the attack on a target that was already gone. Both ends of that attack find nobody and hand it back to the walk, which fails again, so the loop runs out inside the same step and starts over on the next one. One match wrote 67,416 lines about it, and every line is pushed out to disk as it is written. The failed walk now counts as the walk being over. The unit looks once more, and with nobody there it goes back to what it was doing. A save that caught the chase dropped it on load; it picks the target back up. A soldier whose tunnel is gone did the same thing, and a computer match wrote 80 of those lines. With no tunnel he waits and looks. A replay recorded before this change plays back differently.
- Engineers can clear mines and booby traps they cannot see.
- A helicopter no longer boards a transport from the air.
diff --git a/GeneralsMD/Code/BuildFingerprint.manifest b/GeneralsMD/Code/BuildFingerprint.manifest
index 29208367e..3ebaa5639 100644
--- a/GeneralsMD/Code/BuildFingerprint.manifest
+++ b/GeneralsMD/Code/BuildFingerprint.manifest
@@ -44,6 +44,7 @@ Data/Scenarios/bridgelong.txt
Data/Scenarios/chokeprobe.txt
Data/Scenarios/comturret.txt
Data/Scenarios/crowdbattle.txt
+Data/Scenarios/guardradius.txt
Data/Scenarios/helislide.txt
Data/Scenarios/helitypes.txt
Data/Scenarios/helixturret.txt
diff --git a/GeneralsMD/Code/Data/Scenarios/guardradius.txt b/GeneralsMD/Code/Data/Scenarios/guardradius.txt
new file mode 100644
index 000000000..dfb54ad6b
--- /dev/null
+++ b/GeneralsMD/Code/Data/Scenarios/guardradius.txt
@@ -0,0 +1,33 @@
+# Does the radius on a guard order change what the guard takes on?
+#
+# Two posts of two Rangers and two Missile Defenders each, 700 apart on the open middle of the
+# small generated map mobopen.txt uses, each with an unarmed worker standing 300 from its post.
+# A guard's own range is its vision times GuardInnerModifierHuman (1.8): 180 for a Ranger, 270 for
+# a Missile Defender, so neither reaches the worker. The north post gets the guard key with no
+# radius, as a double-click guard or an old replay sends it; the south post gets 350, a few notches
+# of the wheel. The north worker should still be standing at the end and the south one dead.
+#
+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit
+# -randommap 1 2 small -autoskirmish 2 -takeover
+# -side 0 FactionAmerica -side 1 FactionGLA -seed 1 -maxframes 900
+# -scenario guardradius -logPrefix guardradius_
+#
+# See mobstress.txt for the line grammar.
+
+30 spawn 0 AmericaInfantryRanger 2 700 500 20
+30 spawn 0 AmericaInfantryMissileDefender 2 700 530 20
+30 spawn 1 GLAInfantryWorker 1 1000 500
+
+30 spawn 0 AirF_AmericaInfantryRanger 2 700 1200 20
+30 spawn 0 AirF_AmericaInfantryMissileDefender 2 700 1230 20
+30 spawn 1 Chem_GLAInfantryWorker 1 1000 1200
+
+60 shiftguard 0 AmericaInfantryRanger 700 515
+60 shiftguard 0 AmericaInfantryMissileDefender 700 515
+60 shiftguard 0 AirF_AmericaInfantryRanger 700 1215 350
+60 shiftguard 0 AirF_AmericaInfantryMissileDefender 700 1215 350
+
+61 tally 1 GLAInfantryWorker
+61 tally 1 Chem_GLAInfantryWorker
+880 tally 1 GLAInfantryWorker
+880 tally 1 Chem_GLAInfantryWorker
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
index 2dff652cd..32b3903d9 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
@@ -560,7 +560,7 @@ public: // ********************************************************************
};
struct OrderHint
{
- OrderHint( void ) : kind( ORDER_HINT_MOVE ), owner( INVALID_ID ), bornMs( 0 ), step( 0 ), icon( NULL ) {}
+ OrderHint( void ) : kind( ORDER_HINT_MOVE ), owner( INVALID_ID ), bornMs( 0 ), step( 0 ), icon( NULL ), radius( 0.0f ) {}
Coord3D from; ///< where the unit is now
Coord3D to; ///< where it is going
@@ -569,6 +569,7 @@ public: // ********************************************************************
UnsignedInt bornMs; ///< when the marker first appeared, so it can be slid in
Int step; ///< its place in the order the unit will get to its points, from 1; 0 when it has only the one
const Image *icon; ///< the upgrade's own button art on an upgrade step, NULL otherwise
+ Real radius; ///< the circle a guard holds round 'to', 0 for every other kind
};
const std::vector<OrderHint>& getOrderHints( void ) const { return m_drawnOrderHints; }
@@ -1254,6 +1255,14 @@ public: // ********************************************************************
void toggleGuardArmed( void ) { m_guardArmed = !m_guardArmed; m_attackMoveToMode = FALSE; m_forceAttackArmed = FALSE; m_moveArmed = FALSE; }
Bool isGuardArmed( void ) const { return m_guardArmed; }
+ // An order that covers a circle around the point it is given on (the guard key, EA's guard
+ // buttons) is armed with a radius: the wheel grows and shrinks it instead of zooming, a ring
+ // under the cursor shows it, and the order carries it. The scale drops back to 1 when nothing
+ // is armed any more.
+ Bool isAreaPicking( void ) const;
+ Real getAreaPickRadius( void ) const; ///< what the next area order covers, in world units
+ void adjustAreaPickRadius( Real notches );
+
// the move key arms the order a right click gives, for the left button: the next order click is
// that move, and a left drag draws the formation line
void toggleMoveArmed( void ) { m_moveArmed = !m_moveArmed; m_attackMoveToMode = FALSE; m_forceAttackArmed = FALSE; m_guardArmed = FALSE; }
@@ -1848,6 +1857,7 @@ protected:
Bool m_attackMoveToMode; ///< are we in attack move mode?
Bool m_forceAttackArmed; ///< is the attack key holding force fire for the next click?
Bool m_guardArmed; ///< is the guard key holding a guard order for the next click?
+ Real m_areaPickScale; ///< what the wheel has made of the armed area order's default radius
Bool m_moveArmed; ///< is the move key holding a move for the next click?
Bool m_orderKeyKeptByShift; ///< an armed key was clicked with under shift, and drops when shift comes up
Bool m_preferSelection; ///< the shift key has been depressed.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIGuard.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIGuard.h
index 0124cba68..97c83e48c 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIGuard.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIGuard.h
@@ -49,6 +49,9 @@
#include "GameLogic/AI.h"
// DEFINES ////////////////////////////////////////////////////////////////////
+/// the widest circle a player's guard order may give; the message is network input, so logic holds it here
+const Real GUARD_RADIUS_MAX = 800.0f;
+
// TYPE DEFINES ///////////////////////////////////////////////////////////////
enum
{
@@ -133,6 +136,7 @@ public:
Bool lookForInnerTarget(void);
static Real getStdGuardRange(const Object* obj);
+ static Real getGuardRange(const Object* obj); ///< the player's radius when the order gave one, else the standard range
};
//--------------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h
index 7ebd23329..b4ea0939e 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h
@@ -376,6 +376,9 @@ public:
virtual GuardTargetType getGuardTargetType() const { return m_guardTargetType[1]; }
virtual void clearGuardTargetType() { m_guardTargetType[1] = m_guardTargetType[0]; m_guardTargetType[0] = GUARDTARGET_NONE; }
virtual GuardMode getGuardMode() const { return m_guardMode; }
+ // the radius a player's guard order gave this unit; 0 leaves it on its own vision-based range
+ Real getGuardRadius() const { return m_guardRadius; }
+ void setGuardRadius( Real radius ) { m_guardRadius = radius; }
virtual Object* construct( const ThingTemplate *what,
const Coord3D *pos, Real angle,
@@ -851,6 +854,7 @@ private:
*/
GuardMode m_guardMode;
+ Real m_guardRadius; ///< set by a player's guard order; 0 for the vision-based range
GuardTargetType m_guardTargetType[2];
Coord3D m_locationToGuard;
ObjectID m_objectToGuard;
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h
index 74c9f1068..c0d5ef10c 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h
@@ -78,7 +78,7 @@ enum ScenarioActionType
SCENARIO_ACTION_SHIFTMOVE, ///< shiftmove <slot> <selector> <position>; a shift right click, onto the units' order queue
SCENARIO_ACTION_SHIFTATTACKMOVE, ///< shiftattackmove <slot> <selector> <position>; the same with attack move
SCENARIO_ACTION_SHIFTATTACK, ///< shiftattack <slot> <selector> <targetSlot> <targetSelector>; the same with an attack on one unit
- SCENARIO_ACTION_SHIFTGUARD, ///< shiftguard <slot> <selector> <position>; the same with the guard key
+ SCENARIO_ACTION_SHIFTGUARD, ///< shiftguard <slot> <selector> <position> [radius]; the same with the guard key, and the circle the wheel set
SCENARIO_ACTION_SHIFTPOWER, ///< shiftpower <slot> <selector> <targetSlot> <targetSelector> <power>; the same with a special power armed, on one object
SCENARIO_ACTION_SHIFTUPGRADE, ///< shiftupgrade <slot> <selector> <upgrade>; shift on an object upgrade button, bought by every unit that matches
SCENARIO_ACTION_DOCK, ///< dock <slot> <selector> <targetSlot> <targetSelector>; a right click on a supply point or a dock
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index 73af20c7a..9af795550 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -1334,6 +1334,7 @@ InGameUI::InGameUI()
m_attackMoveToMode = false;
m_forceAttackArmed = false;
m_guardArmed = false;
+ m_areaPickScale = 1.0f;
m_moveArmed = false;
m_orderKeyKeptByShift = false;
m_preferSelection = false;
@@ -1590,7 +1591,8 @@ void InGameUI::setRadiusCursor(RadiusCursorType cursorType, const SpecialPowerTe
radius = w ? w->getContinueAttackRange() : 0.0f;
break;
case RADIUSCURSOR_GUARD_AREA:
- radius = AIGuardMachine::getStdGuardRange(obj);
+ // no decal: its size was fixed when the button was pressed, and the wheel changes the radius
+ // after that. The area pick ring takes its place (isAreaPicking)
break;
case RADIUSCURSOR_FRIENDLY_SPECIALPOWER:
case RADIUSCURSOR_OFFENSIVE_SPECIALPOWER:
@@ -3769,6 +3771,10 @@ void InGameUI::update( void )
updateReplaySeek();
+ // the wheeled radius belongs to the order it was wheeled for; a shift-kept key keeps it
+ if( !isAreaPicking() )
+ m_areaPickScale = 1.0f;
+
/// @todo make sure this code gets called even when the UI is not being drawn
if ( m_videoStream && m_videoBuffer )
{
@@ -4226,6 +4232,7 @@ void InGameUI::reset( void )
m_attackMoveToMode = false;
m_forceAttackArmed = false;
m_guardArmed = false;
+ m_areaPickScale = 1.0f;
m_moveArmed = false;
m_orderKeyKeptByShift = false;
m_preferSelection = false;
@@ -5373,6 +5380,9 @@ void InGameUI::collectOrderHints( void )
if( !getGuardedSpot( ai, resolvedGoal ) )
continue;
goalResolved = TRUE;
+ // and the circle it holds there
+ if( ai->getCurrentStateID() == AI_GUARD )
+ hint.radius = AIGuardMachine::getGuardRange( obj );
break;
}
@@ -7346,6 +7356,62 @@ void InGameUI::adjustPlacementRowGap( Real spin )
} // end adjustPlacementRowGap
+static const Real AREA_PICK_RADIUS_MIN = 50.0f;
+static const Real AREA_PICK_STEP = 1.15f; ///< what one notch of the wheel multiplies the radius by
+
+//-------------------------------------------------------------------------------------------------
+/** The guard key, or one of EA's guard buttons waiting for its click. */
+//-------------------------------------------------------------------------------------------------
+Bool InGameUI::isAreaPicking( void ) const
+{
+ if( m_guardArmed )
+ return TRUE;
+
+ const CommandButton *command = m_pendingGUICommand;
+ return command && ( command->getCommandType() == GUI_COMMAND_GUARD ||
+ command->getCommandType() == GUI_COMMAND_GUARD_WITHOUT_PURSUIT ||
+ command->getCommandType() == GUI_COMMAND_GUARD_FLYING_UNITS_ONLY );
+}
+
+//-------------------------------------------------------------------------------------------------
+/** The radius the armed order starts from before the wheel touches it. A guard used to cover
+ * each unit's own vision, so riflemen and rocket troops on one spot held two different circles;
+ * the whole selection now takes the widest of them. */
+//-------------------------------------------------------------------------------------------------
+static Real areaPickBaseRadius( const DrawableList& selected )
+{
+ Real widest = 0.0f;
+ for( DrawableList::const_iterator it = selected.begin(); it != selected.end(); ++it )
+ {
+ const Object *obj = (*it)->getObject();
+ if( obj && obj->isLocallyControlled() && obj->getAI() )
+ widest = max( widest, AIGuardMachine::getStdGuardRange( obj ) );
+ }
+ return widest;
+}
+
+//-------------------------------------------------------------------------------------------------
+Real InGameUI::getAreaPickRadius( void ) const
+{
+ const Real radius = areaPickBaseRadius( m_selectedDrawables ) * m_areaPickScale;
+ return min( max( radius, AREA_PICK_RADIUS_MIN ), GUARD_RADIUS_MAX );
+}
+
+//-------------------------------------------------------------------------------------------------
+/** A notch away from the player grows the circle by a fixed share, so the wheel feels the same on a
+ * small circle as on a big one. The scale stops where the radius does, so the wheel never winds
+ * up travel that has to be undone before the circle moves again. */
+//-------------------------------------------------------------------------------------------------
+void InGameUI::adjustAreaPickRadius( Real notches )
+{
+ const Real base = areaPickBaseRadius( m_selectedDrawables );
+ if( base <= 0.0f )
+ return;
+
+ m_areaPickScale *= (Real)pow( AREA_PICK_STEP, notches );
+ m_areaPickScale = min( max( m_areaPickScale, AREA_PICK_RADIUS_MIN / base ), GUARD_RADIUS_MAX / base );
+}
+
//-------------------------------------------------------------------------------------------------
/** Every piece faces 'angle', the heading on the ghost before the drag began: the drag is spent on
* the row, so it cannot aim as well. The row stops where the money does, which is what the logic
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
index faad6be13..e03dd9b7e 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
@@ -1010,7 +1010,10 @@ GameMessage::Type CommandTranslator::issueMoveToLocationCommand( const Coord3D *
// a posted unit holds its spot and shoots what walks into range, rather than chasing it
// off the post the player put it on
if (msgType == GameMessage::MSG_DO_GUARD_POSITION)
+ {
movemsg->appendIntegerArgument( GUARDMODE_GUARD_WITHOUT_PURSUIT );
+ movemsg->appendRealArgument( TheInGameUI->getAreaPickRadius() );
+ }
} // end if
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/GUICommandTranslator.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/GUICommandTranslator.cpp
index 27795ca6a..852180c5f 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/GUICommandTranslator.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/GUICommandTranslator.cpp
@@ -230,6 +230,7 @@ static CommandStatus doGuardCommand( const CommandButton *command, GuardMode gua
msg = TheMessageStream->appendMessage( GameMessage::MSG_DO_GUARD_OBJECT );
msg->appendObjectIDArgument( target->getID() );
msg->appendIntegerArgument(guardMode);
+ msg->appendRealArgument( TheInGameUI->getAreaPickRadius() );
pickAndPlayUnitVoiceResponse(TheInGameUI->getAllSelectedDrawables(), GameMessage::MSG_DO_GUARD_OBJECT);
}
}
@@ -254,6 +255,7 @@ static CommandStatus doGuardCommand( const CommandButton *command, GuardMode gua
msg = TheMessageStream->appendMessage( GameMessage::MSG_DO_GUARD_POSITION );
msg->appendLocationArgument(world);
msg->appendIntegerArgument(guardMode);
+ msg->appendRealArgument( TheInGameUI->getAreaPickRadius() );
pickAndPlayUnitVoiceResponse(TheInGameUI->getAllSelectedDrawables(), GameMessage::MSG_DO_GUARD_POSITION);
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp
index 58d80d500..1142aad0f 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp
@@ -165,6 +165,12 @@ GameMessageDisposition PlaceEventTranslator::translateGameMessage(const GameMess
TheInGameUI->adjustPlacementRowGap( msg->getArgument( 1 )->real );
return DESTROY_MESSAGE;
}
+ // and while a guard is armed it sizes the circle the guard will hold
+ if( TheInGameUI->isAreaPicking() )
+ {
+ TheInGameUI->adjustAreaPickRadius( msg->getArgument( 1 )->real );
+ return DESTROY_MESSAGE;
+ }
break;
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGuard.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGuard.cpp
index ea7533c88..dfa32606b 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGuard.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGuard.cpp
@@ -211,6 +211,15 @@ AIGuardMachine::~AIGuardMachine()
return visionRange;
}
+//--------------------------------------------------------------------------------------
+/*static*/ Real AIGuardMachine::getGuardRange(const Object* obj)
+{
+ // The standard range is the unit's own vision, so a mixed group used to guard a different
+ // circle per unit type. A player's order carries one radius for the whole group.
+ const Real radius = obj->getAI()->getGuardRadius();
+ return radius > 0.0f ? radius : getStdGuardRange(obj);
+}
+
//--------------------------------------------------------------------------------------
Bool AIGuardMachine::lookForInnerTarget(void)
{
@@ -277,7 +286,7 @@ Bool AIGuardMachine::lookForInnerTarget(void)
// (getNextMoodTarget's UNFOGGED). It picks from what its player can see now.
filters[count++] = &filterFogged;
- Real visionRange = AIGuardMachine::getStdGuardRange(owner);
+ Real visionRange = AIGuardMachine::getGuardRange(owner);
if (area)
{
@@ -424,7 +433,7 @@ StateReturnType AIGuardInnerState::onEnter( void )
return STATE_SUCCESS;
}
m_exitConditions.m_center = pos;
- m_exitConditions.m_radiusSqr = sqr(AIGuardMachine::getStdGuardRange(getMachineOwner()));
+ m_exitConditions.m_radiusSqr = sqr(AIGuardMachine::getGuardRange(getMachineOwner()));
m_exitConditions.m_conditionsToConsider = (ExitConditions::ATTACK_ExitIfOutsideRadius |
ExitConditions::ATTACK_ExitIfNoUnitFound);
@@ -539,6 +548,9 @@ StateReturnType AIGuardOuterState::onEnter( void )
Object *obj = getMachineOwner();
Real range = TheAI->getAdjustedVisionRangeForObject(obj, AI_VISIONFACTOR_OWNERTYPE | AI_VISIONFACTOR_MOOD);
+ // the chase leash never ends inside the circle the player drew
+ if (range < obj->getAI()->getGuardRadius())
+ range = obj->getAI()->getGuardRadius();
const PolygonTrigger *area = getGuardMachine()->getAreaToGuard();
if (area)
@@ -585,7 +597,7 @@ StateReturnType AIGuardOuterState::update( void )
deltaAggr.x = m_exitConditions.m_center.x - goalObj->getPosition()->x;
deltaAggr.y = m_exitConditions.m_center.y - goalObj->getPosition()->y;
deltaAggr.z = m_exitConditions.m_center.z - goalObj->getPosition()->z;
- Real visionSqr = sqr(AIGuardMachine::getStdGuardRange(getMachineOwner()));
+ Real visionSqr = sqr(AIGuardMachine::getGuardRange(getMachineOwner()));
if (deltaAggr.lengthSqr() <= visionSqr)
{
// reset the counter
@@ -843,7 +855,7 @@ StateReturnType AIGuardAttackAggressorState::onEnter( void )
Coord3D pos = targetToGuard ? *targetToGuard->getPosition() : *getGuardMachine()->getPositionToGuard();
//Don't allow guarding units to leave their guard radius!
m_exitConditions.m_center = pos;
- m_exitConditions.m_radiusSqr = sqr(AIGuardMachine::getStdGuardRange(getMachineOwner()));
+ m_exitConditions.m_radiusSqr = sqr(AIGuardMachine::getGuardRange(getMachineOwner()));
m_exitConditions.m_attackGiveUpFrame = TheGameLogic->getFrame() + TheAI->getAiData()->m_guardChaseUnitFrames;
m_exitConditions.m_conditionsToConsider = (ExitConditions::ATTACK_ExitIfExpiredDuration |
ExitConditions::ATTACK_ExitIfNoUnitFound |
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
index 9181cab94..065210ef0 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
@@ -290,6 +290,7 @@ AIUpdateInterface::AIUpdateInterface( Thing *thing, const ModuleData* moduleData
m_desiredSpeed = FAST_AS_POSSIBLE;
m_lastCommandSource = CMD_FROM_AI;
m_guardMode = GUARDMODE_NORMAL;
+ m_guardRadius = 0.0f;
m_guardTargetType[0] = m_guardTargetType[1] = GUARDTARGET_NONE;
m_locationToGuard.zero();
m_objectToGuard = INVALID_ID;
@@ -6063,6 +6064,9 @@ void AIUpdateInterface::privateGuardPosition( const Coord3D *pos, GuardMode guar
}
m_locationToGuard = adjPos;
m_guardMode = guardMode;
+ // only a player's guard order carries a radius, set just before it arrives here
+ if (cmdSource != CMD_FROM_PLAYER)
+ m_guardRadius = 0.0f;
getStateMachine()->clear();
// The guard machine moves on its own goal, so the outer one kept whatever the last order left
@@ -6113,6 +6117,8 @@ void AIUpdateInterface::privateGuardObject( Object *objectToGuard, GuardMode gua
}
m_guardMode = guardMode;
m_objectToGuard = objectToGuard->getID();
+ if (cmdSource != CMD_FROM_PLAYER)
+ m_guardRadius = 0.0f;
getStateMachine()->clear();
setLastCommandSource( cmdSource );
@@ -6139,6 +6145,7 @@ void AIUpdateInterface::privateGuardArea( const PolygonTrigger *areaToGuard, Gua
}
m_areaToGuard = areaToGuard;
m_guardMode = guardMode;
+ m_guardRadius = 0.0f; // the area is the radius
Coord3D pos;
m_areaToGuard->getCenterPoint(&pos);
@@ -7309,12 +7316,13 @@ void AIUpdateInterface::crc( Xfer *x )
* 14: the salvage return position and its flag
* 16: the tunnel trip's goal and its flag
* 17: how the tunnel trip's last leg is walked
- * 18: the target a helicopter keeps shooting while it moves away */
+ * 18: the target a helicopter keeps shooting while it moves away
+ * 19: the radius a player's guard order set */
// ------------------------------------------------------------------------------------------------
void AIUpdateInterface::xfer( Xfer *xfer )
{
// version
- const XferVersion currentVersion = 18;
+ const XferVersion currentVersion = 19;
XferVersion version = currentVersion;
xfer->xferVersion( &version, currentVersion );
@@ -7653,6 +7661,9 @@ void AIUpdateInterface::xfer( Xfer *xfer )
xfer->xferUnsignedInt(&m_withdrawFrame);
}
+ if (version >= 19)
+ xfer->xferReal(&m_guardRadius);
+
} // end xfer
// ------------------------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
index ed72a012e..7dfbcf2e1 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
@@ -64,6 +64,7 @@
#include "GameLogic/ObjectIter.h"
#include "GameLogic/PartitionManager.h"
#include "GameLogic/AI.h"
+#include "GameLogic/AIGuard.h"
#include "GameLogic/Module/AIUpdate.h"
#include "GameLogic/Module/DozerAIUpdate.h"
#include "GameLogic/Module/SupplyTruckAIUpdate.h"
@@ -295,6 +296,32 @@ static void doClearRallyPoint( Object *obj )
}
+// ------------------------------------------------------------------------------------------------
+/** A guard order's last argument is the radius the player wheeled to, one circle for the whole
+ * group. A message without it, a double-click guard or a replay recorded before it, leaves each
+ * unit on its own vision-based range. The number came over the network, so anything that is not
+ * a sane distance reads as none, or as the cap. */
+// ------------------------------------------------------------------------------------------------
+static void setGroupGuardRadius( AIGroup *group, const GameMessage *msg, Int argIndex )
+{
+ Real radius = 0.0f;
+ if( msg->getArgumentCount() > argIndex && msg->getArgumentDataType( argIndex ) == ARGUMENTDATATYPE_REAL )
+ radius = msg->getArgument( argIndex )->real;
+ if( !( radius >= 0.0f ) ) // NaN fails this too
+ radius = 0.0f;
+ if( radius > GUARD_RADIUS_MAX )
+ radius = GUARD_RADIUS_MAX;
+ DEBUG_LOG(( "GUARD RADIUS: frame %d player %d radius %.0f\n", TheGameLogic->getFrame(), msg->getPlayerIndex(), radius ));
+
+ const VecObjectID& ids = group->getAllIDs();
+ for( VecObjectID::const_iterator it = ids.begin(); it != ids.end(); ++it )
+ {
+ Object *obj = TheGameLogic->findObjectByID( *it );
+ if( obj && obj->getAIUpdateInterface() )
+ obj->getAIUpdateInterface()->setGuardRadius( radius );
+ }
+}
+
static Object * getSingleObjectFromSelection(const AIGroup *currentlySelectedGroup)
{
// an empty group is not the same as no group: the iterator below was taken from an empty
@@ -1074,6 +1101,7 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, AIGroup *orderedGroup
GuardMode gm = (GuardMode)msg->getArgument( 1 )->integer;
if (currentlySelectedGroup)
{
+ setGroupGuardRadius( currentlySelectedGroup, msg, 2 );
currentlySelectedGroup->groupGuardPosition(&loc, gm, CMD_FROM_PLAYER);
}
@@ -1100,7 +1128,10 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, AIGroup *orderedGroup
AIUpdateInterface *ai = obj->getAIUpdateInterface();
if (ai)
+ {
+ ai->setGuardRadius( 0.0f );
ai->aiGuardPosition( obj->getPosition(), gm, CMD_FROM_PLAYER );
+ }
}
}
@@ -1176,7 +1207,10 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, AIGroup *orderedGroup
station.z = TheTerrainLogic->getGroundHeight( station.x, station.y );
if (guardAlong)
+ {
+ movers[ i ]->getAIUpdateInterface()->setGuardRadius( 0.0f );
movers[ i ]->getAIUpdateInterface()->aiGuardPosition( &station, GUARDMODE_GUARD_WITHOUT_PURSUIT, CMD_FROM_PLAYER );
+ }
else if (fireAlong)
movers[ i ]->getAIUpdateInterface()->aiAttackPosition( &station, NO_MAX_SHOTS_LIMIT, CMD_FROM_PLAYER );
else if (attackAlong)
@@ -1198,6 +1232,7 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, AIGroup *orderedGroup
GuardMode gm = (GuardMode)msg->getArgument( 1 )->integer;
if (currentlySelectedGroup)
{
+ setGroupGuardRadius( currentlySelectedGroup, msg, 2 );
currentlySelectedGroup->groupGuardObject(obj, gm, CMD_FROM_PLAYER);
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp
index f4b88d76c..8b75f69d7 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp
@@ -378,6 +378,8 @@ ScenarioParseResult ScenarioDrill_parseLine( const char *line, ScenarioAction *a
return position;
if (actionType == SCENARIO_ACTION_ARRIVE && count > next)
action->radius = (Real)atof( tokens[ next ].str() );
+ if (actionType == SCENARIO_ACTION_SHIFTGUARD)
+ action->radius = (count > next) ? (Real)atof( tokens[ next ].str() ) : 0.0f; // the wheeled radius, none by default
if (actionType == SCENARIO_ACTION_POWER && count > next)
action->targetSelector = tokens[ next ]; // fire only the power of this name
break;
@@ -1220,7 +1222,11 @@ static Bool executeShiftOrder( const ScenarioAction &action, Player *player, con
if (type == GameMessage::MSG_DO_ATTACKMOVETO)
msg->appendBooleanArgument( FALSE );
if (type == GameMessage::MSG_DO_GUARD_POSITION)
+ {
msg->appendIntegerArgument( GUARDMODE_GUARD_WITHOUT_PURSUIT );
+ if (action.radius > 0.0f)
+ msg->appendRealArgument( action.radius );
+ }
}
player->getOrderQueue()->setNextOrderMode( ORDER_QUEUE_APPEND );
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h
index 247bbcfd4..6e3a67f05 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h
@@ -88,6 +88,7 @@ protected:
void drawAllyCursors( void ); ///< each ally's pointer and name, over the world
void drawOrderStep( const OrderHint& hint, const ICoord2D& tip, UnsignedInt color ); ///< a shift list step's number and what it is
void drawBuildPlanNumbers( void ); ///< each waiting plan's turn in its builder's queue
+ void drawGuardMarkers( void ); ///< the guard badge over each of the local player's guarding units
RenderObjClass *m_buildingPlacementAnchor;
RenderObjClass *m_buildingPlacementArrow;
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
index 540105002..2f46c36ad 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
@@ -407,6 +407,8 @@ void W3DInGameUI::reset( void )
} // end reset
+static void drawGroundRing( const Coord3D& center, Real radius, UnsignedInt color, Real width );
+
//-------------------------------------------------------------------------------------------------
/** Draw member for the W3D implemenation of the game user interface */
//-------------------------------------------------------------------------------------------------
@@ -441,6 +443,18 @@ void W3DInGameUI::draw( void )
if( isAttackCircling() )
drawAttackCircle();
+ // which of the local player's units are holding a guard
+ drawGuardMarkers();
+
+ // the circle an armed guard will hold, under the cursor, at the size the wheel left it. A drag
+ // is drawing a guard line instead, where every unit holds its own station
+ if( isAreaPicking() && !m_isFormationDragging )
+ {
+ Coord3D center;
+ TheTacticalView->screenToTerrain( &TheMouse->getMouseStatus()->pos, &center );
+ drawGroundRing( center, getAreaPickRadius(), 0xCC55CCFF, 2.0f ); // the guard blue the hints use
+ }
+
// for each view draw hints
/// @todo should the UI be iterating through views like this?
if( TheDisplay )
@@ -914,19 +928,12 @@ void W3DInGameUI::drawFormationLine( void )
} // end drawFormationLine
//-------------------------------------------------------------------------------------------------
-/** draw the circle a left drag is sweeping targets out of. It is a circle on the ground, not on
- * the screen, so it follows the terrain the way the selection it is about to make does */
+/** A circle on the ground, not on the screen, so it follows the terrain the way the units it is
+ * about do */
//-------------------------------------------------------------------------------------------------
-void W3DInGameUI::drawAttackCircle( void )
+static void drawGroundRing( const Coord3D& center, Real radius, UnsignedInt color, Real width )
{
- Coord3D center;
- Real radius;
- if( !getAttackCircleGround( center, radius ) )
- return;
-
const Int segments = 48;
- const UnsignedInt color = 0xCCFF5555; //0xAARRGGBB, the attack red the hints use
- const Real width = 2.0f;
ICoord2D previous;
Bool havePrevious = FALSE;
@@ -951,6 +958,19 @@ void W3DInGameUI::drawAttackCircle( void )
previous = screen;
havePrevious = TRUE;
}
+}
+
+//-------------------------------------------------------------------------------------------------
+/** draw the circle a left drag is sweeping targets out of */
+//-------------------------------------------------------------------------------------------------
+void W3DInGameUI::drawAttackCircle( void )
+{
+ Coord3D center;
+ Real radius;
+ if( !getAttackCircleGround( center, radius ) )
+ return;
+
+ drawGroundRing( center, radius, 0xCCFF5555, 2.0f ); // the attack red the hints use
// and the radius itself, so the drag reads as a radius rather than a rubber band
ICoord2D middle;
@@ -1238,10 +1258,25 @@ void W3DInGameUI::drawOrderHints( void )
const UnsignedInt nowMs = Clock_Milliseconds();
+ // a group on one guard order is one circle, not one per unit stacked into an opaque band
+ std::vector<const OrderHint *> ringsDrawn;
+
for( std::vector<OrderHint>::const_iterator it = hints.begin(); it != hints.end(); ++it )
{
const UnsignedInt lineColor = orderHintLineColor( it->kind );
+ if( it->radius > 0.0f )
+ {
+ Bool drawn = FALSE;
+ for( size_t r = 0; r < ringsDrawn.size() && !drawn; ++r )
+ drawn = ringsDrawn[ r ]->radius == it->radius && ringsDrawn[ r ]->to.x == it->to.x && ringsDrawn[ r ]->to.y == it->to.y;
+ if( !drawn )
+ {
+ drawGroundRing( it->to, it->radius, lineColor, width );
+ ringsDrawn.push_back( &(*it) );
+ }
+ }
+
const UnsignedInt ageMs = nowMs - it->bornMs;
Real arrival = 1.0f;
if( ageMs < MARKER_SLIDE_MS )
@@ -1351,6 +1386,50 @@ void W3DInGameUI::drawBuildPlanNumbers( void )
} // end drawBuildPlanNumbers
+//-------------------------------------------------------------------------------------------------
+/** A guarding unit looks like an idle one until something walks into its circle, so each of the
+ * local player's guards wears the guard button's own art over its head, selected or not. Two
+ * groups on overlapping posts can then be told apart from the ones simply standing about. */
+//-------------------------------------------------------------------------------------------------
+void W3DInGameUI::drawGuardMarkers( void )
+{
+ const Real MARKER_HEIGHT = 14.0f;
+ const Real MARKER_LIFT = 6.0f; // clear of the health bar's line over the model's top
+
+ const Image *badge = TheMappedImageCollection->findImageByName( "SSGuard" );
+ if( badge == NULL )
+ return;
+
+ const Real scale = orderStepScale();
+ const Int height = REAL_TO_INT( MARKER_HEIGHT * scale );
+ const Int width = height * badge->getImageWidth() / max( badge->getImageHeight(), 1 );
+ const Int lift = REAL_TO_INT( MARKER_LIFT * scale );
+
+ // ponytail: walks every object each frame, like drawBuildPlanNumbers; share one walk if it shows
+ for( Object *obj = TheGameLogic->getFirstObject(); obj; obj = obj->getNextObject() )
+ {
+ if( !obj->isLocallyControlled() || obj->isEffectivelyDead() || obj->getContainedBy() )
+ continue;
+ const AIUpdateInterface *ai = obj->getAI();
+ if( ai == NULL || ai->getCurrentStateID() != AI_GUARD )
+ continue;
+ const Drawable *draw = obj->getDrawable();
+ if( draw == NULL || draw->isDrawableEffectivelyHidden() )
+ continue;
+
+ Coord3D top = *obj->getPosition();
+ top.z += obj->getGeometryInfo().getMaxHeightAbovePosition();
+ ICoord2D spot;
+ if( !TheTacticalView->worldToScreen( &top, &spot ) )
+ continue;
+
+ const Int x = spot.x - width / 2;
+ const Int y = spot.y - lift - height;
+ TheDisplay->drawImage( badge, x, y, x + width, y + height, 0xCCFFFFFF );
+ }
+
+} // end drawGuardMarkers
+
//-------------------------------------------------------------------------------------------------
/** A patch of the ally's own colour on the ground under their cursor. It is a fan of rings whose
* alpha falls to nothing at the rim, drawn in the terrain pass like the attack circle's wash, so
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index a01e98714..4fee03b7b 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -14733,6 +14733,9 @@ TEST(scenario_parses_the_order_lines)
CHECK_EQ( (Int)action.action, (Int)SCENARIO_ACTION_SHIFTATTACKMOVE );
CHECK_EQ( (Int)ScenarioDrill_parseLine( "200 shiftguard 0 * 900 700", &action ), (Int)SCENARIO_PARSE_OK );
CHECK_EQ( (Int)action.action, (Int)SCENARIO_ACTION_SHIFTGUARD );
+ CHECK( action.radius == 0.0f );
+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "200 shiftguard 0 * 900 700 350", &action ), (Int)SCENARIO_PARSE_OK );
+ CHECK( action.radius == 350.0f );
CHECK_EQ( (Int)ScenarioDrill_parseLine( "200 shiftattack 0 * 1 AmericaCommandCenter", &action ), (Int)SCENARIO_PARSE_OK );
CHECK_EQ( (Int)action.action, (Int)SCENARIO_ACTION_SHIFTATTACK );
CHECK_STR( action.targetSelector.str(), "AmericaCommandCenter" );