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.

fix(gameclient): eight defects found reading the attack circle code

Olcay Seygan7008f262331b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b9875c3f9..59c2c1c04 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -119,8 +119,8 @@ found and fixed — EA's own, not port damage.**
- The three buttons each do one thing now. Left selects, and only selects. Right gives orders, and nothing it does moves the camera. The camera is on the middle button, and it scrolls the way the right button used to: the spot you pressed on stays put, and the further you pull away from it the faster the map runs. Hold Ctrl and the same drag turns the view instead. The wheel zooms toward whatever the cursor is over and the screen edges still scroll. The classic scheme, where left both selected and commanded and right scrolled and deselected, is gone rather than switched off, and the two checkboxes that used to choose between them are out of the options screen.
- Drag the right button and you draw a line: the selection spreads itself evenly along it, in the order the units already stand, so a column arrives as a firing line instead of a queue. It is the line you actually drew, curves and all, however far you keep drawing it: a long sweep used to give up partway through and finish as one straight run to the cursor, and now it holds its shape to the end. Letting go over the sidebar finishes the order rather than leaving the line stuck to the cursor. Draw the same line with attack move armed and the whole line is an attack move: artillery spread across a front, each gun firing on what walks into it, instead of one clump on one spot. Armed with attack instead, every unit fires on its own station along the line, which is a barrage laid across a ridge in one drag. This is what the right button freed up. `FormationDrag = no` in Options.ini turns it off if you would rather a slipped click did nothing.
- Selected units draw a thread to wherever they are going, and the marker on the spot is the game's own cursor. Every order that has a cursor gets that cursor: move, attack move, attack, force fire, ground fire, enter, dock, repair, heal, capture, hack, guard, a waypoint path. Green for a move, pink for an attack-move, red for anything that shoots, so a group told three different things reads as three different colours. It is not a flash at the moment of the order: the line is asked of the unit every frame, so it lasts until the unit gets there, changes its mind or leaves your selection, and it shows on the formation line while you are still drawing it. A unit that has walked off the edge of the screen still draws its line, which is how you see where the half of your army you cannot see is headed. The animated ring the ground used to sprout wherever you clicked is gone: it flashed for a second and told you nothing the marker sitting on the destination does not, and that marker stays for as long as the order does. A marker that has just appeared slides the last few pixels up out of the bottom right and fades in as it lands, over about an eighth of a second, so a fresh order catches your eye without anything flashing. Aircraft draw their thread from the click, not from the moment they leave the runway. A plane parked on its airfield answers an order by starting its takeoff and puts the order itself aside until the wheels are up, so the taxi and the climb, which is exactly the stretch where you are wondering whether the strike went out at all, used to show nothing.
-- A is attack and F is attack move, each arming the next order click. A click on the ground with A held down is a shot at that ground, on your own tank a shot at your own tank, and the mode drops again the moment the order goes out, so nothing stays armed behind your back. Ctrl still forces fire while you hold it. The two keys turn each other off, and the letters they took were sitting on grid commands that moved.
-- With A armed, hold the left button and drag a circle instead: everything hostile you can see inside it becomes a target list, nearest first, and the selection works down that list on its own. When the current target dies the next order goes out the same frame, so a strike group clears a circle without you clicking once per tank. It moves on from a target the group has stopped working on, too, rather than only from a dead one: something none of them can reach or hurt used to sit at the head of the list and hold every other target behind it for the rest of the match. That list is the same queue a shift-clicked attack builds, so you can see it: every target still owed has its own thread and marker, in the order they will be taken, instead of one line to whatever is being shot at this second. Hold shift while you draw the circle and its targets go on the end of what the group is already working through; draw it without shift and the circle replaces the lot. The ground inside the circle is washed the same red while you drag it, painted on the map rather than over it, so it runs up the hills inside the circle and your own tanks stand on top of it. Any order you give by hand ends the list. Losing a unit does not: the list belongs to the group that was told and carries on with whoever is left, which is worth saying because for a while it did not, and one tank dying threw away every target still owed. A target with enough of your fire already in the air to kill it counts as done, so the rest of the group takes the next thing on the list rather than emptying itself into something that is dead and has not fallen over yet. Aircraft are what this is for: a flight fires from range and the missiles are seconds behind, and four planes used to spend all four loads on the first tank in the circle. Running out of ammo does not cost you the list either. A flight that empties its racks flies home, lands, rearms and comes back to the target it left, and the queue waits for it instead of counting the trip as the group giving up: a circle drawn for four planes used to be empty by the time they were back in the air, one entry lost every two seconds they were away. The threads stay on the ground for the whole trip, too. A plane flying home has no target and no order to read, so the list it was still holding used to vanish off the map the moment it turned for base and reappear only when it was shooting again, which looks exactly like the list being thrown away.
+- A is attack and F is attack move, each arming the next order click. A click on the ground with A held down is a shot at that ground, on your own tank a shot at your own tank, and the mode drops again the moment the order goes out, so nothing stays armed behind your back. The click keeps your group, too: an attack click that was not a drag used to run the same deselect an ordinary left click runs, so the order arrived a moment after the units it was meant for had been dropped. Ctrl still forces fire while you hold it. The two keys turn each other off, and the letters they took were sitting on grid commands that moved.
+- With A armed, hold the left button and drag a circle instead: everything hostile you can see inside it becomes a target list, nearest first, and the selection works down that list on its own. When the current target dies the next order goes out the same frame, so a strike group clears a circle without you clicking once per tank. It moves on from a target the group has stopped working on, too, rather than only from a dead one: something none of them can reach or hurt used to sit at the head of the list and hold every other target behind it for the rest of the match. That list is the same queue a shift-clicked attack builds, so you can see it: every target still owed has its own thread and marker, in the order they will be taken, instead of one line to whatever is being shot at this second. Hold shift while you draw the circle and its targets go on the end of what the group is already working through; draw it without shift and the circle replaces the lot. The ground inside the circle is washed the same red while you drag it, painted on the map rather than over it, so it runs up the hills inside the circle and your own tanks stand on top of it. Any order you give by hand ends the list. Losing a unit does not: the list belongs to the group that was told and carries on with whoever is left, which is worth saying because for a while it did not, and one tank dying threw away every target still owed. A target with enough of your fire already in the air to kill it counts as done, so the rest of the group takes the next thing on the list rather than emptying itself into something that is dead and has not fallen over yet. Aircraft are what this is for: a flight fires from range and the missiles are seconds behind, and four planes used to spend all four loads on the first tank in the circle. Running out of ammo does not cost you the list either. A flight that empties its racks flies home, lands, rearms and comes back to the target it left, and the queue waits for it instead of counting the trip as the group giving up: a circle drawn for four planes used to be empty by the time they were back in the air, one entry lost every two seconds they were away. The threads stay on the ground for the whole trip, too. A plane flying home has no target and no order to read, so the list it was still holding used to vanish off the map the moment it turned for base and reappear only when it was shooting again, which looks exactly like the list being thrown away. What the circle picks up is what you can shoot: a shell or a missile crossing it is on the enemy's side like everything else and used to go on the list as a target, costing the group a two second stall on something that was about to stop existing. A target that has driven into the shroud since you picked it keeps its place in the list but stops drawing its thread, so the line cannot be used to trace it through the fog. An attack-move queued behind other orders keeps the force fire it was given rather than losing it when the attack key drops.
- Shift queues an attack now, not only a move. A or F held down while you shift-click adds a force-attack or an attack-move to the line of orders a group is already holding, and it fires the moment the order in front of it is finished - a target dead, or nobody left chasing an attack-move point. The coloured thread that shows a queued order covers it too, so a queue of "go here, then attack that, then attack-move over there" reads as one continuous line in three colours. The game's own white waypoint markings, which used to draw over the same ground the moment shift went down, are gone - they only ever duplicated what the coloured thread already showed, and doing both left a queued attack sitting under two different pictures of itself.
- Ctrl+D takes every unit of the kinds you have selected that is on the screen, and pressed twice inside half a second takes them across the whole map. One tank selected and two keystrokes is your whole armour, wherever it is standing. It was on Shift+Ctrl+E, which is three fingers for something you do in every fight, and it only ever reached across the map when the screen had nothing left to give - so the wide selection happened to you instead of being asked for.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
index b86e12262..eee3ed607 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
@@ -467,6 +467,7 @@ public: // ********************************************************************
{
Coord3D pos; ///< where to attack-move to, or the last known spot of targetID
ObjectID targetID; ///< INVALID_ID for a plain attack-move point, a specific victim otherwise
+ Bool forceAttack; ///< what the attack key said when it was queued, not when it goes out
};
void queueAttackWaypoint( const Coord3D *pos, Object *targetObj );
void clearShiftAttackQueue( void );
@@ -1045,6 +1046,7 @@ protected:
void sendShiftAttackOrder( const AttackWaypoint& waypoint ); ///< put one queue entry on the message stream
void logShiftAttackQueue( const char *why ) const; ///< one line saying what the queue did and what its group was doing
void addShiftAttackQueueTail( OrderHint& hint, const std::vector<OrderHint>& previous ); ///< every target still owed, drawn on from where the hint leaves off
+ Bool isHiddenByShroud( const Object *obj ) const; ///< is the shroud over this, for the player at this machine
void collectSelectedObjectIDs( std::vector<ObjectID>& ids ) const; ///< the selection by id, sorted
Bool selectionOwnsShiftAttackQueue( const std::vector<ObjectID>& selected ) const; ///< is this still the group the queue was given to
Bool m_displayedMaxWarning; ///< keeps the warning from being shown over and over
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index 2d8096f8e..55483ee80 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -2973,7 +2973,7 @@ void InGameUI::updateOrderHints( void )
// the order the group is on right now is no longer in the list, so it is drawn from here
const Object *active = m_shiftAttackQueueActive.targetID != INVALID_ID
? TheGameLogic->findObjectByID( m_shiftAttackQueueActive.targetID ) : NULL;
- if( active && !active->isEffectivelyDead() )
+ if( active && !active->isEffectivelyDead() && !isHiddenByShroud( active ) )
{
hint.kind = ORDER_HINT_ATTACK;
hint.to = *active->getPosition();
@@ -3005,9 +3005,11 @@ void InGameUI::addShiftAttackQueueTail( OrderHint& hint, const std::vector<Order
{
// a queued victim is drawn where it stands now rather than where it stood when the player
// picked it, so the thread follows a target that is driving away. One that died while it
- // waited its turn is drawn nowhere: the order will be skipped
+ // waited its turn is drawn nowhere: the order will be skipped. Nor is one that has driven
+ // into the shroud since it was picked - the thread would otherwise trace it through the
+ // fog, which is a look at the map you have not earned
const Object *victim = TheGameLogic->findObjectByID( qit->targetID );
- if( victim == NULL || victim->isEffectivelyDead() )
+ if( victim == NULL || victim->isEffectivelyDead() || isHiddenByShroud( victim ) )
continue;
hint.kind = ORDER_HINT_ATTACK;
@@ -3122,7 +3124,6 @@ Bool InGameUI::issueAttackCircle( void )
return FALSE;
Player *local = ThePlayerList->getLocalPlayer();
- const Int localIndex = local->getPlayerIndex();
ObjectIterator *iter = ThePartitionManager->iterateObjectsInRange( &center, radius,
FROM_CENTER_2D, NULL,
@@ -3135,7 +3136,17 @@ Bool InGameUI::issueAttackCircle( void )
continue;
if( local->getRelationship( obj->getTeam() ) != ENEMIES )
continue;
- if( obj->getShroudedStatus( localIndex ) > OBJECTSHROUD_PARTIAL_CLEAR )
+ if( isHiddenByShroud( obj ) )
+ continue;
+
+ //
+ // Not everything hostile standing in the circle is something to shoot at. A shell or a
+ // missile in flight is an object on the enemy's team like any other, and the range query hands
+ // them over the same way it hands over tanks; the rest of the engine drops them by kind
+ // wherever it scans. Each one that reached the list cost the group a two second stall on a
+ // target that was about to stop existing.
+ //
+ if( obj->isKindOf( KINDOF_PROJECTILE ) || obj->isKindOf( KINDOF_UNATTACKABLE ) )
continue;
queueAttackWaypoint( obj->getPosition(), obj );
@@ -3147,6 +3158,15 @@ Bool InGameUI::issueAttackCircle( void )
return TRUE;
}
+//-------------------------------------------------------------------------------------------------
+/** Whether the shroud is over this object as far as the player at this machine is concerned. */
+//-------------------------------------------------------------------------------------------------
+Bool InGameUI::isHiddenByShroud( const Object *obj ) const
+{
+ const Int localIndex = ThePlayerList->getLocalPlayer()->getPlayerIndex();
+ return obj->getShroudedStatus( localIndex ) > OBJECTSHROUD_PARTIAL_CLEAR;
+}
+
//-------------------------------------------------------------------------------------------------
/** Every selected object by id, sorted, which is how the shift queue recognises the group it was
* given to. */
@@ -3191,6 +3211,10 @@ void InGameUI::queueAttackWaypoint( const Coord3D *pos, Object *targetObj )
order.pos = *pos;
order.targetID = targetObj ? targetObj->getID() : INVALID_ID;
+ // remembered rather than read again when the order goes out: the attack key drops the moment the
+ // first order of the queue is sent, so everything behind it used to lose its force attack
+ order.forceAttack = isInForceAttackMode();
+
// who the queue belongs to. A selection that is not part of the group holding the queue starts
// a fresh one rather than adding to whatever the old selection was doing
std::vector<ObjectID> current;
@@ -3203,18 +3227,7 @@ void InGameUI::queueAttackWaypoint( const Coord3D *pos, Object *targetObj )
m_shiftAttackQueueRunning = TRUE;
m_shiftAttackQueueActive = order;
m_shiftAttackQueueEngagedFrame = TheGameLogic->getFrame();
-
- if( order.targetID != INVALID_ID )
- {
- GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_DO_ATTACK_OBJECT );
- msg->appendObjectIDArgument( order.targetID );
- }
- else
- {
- GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_DO_ATTACKMOVETO );
- msg->appendLocationArgument( order.pos );
- msg->appendBooleanArgument( isInForceAttackMode() );
- }
+ sendShiftAttackOrder( order );
return;
}
@@ -3229,6 +3242,7 @@ void InGameUI::clearShiftAttackQueue( void )
m_shiftAttackQueueRunning = FALSE;
m_shiftAttackQueueActive.targetID = INVALID_ID;
m_shiftAttackQueueActive.pos.zero();
+ m_shiftAttackQueueActive.forceAttack = FALSE;
m_shiftAttackQueueEngagedFrame = 0;
m_shiftAttackQueueWaitingForRearm = FALSE;
m_shiftAttackQueueWaitingForSelection = FALSE;
@@ -3288,7 +3302,7 @@ void InGameUI::sendShiftAttackOrder( const AttackWaypoint& waypoint )
{
GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_DO_ATTACKMOVETO );
msg->appendLocationArgument( waypoint.pos );
- msg->appendBooleanArgument( isInForceAttackMode() );
+ msg->appendBooleanArgument( waypoint.forceAttack );
}
}
@@ -3308,9 +3322,26 @@ void InGameUI::updateShiftAttackQueue( void )
// two seconds at the logic's own rate: longer than any repath, shorter than a stalled list
const UnsignedInt ABANDON_ORDER_FRAMES = 60;
+ // half a minute with the group out of hand. The list belongs to those units and waits for them,
+ // but a player who has walked away from it should not have it fire again ten minutes later
+ // because they happened to reselect the same planes
+ const UnsignedInt FORGET_UNHELD_FRAMES = 900;
+
if( !m_shiftAttackQueueRunning )
return;
+ //
+ // A replay is played back from the recorded command stream, and this is a place that writes new
+ // commands into it. A viewer who arms the attack key and drags a circle would be adding orders
+ // that were never in the recording, which is exactly the shape of desync that makes a replay
+ // stop matching its own CRC.
+ //
+ if( TheGameLogic->isInReplayGame() )
+ {
+ clearShiftAttackQueue();
+ return;
+ }
+
std::vector<ObjectID> current;
collectSelectedObjectIDs( current );
@@ -3346,11 +3377,23 @@ void InGameUI::updateShiftAttackQueue( void )
TheGameLogic->getFrame(), stillAlive));
}
- m_shiftAttackQueueEngagedFrame = TheGameLogic->getFrame();
+ // the clock is deliberately not reset here, so a list nobody comes back to eventually lapses
+ if( TheGameLogic->getFrame() - m_shiftAttackQueueEngagedFrame > FORGET_UNHELD_FRAMES )
+ {
+ logShiftAttackQueue( "over, half a minute with none of the group in hand" );
+ clearShiftAttackQueue();
+ }
+
return;
}
- m_shiftAttackQueueWaitingForSelection = FALSE;
+ if( m_shiftAttackQueueWaitingForSelection )
+ {
+ // back in hand: the order in flight gets its two seconds again rather than being judged on a
+ // clock that ran the whole time the group was out of the selection
+ m_shiftAttackQueueWaitingForSelection = FALSE;
+ m_shiftAttackQueueEngagedFrame = TheGameLogic->getFrame();
+ }
if( !selectionOwnsShiftAttackQueue( current ) )
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp
index 1ffdb4fce..701ab88c4 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp
@@ -1060,8 +1060,16 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessa
{
TheInGameUI->clearAttackMoveToMode();
m_attackCircleJustIssued = TRUE;
- break;
}
+
+ //
+ // Either way this press belonged to the attack key rather than to selection, so the
+ // release stops here. Falling through reaches the deselect that ends an ordinary left
+ // click, and for a press that was not a drag - a plain attack click, or a circle small
+ // enough to have no radius - that threw the group away a moment before the click behind
+ // it arrived as the order, leaving the order with nobody to give it to.
+ //
+ break;
}
if (m_dragSelecting) {
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
index aea85f93d..2c03f28ec 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
@@ -793,7 +793,16 @@ void W3DInGameUI::drawAttackCircleFill( void )
GroundOverlayQuads &quads = theGroundOverlayQuads;
const UnsignedInt fill = overlayColor( FILL_RGB, FILL_ALPHA );
- for( r = 0; r < FILL_RINGS; ++r )
+ // the innermost band is a fan around the centre point, two segments to a quad. Running it through
+ // the same loop as the rest pins both inner corners to that one point, and every second triangle
+ // of the band comes out with no area at all
+ for( s = 0; s < FILL_SEGMENTS; s += 2 )
+ {
+ quads.add( ring[ 0 ][ 0 ], ring[ 1 ][ s ], ring[ 1 ][ s + 1 ], ring[ 1 ][ s + 2 ],
+ fill, fill, fill, fill );
+ }
+
+ for( r = 1; r < FILL_RINGS; ++r )
{
for( s = 0; s < FILL_SEGMENTS; ++s )
{