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(gameengine): Force Attack button on base defences that shoot

Olcay Seyganca768c4cb1b4
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e029f06a5..257af3f2b 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 (that hold is yours to move on the launcher's Command bar page), 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 the hold key has always given. The hold is Ctrl until you change it on the launcher's Hotkeys page, Command bar tab, and the button wears whatever you bound. Shift plus that hold still draws a selection box. 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. Base defences that shoot have it too: the Patriot Battery of every general, the Gattling Cannon, the Fire Base and the Stinger Site, wherever their bar has a free place, so a defence can fire on the ground or on a friendly. A Tunnel Network's bar is full and a Bunker has no gun of its own, so neither gets one. It arms the same fire-on-whatever-is-under-the-pointer mode the hold key has always given. The hold is Ctrl until you change it on the launcher's Hotkeys page, Command bar tab, and the button wears whatever you bound. Shift plus that hold still draws a selection box. This version's data checksum differs, so it cannot join a game hosted on an older one.
- The dark plate behind Exit, Restart and the options screen in a match covers the whole picture. It used to sit in a 4:3 frame in the middle, so a widescreen left the battlefield bright down both sides. The box itself keeps the shape it was drawn in.
- 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.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
index 2c24d77b1..fd9a07903 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
@@ -510,8 +510,15 @@ Bool ControlBar_commandPlaces( const Int *types, const Int *groups, const Int *p
void ControlBar_fitCommandSlots( const Int *types, const Bool *windowed, Int count, Int *shown );
/** Slot 12 (0-based 11) when the set already has Attack Move and that hole is empty: left of Stop,
- * under Attack Move. -1 when the set has no Attack Move, or already uses 12 (China CC mines). */
-Int ControlBar_forceAttackSlot( const Int *types, Int count );
+ * under Attack Move. A base defence that shoots (`firingDefense`) takes 12 too, or 11 above it when
+ * 12 is taken (Gattling Cannon's mines, Stinger Site's camo net, Fire Base's Sell). -1 when neither
+ * applies, or the place is used (China CC mines, a Tunnel Network's full bar). */
+Int ControlBar_forceAttackSlot( const Int *types, Int count, Bool firingDefense );
+
+/** A base defence that shoots: FS_BASE_DEFENSE with its own gun (CAN_ATTACK: Patriot, Gattling
+ * Cannon, Fire Base, Tunnel Network) or soldiers for a gun (SPAWNS_ARE_THE_WEAPONS: Stinger Site).
+ * A Bunker or Speaker Tower is neither. The launcher's Hotkeys page reads KindOf the same way. */
+Bool ControlBar_isFiringDefense( const Object *obj );
/** Grid keys' second pass over ControlBar_fitCommandSlots' `shown`: a button in window w with no key
* there (`unkeyed[ w ]`) moves to the first empty window, leftmost first, whose place has a key
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
index 6a189ea93..2ce5ad771 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
@@ -416,17 +416,28 @@ void ControlBar_fitCommandSlots( const Int *types, const Bool *windowed, Int cou
}
//-------------------------------------------------------------------------------------------------
-Int ControlBar_forceAttackSlot( const Int *types, Int count )
+Int ControlBar_forceAttackSlot( const Int *types, Int count, Bool firingDefense )
{
- enum { SLOT = 11 };
- if( count <= SLOT || types[ SLOT ] != GUI_COMMAND_NONE )
+ enum { SLOT = 11, ABOVE = 10 };
+ if( count <= SLOT )
return -1;
- for( Int slot = 0; slot < count; slot++ )
- if( types[ slot ] == GUI_COMMAND_ATTACK_MOVE )
- return SLOT;
+ Bool fights = firingDefense;
+ for( Int slot = 0; slot < count && !fights; slot++ )
+ fights = types[ slot ] == GUI_COMMAND_ATTACK_MOVE;
+ if( fights && types[ SLOT ] == GUI_COMMAND_NONE )
+ return SLOT;
+ if( firingDefense && types[ ABOVE ] == GUI_COMMAND_NONE )
+ return ABOVE;
return -1;
}
+//-------------------------------------------------------------------------------------------------
+Bool ControlBar_isFiringDefense( const Object *obj )
+{
+ return obj->isKindOf( KINDOF_FS_BASE_DEFENSE )
+ && ( obj->isKindOf( KINDOF_CAN_ATTACK ) || obj->isKindOf( KINDOF_SPAWNS_ARE_THE_WEAPONS ) );
+}
+
//-------------------------------------------------------------------------------------------------
void ControlBar_packKeyedSlots( const Bool *keyed, const Bool *unkeyed, Int count, Int *shown )
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp
index 5d4824f19..0f8e22574 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp
@@ -391,7 +391,7 @@ void ControlBar::populateCommand( Object *obj )
types[ i ] = shows ? button->getCommandType() : GUI_COMMAND_NONE;
}
{
- const Int forceSlot = ControlBar_forceAttackSlot( types, MAX_COMMANDS_PER_SET );
+ const Int forceSlot = ControlBar_forceAttackSlot( types, MAX_COMMANDS_PER_SET, ControlBar_isFiringDefense( obj ) );
const CommandButton *force = forceSlot >= 0 ? findCommandButton( AsciiString( "Command_ForceAttack" ) ) : NULL;
if( force )
{
@@ -421,7 +421,7 @@ void ControlBar::populateCommand( Object *obj )
windowed[ i ] = m_commandWindows[ i ] != NULL;
}
{
- const Int forceSlot = ControlBar_forceAttackSlot( types, MAX_COMMANDS_PER_SET );
+ const Int forceSlot = ControlBar_forceAttackSlot( types, MAX_COMMANDS_PER_SET, ControlBar_isFiringDefense( obj ) );
const CommandButton *force = forceSlot >= 0 ? findCommandButton( AsciiString( "Command_ForceAttack" ) ) : NULL;
if( force )
{
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index f34457463..f5991f9ea 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -4144,14 +4144,25 @@ TEST(controlbar_force_attack_slot_is_under_attack_move)
types[ 10 ] = GUI_COMMAND_ATTACK_MOVE;
types[ 12 ] = GUI_COMMAND_GUARD;
types[ 13 ] = GUI_COMMAND_STOP;
- CHECK_EQ( ControlBar_forceAttackSlot( types, SLOTS ), 11 );
+ CHECK_EQ( ControlBar_forceAttackSlot( types, SLOTS, FALSE ), 11 );
types[ 11 ] = GUI_COMMAND_OBJECT_UPGRADE;
- CHECK_EQ( ControlBar_forceAttackSlot( types, SLOTS ), -1 );
+ CHECK_EQ( ControlBar_forceAttackSlot( types, SLOTS, FALSE ), -1 );
types[ 11 ] = N;
types[ 10 ] = N;
- CHECK_EQ( ControlBar_forceAttackSlot( types, SLOTS ), -1 );
+ CHECK_EQ( ControlBar_forceAttackSlot( types, SLOTS, FALSE ), -1 );
+
+ /* A base defence that shoots has no Attack Move. Patriot (Stop 13, Sell 14) takes 12; Gattling
+ Cannon (mines 12) takes 11 above them; GLA Tunnel Network fills 1 to 14 and gets none */
+ types[ 12 ] = GUI_COMMAND_STOP;
+ types[ 13 ] = GUI_COMMAND_SELL;
+ CHECK_EQ( ControlBar_forceAttackSlot( types, SLOTS, TRUE ), 11 );
+ types[ 11 ] = GUI_COMMAND_PLAYER_UPGRADE;
+ CHECK_EQ( ControlBar_forceAttackSlot( types, SLOTS, TRUE ), 10 );
+ for( Int slot = 0; slot < 14; slot++ )
+ types[ slot ] = GUI_COMMAND_EXIT_CONTAINER;
+ CHECK_EQ( ControlBar_forceAttackSlot( types, SLOTS, TRUE ), -1 );
/* Contra ranger: Attack Move in 15, slot 12 empty. Inject then fit keeps Force Attack in 12
and still maps Attack Move, Guard and Stop to 11, 13 and 14 */
@@ -4161,7 +4172,7 @@ TEST(controlbar_force_attack_slot_is_under_attack_move)
windowed[ slot ] = slot < WINDOWS;
Int ranger[ SLOTS ] = { U, U, U, U, U, N, GUI_COMMAND_SPECIAL_POWER, W, N, W, N, N, N, N,
GUI_COMMAND_ATTACK_MOVE, N, GUI_COMMAND_GUARD, GUI_COMMAND_STOP };
- CHECK_EQ( ControlBar_forceAttackSlot( ranger, SLOTS ), 11 );
+ CHECK_EQ( ControlBar_forceAttackSlot( ranger, SLOTS, FALSE ), 11 );
ranger[ 11 ] = GUI_COMMAND_FORCE_ATTACK;
ControlBar_fitCommandSlots( ranger, windowed, SLOTS, shown );
CHECK_EQ( shown[ 10 ], 14 );