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(gameclient): drag the camera on the radar, Legacy ctrl fires
Olcay Seygan6b958d8b8c96
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 4e7b4b88c..228d90df4 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -582,9 +582,10 @@ found and fixed — EA's own, not port damage.**- The promotion screen closes when you press its key again, however fast you press it. The screen fades in, and the fade drives the window itself for several frames either way - so a second press during the fade read the screen as still shut and opened it again, and a press just after it was closed was undone by the fade's next frame.- The command bar stops changing under you while you are using it. With nothing selected the bar shows one of your builders so you can place a structure without picking a dozer first, and it showed whichever one happened to be idle - so a dozer finishing a building on the far side of the base took the bar over, dropping a half-typed build hotkey and taking the structure off your cursor. The builder you are working with keeps the bar.- The command bar's artwork moves with the command bar. Minimising it slid the buttons off the bottom of the screen and left the metal they sit on painted over the battlefield; the same painting stood still through the slide the bar makes when a match opens. It travels with the bar and goes with it.-- Play it the way it shipped. Options > Controls has a Mouse and Keyboard box with two answers. Modern is this game as it is now. Legacy is the 2003 game: left click selects and orders, right click deselects, a right drag scrolls the map, a middle drag turns the camera, and the command bar answers the game's own letter for each button, painted in the button's corner the way the grid keys are. Those letters are the English game's even when the words are Turkish: the translation marks every label's first letter, which would have put K on three GLA structures and S on five. The promotion screen's number keys and the general's power keys are this game's additions, so under Legacy their labels are gone and the number keys pick your groups again. Every key comes from the game's own key map, so the grid keys, the two-key structures, Alt+Z signals, Ctrl+Z barracks, Tab, box select filters, formation lines, zoom to cursor and clickable health bars all stand down. It changes the moment you press Accept, even in the middle of a match, and it only changes your own screen.-- The lines from your selection to where it is headed can be switched off. Options > Gameplay has an Order Lines box, on by default. Off, a selected unit shows no line to its goal and none through its shift queue; the line you draw while dragging a formation still shows, because that one is the order being given. It changes the moment you press Accept.+- Play it the way it shipped. Options > Controls has a Mouse and Keyboard box with two answers. Modern is this game as it is now. Legacy is the 2003 game: left click selects and orders, right click deselects, a right drag scrolls the map, a middle drag turns the camera, and the command bar answers the game's own letter for each button, painted in the button's corner the way the grid keys are. Holding Ctrl makes a click force fire, at the ground or at your own units. Those letters are the English game's even when the words are Turkish: the translation marks every label's first letter, which would have put K on three GLA structures and S on five. The promotion screen's number keys and the general's power keys are this game's additions, so under Legacy their labels are gone and the number keys pick your groups again. Every key comes from the game's own key map, so the grid keys, the two-key structures, Alt+Z signals, Ctrl+Z barracks, Tab, box select filters, formation lines, zoom to cursor and clickable health bars all stand down. It changes the moment you press Accept, even in the middle of a match, and it only changes your own screen.+- The lines from your selection to where it is headed can be switched off. Options > Gameplay has an Order Lines box, on by default. Off, a selected unit shows no line to its goal and none through its queue, but the marker on every point it is headed for stays, so an attack move or a string of waypoints is still there to see. The line you draw while dragging a formation still shows, because that one is the order being given. It changes the moment you press Accept.- Click through the command bar wherever its metal is not. The bar is three shaped plates with sloped tops and cut corners, but it caught clicks over the whole rectangle each plate sits in, so a unit standing in the sky above the radar's slope, or in the notch beside the command grid, could not be clicked or ordered to. Between 3 and 22 percent of each plate's rectangle is empty, depending on the side and the panel. Those parts belong to the battlefield now, and the buttons and metal still take every click they did.+- Drag the camera across the radar. Press on the radar and keep the button down, and the camera follows the cursor over the map until you let go; before, it jumped once per click, so crossing the map meant clicking your way over it. The button that moves the camera with a click is the one that drags it, left under Modern and right under Legacy, and with nothing selected either one does. Run the left button off the side of the radar and the camera waits at the edge of the map. A selection box dragged onto the radar from the battlefield leaves the camera where it is.- Widescreen resolutions are back in the options menu, and the list works during a match. It was greyed out the moment a game started, because changing it rebuilt the menus and then pushed the main menu over whatever you were playing. It rebuilds the menus for later and leaves you on the battlefield with the command bar back up.- Changing the resolution during a match no longer takes the game down. Two things were behind it. The old command bar's windows were handed back while the menu system still had them on its list, so the next thing that painted a button read whatever had since been written over it. And the bar itself was thrown away and built from scratch, which handed out fresh copies of every build button while your factories, your repair crews and the promotion screen went on pointing at the old ones. The bar's windows are rebuilt now and the bar keeps everything that is not a window.- One command bar, not three. Changing the resolution during a match rebuilt the bar and left the old one behind, still drawn and still taking clicks at the size of the screen it was built for - and the confirmation box you answer afterwards rebuilds it a second time, so two mode changes in a row put three command bars on top of each other across the bottom of the battlefield. The code that was meant to throw the old one away asked the window system for a window called "ControlBar.wnd", and the bar's window is called "ControlBar.wnd:ControlBarParent", so it never found anything to throw away and never had.diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.strindex 80540abad..5fa98e19b 100644--- a/GeneralsMD/Code/Data/Patch.str+++ b/GeneralsMD/Code/Data/Patch.str@@ -755,7 +755,7 @@ GUI:OrderLinesENDTOOLTIP:OrderLines-"A line from each selected unit to where it is going, and on through every point it has queued."+"A line from each selected unit to where it is going, and on through every point it has queued. Off, the markers on those points stay."ENDGUI:PlayerColorsdiff --git a/GeneralsMD/Code/Data/Turkish/Generals.str b/GeneralsMD/Code/Data/Turkish/Generals.strindex d9aa38482..bf664a89f 100644--- a/GeneralsMD/Code/Data/Turkish/Generals.str+++ b/GeneralsMD/Code/Data/Turkish/Generals.str@@ -15326,7 +15326,7 @@ GUI:OrderLinesENDTOOLTIP:OrderLines-"Seçili her birimden gittiği yere, oradan da sıraya aldığı her noktaya bir çizgi çeker."+"Seçili her birimden gittiği yere, oradan da sıraya aldığı her noktaya bir çizgi çeker. Kapalıyken çizgiler gider, o noktalardaki işaretler kalır."ENDGUI:PlayerColorsdiff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.hindex 7c2d753b6..8e208ee99 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h@@ -868,6 +868,7 @@ public: // ********************************************************************void toggleForceAttackArmed( void ) { m_forceAttackArmed = !m_forceAttackArmed; m_attackMoveToMode = FALSE; m_guardArmed = FALSE; }Bool isForceAttackArmed( void ) const { return m_forceAttackArmed; }Bool isOrderKeyArmed( void ) const { return m_forceAttackArmed || m_attackMoveToMode || m_guardArmed; } ///< the next left click is an attack, an attack move or a guard+ Bool isForceFireOn( void ) const; ///< the next order click force fires: the attack key armed it, or Legacy's ctrl is held// and the guard key arms guard the same way: the next order click posts the selection on that// spot, or on that object, and a drag posts them along the line instead of stacking them alldiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarCallback.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarCallback.cppindex 4936c0c1b..81be1c393 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarCallback.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarCallback.cpp@@ -57,6 +57,36 @@//external declarations of the Gadgets the callbacks can useWindowLayout *popupCommunicatorLayout = NULL;+// The drag message of the button whose press on the radar moved the camera, or GWM_NONE. Dragging+// that button on keeps the camera under the cursor; a drag that came onto the radar from the+// battlefield, a selection box say, was never pressed here and leaves the camera alone.+static UnsignedInt s_radarLookDrag = GWM_NONE;++//-------------------------------------------------------------------------------------------------+/** The mouse position packed into a window message, relative to that window's corner */+//-------------------------------------------------------------------------------------------------+static ICoord2D windowLocalMouse( GameWindow *window, WindowMsgData mData1 )+{+ ICoord2D screenPos;+ window->winGetScreenPosition( &screenPos.x, &screenPos.y );++ ICoord2D mouse;+ mouse.x = (mData1 & 0xFFFF) - screenPos.x;+ mouse.y = (mData1 >> 16) - screenPos.y;+ return mouse;+}++//-------------------------------------------------------------------------------------------------+/** The spot on the map under a pixel of the radar window. FALSE off the radar's picture. */+//-------------------------------------------------------------------------------------------------+static Bool radarPixelToWorld( const ICoord2D *pixel, Coord3D *world )+{+ ICoord2D radar;+ return (TheRadar->isRadarHidden() == FALSE || TheRadar->isRadarForced()) &&+ TheRadar->localPixelToRadar( pixel, &radar ) &&+ TheRadar->radarToWorld( &radar, world );+}+//-------------------------------------------------------------------------------------------------/** Input procedure for the left HUD */@@ -97,6 +127,11 @@ WindowMsgHandledType LeftHUDInput( GameWindow *window, UnsignedInt msg,case GWM_MOUSE_LEAVING:{+ // A left press holds the radar and never sees these until it lets go. A right drag does,+ // and one that leaves the radar has finished moving the camera.+ if( msg != GWM_NONE )+ s_radarLookDrag = GWM_NONE;+//// consider changing the mouse cursor if we are not in the process of firing// targeted "superweapons" which we can use the radar itself to fire@@ -221,30 +256,40 @@ WindowMsgHandledType LeftHUDInput( GameWindow *window, UnsignedInt msg,// ------------------------------------------------------------------------case GWM_RIGHT_UP:// Here to eatcase GWM_LEFT_UP:// Here to eat+ s_radarLookDrag = GWM_NONE;break;- case GWM_RIGHT_DOWN:- case GWM_LEFT_DOWN:+ // ------------------------------------------------------------------------+ // Holding the button that moved the camera and dragging keeps the camera under the cursor.+ case GWM_LEFT_DRAG:+ case GWM_RIGHT_DRAG:{- ICoord2D mouse;- ICoord2D radar;- ICoord2D size;- ICoord2D screenPos;- Coord3D world;-- // get window size+ if( msg != s_radarLookDrag )+ return MSG_IGNORED;++ // A left press holds the radar for the whole drag, so the cursor can run off the picture.+ // It pins to the picture's edge there and the camera stops on the map's edge, rather than+ // wherever the last move inside the picture happened to leave it.+ ICoord2D mouse = windowLocalMouse( window, mData1 );+ ICoord2D size, ul, lr;window->winGetSize( &size.x, &size.y );+ TheRadar->findDrawPositions( 0, 0, size.x, size.y, &ul, &lr );+ mouse.x = max( ul.x, min( mouse.x, lr.x - 1 ) );+ mouse.y = max( ul.y, min( mouse.y, lr.y - 1 ) );- // get mouse position- mouse.x = mData1 & 0xFFFF;- mouse.y = mData1 >> 16;-- // get window screen position- window->winGetScreenPosition( &screenPos.x, &screenPos.y );+ Coord3D world;+ if( radarPixelToWorld( &mouse, &world ) )+ TheTacticalView->lookAt( &world );+ break;+ }- // set mouse position to be relative to this window- mouse.x -= screenPos.x;- mouse.y -= screenPos.y;+ case GWM_RIGHT_DOWN:+ case GWM_LEFT_DOWN:+ {+ s_radarLookDrag = GWM_NONE;++ ICoord2D mouse = windowLocalMouse( window, mData1 );+ Coord3D world;//// translate mouse position to radar position ... we know that the mouse@@ -252,9 +297,7 @@ WindowMsgHandledType LeftHUDInput( GameWindow *window, UnsignedInt msg,// completely drawn with the radar ... so it's just a translation from// our window size we're drawing into to the radar cell size//- if( (TheRadar->isRadarHidden() == FALSE || TheRadar->isRadarForced()) &&- TheRadar->localPixelToRadar( &mouse, &radar ) &&- TheRadar->radarToWorld( &radar, &world ) )+ if( radarPixelToWorld( &mouse, &world ) ){// No drawables, or a right click automatically means its a look at.@@ -270,6 +313,7 @@ WindowMsgHandledType LeftHUDInput( GameWindow *window, UnsignedInt msg,if( drawableList->empty() || msg == lookButton ){TheTacticalView->lookAt( &world );+ s_radarLookDrag = (msg == GWM_LEFT_DOWN) ? GWM_LEFT_DRAG : GWM_RIGHT_DRAG;break;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex 7d562806c..825bf7fde 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -3095,14 +3095,6 @@ void InGameUI::updateOrderHints( void )return;}- // the player turned the lines off in the options; the formation line above is the drag itself and- // still draws- if( !TheGlobalData->m_showOrderLines )- {- m_orderHints.clear();- return;- }-// last frame's markers, kept only so this frame's can inherit their age (see addOrderHint)std::vector<OrderHint> previous;previous.swap( m_orderHints );@@ -4466,6 +4458,20 @@ void InGameUI::createCommandHint( const GameMessage *msg )}}+//-------------------------------------------------------------------------------------------------+/** Ctrl held is how the game as shipped force fired, and Legacy is that game. Modern keeps ctrl for+ * the shared pace on a move and force fires on the attack key alone. */+//-------------------------------------------------------------------------------------------------+Bool InGameUI_isForceFireOn( Bool forceAttackArmed, Bool ctrlHeld, Bool legacyInput )+{+ return forceAttackArmed || ( legacyInput && ctrlHeld );+}++Bool InGameUI::isForceFireOn( void ) const+{+ return InGameUI_isForceFireOn( m_forceAttackArmed, m_forceAttackMode, TheGlobalData->isLegacyInput() );+}+//-------------------------------------------------------------------------------------------------/// Get drawable ID under cursor//-------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cppindex 13b742213..d932a443a 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp@@ -102,8 +102,9 @@//-------------------------------------------------------------------------------------------------/*** Is the next order click a force fire?- * Only the attack key arms it. Holding ctrl used to do the same, and ctrl is the "one shared pace"- * modifier on a move (see issueMoveToLocationCommand), so a ctrl click could not ask for both.+ * Under Modern only the attack key arms it: ctrl is the "one shared pace" modifier on a move (see+ * issueMoveToLocationCommand), so a ctrl click could not ask for both. Legacy's ctrl is still the+ * game's own force fire (InGameUI::isForceFireOn).*/Bool CommandXlat_isForceAttackTargeting( Bool forceAttackArmed, Bool attackMoveArmed ){@@ -112,7 +113,7 @@ Bool CommandXlat_isForceAttackTargeting( Bool forceAttackArmed, Bool attackMoveAstatic Bool isForceAttackTargeting( void ){- return CommandXlat_isForceAttackTargeting( TheInGameUI->isForceAttackArmed(),+ return CommandXlat_isForceAttackTargeting( TheInGameUI->isForceFireOn(),TheInGameUI->isInAttackMoveToMode() );}diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cppindex ab66dcddc..658bb5f80 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp@@ -460,7 +460,7 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessa// when we're not in force attackable mode!UnsignedInt pickType = getPickTypesForContext( true /*TheInGameUI->isInForceAttackMode()*/ );- Drawable *underCursor = TheTacticalView->pickDrawable( &pixel, TheInGameUI->isForceAttackArmed(), (PickType) pickType );+ Drawable *underCursor = TheTacticalView->pickDrawable( &pixel, TheInGameUI->isForceFireOn(), (PickType) pickType );//// a click on a health bar selects its owner, so the cursor has to say so before the@@ -505,8 +505,8 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessabreak;}- // an armed order key makes this click an order, which CommandXlat gives- if (TheInGameUI->isOrderKeyArmed())+ // an armed order key, or Legacy's ctrl, makes this click an order, which CommandXlat gives+ if (TheInGameUI->isOrderKeyArmed() || TheInGameUI->isForceFireOn())break;const IRegion2D& region = msg->getArgument(0)->pixelRegion;diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/SelectionInfo.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/SelectionInfo.cppindex 72dcab606..f69ce1382 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/SelectionInfo.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/SelectionInfo.cpp@@ -76,7 +76,7 @@ PickDrawableStruct::PickDrawableStruct() : drawableListToFill(NULL)//Initializations inserteddrawableListToFill = FALSE;//- forceAttackMode = TheInGameUI->isForceAttackArmed();+ forceAttackMode = TheInGameUI->isForceFireOn();UnsignedInt pickType = getPickTypesForContext(forceAttackMode);translatePickTypesToKindof(pickType, kindofsToMatch);if (!forceAttackMode)@@ -98,7 +98,7 @@ extern Bool contextCommandForNewSelection(const DrawableList *currentlySelectedDif (!(currentlySelectedDrawables && newlySelectedDrawables && outSelectionInfo))return FALSE;- Bool forceFire = TheInGameUI->isForceAttackArmed();+ Bool forceFire = TheInGameUI->isForceFireOn();Bool forceMove = TheInGameUI->isInForceMoveToMode();if (forceFire || forceMove) {diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cppindex bb21c803f..fb08ec359 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp@@ -1139,7 +1139,10 @@ void W3DInGameUI::drawOrderHints( void )if( TheTacticalView->worldToScreenTriReturn( &it->to, &to ) == View::WTS_INVALID )continue;- TheDisplay->drawLine( from.x, from.y, to.x, to.y, width, lineColor );+ // Order Lines off in the options takes the lines away and leaves the markers: where a unit is+ // going is still worth a glance when the thread across the map is not+ if( TheGlobalData->m_showOrderLines )+ TheDisplay->drawLine( from.x, from.y, to.x, to.y, width, lineColor );// the marker is the plain pointer, tinted: its white body takes the order colour and the// dark outline stays. The hot spot is the pixel the player aims with, so that is the pixeldiff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cppindex 45547d3d4..09c8c6000 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp@@ -2426,7 +2426,7 @@ Int W3DView::iterateDrawablesInRegion( IRegion2D *screenRegion,if (regionIsPoint){// Allow all drawables to be picked.- onlyDrawableToTest = pickDrawable(&screenRegion->lo, TRUE, (PickType) getPickTypesForContext(TheInGameUI->isForceAttackArmed()));+ onlyDrawableToTest = pickDrawable(&screenRegion->lo, TRUE, (PickType) getPickTypesForContext(TheInGameUI->isForceFireOn()));//// Nothing under the cursor in the scene, so a health bar is allowed to answer for its owner.diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 6ebf34ec4..b0ea75e14 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -994,6 +994,22 @@ TEST(force_fire_is_the_attack_key_and_nothing_else)CHECK( !CommandXlat_isForceAttackTargeting( false, true ) );}+/* InGameUI.cpp: Legacy is the game as shipped, where holding ctrl is force fire. Modern keeps ctrl for+ the shared pace and force fires on the attack key alone. */+extern Bool InGameUI_isForceFireOn( Bool forceAttackArmed, Bool ctrlHeld, Bool legacyInput );++TEST(legacy_ctrl_force_fires_and_modern_ctrl_does_not)+{+ CHECK( InGameUI_isForceFireOn( false, true, true ) );+ CHECK( !InGameUI_isForceFireOn( false, true, false ) );++ /* the attack key arms it under either scheme */+ CHECK( InGameUI_isForceFireOn( true, false, false ) );+ CHECK( InGameUI_isForceFireOn( true, false, true ) );++ CHECK( !InGameUI_isForceFireOn( false, false, true ) );+}+/* Player.cpp: the lobby's unit limit is 840 units shared out by the players who are not watching. */TEST(unit_limit_shares_840_between_the_players){