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): hold position, windowed edge scroll and 45 degree placement snap

Olcay Seygan4396433b9259
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
index 4bcf1e1a3..00e1546d6 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
@@ -324,6 +324,8 @@ public:
Real m_cameraAdjustSpeed; ///< Rate at which we adjust camera height
Bool m_enforceMaxCameraHeight; ///< Enfoce max camera height while scrolling?
Bool m_useGridHotKeys; ///< command bar keys come from the slot grid, not the '&' letter in each button's label
+ Bool m_edgeScrollInWindowedMode; ///< allow screen-edge scrolling while running in a window
+ Bool m_snapBuildPlacementTo45; ///< quantize the drag-to-rotate build placement angle to 45 degrees
Bool m_buildMapCache;
AsciiString m_initialFile; ///< If this is specified, load a specific map/replay from the command-line
AsciiString m_pendingFile; ///< If this is specified, use this map at the next game start
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h
index 328523698..46dd0b497 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h
@@ -288,6 +288,7 @@ public:
MSG_META_TAKE_SCREENSHOT, ///< take screenshot
MSG_META_ALL_CHEER, ///< Yay! :)
MSG_META_TOGGLE_ATTACKMOVE, ///< enter attack-move mode
+ MSG_META_HOLD_POSITION, ///< hold position: guard in place, no pursuit (fork)
MSG_META_BEGIN_CAMERA_ROTATE_LEFT,
MSG_META_END_CAMERA_ROTATE_LEFT,
@@ -623,6 +624,7 @@ public:
MSG_LOGIC_CRC, ///< CRC from the logic passed around in a network game :)
MSG_SET_MINE_CLEARING_DETAIL, ///< CRC from the logic passed around in a network game :)
MSG_ENABLE_RETALIATION_MODE, ///< Turn retaliation mode on or off for the specified player.
+ MSG_DO_HOLD_POSITION, ///< Every selected unit guards the spot it is standing on (fork)
MSG_BEGIN_DEBUG_NETWORK_MESSAGES = 1900, ///< network messages that exist only in debug/internal builds. all grouped separately.
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.h b/GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.h
index 3011783ce..8e3546ca8 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.h
@@ -109,6 +109,8 @@ public:
Real getGammaValue(void);
Real getMaxCameraHeight(void);
Bool getUseGridHotKeys(void);
+ Bool getEdgeScrollInWindowedMode(void);
+ Bool getSnapBuildPlacementTo45(void);
Int getTextureReduction(void);
void getResolution(Int *xres, Int *yres);
Bool get3DShadowsEnabled(void);
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameLOD.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameLOD.cpp
index 2f0b67879..97a214241 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GameLOD.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameLOD.cpp
@@ -365,6 +365,8 @@ void GameLODManager::init(void)
// Grid command-bar keys are an input scheme, not a detail level either.
TheWritableGlobalData->m_useGridHotKeys = optionPref.getUseGridHotKeys();
+ TheWritableGlobalData->m_edgeScrollInWindowedMode = optionPref.getEdgeScrollInWindowedMode();
+ TheWritableGlobalData->m_snapBuildPlacementTo45 = optionPref.getSnapBuildPlacementTo45();
setStaticLODLevel(userSetDetail);
}
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
index eb96cac69..d5e17b880 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
@@ -181,6 +181,8 @@ GlobalData* GlobalData::m_theOriginal = NULL;
{ "CameraHeight", INI::parseReal, NULL, offsetof( GlobalData, m_cameraHeight ) },
{ "MaxCameraHeight", INI::parseReal, NULL, offsetof( GlobalData, m_maxCameraHeight ) },
{ "UseGridHotKeys", INI::parseBool, NULL, offsetof( GlobalData, m_useGridHotKeys ) },
+ { "EdgeScrollInWindowedMode", INI::parseBool, NULL, offsetof( GlobalData, m_edgeScrollInWindowedMode ) },
+ { "SnapBuildPlacementTo45", INI::parseBool, NULL, offsetof( GlobalData, m_snapBuildPlacementTo45 ) },
{ "MinCameraHeight", INI::parseReal, NULL, offsetof( GlobalData, m_minCameraHeight ) },
{ "TerrainHeightAtEdgeOfMap", INI::parseReal, NULL, offsetof( GlobalData, m_terrainHeightAtEdgeOfMap ) },
{ "UnitDamagedThreshold", INI::parseReal, NULL, offsetof( GlobalData, m_unitDamagedThresh ) },
@@ -982,6 +984,8 @@ GlobalData::GlobalData()
m_cameraAdjustSpeed = 0.1f;
m_enforceMaxCameraHeight = TRUE;
m_useGridHotKeys = FALSE;
+ m_edgeScrollInWindowedMode = FALSE;
+ m_snapBuildPlacementTo45 = FALSE;
m_animateWindows = TRUE;
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp
index beb1267ef..e252e19ca 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp
@@ -393,6 +393,7 @@ AsciiString GameMessage::getCommandTypeAsAsciiString(GameMessage::Type t)
CHECK_IF(MSG_META_TAKE_SCREENSHOT)
CHECK_IF(MSG_META_ALL_CHEER)
CHECK_IF(MSG_META_TOGGLE_ATTACKMOVE)
+ CHECK_IF(MSG_META_HOLD_POSITION)
CHECK_IF(MSG_META_BEGIN_CAMERA_ROTATE_LEFT)
CHECK_IF(MSG_META_END_CAMERA_ROTATE_LEFT)
CHECK_IF(MSG_META_BEGIN_CAMERA_ROTATE_RIGHT)
@@ -663,6 +664,7 @@ AsciiString GameMessage::getCommandTypeAsAsciiString(GameMessage::Type t)
CHECK_IF(MSG_DO_FORCEMOVETO)
CHECK_IF(MSG_ADD_WAYPOINT)
CHECK_IF(MSG_DO_GUARD_POSITION)
+ CHECK_IF(MSG_DO_HOLD_POSITION)
CHECK_IF(MSG_DO_GUARD_OBJECT)
CHECK_IF(MSG_DO_STOP)
CHECK_IF(MSG_DO_SCATTER)
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
index dd4a92449..410e03673 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
@@ -736,6 +736,30 @@ Bool OptionPreferences::getUseGridHotKeys(void)
return stricmp(it->second.str(), "yes") == 0;
}
+Bool OptionPreferences::getEdgeScrollInWindowedMode(void)
+{
+ // Another power-user Options.ini key. Retail refuses to edge-scroll in a window because the
+ // cursor can legitimately sit on the border while you reach for something else; on a second
+ // monitor (or borderless) that is exactly the behaviour you want back.
+ OptionPreferences::const_iterator it = find("EdgeScrollInWindowedMode");
+ if (it == end())
+ return TheGlobalData->m_edgeScrollInWindowedMode;
+
+ return stricmp(it->second.str(), "yes") == 0;
+}
+
+Bool OptionPreferences::getSnapBuildPlacementTo45(void)
+{
+ // Power-user Options.ini key. Drag-to-rotate placement is free-angle in retail; with this on
+ // it clicks to the eight 45 degree headings, which is what you want for walls and for lining
+ // defenses up with a base.
+ OptionPreferences::const_iterator it = find("SnapBuildPlacementTo45");
+ if (it == end())
+ return TheGlobalData->m_snapBuildPlacementTo45;
+
+ return stricmp(it->second.str(), "yes") == 0;
+}
+
Int OptionPreferences::getTextureReduction(void)
{
OptionPreferences::const_iterator it = find("TextureReduction");
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index 48b977334..4ed16fc71 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -1440,6 +1440,14 @@ void InGameUI::handleBuildPlacements( void )
v.y = worldEnd.y - worldStart.y;
angle = v.toAngle();
+ // optional 45 degree snap (SnapBuildPlacementTo45 in Options.ini) - lines walls and
+ // defenses up with the base instead of leaving them at whatever the drag produced.
+ if( TheGlobalData->m_snapBuildPlacementTo45 )
+ {
+ const Real step = PI / 4.0f;
+ angle = ((Real)REAL_TO_INT_FLOOR( angle / step + (angle >= 0.0f ? 0.5f : -0.5f) )) * step;
+ }
+
} // end if
} // end if
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
index 9eed7144a..67e4f7762 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
@@ -3202,6 +3202,22 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
TheInGameUI->toggleAttackMoveToMode( );
break;
+ //
+ // Hold position: every selected unit guards the spot it is standing on and does not
+ // pursue. The location has to be resolved per unit on the logic side, so this carries
+ // only the guard mode - see MSG_DO_HOLD_POSITION in GameLogicDispatch.
+ //
+ case GameMessage::MSG_META_HOLD_POSITION:
+ {
+ if( TheInGameUI->getSelectCount() > 0 )
+ {
+ GameMessage *holdMsg = TheMessageStream->appendMessage( GameMessage::MSG_DO_HOLD_POSITION );
+ holdMsg->appendIntegerArgument( GUARDMODE_GUARD_WITHOUT_PURSUIT );
+ disp = DESTROY_MESSAGE;
+ }
+ break;
+ }
+
case GameMessage::MSG_META_BEGIN_CAMERA_ROTATE_LEFT:
DEBUG_ASSERTCRASH(!TheInGameUI->isCameraRotatingLeft(), ("Setting rotate camera left, but it's already set!"));
TheInGameUI->setCameraRotateLeft( true );
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp
index 36a62f2e5..d10063088 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp
@@ -298,7 +298,9 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage
break;
}
- if (!TheGlobalData->m_windowed)
+ // retail disables edge scrolling entirely in a window; EdgeScrollInWindowedMode in
+ // Options.ini turns it back on for people who play windowed or borderless.
+ if (!TheGlobalData->m_windowed || TheGlobalData->m_edgeScrollInWindowedMode)
{
if (m_isScrolling)
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp
index 48ac8498c..086393d91 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp
@@ -175,6 +175,7 @@ static const LookupListRec GameMessageMetaTypeNames[] =
{ "SCATTER", GameMessage::MSG_META_SCATTER },
{ "STOP", GameMessage::MSG_META_STOP },
{ "TOGGLE_ATTACKMOVE", GameMessage::MSG_META_TOGGLE_ATTACKMOVE },
+ { "HOLD_POSITION", GameMessage::MSG_META_HOLD_POSITION },
{ "DEPLOY", GameMessage::MSG_META_DEPLOY },
{ "CREATE_FORMATION", GameMessage::MSG_META_CREATE_FORMATION },
{ "FOLLOW", GameMessage::MSG_META_FOLLOW },
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
index 02b70873d..5bebfeca2 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
@@ -896,6 +896,33 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )
break;
}
+ //---------------------------------------------------------------------------------------------
+ //
+ // Hold position (fork). MSG_DO_GUARD_POSITION guards ONE point with the whole group, which
+ // makes everyone walk to it; hold position means each unit guards where it already stands,
+ // so the position is resolved here, per member.
+ //
+ case GameMessage::MSG_DO_HOLD_POSITION:
+ {
+ GuardMode gm = (GuardMode)msg->getArgument( 0 )->integer;
+ if (currentlySelectedGroup)
+ {
+ const VecObjectID& ids = currentlySelectedGroup->getAllIDs();
+ for (VecObjectID::const_iterator it = ids.begin(); it != ids.end(); ++it)
+ {
+ Object *obj = TheGameLogic->findObjectByID( *it );
+ if (!obj || obj->getControllingPlayer() != thisPlayer)
+ continue;
+
+ AIUpdateInterface *ai = obj->getAIUpdateInterface();
+ if (ai)
+ ai->aiGuardPosition( obj->getPosition(), gm, CMD_FROM_PLAYER );
+ }
+ }
+
+ break;
+ }
+
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_DO_GUARD_OBJECT:
{