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): turn the fork's conveniences on by default
Olcay Seygan00dc8a8f2013
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cppindex fb969725e..2a0108a2c 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp@@ -992,16 +992,23 @@ GlobalData::GlobalData()m_cameraAdjustSpeed = 0.1f;m_enforceMaxCameraHeight = TRUE;m_useGridHotKeys = FALSE;- m_edgeScrollInWindowedMode = FALSE;- m_snapBuildPlacementTo45 = FALSE;- m_snapCameraRotateTo45 = FALSE;- m_middleMousePans = FALSE;- m_zoomToCursor = FALSE;- m_showHudOverlay = FALSE;- m_showPlacementRangeRing = FALSE;- m_workersReturnToSupply = FALSE;- m_alwaysShowWaypointLines = FALSE;- m_detailedBuildTooltips = FALSE;++ //+ // The fork's own conveniences default ON. They were opt-in at first, which in practice meant+ // nobody saw them: an Options.ini that predates them simply has no such key, so every one of+ // them stayed off and the features looked like they had never been added. Each can still be+ // turned off by name in Options.ini.+ //+ m_edgeScrollInWindowedMode = TRUE;+ m_snapBuildPlacementTo45 = TRUE;+ m_snapCameraRotateTo45 = TRUE;+ m_middleMousePans = TRUE;+ m_zoomToCursor = TRUE;+ m_showHudOverlay = TRUE;+ m_showPlacementRangeRing = TRUE;+ m_workersReturnToSupply = TRUE;+ m_alwaysShowWaypointLines = TRUE;+ m_detailedBuildTooltips = TRUE;m_animateWindows = TRUE;diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cppindex c4e3668a6..dc542ae8c 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp@@ -2338,6 +2338,21 @@ GameMessage::Type CommandTranslator::evaluateContextCommand( Drawable *draw,* The Command Translator translates mouse events into object command messages* such as move_to, attack, etc.*/+//-------------------------------------------------------------------------------------------------+/** SnapCameraRotateTo45: settle the camera heading on the nearest eighth when a rotate ends.+ * Applies to the keyboard rotate as well as the middle-drag one, because MiddleMousePans takes+ * the drag away and the snap would otherwise have nothing left to fire on. */+//-------------------------------------------------------------------------------------------------+static void snapCameraHeadingTo45( void )+{+ if( !TheGlobalData->m_snapCameraRotateTo45 || TheTacticalView == NULL )+ return;++ const Real step = PI / 4.0f;+ Real a = TheTacticalView->getAngle();+ TheTacticalView->setAngle( ((Real)REAL_TO_INT_FLOOR( a / step + (a >= 0.0f ? 0.5f : -0.5f) )) * step );+}+GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage *msg){GameMessage::Type t = msg->getType();@@ -3272,6 +3287,7 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessagecase GameMessage::MSG_META_END_CAMERA_ROTATE_LEFT:DEBUG_ASSERTCRASH(TheInGameUI->isCameraRotatingLeft(), ("Clearing rotate camera left, but it's already clear!"));TheInGameUI->setCameraRotateLeft( false );+ snapCameraHeadingTo45();break;case GameMessage::MSG_META_BEGIN_CAMERA_ROTATE_RIGHT:DEBUG_ASSERTCRASH(!TheInGameUI->isCameraRotatingRight(), ("Setting rotate camera right, but it's already set!"));@@ -3280,6 +3296,7 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessagecase GameMessage::MSG_META_END_CAMERA_ROTATE_RIGHT:DEBUG_ASSERTCRASH(TheInGameUI->isCameraRotatingRight(), ("Clearing rotate camera right, but it's already clear!"));TheInGameUI->setCameraRotateRight( false );+ snapCameraHeadingTo45();break;case GameMessage::MSG_META_BEGIN_CAMERA_ZOOM_IN:DEBUG_ASSERTCRASH(!TheInGameUI->isCameraZoomingIn(), ("Setting zoom camera in, but it's already set!"));diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cppindex 34f0fde74..72a0d88db 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp@@ -3730,37 +3730,50 @@ void AIAttackMoveToState::stopEngaging( void )//----------------------------------------------------------------------------------------------------------/**- * True when the approach has pulled us further than ATTACK_MOVE_LEASH_CELLS from the spot where we- * picked the victim. Computer and script attack moves keep their retail chase behavior.+ * The leash rule itself, with no Object involved so test_gameengine can link straight to it.+ * Free function (not a member, not static) for that reason - the same trick as+ * GameEngine_isLogicFrameDue.+ *+ * A human player's ground unit is pulled off its attack move once the fight has dragged it more+ * than ATTACK_MOVE_LEASH_CELLS from where it picked the victim. Computer and script attack moves+ * keep their retail chase behavior and are never leashed here.+ *+ * Aircraft are never leashed either. The leash exists to stop a ground unit being walked off its+ * attack move by a target that backs away, and it is measured from where the target was acquired -+ * but an aircraft acquires out to its weapon range, which is far longer than the leash is. It+ * therefore broke the leash on the way in, every time, and disengaged before it was ever in range+ * to fire; the requireProgressTowardGoal() that follows then flew it further down the path before+ * it was allowed to try again. The net effect was an aircraft that picked target after target,+ * never shot at any of them, and never spent the ammunition that would have sent it home.+ * What bounds an aircraft is its ammunition, not distance.*/-Bool AIAttackMoveToState::hasLeftTheLeash( void )+Bool AIAttackMove_leashBroken( Bool isHumanPlayer, Bool isAirborne, Real dx, Real dy, Int leashCells ){- if (!m_isEngaging)+ if (!isHumanPlayer)return FALSE;- Object *owner = getMachineOwner();- if (owner->getControllingPlayer()->getPlayerType() != PLAYER_HUMAN)+ if (isAirborne)return FALSE;- //- // Aircraft are not leashed. The leash keeps a ground unit from being walked off its attack move- // by a target that backs away, and it is measured from where the target was acquired - but an- // aircraft acquires out to its weapon range, which is far longer than the leash. It therefore- // broke the leash on the way in, every time, and disengaged before firing a shot; the- // requireProgressTowardGoal() that follows then flew it further down the path before it was- // allowed to try again. The net effect was an aircraft that picked target after target,- // never shot at any of them, and never ran its tanks dry enough to go home.- //- // What bounds an aircraft is its ammunition, not distance: it empties its load and JetAIUpdate- // takes it home to reload (and, since the attack move is a standing order, picks the order back- // up afterwards).- //- if (owner->isUsingAirborneLocomotor())+ return (dx*dx + dy*dy) > sqr(leashCells*PATHFIND_CELL_SIZE_F);+}++//----------------------------------------------------------------------------------------------------------+/**+ * True when the fight has pulled us off the attack move; see AIAttackMove_leashBroken above.+ */+Bool AIAttackMoveToState::hasLeftTheLeash( void )+{+ if (!m_isEngaging)return FALSE;- Real dx = owner->getPosition()->x - m_engageOrigin.x;- Real dy = owner->getPosition()->y - m_engageOrigin.y;- return (dx*dx + dy*dy) > sqr(ATTACK_MOVE_LEASH_CELLS*PATHFIND_CELL_SIZE_F);+ Object *owner = getMachineOwner();+ return AIAttackMove_leashBroken(+ owner->getControllingPlayer()->getPlayerType() == PLAYER_HUMAN,+ owner->isUsingAirborneLocomotor(),+ owner->getPosition()->x - m_engageOrigin.x,+ owner->getPosition()->y - m_engageOrigin.y,+ ATTACK_MOVE_LEASH_CELLS );}//----------------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 2a3cf120a..1113e06af 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -511,3 +511,37 @@ TEST(physics_forward_speed_is_the_projection_not_a_per_axis_norm)Coord3D climb; climb.x = 0.0f; climb.y = 0.0f; climb.z = 12.0f;CHECK_NEAR( PhysicsBehavior::calcForwardSpeed( climb, up ), 12.0f, 0.01f );}++/* AIStates.cpp: an attack move leashes a human player's ground unit so a target+ that backs away cannot walk it off the order. Aircraft must be exempt: they+ acquire out to weapon range, which is far beyond the leash, so they broke it on+ the way in every time and disengaged before ever being in range to fire - which+ also meant they never spent the ammunition that sends them home to reload. */+extern Bool AIAttackMove_leashBroken( Bool isHumanPlayer, Bool isAirborne, Real dx, Real dy, Int leashCells );++TEST(attack_move_leashes_ground_units_but_never_aircraft)+{+ /* PATHFIND_CELL_SIZE_F is 10 and ATTACK_MOVE_LEASH_CELLS is 12, so the leash+ is 120 world units for a human player's ground unit. */+ const Real cell = 10.0f;+ const Int LEASH = 12; /* ATTACK_MOVE_LEASH_CELLS, which is protected on the state */++ /* a ground unit: inside the leash it keeps fighting, past it the fight is off. */+ CHECK( !AIAttackMove_leashBroken( true, false, 0.0f, 0.0f, LEASH ) );+ CHECK( !AIAttackMove_leashBroken( true, false, 11.0f*cell, 0.0f, LEASH ) );+ CHECK( AIAttackMove_leashBroken( true, false, 13.0f*cell, 0.0f, LEASH ) );+ CHECK( AIAttackMove_leashBroken( true, false, 0.0f, 13.0f*cell, LEASH ) );+ /* measured as a radius, not per axis */+ CHECK( AIAttackMove_leashBroken( true, false, 10.0f*cell, 10.0f*cell, LEASH ) );++ /* an aircraft is never leashed, however far the fight has taken it - this is+ the case that used to fire on the way in to every single target. */+ CHECK( !AIAttackMove_leashBroken( true, true, 13.0f*cell, 0.0f, LEASH ) );+ CHECK( !AIAttackMove_leashBroken( true, true, 100.0f*cell, 0.0f, LEASH ) );+ CHECK( !AIAttackMove_leashBroken( true, true, 500.0f*cell, 500.0f*cell, LEASH ) );++ /* the computer and scripts keep retail chase behaviour: never leashed here,+ airborne or not. */+ CHECK( !AIAttackMove_leashBroken( false, false, 500.0f*cell, 0.0f, LEASH ) );+ CHECK( !AIAttackMove_leashBroken( false, true, 500.0f*cell, 0.0f, LEASH ) );+}