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): cap the computer player's hackers at six

Olcay Seygan38460d081fdc
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6b4325a0d..d15591998 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -64,7 +64,7 @@ found and fixed — EA's own, not port damage.**
- It no longer sits on a pile of cash. Past a level that depends on the difficulty, the more money it has the faster it builds - twice the pile, half the wait, and it stops at four times. It is spending sooner, not building faster: the rate itself is untouched.
- A full bank buys a bigger army. Late in a match the computer's plan allows one of each attack group, so once they were all on the map it only replaced its losses and banked the rest: a Hard USA sat on 117,000 on Twilight Flame. Now every 8,000 in the bank on Hard allows one more copy of each attack group, up to four of them.
-- Hard builds past its plan. When every war factory, barracks or airfield it owns is busy it puts down another, beside its newest expansion so the army comes out nearer the fighting. Buildings that pay out on a timer, supply drop zones and black markets, go up one after another as soon as the bank is past a small cushion, whatever else it is buying; they used to wait until production had nothing to ask for, which on a busy map was never, and over twelve four-player matches the count went from 5 to 95. China trains a hacker from every barracks that has room in its queue, not one barracks at a time: 120 hackers across those matches became 375. A hacker left standing still is put to work.
+- Hard builds past its plan. When every war factory, barracks or airfield it owns is busy it puts down another, beside its newest expansion so the army comes out nearer the fighting. Buildings that pay out on a timer, supply drop zones and black markets, go up one after another as soon as the bank is past a small cushion, whatever else it is buying; they used to wait until production had nothing to ask for, which on a busy map was never, and over twelve four-player matches the count went from 5 to 95. China trains a hacker from every barracks that has room in its queue, not one barracks at a time: 120 hackers across those matches became 375. A hacker left standing still is put to work. It stops at six, an internet center's four plus a couple, because nothing counted them before: a Hard Tank General trained 67 over twenty thousand frames, about two thirds of everything it spent, and every one of them went through the barracks queue its army was waiting in. A player watching it from the other side of the map said China's tank general builds nothing but infantry, and he was right. Seven now, and the teams at the top of its build list are tanks.
- Hard picks its road into your base. Of the three approaches it takes the one with the fewest guns it has seen along it, and keeps to the one its plan named until it has scouted something. Aiming at your money instead was tried first and walked it straight past your army.
- Hard sends its attack groups out together. A group too small to be a wave on its own waits on the near side of its base until about seven tanks' worth has gathered, or a minute and a half has passed, and then everything waiting leaves on one road at the pace of its slowest unit. A lone artillery piece or a single bomb truck used to drive across the map by itself, and nearly a third of Hard's units died with barely anyone of their own nearby.
- It puts more harvesters on a supply centre with more piles around it, instead of the same three numbers everywhere.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h
index 0070a5037..8c89a04b5 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h
@@ -325,6 +325,8 @@ protected:
void buildAsap(const ThingTemplate *tmpl); ///< the plan's own unbuilt entry if it has one, otherwise a new spot behind the base
void buyMoneyUnits(void);
+ Int countMoneyUnits(void) const; ///< money units of this player's that are still standing
+ Bool hasEnoughMoneyUnitsFor(TeamPrototype *proto) const; ///< this team is all hackers and the cap is reached
Bool placeNear(const ThingTemplate *tmpl, const Coord3D *center, Real innerRadius); ///< a legal, safe spot on a ring round center, queued for a dozer
Real knownFirepowerAlongPath(Waypoint *way); ///< what this AI has seen that can shoot, along an approach
AsciiString secondApproachLabel(const Coord3D *from, const AsciiString &taken, Int pathSuffix); ///< the quietest other road, or empty
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
index 52d67b9cc..bf0636eb0 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
@@ -1925,12 +1925,62 @@ Bool AIPlayer::isPossibleToBuildTeam( TeamPrototype *proto, Bool requireIdleFact
/** Check if this team is buildable, doesn't exceed maximum limits, meets conditions,
* and isn't under construction. */
// ------------------------------------------------------------------------------------------------
+/** How many money units are worth owning. An internet center holds four, and one working outside
+ it earns the same, so a couple over that covers a center being rebuilt. Everything past this is
+ a barracks slot the army wanted and 625 that did not buy a tank. */
+static const Int MAX_MONEY_UNITS = 6;
+
+static void countMoneyUnit( Object *obj, void *userData )
+{
+ if( obj->isKindOf( KINDOF_MONEY_HACKER ) && !obj->isEffectivelyDead() )
+ (*(Int *)userData)++;
+}
+
+/** How many money units this player has standing, dead ones excluded. Counted rather than tracked:
+ a hacker dies, is captured, or walks into a transport, and a running tally would drift. */
+Int AIPlayer::countMoneyUnits( void ) const
+{
+ Int count = 0;
+ m_player->iterateObjects( countMoneyUnit, &count );
+ return count;
+}
+
+/** Is every unit this team asks for a money unit? The shipped skirmish scripts give China's hacker
+ team a production priority of 1000, which no other team can be scored above, so once it is
+ buildable it wins every selection it is offered - fifteen of thirty-five on seed 11. */
+static Bool isMoneyUnitTeam( const TeamPrototype *proto )
+{
+ const TeamTemplateInfo *info = proto->getTemplateInfo();
+ Int named = 0;
+ for( Int i = 0; i < info->m_numUnitsInfo; ++i )
+ {
+ const ThingTemplate *unit = TheThingFactory->findTemplate( info->m_unitsInfo[ i ].unitThingName, FALSE );
+ if( unit == NULL )
+ continue; // a map's team naming a unit this game does not have
+ if( !unit->isKindOf( KINDOF_MONEY_HACKER ) )
+ return FALSE;
+ ++named;
+ }
+ return named > 0;
+}
+
+/** A team of nothing but hackers spends against the same cap the direct purchase does, or the two
+ of them together bury a barracks under money units all match. */
+Bool AIPlayer::hasEnoughMoneyUnitsFor( TeamPrototype *proto ) const
+{
+ return isMoneyUnitTeam( proto ) && countMoneyUnits() >= MAX_MONEY_UNITS;
+}
+
Bool AIPlayer::isAGoodIdeaToBuildTeam( TeamPrototype *proto )
{
// Check condition.
if (!proto->evaluateProductionCondition()) {
return false;
}
+
+ if (hasEnoughMoneyUnitsFor(proto)) {
+ return false;
+ }
// check build limit
if (proto->countTeamInstances() >= proto->getTemplateInfo()->m_maxInstances){
if (TheGlobalData->m_debugAI) {
@@ -4429,6 +4479,7 @@ static void findInternetCenterWithRoom( Object *obj, void *userData )
/** How near the quiet spot a hacker has to be before it sits down there. */
static const Real HACK_SPOT_RADIUS = 120.0f;
+
/** A hacker standing about is income nobody switched on. It used to switch on wherever it stood,
* which was the barracks' rally point, and a player watched China's hackers sit down at the front of
* its base and get shot. */
@@ -4903,11 +4954,21 @@ void AIPlayer::doSuperweapons( void )
/** A money unit from every factory that trains one and has at most one thing in its queue. An
* idle-only rule measured as two hackers in a whole match, because a barracks feeding the army is
* never idle; one slot behind the army's unit is a delay the army does not notice. It used to be
- * one factory a pass; the owner's call is that a Hard China never falls behind on hackers. */
+ * one factory a pass; the owner's call is that a Hard China never falls behind on hackers.
+ *
+ * With a cap, because nothing counted them. A Hard Tank General trained 67 of them over 20,000
+ * frames on seed 11, about two thirds of everything it spent, and a player watching it from the
+ * other side of the map reported that China's tank general builds nothing but infantry. A hacker
+ * earns only while it is sitting still and working, an internet center holds four, and past a
+ * handful the next one is a rifleman with no rifle standing in a barracks queue the army wants. */
//----------------------------------------------------------------------------------------------------------
void AIPlayer::buyMoneyUnits( void )
{
const Int MAX_QUEUED_AHEAD = 1;
+ Int owned = countMoneyUnits();
+ if( owned >= MAX_MONEY_UNITS )
+ return;
+
for( BuildListInfo *info = m_player->getBuildList(); info; info = info->getNext() )
{
Object *factory = TheGameLogic->findObjectByID( info->getObjectID() );
@@ -4918,8 +4979,13 @@ void AIPlayer::buyMoneyUnits( void )
continue;
const ThingTemplate *moneyUnit = buildableOfKind( factory, GUI_COMMAND_UNIT_BUILD, KINDOF_MONEY_HACKER );
if( moneyUnit && pu->queueCreateUnit( moneyUnit, pu->requestUniqueUnitID() ) )
- DEBUG_LOG(("AI ECONOMY frame %d player %d trains '%s', %d in the bank\n", TheGameLogic->getFrame(),
- m_player->getPlayerIndex(), moneyUnit->getName().str(), m_player->getMoney()->countMoney()));
+ {
+ DEBUG_LOG(("AI ECONOMY frame %d player %d trains '%s', %d in the bank, %d money units\n",
+ TheGameLogic->getFrame(), m_player->getPlayerIndex(), moneyUnit->getName().str(),
+ m_player->getMoney()->countMoney(), owned + 1));
+ if( ++owned >= MAX_MONEY_UNITS )
+ return;
+ }
}
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp
index 7dfe1805a..8f7eec66d 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp
@@ -396,6 +396,10 @@ Bool AISkirmishPlayer::isAGoodIdeaToBuildTeam( TeamPrototype *proto )
if (!proto->evaluateProductionCondition()) {
return false;
}
+
+ if (hasEnoughMoneyUnitsFor(proto)) {
+ return false;
+ }
// check build limit, which a hoard raises for attack teams; defence teams keep the data's
const TeamTemplateInfo *info = proto->getTemplateInfo();
Int allowedInstances = info->m_maxInstances;