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
perf(gameengine): fill the ai matchup tables on the loading screen
Olcay Seyganb0f0797623ff
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 3c5ff2736..f8a8f4322 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -273,6 +273,7 @@ found and fixed — EA's own, not port damage.**- Now the priority is the start of a score, not the whole of it. What it can *see* you fielding weights the choice, and the weighing is the game's own arithmetic: for every unit it could build and every unit it sees you with, how many shots each needs to kill the other through its armour, how long it waits between them, and what each one costs. A Crusader shell does a tenth of its damage to a rifleman, so your Rebels get Gattlings and your Overlords get Tank Hunters, not whatever the script listed first. Stealth still pushes detectors up. It reads the same unit data the game fights with, so a mod's units are weighed correctly too.- How much that weighs depends on the level: nothing on Easy, which is what the game always did, about half on Normal, and the full weight on Hard.- 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 cheatdiff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.hindex e64bbe288..c6f3ee3ad 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h@@ -181,6 +181,11 @@ public:static void resetFrameProfile( void );static const char *getProfileReport( void );+ /** Empty the unit-against-unit tables from the last match and, when a skirmish AI plays this one,+ * fill them for every unit the sides in it can build, so the first team choice does not pay for+ * them mid-match. Called by GameLogic::startNewGame once the map's INI and the players are in. */+ static void prepareMatchupTables( void );+/** Base building is the expensive job once the expansion convoy is out of the way, and it is a* loop over the build list that calls several searches per entry. These name which one.* AISkirmishPlayer overrides processBaseBuilding, so both copies are instrumented and thediff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cppindex 82365ab84..413d90bb2 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp@@ -301,8 +301,9 @@ static Int64 theAIBaseSubStart;templateFramesToKill). selectTeamToBuild asks it for every unit of every candidate team againstevery kind of enemy in sight, both ways round, and each answer walks module names, weapon sets andarmour: an eight-player match spent 84ms of one frame there. Nothing it reads changes during a- match, so the answer is kept. The destructor empties it, because the next match can free a template- and hand its address to another. */+ match, so the answer is kept. prepareMatchupTables empties it at the start of every match, because+ the next match can free a template and hand its address to another, and fills it on the loading+ screen when a skirmish AI is playing. */typedef std::pair<const ThingTemplate *, const ThingTemplate *> AITemplatePair;static std::map<AITemplatePair, Real> theFramesToKillCache;// the two questions under it that walk a template's module list by name, kept the same way: the first@@ -485,9 +486,6 @@ m_role(AIROLE_AGGRESSIVE)AIPlayer::~AIPlayer(){clearTeamsInQueue();- theFramesToKillCache.clear();- theMaxHealthCache.clear();- theDetectsStealthCache.clear();}// ------------------------------------------------------------------------------------------------@@ -2657,6 +2655,51 @@ static Real templateFramesToKill( const ThingTemplate *attacker, const ThingTempreturn frames;}+/*static*/ void AIPlayer::prepareMatchupTables( void )+{+ theFramesToKillCache.clear();+ theMaxHealthCache.clear();+ theDetectsStealthCache.clear();++ Bool skirmishAI = FALSE;+ std::vector<AsciiString> sides;+ for( Int i = 0; i < ThePlayerList->getPlayerCount(); ++i )+ {+ Player *player = ThePlayerList->getNthPlayer( i );+ if( player->isSkirmishAIPlayer() )+ skirmishAI = TRUE;+ if( std::find( sides.begin(), sides.end(), player->getSide() ) == sides.end() )+ sides.push_back( player->getSide() );+ }+ if( !skirmishAI )+ return;++#ifdef DEBUG_LOGGING+ const Int64 start = Clock_Ticks();+#endif+ // ponytail: units only, the ones a side in the match can buy; a captured or scripted unit, a+ // defence, an override from map.ini is still answered the first time it is asked+ std::vector<const ThingTemplate *> units;+ for( const ThingTemplate *tmpl = TheThingFactory->firstTemplate(); tmpl; tmpl = tmpl->friend_getNextTemplate() )+ {+ if( tmpl->friend_getBuildCost() <= 0 || tmpl->isKindOf( KINDOF_STRUCTURE ) || tmpl->getBuildable() == BSTATUS_NO )+ continue;+ if( std::find( sides.begin(), sides.end(), tmpl->getDefaultOwningSide() ) != sides.end() )+ units.push_back( tmpl );+ }+ for( size_t a = 0; a < units.size(); ++a )+ {+ templateDetectsStealth( units[ a ] );+ for( size_t t = 0; t < units.size(); ++t )+ templateFramesToKill( units[ a ], units[ t ] );+ }+#ifdef DEBUG_LOGGING+ const Int64 end = Clock_Ticks();+ DEBUG_LOG(( "AI MATCHUP PREFILL %d units, %d pairs, %.1fms\n", (Int)units.size(),+ (Int)theFramesToKillCache.size(), aiPlayerElapsedMS( start, end ) ));+#endif+}+//-------------------------------------------------------------------------------------------------/** Count one visible enemy unit into the army: one entry per kind of unit, in the order first seen. *///-------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cppindex eb92714da..ac05a9a79 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp@@ -1592,7 +1592,10 @@ void GameLogic::startNewGame( Bool loadingSaveGame )TheTeamFactory->reset();ThePlayerList->newGame();- // update the loadscreen+ // the AI's unit-against-unit tables, here on the loading screen rather than at its first team choice+ AIPlayer::prepareMatchupTables();++ // update the loadscreenupdateLoadProgress(LOAD_PROGRESS_POST_PLAYER_LIST_RESET);// Tell the script engine that a newe set of scripts is loaded.