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(gameengine): place a blocked structure at the nearest legal spot
Olcay Seygan54029d0c4510
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 5db5c17f1..fa6c13656 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -185,6 +185,7 @@ found and fixed — EA's own, not port damage.**- The placement grid is drawn on the ground and follows the slope.- Unbuildable ground is a soft red wash, crossed out square by square.- Running out of money no longer strands the ghost on the map.+- A building you point at blocked ground slides to the nearest spot it fits, and lands there.- GLA defences get a range ring while you site them.- A click clears a half-typed building shortcut.- The two-key building shortcut survives the command bar's redraw now.diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.hindex 139be6c78..55f998e4c 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h@@ -334,6 +334,7 @@ public:Bool m_snapBuildPlacementTo45; ///< quantize the drag-to-rotate build placement angle to 45 degreesBool m_snapCameraRotateTo45; ///< quantize the camera heading to 45 degrees when a middle-drag rotate endsBool m_gridBuildPlacement; ///< quantize structure placement to the pathfinder's build grid+ Bool m_nudgeBuildPlacement; ///< slide a blocked structure to the nearest spot it does fitBool m_middleMousePans; ///< middle-button drag pans the camera instead of rotating itBool m_zoomToCursor; ///< the mouse wheel zooms toward whatever the cursor is overBool m_showHudOverlay; ///< draw the fps / elapsed time / income line in the cornerdiff --git a/GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.h b/GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.hindex 4af4e21a6..4575dc78c 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.h@@ -112,6 +112,7 @@ public:Bool getSnapBuildPlacementTo45(void);Bool getSnapCameraRotateTo45(void);Bool getGridBuildPlacement(void);+ Bool getNudgeBuildPlacement(void);Bool getMiddleMousePans(void);Bool getZoomToCursor(void);Bool getShowHudOverlay(void);diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.hindex 9b8c80b75..0b908b1c8 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h@@ -483,6 +483,70 @@ public: // ********************************************************************return ((Real)REAL_TO_INT_FLOOR( (v - offset) / cell + 0.5f )) * cell + offset;}+ /** NudgeBuildPlacement: when the spot under the cursor is blocked, slide the structure to the+ * nearest one it does fit and show it there, so the ghost answers "here, then" instead of just+ * going red. Moves 'world' and returns TRUE if it found somewhere; leaves it alone otherwise. */+ virtual Bool nudgePlacementToLegal( Coord3D *world, const ThingTemplate *what, Real angle,+ Object *builderObject ) const;++ /** What the ghost asks of a spot before it goes green. One place, because the nudge search has+ * to ask exactly the same question or it would offer a spot the ghost then paints red. */+ static UnsignedInt placementCheckOptions( void );+ enum { PLACEMENT_NUDGE_PATHFINDS = 12 }; ///< unreachable candidates tolerated before the search gives up++ /** The offsets that search tries: every cell of a square this many rings across, ordered by+ * true distance so that "the first one that fits" is "the nearest one that fits". Ring by+ * ring would not be that ordering - from three rings out, a ring's own diagonal (1.41 cells)+ * is farther than the next ring's straight neighbour - and sampling only the eight compass+ * directions, as this first did, walks straight past the gap one cell to the side of them.+ * The table is built and sorted once, on the first placement of the session. Inline and+ * static so a test can check the ordering without linking the whole in-game UI. */+ enum { PLACEMENT_NUDGE_RINGS = 10 }; ///< how far out to look, in grid cells+ enum { PLACEMENT_NUDGE_SPAN = 2 * PLACEMENT_NUDGE_RINGS + 1 };+ enum { PLACEMENT_NUDGE_TRIES = PLACEMENT_NUDGE_SPAN * PLACEMENT_NUDGE_SPAN - 1 };+ static void placementNudgeOffset( Int index, Real step, Real *dx, Real *dy )+ {+ static Int cellX[ PLACEMENT_NUDGE_TRIES ];+ static Int cellY[ PLACEMENT_NUDGE_TRIES ];+ static Bool ordered = FALSE;++ if( ordered == FALSE )+ {+ Int n = 0;+ for( Int y = -PLACEMENT_NUDGE_RINGS; y <= PLACEMENT_NUDGE_RINGS; y++ )+ for( Int x = -PLACEMENT_NUDGE_RINGS; x <= PLACEMENT_NUDGE_RINGS; x++ )+ if( x != 0 || y != 0 ) // the spot the player is pointing at is the one that failed+ {+ cellX[ n ] = x;+ cellY[ n ] = y;+ n++;+ }++ // insertion sort by distance; it runs once for the whole session, and being in distance+ // order is the entire contract of this list+ for( Int i = 1; i < PLACEMENT_NUDGE_TRIES; i++ )+ {+ const Int keyX = cellX[ i ];+ const Int keyY = cellY[ i ];+ const Int keyD = keyX * keyX + keyY * keyY;+ Int j = i - 1;++ while( j >= 0 && cellX[ j ] * cellX[ j ] + cellY[ j ] * cellY[ j ] > keyD )+ {+ cellX[ j + 1 ] = cellX[ j ];+ cellY[ j + 1 ] = cellY[ j ];+ j--;+ }+ cellX[ j + 1 ] = keyX;+ cellY[ j + 1 ] = keyY;+ }++ ordered = TRUE;+ }++ *dx = cellX[ index ] * step;+ *dy = cellY[ index ] * step;+ }virtual void setPlacementAngle( Real angle ); ///< aim the structure on the cursor, and keep that heading for the next onevirtual Bool rotatePendingPlacement( Int steps ); ///< turn the structure on the cursor by 45 degrees a step@@ -805,6 +869,7 @@ protected:ICoord2D m_placeAnchorEnd; ///< place angle anchor endReal m_placeAngleOffset; ///< wheel-chosen heading, added to every structure's own view angleBool m_placementLegal; ///< last legality verdict for the spot under the structure being placed+ Coord3D m_placementNudge; ///< how far the last legality check had to slide the structure to make it fitInt m_selectCount; ///< Number of objects currently "selected"Int m_maxSelectCount; ///< Max number of objects to selectUnsignedInt m_frameSelectionChanged; ///< Frame when the selection last changed.diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameLOD.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameLOD.cppindex 0c7cff4fb..72b5d4924 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GameLOD.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameLOD.cpp@@ -368,6 +368,7 @@ void GameLODManager::init(void)TheWritableGlobalData->m_snapBuildPlacementTo45 = optionPref.getSnapBuildPlacementTo45();TheWritableGlobalData->m_snapCameraRotateTo45 = optionPref.getSnapCameraRotateTo45();TheWritableGlobalData->m_gridBuildPlacement = optionPref.getGridBuildPlacement();+ TheWritableGlobalData->m_nudgeBuildPlacement = optionPref.getNudgeBuildPlacement();TheWritableGlobalData->m_middleMousePans = optionPref.getMiddleMousePans();TheWritableGlobalData->m_zoomToCursor = optionPref.getZoomToCursor();TheWritableGlobalData->m_showHudOverlay = optionPref.getShowHudOverlay();diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cppindex 8aa8b5f2e..6b39691fb 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp@@ -191,6 +191,7 @@ GlobalData* GlobalData::m_theOriginal = NULL;{ "SnapBuildPlacementTo45", INI::parseBool, NULL, offsetof( GlobalData, m_snapBuildPlacementTo45 ) },{ "SnapCameraRotateTo45", INI::parseBool, NULL, offsetof( GlobalData, m_snapCameraRotateTo45 ) },{ "GridBuildPlacement", INI::parseBool, NULL, offsetof( GlobalData, m_gridBuildPlacement ) },+ { "NudgeBuildPlacement", INI::parseBool, NULL, offsetof( GlobalData, m_nudgeBuildPlacement ) },{ "MiddleMousePans", INI::parseBool, NULL, offsetof( GlobalData, m_middleMousePans ) },{ "ZoomToCursor", INI::parseBool, NULL, offsetof( GlobalData, m_zoomToCursor ) },{ "ShowHudOverlay", INI::parseBool, NULL, offsetof( GlobalData, m_showHudOverlay ) },@@ -1037,6 +1038,7 @@ GlobalData::GlobalData()m_snapBuildPlacementTo45 = TRUE;m_snapCameraRotateTo45 = TRUE;m_gridBuildPlacement = TRUE;+ m_nudgeBuildPlacement = TRUE;// middle-drag stays a rotate by default (it snaps to 45 degrees on release); pan is opt-inm_middleMousePans = FALSE;m_zoomToCursor = TRUE;diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cppindex 7f57b3202..24eb0bba3 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp@@ -772,6 +772,18 @@ Bool OptionPreferences::getGridBuildPlacement(void)return stricmp(it->second.str(), "yes") == 0;}+Bool OptionPreferences::getNudgeBuildPlacement(void)+{+ // Options.ini key. A structure whose spot is blocked slides to the nearest one it does fit+ // instead of just going red under the cursor, so a base can be laid out by pointing roughly at+ // where each building goes. Off restores the retail "find the legal pixel yourself" placement.+ OptionPreferences::const_iterator it = find("NudgeBuildPlacement");+ if (it == end())+ return TheGlobalData->m_nudgeBuildPlacement;++ return stricmp(it->second.str(), "yes") == 0;+}+Bool OptionPreferences::getMiddleMousePans(void){OptionPreferences::const_iterator it = find("MiddleMousePans");diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex fa07e3506..cf89a71cf 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -82,6 +82,7 @@#include "GameLogic/Object.h"#include "GameLogic/GameLogic.h"#include "GameLogic/PartitionManager.h"+#include "GameLogic/TerrainLogic.h"#include "GameLogic/ScriptEngine.h"#include "GameLogic/Module/ContainModule.h"#include "GameLogic/Module/ProductionUpdate.h"@@ -1036,6 +1037,7 @@ InGameUI::InGameUI()m_placeAnchorInProgress = FALSE;m_placeAngleOffset = 0.0f;m_placementLegal = TRUE;+ m_placementNudge.zero();m_videoStream = NULL;m_videoBuffer = NULL;@@ -1636,6 +1638,21 @@ void InGameUI::handleBuildPlacements( void )to do is set a simple angle and have it automatically change, ug! */TheTacticalView->screenToTerrain( &loc, &world );snapPlacementToGrid( &world, m_pendingPlaceType, angle );++ //+ // NudgeBuildPlacement: the ghost sits where the last legality check found room, which is+ // the cursor itself whenever the cursor works. The check below runs every other frame and+ // always measures from the cursor, never from an already-nudged spot, so the offset cannot+ // walk away from the mouse; the ghost is at most one frame behind it.+ //+ const Coord3D cursorWorld = world;+ if( m_placementNudge.x != 0.0f || m_placementNudge.y != 0.0f )+ {+ world.x += m_placementNudge.x;+ world.y += m_placementNudge.y;+ world.z = TheTerrainLogic->getGroundHeight( world.x, world.y );+ }+m_placeIcon[ 0 ]->setPosition( &world );m_placeIcon[ 0 ]->setOrientation( angle );@@ -1654,18 +1671,45 @@ void InGameUI::handleBuildPlacements( void )Object *builderObject = TheGameLogic->findObjectByID( getPendingPlaceSourceObjectID() );+ const UnsignedInt checkOptions = placementCheckOptions();+ Coord3D spot = cursorWorld;LegalBuildCode lbc;- lbc = TheBuildAssistant->isLocationLegalToBuild( &world,- m_pendingPlaceType,- angle,- BuildAssistant::USE_QUICK_PATHFIND |- BuildAssistant::TERRAIN_RESTRICTIONS |- BuildAssistant::CLEAR_PATH |- BuildAssistant::NO_OBJECT_OVERLAP |- BuildAssistant::SHROUD_REVEALED |- BuildAssistant::IGNORE_STEALTHED,- builderObject,- NULL );+ lbc = TheBuildAssistant->isLocationLegalToBuild( &spot, m_pendingPlaceType, angle,+ checkOptions, builderObject, NULL );++ //+ // Blocked: look for the nearest spot that is not, and move the ghost there - the click+ // does the same search (see PlaceEventTranslator), so what you see is where it lands.+ // Shroud is left alone on purpose: unscouted ground is not a placement mistake to fix,+ // and hunting around in it would answer questions about ground you cannot see.+ //+ m_placementNudge.zero();+ if( lbc != LBC_OK && lbc != LBC_SHROUD )+ {+ const Bool moved = nudgePlacementToLegal( &spot, m_pendingPlaceType, angle,+ builderObject );++ //+ // Either way the search has just painted a red bib on everything it bumped into on+ // the way out, which is a report on spots nobody is proposing. Clear them, and if+ // there was nowhere to go, ask about the spot under the cursor once more so the one+ // bib that does explain the refusal comes back.+ //+ TheTerrainVisual->removeAllBibs();++ if( moved )+ {+ m_placementNudge.x = spot.x - cursorWorld.x;+ m_placementNudge.y = spot.y - cursorWorld.y;+ lbc = LBC_OK;+ }+ else+ {+ TheBuildAssistant->isLocationLegalToBuild( &cursorWorld, m_pendingPlaceType, angle,+ checkOptions, builderObject, NULL );+ }+ }+// the cursor reads this too - see createCommandHint's MOUSEMODE_BUILD_PLACE casem_placementLegal = ( lbc == LBC_OK );@@ -3330,6 +3374,7 @@ void InGameUI::placeBuildAvailable( const ThingTemplate *build, Drawable *buildD{m_mouseMode = MOUSEMODE_BUILD_PLACE;m_placementLegal = TRUE;+ m_placementNudge.zero();m_mouseModeCursor = placementCursor( TRUE );Drawable *draw;@@ -3576,6 +3621,94 @@ void InGameUI::snapPlacementToGrid( Coord3D *world, const ThingTemplate *what, R} // end snapPlacementToGrid+//-------------------------------------------------------------------------------------------------+/** The legality question asked of the spot under the ghost, in one place - the nudge search asks it+ * of every candidate too. IGNORE_STEALTHED is deliberate: a structure you cannot put down is a+ * place a stealthed unit is standing, and the placement cursor is not a detector. The click+ * re-asks with FAIL_STEALTHED_WITHOUT_FEEDBACK, which is where that actually gets decided. */+//-------------------------------------------------------------------------------------------------+UnsignedInt InGameUI::placementCheckOptions( void )+{+ return BuildAssistant::USE_QUICK_PATHFIND |+ BuildAssistant::TERRAIN_RESTRICTIONS |+ BuildAssistant::CLEAR_PATH |+ BuildAssistant::NO_OBJECT_OVERLAP |+ BuildAssistant::SHROUD_REVEALED |+ BuildAssistant::IGNORE_STEALTHED;++} // end placementCheckOptions++//-------------------------------------------------------------------------------------------------+/** NudgeBuildPlacement (Options.ini): the spot under the cursor is blocked - a rock, a neighbour's+ * bib, ground too steep by a hair - so find the nearest one that is not and put the structure+ * there instead of turning it red and leaving the player to hunt for the legal pixel by hand.+ *+ * Nearest is meant literally: candidates come out of placementNudgeOffset in distance order, so+ * the first one that fits is the closest one that fits. A step is one pathfinder cell, which is+ * also what GridBuildPlacement snaps to, so a nudged structure stays on the same grid as the ones+ * already down.+ *+ * The cost is in the pathfind, not in the ground: EA's own comment on the caller says the check+ * is too expensive to run every frame, and that is the CLEAR_PATH half of it. So the sweep asks+ * the cheap questions first - shroud, overlap, terrain - across all PLACEMENT_NUDGE_TRIES cells,+ * and only spends a pathfind on a cell that already passed those.+ *+ * ponytail: reaches PLACEMENT_NUDGE_RINGS cells (100 units) and gives up, and gives up sooner+ * after PLACEMENT_NUDGE_PATHFINDS unreachable candidates. Both are flat numbers; scale them off+ * the structure's own footprint if a supply centre still ends up hunting too far. */+//-------------------------------------------------------------------------------------------------+Bool InGameUI::nudgePlacementToLegal( Coord3D *world, const ThingTemplate *what, Real angle,+ Object *builderObject ) const+{+ if( world == NULL || what == NULL || TheGlobalData->m_nudgeBuildPlacement == FALSE )+ return FALSE;++ // a wall tiles from the two points you dragged between; sliding one end off that line is not help+ if( TheBuildAssistant->isLineBuildTemplate( what ) )+ return FALSE;++ // CLEAR_PATH is the pathfind, and USE_QUICK_PATHFIND only says which one it uses+ const UnsignedInt fullOptions = placementCheckOptions();+ const UnsignedInt groundOptions = fullOptions & ~BuildAssistant::CLEAR_PATH;+ Int pathfinds = 0;++ for( Int i = 0; i < PLACEMENT_NUDGE_TRIES; i++ )+ {+ Real dx, dy;+ placementNudgeOffset( i, (Real)PLACEMENT_CELL, &dx, &dy );++ Coord3D test = *world;+ test.x += dx;+ test.y += dy;+ test.z = TheTerrainLogic->getGroundHeight( test.x, test.y );++ // is there room at all? cheap, and it throws out all but a handful of the candidates+ if( TheBuildAssistant->isLocationLegalToBuild( &test, what, angle, groundOptions,+ builderObject, NULL ) != LBC_OK )+ continue;++ // there is - can the builder actually walk to it?+ if( TheBuildAssistant->isLocationLegalToBuild( &test, what, angle, fullOptions,+ builderObject, NULL ) == LBC_OK )+ {+ *world = test;+ return TRUE;+ }++ //+ // Room the builder cannot reach - across a cliff, behind a wall. A few of those are+ // normal near the edge of a base; a lot of them means the whole neighbourhood is cut off,+ // and there is no sense pathfinding to every cell of it twice a frame.+ //+ if( ++pathfinds >= PLACEMENT_NUDGE_PATHFINDS )+ break;++ } // end for i++ return FALSE;++} // end nudgePlacementToLegal+//-------------------------------------------------------------------------------------------------/** Aim the structure sitting on the cursor at 'angle', and keep that heading for the placementsdiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cppindex 5975f21b1..97542ec7f 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp@@ -308,18 +308,27 @@ GameMessageDisposition PlaceEventTranslator::translateGameMessage(const GameMess}// check to see if this is a legal location to build something at+ // what the ghost was asking all along, plus the one question it does not ask: the+ // placement cursor ignores stealthed units, committing to the spot does not+ const UnsignedInt placeOptions = InGameUI::placementCheckOptions() |+ BuildAssistant::FAIL_STEALTHED_WITHOUT_FEEDBACK;LegalBuildCode lbc;- lbc = TheBuildAssistant->isLocationLegalToBuild( &world,- build,- angle,- BuildAssistant::USE_QUICK_PATHFIND |- BuildAssistant::TERRAIN_RESTRICTIONS |- BuildAssistant::CLEAR_PATH |- BuildAssistant::NO_OBJECT_OVERLAP |- BuildAssistant::SHROUD_REVEALED |- BuildAssistant::IGNORE_STEALTHED |- BuildAssistant::FAIL_STEALTHED_WITHOUT_FEEDBACK,+ lbc = TheBuildAssistant->isLocationLegalToBuild( &world, build, angle, placeOptions,builderObj, NULL );++ //+ // NudgeBuildPlacement: blocked where they clicked, so build at the nearest spot that+ // is not - the same search the ghost was already showing them (InGameUI::update ->+ // handleBuildPlacements), so the structure goes down where they were looking. The+ // verdict is taken again at the new spot rather than assumed: this check is the+ // stricter one, it fails on a stealthed unit the ghost is told to ignore.+ //+ if( lbc != LBC_OK && lbc != LBC_SHROUD &&+ TheInGameUI->nudgePlacementToLegal( &world, build, angle, builderObj ) )+ {+ lbc = TheBuildAssistant->isLocationLegalToBuild( &world, build, angle, placeOptions,+ builderObj, NULL );+ }if( lbc == LBC_OK ){//Are we building this structure via the special power system? (special case for sneak attack)diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 5453cac37..7d6d64a3a 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -1514,6 +1514,58 @@ TEST(command_availability_rank_is_not_the_enum_order)CHECK_EQ((Int)best, (Int)COMMAND_AVAILABLE);}+/*+ * NudgeBuildPlacement. The whole promise of the feature is "nearest spot that fits", and the+ * only thing that makes "first candidate that fits" mean that is the order the candidates come+ * out in. Ring by ring is not that order - from three rings out a ring's own diagonal is+ * farther than the next ring's straight neighbour - and the square has to be filled in, not+ * just sampled along the eight compass directions, or the search walks past the gap one cell+ * to the side of them.+ */+TEST(placement_nudge_offsets_come_out_nearest_first)+{+ const Real step = (Real)InGameUI::PLACEMENT_CELL;+ const Int rings = InGameUI::PLACEMENT_NUDGE_RINGS;+ Real dx[ InGameUI::PLACEMENT_NUDGE_TRIES ], dy[ InGameUI::PLACEMENT_NUDGE_TRIES ];+ Int i, j;++ for (i = 0; i < InGameUI::PLACEMENT_NUDGE_TRIES; i++)+ InGameUI::placementNudgeOffset(i, step, &dx[i], &dy[i]);++ /* nearest first, and never standing still - the cursor's own spot is the one that failed */+ for (i = 0; i < InGameUI::PLACEMENT_NUDGE_TRIES; i++)+ {+ Real d = dx[i] * dx[i] + dy[i] * dy[i];++ CHECK(d > 0.0f);+ if (i > 0)+ CHECK(d >= dx[i-1] * dx[i-1] + dy[i-1] * dy[i-1] - 0.0001f);+ }++ /* the first move offered is one cell straight, not a diagonal */+ CHECK_NEAR(dx[0] * dx[0] + dy[0] * dy[0], step * step, 0.0001f);++ /* the whole square is covered, once each: every cell of it is in the list exactly once, so+ * a gap one cell to the side of a compass direction is found like any other */+ CHECK_EQ(InGameUI::PLACEMENT_NUDGE_TRIES, (2 * rings + 1) * (2 * rings + 1) - 1);+ for (i = 0; i < InGameUI::PLACEMENT_NUDGE_TRIES; i++)+ for (j = i + 1; j < InGameUI::PLACEMENT_NUDGE_TRIES; j++)+ CHECK(fabsf(dx[i] - dx[j]) > 0.0001f || fabsf(dy[i] - dy[j]) > 0.0001f);++ /* every candidate lands on the same build grid the snap uses, so a nudged structure still+ * shares its edges with the ones already down, and none of them leaves the square */+ for (i = 0; i < InGameUI::PLACEMENT_NUDGE_TRIES; i++)+ {+ CHECK_NEAR(dx[i] / step, (Real)REAL_TO_INT_FLOOR(dx[i] / step + 0.5f), 0.0001f);+ CHECK_NEAR(dy[i] / step, (Real)REAL_TO_INT_FLOOR(dy[i] / step + 0.5f), 0.0001f);+ CHECK(fabsf(dx[i]) <= rings * step + 0.0001f && fabsf(dy[i]) <= rings * step + 0.0001f);+ }++ /* and the far corner really is last - the list is the whole search, not a prefix of it */+ CHECK_NEAR(fabsf(dx[InGameUI::PLACEMENT_NUDGE_TRIES - 1]), rings * step, 0.0001f);+ CHECK_NEAR(fabsf(dy[InGameUI::PLACEMENT_NUDGE_TRIES - 1]), rings * step, 0.0001f);+}+TEST(placement_grid_snap_puts_footprint_edges_on_cell_lines){const Real cell = 10.0f;diff --git a/README.md b/README.mdindex 3cd99bcc0..0f2c7ae4b 100644--- a/README.md+++ b/README.md@@ -117,6 +117,7 @@ All of these live in `Options.ini`, in your Zero Hour Data folder. Back it up fi| `StaticGameLOD = Custom` + `MaxParticleCount = 10000` | four times the High preset — much denser explosions and smoke || `DynamicLOD = no` | the game never silently downgrades quality mid-match || `GridBuildPlacement = No` | restores free building placement |+| `NudgeBuildPlacement = No` | a blocked building stays red under the cursor instead of sliding to the nearest spot that fits |The rest of the quality switches, all worth turning on: `UseShadowVolumes`, `UseShadowDecals`,`UseCloudMap`, `UseLightMap`, `ShowSoftWaterEdge`, `ExtraAnimations`, `HeatEffects`, `ShowTrees`,