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(gameengine): keep team waypoint when reinforcements join

T0T0Wc021745522bc
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9473f55da..bd76f3624 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -159,6 +159,7 @@ found and fixed — EA's own, not port damage.**
- A guarding unit no longer fights itself between returning to post and shooting back.
- Engineers can clear mines and booby traps they cannot see.
- A helicopter no longer boards a transport from the air.
+- A reinforcement joining a team already moving along a waypoint path no longer crashes the match. It picks up the team's current waypoint before trying to follow it.
- Select a big army, right click once, and all of it goes. In a crowd, units step aside to let a neighbour past, and a unit that stepped aside at the moment it was working out its route forgot the order and stood where it was. Out of 120 units sent across a small map, 7 were left behind, and the bigger the selection the more of them stayed. Now 200 out of 200 get there. Clicking on a building did the same thing to the whole group: there was no open ground right under the cursor, so nobody was given a place to stand. The group now stands around the building.
- The whole unit limit moves on one click. The lobby allows 840 units in a match, and the game could only keep 512 of them waiting for a route at once: sent across the map together, 329 of 841 never took a step, then or ever. All 840 go now, whether one player owns them or two armies of 420 are crossing through each other, and the game never falls behind: the click itself costs 13 milliseconds, and no moment of the march took longer than 33, the time the game has for each step of the battle. With all 840 on screen the picture averages 30 frames a second on the new renderer and 37 on the old one, 2.7 milliseconds quicker than before because a crowd of infantry now redraws its shadows' poses in turns instead of every soldier every frame.
- A tank in a column no longer parks behind the one in front while that one drives away. Touching the tank ahead cut its speed a little more every moment and never let it come back, so once the leader had paused, the follower sat at a dead stop until their hulls came apart and then crawled back up to speed. Every pause at the head of a column rippled down it as a line of tanks standing still. The follower now picks its speed up again as soon as the one in front moves off. Across eight maps, stops of a second or more behind the unit ahead fell from 27 to 19 in a 30-unit squad and from 1169 to 781 in a 200-unit army, the longest single stop in that army went from 14.6 seconds to 9, and the last tank of the squad arrives 6.6 seconds sooner. In computer-against-computer matches, the time units spent jammed so hard that the game counted them stuck fell from about 1.3 seconds a match to half a second.
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
index 1839fd2da..e64d6afae 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
@@ -4538,6 +4538,15 @@ void AIFollowWaypointPathState::loadPostProcess( void )
AIInternalMoveToState::loadPostProcess();
} // end loadPostProcess
+//----------------------------------------------------------------------------------------------------------
+/** Pick the waypoint a unit joining a group should start from. A freshly joined unit has no
+ waypoint of its own, while the rest of its team may already be part-way along the path. */
+const Waypoint *AIFollowWaypointPath_groupInitialWaypoint( const Waypoint *goalWaypoint,
+ const Waypoint *teamWaypoint )
+{
+ return goalWaypoint ? goalWaypoint : teamWaypoint;
+}
+
//----------------------------------------------------------------------------------------------------------
StateReturnType AIFollowWaypointPathState::onEnter()
{
@@ -4548,8 +4557,6 @@ StateReturnType AIFollowWaypointPathState::onEnter()
if (m_currentWaypoint == NULL && !m_moveAsGroup) return STATE_FAILURE;
- getMachine()->setGoalPosition(m_currentWaypoint->getLocation());
-
m_framesSleeping = 0;
m_groupOffset.x = m_groupOffset.y = 0;
@@ -4588,9 +4595,15 @@ StateReturnType AIFollowWaypointPathState::onEnter()
m_groupOffset.y = obj->getPosition()->y - center.y;
}
}
- if (m_currentWaypoint==NULL && m_moveAsGroup) {
- m_currentWaypoint = obj->getTeam()->getCurrentWaypoint();
+ if (m_moveAsGroup) {
+ m_currentWaypoint = AIFollowWaypointPath_groupInitialWaypoint(
+ m_currentWaypoint, obj->getTeam()->getCurrentWaypoint());
}
+ if (m_currentWaypoint == NULL)
+ return STATE_FAILURE;
+
+ getMachine()->setGoalPosition(m_currentWaypoint->getLocation());
+
// set initial movement goal
computeGoal(m_moveAsGroup);
StateReturnType ret = AIInternalMoveToState::onEnter();
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 2b8187eb5..1d0b09af0 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -1384,6 +1384,27 @@ TEST(attack_move_turns_on_whoever_is_shooting_it)
CHECK( !AIAttackMove_shouldRetaliate( 0xffffffff, 0xfffffff0, WINDOW, false, true ) );
}
+/* AIStates.cpp: joinTeam clears a reinforcement's own waypoint before copying the state of a unit
+ already in its team. If that state follows a waypoint path as a group, the reinforcement has to
+ pick up the team's current waypoint before the state reads its location. */
+extern const Waypoint *AIFollowWaypointPath_groupInitialWaypoint( const Waypoint *goalWaypoint,
+ const Waypoint *teamWaypoint );
+
+TEST(a_reinforcement_joins_the_waypoint_path_its_team_is_following)
+{
+ const Waypoint *ownWaypoint = (const Waypoint *)0x100;
+ const Waypoint *teamWaypoint = (const Waypoint *)0x200;
+
+ /* An explicit order stays authoritative; joining must not rewind the unit to the team's point. */
+ CHECK_EQ( AIFollowWaypointPath_groupInitialWaypoint( ownWaypoint, teamWaypoint ), ownWaypoint );
+
+ /* This is the crash case: joinTeam left no local goal, but the active team has one. */
+ CHECK_EQ( AIFollowWaypointPath_groupInitialWaypoint( NULL, teamWaypoint ), teamWaypoint );
+
+ /* A team whose path has ended has nothing safe to dereference; the state must fail instead. */
+ CHECK( AIFollowWaypointPath_groupInitialWaypoint( NULL, NULL ) == NULL );
+}
+
/* BitFlags used to be templated on the bit count alone, and its name table is a static
member of the instantiation - so two flag sets with the same count were the SAME type
and shared one s_bitNameList. The linker folded the two definitions and kept whichever