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(ai): spread china's healer helixes a tower's reach apart

Olcay Seyganf5e0d77b7baf
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 99504eb02..4ee5b4266 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -183,7 +183,7 @@ found and fixed — EA's own, not port damage.**
- And its helicopters carry people. On Hard, infantry waiting for the attack now boards any helicopter with a seat, not only one it can shoot out of, and a helicopter carrying riders who cannot shoot from it puts them down just short of the fight, on the first ground none of your guns it knows about can reach, from where they go on at you on foot. The boarding never worked before this either: a helicopter the plan had put on guard stayed in the air, so the riders walked up to it and turned away. The same Black Lotus was sent to one Helix three times in two minutes. A helicopter now lands for its riders. The capturer flies too: when the building it is after is a long walk away and a helicopter is waiting at home, it gets in, and the helicopter puts it down beside the building. China's attacks are mostly tanks, so its Helixes still leave with one rider more often than five.
- Its infantry rides in its vehicles. The computer's plan tells a group with a Humvee to climb in and, in the same breath, to stand guard, and the guard order won before anyone took a step: over two Hard four-player matches not one soldier boarded anything, Humvee, Battle Bus or helicopter. Now soldiers standing at home climb into their own group's Humvee or Battle Bus on every difficulty, and the group goes wherever its plan sends it with them shooting from inside. Soldiers waiting for the next attack fill any Humvee, Battle Bus or helicopter at home they can shoot out of, an Overlord or Emperor carrying its battle bunker included, and that vehicle leaves with the attack. A soldier who could not shoot from a vehicle never rides in one, except in a helicopter on Hard, which puts him down short of the fight as before. China's attacks on Hard carry no infantry at all, so its Helixes flew off with the waves empty, 14 times over those two matches, though both had bought the bunker by the middle of the match. Medium and Hard now train soldiers for any helicopter seat they could shoot from that stands empty, an attack ready to leave waits up to twenty seconds for them to climb in, and an empty bunkered Helix whose soldiers are still on their way stays behind for the next attack rather than fly off unarmed. The Air Force General on Medium and Hard also buys up to two Combat Chinooks, where it only ever bought the supply Chinook before. They stay off the supply runs and fill with Rangers. On Hard they fly with the attacks, all eight shooting from inside; Medium mostly keeps them at home, loaded. Replays recorded before this change play out differently.
- Its Chinooks fly the army. A USA attack walked the whole road, at the pace of its slowest tank. Medium and Hard now buy plain Chinooks for nothing but lift, more of them the bigger the attack and the longer the road: they load tanks and soldiers at home, put them down on the attack's road short of anything the computer has seen that can shoot, and go home for the next load while the attack is under way. The drop is one a straight flight from the base reaches over quiet ground, after the first version flew seven loaded Chinooks in one match straight at a drop beyond an enemy base and lost every one. A Chinook hit hard on the way puts its load down where it is. Neither these nor the Air Force General's Combat Chinooks go on the supply runs unless nothing else is left to gather and nothing else can be bought, and the Combat Chinook is no longer ever bought as a gatherer.
-- Its Helixes have jobs. Every Helix the computer owned bought its upgrades in button order, so each one carried a battle bunker whatever it was up against, with napalm on top. A Helix in one of its attack or guard groups now looks at what it knows of your army first and takes the gattling cannon when most of your strength is on foot, the bunker when most of it is in vehicles, and the soldiers trained to sit in that bunker are Tank Hunters rather than Red Guards. Against GLA over four Hard matches that came out 15 bunkers to 6 cannons, each decided on the split at that moment. China on Medium and Hard also buys two Helixes as healers, a third once its army passes thirty units, each under a Propaganda Tower. They hang behind the attack over whichever of its units is most hurt, carry nobody, and pull away when they are hit or when anti-air they know of comes near; over twelve Hard matches they spent 93% of their time out of the base further from the nearest enemy gun than it could shoot. Two more Helixes take the napalm bomb, or the Nuke General's nuclear one, and raid your base, a factory first and otherwise whatever pays for it or powers it. A raid comes in from the side your known anti-air does not cover, looks for a new way in when a gun turns up ahead, and turns for home when it is hit below half health. Over the same twelve matches 126 raids went out, 23 dropped their bomb, five buildings fell after a drop, and 31 raiders were shot down on a raid. The Infantry General's Helix has no tower, so it only raids. Replays recorded before this change play out differently.
+- Its Helixes have jobs. Every Helix the computer owned bought its upgrades in button order, so each one carried a battle bunker whatever it was up against, with napalm on top. A Helix in one of its attack or guard groups now looks at what it knows of your army first and takes the gattling cannon when most of your strength is on foot, the bunker when most of it is in vehicles, and the soldiers trained to sit in that bunker are Tank Hunters rather than Red Guards. Against GLA over four Hard matches that came out 15 bunkers to 6 cannons, each decided on the split at that moment. China on Medium and Hard also buys two Helixes as healers, a third once its army passes thirty units, each under a Propaganda Tower. They hang behind the attack over whichever of its units is most hurt, carry nobody, and pull away when they are hit or when anti-air they know of comes near; over twelve Hard matches they spent 93% of their time out of the base further from the nearest enemy gun than it could shoot. They used to bunch up over the same tank, which got nothing out of it: a unit inside two towers heals no faster than inside one. Each healer now keeps its spot at least a tower's reach, 150, from the others', going to the most hurt unit nobody else's tower already covers, or stepping sideways behind the attack until it is clear of theirs. Two more Helixes take the napalm bomb, or the Nuke General's nuclear one, and raid your base, a factory first and otherwise whatever pays for it or powers it. A raid comes in from the side your known anti-air does not cover, looks for a new way in when a gun turns up ahead, and turns for home when it is hit below half health. Over the same twelve matches 126 raids went out, 23 dropped their bomb, five buildings fell after a drop, and 31 raiders were shot down on a raid. The Infantry General's Helix has no tower, so it only raids. Replays recorded before this change play out differently.
- It comes at you from two sides. An attack big enough to be two sends a third of its strength down the second-quietest road, so you cannot meet the whole thing in one place.
- It holds ground between attacks. Hard gathers its next wave a third of the way along the road to you, not in front of its own base, as long as nothing it has seen can shoot at that spot; otherwise it gathers at home.
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
index e86d346f9..7bac9bcf7 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
@@ -8068,6 +8068,10 @@ static const Int MAX_RAIDERS = 2;
static const Real HEALER_PATIENT_HEALTH = 0.9f; ///< a unit below this share of its health is worth hovering over
static const UnsignedInt HEALER_HIT_FRAMES = 3 * LOGICFRAMES_PER_SECOND; ///< a healer hit this recently pulls back
static const UnsignedInt HEALER_REPORT_FRAMES = 60 * LOGICFRAMES_PER_SECOND;
+/** The reach of a Helix's propaganda tower, ChinaHelixPropagandaTower's Radius in retail ChinaAir.ini.
+ * A unit inside two towers heals as fast as inside one (Object::attemptHealingFromSoleBenefactor),
+ * so a healer keeps its spot this far from every other healer's. */
+static const Real HEALER_TOWER_RADIUS = 150.0f;
/** How far past a known gun's reach a Helix keeps, for the gun's own step forward. */
static const Real HELIX_GUN_MARGIN = 80.0f;
@@ -8397,10 +8401,21 @@ Coord3D AIPlayer::rearOf( const Coord3D *from, const std::vector<AIKnownGun> &gu
return spot;
}
+static Bool insideAnotherTower( const std::vector<Coord3D> &taken, Real x, Real y )
+{
+ for( size_t t = 0; t < taken.size(); ++t )
+ if( sqr( taken[ t ].x - x ) + sqr( taken[ t ].y - y ) < sqr( HEALER_TOWER_RADIUS ) )
+ return TRUE;
+ return FALSE;
+}
+
/** A healer goes over the most hurt of ours that stands clear of every known gun, out with the army
* when the army is out; with nobody hurt it hangs behind the middle of whoever is out, at the first
* point toward home no known gun reaches. Hit, or with a known anti-air gun in reach, it pulls back
- * the same way. It carries nobody and is in no wave. */
+ * the same way. It carries nobody and is in no wave.
+ * Healers in lower slots choose first, and a later one leaves alone whatever already stands inside
+ * their towers: it takes the most hurt unit outside them, and its place behind the wave moves
+ * sideways across the way home until it clears them. */
void AIPlayer::steerHealer( Int slot, const std::vector<AIKnownGun> &guns )
{
DutyHelix &duty = m_dutyHelix[ slot ];
@@ -8446,6 +8461,14 @@ void AIPlayer::steerHealer( Int slot, const std::vector<AIKnownGun> &guns )
}
else if( helix->hasUpgrade( tower ) )
{
+ // the spots the healers in lower slots took this pass, the slots being steered in order
+ std::vector<Coord3D> taken;
+ for( Int s = 0; s < slot; ++s )
+ {
+ const DutyHelix &other = m_dutyHelix[ s ];
+ if( other.id != INVALID_ID && other.role == HELIX_HEALER && (other.phase == HEAL_PATIENT || other.phase == HEAL_REAR) )
+ taken.push_back( other.spot );
+ }
std::vector<Object *> owned;
m_player->iterateObjects( collectOwned, &owned );
Object *hurtOut = NULL;
@@ -8470,7 +8493,8 @@ void AIPlayer::steerHealer( Int slot, const std::vector<AIKnownGun> &guns )
}
const BodyModuleInterface *body = obj->getBodyModule();
const Real missing = body->getMaxHealth() - body->getHealth();
- if( body->getHealth() >= HEALER_PATIENT_HEALTH * body->getMaxHealth() || deepestReach( guns, at->x, at->y, FALSE ) >= -HELIX_GUN_MARGIN )
+ if( body->getHealth() >= HEALER_PATIENT_HEALTH * body->getMaxHealth() || deepestReach( guns, at->x, at->y, FALSE ) >= -HELIX_GUN_MARGIN ||
+ insideAnotherTower( taken, at->x, at->y ) )
continue;
if( !home && missing > missingOut )
{
@@ -8495,6 +8519,29 @@ void AIPlayer::steerHealer( Int slot, const std::vector<AIKnownGun> &guns )
middle.x /= out;
middle.y /= out;
spot = rearOf( &middle, guns );
+ // sideways, alternately right and left, by a tower's reach plus the slack a lower slot's spot
+ // keeps before it is re-ordered, so a step always clears the spot it stepped away from
+ const Real dx = m_baseCenter.x - middle.x;
+ const Real dy = m_baseCenter.y - middle.y;
+ const Real length = (Real)sqrt( dx * dx + dy * dy );
+ if( length > 0.0f && insideAnotherTower( taken, spot.x, spot.y ) )
+ {
+ Region3D extent;
+ TheTerrainLogic->getExtent( &extent );
+ for( Int step = 1; step <= 4; ++step )
+ {
+ const Real side = (HEALER_TOWER_RADIUS + HELIX_REORDER_DISTANCE) * ((step + 1) / 2) * ((step & 1) ? 1.0f : -1.0f);
+ const Real x = spot.x - dy / length * side;
+ const Real y = spot.y + dx / length * side;
+ if( x >= extent.lo.x && x <= extent.hi.x && y >= extent.lo.y && y <= extent.hi.y &&
+ !insideAnotherTower( taken, x, y ) && deepestReach( guns, x, y, FALSE ) < -HELIX_GUN_MARGIN )
+ {
+ spot.x = x;
+ spot.y = y;
+ break;
+ }
+ }
+ }
}
}
if( phase == HEAL_HOME && isAtHome( pos ) )