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): Force Attack shows Ctrl, Ctrl+Shift box-selects
Olcay Seygan8bd0a16c66eb
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex f1ad7ea22..50f041ef2 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -53,7 +53,7 @@ found and fixed — EA's own, not port damage.**- The choice between a Classic and a Reforged interface is gone. There is one, laid out the way Zero Hour shipped, and the orders Reforged added now live on the keys you already know: A attack-moves, holding Ctrl fires on whatever is under the cursor as it did in 2003, a guard order can cover a patch of ground instead of one spot, and orders queue up one after another. Everything your base is building stands on the screen as a line of text each, the six closest to done first and "+N more" for the rest. Superweapon countdowns are listed the same way, up to eighteen. Both lists are in bold type, the build list in white and each countdown in its owner's colour. The promotion screen no longer darkens the battlefield behind it. Whether the right button gives orders, or the left as in 1.04, is a setting in the launcher.- An attack move and a Ctrl attack fire on the left click in every mouse setup. With the right button giving orders, A then a right click attack-moved, and Ctrl fired only on a right click, so the same hands did different things depending on one checkbox. Now A, or Ctrl held, then a left click is the attack everywhere, and a right click with A armed puts the key down without an order. Ctrl with a right click gives none. Plain orders stay on whichever button your setup gives them.-- Combat units that attack-move now have a Force Attack button on the command bar, under Attack Move and left of Stop. It arms the same fire-on-whatever-is-under-the-pointer mode holding Ctrl has always given, and the launcher's Hotkeys page can give that button its own letter. This version's data checksum differs, so it cannot join a game hosted on an older one.+- Combat units that attack-move now have a Force Attack button on the command bar, under Attack Move and left of Stop. It arms the same fire-on-whatever-is-under-the-pointer mode holding Ctrl has always given, and the button wears Ctrl. This version's data checksum differs, so it cannot join a game hosted on an older one.- Buildings select together again, which the one interface had taken away. Shift-click them, drag a box over them, or double-click one for every building of its kind on the screen; select four War Factories and each tank you click goes to whichever has the shortest queue. Double-click a unit and every one of that kind whose feet sit in the picture is taken, including the ones sitting past the camera's far clip that used to be skipped. A building and a unit still never share a selection.- Formation lines are back for everyone. With move, attack move or guard armed, a left drag spreads the selection along the line you draw again; since the one interface it drew a selection box instead, because the line was switched off for the Classic mouse that every player now runs. A drag with no order armed is still the selection box.- Every key is yours to move. The launcher's Hotkeys page draws the command bar of every building and unit each general can field, cameos and letters as the game shows them, and a click and a keypress gives any button a new letter or none. Two buttons on one bar that would share a letter are marked before you play. The keyboard commands are there too, from bookmarks and team keys to the camera, along with the ones Zero Hour never bound: select every fighting unit, vehicle or aircraft, every barracks, war factory or airfield, the next idle worker or unit, pause, the general's promotions, the three signals to your allies and the general's powers. Your keys are yours alone; the other players in a match keep theirs, and a match never refuses you for them. Every mod you install brings its own generals to the page, ShockWave's fifteen next to Zero Hour's thirteen, and a key you give a ShockWave button stays with ShockWave.@@ -347,7 +347,7 @@ found and fixed — EA's own, not port damage.**## Selecting and ordering with the mouse- Ctrl+Q now takes infantry only, not every armed thing you own.-- A box drawn with Ctrl held takes those units back out of your selection instead of replacing it, so a group is trimmed by dragging over the corner of it rather than picked again from scratch. Held with Alt the box keeps only what can shoot: drag across your base and you get the tanks, not the dozers and supply trucks standing among them. Both are drag-only, and a single click still means exactly what it always did.+- A box drawn with Ctrl held takes those units back out of your selection instead of replacing it, so a group is trimmed by dragging over the corner of it rather than picked again from scratch. Held with Alt the box keeps only what can shoot: drag across your base and you get the tanks, not the dozers and supply trucks standing among them. Both are drag-only, and a single click still means exactly what it always did. Hold Ctrl and Shift and drag: the units in the box are selected. Ctrl alone still draws the fire circle.- A box dragged over your army and your economy together takes the army. The dozers, workers, supply trucks and hackers standing among the tanks stay where they are, and ambulances and troop carriers go with the soldiers they look after. A box with nobody military in it takes the workers the way it always did.- The three buttons are split cleanly now. Left selects, and only selects. A right click gives the order, and a right drag scrolls the map the way it did in 2003: the spot you pressed on stays put, and the further you pull away from it the faster the map runs. The drag only starts once the pointer has really travelled, so a click your hand wobbles a pixel or two is still an order and the camera does not twitch. A pan never throws away the building on your cursor or the power you were about to aim. The middle button turns the view, with no key held, and a middle click without a drag puts the camera back where it started. The wheel zooms toward whatever the cursor is over and the screen edges still scroll. The classic scheme, where left both selected and commanded and right scrolled and deselected, is gone rather than switched off, and the two checkboxes that used to choose between them are out of the options screen.- How far the pointer travels before a click becomes a drag is yours to set. Drag Threshold on Options > Controls runs from 2 to 50 pixels, and the game's own value was 25. Raise it if selection boxes start by accident, lower it if your drags are read as clicks.diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h b/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.hindex 930e1d905..3d89225d7 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h@@ -113,7 +113,8 @@ public:* Hotkeys page writes it, INI::parseCommandButtonHotKeyDefinition reads it), 0 where the player* took the key away, and labelKey, the letter after the label's '&', where the player left the* button alone; upper case. Attack move, stop, guard, rally point, evacuate and sell have their- * fixed letters and no other button gets one. With grid keys on (INI::parseCommandBarGridDefinition) a button on the command bar,+ * fixed letters and no other button gets one. Force Attack is 0: it is Ctrl, painted on the+ * cameo, never a letter. With grid keys on (INI::parseCommandBarGridDefinition) a button on the command bar,* barSlot its ButtonCommand number less one, gets its place's key instead, except attack move, stop, guard, rally point, evacuate and combat drop, and any other button* (barSlot -1) loses a letter the grid uses. */static WideChar playerButtonKey( const AsciiString& button, WideChar labelKey, Int barSlot,diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cppindex e3e0241eb..e96dd7658 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp@@ -4616,10 +4616,19 @@ void ControlBar::setControlCommand( GameWindow *button, const CommandButton *comfor( Int slot = 0; slot < MAX_COMMANDS_PER_SET; slot++ )if( m_commandWindows[ slot ] == button )barSlot = slot;- const WideChar letter = HotKeyManager::playerButtonKey( commandButton->getName(),+ // Force Attack is Ctrl, the hold that force-fires. Showing H or F on the cameo would+ // steal that letter and lie about the key. Do not addHotKey it: Ctrl is already+ // MSG_META_BEGIN_FORCEATTACK, and binding the button to Ctrl would toggle on every press.+ const Bool forceAttack = commandButton->getCommandType() == GUI_COMMAND_FORCE_ATTACK;+ const WideChar letter = forceAttack ? 0 : HotKeyManager::playerButtonKey( commandButton->getName(),TheGameText ? TheGameText->fetchEnglishHotKey( commandButton->getTextLabel() ) : 0, barSlot,commandButton->getCommandType() );- if( letter != 0 )+ if( forceAttack )+ {+ GadgetButtonSetText( button, UnicodeString( u"Ctrl" ) );+ button->winSetStatus( WIN_STATUS_SHORTCUT_BUTTON );+ }+ else if( letter != 0 ){TheHotKeyManager->addHotKey( button, HotKeyManager::nameOf( letter ) );const WideChar text[ 2 ] = { letter, 0 };diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cppindex 79eef7fb0..c4c1ee206 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp@@ -446,6 +446,10 @@ static Bool isOneOf( WideChar letter, const WideChar *letters, Int count )WideChar HotKeyManager::playerButtonKey( const AsciiString& button, WideChar labelKey, Int barSlot,Int commandType ){+ // Force Attack is Ctrl. Slot 12's grid letter is H, the English label's is F; neither is+ // the key, and neither may bind the button.+ if( commandType == GUI_COMMAND_FORCE_ATTACK )+ return 0;AsciiString lower = button;lower.toLower();Int ownMod = -1;diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cppindex 812ccbc26..0ece0fd94 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp@@ -736,8 +736,11 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessabetween a selection and the right selection. Shift already adds, so what was missingwas a way to take things back out and a way to leave the base staff behind: Alt keepsonly what can shoot, Ctrl removes the box from the selection instead of replacing it.- Both are drag-only. A point click has to stay exactly what it was - a filter that eats- single clicks reads as a broken mouse. Classic has neither: its Ctrl is force fire. */+ Ctrl+Shift selects the box: both meta modes drop when the second modifier goes+ down, the fire circle never starts, and this Ctrl-remove used to eat the click.+ Both filters are drag-only. A point click has to stay exactly what it was - a filter+ that eats single clicks reads as a broken mouse. Classic has neither: its Ctrl is+ force fire. */if (!isPoint && !TheGlobalData->isClassicMouse()){if (TheKeyboard->isAlt())@@ -762,7 +765,7 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessa}}- if (TheKeyboard->isCtrl())+ if (TheKeyboard->isCtrl() && !TheKeyboard->isShift()){GameMessage *removeMsg = NULL;DrawableListIt rit;@@ -1101,9 +1104,12 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessa// with the attack key armed or Ctrl held the left button draws a circle instead of a// selection box, and everything hostile inside it becomes a target list. An armed line key- // (move, attack move, guard) keeps its line under Ctrl+ // (move, attack move, guard) keeps its line under Ctrl. Ctrl+Shift is the box: you can+ // pick units without dropping force-fire. Shift with the attack key armed still queues a+ // circle.if( TheInGameUI->isForceFireOn() && !TheInGameUI->isLineOrderArmed() && TheInGameUI->getSelectCount() > 0- && TheInGameUI->getGUICommand() == NULL && TheInGameUI->getPendingPlaceType() == NULL )+ && TheInGameUI->getGUICommand() == NULL && TheInGameUI->getPendingPlaceType() == NULL+ && !( TheKeyboard->isCtrl() && TheKeyboard->isShift() ) )TheInGameUI->beginAttackCircle( m_selectFeedbackAnchor );break;}diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DPushButton.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DPushButton.cppindex 2eb9f253f..023992548 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DPushButton.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DPushButton.cpp@@ -304,7 +304,8 @@ static void drawClassicKeyBadge( GameWindow *window, const UnicodeString &text,window->winGetScreenPosition( &origin.x, &origin.y );window->winGetSize( &size.x, &size.y );- DisplayString *badge = badgeString( text, getBadgeFont( window, CLASSIC_KEY_BADGE_DESIGN_POINTS ) );+ GameFont *font = getBadgeFont( window, CLASSIC_KEY_BADGE_DESIGN_POINTS );+ DisplayString *badge = badgeString( text, font );if( badge == NULL )return;@@ -313,16 +314,33 @@ static void drawClassicKeyBadge( GameWindow *window, const UnicodeString &text,if( textWidth <= 0 || textHeight <= 0 )return;- // one pixel in from the button's edge, never more than half the button- const Int side = min( textHeight, min( size.x, size.y ) / 2 );+ // one pixel in from the button's edge, never more than half the button high. A letter sits+ // on a square of the line height so I and M share a plate. A chord name (Ctrl on Force+ // Attack) is wider: grow the plate to the word, shrink the font if the button cannot hold it.+ const Int pad = 2;+ const Int maxW = size.x - 2;+ const Int maxH = min( size.x, size.y ) / 2;+ while( font != NULL && font->pointSize > BADGE_LEAST_POINTS && textWidth + pad > maxW )+ {+ font = TheFontLibrary->getFont( font->nameString, font->pointSize - 1, TRUE );+ badge = badgeString( text, font );+ if( badge == NULL )+ return;+ badge->getSize( &textWidth, &textHeight );+ }++ const Int plateH = min( textHeight, maxH );+ Int plateW = plateH;+ if( textWidth + pad > plateW )+ plateW = min( textWidth + pad, maxW );const Int left = origin.x + 1;const Int top = origin.y + 1;- TheDisplay->drawFillRect( left, top, side, side, GameMakeColor( 2, 4, 5, 230 ) );- TheDisplay->drawOpenRect( left, top, side, side, 1, GameMakeColor( 90, 90, 90, 255 ) );+ TheDisplay->drawFillRect( left, top, plateW, plateH, GameMakeColor( 2, 4, 5, 230 ) );+ TheDisplay->drawOpenRect( left, top, plateW, plateH, 1, GameMakeColor( 90, 90, 90, 255 ) );- IRegion2D plate = { { left, top }, { left + side, top + side } };+ IRegion2D plate = { { left, top }, { left + plateW, top + plateH } };badge->setClipRegion( &plate );- badge->draw( left + ( side - textWidth ) / 2, top + ( side - textHeight ) / 2, color, GameMakeColor( 0, 0, 0, 255 ) );+ badge->draw( left + ( plateW - textWidth ) / 2, top + ( plateH - textHeight ) / 2, color, GameMakeColor( 0, 0, 0, 255 ) );} // end drawClassicKeyBadgediff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 861e4dd92..c9836b7ce 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -4168,6 +4168,10 @@ TEST(controlbar_force_attack_slot_is_under_attack_move)CHECK_EQ( shown[ 11 ], 11 );CHECK_EQ( shown[ 12 ], 16 );CHECK_EQ( shown[ 13 ], 17 );++ /* Force Attack is Ctrl: slot 12's grid H and the English label's F both stay off the button */+ CHECK_EQ( HotKeyManager::playerButtonKey( AsciiString( "Command_ForceAttack" ), 'F', 11,+ GUI_COMMAND_FORCE_ATTACK ), 0 );}/* Grid keys leave windows 11 and 13 keyless. The USA War Factory's TOW upgrade in 11 moves to the