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): hard ai trains another dozer when every one is building

Olcay Seygan6650a872899c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e70850c15..0bb1bbadb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -82,6 +82,7 @@ found and fixed — EA's own, not port damage.**
- It keeps its lights on, and keeps them out of reach. Its plan carries a fixed number of power plants and nothing ever adds one, so a raid that took two of them left the base underpowered - radar dark, base defences off, superweapon clock stopped - until a rebuild timer came round and put the new plant back on the spot the raid already knew the way to. It now buys a plant when the margin gets thin rather than when the meter reads zero, and puts it on the far side of the base from whoever it is fighting.
- Spare cash also buys a gun on the side the trouble comes from. Production and income go up around the middle of the base, the power goes behind it, and base defences go out in front, so money that keeps arriving thickens the base in the order a base wants to be thick in. Front means towards the nearest enemy, which is not the same as the one it has decided to attack - that one can be across the map, and a wall built facing it has its back to the neighbour. The walls grow with the army. One gun every minute and a half, never more than ten, used to be the rule; now the computer may stand one gun for every four fighting units it has, so a big army comes home to a fortress and a beaten one rebuilds its tanks before its bunkers. Letting it buy guns on every pass instead was tried first: 241 guns over twelve four-player matches, and they ate the army, down to 60 kills a match from 73. Tied to the army, 71 guns, and the army is the biggest of any version tried, 78 kills a match.
- Hard builds its superweapon as soon as it can pay for one, 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 the moment the money is in the bank; on Twilight Flame the first particle cannon was up at 4.3 minutes and the first nuke at 4.9. More follow as the base grows, one for every four guns defending it, so a computer holding twenty guns can stand six superweapons; over twelve four-player matches that came to about three each. The lobby's superweapon limit and Pro Rules still apply to the computer exactly as they do to you.
+- 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.
- Its hackers work from home. A hacker set to work wherever it stood, which was the barracks' rally point, so China's income sat at the front of its base. It now goes into an Internet Center with room, or walks to the quiet side of the base first.
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
index ec470a7df..20e6466dc 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
@@ -4492,6 +4492,9 @@ static const Real DEFENSE_STANDOFF = 1.0f;
static const Int ARMY_PER_DEFENSE = 4;
static const Int DEFENSES_PER_SUPERWEAPON = 4;
+/** Dozers a Hard AI trains on its own when every one it has is on a building. */
+static const Int MAX_ECONOMY_DOZERS = 4;
+
/** Tries on each ring when looking for somewhere to put a purchase down. Every try is a legality
* check that costs about a millisecond, so this bounds the spike rather than the search. */
static const Int PLACEMENT_ANGLES = 12;
@@ -4640,6 +4643,23 @@ static void findAnyDozer( Object *obj, void *userData )
*dozer = obj;
}
+struct DozerTally
+{
+ Int dozers;
+ Int building;
+};
+
+static void tallyDozer( Object *obj, void *userData )
+{
+ DozerTally *tally = (DozerTally *)userData;
+ if( !obj->isKindOf( KINDOF_DOZER ) || obj->isEffectivelyDead() || obj->getAI() == NULL )
+ return;
+ ++tally->dozers;
+ DozerAIInterface *dozerAI = obj->getAI()->getDozerAIInterface();
+ if( dozerAI && dozerAI->isTaskPending( DOZER_TASK_BUILD ) )
+ ++tally->building;
+}
+
/** A purchase of this kind is already on the build list and waiting for a dozer. Asked per template
* rather than for the whole list: the script's own plan keeps seven to twenty priority entries
* waiting through most of a match, and a global "wait for the last one" never let anything through. */
@@ -4878,6 +4898,16 @@ void AIPlayer::doEconomy( void )
if( !m_player->getCanBuildBase() || !m_baseCenterSet )
return;
+ /* Base building only ever asked for a dozer when it had none, so a Hard AI played the whole match
+ on two, and everything bought below waited in one line for them: nine base-building passes in
+ ten found both on a job. Four China Tank AIs on Twilight Flame, seeds 7 to 9, free-for-all and
+ 2v2, 18,000 frames: 8 of the 24 never put up a war factory and never attacked. With this, none,
+ 39 attack waves became 82, and each spent 67,000 instead of 45,000. */
+ DozerTally dozers = { 0, 0 };
+ m_player->iterateObjects( tallyDozer, &dozers );
+ if( dozers.dozers > 0 && dozers.building == dozers.dozers && dozers.dozers < MAX_ECONOMY_DOZERS )
+ queueDozer();
+
// any dozer will do to read the buttons from: an idle one is what builds it, and that is later
Object *dozer = NULL;
m_player->iterateObjects( findAnyDozer, &dozer );