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): pulled-out veterans leave their team until mended

Olcay Seygancb1a4a51e5b5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 122836474..18ee04dc5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -220,7 +220,7 @@ found and fixed — EA's own, not port damage.**
- Matches finish. Two of these opponents used to fail to settle 65% of their games inside sixteen minutes; it is half that now, and they end in under seven minutes on average instead of ten.
- The retreat actually happens now, on Normal as well as Hard. The order home was handed to units that were already fighting, and the game laid it over their attack instead of replacing it, so a team told to break off carried on driving at what it was shooting, and its aggressive mood turned any walk that did start into a fight on the way. A unit that makes it home gets its mood back when it stops walking.
- A beaten team stops running once it is out of range. It used to break off a fight at your front door and walk the whole map back to its base at full health, where nothing repaired it, then stand there until a script or the next wave remembered it. Now it falls back just past the reach of the guns it was losing to, waits, and goes straight back in as soon as that fight turns: your units leave or die, or enough of its own arrive. If the fight still looks lost half a minute later, it goes home and joins the next wave. A team only walks home first when your guns cover the whole road. In 32 Hard against Hard matches on Twilight Flame, 2,748 of 2,756 retreats stopped short of home, and the side doing it lost 92 units a match where it had lost 96, for the same number of kills; that difference is inside the noise of 32 matches. Replays recorded before this change play out differently.
-- It looks after its veterans. A heroic tank cost the computer no more thought than one off the line, and it fought to the last chevron. Now a unit with a rank pulls out on its own health, whatever its team does: under 35% for a veteran, 45% for an elite, 55% for a heroic. It also leaves a fight its team is losing before the team gives up, the higher the rank the sooner, though never one it is even in. It goes to whatever of its side's buildings can mend it, a tank to its repair point or a soldier to his barracks, and home when there is none. The computer also counts a ranked unit for a quarter more per chevron when it weighs one army against another, yours included, since your chevrons are on show. Over eight Hard matches on Twilight Flame it pulled out 422 ranked units, 28 of them heroic, and 358 of those went to a building that mends them. Both sides lost 1,979 units where the same matches had cost them 2,080, and 3% less in value, with the same economy. Replays recorded before this change play out differently.
+- It looks after its veterans. A heroic tank cost the computer no more thought than one off the line, and it fought to the last chevron. Now a unit with a rank pulls out on its own health, whatever its team does: under 35% for a veteran, 45% for an elite, 55% for a heroic. It also leaves a fight its team is losing before the team gives up, the higher the rank the sooner, though never one it is even in. It goes to whatever of its side's buildings can mend it, a tank to its repair point or a soldier to his barracks, and home when there is none. The computer also counts a ranked unit for a quarter more per chevron when it weighs one army against another, yours included, since your chevrons are on show. Over eight Hard matches on Twilight Flame it pulled out 422 ranked units, 28 of them heroic, and 358 of those went to a building that mends them. Both sides lost 1,979 units where the same matches had cost them 2,080, and 3% less in value, with the same economy. Replays recorded before this change play out differently. A unit sent off to be mended now leaves its squad on the way, so the squad's next order no longer drags it back into the fight half-repaired; it joins a new squad once it is fixed or home. Before, a Black Lotus at 67% health was sent to her barracks four times in a row and never arrived, and one unit was pulled out twelve times in a match. Over the same two 2v2 Hard matches on Twilight Flame the most any unit was pulled out fell from 12 and 8 to 5 and 2, and the ones still pulled out twice came back mended in between.
- It no longer runs from a fight in its own base. Home was where the retreat went, so when you rushed a Normal or Hard computer early, every defender was outnumbered, read the fight as lost, and was ordered back to the middle of the base it was already standing in, walking and not shooting, again every second and a half. Sixteen rebels and four Scorpions sent into a Hard USA base a minute in went a full minute without losing one. A fight at home is now fought where it is. While the base is being hit the computer also keeps its attack groups at home: nothing it has gathered leaves on a wave, nothing waiting to leave gathers out on the road, and the groups guarding the base are no longer called away to join an attack. What was gathered goes once none of your units it knows of stands in its base, or half a minute after the last hit. And it spends on the fight. A minute in, its opening has gone on buildings: a Hard USA had two soldiers and 8,000 in the bank when that rush arrived. Now a base under attack trains fighters from every factory that has room, each one picked against whatever of yours it has the least answer to yet, so sixteen rebels and four Scorpions get Rangers as well as Missile Defenders. It stops buying income buildings and extra factories until the fight is over, puts a gun up between the middle of its base and your units when it finds the room, and sends what it has at home at you once there is enough of it to matter; a handful sent out by twos only feeds you. Over four matches the USA left 36 of those 64 rebels alive where it had left 49. China and GLA already train at the pace their barracks allow, and came out about where they were. Replays recorded before this change play out differently.
## Hard fights each unit from where it is strongest
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h
index f5786b2b3..cc0554d59 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h
@@ -683,6 +683,7 @@ protected:
Real fightRatio(const Coord3D *centre, Bool countHolders, Real *enemyHealth, Real *enemyPower, std::vector<Real> *enemyGuns); ///< the exchange around centre, by the units in it when the rung weighs them
Bool doFallback(Team *team); ///< TRUE when it sent the team's holders back or home on this pass
void pullOutRanked(Team *team, Bool inFight, Real ratio); ///< veterans and up leave earlier than the team, to a repair or heal pad
+ void releaseMendedRanked(void); ///< pulled-out ranked units standing idle again become recruitable
void stepCalmly(Object *obj, TacticalStep *step, const Coord3D *spot); ///< a move the unit's mood cannot turn into an attack move
void restoreMood(Object *obj, TacticalStep *step);
Bool pickTacticalSpot(const Object *obj, const Coord3D *from, const Coord3D *awayFrom, Real distance,
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
index 5162eeb6a..27c2b8a45 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
@@ -10381,10 +10381,16 @@ static Object *findMender( Player *player, Object *unit )
/** The ranked members of a team that AIRetreat_rankPullsOut says go, to the nearest building that mends
* them, or home when there is none. Marked as a walk home, so neither this nor the team's retreat
- * turns them round for RETREAT_HOME_WALK_FRAMES. */
+ * turns them round for RETREAT_HOME_WALK_FRAMES.
+ *
+ * A pulled unit leaves its team for the default one and is kept from being recruited until it stands
+ * idle again, mended or home. Left in its team, the team's next script order (a waypoint path, an
+ * attack move) took it off the repair pad on the way: one Tomahawk was sent to its War Factory at 4%,
+ * 2% and 2% health thirty seconds apart and never reached it. Once idle, any team recruits it back. */
void AIPlayer::pullOutRanked( Team *team, Bool inFight, Real ratio )
{
const UnsignedInt now = TheGameLogic->getFrame();
+ std::vector<Object *> pulled;
for( DLINK_ITERATOR<Object> objIter = team->iterate_TeamMemberList(); !objIter.done(); objIter.advance() )
{
Object *obj = objIter.cur();
@@ -10427,6 +10433,31 @@ void AIPlayer::pullOutRanked( Team *team, Bool inFight, Real ratio )
inFight ? ratio : 0.0f, inFight ? "" : " (none)", (Int)state,
(Real)sqrt( sqr( to->x - obj->getPosition()->x ) + sqr( to->y - obj->getPosition()->y ) ),
mender ? mender->getTemplate()->getName().str() : "base", (Int)obj->getAI()->getCurrentStateID()));
+ pulled.push_back( obj );
+ }
+ // out of the member walk above, which setTeam would break
+ for( std::vector<Object *>::const_iterator p = pulled.begin(); p != pulled.end(); ++p )
+ {
+ (*p)->setTeam( m_player->getDefaultTeam() );
+ (*p)->getAI()->setIsRecruitable( FALSE );
+ }
+}
+
+/** Pulled-out ranked units that stand idle again, mended or home, go back to being recruitable.
+ * ponytail: any ranked default-team unit not recruitable counts as one of ours; a script that marks
+ * a default-team veteran unrecruitable would see it undone. */
+void AIPlayer::releaseMendedRanked( void )
+{
+ for( DLINK_ITERATOR<Object> m = m_player->getDefaultTeam()->iterate_TeamMemberList(); !m.done(); m.advance() )
+ {
+ Object *obj = m.cur();
+ AIUpdateInterface *ai = obj->getAI();
+ if( ai == NULL || ai->isRecruitable() || obj->getVeterancyLevel() <= LEVEL_REGULAR || obj->isEffectivelyDead() )
+ continue;
+ const StateID state = ai->getCurrentStateID();
+ if( state == AI_DOCK || state == AI_ENTER || state >= 1000 || ai->isMoving() )
+ continue;
+ ai->setIsRecruitable( TRUE );
}
}
@@ -10451,6 +10482,8 @@ void AIPlayer::doRetreats( void )
if( m_retreatTimer < 1 )
m_retreatTimer = 1;
+ releaseMendedRanked();
+
if( !m_baseCenterSet )
return; // nowhere to fall back to