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): space a shift-dragged row with the wheel
Olcay Seygand1e32228b338
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 0274184e7..4cf5e0bd0 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -651,6 +651,7 @@ A third pass went through the generals' powers, promotions and unit abilities.- Running out of money no longer strands the ghost on the map.- Holding shift and clicking out a row of buildings no longer stops halfway and selects one.- Hold shift and drag, and the row is one stroke. Press where the first building goes, drag the way the row runs, and a ghost appears for every building that fits end to end along the line, all facing the way the first one was turned. The row runs exactly the way you drag it, at 20 degrees as happily as along the map's edge, and packs the buildings as close as their shape allows: one turned onto the line of the row stands wall to wall with the next, and a factory keeps its door lane clear. A row of Power Plants turned square to the map packs 44 apart; it used to go down on whole grid squares, 50 apart, with a strip of dirt at every joint. It stops at the last building your bank can pay for. A ghost that lands on a rock or someone's tank turns red and is left out when you let go; the rest go up. With two or three workers selected the buildings are shared out to the nearest free one, and the ones nobody is free for wait as plans until a worker comes off its job. A plain drag still turns the building, and walls still tile the way they always did.+- While that row is on the cursor, the wheel opens and closes the space between the buildings, one grid square a notch. It will not pack them any tighter than they already sit against each other. Letting go places the row and takes the building off the cursor, so the next click is not another one. Holding shift and clicking them out one at a time still keeps the ghost up.- Buildings need a worker selected. With nothing selected the command bar used to borrow one of your dozers and offer its buildings anyway. It stays empty now until you pick a worker, and a replay recorded with a building placed that way plays back without it.- Turning a building no longer turns everything you build afterwards. A wheeled heading still carries from one wall to the next, but the next supply centre comes out facing the way it was designed to.- A building you point at blocked ground slides to the nearest spot it fits, and lands there.diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.hindex 2fa96932b..95daacc5d 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h@@ -694,20 +694,24 @@ public: // ********************************************************************* turned onto the row's own line stands face to face with the next, and one turned across it* corner to corner, which is the closest a straight row of those can get. The step is not* rounded to the build grid: a Power Plant is 44 across and the grid is 10, and rounding it- * up left 6 of dirt at every joint. Never fewer than one, never more than 'most'. Inline+ * up left 6 of dirt at every joint. 'extraGap' is world units the wheel adds on top of that+ * touch while the line is being drawn. Zero packs them flush, and a negative value is+ * ignored, so the row never overlaps. Never fewer than one, never more than 'most'. Inline* and static so a test can reach it without linking the whole in-game UI. */static Int placementRow( Real dx, Real dy, Real headingCos, Real headingSin, Real halfFacing,- Real halfSide, Int most, Coord2D *step )+ Real halfSide, Int most, Coord2D *step, Real extraGap = 0.0f ){step->x = 0.0f;step->y = 0.0f;const Real length = (Real)sqrt( dx * dx + dy * dy );if( length > 0.0f ){- const Real touch = placementTouchDistance( dx / length, dy / length, headingCos, headingSin,- 2.0f * halfFacing, 2.0f * halfSide );- step->x = dx / length * touch;- step->y = dy / length * touch;+ Real span = placementTouchDistance( dx / length, dy / length, headingCos, headingSin,+ 2.0f * halfFacing, 2.0f * halfSide );+ if( extraGap > 0.0f )+ span += extraGap;+ step->x = dx / length * span;+ step->y = dy / length * span;}Int count = 1;@@ -724,6 +728,8 @@ public: // ********************************************************************/// would dragging the anchor lay a row of the pending structure, rather than aim one?Bool placesRow( void );+ /// wheel notches while that row is being drawn: one grid square of gap a notch, never below flush+ void adjustPlacementRowGap( Real spin );/// the centres of that row from 'start' toward 'end', as many as MaxLineBuildObjects and the money allowvoid computePlacementRow( const ThingTemplate *what, Real angle, const Coord3D *start,const Coord3D *end, std::vector<Coord3D> *positions ) const;@@ -1360,6 +1366,8 @@ protected:const ThingTemplate * m_placeAngleType; ///< the structure that heading was chosen for; another type starts square againBool m_placementLegal; ///< last legality verdict for the spot under the structure being placedCoord3D m_placementNudge; ///< how far the last legality check had to slide the structure to make it fit+ Real m_placementRowGap; ///< extra world units between a shift-dragged row, on top of the buildings touching+ Real m_placementRowGapWheel; ///< fractional notches not yet worth a whole grid square/// a structure ordered here, and the logic frame it was ordered on - see recordPendingPlacementstruct PendingPlacementdiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex ad17c06bd..925ac91e3 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -1159,6 +1159,8 @@ InGameUI::InGameUI()m_placeAngleType = NULL;m_placementLegal = TRUE;m_placementNudge.zero();+ m_placementRowGap = 0.0f;+ m_placementRowGapWheel = 0.0f;m_videoStream = NULL;m_videoBuffer = NULL;@@ -6620,6 +6622,12 @@ void InGameUI::destroyPlacementIcons( void )//-------------------------------------------------------------------------------------------------void InGameUI::placeBuildAvailable( const ThingTemplate *build, Drawable *buildDrawable ){+ //+ // Each placement starts packed. The wheel opens the row while its line is being drawn, and that+ // gap belongs to the line, not to the next building.+ //+ m_placementRowGap = 0.0f;+ m_placementRowGapWheel = 0.0f;// if building something, no radius cursor, thankewif (build != NULL)@@ -6946,6 +6954,37 @@ Bool InGameUI::placesRow( void )!TheBuildAssistant->isLineBuildTemplate( m_pendingPlaceType );}+//-------------------------------------------------------------------------------------------------+/** One grid square a notch, added to the packed step. A notch toward the user closes it back,+ * and it stops at the buildings touching: tighter than that is two structures on one footprint.+ * Fractions pile up, so a touchpad swipe that arrives as halves still moves the row. */+//-------------------------------------------------------------------------------------------------+void InGameUI::adjustPlacementRowGap( Real spin )+{+ const Real cell = (Real)PLACEMENT_CELL;+ const Real cap = 20.0f * cell;++ m_placementRowGapWheel += spin;+ const Int steps = (Int)m_placementRowGapWheel;+ if( steps == 0 )+ return;++ m_placementRowGapWheel -= (Real)steps;+ m_placementRowGap += (Real)steps * cell;++ if( m_placementRowGap < 0.0f )+ {+ m_placementRowGap = 0.0f;+ m_placementRowGapWheel = 0.0f;+ }+ else if( m_placementRowGap > cap )+ {+ m_placementRowGap = cap;+ m_placementRowGapWheel = 0.0f;+ }++} // end adjustPlacementRowGap+//-------------------------------------------------------------------------------------------------/** Every piece faces 'angle', the heading on the ghost before the drag began: the drag is spent on* the row, so it cannot aim as well. The row stops where the money does, which is what the logic@@ -6976,7 +7015,8 @@ void InGameUI::computePlacementRow( const ThingTemplate *what, Real angle, constCoord2D step;const Int count = placementRow( end->x - start->x, end->y - start->y, (Real)Cos( angle ),- (Real)Sin( angle ), halfFacing, minor, most, &step );+ (Real)Sin( angle ), halfFacing, minor, most, &step,+ m_placementRowGap );positions->clear();for( Int i = 0; i < count; i++ ){diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cppindex d9736f2e7..4416a9bc2 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp@@ -143,6 +143,24 @@ GameMessageDisposition PlaceEventTranslator::translateGameMessage(const GameMessswitch(msg->getType()){+ //---------------------------------------------------------------------------------------------+ //+ // While a shift-dragged row is on the ground, the wheel opens and closes the gap instead of+ // zooming. The same message is what LookAtTranslator zooms with, and this translator runs+ // first, so eating it here is what keeps the camera still. A row that has not been started+ // yet leaves the wheel alone: ctrl still turns the building, and a plain roll still zooms.+ //+ case GameMessage::MSG_RAW_MOUSE_WHEEL:+ {+ if( TheInGameUI->getPendingPlaceType() && TheInGameUI->isPlacementAnchored() &&+ TheInGameUI->placesRow() )+ {+ TheInGameUI->adjustPlacementRowGap( msg->getArgument( 1 )->real );+ return DESTROY_MESSAGE;+ }+ break;+ }+case GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_DOWN:case GameMessage::MSG_RAW_MOUSE_RIGHT_DOUBLE_CLICK:{@@ -494,9 +512,14 @@ GameMessageDisposition PlaceEventTranslator::translateGameMessage(const GameMess//// get out of pending placement mode, this will also clear the arrow anchor status -// unless shift is held, which keeps placing the same structure until released.+ // A shift-dragged row is the exception: shift is what drew the line, and it is still+ // down when the button comes up, so leaving the ghost up would start another building+ // on the next click. The row is the whole order.//Drawable *nextBuilder = builderObj ? builderObj->getDrawable() : NULL;- if( TheKeyboard && TheKeyboard->isShift() && nextBuilder )+ if( row )+ TheInGameUI->placeBuildAvailable( NULL, NULL );+ else if( TheKeyboard && TheKeyboard->isShift() && nextBuilder )TheInGameUI->placeBuildAvailable( build, nextBuilder );elseTheInGameUI->placeBuildAvailable( NULL, NULL );diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 38757731c..0c59d6540 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -2318,6 +2318,15 @@ TEST(placement_row_packs_the_footprint_along_the_drag)CHECK_EQ(InGameUI::placementRow(1000.0f, 0.0f, 1.0f, 0.0f, 20.0f, 15.0f, 5, &step), 5);CHECK_EQ(InGameUI::placementRow(1000.0f, 0.0f, 1.0f, 0.0f, 20.0f, 15.0f, 0, &step), 1);CHECK_EQ(InGameUI::placementRow(0.0f, 0.0f, 1.0f, 0.0f, 20.0f, 15.0f, 50, &step), 1);++ /* ten units of extra gap on the 40.5 touch: the same drag that held four now holds three */+ CHECK_EQ(InGameUI::placementRow(122.0f, 0.0f, 1.0f, 0.0f, 20.0f, 15.0f, 50, &step, 10.0f), 3);+ CHECK_NEAR(step.x, 50.5f, 0.0001f);+ CHECK_NEAR(step.y, 0.0f, 0.0001f);++ /* a negative gap is ignored: the row never packs tighter than the footprints allow */+ InGameUI::placementRow(100.0f, 0.0f, 1.0f, 0.0f, 20.0f, 15.0f, 50, &step, -20.0f);+ CHECK_NEAR(step.x, 40.5f, 0.0001f);}