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): keep units selected through an automatic tunnel trip

Olcay Seygan8e5e33821a28
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cbed0aa04..ceb17ead3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -412,7 +412,8 @@ found and fixed — EA's own, not port damage.**
- Circular range checks are circles now, not the square drawn around them.
- A tunnel network heals at one rate, however many entrances it has.
-- GLA units take the tunnels on their own. Give a move order across the map, and if the way through your network is any shorter than the walk, the whole selection goes down the tunnel nearest it and comes up at the one nearest where you sent it, then walks the rest. An attack move does the same and comes up still attack-moving, and fresh units heading for a rally point across the map take the tunnels too, fighting on the way if they would have walked there fighting. The tunnels used to have to be almost a third shorter before anybody took them, so fresh units with a tunnel beside their barracks and one beside the rally point mostly walked anyway. Passing through does not count as resting: only units you put inside yourself are healed. The group decides together: fifteen Rebels with six places already taken all go through, where a first version sent ten underground and walked the other five. The green order line shows it: one line to the tunnel they go down and one from the tunnel they come up at to where you sent them. Twelve Rebels crossing a small map with a tunnel at each end got there in 21 seconds instead of 50, four Scorpions in 9 instead of 21. A tunnel that has just been hit is skipped, so nobody surfaces into the fire. So is one that is still a foundation or is being sold: a tunnel you had only just placed used to count straight away, and units sent across the map queued up at a building site. The computer does it too: a GLA team losing a fight near one of its tunnels falls back underground and comes up at home, which happened 10 to 25 times a match in four Brutal GLA mirrors on Twilight Flame, and an attack wave takes the tunnels when they come up nearer your base than its road does. And the computer now digs them on purpose: a tunnel at home, one at the expansion it holds, and one three quarters of the way down the road its next wave will take, as long as nothing it has seen there can shoot. It does not wait for a fat bank to do it: a tunnel costs 800 and pays back on the first wave. In four Brutal GLA mirrors on Twilight Flame, 10 of 49 attack waves went underground, where none had before, and beaten teams fell back through a tunnel 250 times. Units you put in a tunnel yourself stay put, and a network they have filled is left alone: the order walks. With one place free, everybody still goes through it one after the other, since a unit passing through leaves the moment it arrives. Replays recorded before this change play out differently.
+- GLA units take the tunnels on their own. Give a move order across the map, and if the way through your network is any shorter than the walk, the whole selection goes down the tunnel nearest it and comes up at the one nearest where you sent it, then walks the rest. An attack move does the same and comes up still attack-moving, and fresh units heading for a rally point across the map take the tunnels too, fighting on the way if they would have walked there fighting. The tunnels used to have to be almost a third shorter before anybody took them, so fresh units with a tunnel beside their barracks and one beside the rally point mostly walked anyway. Passing through does not count as resting: only units you put inside yourself are healed. The group decides together: fifteen Rebels with six places already taken all go through, where a first version sent ten underground and walked the other five. The green order line shows it: one line to the tunnel they go down and one from the tunnel they come up at to where you sent them. Twelve Rebels crossing a small map with a tunnel at each end got there in 21 seconds instead of 50, four Scorpions in 9 instead of 21. A tunnel that has just been hit is skipped, so nobody surfaces into the fire. So is one still going up or being sold: a tunnel you had only just placed used to count straight away, and units sent across the map queued up at a building site. The computer does it too: a GLA team losing a fight near one of its tunnels falls back underground and comes up at home, which happened 10 to 25 times a match in four Brutal GLA mirrors on Twilight Flame, and an attack wave takes the tunnels when they come up nearer your base than its road does. And the computer now digs them on purpose: a tunnel at home, one at the expansion it holds, and one three quarters of the way down the road its next wave will take, as long as nothing it has seen there can shoot. It does not wait for a fat bank to do it: a tunnel costs 800 and pays back on the first wave. In four Brutal GLA mirrors on Twilight Flame, 10 of 49 attack waves went underground, where none had before, and beaten teams fell back through a tunnel 250 times. Units you put in a tunnel yourself stay put, and a network they have filled is left alone: the order walks. With one place free, everybody still goes through it one after the other, since a unit passing through leaves the moment it arrives. Replays recorded before this change play out differently.
+- Units a move order takes through the tunnels come out still selected. Going underground took each one off your selection and nothing put it back, so a group sent across the map surfaced as nobody's and had to be picked up again by hand. A trip you order by clicking a tunnel still leaves the selection the way it always has, and picking something else while they are underground means they stay out of it.
## The power bar tells the truth
@@ -540,8 +541,8 @@ found and fixed — EA's own, not port damage.**
- Your workers tell you a supply point has run dry once a match. With piles refilling, they ran dry again and again, and every time the same worker said so.
- Workers stop hesitating on their way in and out. A dock has a queue outside it and a worker treated its place in that queue as a destination: it drove to the spot, stopped dead, waited a frame, drove to the door, stopped again, and only then went in - twice a load, and nearly every load with nothing else queued. With the dock empty it drives straight in. The first version of that also skipped the walk to a supply pile or a GLA stash, which have no door of their own, so a worker a long way off played its loading animation where it stood and was paid anyway. In a four-player test match 72 loads were picked up or dropped off away from the dock, one of them 613 feet from it; now there are none.
- Hackers show how far off the next payout is. So do the black market and the oil derricks.
-- A hacker working from inside an Internet Center shows what it earns. The green figure floats over the building on every payout, the way it does over one sitting in the field. It never appeared, because the game asked the hacker whether it could be seen and a garrisoned unit is not drawn at all - which is the one place a hacker is meant to work.
- A hacker already at work stays at work when you tell a group of hackers to hack. It used to fold its laptop away and set it up again, and the payout it was halfway to started over from nothing. One that is packing up takes the order and unpacks again. Replays recorded before this change play out differently.
+- A hacker working from inside an Internet Center shows what it earns. The green figure floats over the building on every payout, the way it does over one sitting in the field. It never appeared, because the game asked the hacker whether it could be seen and a garrisoned unit is not drawn at all - which is the one place a hacker is meant to work.
- Factories take a hundred units in the queue, not nine. The build queue only ever had nine buttons and that had become the limit.
- A match can pay everyone a wage. `MoneyPerMinute` in `GameData.ini` drops the same sum into every
living player's account on the minute, on top of whatever they are mining, which is the knob a
@@ -1275,9 +1276,9 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same
- Audio is real, through the audio library the retail game ships with.
- A death cry plays to the end. So does "construction complete", and the tail of a gun. Telling a sound to stop used to cut it off that frame, where the 2003 game let it finish and only kept it from repeating; our own fix for the audio thread broke that, and it is put back. A looping sound caught in the pause between two plays can be stopped too, instead of carrying on after whatever made it is gone.
+- A sound on the right of the screen comes out of the right speaker. Since the game went 64-bit its sound library worked left and right out the wrong way round, so a tank firing off to the right was heard on the left. Only a sound well off to one side swings far enough to notice, which is why it seemed to come and go.
- Your units answer you over the battle. A reply plays at whichever of the effects and voice sliders is higher, lifted again on top of that, so "Moving out" is heard in the middle of an artillery duel. Nothing else is turned down to make room for it. EVA and briefings stay where the voice slider puts them.
- Movies follow the voice volume slider. The volume was handed to the video before it was ready to take it, so every movie played at full level, and moving the slider while one was playing changed nothing.
-- A sound on the right of the screen comes out of the right speaker. Since the game went 64-bit its sound library worked left and right out the wrong way round, so a tank firing off to the right was heard on the left. Only a sound well off to one side swings far enough to notice, which is why it seemed to come and go.
- A sound at the edge of its range can fade out instead of stopping dead. The volume curve never
actually reaches zero, so a sound you are walking away from was cut off mid-note at the maximum
range. `RangeVolumeFade = Yes` in `AudioSettings.ini` uses a fade that reaches zero exactly where
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
index 766f56915..2b7d1fcc1 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
@@ -707,6 +707,8 @@ public: // ********************************************************************
virtual void selectDrawable( Drawable *draw ); ///< Mark given Drawable as "selected"
virtual void deselectDrawable( Drawable *draw ); ///< Clear "selected" status from Drawable
virtual void deselectAllDrawables( void ); ///< Clear the "select" flag from all drawables
+ void holdSelectionThroughTunnel( Drawable *draw ); ///< a selected unit going down a tunnel on its own is selected again when it comes up
+ void restoreSelectionAfterTunnel( Drawable *draw ); ///< reselect a unit held by holdSelectionThroughTunnel
virtual Int getSelectCount( void ) { return m_selectCount; } ///< Get count of currently selected drawables
virtual Int getMaxSelectCount( void ) { return m_maxSelectCount; } ///< Get the max number of selected drawables
virtual UnsignedInt getFrameSelectionChanged( void ) { return m_frameSelectionChanged; } ///< Get the max number of selected drawables
@@ -1082,6 +1084,7 @@ protected:
AsciiString m_currentlyPlayingMovie; ///< Used to push updates to TheScriptEngine
DrawableList m_selectedDrawables; ///< A list of all selected drawables.
DrawableList m_selectedLocalDrawables; ///< A list of all selected drawables owned by the local player
+ std::vector<ObjectID> m_tunnelTripRiders; ///< selected units inside the tunnel network on a move order, selected again when they come out
Bool m_isDragSelecting; ///< If TRUE, an area selection is in progress
IRegion2D m_dragSelectRegion; ///< if isDragSelecting is TRUE, this contains select region
Bool m_isFormationDragging; ///< TRUE while a formation line is being drawn (fork)
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
index 85f734059..253a53c9c 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
@@ -5332,7 +5332,13 @@ void Drawable::updateHiddenStatus()
{
Bool hidden = m_hidden || m_hiddenByStealth;
if( hidden )
+ {
+ if( isSelected() )
+ TheInGameUI->holdSelectionThroughTunnel( this );
TheInGameUI->deselectDrawable( this );
+ }
+ else
+ TheInGameUI->restoreSelectionAfterTunnel( this );
for (DrawModule** dm = getDrawModules(); *dm; ++dm)
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index a8bef2809..009495a3a 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -6982,6 +6982,9 @@ void InGameUI::deselectAllDrawables( void )
// keep our list all tidy
m_selectedDrawables.clear();
+ // a fresh selection is the player's choice, and a unit still underground is not in it
+ m_tunnelTripRiders.clear();
+
// our selection can no longer consist of exactly one angry mob
m_soloNexusSelectedDrawableID = INVALID_DRAWABLE_ID;
@@ -7007,6 +7010,42 @@ const DrawableList *InGameUI::getAllSelectedDrawables( void ) const
return &m_selectedDrawables;
}
+//-------------------------------------------------------------------------------------------------
+/** A tunnel hides its passengers, and hiding a drawable deselects it. A player who never asked for
+ * the tunnel, because a move order took it on its own, lost the unit from the selection on the way
+ * through; remember it here so it comes back out selected. A trip ordered by clicking the tunnel
+ * still deselects, as it always did. */
+//-------------------------------------------------------------------------------------------------
+void InGameUI::holdSelectionThroughTunnel( Drawable *draw )
+{
+ const Object *obj = draw->getObject();
+ if( obj == NULL || obj->getAI() == NULL || !obj->getAI()->hasTunnelTrip() )
+ return;
+ if( obj->getControllingPlayer() != ThePlayerList->getLocalPlayer() )
+ return;
+
+ m_tunnelTripRiders.push_back( obj->getID() );
+}
+
+//-------------------------------------------------------------------------------------------------
+void InGameUI::restoreSelectionAfterTunnel( Drawable *draw )
+{
+ const Object *obj = draw->getObject();
+ if( obj == NULL )
+ return;
+
+ std::vector<ObjectID>::iterator rider = std::find( m_tunnelTripRiders.begin(), m_tunnelTripRiders.end(), obj->getID() );
+ if( rider == m_tunnelTripRiders.end() )
+ return;
+ m_tunnelTripRiders.erase( rider );
+
+ // the tunnel took it out of the logic side's group too, so it goes back in the way a click adds it
+ GameMessage *groupMsg = TheMessageStream->appendMessage( GameMessage::MSG_CREATE_SELECTED_GROUP );
+ groupMsg->appendBooleanArgument( FALSE );
+ groupMsg->appendObjectIDArgument( obj->getID() );
+ selectDrawable( draw );
+}
+
//-------------------------------------------------------------------------------------------------
/** Return the list of all the currently selected Drawable pointers. */
//-------------------------------------------------------------------------------------------------