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(scriptengine): script timers count at the retail 30 hz rate
Olcay Seygan578e3b52c5af
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 2c1ee16ef..9feb93b67 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -12,6 +12,7 @@ found and fixed — EA's own, not port damage.**- The game now works out the battle 60 times a second, double the 30 Zero Hour has run at since 2003. Each step is 17 milliseconds where it was 33, so an order you give waits half as long for the step that carries it out, and a unit turning, braking or firing moves in steps half the size.- The match plays at the speed it always did. Every speed, delay, reload and build time in the game's data was converted to the shorter step, so a Crusader still fires every two seconds. The balance is the one you know.+- Mission timers keep EA's clock. A map's countdown still ticks 30 times a second, because the missions read a running timer's number and act on it: the second American mission declares victory when its "Win" timer drops below 1700, and on the first 60-step builds that came after 38 seconds instead of 10. The cutscene cues, the random music pick in the campaigns and the generals' challenges, the shell map's camera loop and the lightning on Eastern Everglades and Rocky Rampage were off the same way, 30 maps in all, and run on their original timing again. Custom maps get the same.- Normal speed is now the fastest a skirmish or a mission runs. The game speed choice in the skirmish lobby offers x0.5, x0.75 and x1, and x1 is 60 steps a second; the x1.5 and x2 it used to have are gone. A lobby left on one of them, or a saved game made at one, comes back at x1, and the speed console command and a mission's own script stay between half speed and normal as well. Replays still play as fast as you ask, and network games are untouched.- Replays and saved games from earlier versions will not load in this one. A player on an earlier version cannot join a match with a player on this version, whichever of them hosts, so a LAN party needs everyone on the same build.diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex 82282f302..8fa6f988c 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -6445,7 +6445,7 @@ void InGameUI::postDraw( void )Int framesLeft = TheScriptEngine->getCounter(timerName)->value;UnsignedInt readyFrame = TheGameLogic->getFrame();if (framesLeft > 0)- readyFrame += framesLeft;+ readyFrame += framesLeft * LOGICFRAMES_PER_RETAIL_FRAME; // script timers count retail framesInt readySecs = ControlBar_secondsFromFrames( (Real)(readyFrame - TheGameLogic->getFrame()) );if ( (info->isCountdown && readySecs != info->timestamp) || (!info->isCountdown && framesLeft != info->timestamp) ){diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cppindex 288b86151..1cd83b156 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp@@ -5704,10 +5704,12 @@ void ScriptEngine::update( void )TheScriptConditions->update();}SCRIPT_PHASE_END( SCRIPT_PHASE_CONDITIONS );- // Update any countdown timers.+ // Update any countdown timers. They count retail 30 Hz frames, one every other logic frame,+ // because maps compare a running timer's value with numbers written for 30 Hz ("timer < 1700").Int i;+ const Bool retailTick = (TheGameLogic->getFrame() % LOGICFRAMES_PER_RETAIL_FRAME) == 0;// Note - counters start at 1. 0 means not assigned.- for (i=1; i<m_numCounters; i++) {+ for (i=1; retailTick && i<m_numCounters; i++) {if (m_counters[i].isCountdownTimer) {// If counter has any time left, decrement. Counters go to -1 and stop.if (m_counters[i].value >= 0) {@@ -6892,6 +6894,13 @@ Bool ScriptEngine::evaluateTimer( Condition *pCondition )return (value < 1);}+/** Seconds to timer frames. Script timers count retail 30 Hz frames (see update), and this is+ * retail's own msec-to-frames sum, so a timer holds the number EA's maps compare it with. */+static Int retailTimerFrames( Real seconds )+{+ return REAL_TO_INT_CEIL( seconds * 1000.0f * ((Real)RETAIL_LOGICFRAMES_PER_SECOND / (Real)MSEC_PER_SECOND) );+}+//-------------------------------------------------------------------------------------------------/** Starts a timer. *///-------------------------------------------------------------------------------------------------@@ -6909,14 +6918,14 @@ void ScriptEngine::setTimer( ScriptAction *pAction, Bool millisecondTimer, BoolReal randomValue = pAction->getParameter(2)->getReal();value = GameLogicRandomValue(value, randomValue);}- m_counters[counterNdx].value = REAL_TO_INT_CEIL(ConvertDurationFromMsecsToFrames(value*1000));+ m_counters[counterNdx].value = retailTimerFrames(value);} else {Int value = pAction->getParameter(1)->getInt();if (random) {Int randomValue = pAction->getParameter(2)->getInt();value = GameLogicRandomValue(value, randomValue);}- m_counters[counterNdx].value = ConvertRetailFrames(value); // 30 Hz frames in the map+ m_counters[counterNdx].value = value; // 30 Hz frames in the map, and timers tick at 30 Hz}m_counters[counterNdx].isCountdownTimer = true;}@@ -6966,7 +6975,7 @@ void ScriptEngine::adjustTimer( ScriptAction *pAction, Bool millisecondTimer, BoReal value = pAction->getParameter(0)->getReal();if (!add)value = -value;- m_counters[counterNdx].value += REAL_TO_INT_CEIL(ConvertDurationFromMsecsToFrames(value*1000));+ m_counters[counterNdx].value += retailTimerFrames(value);} else {Int value = pAction->getParameter(0)->getInt();if (!add)