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): ai map gate reads only what every machine shares
Olcay Seygan31fa02fc5519
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c8ccdf95f..9264e2dbf 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -497,7 +497,7 @@ found and fixed, EA's own, not port damage.**- Nor does it know which start position you took. It used to read that straight off the lobby, for every player, from the first second. Now it works it out: each position it has not looked at is a suspect, and the odds are simply how many opponents are still unaccounted for over how many places they could be - three of you on an eight-position map is 3 in 7 for each. Every empty position its scout crosses off makes the rest likelier, 3 in 6, then 3 in 5. When the numbers meet, it stops looking: three opponents with three places left to be is not a guess, and walking over to confirm it would waste the trip. On a two-player map that is true from the start, so nothing changed there - it never wastes a second hunting for an address it can work out by subtraction. Where it has not worked you out yet, it attacks the position you are most likely to be on, and finds out on arrival.- Nor does it read your base off the map. Where your base is, what it is worth, which supply dock to expand to and where to aim a superweapon all came off a walk of your object list, in the shroud, from the first second of the match. The computer now only counts what it can see, plus the buildings it has already found - buildings do not walk away. Before it has scouted you, all it knows is where you started, which is on the map preview anyway.- A map that scripts its own computer player, the way Art of Defense maps script their GLA waves, gets that player back. All of the above ran on top of the map's script and pulled the waves off their routes: on AOD Super V the GLA sent 13 bunches of wave units off hunting on their own in one Easy match of 30,000 frames, and it could start a base of its own beside them. Now it plays the map's script and nothing else, as it did in the original game, on every difficulty. Official and random maps leave their computer players to the game's own scripts and play exactly as before.-- Everything in this section now plays on the official maps and the random ones only, in skirmish and in LAN and online rooms with computer seats. A map you downloaded or made yourself gets Zero Hour's own computer opponent back, the one its maker built and tested the map against: EA's scripts as they shipped, EA's build pace, EA's choice of enemy and its sight of the whole map, no personality whatever the lobby says. Campaign missions and the Generals' Challenge already had it and keep it. On a copy of Tournament Desert dropped into the Maps folder, two Hard computers now play 24,000 steps without one of the 20 attack waves and 39 economy moves they make on the shipped Tournament Desert with the same seed, and both replays play back to the same world. A replay recorded on a custom map before this change plays back differently.+- Everything in this section now plays on the official maps and the random ones only, in skirmish and in LAN and online rooms with computer seats. A map you downloaded or made yourself gets Zero Hour's own computer opponent back, the one its maker built and tested the map against: EA's scripts as they shipped, EA's build pace, EA's choice of enemy and its sight of the whole map, no personality whatever the lobby says. Campaign missions and the Generals' Challenge had most of it already, and now get the rest: their computer units see into the fog again as EA's did, shell oil derricks, and leave salvage crates alone, so a mission plays out differently from the last build (the second GLA mission ends its first 6,500 steps on a different world). Missions record no replays, as in EA's game, so none break. Official and random maps keep every computer player as it was, the civilians included. On a copy of Tournament Desert dropped into the Maps folder, two Hard computers now play 24,000 steps without one of the 20 attack waves and 39 economy moves they make on the shipped Tournament Desert with the same seed, and both replays play back to the same world. A replay recorded on a custom map before this change plays back differently.## Superweapons that go where the damage isdiff --git a/GeneralsMD/Code/GameEngine/Include/Common/Player.h b/GeneralsMD/Code/GameEngine/Include/Common/Player.hindex 3791137b1..ff8012a64 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/Player.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/Player.h@@ -617,6 +617,7 @@ public:/// Is this player a skirmish ai player?Bool isSkirmishAIPlayer( void );Bool aiRunsOwnAI( void ) const; ///< a computer player on the fork's AI (AIPlayer::runsOwnAI); FALSE for a human and for EA's AI+ Bool isForkMapComputer( void ) const; ///< any computer player, the civilians included, in a match on a map the fork's AI plays (SidesList::forkAIMap)/// Have the ai check for bridges.virtual Bool checkBridges(Object *unit, Waypoint *way);diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cppindex 4cf615c17..fc3f6b96f 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp@@ -1292,6 +1292,12 @@ Bool Player::aiRunsOwnAI( void ) constreturn m_ai != NULL && m_ai->runsOwnAI();}+//-------------------------------------------------------------------------------------------------+Bool Player::isForkMapComputer( void ) const+{+ return m_playerType == PLAYER_COMPUTER && TheSidesList != NULL && TheSidesList->forkAIMap();+}+//----------------------------------------------------------------------------------------------------------/**diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cppindex 335eb7245..344a830a9 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp@@ -1485,9 +1485,13 @@ void GameState::friend_xferSaveDataForCRC( Xfer *xfer, SnapshotType which )gameInfo->description.clear();gameInfo->saveFileType = SAVE_FILE_TYPE_NORMAL;gameInfo->missionMapName.clear();+ // cleared for the CRC's sake and put back after: a loaded save still needs to know the map it+ // was started on (SidesList::isForkAIMapPath), and the next save writes it out again+ const AsciiString pristine = gameInfo->pristineMapName;gameInfo->pristineMapName.clear();xferSaveData(xfer, which);+ gameInfo->pristineMapName = pristine;}// ------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/SidesList.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/SidesList.cppindex 80198c77a..ae105a798 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/SidesList.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/SidesList.cpp@@ -703,12 +703,32 @@ SidesInfo *SidesList::findSkirmishSideNamed(const AsciiString& side, Int mod, Tepath = TheGameState->getPristineMapName();if (path.isEmpty())return false;- // the generator's maps sit in the player's own Maps folder, but the game made them- if (isGeneratedMapPath(path))++ // The generator's maps sit in the player's own Maps folder, but the game made them. Told by the+ // leaf name alone ("rmg_v17_..."), the way the lobby and the replay carry it: isGeneratedMapPath+ // also checks a template's CRC against this machine's copy of it, a local file.+ const char *back = path.reverseFind('\\');+ const char *forward = path.reverseFind('/');+ const char *sep = (forward != NULL && (back == NULL || forward > back)) ? forward : back;+ AsciiString leaf = sep ? sep + 1 : path.str();+ leaf.toLower();+ Int version = 0, seed = 0, players = 0, cells = 0;+ if (sscanf(leaf.str(), "rmg_v%d_%d_%dp_%dc", &version, &seed, &players, &cells) == 4 &&+ version == RANDOM_MAP_GENERATOR_VERSION)return true;- // "maps\..." is the game's folder and its archives, "userdata\maps\..." the player's: the same- // portable name the lobby sends and the replay records, so every machine reads the same answer- return TheGameState && TheGameState->realMapPathToPortableMapPath(path).startsWithNoCase("maps\\");++ // The player's own Maps folder first: with no user data folder it would be "Maps" itself, the+ // game's, and nothing tells the two apart, so the game's wins as it does for the lobby. Then the+ // game's folder and its archives. Anything else (a save's copy with no pristine name) is not ours.+ const AsciiString userData = TheGlobalData->getPath_UserData();+ if (!userData.isEmpty())+ {+ AsciiString userMaps = userData;+ userMaps.concat("Maps\\");+ if (path.startsWithNoCase(userMaps.str()))+ return false;+ }+ return path.startsWithNoCase("maps\\") || path.startsWithNoCase("maps/");}void SidesList::prepareForMP_or_Skirmish(void)@@ -759,12 +779,14 @@ void SidesList::prepareForMP_or_Skirmish(void)if (!gotScripts) {AsciiString path = "data\\Scripts\\SkirmishScripts.scb";// A player's own map gets EA's scripts as EA shipped them: the fork's file carries its own- // openings and its Hard without the free cash. A -mod brings its own skirmish AI and keeps it.- // ponytail: any -mod keeps the resolved file, even one that ships no .scb; check the mod's- // archives for one if that ever matters.- // (GlobalData::computeExeCRC hashes this file too, under the same name)+ // openings and its Hard without the free cash. A -mod that ships its own SkirmishScripts.scb+ // keeps it, since that is the file that resolves; a mod with none (art only) changes nothing.+ // Either way the exe CRC hashes the resolved file and this one (GlobalData::computeExeCRC), so+ // two machines that disagree here never share a match.const char *retail = "data\\Scripts\\SkirmishScriptsRetail.scb";- if (!m_forkAIMap && TheGlobalData->m_mods.empty() && TheFileSystem->doesFileExist(retail))+ Bool inModArchive = FALSE;+ const Bool modScripts = TheFileSystem->modLooseFile(path, &inModArchive).isNotEmpty() || inModArchive;+ if (!m_forkAIMap && !modScripts && TheFileSystem->doesFileExist(retail))path = retail;DEBUG_LOG(("Skirmish map using standard scripts %s: fork AI %s, map %s\n", path.str(),m_forkAIMap ? "on" : "off", TheGlobalData->m_mapName.str()));diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cppindex a043a1ee6..a3aac3b03 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp@@ -6057,7 +6057,7 @@ Bool PartitionFilterPossibleToAttack::allow(Object *objOther)// picking its own target, so an explicit order to level one still goes through, and a tech// building that shoots back is still shot back at.//- if (m_obj->getControllingPlayer() && m_obj->getControllingPlayer()->aiRunsOwnAI() &&+ if (m_obj->getControllingPlayer() && m_obj->getControllingPlayer()->isForkMapComputer() &&aiIsIncomeNotATarget(objOther->isKindOf(KINDOF_TECH_BUILDING),objOther->isKindOf(KINDOF_CAPTURABLE),objOther->isKindOf(KINDOF_TECH_BASE_DEFENSE)))diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cppindex c26c32c57..5c486da1c 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp@@ -7079,11 +7079,12 @@ Object* AIUpdateInterface::getNextMoodTarget( Bool calledByAI, Bool calledDuring// members and base defence turrets all route through here - so the exemption covered every one// of them. The AI now sees what a player sees, which is also what makes stealth work against it.//- // A computer player on EA's AI (a mission, a Challenge, a player's own map) keeps EA's exemption:- // those maps and their scripts were made for an opponent whose units see into the fog.+ // A computer player in a mission, a Challenge or on a player's own map keeps EA's exemption:+ // those maps and their scripts were made for an opponent whose units see into the fog. On an+ // official or random map every computer player, the civilians too, plays by the rule above.const Player *controller = obj->getControllingPlayer();if( controller && ( beyondVision ||- ( calledByAI && ( controller->getPlayerType() == PLAYER_HUMAN || controller->aiRunsOwnAI() ) ) ) )+ ( calledByAI && ( controller->getPlayerType() == PLAYER_HUMAN || controller->isForkMapComputer() ) ) ) ){flags |= AI::UNFOGGED;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cppindex 12a36f71a..4b3f670a6 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp@@ -4757,8 +4757,9 @@ static void salvageCrateTick( void )if( owner == NULL || crate->getShroudedStatus( owner->getPlayerIndex() ) >= OBJECTSHROUD_FOGGED )continue;// a human's units go where the human sends them; only the computer's are sent for salvage,- // and only on the fork's AI: EA's never went for a crate on its own- if( owner->getPlayerType() != PLAYER_COMPUTER || !owner->aiRunsOwnAI() )+ // and only on an official or random map: in a mission, a Challenge or on a player's own map+ // the computer plays EA's game, which never went for a crate on its own+ if( !owner->isForkMapComputer() )continue;const Bool upgrades = wantsSalvageUpgrade( them );