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(gameclient): stealthed fire and smoke follow their stealth
Olcay Seyganb3a7c2fa8d86
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 8f5e2ab22..92f4ceeed 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1460,6 +1460,7 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same- A China mine field tells you what kind it is. EA's field had no model at all, only a soft white glint swelling and fading on each of its eight spots, so your own minefield looked like a patch of fireflies. Each mine is now marked by a small arming light that snaps on for a quarter of a second every second and a half, red on standard and cluster mines and blue on EMP mines, with a white-hot point and a dark rim that keep it readable on grass, sand or snow. No mine body is drawn on the ground, only the light. The enemy still sees nothing until he detects the field. A mine going off under a tank now throws a column of dark earth twice the tank's height, scatters clods round it and leaves a low black smoke and a scorch, with a short jolt of the screen; it used to puff a pale spray of specks that looked like dust kicked up. An EMP mine throws no earth, so you can tell which kind went off: it lights a blue ring across the ground, a crackle of blue sparks and a short blue flash at the spot; EA's flash grew until it washed the whole screen white for a fifth of a second. What a mine does is unchanged.- A base out of power looks out of power. A building that switches off when your power runs short, or one a hacker shut down, drains to a cold grey and sags darker, and its windows and lamps go out. Every few seconds it blinks dark for an instant or its lights catch again for a moment, and blue sparks jump on its walls where something shorts. A tank or building hit by an EMP crawls with thin blue arcs for as long as it stays dead, where it used to just turn dark grey.- Your own stealthed units look like glass, not like ice. In 3.0 a camouflaged Rebel, a Pathfinder or Colonel Burton came out under a blue skin with bands running up it, which players rightly called ugly. The blue is gone: the ground behind him shows through his body in its own colours and bends, a slow lens that ripples along him and pulls harder at his outline, with only a hint of his own paint left in it. The bend is what you find him by: each face of him tips the ground behind it its own way, so his shape shows even on plain sand, and the bend never drops below a few pixels, and a faint cool haze that thickens at his outline keeps a cloaked soldier or building findable at the zoom you play at, without turning him white. Up close a building's flat wall bends across its face. It moves slowly and never fizzes. He never turns solid, and the 2003 breathing of the fade is still there. His shadow fades with him, to between a quarter and a half of its strength as he breathes, where it used to lie on the ground at full strength and give him away before his body did; on Classic and the old renderer the shadow stays whole. When an enemy detector has found him, his whole body beats amber along with his edge, so a spotted building reads as spotted and does not just turn tan. On every renderer, a stealthed unit of yours no longer comes out solid whenever no building is on the screen: the game drew it a second time without its see-through. An enemy stealth unit your detector finds used to turn into a flat orange shape with no paint; now it shows as heat, its own shading run from dark red through orange to a warm yellow that stops short of white, so you can still tell a tank from a soldier and bright GLA paint keeps its detail, with a burning outline and a slow glow climbing it that flares on every sweep of the detector. The fine scan lines of 3.0 are gone, since zoomed out they broke into stripes. This is the default renderer; Classic and the old renderer keep the 2003 look for all of these.+- A hidden base no longer burns in plain view. The fire and smoke on a stealthed building or unit, damage flames and chimney smoke alike, kept drawing for the enemy while the building itself was invisible, so a burning Stealth General base under Camo Netting stood out as a column of black smoke on an empty patch of ground. The enemy now sees none of it until a detector finds the building, and then all of it. On your own side the flames and smoke go faint with the building and breathe with it, the fire a little stronger than the smoke, so they no longer sit at full strength beside the glass. This holds on every renderer, and the smoke's shadow and the light its fire throws on nearby smoke go with it.- Effects fade out instead of blinking off. The rings a nuke sends across the ground, and any spark, flash or puff whose own colours never reached nothing, used to vanish at full strength on their last frame. Each one now dims away over its last quarter of a second, or over a quarter of its life when it lives shorter than that. One that was already fading looks the way it always did.- Toxin, anthrax and radiation pools lie on the ground. A pool is a carpet of puddle pictures spread up to 140 paces from where the shell or the spray came down, and every one of them was drawn dead flat at the height of that one spot: on a hillside the uphill half of the pool disappeared into the slope and the downhill half hung in the air above it. Each puddle now bends over the ground underneath it, on both renderers, and a pool on a bridge stays on the deck. The pool also holds still. It used to throb twice a second, because every half second the pool's poison fired a fresh batch of puddles that swelled out of black to full green and back to black in two seconds, each batch somewhere new. Now it comes up in half a second, stays one pool at full colour for as long as it does damage, and fades over its last three seconds, or over three seconds from the moment the fog of war closes over it. It is not frozen, though: each puddle fades down and back up on its own beat, so the surface shimmers like something liquid while the pool as a whole never pulses. Four Scud warheads landing on one spot used to stack into a white-hot blotch in the middle; overlapping pools now share their light and the middle stays toxin green. The ground under it takes on its colour, green for toxin and the anthrax colours for anthrax, so it looks spilled rather than shone onto the grass. China's radiation keeps its orange but glows instead of browning the grass, which made it look like a scorch mark, and small bubbles swell out of it and pop. A nuke's radiation lies on the hillside as a pool from three seconds after the blast, where its first ten seconds used to be flat squares cutting into the slope.- A Scud Storm or a carpet bomb shakes the screen as hard as it should. The game cut a pile of heavy shakes back to a mild one, so a run of missiles or bombs landing together shook less than one of them alone. Each now shakes a step lighter and the run builds up. Demo traps and Aurora bombs shake now, and a falling building shakes harder the bigger it was.diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ParticleSys.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ParticleSys.hindex 3750062ec..ae1ce6c3f 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ParticleSys.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ParticleSys.h@@ -793,6 +793,9 @@ public:/// TRUE if this system is the kind of big soft cloud that should shade the ground under itBool shouldCastGroundShadow( void ) const;+ /// How much of this system the local player sees, for the stealth of what it is attached to.+ Real getStealthFade( void ) const;+protected:// snapshot methodsdiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cppindex f4d37e606..b1c21f1f9 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp@@ -2691,7 +2691,54 @@ Bool ParticleSystem::shouldCastGroundShadow( void ) constif (m_isGroundAligned)return FALSE;- return TRUE;+ return getStealthFade() > 0.0f;+}++// ------------------------------------------------------------------------------------------------+/** The smoke and fire on a stealthed unit or building go with it. An enemy's that the local player+ * cannot see draw nothing: retail stopped only the model's own bone systems, and a hidden base still+ * burned and smoked in plain view. The player's own stealthed one breathes with its stealth+ * opacity, a third of it for smoke and a little over half for fire, beside the glass the cloak draws.+ * Detected by the enemy, or not stealthed at all, it draws whole. A slave follows its master, which+ * carries the attachment. Client drawing only; nothing goes back into the logic. */+// ------------------------------------------------------------------------------------------------+Real ParticleSystem::getStealthFade( void ) const+{+ const ParticleSystem *sys = this;+ while (sys->m_masterSystem)+ sys = sys->m_masterSystem;++ const Drawable *draw = NULL;+ if (sys->m_attachedToDrawableID != INVALID_DRAWABLE_ID)+ draw = TheGameClient->findDrawableByID( sys->m_attachedToDrawableID );+ else if (sys->m_attachedToObjectID != INVALID_ID)+ {+ // gone since the last particle update, which then destroys the system+ const Object *obj = TheGameLogic->findObjectByID( sys->m_attachedToObjectID );+ if (obj)+ draw = obj->getDrawable();+ }+ if (draw == NULL)+ return 1.0f;++ switch (draw->getStealthLook())+ {+ case STEALTHLOOK_INVISIBLE:+ return 0.0f;+ case STEALTHLOOK_VISIBLE_FRIENDLY:+ case STEALTHLOOK_VISIBLE_FRIENDLY_DETECTED:+ // Alpha tested particles take no fade (less alpha only cuts holes in them), and a+ // multiplying one half faded is a grey smear, so those draw whole and not at all.+ switch (m_shaderType)+ {+ case ADDITIVE: return draw->getEffectiveOpacity() * 0.55f;+ case ALPHA_TEST: return 1.0f;+ case MULTIPLY: return 0.0f;+ default: return draw->getEffectiveOpacity() * 0.35f;+ }+ default:+ return 1.0f;+ }}// ------------------------------------------------------------------------------------------------@@ -2735,7 +2782,7 @@ void ParticleSystem::updateGroundShadow( const ParticleShadowBlob *blob )m_groundShadow->setSize( sizeX, sizeY );m_groundShadow->setPosition( centerX, centerY,TheTerrainLogic ? TheTerrainLogic->getGroundHeight( centerX, centerY ) : 0.0f );- m_groundShadow->setOpacity( opacity );+ m_groundShadow->setOpacity( REAL_TO_INT( opacity * getStealthFade() ) );}// ------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DParticleSys.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DParticleSys.hindex d75393352..2334a08db 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DParticleSys.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DParticleSys.h@@ -79,6 +79,7 @@ public:ShaderClass shader;Int capacity; ///< quads reserved: the system's particles, at most MAX_POINTS_PER_GROUPUnsignedInt fieldIncrement; ///< 1 if every drawn particle counts against the field budget+ Real fade; ///< ParticleSystem::getStealthFade, above zeroInt drawn; ///< written by the jobUnsignedInt pastLimit; ///< written by the job: on-screen particles past capacityBool glow; ///< written by the job: the fire's glow is in the normals, not the colourdiff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cppindex 3f7d74785..513aec57e 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp@@ -3940,10 +3940,15 @@ static void fillSmokeMap( const Matrix3D &sunTransform, const Vector3 &focus, Reif (*((UnsignedInt *)sys->getParticleTypeName().str()) == 0x44554D53)continue;+ // a stealthed thing's smoke shades the ground only as much as it is drawn+ const Real fade = sys->getStealthFade();+ if (fade <= 0.0f)+ continue;+const UnsignedInt layers = sys->getVolumeParticleDepth();for (Particle *p = sys->getFirstParticle(); p; p = p->m_systemNext){- const Real opticalDepth = particleSunMapOpticalDepth( p->getAlpha(), layers );+ const Real opticalDepth = particleSunMapOpticalDepth( p->getAlpha() * fade, layers );if (opticalDepth <= 0.0f)continue;const Coord3D *pos = p->getPosition();diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cppindex ab67e15ba..453224ebc 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp@@ -167,7 +167,7 @@ static UnsignedInt s_fireLightsParticles;static UnsignedInt s_fireLightsSystems;/** One additive system as a point light, if it is bright enough. */-static void gatherFireLight( ParticleSystem *sys )+static void gatherFireLight( ParticleSystem *sys, Real fade ){Real w = 0.0f, x = 0.0f, y = 0.0f, z = 0.0f, sq = 0.0f;for (Particle *p = sys->getFirstParticle(); p; p = p->m_systemNext)@@ -202,7 +202,7 @@ static void gatherFireLight( ParticleSystem *sys )fire.reach = reach;// fire's own colour, and the strength from how much of the flames there is- light.strength = w < FIRE_LIGHT_FULL_WEIGHT ? w / FIRE_LIGHT_FULL_WEIGHT : 1.0f;+ light.strength = (w < FIRE_LIGHT_FULL_WEIGHT ? w / FIRE_LIGHT_FULL_WEIGHT : 1.0f) * fade;const Real scale = light.strength * FIRE_LIGHT_GAIN;light.r = FIRE_LIGHT_RED * scale;light.g = FIRE_LIGHT_GREEN * scale;@@ -376,6 +376,22 @@ static inline void lightSmoke( const Coord3D *pos, Real alpha, const SmokeLight}}+/** A particle of a stealthed thing's system, faded by ParticleSystem::getStealthFade, which only+ * hands a partial fade to additive and alpha blended systems: an additive particle adds less+ * light, an alpha blended one takes less alpha. */+static inline void stealthFadeParticle( ParticleSystemInfo::ParticleShaderType type, Real fade,+ Real &red, Real &green, Real &blue, Real &alpha )+{+ if (type == ParticleSystemInfo::ADDITIVE)+ {+ red *= fade;+ green *= fade;+ blue *= fade;+ }+ else+ alpha *= fade;+}+/** What every job of one frame's billboard fill reads. */struct BillboardFillJob{@@ -407,6 +423,7 @@ static void fillBillboards( Int index, void *context )Int drawn = 0;SmokeLight lights[ SMOKE_LIGHTS_PER_SYSTEM ];const Int lightCount = pickSmokeLights( fill.system, job->lights, job->lightCount, lights );+ const ParticleSystemInfo::ParticleShaderType shaderType = fill.system->getShaderType();for (Particle *p = fill.system->getFirstParticle(); p; p = p->m_systemNext){@@ -437,7 +454,10 @@ static void fillBillboards( Int index, void *context )blue = color->blue;}}- const unsigned packed = DX8Wrapper::Convert_Color_Clamp( Vector4( red, green, blue, p->getAlpha() ) );+ Real alpha = p->getAlpha();+ if (fill.fade < 1.0f)+ stealthFadeParticle( shaderType, fill.fade, red, green, blue, alpha );+ const unsigned packed = DX8Wrapper::Convert_Color_Clamp( Vector4( red, green, blue, alpha ) );// The orientation table's index wraps, as it did on Windows (Platform/MsvcFloatCasts.h).const uint8 orientation = floatToByteAsMsvc( p->getAngle() * 255.0f / (2.0f * PI) );PointGroupClass::Write_Billboard( quad, job->view, Vector3( pos->x, pos->y, pos->z ), psize,@@ -663,6 +683,7 @@ struct FieldStateRGBColor color; ///< the template's brightest keyframeParticleSystemInfo::ParticleShaderType shader;AsciiString texture;+ Real stealth; ///< ParticleSystem::getStealthFade of the last system seen at it};static const Int FIELD_GRACE = LOGICFRAMES_PER_SECOND; ///< logic frames a field with no object outlives its systems@@ -845,6 +866,7 @@ static Int collectGroundFields( ParticleSystemManager::ParticleSystemList &systestate.radius = WWMath::Max( state.radius, radius );state.particleEnd = WWMath::Max( state.particleEnd, now + life );}+ st->second.stealth = sys->getStealthFade();}Int laid = 0;@@ -855,15 +877,17 @@ static Int collectGroundFields( ParticleSystemManager::ParticleSystemList &syste// Kept while its systems are, even faded out: the systems outlive the object by a few// seconds, and a field forgotten under them would be found again as a new one.- const Real fade = fieldFade( state, now );+ const Real lifeFade = fieldFade( state, now );const Bool stale = now - state.seen > FIELD_GRACE;- if ((stale && fade <= 0.0f) || now < state.seen)+ if ((stale && lifeFade <= 0.0f) || now < state.seen){// out, or a frame count from before a loads_fieldStates.erase( st++ );continue;}++st;+ // a field on a stealthed thing goes with it, as its other particles do+ const Real fade = lifeFade * state.stealth;if (fade <= 0.0f)continue;@@ -1243,6 +1267,10 @@ void W3DParticleSystemManager::doParticles(RenderInfoClass &rinfo)if (particles == 0)continue;+ fill.fade = sys->getStealthFade();+ if (fill.fade <= 0.0f)+ continue;+fill.system = sys;fill.capacity = (particles < (Int)MAX_POINTS_PER_GROUP) ? particles : (Int)MAX_POINTS_PER_GROUP;fill.fieldIncrement = ( sys->getPriority() == AREA_EFFECT && sys->m_isGroundAligned != FALSE ) ? 1 : 0;@@ -1277,7 +1305,12 @@ void W3DParticleSystemManager::doParticles(RenderInfoClass &rinfo)ParticleSystem *sys = *it;if (sys && !sys->isUsingDrawables() && sys->getShaderType() == ParticleSystemInfo::ADDITIVE&& sys->getParticleCount() > 0)- gatherFireLight( sys );+ {+ // a hidden fire lights nothing, an own stealthed one only as much as it shows+ const Real fade = sys->getStealthFade();+ if (fade > 0.0f)+ gatherFireLight( sys, fade );+ }}s_fireLightsValid = TRUE;s_fireLightsFrame = m_lastLogicFrameUpdate;@@ -1316,6 +1349,11 @@ void W3DParticleSystemManager::doParticles(RenderInfoClass &rinfo)if (sys->isUsingDrawables())continue;+ // the same answer the billboard reservation above had, so a skipped system is skipped here too+ const Real fade = sys->getStealthFade();+ if (fade <= 0.0f)+ continue;+//temporary hack that checks if texture name starts with "SMUD" - if so, we can assume it's a smudge typeif (/*sys->isUsingSmudge()*/ *((UnsignedInt *)sys->getParticleTypeName().str()) == 0x44554D53){@@ -1345,7 +1383,7 @@ void W3DParticleSystemManager::doParticles(RenderInfoClass &rinfo)// for both - now that it reads .Y, a heat smudge pulled twice as far sideways.smudge->m_offset.Set( GameClientRandomValueReal(-0.06f,0.06f), GameClientRandomValueReal(-0.06f,0.06f) );smudge->m_size = psize;- smudge->m_opacity = p->getAlpha();+ smudge->m_opacity = p->getAlpha() * fade;visibleSmudgeCount++;}}@@ -1422,7 +1460,9 @@ void W3DParticleSystemManager::doParticles(RenderInfoClass &rinfo)RGBAArray[count].W = p->getAlpha();if (lightCount > 0)lightSmoke( pos, RGBAArray[count].W, lights, lightCount, RGBAArray[count].X, RGBAArray[count].Y, RGBAArray[count].Z );-+ if (fade < 1.0f)+ stealthFadeParticle( sys->getShaderType(), fade, RGBAArray[count].X, RGBAArray[count].Y, RGBAArray[count].Z, RGBAArray[count].W );+angleArray[count] = floatToByteAsMsvc( p->getAngle() * 255.0f / (2.0f * PI) );if (++count == MAX_POINTS_PER_GROUP)