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(w3ddevice): destroyed buildings sink into the ground, as an option

Olcay Seygane660ccc8cbf3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 53a3935a4..42960cda2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,10 @@ found and fixed, EA's own, not port damage.**
---
+## Buildings go down
+
+- Collapsing Buildings, under Options, Display, is a new setting, off by default until it has been played. EA's building stands until the frame it dies, then it is gone or it is a pile of rubble, with a cloud thrown over the moment. With this on it holds for a beat, shudders, leans about seven degrees and goes into the ground, a second for a small one and up to two and a half for a tall one. Most of the fall happens inside EA's cloud, so the part you see is the first half second, the roof dropping as the smoke comes up. It blocks nothing and nothing in the game reads it, so two players in one match can have it set differently. Direct3D 11 only.
+
## A sky over the map
- Atmosphere, under Options, Graphics, is a new setting, off by default until it has been played. Tilt the camera flat or fly it low in a replay and EA's game ran out of world, black above the skyline and a far plane that cut the ground off in a line. With this on there is a sky, EA's own art for the map's hour, the ground far from the camera fades toward its colour, and the black ring past the map goes into the same haze. Your fog of war stays as dark as it was, the ground near the camera stays clear, and nothing moves but your camera. Your opponent's setting is his own, because no part of the game reads this. A battle of three armies and three superweapons takes the graphics card's frame from about 8.0 to 8.2 ms. Direct3D 11 only, and off under Classic Graphics.
diff --git a/GeneralsMD/Code/BuildFingerprint.manifest b/GeneralsMD/Code/BuildFingerprint.manifest
index bb611f034..95a9eec8f 100644
--- a/GeneralsMD/Code/BuildFingerprint.manifest
+++ b/GeneralsMD/Code/BuildFingerprint.manifest
@@ -1803,6 +1803,7 @@ GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DTankTruckDraw.h
GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DTracerDraw.h
GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DTreeDraw.h
GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DTruckDraw.h
+GameEngineDevice/Include/W3DDevice/GameClient/StructureCollapse.h
GameEngineDevice/Include/W3DDevice/GameClient/SunShadowCasterCull.h
GameEngineDevice/Include/W3DDevice/GameClient/TerrainTex.h
GameEngineDevice/Include/W3DDevice/GameClient/TileData.h
@@ -1998,6 +1999,7 @@ GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DBufferManager.cpp
GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp
GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DShadow.cpp
GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp
+GameEngineDevice/Source/W3DDevice/GameClient/StructureCollapse.cpp
GameEngineDevice/Source/W3DDevice/GameClient/TerrainTex.cpp
GameEngineDevice/Source/W3DDevice/GameClient/TileData.cpp
GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp
diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.str
index e141f97d6..543276e1f 100644
--- a/GeneralsMD/Code/Data/Patch.str
+++ b/GeneralsMD/Code/Data/Patch.str
@@ -1564,6 +1564,14 @@ TOOLTIP:Atmosphere
"The ground far from the camera fades toward the sky's colour, and where the map ends or the camera lies flat you see a sky by the map's time of day instead of black. The ground near the camera stays clear and fog of war keeps its dark. Only your picture changes: nothing in the game reads it, and other players see their own setting. Direct3D 11 only, and off under Classic Graphics."
END
+GUI:StructureCollapse
+"Collapsing Buildings"
+END
+
+TOOLTIP:StructureCollapse
+"A destroyed building sinks into the ground under the blast instead of vanishing in one frame, or swapping to its rubble in one. Only your picture changes: it blocks nothing, nothing in the game reads it, and other players see their own setting. Direct3D 11 only, and off under Classic Graphics."
+END
+
GUI:FormationDrag
"Drag Out A Formation"
END
diff --git a/GeneralsMD/Code/Data/Turkish/Generals.str b/GeneralsMD/Code/Data/Turkish/Generals.str
index 61ed90360..cc71a720b 100644
--- a/GeneralsMD/Code/Data/Turkish/Generals.str
+++ b/GeneralsMD/Code/Data/Turkish/Generals.str
@@ -15957,6 +15957,14 @@ TOOLTIP:Atmosphere
"Kameradan uzak zemin gökyüzünün rengine doğru solar; haritanın bittiği yerde ya da kamera yatık durduğunda siyah yerine haritanın saatine uygun bir gökyüzü görünür. Kameraya yakın zemin temiz kalır, savaş sisi karanlığını korur. Değişen sadece sizin görüntünüzdür: oyunda hiçbir şey bunu okumaz, diğer oyuncular kendi ayarını görür. Yalnızca Direct3D 11 ile, Klasik Grafikler açıkken kapalıdır."
END
+GUI:StructureCollapse
+"Yıkılan Binalar"
+END
+
+TOOLTIP:StructureCollapse
+"Yok edilen bina bir karede kaybolmak ya da enkaza dönmek yerine patlamanın altında yere gömülür. Değişen sadece sizin görüntünüzdür: hiçbir şeyi engellemez, oyunda hiçbir şey bunu okumaz, diğer oyuncular kendi ayarını görür. Yalnızca Direct3D 11 ile, Klasik Grafikler açıkken kapalıdır."
+END
+
GUI:FormationDrag
"Sürükleyerek Düzen Kur"
END
diff --git a/GeneralsMD/Code/Data/Window/Menus/OptionsMenuClassic.wnd b/GeneralsMD/Code/Data/Window/Menus/OptionsMenuClassic.wnd
index 73e6f3b0b..1752d68d7 100644
--- a/GeneralsMD/Code/Data/Window/Menus/OptionsMenuClassic.wnd
+++ b/GeneralsMD/Code/Data/Window/Menus/OptionsMenuClassic.wnd
@@ -2558,6 +2558,53 @@ WINDOW
IMAGE: NoImage, COLOR: 255 255 255 255, BORDERCOLOR: 255 255 255 255;
END
CHILD
+ WINDOW
+ WINDOWTYPE = CHECKBOX;
+ SCREENRECT = UPPERLEFT: 288 238, BOTTOMRIGHT: 512 262, CREATIONRESOLUTION: 800 600;
+ NAME = "OptionsMenu.wnd:CheckStructureCollapse";
+ STATUS = ENABLED+IMAGE+BORDER;
+ STYLE = CHECKBOX+MOUSETRACK;
+ SYSTEMCALLBACK = "[None]";
+ INPUTCALLBACK = "[None]";
+ TOOLTIPCALLBACK = "[None]";
+ DRAWCALLBACK = "[None]";
+ FONT = NAME: "Arial", SIZE: 14, BOLD: 0;
+ HEADERTEMPLATE = "MinorTitle";
+ TOOLTIPTEXT = "TOOLTIP:StructureCollapse";
+ TOOLTIPDELAY = -1;
+ TEXT = "GUI:StructureCollapse";
+ TEXTCOLOR = ENABLED: 255 255 255 255, ENABLEDBORDER: 0 0 0 255,
+ DISABLED: 192 192 192 255, DISABLEDBORDER: 64 64 64 255,
+ HILITE: 186 255 12 255, HILITEBORDER: 0 0 0 255;
+ ENABLEDDRAWDATA = IMAGE: NoImage, COLOR: 255 0 0 255, BORDERCOLOR: 255 128 128 255,
+ IMAGE: Active-Unchecked, COLOR: 255 255 255 0, BORDERCOLOR: 128 128 255 255,
+ IMAGE: Active-Checked, COLOR: 0 0 255 255, BORDERCOLOR: 128 128 255 255,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;
+ DISABLEDDRAWDATA = IMAGE: NoImage, COLOR: 128 128 128 255, BORDERCOLOR: 192 192 192 255,
+ IMAGE: Disabled-Unchecked, COLOR: 255 255 255 0, BORDERCOLOR: 192 192 192 255,
+ IMAGE: Disabled-Checked, COLOR: 64 64 64 255, BORDERCOLOR: 254 254 254 255,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;
+ HILITEDRAWDATA = IMAGE: NoImage, COLOR: 0 255 0 255, BORDERCOLOR: 128 255 128 255,
+ IMAGE: Active-HiLighted, COLOR: 255 255 255 0, BORDERCOLOR: 128 128 255 255,
+ IMAGE: Active-Checked, COLOR: 255 255 0 255, BORDERCOLOR: 254 254 254 255,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;
+ END
+ CHILD
WINDOW
WINDOWTYPE = STATICTEXT;
SCREENRECT = UPPERLEFT: 536 182, BOTTOMRIGHT: 760 206, CREATIONRESOLUTION: 800 600;
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
index 387b1fb7a..f3e9f839d 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
@@ -713,6 +713,7 @@ public:
Bool m_weatherEffects; ///< "Weather": rain, blowing sand or snow by the map's ground, and a wind on trees and smoke (Direct3D 11, client only)
Bool m_waterSplashes; ///< "WaterSplashes": a splash and rings where a blast or a falling body meets water (Direct3D 11, client only)
Bool m_atmosphere; ///< "Atmosphere": the far ground fades toward the horizon and an empty frame takes a sky (Direct3D 11, client only)
+ Bool m_structureCollapse; ///< "StructureCollapse": a building's last model goes into the ground (Direct3D 11, client only)
Bool m_internalHdr; ///< "InternalHdr": what passes white in the half float scene keeps its colour on the way to eight bits; no HDR monitor output (Direct3D 11, client only)
Int m_maxParticleCount; ///< maximum number of particles that can exist
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
index e95a54207..1a1f2bf2a 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
@@ -474,6 +474,7 @@ public:
first (animation timing, a model rebuild), which an on-demand flush inside the tick runs; the
rest an on-demand flush leaves for after the tick. */
void doClientWork( const std::function<void()>& work, ClientWorkOrder order, Bool movesBones = FALSE );
+ void startCollapse(); ///< the Collapse option, on the way to rubble
//---------------------------------------------------------------------------
void setDrawableStatus( DrawableStatus bit ) { BitSet( m_status, bit ); }
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/GameClient.h b/GeneralsMD/Code/GameEngine/Include/GameClient/GameClient.h
index 6ed9a9d04..573288814 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/GameClient.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/GameClient.h
@@ -144,6 +144,7 @@ public:
virtual void addGroundMark(const Coord3D *pos, Real radius, Int type) {} ///< the Battle Marks option: a burn that fades, nothing logic reads
virtual void structureFell(const Coord3D *pos, Real radius) {} ///< a building is down: what the client alone does about it
virtual void splashInWater(const Coord3D *pos, Real radius) {} ///< the Water Splashes option: a blast or a body came down here, nothing logic reads
+ virtual void structureCollapsing(Drawable *draw, Real height) {} ///< the Collapse option: this drawable's model as it stands is the building's last, nothing logic reads
virtual Bool loadMap( AsciiString mapName ); ///< load a map into our scene
virtual void unloadMap( AsciiString mapName ); ///< unload the specified map from our scene
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
index abc24e58f..d53d5eafc 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
@@ -1142,6 +1142,7 @@ GlobalData::GlobalData()
m_weatherEffects = FALSE;
m_waterSplashes = FALSE;
m_atmosphere = FALSE;
+ m_structureCollapse = FALSE;
m_internalHdr = FALSE;
m_horizontalScrollSpeedFactor = 1.0;
m_verticalScrollSpeedFactor = 1.0;
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
index 50a41e957..2d67bf58c 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
@@ -149,6 +149,7 @@ OPTION_BOOL_ACCESSORS( m_ambientOcclusion )
OPTION_BOOL_ACCESSORS( m_weatherEffects )
OPTION_BOOL_ACCESSORS( m_waterSplashes )
OPTION_BOOL_ACCESSORS( m_atmosphere )
+OPTION_BOOL_ACCESSORS( m_structureCollapse )
OPTION_BOOL_ACCESSORS( m_internalHdr )
OPTION_INT_ACCESSORS( m_shadowQuality )
OPTION_INT_ACCESSORS( m_graphicsQuality )
@@ -668,6 +669,14 @@ const OptionDef TheOptionCatalog[] =
OPTION_BOOL, APPLY_LIVE, 0, 1,
get_m_atmosphere, set_m_atmosphere },
+ // A building's last model goes into the ground: StructureCollapse.cpp moves a copy no drawable owns,
+ // and no sim reads it. Off under Classic graphics and -d3d9, and no row in
+ // the quality table: an opt-in until it has been seen. On Options > Display, under Picture: every
+ // column of Graphics and Effects is full.
+ { "StructureCollapse", OPT_WND( "CheckStructureCollapse" ), "GUI:StructureCollapse",
+ OPTION_BOOL, APPLY_LIVE, 0, 1,
+ get_m_structureCollapse, set_m_structureCollapse },
+
// What passes white keeps its colour on the way to the eight bit screen; no HDR monitor output. The
// post chain is told every frame. Classic graphics has no half float scene and -d3d9 no chain, and
// no row in the quality table: an opt-in until it has been seen. On Options > Effects.
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
index 845d3dbe0..697330ffe 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
@@ -1464,11 +1464,35 @@ const Real Drawable::getScale (void) const
// return getTemplate()->getAssetScale();
}
+//-------------------------------------------------------------------------------------------------
+/** The Collapse option: a building that is about to vanish or swap to rubble in one frame hands over
+ its model as it stands, which is why this comes before the rubble state. What stages its own end
+ keeps it: EA's high rises, towers that topple, a slow death and a landmark bridge's animation. */
+//-------------------------------------------------------------------------------------------------
+void Drawable::startCollapse()
+{
+ const Object *obj = getObject();
+ if (obj == NULL || !isKindOf(KINDOF_STRUCTURE) || isKindOf(KINDOF_BRIDGE) || isKindOf(KINDOF_BRIDGE_TOWER)
+ || obj->testStatus(OBJECT_STATUS_UNDER_CONSTRUCTION) || obj->testStatus(OBJECT_STATUS_SOLD))
+ return;
+ static const NameKeyType collapseKey = NAMEKEY("StructureCollapseUpdate");
+ static const NameKeyType toppleKey = NAMEKEY("StructureToppleUpdate");
+ static const NameKeyType slowDeathKey = NAMEKEY("SlowDeathBehavior");
+ if (obj->findUpdateModule(collapseKey) || obj->findUpdateModule(toppleKey) || obj->findUpdateModule(slowDeathKey))
+ return;
+ // the template's: by now the body has put the object's own geometry at rubble height
+ const Real height = obj->getTemplate()->getTemplateGeometryInfo().getMaxHeightAbovePosition();
+ doClientWork( [this, height]() { TheGameClient->structureCollapsing( this, height ); }, WORK_AFTER_FLUSH );
+}
+
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void Drawable::reactToBodyDamageStateChange(BodyDamageType newState)
{
- static const ModelConditionFlagType TheDamageMap[BODYDAMAGETYPE_COUNT] =
+ if (newState == BODY_RUBBLE && TheGlobalData->m_structureCollapse && !TheGameLogic->isLoadingMap())
+ startCollapse();
+
+ static const ModelConditionFlagType TheDamageMap[BODYDAMAGETYPE_COUNT] =
{
MODELCONDITION_INVALID,
MODELCONDITION_DAMAGED,
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 212ee0fd6..ce5ad614c 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
@@ -2961,7 +2961,7 @@ void OptionsMenuInit( WindowLayout *layout, void *userData )
// three looks only the Direct3D 11 picture draws; under -d3d9 their boxes keep the saved value, greyed
if( !TheGlobalData->m_direct3D11 )
{
- static const char *const direct3D11Only[] = { "MapLight", "TeamGlow", "WaterFoam", "GroundMarks", "Firelight", "HemiAmbient", "AmbientOcclusion", "InternalHdr", "Weather", "WaterSplashes", "Atmosphere" };
+ static const char *const direct3D11Only[] = { "MapLight", "TeamGlow", "WaterFoam", "GroundMarks", "Firelight", "HemiAmbient", "AmbientOcclusion", "InternalHdr", "Weather", "WaterSplashes", "Atmosphere", "StructureCollapse" };
for( Int i = 0; i < (Int)( sizeof( direct3D11Only ) / sizeof( direct3D11Only[ 0 ] ) ); ++i )
findOptionWidget( *findOptionDef( direct3D11Only[ i ] ) )->winEnable( FALSE );
}
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/StructureCollapse.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/StructureCollapse.h
new file mode 100644
index 000000000..bb9da3f48
--- /dev/null
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/StructureCollapse.h
@@ -0,0 +1,61 @@
+/*
+** Command & Conquer Generals Zero Hour(tm)
+** Copyright 2025 Electronic Arts Inc.
+**
+** This program is free software: you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation, either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+// Modified 2026 by Olcay Seygan for Zero Hour Reforged; see the git history.
+
+// FILE: StructureCollapse.h
+// The Collapse option: a copy of a building's last model goes into the ground. A render object no
+// drawable owns: the object is already gone or already rubble, and nothing in the game reads any of
+// this. The timing is here, free of the engine, so a test can hold it.
+
+#pragma once
+
+class RenderObjClass;
+
+namespace StructureCollapse {
+
+enum { MAX_PIECES = 48 }; ///< a nuke on a base loses the rest of its copies, not a frame
+
+/// Seconds a building of this height takes to go into the ground.
+inline float sinkSeconds(float height)
+{
+ const float seconds = 0.9f + height / 60.0f;
+ return seconds < 2.5f ? seconds : 2.5f;
+}
+
+/// How much of its height a building has lost at this many seconds, 0 to 1: a beat, then faster and faster.
+inline float sunk(float seconds, float total)
+{
+ const float BEAT = 0.15f;
+ if (seconds <= BEAT)
+ return 0.0f;
+ if (seconds >= total)
+ return 1.0f;
+ const float fraction = (seconds - BEAT) / (total - BEAT);
+ return fraction * fraction;
+}
+
+/// Hand over a copy of a building's model as it stands: this takes the reference and it goes into the ground.
+void add(RenderObjClass *copy, float height);
+
+/// Moves what is falling. Outside the frame's draw: this adds to the scene.
+void update();
+
+/// Nothing falling, nothing in the scene: a map is ending.
+void clear();
+
+} // namespace StructureCollapse
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DGameClient.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DGameClient.h
index f7a0f5aa3..0ba86deb4 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DGameClient.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DGameClient.h
@@ -95,6 +95,7 @@ public:
virtual void addGroundMark(const Coord3D *pos, Real radius, Int type);
virtual void structureFell(const Coord3D *pos, Real radius);
virtual void splashInWater(const Coord3D *pos, Real radius);
+ virtual void structureCollapsing(Drawable *draw, Real height);
virtual void createRayEffectByTemplate( const Coord3D *start, const Coord3D *end, const ThingTemplate* tmpl ); ///< create effect needing start and end location
//virtual Bool getBonePos(Drawable *draw, AsciiString boneName, Coord3D* pos, Matrix3D* transform) const;
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/StructureCollapse.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/StructureCollapse.cpp
new file mode 100644
index 000000000..c8bc5b075
--- /dev/null
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/StructureCollapse.cpp
@@ -0,0 +1,153 @@
+/*
+** Command & Conquer Generals Zero Hour(tm)
+** Copyright 2025 Electronic Arts Inc.
+**
+** This program is free software: you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation, either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+// Modified 2026 by Olcay Seygan for Zero Hour Reforged; see the git history.
+
+// FILE: StructureCollapse.cpp
+// See StructureCollapse.h. The list is empty unless the option is on and something just fell.
+
+#include "Common/GameEngine.h"
+#include "Common/GlobalData.h"
+#include "GameClient/ClientRandomValue.h"
+#include "GameClient/GameClient.h"
+#include "GameClient/ObserverCamera.h"
+#include "GameLogic/GameLogic.h"
+#include "GameLogic/PartitionManager.h"
+#include "W3DDevice/GameClient/StructureCollapse.h"
+#include "W3DDevice/GameClient/W3DDisplay.h"
+#include "W3DDevice/GameClient/W3DScene.h"
+#include "WW3D2/rendobj.h"
+#include "WW3D2/scene.h"
+
+#include <vector>
+
+namespace StructureCollapse {
+
+namespace {
+
+struct Piece
+{
+ RenderObjClass *robj;
+ Matrix3D base; ///< where it stood
+ Vector3 axis; ///< what it leans over, level
+ Real depth; ///< how far it has to go
+ Real seconds; ///< sinkSeconds
+ Real born; ///< logic frame
+ Bool started;
+};
+
+std::vector<Piece> s_pieces;
+
+const Real MAX_LEAN = 0.12f; // radians, enough to read as falling rather than a lift going down
+
+/// How far down the whole model is out of sight at full lean, which lifts the side away from the fall.
+Real depthUnderGround(const RenderObjClass &robj, const Vector3 &foot)
+{
+ const Real BELOW_THE_GROUND = 5.0f;
+ const AABoxClass &box = robj.Get_Bounding_Box();
+ const Real reachX = WWMath::Fabs(box.Center.X - foot.X) + box.Extent.X;
+ const Real reachY = WWMath::Fabs(box.Center.Y - foot.Y) + box.Extent.Y;
+ const Real top = box.Center.Z + box.Extent.Z - foot.Z;
+ return top + BELOW_THE_GROUND + MAX_LEAN * WWMath::Sqrt(reachX * reachX + reachY * reachY);
+}
+
+/// First sight of it, outside the draw: what the fog hides goes without being seen.
+Bool start(Piece &piece)
+{
+ piece.started = TRUE;
+ const Vector3 foot = piece.base.Get_Translation();
+ const Coord3D at = { foot.X, foot.Y, foot.Z };
+ if (ThePartitionManager->getShroudStatusForPlayer(TheObserverCamera.getShroudPlayerIndex(), &at) != CELLSHROUD_CLEAR)
+ return FALSE;
+ const Real heading = GameClientRandomValueReal(0.0f, 2.0f * PI);
+ piece.axis.Set(WWMath::Cos(heading), WWMath::Sin(heading), 0.0f);
+ ((SimpleSceneClass *)W3DDisplay::m_3DScene)->Add_Render_Object(piece.robj);
+ return TRUE;
+}
+
+/// Where it is at this many seconds, or FALSE when it is under.
+Bool place(Piece &piece, Real seconds)
+{
+ if (seconds >= piece.seconds)
+ return FALSE;
+ const Real MAX_SHUDDER = 0.5f; // units
+ const Real SHUDDER_RATE = 45.0f; // radians a second, of the game's time so a pause holds it still
+ const Real fraction = sunk(seconds, piece.seconds);
+ const Real shudder = MAX_SHUDDER * (1.0f - fraction);
+ const Vector3 foot = piece.base.Get_Translation();
+
+ Matrix3D turn(piece.axis, MAX_LEAN * fraction);
+ const Vector3 slide(shudder * WWMath::Sin(SHUDDER_RATE * seconds), shudder * WWMath::Cos(SHUDDER_RATE * seconds),
+ -piece.depth * fraction);
+ turn.Set_Translation(foot + slide - turn.Rotate_Vector(foot));
+ Matrix3D moved;
+ Matrix3D::Multiply(turn, piece.base, &moved);
+ piece.robj->Set_Transform(moved);
+ return TRUE;
+}
+
+void release(Piece &piece)
+{
+ piece.robj->Remove();
+ REF_PTR_RELEASE(piece.robj);
+}
+
+} // namespace
+
+void add(RenderObjClass *copy, float height)
+{
+ if (s_pieces.size() >= MAX_PIECES)
+ {
+ REF_PTR_RELEASE(copy);
+ return;
+ }
+ Piece piece;
+ piece.robj = copy;
+ piece.base = copy->Get_Transform();
+ piece.axis.Set(1.0f, 0.0f, 0.0f);
+ piece.depth = depthUnderGround(*copy, piece.base.Get_Translation());
+ piece.seconds = sinkSeconds(height);
+ piece.born = (Real)TheGameLogic->getFrame();
+ piece.started = FALSE;
+ s_pieces.push_back(piece);
+}
+
+void update()
+{
+ if (s_pieces.empty())
+ return;
+ const Real now = (Real)TheGameLogic->getFrame() + WWMath::Clamp(GameEngine_logicTickFraction(), 0.0f, 1.0f);
+ size_t kept = 0;
+ for (size_t i = 0; i < s_pieces.size(); ++i)
+ {
+ Piece &piece = s_pieces[i];
+ if ((piece.started || start(piece)) && place(piece, (now - piece.born) / LOGICFRAMES_PER_SECOND))
+ s_pieces[kept++] = piece;
+ else
+ release(piece);
+ }
+ s_pieces.erase(s_pieces.begin() + kept, s_pieces.end());
+}
+
+void clear()
+{
+ for (size_t i = 0; i < s_pieces.size(); ++i)
+ release(s_pieces[i]);
+ s_pieces.clear();
+}
+
+} // namespace StructureCollapse
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DGameClient.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DGameClient.cpp
index 924ff58ff..925cc7b93 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DGameClient.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DGameClient.cpp
@@ -62,12 +62,17 @@
#include "W3DDevice/GameClient/W3DScene.h"
#include "W3DDevice/GameClient/W3DShadow.h"
#include "W3DDevice/GameClient/GroundMarks.h"
+#include "W3DDevice/GameClient/StructureCollapse.h"
+#include "W3DDevice/GameClient/Module/W3DModelDraw.h"
#include "W3DDevice/GameClient/HeightMap.h"
+#include "WW3D2/hlod.h"
#include "WW3D2/part_emt.h"
#include "WW3D2/hanim.h"
#include "WW3D2/htree.h"
#include "WW3D2/animobj.h" ///< @todo superhack for demo, remove!
+extern void disableUVAnimations(RenderObjClass *robj); // W3DGhostObject.cpp
+
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
W3DGameClient::W3DGameClient()
@@ -99,6 +104,9 @@ void W3DGameClient::init( void )
void W3DGameClient::update( void )
{
+ // before the base, whose draw opens the window the tick runs beside
+ StructureCollapse::update();
+
// call base
GameClient::update();
@@ -111,6 +119,8 @@ void W3DGameClient::update( void )
void W3DGameClient::reset( void )
{
+ StructureCollapse::clear();
+
// call base class
GameClient::reset();
@@ -247,6 +257,41 @@ void W3DGameClient::splashInWater(const Coord3D *pos, Real radius)
}
}
+//-------------------------------------------------------------------------------------------------
+/** The Collapse option, with the model the building had a frame before rubble: the copy that goes
+ * into the ground. Runs among the drawable's own work after the tick, and the drawable may be gone
+ * by the next frame. The animation stops where it stands, as a ghost object's does. */
+//-------------------------------------------------------------------------------------------------
+void W3DGameClient::structureCollapsing(Drawable *draw, Real height)
+{
+ if (TheGlobalData->m_classicGraphics || !Direct3D11_Present_Is_Enabled() || W3DDisplay::m_3DScene == NULL)
+ return;
+ // a slab of foundation or a mine's stub has nothing to go down
+ const Real MIN_HEIGHT = 8.0f;
+ if (height < MIN_HEIGHT || draw->isDrawableEffectivelyHidden())
+ return;
+ for (DrawModule **dm = draw->getDrawModules(); *dm; ++dm)
+ {
+ ObjectDrawInterface *di = (*dm)->getObjectDrawInterface();
+ RenderObjClass *robj = di ? ((W3DModelDraw *)di)->getRenderObject() : NULL;
+ if (robj == NULL || robj->Is_Hidden())
+ continue;
+ RenderObjClass *copy = robj->Clone();
+ copy->Set_ObjectColor(robj->Get_ObjectColor());
+ copy->Set_Transform(robj->Get_Transform());
+ copy->Set_Collision_Type(0); // a click goes through to what stands behind it
+ if (robj->Class_ID() == RenderObjClass::CLASSID_HLOD)
+ {
+ float frame, mult;
+ int mode, numFrames;
+ HAnimClass *anim = ((HLodClass *)robj)->Peek_Animation_And_Info(frame, numFrames, mode, mult);
+ copy->Set_Animation(anim, frame);
+ disableUVAnimations(copy);
+ }
+ StructureCollapse::add(copy, height);
+ }
+}
+
//-------------------------------------------------------------------------------------------------
/** create an effect that requires a start and end location */
//-------------------------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/Tests/test_ground_marks.cpp b/GeneralsMD/Code/Tests/test_ground_marks.cpp
index 5988a2482..b214ad623 100644
--- a/GeneralsMD/Code/Tests/test_ground_marks.cpp
+++ b/GeneralsMD/Code/Tests/test_ground_marks.cpp
@@ -3,9 +3,20 @@
#include "test_harness.h"
#include "W3DDevice/GameClient/GroundMarks.h"
+#include "W3DDevice/GameClient/StructureCollapse.h"
using namespace GroundMarks;
+TEST(a_collapsing_building_waits_a_beat_then_gets_faster_and_is_under_by_its_time)
+{
+ using namespace StructureCollapse;
+ CHECK_EQ(sunk(0.1f, 1.5f), 0.0f);
+ CHECK(sunk(0.6f, 1.5f) < 0.5f * sunk(1.2f, 1.5f));
+ CHECK_EQ(sunk(1.5f, 1.5f), 1.0f);
+ CHECK(sinkSeconds(20.0f) < sinkSeconds(60.0f));
+ CHECK_EQ(sinkSeconds(1000.0f), 2.5f);
+}
+
TEST(a_mark_holds_then_fades_to_nothing)
{
CHECK_EQ(strength(0), 1.0f);
diff --git a/GeneralsMD/Code/Tools/optionsmenu_layout.py b/GeneralsMD/Code/Tools/optionsmenu_layout.py
index f6f0b9eb0..a571350be 100644
--- a/GeneralsMD/Code/Tools/optionsmenu_layout.py
+++ b/GeneralsMD/Code/Tools/optionsmenu_layout.py
@@ -246,6 +246,7 @@ NEW_CONTROLS = [
(CHECK, "CheckWeather", "GUI:Weather"),
(CHECK, "CheckWaterSplashes", "GUI:WaterSplashes"),
(CHECK, "CheckAtmosphere", "GUI:Atmosphere"),
+ (CHECK, "CheckStructureCollapse", "GUI:StructureCollapse"),
(LABEL, "LabelGraphicsQuality", "GUI:GraphicsQuality"),
(SLIDER, "SliderGraphicsQuality", None),
]
@@ -350,7 +351,9 @@ GROUP_LAYOUT = [
setting("LabelFullscreenScaling", "ComboBoxFullscreenScaling"),
("check", "CheckVSync")]),
("GUI:OptionsGroupPicture", [
- setting("GammaLabel", "SliderGamma", "ValueGamma")])]),
+ setting("GammaLabel", "SliderGamma", "ValueGamma"),
+ # every column of Graphics and Effects is full
+ ("check", "CheckStructureCollapse")])]),
("PageGraphics", [
# the particle limit went to Effects' Particles group to make room for the quality slider