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): open a game at the zoom the wheel can reach

Olcay Seygan3ff239ec0c65
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 67d5e3082..743c41581 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -174,6 +174,12 @@ a millimetre, so it always measured nothing and moved nothing. The spot under yo
held there for the whole glide. Roll the wheel over the far corner of your base and you end up at
that corner, not in the middle of the screen.
+**A skirmish opens zoomed all the way out.** The game used to drop you at the map author's own
+camera height, which is tighter than the wheel will go, so the first thing anyone did on every
+single map was roll the wheel back to see their base and the ground around it. It now opens at the
+widest view the wheel can reach. Middle-click still snaps back to the author's framing, and
+`StartAtMaxZoom = No` in `GameData.ini` puts the old opening back.
+
**Hold Ctrl and roll the wheel to turn a building before you put it down** — a clean 45 degrees a
notch, and the next building you place keeps the same facing, so a wall or a line of bunkers goes
down straight without aiming each piece by hand.
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
index d965e6930..b53696c82 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
@@ -128,6 +128,7 @@ public:
Bool m_useShadowVolumesForSkins; // "UseShadowVolumesForSkins": also cast volume shadows off skinned meshes
Bool m_useShadowDecals;
Bool m_shadowsForProjectiles; // "ShadowsForProjectiles": missiles and bombs that have no shadow of their own get a decal one
+ Bool m_startAtMaxZoom; // "StartAtMaxZoom": a game opens as far out as the wheel goes, not at the map's own default
Bool m_shadowsForProps; // "ShadowsForProps": fences, rubbish, shrubs - scenery the art gave no shadow at all
Bool m_shadowsForParticles; // "ShadowsForParticles": big alpha-blended particle clouds drop a soft blob on the ground
Bool m_particleGroundBounce; // "-particlebounce": terrain collision on for every particle system
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/View.h b/GeneralsMD/Code/GameEngine/Include/GameClient/View.h
index e8ee2840f..cf80ffa81 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/View.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/View.h
@@ -185,6 +185,7 @@ public:
virtual void zoomIn( void ); ///< Zoom in, closer to the ground, limit to min
virtual void zoomOut( void ); ///< Zoom out, farther away from the ground, limit to max
virtual void setZoomToDefault( void ) { } ///< Set zoom to default value
+ virtual void setZoomToMax( void ) { } ///< Set zoom as far out as the player may zoom by hand
virtual Real getMaxZoom( void ) { return m_maxZoom; } ///< return max zoom value
virtual void setOkToAdjustHeight( Bool val ) { m_okToAdjustHeight = val; } ///< Set this to adjust camera height
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
index 2a3736e49..48bc2eb96 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
@@ -100,6 +100,7 @@ GlobalData* GlobalData::m_theOriginal = NULL;
{ "UseShadowVolumesForSkins", INI::parseBool, NULL, offsetof( GlobalData, m_useShadowVolumesForSkins ) },
{ "UseShadowDecals", INI::parseBool, NULL, offsetof( GlobalData, m_useShadowDecals ) },
{ "ShadowsForProjectiles", INI::parseBool, NULL, offsetof( GlobalData, m_shadowsForProjectiles ) },
+ { "StartAtMaxZoom", INI::parseBool, NULL, offsetof( GlobalData, m_startAtMaxZoom ) },
{ "ShadowsForProps", INI::parseBool, NULL, offsetof( GlobalData, m_shadowsForProps ) },
{ "ShadowsForParticles", INI::parseBool, NULL, offsetof( GlobalData, m_shadowsForParticles ) },
{ "TextureReductionFactor", INI::parseInt, NULL, offsetof( GlobalData, m_textureReductionFactor ) },
@@ -647,6 +648,7 @@ GlobalData::GlobalData()
m_useShadowVolumesForSkins = TRUE; //on by default: the shipped INI has no entry for it
m_useShadowDecals = FALSE;
m_shadowsForProjectiles = TRUE; //on by default: the shipped INI has no entry for it
+ m_startAtMaxZoom = TRUE; //open a game framed as wide as the player could zoom by hand
m_shadowsForProps = TRUE; //likewise: scenery with no shadow of its own gets one
m_shadowsForParticles = TRUE; //on by default: the shipped INI has no entry for it
m_textureReductionFactor = -1;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
index 53756b8a3..e65628bf8 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
@@ -2028,7 +2028,12 @@ void GameLogic::startNewGame( Bool loadingSaveGame )
updateLoadProgress(LOAD_PROGRESS_POST_PRELOAD_ASSETS);
TheTacticalView->setAngleAndPitchToDefault();
- TheTacticalView->setZoomToDefault();
+ //StartAtMaxZoom: open the map as far out as the wheel itself may go rather than at the map's
+ //own default height, which is the tighter of the two.
+ if( TheGlobalData->m_startAtMaxZoom )
+ TheTacticalView->setZoomToMax();
+ else
+ TheTacticalView->setZoomToDefault();
if( TheRecorder )
TheRecorder->initControls();
@@ -2074,7 +2079,12 @@ void GameLogic::startNewGame( Bool loadingSaveGame )
// Set up the camera height based on the map height & globalData.
TheTacticalView->initHeightForMap();
TheTacticalView->setAngleAndPitchToDefault();
- TheTacticalView->setZoomToDefault();
+ //StartAtMaxZoom: open the map as far out as the wheel itself may go rather than at the map's
+ //own default height, which is the tighter of the two.
+ if( TheGlobalData->m_startAtMaxZoom )
+ TheTacticalView->setZoomToMax();
+ else
+ TheTacticalView->setZoomToDefault();
// update the loadscreen
updateLoadProgress(LOAD_PROGRESS_POST_STARTING_CAMERA_2);
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h
index d4ea52a47..9b0d26295 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h
@@ -199,6 +199,8 @@ public:
virtual void setHeightAboveGround(Real z);
virtual void setZoom(Real z);
virtual void setZoomToDefault( void ); ///< Set zoom to default value
+ virtual void setZoomToMax( void ); ///< Set zoom as far out as the player may zoom by hand
+ void setZoomToHeight( Real heightAboveGround ); ///< Frame the camera at this height above the terrain
virtual void setFieldOfView( Real angle ); ///< Set the horizontal field of view angle
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
index d0d2cc765..1b9612564 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
@@ -2065,21 +2065,19 @@ void W3DView::setZoom(Real z)
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
-void W3DView::setZoomToDefault( void )
+void W3DView::setZoomToHeight( Real heightAboveGround )
{
- // default zoom has to be max, otherwise players will just zoom to max always
-
// terrain height + desired height offset == cameraOffset * actual zoom
// find best approximation of max terrain height we can see
Real terrainHeightMax = getHeightAroundPos(m_pos.x, m_pos.y);
- Real desiredHeight = (terrainHeightMax + m_maxHeightAboveGround);
+ Real desiredHeight = (terrainHeightMax + heightAboveGround);
Real desiredZoom = desiredHeight / m_cameraOffset.z;
- //DEBUG_LOG(("W3DView::setZoomToDefault() Current zoom: %g Desired zoom: %g\n", m_zoom, desiredZoom));
+ //DEBUG_LOG(("W3DView::setZoomToHeight() Current zoom: %g Desired zoom: %g\n", m_zoom, desiredZoom));
m_zoom = desiredZoom;
- m_heightAboveGround = m_maxHeightAboveGround;
+ m_heightAboveGround = heightAboveGround;
m_doingMoveCameraOnWaypointPath = false;
m_CameraArrivedAtWaypointOnPathFlag = false;
@@ -2091,6 +2089,24 @@ void W3DView::setZoomToDefault( void )
setCameraTransform();
}
+//-------------------------------------------------------------------------------------------------
+//-------------------------------------------------------------------------------------------------
+void W3DView::setZoomToDefault( void )
+{
+ // default zoom has to be max, otherwise players will just zoom to max always
+ setZoomToHeight( m_maxHeightAboveGround );
+}
+
+//-------------------------------------------------------------------------------------------------
+/** As far out as the wheel itself may go: the manual limit stretches the map's own maximum by
+ZOOM_OUT_LIMIT_FACTOR, and this is where a game opens when StartAtMaxZoom is on. */
+//-------------------------------------------------------------------------------------------------
+void W3DView::setZoomToMax( void )
+{
+ setZoomToHeight( m_zoomLimited ? m_maxHeightAboveGround * ZOOM_OUT_LIMIT_FACTOR
+ : m_maxHeightAboveGround );
+}
+
//-------------------------------------------------------------------------------------------------
/** Set the horizontal field of view angle */
//-------------------------------------------------------------------------------------------------