Skip to content

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.

feat(gameclient): a speed command in the console

Olcay Seygan972ef6f6115c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c9bd35241..faa9b3b9f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -655,7 +655,7 @@ found and fixed — EA's own, not port damage.**
- The skirmish and LAN rooms are laid out again, on one grid. Each column heading sits over its own column instead of up to 18 pixels to the right of it. The seats and the settings page underneath them start and stop at the same two edges, and Play Game stands under the map and your win record on the right-hand pair. The open tab used to be lettered in a grey that measured about 2 to 1 against the panel and read as a button that was switched off. Play Game waits at the bottom right and the button that leaves the room sits at the bottom left, as far from it as the screen allows. With all eight seats taken, "USA Super Weapon General" still fits in its box. The online room keeps its old layout.
- Skirmish keeps starting cash and the game speed slider there. LAN and online keep starting cash next to peace time and the superweapon rule. Before this they were scattered around whatever space each of the three lobby screens happened to have left over.
- The game speed slider stops at 60. Its last notch used to read "--" and started the match at a thousand game frames a second, which no machine can play and every machine tried to. A speed saved on that notch comes back as 60.
-- The speed can change during a skirmish or a mission, too. Numpad plus and minus move it a sixth at a time and say where it stands, 50% up to 200% and past it; Ctrl with numpad plus puts it back. The reset used to land on one and a half times normal speed and the readout gave a number of frames nobody could read as a speed. Network games keep the speed the host picked.
+- The speed can change during a skirmish or a mission, too. Numpad plus and minus move it a sixth at a time and say where it stands, 50% up to 200% and past it; Ctrl with numpad plus puts it back. The console takes an exact number too: `speed 150` for half again as fast, `speed` alone to ask, `speed reset` for normal. The reset used to land on one and a half times normal speed and the readout gave a number of frames nobody could read as a speed. Network games keep the speed the host picked.
- A Unit Limit box on the settings page caps the match at 840 units, shared out evenly: two players get 420 each, four get 210, eight get 105. Units standing and units waiting in a queue both count against your share, buildings do not, and the build buttons grey out when you reach it. A transport that rolls out full is charged for its riders while it is still in the queue, so a Troop Crawler costs nine and cannot slip eight Red Guards past the limit, and a pair of Red Guards costs two. A shift or control batch near the wall queues as many as still fit and stops there, and a button whose next order would not fit greys out. Your own count and your share sit in the top right corner next to the frame rate, so you can see the wall coming. The host ticks it; everybody else sees it ticked.
- Allies can pool their income. Share Income on the settings page splits every payment evenly between whoever earned it and each teammate still in the match, so an oil derrick paying 200 to one of two allies pays 100 to each. Oil Derricks shares the derricks you capture and nothing else; All Income adds supply runs, hackers and black markets. In a two-against-two between computer players one pair of partners had earned 4,600 apart after five minutes without it, and 190 apart with it. It works in skirmish too, with a computer ally. No Sharing is the game as it always played.
- Superweapons are a dropdown instead of a tick box. Allow Superweapons is the game as it plays without a rule. Limit Superweapons leaves each player one Particle Cannon, one Nuclear Missile or one Scud Storm at a time. No Superweapons bars them.
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GameConsole.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GameConsole.cpp
index 24fe68565..5cca341e6 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GameConsole.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GameConsole.cpp
@@ -25,6 +25,7 @@
#include "GameClient/GameConsole.h"
+#include "Common/GameEngine.h"
#include "Common/MessageStream.h"
#include "Common/Player.h"
#include "Common/PlayerList.h"
@@ -119,6 +120,36 @@ static AsciiString runCheat( const ConsoleCheat &cheat, AsciiString arguments )
return result;
}
+//-------------------------------------------------------------------------------------------------
+/** The game speed as a share of normal, the same thing numpad plus and minus move. It changes how
+ * often a logic frame runs and nothing inside one, so a network game, which runs at the pace the
+ * whole room agrees on, is the one place it is refused. */
+//-------------------------------------------------------------------------------------------------
+static const Int SPEED_MIN_PERCENT = 17; ///< 5 logic frames a second
+static const Int SPEED_MAX_PERCENT = 666; ///< 200 logic frames a second
+static const Int SPEED_NORMAL_PERCENT = 100;
+
+static AsciiString runSpeed( AsciiString arguments )
+{
+ AsciiString result;
+ if( !TheGameLogic->isInGame() || TheGameLogic->isInMultiplayerGame() )
+ {
+ result = "speed: single-player matches only";
+ return result;
+ }
+
+ if( !arguments.isEmpty() )
+ {
+ Int percent = arguments.compareNoCase( "reset" ) == 0 ? SPEED_NORMAL_PERCENT : atoi( arguments.str() );
+ if( percent < SPEED_MIN_PERCENT ) percent = SPEED_MIN_PERCENT;
+ if( percent > SPEED_MAX_PERCENT ) percent = SPEED_MAX_PERCENT;
+ TheGameEngine->setFramesPerSecondLimit( percent * LOGICFRAMES_PER_SECOND / SPEED_NORMAL_PERCENT );
+ }
+
+ result.format( "speed %d%%", TheGameEngine->getFramesPerSecondLimit() * SPEED_NORMAL_PERCENT / LOGICFRAMES_PER_SECOND );
+ return result;
+}
+
//-------------------------------------------------------------------------------------------------
GameConsole::GameConsole()
: m_isOpen( FALSE ),
@@ -281,6 +312,7 @@ void GameConsole::runCommand( AsciiString commandLine )
printLine( AsciiString( "help this list" ) );
printLine( AsciiString( "clear empty the scrollback" ) );
printLine( AsciiString( "echo <text> print the text back" ) );
+ printLine( AsciiString( "speed [n] game speed in percent, 100 is normal, 'reset' goes back" ) );
if( areCheatsAvailable() )
printLine( AsciiString( "cheats single-player cheats" ) );
return;
@@ -315,6 +347,12 @@ void GameConsole::runCommand( AsciiString commandLine )
return;
}
+ if( command == "speed" )
+ {
+ printLine( runSpeed( arguments ) );
+ return;
+ }
+
UnicodeString unknown( L"unknown command: " );
UnicodeString name;
name.translate( command );