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(gameengine): size the computer's hackers by army and seats

Olcay Seyganf4d028e610d0
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 10c8dcc0e..d7693f3dc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -75,7 +75,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. 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 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. The limit grows with the match: one hacker for every four fighting units, never more than its Internet Centers have seats for plus four working outside, and never fewer than four. A computer that has not built an army does not buy an economy instead, and one with a full Internet Center and ninety units behind it keeps eight.
- 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 f9bc21bb4..9dc5620d7 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h
@@ -333,8 +333,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
+ Int moneyUnitRoom(void) const; ///< how many more money units this player's army and internet centers carry
+ Bool hasEnoughMoneyUnitsFor(TeamPrototype *proto) const; ///< this team is all hackers and there is no room for more
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 4ef3ac67f..33e815727 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
@@ -2051,26 +2051,6 @@ 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. */
@@ -2090,11 +2070,11 @@ static Bool isMoneyUnitTeam( const TeamPrototype *proto )
return named > 0;
}
-/** A team of nothing but hackers spends against the same cap the direct purchase does, or the two
+/** A team of nothing but hackers spends against the same room 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;
+ return isMoneyUnitTeam( proto ) && moneyUnitRoom() <= 0;
}
Bool AIPlayer::isAGoodIdeaToBuildTeam( TeamPrototype *proto )
@@ -4751,6 +4731,45 @@ static BaseTally tallyBase( Player *player )
return tally;
}
+/** Money units that earn in the open: what a player owns before an internet center stands, and what
+ it keeps beside the centers it has. */
+static const Int MONEY_UNITS_IN_THE_OPEN = 4;
+
+/** Fighting units for every money unit past that. The hackers share the barracks queue with the
+ infantry, and a Hard Tank General with no ratio spent two thirds of 20,000 frames on them. */
+static const Int ARMY_PER_MONEY_UNIT = 4;
+
+/** The money units a player has standing, and the seats its finished internet centers hold for them.
+ Counted rather than tracked: a hacker dies, is captured, or walks into a transport, and a running
+ tally would drift. */
+struct MoneyUnitTally
+{
+ Int owned;
+ Int seats;
+};
+
+static void tallyMoneyUnit( Object *obj, void *userData )
+{
+ MoneyUnitTally *tally = (MoneyUnitTally *)userData;
+ if( obj->isEffectivelyDead() )
+ return;
+ if( obj->isKindOf( KINDOF_MONEY_HACKER ) )
+ ++tally->owned;
+ else if( obj->isKindOf( KINDOF_FS_INTERNET_CENTER ) && !obj->testStatus( OBJECT_STATUS_UNDER_CONSTRUCTION ) )
+ tally->seats += obj->getContain()->getContainMax();
+}
+
+/** Room grows with the army, so an AI that cannot field one does not buy an economy instead, and a
+ late-game bank with forty tanks behind it buys ten. The seats bound it: past the centers' seats
+ plus the few in the open, a hacker is one more target sitting in the base. */
+Int AIPlayer::moneyUnitRoom( void ) const
+{
+ MoneyUnitTally money = { 0, 0 };
+ m_player->iterateObjects( tallyMoneyUnit, &money );
+ const Int byArmy = max( MONEY_UNITS_IN_THE_OPEN, tallyBase( m_player ).army / ARMY_PER_MONEY_UNIT );
+ return min( byArmy, money.seats + MONEY_UNITS_IN_THE_OPEN ) - money.owned;
+}
+
//----------------------------------------------------------------------------------------------------------
/** Which way the trouble comes from, as a unit vector out of this base: towards the nearest enemy,
* at the best address this player has for him.
@@ -5286,17 +5305,15 @@ void AIPlayer::doSuperweapons( void )
* 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.
*
- * 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. */
+ * Within moneyUnitRoom, 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. */
//----------------------------------------------------------------------------------------------------------
void AIPlayer::buyMoneyUnits( void )
{
const Int MAX_QUEUED_AHEAD = 1;
- Int owned = countMoneyUnits();
- if( owned >= MAX_MONEY_UNITS )
+ Int room = moneyUnitRoom();
+ if( room <= 0 )
return;
for( BuildListInfo *info = m_player->getBuildList(); info; info = info->getNext() )
@@ -5310,10 +5327,10 @@ void AIPlayer::buyMoneyUnits( void )
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, %d money units\n",
+ DEBUG_LOG(("AI ECONOMY frame %d player %d trains '%s', %d in the bank, room for %d more\n",
TheGameLogic->getFrame(), m_player->getPlayerIndex(), moneyUnit->getName().str(),
- m_player->getMoney()->countMoney(), owned + 1));
- if( ++owned >= MAX_MONEY_UNITS )
+ m_player->getMoney()->countMoney(), room - 1));
+ if( --room <= 0 )
return;
}
}