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
refactor(gameengine): both superweapons ripple now
Olcay Seygan10accca0f53e
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/ChromaKeyboard.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/ChromaKeyboard.cppindex 6e4560eca..90a42f231 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/ChromaKeyboard.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/ChromaKeyboard.cpp@@ -326,25 +326,25 @@ enum ChromaEffectstatic const Int NUKE_EFFECT_FRAMES = LOGICFRAMES_PER_SECOND * 3;static const Int LASER_EFFECT_FRAMES = LOGICFRAMES_PER_SECOND * 3;static const Int SCUD_EFFECT_FRAMES = LOGICFRAMES_PER_SECOND * 4;-/// How far the nuke's front travels a second, in half-boards. A device is two-/// of these across and about 1.4 from centre to corner, so at this speed the-/// front takes most of a second and a half to clear it.-static const Real NUKE_WAVE_SPEED = 1.0f;-/// How wide the lit band around that front is, in the same units.-static const Real NUKE_WAVE_WIDTH = 0.60f;-/// The detonation before the wave, and the ember left behind it. Without these-/// the nuke is one thin ring crossing the board in under a second with nothing-/// either side of it, which is easy to miss entirely.+// Both the nuke and the scud storm are ripples: rings behind rings, running out+// from where the thing landed. What separates them is size and how many. The+// nuke is one ripple from the middle of the board with long wavelength, so the+// rings are wide and reach the corners. The scud storm is a lot of small ones,+// each no bigger than a few keys, scattered and staggered.+//+// Distances are in half-boards: a device is two of these across and about 1.4+// from its centre to its corner.+static const Real NUKE_RIPPLE_SPEED = 1.0f; ///< how fast the outermost ring travels+static const Real NUKE_RIPPLE_WAVELENGTH = 0.55f; ///< ring to ring+static const Real NUKE_RIPPLE_REACH = 1.8f; ///< where the rings have died away+/// The detonation, before the first ring has gone anywhere.static const Real NUKE_FLASH_SECONDS = 0.30f;-static const Real NUKE_EMBER = 0.40f;-/// The scud storm falls as droplets, not as a wave: a lot of small landings-/// scattered over the board and spread across the whole four seconds. Each one-/// lands bright and small, spreads a little, and goes out.-static const Int SCUD_DROPLET_COUNT = 14;-static const Real SCUD_DROPLET_LIFE = 0.9f;-static const Real SCUD_DROPLET_RADIUS_START = 0.10f;-static const Real SCUD_DROPLET_RADIUS_END = 0.45f;+static const Int SCUD_RIPPLE_COUNT = 14;+static const Real SCUD_RIPPLE_LIFE = 1.1f;+static const Real SCUD_RIPPLE_SPEED = 0.55f;+static const Real SCUD_RIPPLE_WAVELENGTH = 0.16f;+static const Real SCUD_RIPPLE_REACH = 0.55f;static ChromaEffect s_effect = EFFECT_NONE;static UnsignedInt s_effectStartFrame = 0;@@ -383,14 +383,19 @@ static Int chromaEffectFrames( ChromaEffect effect )}//------------------------------------------------------------------------------/** How bright the band around a wave front is at this distance from its origin. */-static Real chromaWaveIntensity( Real distance, Real radius, Real width )+/** How bright one ripple is at this distance from where it landed. Nothing is+ * lit ahead of the outermost ring, the crests behind it are a cosine in the+ * distance the ring has already covered, and the whole thing dies off towards+ * the ripple's reach. */+static Real chromaRippleIntensity( Real distance, Real radius, Real wavelength, Real reach ){- if( radius <= 0.0f )+ if( radius <= 0.0f || distance > radius || distance >= reach )return 0.0f;- const Real offset = distance - radius;- const Real band = 1.0f - (offset < 0.0f ? -offset : offset) / width;- return band > 0.0f ? band : 0.0f;++ const Real phase = (radius - distance) / wavelength;+ const Real crest = 0.5f + 0.5f * cosf( phase * TWO_PI );+ // Squared, so the rings read as rings instead of as a soft gradient.+ return crest * crest * (1.0f - distance / reach);}//-----------------------------------------------------------------------------@@ -425,20 +430,12 @@ static Int chromaEffectColor( Real acrossFraction, Real downFraction, Int cellInif( s_effect == EFFECT_NUKE ){+ // One ripple, from the middle, big enough to reach the corners.const Real distance = (Real)sqrt( across * across + down * down );- const Real radius = elapsed * NUKE_WAVE_SPEED;- Real heat = chromaWaveIntensity( distance, radius, NUKE_WAVE_WIDTH );+ Real heat = chromaRippleIntensity( distance, elapsed * NUKE_RIPPLE_SPEED,+ NUKE_RIPPLE_WAVELENGTH, NUKE_RIPPLE_REACH );- // Ground the front has already passed keeps an ember, so the board is lit- // behind the wave rather than going straight back to black.- if( distance < radius )- {- const Real ember = NUKE_EMBER * (1.0f - distance / radius);- if( ember > heat )- heat = ember;- }-- // The detonation itself, before the wave has gone anywhere.+ // The detonation itself, before the first ring has gone anywhere.if( elapsed < NUKE_FLASH_SECONDS ){const Real flash = 1.0f - elapsed / NUKE_FLASH_SECONDS;@@ -462,33 +459,26 @@ static Int chromaEffectColor( Real acrossFraction, Real downFraction, Int cellInreturn chromaColor( body * body * body * 0.25f, body * body * 0.75f, body );}- // The scud storm rains down: a lot of small landings, in no particular place- // and at no particular moment, each one bright then gone.- const Real lastLanding = (Real)duration / (Real)LOGICFRAMES_PER_SECOND - SCUD_DROPLET_LIFE;+ // A lot of small ripples instead of one big one: rain on water rather than a+ // single stone, in no particular place and at no particular moment.+ const Real lastLanding = (Real)duration / (Real)LOGICFRAMES_PER_SECOND - SCUD_RIPPLE_LIFE;Real best = 0.0f;- for( Int droplet = 0; droplet < SCUD_DROPLET_COUNT; ++droplet )+ for( Int ripple = 0; ripple < SCUD_RIPPLE_COUNT; ++ripple ){- const UnsignedInt dropletSeed = s_effectSeed + (UnsignedInt)droplet * 0x9e3779b9u;- const Real age = elapsed - chromaHashUnit( dropletSeed + 2 ) * lastLanding;- if( age < 0.0f || age >= SCUD_DROPLET_LIFE )+ const UnsignedInt rippleSeed = s_effectSeed + (UnsignedInt)ripple * 0x9e3779b9u;+ const Real age = elapsed - chromaHashUnit( rippleSeed + 2 ) * lastLanding;+ if( age < 0.0f || age >= SCUD_RIPPLE_LIFE )continue;- const Real originAcross = (chromaHashUnit( dropletSeed ) - 0.5f) * 2.0f;- const Real originDown = (chromaHashUnit( dropletSeed + 1 ) - 0.5f) * 2.0f;+ const Real originAcross = (chromaHashUnit( rippleSeed ) - 0.5f) * 2.0f;+ const Real originDown = (chromaHashUnit( rippleSeed + 1 ) - 0.5f) * 2.0f;const Real dx = across - originAcross;const Real dy = down - originDown;const Real distance = (Real)sqrt( dx * dx + dy * dy );- // It lands as a point and spreads as it dies, the way a drop hitting a- // surface does.- const Real life = age / SCUD_DROPLET_LIFE;- const Real radius = SCUD_DROPLET_RADIUS_START- + (SCUD_DROPLET_RADIUS_END - SCUD_DROPLET_RADIUS_START) * life;- const Real falloff = 1.0f - distance / radius;- if( falloff <= 0.0f )- continue;-- const Real intensity = falloff * (1.0f - life);+ const Real intensity = chromaRippleIntensity( distance, age * SCUD_RIPPLE_SPEED,+ SCUD_RIPPLE_WAVELENGTH, SCUD_RIPPLE_REACH )+ * (1.0f - age / SCUD_RIPPLE_LIFE);if( intensity > best )best = intensity;}