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(gamelogic): idle hackers enter a nearby internet center or hack
Olcay Seygan101ea0bc13f2
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 34f8b533a..60d666d90 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1133,6 +1133,7 @@ A third pass went through the generals' powers, promotions and unit abilities.- Workers leave other players' supply piles alone. A truck whose pile ran dry went to the nearest pile it could reach, and that was often the one next to a neighbour's supply centre, where it either stood in his queue or stood idle beside the pile with nowhere of its own to carry the boxes. A pile now belongs to whoever has the closest supply centre beside it, and your trucks, Chinooks and workers only pick their own or a free one. The computer counts those piles out too, so it no longer buys trucks for a neighbour's supplies. Across two 4v4 matches on Twilight Flame, trucks were sent to someone else's pile 109 times; now none are, and the money mined stayed within about one percent. A truck you send to a pile yourself still goes where you sent it.- The white bar over a building's health bar means one of two things: a factory working through its queue, or a superweapon charging. Oil derricks, the black market, supply drop zones, hackers and workers carried one too, each on a money clock nobody can hurry, and a base full of them buried the two bars worth reading. They wear only their health bar now.- A hacker already at work stays at work when you tell a group of hackers to hack. It used to fold its laptop away and set it up again, and the payout it was halfway to started over from nothing. One that is packing up takes the order and unpacks again. Replays recorded before this change play out differently.+- A hacker you leave standing goes to work by itself. After ten seconds with no order it walks into your nearest Internet Center with a free seat, if one is close by, or else opens its laptop where it stands. Any order you give starts the ten seconds over. The computer's hackers already did this. Replays recorded before this change play out differently.- A hacker working from inside an Internet Center shows what it earns. The green figure floats over the building on every payout, the way it does over one sitting in the field. It never appeared, because the game asked the hacker whether it could be seen and a garrisoned unit is not drawn at all - which is the one place a hacker is meant to work.- Factories take a hundred units in the queue, not nine. The build queue only ever had nine buttons and that had become the limit.- A match can pay everyone a wage. `MoneyPerMinute` in `GameData.ini` drops the same sum into everydiff --git a/GeneralsMD/Code/BuildFingerprint.manifest b/GeneralsMD/Code/BuildFingerprint.manifestindex 544aace7b..7ec239483 100644--- a/GeneralsMD/Code/BuildFingerprint.manifest+++ b/GeneralsMD/Code/BuildFingerprint.manifest@@ -830,6 +830,7 @@ GameEngine/Include/GameLogic/Module/HighlanderBody.hGameEngine/Include/GameLogic/Module/HijackerUpdate.hGameEngine/Include/GameLogic/Module/HiveStructureBody.hGameEngine/Include/GameLogic/Module/HordeUpdate.h+GameEngine/Include/GameLogic/Module/IdleHackerUpdate.hGameEngine/Include/GameLogic/Module/ImmortalBody.hGameEngine/Include/GameLogic/Module/InactiveBody.hGameEngine/Include/GameLogic/Module/InstantDeathBehavior.h@@ -1553,6 +1554,7 @@ GameEngine/Source/GameLogic/Object/Update/HeightDieUpdate.cppGameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cppGameEngine/Source/GameLogic/Object/Update/HijackerUpdate.cppGameEngine/Source/GameLogic/Object/Update/HordeUpdate.cpp+GameEngine/Source/GameLogic/Object/Update/IdleHackerUpdate.cppGameEngine/Source/GameLogic/Object/Update/JammerUpdate.cppGameEngine/Source/GameLogic/Object/Update/LaserUpdate.cppGameEngine/Source/GameLogic/Object/Update/LifetimeUpdate.cppdiff --git a/GeneralsMD/Code/Data/INI/BalanceReforged.ini b/GeneralsMD/Code/Data/INI/BalanceReforged.iniindex 012f4eb1e..fde62f6c0 100644--- a/GeneralsMD/Code/Data/INI/BalanceReforged.ini+++ b/GeneralsMD/Code/Data/INI/BalanceReforged.ini@@ -2582,6 +2582,58 @@ Object GLAJetCargoPlaneEndEnd+; ---- a player's idle hacker goes to work -------------------------------------------------------+;+; A hacker left standing ten seconds goes into the nearest own Internet Center with a seat within+; 150, or else starts hacking where it stands. Any order starts the ten seconds over. The computer+; already does this for its own (AIPlayer's putToHacking), so the module skips every non-human+; player.++Object ChinaInfantryHacker+ AddModule+ Behavior = IdleHackerUpdate ModuleTag_IdleHacker+ IdleTime = 10000+ CenterRange = 150.0+ End+ End+End++Object Tank_ChinaInfantryHacker+ AddModule+ Behavior = IdleHackerUpdate ModuleTag_IdleHacker+ IdleTime = 10000+ CenterRange = 150.0+ End+ End+End++Object Infa_ChinaInfantryHacker+ AddModule+ Behavior = IdleHackerUpdate ModuleTag_IdleHacker+ IdleTime = 10000+ CenterRange = 150.0+ End+ End+End++Object Nuke_ChinaInfantryHacker+ AddModule+ Behavior = IdleHackerUpdate ModuleTag_IdleHacker+ IdleTime = 10000+ CenterRange = 150.0+ End+ End+End++Object Boss_InfantryHacker+ AddModule+ Behavior = IdleHackerUpdate ModuleTag_IdleHacker+ IdleTime = 10000+ CenterRange = 150.0+ End+ End+End+Object ChinaJetCarpetBomberReplaceModule ModuleTag_12Behavior = JetSlowDeathBehavior ModuleTag_12_Crashdiff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/IdleHackerUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/IdleHackerUpdate.hnew file mode 100644index 000000000..178b3fb29--- /dev/null+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/IdleHackerUpdate.h@@ -0,0 +1,69 @@+/*+** Command & Conquer Generals Zero Hour(tm)+** Copyright 2025 Electronic Arts Inc.+**+** This program is free software: you can redistribute it and/or modify+** it under the terms of the GNU General Public License as published by+** the Free Software Foundation, either version 3 of the License, or+** (at your option) any later version.+**+** This program is distributed in the hope that it will be useful,+** but WITHOUT ANY WARRANTY; without even the implied warranty of+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+** GNU General Public License for more details.+**+** You should have received a copy of the GNU General Public License+** along with this program. If not, see <http://www.gnu.org/licenses/>.+*/++// FILE: IdleHackerUpdate.h //////////////////////////////////////////////////////////////////////+//+// A human player's hacker left standing for IdleTime goes into the nearest own Internet Center with+// a free seat within CenterRange, or else starts hacking where it stands. Any order resets the+// clock, since it leaves the hacker busy for at least one frame. The computer's hackers are put to+// work by AIPlayer (putToHacking), so this one leaves them alone.+//+///////////////////////////////////////////////////////////////////////////////////////////////////++#pragma once++#ifndef __IDLE_HACKER_UPDATE_H_+#define __IDLE_HACKER_UPDATE_H_++#include "GameLogic/Module/UpdateModule.h"++//-------------------------------------------------------------------------------------------------+class IdleHackerUpdateModuleData : public UpdateModuleData+{+public:++ UnsignedInt m_idleFrames;+ Real m_centerRange;++ IdleHackerUpdateModuleData();++ static void buildFieldParse( MultiIniFieldParse& p );+};++//-------------------------------------------------------------------------------------------------+class IdleHackerUpdate : public UpdateModule+{++ MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( IdleHackerUpdate, "IdleHackerUpdate" )+ MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( IdleHackerUpdate, IdleHackerUpdateModuleData );++public:++ IdleHackerUpdate( Thing *thing, const ModuleData* moduleData );+ // virtual destructor prototype provided by memory pool declaration++ virtual UpdateSleepTime update();++private:++ Object *findInternetCenter();++ UnsignedInt m_idleSinceFrame; ///< the frame the hacker was last seen busy, contained or not the player's+};++#endif // __IDLE_HACKER_UPDATE_H_diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/MemoryInit.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/MemoryInit.cppindex 3850a913f..bf3b0f410 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/MemoryInit.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/MemoryInit.cpp@@ -402,6 +402,7 @@ static PoolSizeRec sizes[] ={ "SpyVisionSpecialPower", 256, 32 },{ "StealthDetectorUpdate", 256, 32 },{ "JammerUpdate", 32, 32 },+ { "IdleHackerUpdate", 64, 32 },{ "StealthUpdate", 512, 128 },{ "StealthUpgrade", 256, 32 },{ "StatusBitsUpgrade", 128, 128 },diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ModuleFactory.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ModuleFactory.cppindex ced33c31e..491c87c5d 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ModuleFactory.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ModuleFactory.cpp@@ -171,6 +171,7 @@#include "GameLogic/Module/MissileLauncherBuildingUpdate.h"#include "GameLogic/Module/StealthDetectorUpdate.h"#include "GameLogic/Module/JammerUpdate.h"+#include "GameLogic/Module/IdleHackerUpdate.h"#include "GameLogic/Module/StealthUpdate.h"#include "GameLogic/Module/SpawnPointProductionExitUpdate.h"#include "GameLogic/Module/SpawnBehavior.h"@@ -398,6 +399,7 @@ void ModuleFactory::init( void )addModule( BaseRegenerateUpdate );addModule( StealthDetectorUpdate );addModule( JammerUpdate );+ addModule( IdleHackerUpdate );addModule( StealthUpdate );addModule( DeletionUpdate );addModule( SmartBombTargetHomingUpdate );diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/IdleHackerUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/IdleHackerUpdate.cppnew file mode 100644index 000000000..f951373b7--- /dev/null+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/IdleHackerUpdate.cpp@@ -0,0 +1,152 @@+/*+** Command & Conquer Generals Zero Hour(tm)+** Copyright 2025 Electronic Arts Inc.+**+** This program is free software: you can redistribute it and/or modify+** it under the terms of the GNU General Public License as published by+** the Free Software Foundation, either version 3 of the License, or+** (at your option) any later version.+**+** This program is distributed in the hope that it will be useful,+** but WITHOUT ANY WARRANTY; without even the implied warranty of+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+** GNU General Public License for more details.+**+** You should have received a copy of the GNU General Public License+** along with this program. If not, see <http://www.gnu.org/licenses/>.+*/++// FILE: IdleHackerUpdate.cpp ////////////////////////////////////////////////////////////////////+//+// A hacker standing about is income nobody switched on. The computer's own hackers have been put to+// work since AIPlayer's putToHacking; a player's stood where he left them until he remembered.+//+///////////////////////////////////////////////////////////////////////////////////////////////////++#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine++#include "Common/Player.h"+#include "Common/Xfer.h"+#include "GameLogic/GameLogic.h"+#include "GameLogic/Object.h"+#include "GameLogic/ObjectIter.h"+#include "GameLogic/PartitionManager.h"+#include "GameLogic/Module/AIUpdate.h"+#include "GameLogic/Module/ContainModule.h"+#include "GameLogic/Module/IdleHackerUpdate.h"++//-------------------------------------------------------------------------------------------------+IdleHackerUpdateModuleData::IdleHackerUpdateModuleData()+{+ m_idleFrames = 10 * LOGICFRAMES_PER_SECOND;+ m_centerRange = 150.0f;+}++//-------------------------------------------------------------------------------------------------+/*static*/ void IdleHackerUpdateModuleData::buildFieldParse( MultiIniFieldParse& p )+{+ UpdateModuleData::buildFieldParse( p );++ static const FieldParse dataFieldParse[] =+ {+ { "IdleTime", INI::parseDurationUnsignedInt, NULL, offsetof( IdleHackerUpdateModuleData, m_idleFrames ) },+ { "CenterRange", INI::parseReal, NULL, offsetof( IdleHackerUpdateModuleData, m_centerRange ) },+ { 0, 0, 0, 0 }+ };+ p.add( dataFieldParse );+}++//-------------------------------------------------------------------------------------------------+IdleHackerUpdate::IdleHackerUpdate( Thing *thing, const ModuleData* moduleData ) : UpdateModule( thing, moduleData )+{+ m_idleSinceFrame = TheGameLogic->getFrame();+}++//-------------------------------------------------------------------------------------------------+IdleHackerUpdate::~IdleHackerUpdate( void )+{+}++//-------------------------------------------------------------------------------------------------+/** The nearest of the owner's finished Internet Centers in range that has a seat for this hacker,+ * ties to the lower id so every machine picks the same one. */+Object *IdleHackerUpdate::findInternetCenter()+{+ Object *me = getObject();+ ObjectIterator *iter = ThePartitionManager->iterateObjectsInRange( me, getIdleHackerUpdateModuleData()->m_centerRange, FROM_CENTER_2D );+ MemoryPoolObjectHolder hold( iter );++ Object *best = NULL;+ Real bestDistSqr = 0.0f;+ for( Object *other = iter->first(); other; other = iter->next() )+ {+ if( !other->isKindOf( KINDOF_FS_INTERNET_CENTER ) || other->getControllingPlayer() != me->getControllingPlayer() ||+ other->isEffectivelyDead() || other->testStatus( OBJECT_STATUS_UNDER_CONSTRUCTION ) || other->testStatus( OBJECT_STATUS_SOLD ) )+ continue;+ const ContainModuleInterface *contain = other->getContain();+ if( contain == NULL || !contain->isValidContainerFor( me, TRUE ) ) // a mod's center may carry no seats+ continue;+ const Real distSqr = ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D );+ if( best == NULL || distSqr < bestDistSqr || ( distSqr == bestDistSqr && other->getID() < best->getID() ) )+ {+ best = other;+ bestDistSqr = distSqr;+ }+ }+ return best;+}++//-------------------------------------------------------------------------------------------------+UpdateSleepTime IdleHackerUpdate::update( void )+{+ Object *me = getObject();+ AIUpdateInterface *ai = me->getAI();+ const UnsignedInt now = TheGameLogic->getFrame();++ // Checked every frame: an order that keeps the hacker busy for a single frame still resets the clock.+ if( me->getControllingPlayer()->getPlayerType() != PLAYER_HUMAN || me->isContained() || me->isEffectivelyDead() || !ai->isIdle() )+ {+ m_idleSinceFrame = now;+ return UPDATE_SLEEP_NONE;+ }+ if( now - m_idleSinceFrame < getIdleHackerUpdateModuleData()->m_idleFrames )+ return UPDATE_SLEEP_NONE;+ m_idleSinceFrame = now;++ Object *center = findInternetCenter();+ DEBUG_LOG(( "IDLEHACKER: frame %d hacker %d %s %d\n", now, me->getID(), center ? "enters" : "hacks in place", center ? center->getID() : 0 ));+ if( center )+ ai->aiEnter( center, CMD_FROM_AI );+ else+ ai->aiHackInternet( CMD_FROM_AI );+ return UPDATE_SLEEP_NONE;+}++// ------------------------------------------------------------------------------------------------+void IdleHackerUpdate::crc( Xfer *xfer )+{+ UpdateModule::crc( xfer );+ xfer->xferUnsignedInt( &m_idleSinceFrame );+}++// ------------------------------------------------------------------------------------------------+/** Xfer method+ * Version Info:+ * 1: Initial version */+// ------------------------------------------------------------------------------------------------+void IdleHackerUpdate::xfer( Xfer *xfer )+{+ XferVersion currentVersion = 1;+ XferVersion version = currentVersion;+ xfer->xferVersion( &version, currentVersion );++ UpdateModule::xfer( xfer );++ xfer->xferUnsignedInt( &m_idleSinceFrame );+}++// ------------------------------------------------------------------------------------------------+void IdleHackerUpdate::loadPostProcess( void )+{+ UpdateModule::loadPostProcess();+}