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(gameclient): let control group 0 be viewed, and stop at the last squad
Olcay Seygancb52df645f73
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c32383fab..fdd5debff 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -590,6 +590,9 @@ original code, and each one was proved by putting the bug back and watching thefor five seconds and take another three to fade it, so what you did eight seconds ago was stillsitting there under everything you had done since. It reads for two and a half seconds and fadesin about one.+- **Double-tapping 0 never jumped the camera to that group.** Nine of the ten control groups took+ you to their units; the 0 group answered the key that selects it and ignored the key that finds+ it.- **The mouse wheel cancelled whatever camera move was in progress** — zoom while panning, the mostcommon camera gesture there is, fought you every time.diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Player.h b/GeneralsMD/Code/GameEngine/Include/Common/Player.hindex bdf4a53f4..91e8db568 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/Player.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/Player.h@@ -114,6 +114,16 @@ static const Int NUM_HOTKEY_SQUADS = 10;enum { NO_HOTKEY_SQUAD = -1 };+//+// The control group keys hand out squad numbers 0 through NUM_HOTKEY_SQUADS-1, and every place+// that turns a key message into a squad number has to say so the same way. One of them said+// "1 through 10" instead, which is the same count of numbers and none of the right ones.+//+inline Bool isValidHotkeySquadIndex( Int squadNumber )+{+ return squadNumber >= 0 && squadNumber < NUM_HOTKEY_SQUADS;+}+// ------------------------------------------------------------------------------------------------typedef Int PlayerIndex;#define PLAYER_INDEX_INVALID -1diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cppindex 0c1f08c0e..bb71bf0e3 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp@@ -1044,7 +1044,7 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessacase GameMessage::MSG_META_CREATE_TEAM9:{Int group = t - GameMessage::MSG_META_CREATE_TEAM0;- if ( group >= 0 && group < 10 )+ if ( isValidHotkeySquadIndex( group ) ){DEBUG_LOG(("META: create team %d\n",group));// Assign selected items to a group@@ -1076,7 +1076,7 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessacase GameMessage::MSG_META_SELECT_TEAM9:{Int group = t - GameMessage::MSG_META_SELECT_TEAM0;- if ( group >= 0 && group < 10 )+ if ( isValidHotkeySquadIndex( group ) ){DEBUG_LOG(("META: select team %d\n",group));@@ -1149,7 +1149,7 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessacase GameMessage::MSG_META_ADD_TEAM9:{Int group = t - GameMessage::MSG_META_ADD_TEAM0;- if ( group >= 0 && group < 10 )+ if ( isValidHotkeySquadIndex( group ) ){DEBUG_LOG(("META: select team %d\n",group));@@ -1230,7 +1230,7 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessacase GameMessage::MSG_META_VIEW_TEAM9:{Int group = t - GameMessage::MSG_META_VIEW_TEAM0;- if ( group >= 1 && group <= 10 )+ if ( isValidHotkeySquadIndex( group ) ){DEBUG_LOG(("META: view team %d\n",group));Player *player = ThePlayerList->getLocalPlayer();diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 8e21bc592..c117bdee2 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -60,6 +60,7 @@#include "Common/StateMachine.h"#include "Common/XferCRC.h"#include "Common/ObjectStatusTypes.h"+#include "Common/Player.h"#include <stdio.h>#include <string.h>@@ -3545,3 +3546,29 @@ TEST(network_command_ids_are_ordered_across_the_sixteen_bit_wrap)CHECK( allOrdered );CHECK_EQ( (Int)id, 64 ); // the run really did cross the wrap}++//////////////////////////////////////////////////////////////////////////////+// Control groups+//////////////////////////////////////////////////////////////////////////////++/* The ten control group keys produce squad numbers 0..NUM_HOTKEY_SQUADS-1. The camera-jump+ handler tested "1 through 10" instead, so the 0 key never centred on its group and the number+ it did accept was one past the last squad. All four handlers ask this one function now. */+TEST(hotkey_squad_index_covers_group_zero_and_stops_at_the_last_squad)+{+ CHECK_EQ( (Int)NUM_HOTKEY_SQUADS, 10 );++ CHECK( isValidHotkeySquadIndex( 0 ) ); // the "0" key, the one that was dropped+ CHECK( isValidHotkeySquadIndex( 1 ) );+ CHECK( isValidHotkeySquadIndex( NUM_HOTKEY_SQUADS - 1 ) );++ CHECK( !isValidHotkeySquadIndex( NUM_HOTKEY_SQUADS ) ); // the one it used to accept+ CHECK( !isValidHotkeySquadIndex( -1 ) );++ // every squad the keys can name is a squad Player::getHotkeySquad will actually look up+ Bool allInRange = TRUE;+ for( Int group = 0; group < 10; ++group )+ if( !isValidHotkeySquadIndex( group ) )+ allInRange = FALSE;+ CHECK( allInRange );+}