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.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
feat(gameengine): skirmish AI takes derricks and docks in the opening
Olcay Seygan75a7540b21b8
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 13b3e3b09..784dc81cb 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -20,6 +20,7 @@ found and fixed, EA's own, not port damage.**- Money it gets back stays what it was. Selling a building or cancelling a queue returns the same sum as yours does, or a computer could queue and cancel its way to a fortune, and cash from a map's script or from an ally is not doubled either. The money figure floating over a computer's truck or building shows what it really banked.- Your own income does not change, and your cut of a computer ally's income under Share Income is the plain cut. Campaign missions and Generals' Challenge opponents earn what they always did.- Replays recorded before this change play out differently.+- It also goes for that money from the start. A computer used to buy the capture research only once a soldier stood idle at home, and by then its opening had often spent the bank. Now the first barracks trains the soldier and starts the research within five seconds of standing, and he walks to the nearest oil derrick while it runs. The same four-player match on Twilight Flame: Hard's first derrick fell at 2 minutes 20 seconds where it had taken 4 minutes 40, Medium's at 2 minutes 35 against 3 minutes 10, Easy's at 2 minutes 50 against 4 minutes 11. Script teams also stopped recruiting that soldier off a half-captured derrick. During the first six minutes a computer that can expand looks for a new supply dock every 15 seconds instead of every minute and will spend its last dollar on the building, where it used to want twice the price in the bank. Replays recorded before this change play out differently.## Missions keep the time their script wrote@@ -230,7 +231,7 @@ found and fixed, EA's own, not port damage.**- Seven computers against one strong player now count each other. Each used to weigh its own army against all of yours, decide it was outmatched and go on the defensive. When a computer now decides whether to defend, it adds its allies' armies, Hard all of them, Medium three quarters and Easy half, and counts your allies against it the same way. Replays recorded before this change play out differently.- You can call them too. A beacon you place asks your computer allies to attack there, and typing `help`, `attack` or `money` in chat (`yardim`, `saldir`, `para` in Turkish) asks for help where you are looking, an attack there, or cash.- Or without typing a word. Alt+Z asks your allies to attack the spot under the pointer, Alt+X to come and defend it, Alt+V for money, and Alt+C only marks a spot to look at. The pointer can be on the radar as well. People on your team see the smoke, the radar ping and a line in the chat; computer allies with a personality act on it, in a skirmish against the computer too, where the keys used to do nothing. The keys come from the launcher and move on its Hotkeys page like any other.-- A personality is a preference, never a bonus: no personality gets extra money, faster building or tougher units.+- A personality is a preference, never a bonus: every computer earns the same double income, and no personality adds money, faster building or tougher units to it.- Computer players with a personality now and then say something in chat, in their own voice, at most once every two and a half minutes. Normal ones stay quiet.- An Infantry computer player no longer crashes the game while one of its factories researches an upgrade. Shopping for a troop carrier, it read the upgrade in the queue as if it were a vehicle.- The choice travels with the game to every player in a LAN or online match and into the replay. Replays and saves from earlier versions load with every computer player on Normal; a save made with this version does not load in an earlier one.@@ -729,14 +730,14 @@ found and fixed, EA's own, not port damage.**- Anti-air was the computer's oldest hole. It is closed.- The skirmish no longer catches a hitch the first time the computer picks a team. It works out every unit-against-unit matchup on the loading screen now, in about a millisecond.-## Three difficulty levels, and none of them cheat+## Three difficulty levels, and one open advantage- Easy, Medium, Hard, the three the game has always had. There were six for a while, with a rung either side of Medium and one above the top; they are gone again, and nothing above the top went with them - Hard now plays what the top of that six-rung ladder played. For a while the top rung was called Brutal on the seat list; it is Hard again, the name the box always printed.-- Every level plays by your rules. No level gets extra money, cheaper units, faster building, longer vision or tougher units - in either direction. What changes is what the computer is allowed to decide: how often it looks at the map, how long it takes to react, whether it counters what you field, whether it masses before attacking, whether it pulls damaged units out.-- Hard used to break that promise without saying so. EA's skirmish scripts handed a Hard computer four free cash drops as the match went on, 10,000 early (5,000 for the GLA), another 10,000, then 15,000 and 20,000 late: up to 55,000 a game that no truck ever hauled. Every general had them. They are switched off, so Hard's bank is what its trucks and oil derricks bring in. The other grants in those scripts, the ones that pay for its first buildings, are untouched.+- Every computer player earns double what its trucks, derricks and other income would pay you, on all three levels, and that is the only rule bent for it. No level gets cheaper units, faster building, longer vision or tougher units. What changes between levels is what the computer is allowed to decide: how often it looks at the map, how long it takes to react, whether it counters what you field, whether it masses before attacking, whether it pulls damaged units out.+- Hard used to break that promise without saying so. EA's skirmish scripts handed a Hard computer four free cash drops as the match went on, 10,000 early (5,000 for the GLA), another 10,000, then 15,000 and 20,000 late: up to 55,000 a game that no truck ever hauled. Every general had them. They are switched off, so Hard's bank is what its trucks and oil derricks bring in, doubled like every computer's. The other grants in those scripts, the ones that pay for its first buildings, are untouched.- A computer that is losing keeps its base. EA's scripts had every general sell off every building it owned the moment its bank fell under 2,000 with no truck, supply building or oil derrick left, or once its last dozer, command centre and factory were gone. Ten seconds later the whole base turned into cash and the match ended on an empty field instead of a fight. That is switched off for all twelve generals at every level, so you finish a beaten opponent by knocking its buildings down.- Easy looks around and answers late, a little sooner than it used to, and it sends its supply trucks to fit the piles. It never pulls a unit out, never builds against what you field, and stops once the opening base is up. Normal reacts a bit sooner, starts spending once the bank passes 6,000, where it used to wait for 10,000, and answers about half of what you field. A unit that is personally finished still leaves, and it still goes out for a second supply pile. Factories past the opening list stay a Hard behaviour. Hard is the opponent with nothing held back: no reaction delay at all, it builds against what it can see you fielding, it gathers an army before it commits it, and it takes a losing team off the field. Replays recorded before this change play out differently.-- Measured, not asserted: Hard beats Easy 15-0 over 32 headless matches with the seats swapped both ways, on twice the army and twice the spending.+- Measured, not asserted: with both earning double, Hard against Easy over 32 matches on generated maps ends 17 wins for Hard, 5 for Easy and 10 undecided.- The ladder reads as one ladder wherever a seat is listed. Half of it was named in EA's old words - "Easy Army", "Medium Army" - and half in ours, in the same drop-down, because four separate lists answered "what is this seat called" and no two of them agreed. Every one of them says Easy AI, Medium AI, Hard AI now: the lobby, the seat itself, the game info panel and the online browser.- All three are in the network and online lobbies as well as skirmish, and the level the host picks is the level every machine at the table plays. A seat also keeps its name, its colour and its start position when the list refreshes, which it did not.- Making Easy easier means giving it worse decisions, never less money. That is the whole promise.diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cppindex 04c3fa3fc..46cf08c45 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp@@ -223,6 +223,11 @@ static Bool playerStartPosition( Int playerNdx, Coord3D *pos )* order and the base builder has its own rhythm to keep. */static const Int EXPANSION_CHECK_SECONDS = 60;+/** The same during the opening (AI_PURCHASE_EARLY_FRAMES), when money sits in the bank and the docks+ * are free for whoever gets there first: a look a minute left a Hard AI's first expansion of its own+ * waiting behind a check that had already said no. */+static const Int EXPANSION_OPENING_CHECK_SECONDS = 15;+/** How often the scout is looked at. It only ever gets an order when it has arrived, so this is a* check, not a repath. */static const Int SCOUT_CHECK_RATE = 2 * LOGICFRAMES_PER_SECOND;@@ -2039,6 +2044,12 @@ void AIPlayer::onUnitProduced( Object *factory, Object *unit )// a support order the fork's AI put in for a job of its own; EA's AI never has one, and// a unit that came out of anything else must not land in those slotsconst Bool dutyOrder = order->m_isScout && runsOwnAI();+ // the first one out that can take a building is the capturer, whichever job ordered it: left+ // for doCapture's five-second look, the scout or a bunker had it first and the capture started over+ if (dutyOrder && ai && m_capturerID == INVALID_ID && unit->findSpecialPowerModuleInterface( SPECIAL_INFANTRY_CAPTURE_BUILDING )) {+ m_capturerID = unit->getID();+ ai->setIsRecruitable( FALSE );+ }if (ai) {// tell it to start gathering resources.// Here is the special bit for this exit style, force wanting on SupplyTruck types@@ -5935,7 +5946,8 @@ void AIPlayer::doExpansion( void )if( --m_expandTimer > 0 )return;- m_expandTimer = EXPANSION_CHECK_SECONDS * LOGICFRAMES_PER_SECOND;+ const Bool opening = TheGameLogic->getFrame() < AI_PURCHASE_EARLY_FRAMES;+ m_expandTimer = ( opening ? EXPANSION_OPENING_CHECK_SECONDS : EXPANSION_CHECK_SECONDS ) * LOGICFRAMES_PER_SECOND;if( !m_player->getCanBuildBase() || !m_baseCenterSet ){@@ -6000,12 +6012,13 @@ void AIPlayer::doExpansion( void )return;}- // pay for it out of what is spare, not out of the army's money- const Int cost = tmpl->calcCostToBuild( m_player );- if( m_player->getMoney()->countMoney() < 2 * cost )+ // pay for it out of what is spare, not out of the army's money. In the opening there is no army to+ // save for and income comes first: at twice the price 35 of 42 stops in Hard's first three minutes were this+ const Int needs = tmpl->calcCostToBuild( m_player ) * ( opening ? 1 : 2 );+ if( m_player->getMoney()->countMoney() < needs ){DEBUG_LOG(("AI EXPAND frame %d player %d stopped by money, %d in the bank, needs %d\n", TheGameLogic->getFrame(),- m_player->getPlayerIndex(), m_player->getMoney()->countMoney(), 2 * cost));+ m_player->getPlayerIndex(), m_player->getMoney()->countMoney(), needs));return;}@@ -14125,6 +14138,9 @@ void AIPlayer::releaseMended( void )if( ai == NULL || ai->isRecruitable() || obj->isEffectivelyDead() || obj->isContained() ||(obj->getVeterancyLevel() <= LEVEL_REGULAR && !obj->isKindOf( KINDOF_INFANTRY )) )continue;+ // never the capturer: mid-capture it reads as idle, and a script team recruited it off the derrick+ if( obj->getID() == m_capturerID )+ continue;const StateID state = ai->getCurrentStateID();if( state == AI_DOCK || state == AI_ENTER || state >= 1000 || ai->isMoving() )continue;@@ -16964,6 +16980,8 @@ Object *AIPlayer::findCapturer( void )continue;if( obj->findSpecialPowerModuleInterface( SPECIAL_INFANTRY_CAPTURE_BUILDING ) == NULL )continue;+ if( obj->isContained() )+ continue; // a soldier in a bunker stays there, and doCapture waits for its capturer's ride to landBool busy = FALSE;for( Int slot = 0; slot < MAX_AI_SCOUTS; ++slot )@@ -17134,7 +17152,10 @@ void AIPlayer::doCapture( void )m_capturerID = INVALID_ID;capturer = findCapturer();if( capturer )+ {m_capturerID = capturer->getID();+ capturer->getAI()->setIsRecruitable( FALSE );+ }}Coord3D from = m_baseCenter;@@ -17146,14 +17167,34 @@ void AIPlayer::doCapture( void )// derricks behind the base waited on it for minutes, or were never taken.Object *target = nearestTechBuilding( &m_baseCenter, FALSE );- if( capturer == NULL )+ // only pay for one when there is something to spend it on+ if( capturer == NULL && target )+ queueCapturer();++ //+ // The Ranger, the Red Guard and the Rebel all come out of the barracks with the capture paused+ // until the player buys it there, and nothing bought it: the capturer walked up to a derrick and+ // stood on it all match. Buy it (buildUpgrade waits for the money and ignores a repeat) the moment+ // a barracks stands, behind the capturer in that barracks' queue. This used to wait for a capturer+ // standing idle, and the scout took the first one out, so it asked at frame 3615 at the earliest,+ // with the opening's bank spent and the research still to come.+ //+ static const AsciiString captureUpgradeName( "Upgrade_InfantryCaptureBuilding" );+ const UpgradeTemplate *captureUpgrade = TheUpgradeCenter->findUpgrade( captureUpgradeName );+ SpecialPowerModuleInterface *mod = capturer ? capturer->findSpecialPowerModuleInterface( SPECIAL_INFANTRY_CAPTURE_BUILDING ) : NULL;+ if( target && captureUpgrade && (capturer == NULL || (mod && mod->getPercentReady() < 1.0f)) &&+ !m_player->hasUpgradeComplete( captureUpgrade ) ){- // only pay for one when there is something to spend it on- if( target )- queueCapturer();- return;+ const Bool queued = m_player->hasUpgradeInProduction( captureUpgrade );+ buildUpgrade( captureUpgradeName );+ if( !queued && m_player->hasUpgradeInProduction( captureUpgrade ) )+ DEBUG_LOG(("AI CAPTURE frame %d player %d buys the capture upgrade for a '%s' %d\n", TheGameLogic->getFrame(), m_player->getPlayerIndex(),+ target->getTemplate()->getName().str(), target->getID()));}+ if( capturer == NULL )+ return;+// the ride out: a capturer sitting in its helicopter is flown to the building and put down beside itif( capturer->isContained() ){@@ -17203,29 +17244,10 @@ void AIPlayer::doCapture( void )}//- // canCaptureBuilding refuses through the shroud and the capture itself has a range, so a target- // we know about but cannot reach from here is walked to first and asked again next check.- //- SpecialPowerModuleInterface *mod = capturer->findSpecialPowerModuleInterface( SPECIAL_INFANTRY_CAPTURE_BUILDING );-- //- // The Ranger, the Red Guard and the Rebel all come out of the barracks with the capture paused- // until the player buys it there, and nothing bought it: the capturer walked up to a derrick and- // stood on it all match. Buy it (buildUpgrade waits for the money and ignores a repeat) and keep- // the capturer home until it is in.+ // canCaptureBuilding refuses through the shroud, the capture itself has a range and an upgrade not+ // in yet reads as not ready, so a target we know about but cannot take from here is walked to first+ // and asked again next check: the research finishes with the capturer already standing on it.//- static const AsciiString captureUpgradeName( "Upgrade_InfantryCaptureBuilding" );- const UpgradeTemplate *captureUpgrade = TheUpgradeCenter->findUpgrade( captureUpgradeName );- if( mod && captureUpgrade && mod->getPercentReady() < 1.0f && !m_player->hasUpgradeComplete( captureUpgrade ) )- {- const Bool queued = m_player->hasUpgradeInProduction( captureUpgrade );- buildUpgrade( captureUpgradeName );- if( !queued && m_player->hasUpgradeInProduction( captureUpgrade ) )- DEBUG_LOG(("AI CAPTURE frame %d player %d buys the capture upgrade for a '%s' %d\n", TheGameLogic->getFrame(), m_player->getPlayerIndex(),- target->getTemplate()->getName().str(), target->getID()));- return;- }-if( mod && TheActionManager->canCaptureBuilding( capturer, target, CMD_FROM_AI ) ){mod->doSpecialPowerAtObject( target, 0 );