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): tunnel trips keep the order, rally points use them

Olcay Seygan7c6f5648bac7
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c2b24f1e3..9d2d081ee 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -399,7 +399,7 @@ 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 clearly 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. 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. 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. 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 clearly 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. 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. 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. 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.
## The power bar tells the truth
diff --git a/GeneralsMD/Code/Data/Scenarios/tunnelattack.txt b/GeneralsMD/Code/Data/Scenarios/tunnelattack.txt
new file mode 100644
index 000000000..ae0d47590
--- /dev/null
+++ b/GeneralsMD/Code/Data/Scenarios/tunnelattack.txt
@@ -0,0 +1,17 @@
+# Tunnel shortcut on a player's attack move: the rebels go underground like tunnelshortcut.txt and
+# come up attack-moving the rest of the way.
+#
+# Measured 2026-09-22 with seed 3: the last rebel is in after 784 frames. A temporary log on the far mouth showed every rebel's last leg handed out
+# as an attack move here and as a plain move under playermove. Rangers were stood beside the last
+# leg to show the difference as a fight, and in this seat setup neither side shot at the other under
+# either order, so the fight is not measured here.
+#
+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit
+# -randommap 3 2 small -autoskirmish 2 -takeover -side 0 FactionGLA -side 1 FactionAmerica
+# -seed 3 -maxframes 4800 -scenario tunnelattack -logPrefix tunnelattack_
+
+30 spawn 0 GLATunnelNetwork 1 start0:0:300
+30 spawn 0 GLATunnelNetwork 1 start1:0:300
+30 spawn 0 GLAInfantryRebel 12 start0:250:300 25
+90 playerattackmove 0 GLAInfantryRebel start1:320:300
+90 arrive 0 GLAInfantryRebel start1:320:300 250
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h
index ea598c88d..6c7e5169d 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h
@@ -752,6 +752,7 @@ public:
Bool takeTunnelTrip( Object *entrance, const Coord3D *goal, TunnelTripEnd end, CommandSourceType cmdSource );
Bool hasTunnelTrip() const { return m_hasTunnelTrip; } ///< on its way through the tunnel network to a move order's goal
const Coord3D *getTunnelTripGoal() const { return &m_tunnelTripGoal; } ///< where the trip ends, once out of the far mouth
+ TunnelTripEnd getTunnelTripEnd() const { return m_tunnelTripEnd; } ///< how the leg from the far mouth is walked
#if defined(_DEBUG) || defined(_INTERNAL)
inline const Coord3D *friend_getRequestedDestination() const { return &m_requestedDestination; }
inline const Coord3D *friend_getRequestedDestination2() const { return &m_requestedDestination2; }
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h
index 885df4e2b..96a9b0f64 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h
@@ -67,7 +67,8 @@ enum ScenarioActionType
SCENARIO_ACTION_PARTICLES, ///< particles <slot> <systemTemplate> <count> <position> [spacing]; slot is read and ignored
SCENARIO_ACTION_ENTER, ///< enter <slot> <selector> <targetSlot> <targetSelector>
SCENARIO_ACTION_PLAYERMOVE, ///< playermove <slot> <selector> <position>; a right click, not a script order
- SCENARIO_ACTION_POWER ///< power <slot> <building> <position> [powerName]; fire its special powers (or the one named) there now, charged or not
+ SCENARIO_ACTION_POWER, ///< power <slot> <building> <position> [powerName]; fire its special powers (or the one named) there now, charged or not
+ SCENARIO_ACTION_PLAYERATTACKMOVE ///< playerattackmove <slot> <selector> <position>; the player's attack move, not a script's
};
/// ScenarioAction::atStart when the position is plain numbers
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/TunnelTracker.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/TunnelTracker.cpp
index 14d2134f7..8a97c57a9 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/TunnelTracker.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/TunnelTracker.cpp
@@ -383,6 +383,12 @@ Real TunnelTracker::getFramesForFullHeal() const
void TunnelTracker::healObject( Object *obj, void *frames)
{
+ // a unit only passing through on its way somewhere was not sent in to be mended; the heal is for
+ // the ones the player put inside
+ const AIUpdateInterface *ai = obj->getAI();
+ if( ai != NULL && ai->hasTunnelTrip() )
+ return;
+
//get the number of frames to heal
Real *framesForFullHeal = (Real*)frames;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index e9326a7a0..64473e645 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -4125,13 +4125,13 @@ void InGameUI::collectOrderHints( void )
case AI_ENTER:
{
- // A move order that is going through the tunnels is still a move: one green thread to
- // the mouth it goes down and one from the mouth it comes up at to where it was sent.
- // The far mouth is worked out the way the unit will work it out when it gets there.
+ // An order that is going through the tunnels is still the order it was: one thread in its
+ // colour to the mouth it goes down and one from the mouth it comes up at to where it was
+ // sent. The far mouth is worked out the way the unit will work it out when it gets there.
const Object *entrance = ai->getGoalObject();
if( ai->hasTunnelTrip() && entrance != NULL )
{
- hint.kind = ORDER_HINT_MOVE;
+ hint.kind = ( ai->getTunnelTripEnd() == TUNNEL_TRIP_ATTACK_MOVE ) ? ORDER_HINT_ATTACK_MOVE : ORDER_HINT_MOVE;
hint.from = *obj->getPosition();
hint.to = *entrance->getPosition();
addOrderHint( hint, previous );
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp
index f0378714b..ec607d218 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp
@@ -3059,6 +3059,18 @@ void AIGroup::groupAttackMoveToPosition( const Coord3D *pos, Int maxShotsToFire,
across a map drove there in single file while the same group told to walk there spread out. */
crowdSeedLanes( m_memberList, center, pos );
+ // through the tunnel network when that is shorter, and fighting again from the far mouth; see
+ // TunnelTracker::findTunnelShortcut. A player's order or a computer's, never a script's: a mission
+ // script sends its units the way the mission was written for.
+ Object *tunnelEntrance = NULL;
+ if ((cmdSource == CMD_FROM_PLAYER || cmdSource == CMD_FROM_AI) && !m_memberList.empty())
+ {
+ const Real walkX = pos->x - center.x;
+ const Real walkY = pos->y - center.y;
+ tunnelEntrance = m_memberList.front()->getControllingPlayer()->getTunnelSystem()->findTunnelShortcut( &center, pos,
+ (Real)sqrt( walkX * walkX + walkY * walkY ) );
+ }
+
// path the members closest to the goal first; it leaves fewer of them to collide on arrival.
MemoryPoolObjectHolder iterHolder;
SimpleObjectIterator *iter = newInstance(SimpleObjectIterator);
@@ -3106,6 +3118,13 @@ void AIGroup::groupAttackMoveToPosition( const Coord3D *pos, Int maxShotsToFire,
else
computeIndividualDestination( &dest, &goalPos, theUnit, &center, FALSE );
+ const TunnelTripEnd tripEnd = theUnit->isAbleToAttack() ? TUNNEL_TRIP_ATTACK_MOVE : TUNNEL_TRIP_MOVE;
+ if (tunnelEntrance != NULL && ai->takeTunnelTrip( tunnelEntrance, &dest, tripEnd, cmdSource ))
+ {
+ ai->clearCrowdLane();
+ continue;
+ }
+
// the speed of the slowest member is picked up by AIAttackMoveToState::onEnter, which runs
// inside this order - the move state resets the desired speed, so it cannot be set here.
if (theUnit->isAbleToAttack())
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
index efe9551a6..de3881730 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
@@ -1187,10 +1187,22 @@ UpdateSleepTime AIUpdateInterface::update( void )
{
Coord3D rallyPoint = m_exitProductionRallyPoint;
m_hasExitProductionRallyPoint = FALSE;
- if (getObject()->isAbleToAttack() && hasFightingWeapon(getObject()))
- privateAttackMoveToPosition( &rallyPoint, NO_MAX_SHOTS_LIMIT, CMD_FROM_AI );
- else
- privateMoveToPosition( &rallyPoint, CMD_FROM_AI );
+ const Bool fights = getObject()->isAbleToAttack() && hasFightingWeapon(getObject());
+
+ // a rally point across the map is reached through the tunnels when they are shorter
+ const Real walkX = rallyPoint.x - getObject()->getPosition()->x;
+ const Real walkY = rallyPoint.y - getObject()->getPosition()->y;
+ Object *entrance = getObject()->getControllingPlayer()->getTunnelSystem()->findTunnelShortcut( getObject()->getPosition(),
+ &rallyPoint, (Real)sqrt( walkX * walkX + walkY * walkY ) );
+ const Bool tunnelled = entrance != NULL
+ && takeTunnelTrip( entrance, &rallyPoint, fights ? TUNNEL_TRIP_ATTACK_MOVE : TUNNEL_TRIP_MOVE, CMD_FROM_AI );
+ if (!tunnelled)
+ {
+ if (fights)
+ privateAttackMoveToPosition( &rallyPoint, NO_MAX_SHOTS_LIMIT, CMD_FROM_AI );
+ else
+ privateMoveToPosition( &rallyPoint, CMD_FROM_AI );
+ }
stRet = STATE_CONTINUE;
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp
index 1ac1a9f8e..9187ddfdd 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp
@@ -159,6 +159,8 @@ static Bool parseActionType( const AsciiString &token, ScenarioActionType *actio
*action = SCENARIO_ACTION_MOVE;
else if (token == "playermove")
*action = SCENARIO_ACTION_PLAYERMOVE;
+ else if (token == "playerattackmove")
+ *action = SCENARIO_ACTION_PLAYERATTACKMOVE;
else if (token == "attackmove")
*action = SCENARIO_ACTION_ATTACKMOVE;
else if (token == "attack")
@@ -249,6 +251,7 @@ static Int tokensNeededFor( ScenarioActionType action )
case SCENARIO_ACTION_MOVE: return SCENARIO_TOKENS_MOVE;
case SCENARIO_ACTION_PLAYERMOVE: return SCENARIO_TOKENS_MOVE;
case SCENARIO_ACTION_POWER: return SCENARIO_TOKENS_MOVE;
+ case SCENARIO_ACTION_PLAYERATTACKMOVE: return SCENARIO_TOKENS_MOVE;
case SCENARIO_ACTION_ATTACKMOVE: return SCENARIO_TOKENS_MOVE;
case SCENARIO_ACTION_ATTACK: return SCENARIO_TOKENS_ATTACK;
case SCENARIO_ACTION_ENTER: return SCENARIO_TOKENS_ATTACK;
@@ -315,6 +318,7 @@ ScenarioParseResult ScenarioDrill_parseLine( const char *line, ScenarioAction *a
case SCENARIO_ACTION_MOVE:
case SCENARIO_ACTION_PLAYERMOVE:
+ case SCENARIO_ACTION_PLAYERATTACKMOVE:
case SCENARIO_ACTION_ATTACKMOVE:
case SCENARIO_ACTION_ARRIVE:
case SCENARIO_ACTION_POWER:
@@ -928,19 +932,24 @@ static Bool executeOrder( const ScenarioAction &action, Player *player, const Co
case SCENARIO_ACTION_MOVE:
case SCENARIO_ACTION_PLAYERMOVE:
case SCENARIO_ACTION_ATTACKMOVE:
+ case SCENARIO_ACTION_PLAYERATTACKMOVE:
{
// A player's move takes a different branch of groupMoveToPosition (every member gathers on
- // the clicked point), so a script order cannot stand in for a right click.
+ // the clicked point), so a script order cannot stand in for a right click. The same goes
+ // for an attack move, which only a player's or a computer's takes through the tunnels.
+ const Bool attacks = action.action == SCENARIO_ACTION_ATTACKMOVE || action.action == SCENARIO_ACTION_PLAYERATTACKMOVE;
if (action.action == SCENARIO_ACTION_MOVE)
group->groupMoveToPosition( &dest, FALSE, CMD_FROM_SCRIPT );
else if (action.action == SCENARIO_ACTION_PLAYERMOVE)
group->groupMoveToPosition( &dest, FALSE, CMD_FROM_PLAYER );
+ else if (action.action == SCENARIO_ACTION_PLAYERATTACKMOVE)
+ group->groupAttackMoveToPosition( &dest, SCENARIO_ATTACK_SHOTS, CMD_FROM_PLAYER );
else
group->groupAttackMoveToPosition( &dest, SCENARIO_ATTACK_SHOTS, CMD_FROM_SCRIPT );
DEBUG_LOG(("SCENARIO: frame %d %s slot %d '%s' x%d to (%.0f,%.0f)\n",
action.frame,
- (action.action == SCENARIO_ACTION_ATTACKMOVE) ? "attackmove" : "move",
+ attacks ? "attackmove" : "move",
action.slot, action.selector.str(), taken, dest.x, dest.y));
break;
}