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): challenge and mission ai keep retail tactics

Olcay Seygan06b702105abd
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7560528d4..a6b69c0bf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -189,7 +189,7 @@ found and fixed — EA's own, not port damage.**
- Each gun goes where it sees the most of the way in. The computer used to aim one spot at the enemy's side of the base and, when that was taken, put the gun down wherever it fitted, which on a crowded map meant behind its own factories with nothing to shoot at. Now it looks at nearly a hundred spots around the base and scores each one by the open ground inside the gun's reach that lies between the base and the enemy. Ground hidden behind its own buildings or a cliff counts for nothing, ground at the back of the base counts for very little, and every gun already standing nearby halves the score, so the guns spread along the front instead of piling up on one corner. It only asks the build rules about the best dozen of those spots, and a spot under a building, on unbuildable ground or within reach of the enemy's own base is crossed off first, so the gun usually goes on the first spot it asks about: 296 of 349 did over 72 matches.
- Its guns come as a mix. It used to put up whichever defence came first on the worker's build bar, every time: a Hard USA base put up 22 Patriots for every Fire Base, a GLA one Stinger Sites, and China's own spare-cash guns were bunkers. Now each new gun is the type the base has fewest of, so Patriots and Fire Bases go up in turn, Stinger Sites alternate with Tunnel Networks, and China's Gattling Cannons get bunkers and Speaker Towers beside them. Those two shoot at nothing on their own, so the computer keeps about one of each for every three cannons. A type lost in a raid is the one rebuilt first. Every general's own versions count, and the planned defences its build scripts ask for follow the same rule. Over 48 one-on-one matches between Hard and Normal computers and 24 between two Hards, the same seeds each time, a Hard USA side built 4.9 guns a match where it built 2.4, 1.6 of them Fire Bases where it built 0.1. China went from 4.0 to 9.9 and GLA from 4.9 to 6.9. Hard won 29 of those 48 matches against Normal, where it won 25. Replays recorded before this change play out differently.
- Hard builds its superweapon as soon as it can pay for one and has the guns to stand it on, and then another. Its scripts held the first one back behind a clock that ran for twelve and a half minutes, seven and a half if you had built your own tech building first, and then allowed exactly one: a player who took on seven Hard computers at once saw a single nuke all match. There is no clock now. The tech building that unlocks it goes up first, and the superweapon follows once the money is in the bank and twelve of its guns stand finished, a rule only the computer plays by (see the lobby section). More follow as the base grows, one for every twelve guns, so a computer holding twenty-four guns can stand two superweapons. The numbers below were measured when four guns were enough. With twelve, a one-on-one between computers rarely lasts long enough: over 96 Hard sides in the same 72 matches, 11 had a superweapon up with four guns and 7 with twelve, the first at 5.4 minutes and most between 8 and 9. Before that rule it put its first particle cannon up at 4.3 minutes on Twilight Flame and its first nuke at 4.9, without a gun to its name. Over 24 matches between two Hard computers on the same map, the first nuke now goes up at 6.2 minutes as a rule, anywhere from 4.4 to 9.8, and the first Particle Cannon at 7.4. The Scud Storm comes last at 7.6 but never later than 8.7, and every GLA side had one inside ten minutes, where 4 of the 32 China and USA sides were still waiting for theirs. The lobby's superweapon limit and Pro Rules still apply to the computer exactly as they do to you.
-- Everything in this section is the skirmish computer's, and Generals Challenge and mission opponents play by their own scripts again. In 2.8.0 they ran the skirmish economy on top of those scripts. A Challenge general on Hard is handed $30,000 with $5,000 more on the way, so General Kwai bought three nuclear silos about a minute into the match, along with power plants, expansions and factories his mission never asked for, all built faster for the money in his bank. Now Kwai puts up one silo, and only after you build a superweapon of your own.
+- Everything in this section is the skirmish computer's, and Generals Challenge and mission opponents play exactly as EA scripted them again. In 2.8.0 they ran the skirmish computer's whole playbook on top of those scripts. A Challenge general on Hard is handed $30,000 with $5,000 more on the way, so General Kwai bought three nuclear silos about a minute into the match, along with power plants, expansions and factories his mission never asked for, all built faster for the money in his bank, and in a fight he pulled hurt units out and repositioned the rest the way a skirmish opponent does. Now Kwai puts up one silo, and only after you build a superweapon of your own, and his tanks come when his script sends them.
- Hard trains more builders when it has work for them. It only ever made a new dozer after losing all of them, so it played every match on the two it had, and every building it bought queued behind those two. On Twilight Flame a third of the China Tank computers never got round to a war factory, never sent an attack, and ended up sitting in a ring of bunkers on a pile of cash. Now, with money in the bank and every dozer busy, it trains another, up to four. Over six four-player matches on that map, every computer built its war factories, the attack waves went from 39 to 82, and each one spent half as much again.
- Hard no longer rebuilds its factories inside your base. A busy computer puts its next war factory beside its newest expansion, and it remembered that expansion forever: after you destroyed the supply centre there, even one it had built right next to your base, it kept putting the factory back up on the same spot. It now only builds beside an expansion it still holds, and only one nearer its own base than yours.
- Hard keeps its lights on. It asked for a new power plant before running out, and the request then sat in a queue behind everything else its plan wanted: one China waited 95 seconds for a plant with 26,000 in the bank, every builder busy, and went dark halfway. A plant now jumps that queue once the margin is thin, a busy builder is taken off whatever it is doing to put it up, and while the base is dark the computer buys nothing else. Over eight four-player matches the time its bases spent without power fell by a third, from 42 minutes to 28 across all of them.
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
index d6bd72de3..d7bbba587 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
@@ -3054,7 +3054,8 @@ Bool AIPlayer::selectTeamToBuild( void )
const AIDifficultyProfile *profile = getSkillProfile();
AIEnemyComposition enemy;
std::vector<AIVisibleEnemy> army;
- if (profile->m_counterCompositionWeight > 0.0f)
+ const Bool skirmish = isSkirmishAI(); // a Challenge or mission opponent picks by priority alone, as EA's did
+ if (skirmish && profile->m_counterCompositionWeight > 0.0f)
computeEnemyComposition( &enemy, &army );
// what a perfect counter, and the role preference, are worth in units of production priority
@@ -3067,7 +3068,7 @@ Bool AIPlayer::selectTeamToBuild( void )
const Real DOMINANT_SHARE = 0.3f;
const Real HARD_COUNTERED = 0.25f;
std::vector<AIVisibleEnemy> dominant;
- if( profile->m_answerArmy && enemy.m_totalThreat > 0.0f )
+ if( skirmish && profile->m_answerArmy && enemy.m_totalThreat > 0.0f )
{
size_t top = 0;
for( size_t k = 1; k < army.size(); ++k )
@@ -3087,10 +3088,13 @@ Bool AIPlayer::selectTeamToBuild( void )
const Bool isDefenceTeam = info->m_isBaseDefense || info->m_isPerimeterDefense;
Real score = INT_TO_REAL( info->m_productionPriority );
- score += profile->m_counterCompositionWeight * COUNTER_SPAN *
- aiCounterScore( enemy, teamCapability( *t, m_player, army ) );
- if( (m_role == AIROLE_DEFENSIVE) == (isDefenceTeam != FALSE) )
- score += ROLE_SPAN;
+ if( skirmish )
+ {
+ score += profile->m_counterCompositionWeight * COUNTER_SPAN *
+ aiCounterScore( enemy, teamCapability( *t, m_player, army ) );
+ if( (m_role == AIROLE_DEFENSIVE) == (isDefenceTeam != FALSE) )
+ score += ROLE_SPAN;
+ }
if( !dominant.empty() && !isDefenceTeam && teamCapability( *t, m_player, dominant ).m_answer < HARD_COUNTERED )
score -= COUNTER_SPAN;
@@ -4681,7 +4685,7 @@ void AIPlayer::doUpgradesAndSkills( void )
case 3: skillset = &sideInfo->m_skillSet4; break;
case 4: skillset = &sideInfo->m_skillSet5; break;
}
- const Bool saves = getSkillProfile()->m_savesSciencePoints;
+ const Bool saves = isSkirmishAI() && getSkillProfile()->m_savesSciencePoints;
Int i;
for (i=0; i<skillset->m_numSkills; i++) {
ScienceType science = skillset->m_skills[i];
@@ -4800,28 +4804,30 @@ void AIPlayer::update( void )
AI_PHASE( AIP_TEAM, doTeamBuilding() ); // See if it's time to start another team.
AI_PHASE( AIP_UPGRADE, doUpgradesAndSkills() ); // See if it's time to build an upgrade or buy a skill.
AI_PHASE( AIP_BRIDGE, updateBridgeRepair() ); // Handle any bridge repairs.
- AI_PHASE( AIP_SCOUT, doScouting() ); // Keep one unit looking at the map.
- AI_PHASE( AIP_RETREAT, doRetreats() ); // Break off the fights we are losing.
- // The economy is the skirmish AI's own. A Challenge or mission opponent is handed its money, its
- // base and its superweapon by the map script, which is the whole of its difficulty: run on top of
- // that, Kwai's $30000 stood three nuclear silos a minute into the match.
- const Bool ownEconomy = isSkirmishAI();
- if( ownEconomy ) AI_PHASE( AIP_EXPAND, doExpansion() ); // Go and take the money that is lying around.
- if( ownEconomy ) AI_PHASE( AIP_CAPTURE, doCapture() ); // ... and the money that is standing around.
- AI_PHASE( AIP_CAPTURE, doHijack() ); // Take the enemy's tanks rather than shoot them.
- if( ownEconomy ) AI_PHASE( AIP_ECONOMY, doEconomy() ); // ... and the money sitting in the bank.
- AI_PHASE( AIP_ECONOMY, doSpending() ); // Upgrades for the army, and whatever is over the bank target.
- if( ownEconomy ) AI_PHASE( AIP_POWER, doPower() ); // Keep the lights on, and out of reach.
- if( ownEconomy ) AI_PHASE( AIP_ECONOMY, doSuperweapons() ); // The big guns, as soon as they can be bought.
- AI_PHASE( AIP_WAVE, rememberEnemies() ); // Write down the enemy army in sight.
- AI_PHASE( AIP_WAVE, answerArmy() ); // Train the answer to the part of it nothing answers.
- AI_PHASE( AIP_WAVE, doMass() ); // Build the fist, and send it when it is one.
- AI_PHASE( AIP_WAVE, doWaves() ); // Send the parked attack teams out together.
- AI_PHASE( AIP_TACTICS, doTactics() ); // Fight each unit from where it is strongest.
- AI_PHASE( AIP_TACTICS, doTransports() ); // Put the helicopters' riders down at the fight.
- AI_PHASE( AIP_TACTICS, doShuttles() ); // Fly the wave's ground units up its road.
- AI_PHASE( AIP_TACTICS, doHelixes() ); // Helix upgrades by the enemy army, healers, bomb raids.
- AI_PHASE( AIP_TACTICS, doAmbulances() ); // Ambulances behind the army, for the hurt and the hazards.
+ // Everything below is the skirmish AI's own. A Challenge or mission opponent is handed its money,
+ // its base, its attacks and its superweapon by the map script, which is the whole of its difficulty:
+ // run on top of that, Kwai's $30000 stood three nuclear silos a minute into the match.
+ if( isSkirmishAI() )
+ {
+ AI_PHASE( AIP_SCOUT, doScouting() ); // Keep one unit looking at the map.
+ AI_PHASE( AIP_RETREAT, doRetreats() ); // Break off the fights we are losing.
+ AI_PHASE( AIP_EXPAND, doExpansion() ); // Go and take the money that is lying around.
+ AI_PHASE( AIP_CAPTURE, doCapture() ); // ... and the money that is standing around.
+ AI_PHASE( AIP_CAPTURE, doHijack() ); // Take the enemy's tanks rather than shoot them.
+ AI_PHASE( AIP_ECONOMY, doEconomy() ); // ... and the money sitting in the bank.
+ AI_PHASE( AIP_ECONOMY, doSpending() ); // Upgrades for the army, and whatever is over the bank target.
+ AI_PHASE( AIP_POWER, doPower() ); // Keep the lights on, and out of reach.
+ AI_PHASE( AIP_ECONOMY, doSuperweapons() ); // The big guns, as soon as they can be bought.
+ AI_PHASE( AIP_WAVE, rememberEnemies() ); // Write down the enemy army in sight.
+ AI_PHASE( AIP_WAVE, answerArmy() ); // Train the answer to the part of it nothing answers.
+ AI_PHASE( AIP_WAVE, doMass() ); // Build the fist, and send it when it is one.
+ AI_PHASE( AIP_WAVE, doWaves() ); // Send the parked attack teams out together.
+ AI_PHASE( AIP_TACTICS, doTactics() ); // Fight each unit from where it is strongest.
+ AI_PHASE( AIP_TACTICS, doTransports() ); // Put the helicopters' riders down at the fight.
+ AI_PHASE( AIP_TACTICS, doShuttles() ); // Fly the wave's ground units up its road.
+ AI_PHASE( AIP_TACTICS, doHelixes() ); // Helix upgrades by the enemy army, healers, bomb raids.
+ AI_PHASE( AIP_TACTICS, doAmbulances() ); // Ambulances behind the army, for the hurt and the hazards.
+ }
#ifdef DEBUG_LOGGING
Int64 playerEnd;
@@ -6556,7 +6562,7 @@ Bool AIPlayer::placeNear( const ThingTemplate *tmpl, const Coord3D *center, Real
//----------------------------------------------------------------------------------------------------------
AsciiString AIPlayer::chooseApproachLabel( const Coord3D *from, const AsciiString &requested, Int pathSuffix )
{
- if( !getSkillProfile()->m_useInfluenceMapForAttackLane || from == NULL )
+ if( !isSkirmishAI() || !getSkillProfile()->m_useInfluenceMapForAttackLane || from == NULL )
return requested;
const Int LANE_COUNT = 3;
@@ -6592,7 +6598,7 @@ AsciiString AIPlayer::chooseApproachLabel( const Coord3D *from, const AsciiStrin
//----------------------------------------------------------------------------------------------------------
AsciiString AIPlayer::secondApproachLabel( const Coord3D *from, const AsciiString &taken, Int pathSuffix )
{
- if( !getSkillProfile()->m_useInfluenceMapForAttackLane )
+ if( !isSkirmishAI() || !getSkillProfile()->m_useInfluenceMapForAttackLane )
return AsciiString::TheEmptyString;
const Int LANE_COUNT = 3;