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
fix(gameengine): send idle ai defenders out and unstick capturers
Olcay Seygan7df440feaa15
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a6355e8e5..abf097a9d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -123,6 +123,7 @@ found and fixed — EA's own, not port damage.**- 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 reads the odds before it attacks. Every attack was sized the same way whoever it was aimed at, so a computer with an army at home went on waiting for a full wave while the enemy across the map had nothing left to fight with. It now weighs its own army against what it has seen of yours, and an army it cannot see it assumes is growing back towards the size of its own. It has to be looking at your buildings before it believes it is ahead. Ahead by about two to one with your base in view, Hard stops waiting and sends each group as it forms. Ahead by about six to one, the computer on any difficulty sends the guards it used to keep at home for the whole match hunting as well, half a minute apart. Outnumbered two to one, Hard and Medium keep their groups at home until twice the usual wave has gathered, and a handful is never sent into an army that size. Two leaks went with it. Units that reached the end of their road into your base used to stop there and wait for something to shoot at them; they now go looking. A group that got reinforcements at home was ordered out again as a whole, which marched the half already fighting in your base back to the middle of the map to start the walk over. Only the ones at home leave now. Over sixteen Hard against Hard matches on Twilight Flame stopped at seventeen minutes, the five that finished took 12 minutes 26 seconds on average where they had taken 13 minutes 55. The other eleven still ran to the stop: the side that is ahead kills units faster than buildings, and a defender with 120,000 in the bank replaces them at its own door. Replays recorded before this change play out differently.- Hard stops piling its army up at home. Its plan only sends an attack group while the signal for the next wave is up, and only a group standing in the base at that moment. A group finished a minute later guarded the base until the signal came round again, and one that fell back from a lost fight guarded it for good: one GLA stood 38 of its Angry Mob by its own buildings with 70,000 in the bank. China's Dragon Tank group never left at all, because the attack order its plan names for it is missing from EA's file. Now any attack group standing idle at home joins the next wave. Rich computers also stopped building extra copies of the groups that only ever guard, four sets of tunnel guards where the plan asked for one. Over eight Hard matches on Twilight Flame, the units standing idle at home late in the match went from 43 to 17, the waves sent went from 134 to 319, and kills went up by a tenth. Replays recorded before this change play out differently.+- The defenders it trains in a hurry go on to fight. Units a Hard computer bought while its base was being hit belonged to no attack group, so once that fight was over they stood wherever it had left them for the rest of the match. They now leave with the next attack, and any of them stuck out on the map goes hunting. An infantryman sent to take an oil derrick or a tech building could also stop halfway and stand frozen at the door for minutes on end; he finishes the job now. Over sixteen Hard matches on Twilight Flame, the computer's fighting units that had not moved or fired for half a minute went from 5.9 a side to 3.6, and it sent 1,155 attack waves where it had sent 1,079. Replays recorded before this change play out differently.- It puts more harvesters on a supply centre with more piles around it, instead of the same three numbers everywhere.- USA's Chinooks stop collecting over the command center. When the pile beside a supply centre ran out, its Chinooks flew home and hovered, and the computer went on buying new ones for its other centres while those sat idle. It only looked for an idle gatherer when a pile stood right next to the centre, a fraction of how far a Chinook looks. An idle gatherer is now sent to any of its supply centres with a pile inside that gatherer's own range, and nothing new is bought while one stands idle beside a pile that has no room for it.- 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.diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.hindex d630b0bc2..677d86413 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h@@ -352,6 +352,7 @@ protected:void buyGunshipChinook(void); ///< Medium and up buy a supply-center transport the riders shoot out of, as a gunshipBool isGunshipRider(const Object *obj) const; ///< infantry loadGunships may put in a transportvoid sendIdleAttackTeams(void); ///< attack teams standing at home join the next wave instead of waiting for the script's signal+ Real addHomeStrays(AIGroup *wave) const; ///< the default team's fighters idle at home go with the waveReal knownFirepowerNear(const Coord3D *pos); ///< what this AI has seen that can shoot, near a pointBool forwardHoldPoint(const AsciiString &approach, Int pathSuffix, const Coord3D *enemyPos, Coord3D *hold); ///< where a wave gathers on its roadvoid sendWave(AIGroup *wave, const AsciiString &approach, Int pathSuffix, Int teams, Real power, UnsignedInt heldFrames);diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cppindex 620587177..51b195606 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp@@ -6548,6 +6548,9 @@ Bool AIPlayer::leavesToFinish( const Object *obj ) constif( aiCombatPower( obj ) <= 0.0f || !obj->isAbleToAttack() || obj->isKindOf( KINDOF_STRUCTURE ) || obj->isKindOf( KINDOF_HARVESTER ) ||obj->isKindOf( KINDOF_DOZER ) || obj->isKindOf( KINDOF_MONEY_HACKER ) )return FALSE;+ // a slave goes where its master goes: a Stinger Site's crew is in the default team, and unselectable+ if( obj->testStatus( OBJECT_STATUS_UNSELECTABLE ) )+ return FALSE;if( obj->isKindOf( KINDOF_AIRCRAFT ) && !isHelicopter( obj ) )return FALSE;const ObjectID id = obj->getID();@@ -6717,6 +6720,7 @@ void AIPlayer::doWaves( void )if( team )waitingPower( team, wave );}+ power += addHomeStrays( wave );/* The helicopters at home go too. A player watched China build helicopters and never send them:the skirmish scripts put the Comanches and the Helixes into guard teams, and across eight@@ -7286,6 +7290,31 @@ void AIPlayer::sendIdleAttackTeams( void )}}+//----------------------------------------------------------------------------------------------------------+/** The default team's fighters standing idle at home join the wave, and what they add to it. defendHome+ * trains its emergency defenders into that team, and no script ever gives it an order: once the fight+ * at home was over they stood where it had left them, for the rest of the match. Sixteen Hard matches+ * on Twilight Flame, looked at every thirty seconds, found 2.4 of them a side standing still for half a+ * minute or more, the largest of the idle piles; with this and the hunt in sendIdleUnitsHunting, 0.4. */+//----------------------------------------------------------------------------------------------------------+Real AIPlayer::addHomeStrays( AIGroup *wave ) const+{+ Real power = 0.0f;+ for( DLINK_ITERATOR<Object> m = m_player->getDefaultTeam()->iterate_TeamMemberList(); !m.done(); m.advance() )+ {+ Object *obj = m.cur();+ if( obj->isEffectivelyDead() || obj->getAI() == NULL || obj->isContained() || obj->isKindOf( KINDOF_IMMOBILE ) ||+ !isAtHome( obj->getPosition() ) || !leavesToFinish( obj ) )+ continue;+ const StateID state = obj->getAI()->getCurrentStateID();+ if( state != AI_IDLE && state != AI_GUARD && state != AI_GUARD_RETALIATE )+ continue;+ power += aiCombatPower( obj );+ wave->add( obj );+ }+ return power;+}+//----------------------------------------------------------------------------------------------------------/** Sixteen Hard matches on Twilight Flame had a side four to one ahead and calling its enemy finished* for up to 40% of the match without winning it. One of them, a USA with 46,625 of army against a@@ -7316,7 +7345,10 @@ void AIPlayer::sendIdleUnitsHunting( void )for( Player::PlayerTeamList::const_iterator t = m_player->getPlayerTeams()->begin(); t != m_player->getPlayerTeams()->end(); ++t ){const TeamTemplateInfo *info = (*t)->getTemplateInfo();- const Bool attacks = !info->m_isBaseDefense && !info->m_isPerimeterDefense && aiTeamAttacks( info );+ // the default team's fighters away from home hunt too: no script ever sends them anywhere. At home+ // they leave with the next wave (addHomeStrays), or with the guards when the guards go+ const Bool attacks = ((*t) == m_player->getDefaultTeam()->getPrototype() && !guardsGo) ||+ (!info->m_isBaseDefense && !info->m_isPerimeterDefense && aiTeamAttacks( info ));if( !attacks && !guardsGo )continue;for( DLINK_ITERATOR<Team> iter = (*t)->iterate_TeamInstanceList(); !iter.done(); iter.advance() )diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpecialAbilityUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpecialAbilityUpdate.cppindex a13850f3e..193c52623 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpecialAbilityUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpecialAbilityUpdate.cpp@@ -233,7 +233,11 @@ UpdateSleepTime SpecialAbilityUpdate::update( void )onExit( false );return calcSleepTime();}- if( abilityBrokenByMovement( ai->isMoving(), isPowerCurrentlyInUse(), ai->isTurningToFace() ) )+ // AI_BUSY is the ability's own pack and unpack, and only this module ends it; any order that walks the+ // unit away replaces it first. isMoving() can still read true in it, and a capture broken there left+ // its rifleman busy and standing still for the rest of the match: 0.4 of them a side at every look+ // over 16 Hard matches, a median of three minutes each+ if( abilityBrokenByMovement( ai->isMoving(), isPowerCurrentlyInUse(), ai->isTurningToFace() || ai->getCurrentStateID() == AI_BUSY ) ){// Capture is broken by movement just as if we had been given a direct command (above check).// However, the time of Facing the target is considered isPowerCurrentlyInUse, but isMoving. So let that slide.