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(w3ddevice): -volsmoke a nuke over a nuke's cloud takes its slab
Olcay Seyganae2eea8d6892
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ccfe82ea8..3b79d07de 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -115,7 +115,7 @@ found and fixed, EA's own, not port damage.**- A tank goes up the way the footage of a real one does. Orange flame and black smoke burst out low along its own hull, long under an Overlord and short under a Crusader, and roll along the ground off both ends. A ragged fan of blown-out white fire with orange edges rises straight off the hull and opens wider as it climbs, tallest in the middle, on High about twice as tall as the fire is wide and on Low a shorter fan of the same shape, and in about a second it has cooled through orange to grey-brown smoke. Two round near-black blobs stand on each long side of the hull at its top, in front of the fire, apart from each other with flame showing between them and their rims glowing red, and slump away inside a second; the soot laid there before burned with the fire beside it and from the side read as a haze. White-hot sparks streak up out of the fire and out over the fan in long thin straight lines and fall back, where they were short orange beaded comets. The wreck's black column is gone about two seconds after the death, and a thin wisp over a glowing ember fades out by three and a half, a quarter as long as the game's own smoke with the setting Off, so a fast game is never fighting through last minute's smoke; it used to stand for half a minute, which in a fast game left a field of black pillars. A Crusader's fan no longer stands on a thin stem or grows horns at its edges. The glowing ball and the rays round it are gone, and so is the ring on the ground. Shells that hit a tank's armour no longer throw a fountain of dirt off it. The scrap flying off a dead tank keeps its own sparks but no longer drags thick grey arcs across the fire, and every gun but a tank's keeps the soft grey muzzle puff it always had, where it had turned into a flat tan disc on the ground.- A tank gun fires the way footage of a real one does. A cone of flame comes straight out of the muzzle along the barrel's own aim, white-hot at the tip and orange-red at its fringe, widening forward, and is gone in about a sixth of a second; the first version blew a round ball a gun's length ahead of the barrel with a gap behind it. It leaves a little grey smoke in front of the gun over the dust the blast blows off the ground round the tank's front, and both are gone in a second and a half. A Battlemaster's or a Scorpion's smaller gun throws a smaller flame, an Overlord's a bigger one. A shell striking armour throws one dense burst of thin white-yellow streaks out of the point it struck, over a hot white core, back towards the tank that fired it. The game's own sparks used to burst over the turret whichever side was struck, and stacked on the new ones they read as fireworks all over the tank: for those hits they are gone, and the white oval that used to flash over the whole tank is a small flash now. In a fight of fifteen tanks the shots and hits cost about 0.2 ms of GPU time a frame on High and next to nothing on Low, on an RTX 2060. Six shots at a time draw this way on High and three on Low; past that a shot keeps the game's own flash, and a shot whose slab a bigger blast takes gets its own flash back.- A nuke builds a mushroom you can read. The flash is light: the ground, the buildings and the missile's own smoke trail go white for a third of a second, where a flat white disc used to cover half the screen for most of a second. From the first frame a lumpy ball of fire sits on the ground, yellow-white inside an orange-red rim, with a thin white dome running out round it, and the orange disc that lay on the ground under it is gone. The ball rises and slows, and by five seconds is an orange cap on a thin grey-brown stem. A white collar rings the stem for a few seconds. The cap cools to cream and lumpy cauliflower, three to four times as wide as the stem, stands whole for ten seconds, then softens and thins away and is gone 22 seconds after the blast, when the game's own nuke is gone with the setting Off. The old one was a dark brown disc that had thinned away inside twelve seconds, and the first version of this one stood for a minute and a half. The dark dust that used to bury the whole base under the cloud is gone, and a low wall of dust runs out along the ground between the buildings instead. The missile's own trail is smoke in the same air now, a thick pale column behind it on the way up from the silo and on the way down, drifting with the wind and spreading as it thins, where it used to stay a column of flat sprites.-- Every other smoke goes the same way while it is on: missile and rocket trails, the dust behind a tank, a burning building's column, muzzle smoke. They are fed into one body of air round the camera instead of being drawn as sprites, and a unit moving through it pushes it. A tank's hull shoves the smoke aside and leaves a turning wake, a jet drags a sheet of it down between two wingtip vortices, and a helicopter hovering low flattens a burning column into a dark ring on the ground and lifts a band of dust round itself. A blast's wave runs out through every smoke it reaches, the other blasts' clouds, the burning buildings' flames and the smoke hanging in the air, and moves it while it passes: a Scud Launcher's missile lands in the last one's smoke and shoves it aside, and a second nuke's wave tears into the first one's mushroom, which lets go of its cauliflower shape and is shoved aside and upward as a soft tan cloud, and thins away until it is gone 12 seconds after it was let go and never later than a nuke left alone; it used to hang on untouched for over a minute. On Low the second nuke takes the first one's place in the air, so there the first cloud goes the moment the second lands. Before, a wave's push was mostly lost in the first frame, a nuke's cap pulled itself straight back into shape, and a Scud's warheads pushed nothing at all. Units you cannot see push nothing, and a blast in the shroud sends no wave, so the smoke never gives away a stealthed tank, an unscouted base or a strike out of sight.+- Every other smoke goes the same way while it is on: missile and rocket trails, the dust behind a tank, a burning building's column, muzzle smoke. They are fed into one body of air round the camera instead of being drawn as sprites, and a unit moving through it pushes it. A tank's hull shoves the smoke aside and leaves a turning wake, a jet drags a sheet of it down between two wingtip vortices, and a helicopter hovering low flattens a burning column into a dark ring on the ground and lifts a band of dust round itself. A blast's wave runs out through every smoke it reaches, the other blasts' clouds, the burning buildings' flames and the smoke hanging in the air, and moves it while it passes: a Scud Launcher's missile lands in the last one's smoke and shoves it aside, and a second nuke's wave tears into the first one's mushroom, which lets go of its cauliflower shape and is shoved aside and upward as a soft tan cloud, and thins away until it is gone 12 seconds after it was let go and never later than a nuke left alone; it used to hang on untouched for over a minute. A nuke landing within 200 units of another goes off in that nuke's own air, and its wave pushes the old cloud out of the way as its fireball rises through it. A nuke landing further off and more than a sixth of a second after the first used to join it inside three seconds and 500 units, drawing and pushing nothing; now it is a nuke of its own. Low holds one nuke's air, so a second one moves that air under itself and the first cloud stays in it: whole up to about 450 units apart, cut by the air's edge beyond that and gone past about 800, where it used to go the moment the second landed. Before, a wave's push was mostly lost in the first frame, a nuke's cap pulled itself straight back into shape, and a Scud's warheads pushed nothing at all. Units you cannot see push nothing, and a blast in the shroud sends no wave, so the smoke never gives away a stealthed tank, an unscouted base or a strike out of sight.- Aircraft thin the smoke they fly through, at any height. A jet drags clean air along the last two and a half seconds of its path, through a nuke's stem or a burning column; its wake used to fade out as it climbed, and at its usual 100 units over the ground it was down to about half. A helicopter's downwash now reaches down from wherever it flies and thins what it blows through: a Helix crossing a nuke's stem leaves it visibly thinner, and one over a Scud Storm's cloud shoves it down and out along the ground. A helicopter more than about ten rotor radii up used to do nothing at all.- Missile and rocket trails are thin ribbons of real smoke. A Tomahawk's, a Rocket Buggy's and a Scud Launcher's lay a pale line that breaks into puffs, widens towards its old end, stirs and drifts off with the wind, and fades out along its length as it goes, the oldest end first, so a Rocket Buggy salvo no longer leaves a tan haze over the field: a Tomahawk's arc over Heartland Shield is gone about 2 s after the launch, where it hung on for 5 to 6 and the game's own lasts about 3. A trail that climbs high, a Scud's arc or the nine columns a Scud Storm puts up, goes into a second, taller body of air over the battlefield, a thousand units high, where it thins just as fast. The trails are lit by the sun like any smoke: the Scud Storm's columns had stood as straight glowing pillars of one width that read as beams of light, and at night on Dark Night the trails stood out pale blue as if lit from inside. Now a big missile, a Scud's, a Tomahawk's or the nuclear missile's, leaves a white plume that billows out wider as it ages, lumpy and shaded on its far side, while a Rocket Buggy's, a Stinger's or a Comanche's rocket leaves a thin grey trail. The infantry rockets follow the RPG-7 photo: a Tunnel Defender's, a Tank Hunter's or a Missile Defender's rocket carries a small bright flame right at its tail and draws a thin grey wisp straight along its path, where the game's own trail was a bright white rope with a regular wiggle (the rocket flies within a unit of a straight line; the game threw each point of its line sideways) and its glow burned as two orange dots a rocket's length behind it. The launcher puffs a white backblast behind the soldier instead of a yellow-white flash as big as he is. Every one burns at the nozzle, a short white-yellow flame that is gone a few frames behind the missile. A launch throws a cloud: a Scud Storm, a Scud Launcher, a Tomahawk launcher and the nuclear silo blow a white cloud out sideways over the pad and the ground round it, under a flash at the nozzle, and it is gone in about four seconds. A rocket's backblast leaves a white puff at the launcher, where before it was gone before it showed. Before, a fast missile's trail broke into a dotted line of brown blobs, and once a missile climbed past about 200 units over the ground the top of its trail simply vanished.- Buildings come down in their own shape. The smoke reads the building's model: the moment one dies, a white-yellow fireball bursts out of each of its parts, a War Factory's hall and its two stacks, a Speaker Tower's mast, bigger than the part it came from and pushed out through its walls, cools to orange under a sooty edge and is gone in well under a second, while a ragged plume climbs out of the tops and cools to smoke. Before, the parts filled with dull dust that slumped and only three small fires came off the roof. The chunks the building throws trail thin pale dust as they fly, gone before the column is, where they used to fly bare, and the white shower of shards that burst over the fall like a firework is gone while the smoke draws it; with the smoke Off both stay as they were. The collapse throws a pale dust cloud that rolls out along the ground on every side, heavier than the air and hugging the terrain, two to three times the building's width out before it thins, and runs round the buildings beside it, between their real walls and stacks rather than over one box. Before, the dust had nowhere to go but up, and a fall was only a column. The ruin burns under a thick black-grey column with the fire still glowing in its foot, where it used to be a thin pale wisp, for two seconds, so a fall's own smoke and dust are off the screen 3 to 4 s after it and only the game's own column is left in the air until about 6, sooner than the game's own at 7 to 8 (it stayed for fourteen at first, and in a fast game that hid the next fight); a damaged building's own smoke and the dust round it thin within a couple of seconds of their puffs. The size follows the building: an American Power Plant's is about half the width of a War Factory's or a Particle Cannon's. Each damaged stage on the way down blows fire out of the top of the standing building with a little smoke, where it used to leave a big black cloud over the roof, and the shells landing on it in that moment no longer leave their fireballs floating over the cloud. A Rocket Buggy's rockets hitting the rubble throw their dirt for a second and it falls back, where their brown fountains stood beside a fallen War Factory as tan fingers for six seconds after everything else had gone. The fall's smoke is lit on its sunny side: on Winter Wolf's snow it had stood as one block of pure black across the middle of the screen. The game's own fireball sprites, flare and flat shock ring for that moment are gone while the smoke is on; flying debris keeps its sparks.diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/VolumeShockCore.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/VolumeShockCore.hindex 801069ac0..1936bad19 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/VolumeShockCore.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/VolumeShockCore.h@@ -45,6 +45,25 @@ inline int releasedLife(int life, int age, int framesPerSecond)return end < life ? end : life;}+// A nuke's flare first seen more than FlareJoinFrames after a live nuclear volume's birth is a new nuke,+// not a part of it (its own mushroom systems join for longer, since they start later).+const int FlareJoinFrames = 10;+inline bool nukeFlare(const char *name) { return !std::strcmp(name, "NukeFlare") || !std::strcmp(name, "NukeGLAFlare"); }+// A nuke within this of the middle of a live nuke's box takes that slab over as it stands, cloud and+// flow, and goes off where it landed inside the box: its cap, 135 units across its radius, stays clear+// of the box's walls, which fade from 384 units out.+const float InheritReach = 200.0f;+// One past that, with no slab free, takes it too, the nearest: the box moves under it in whole cells,+// just far enough to bring it InheritReach from the middle. Two nukes 449 units apart then both stand+// inside the walls' fade, and the old cloud is off the box only past about 815.+inline void inheritShift(float dx, float dy, float cell, float shift[2])+{+ const float distance = std::sqrt(dx * dx + dy * dy);+ const float past = distance > InheritReach ? (distance - InheritReach) / distance : 0.0f;+ shift[0] = std::floor(dx * past / cell + 0.5f);+ shift[1] = std::floor(dy * past / cell + 0.5f);+}+// speed units/s, push units at the blast, r0 units (where D has halved), seconds it runs, the most of// the smoke one passage mixes awaystruct ShockClass { float speed, push, r0, seconds, disperse; };@@ -76,7 +95,7 @@ inline const ShockClass *frontOf(const char *name){if (!name) return nullptr;// a nuke's flare goes off at its impact, also when it joins a nuke before it and starts no volume- if (!std::strcmp(name, "NukeFlare") || !std::strcmp(name, "NukeGLAFlare")) return &Nuclear;+ if (nukeFlare(name)) return &Nuclear;if (!std::strcmp(name, "ScudMissleExplosionArms") || !std::strcmp(name, "ScudMissleLauncherExplosionArms")) return &Scud;if (!std::strcmp(name, "NukeCannonBlastWave")) return &NukeCannon;if (std::strstr(name, "Shockwave") || std::strstr(name, "BlastWave") || !std::strcmp(name, "CarpetBombWave")diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/DX11VolumeSmoke.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/DX11VolumeSmoke.cppindex 89e1e5ded..25de170c0 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/DX11VolumeSmoke.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/DX11VolumeSmoke.cpp@@ -1657,6 +1657,13 @@ struct Volume {// moved its middle; under 0.05 the cap is let go, free smoke.float hold = 1;float capPushed = 0;+ // A nuke that took over the slab of a nuke before it (heirOf): its own front pushes the old cloud,+ // which fades as free smoke until oldCloudEnds, in the colour it had (oldCream), and the fields+ // are still to move this many cells in the grid if the box moved under it (scrollInherited).+ bool inherited = false;+ int oldCloudEnds = 0;+ float oldCream = 0;+ int scroll[3] = {};};struct Tier {@@ -3081,7 +3088,8 @@ void schedule(const Volume &volume, unsigned slab, float t, DrawConstants *draw)billows = smoothstep01(t, 5.0f, 9.0f) * (0.5f + 0.5f * fade);spared = (std::max)(1 - smoothstep01(t, 4.0f, 8.0f), 1 - fade);// dark smoke round the fire at first, cream once it is lit only by the sun, greyer as it goes- const float cream = smoothstep01(t, 3.0f, 12.0f), grey = smoothstep01(t, VolumeShock::NukeFadeFrom, VolumeShock::NukeLife);+ // (one slab, one colour: a cloud inherited cream would have turned dark with the new fire's smoke)+ const float cream = (std::max)(smoothstep01(t, 3.0f, 12.0f), volume.oldCream), grey = smoothstep01(t, VolumeShock::NukeFadeFrom, VolumeShock::NukeLife);const float early[3] = { 0.32f, 0.22f, 0.16f }, lit[3] = { 0.88f, 0.84f, 0.78f }, late[3] = { 0.80f, 0.79f, 0.78f };for (unsigned i = 0; i < 3; ++i) soot[i] = early[i] + (lit[i] - early[i]) * cream + (late[i] - lit[i]) * grey;// the fire's gain low while the fireball is hottest, so its lumps and its cooler rim show@@ -3259,7 +3267,7 @@ void layFloor(ID3D11DeviceContext *context, const Tier &tier, unsigned slab, Vol// a blast on a building goes off on its roof, not inside it// (a launch's too: laid under a Scud Storm's silo, its billows were inside the building and only// a flat white sheet lay on the roof)- if (volume.reset && volume.kind != Airburst && volume.kind != Structure && volume.kind != Fire) {+ if ((volume.reset || (volume.inherited && now - volume.born < 2)) && volume.kind != Airburst && volume.kind != Structure && volume.kind != Fire) {const unsigned column = unsigned(volume.blast[1]) * shape.gx + unsigned(volume.blast[0]);volume.blast[2] = (std::max)(volume.blast[2], heights[column] + 0.5f);}@@ -3268,10 +3276,47 @@ void layFloor(ID3D11DeviceContext *context, const Tier &tier, unsigned slab, Volcontext->UpdateSubresource(tier.floor, 0, ®ion, heights.data(), shape.gx * sizeof(float), 0);}+// A box moved under the nuke that inherited it (heirOf): the smoke stays where it is in the world, so+// its fields move the other way in the grid, once. By copies, so no program is added for it.+void scrollInherited(ID3D11DeviceContext *context, Tier &tier)+{+ const TierShape &shape = tier.shape;+ bool any = false;+ for (unsigned slab = 0; slab < shape.slabs; ++slab) {+ const int *s = volumes[shape.first + slab].scroll;+ any = any || s[0] || s[1] || s[2];+ }+ if (!any) return;+ unbindCompute(context);+ const unsigned in = tier.current, out = 1 - in;+ const float zero[4] = {};+ context->ClearUnorderedAccessViewFloat(tier.velocity[1].write, zero);+ context->ClearUnorderedAccessViewFloat(tier.density[out].write, zero);+ context->ClearUnorderedAccessViewFloat(tier.pressure[0].write, zero); // (the old place's)+ for (unsigned slab = 0; slab < shape.slabs; ++slab) {+ int (&s)[3] = volumes[shape.first + slab].scroll;+ const int size[3] = { (int)shape.gx, (int)shape.gy, (int)shape.gz };+ const int kept[3] = { size[0] - std::abs(s[0]), size[1] - std::abs(s[1]), size[2] - std::abs(s[2]) };+ if (kept[0] > 0 && kept[1] > 0 && kept[2] > 0) {+ const int from[3] = { (std::max)(s[0], 0), (std::max)(s[1], 0), (std::max)(s[2], 0) };+ const UINT z = slab * shape.gz;+ const D3D11_BOX box = { (UINT)from[0], (UINT)from[1], z + from[2],+ UINT(from[0] + kept[0]), UINT(from[1] + kept[1]), z + from[2] + kept[2] };+ const UINT x = (std::max)(-s[0], 0), y = (std::max)(-s[1], 0), toZ = z + (std::max)(-s[2], 0);+ context->CopySubresourceRegion(tier.velocity[1].texture, 0, x, y, toZ, tier.velocity[0].texture, 0, &box);+ context->CopySubresourceRegion(tier.density[out].texture, 0, x, y, toZ, tier.density[in].texture, 0, &box);+ }+ s[0] = s[1] = s[2] = 0;+ }+ context->CopyResource(tier.velocity[0].texture, tier.velocity[1].texture);+ tier.current = out;+}+void step(ID3D11DeviceContext *context, unsigned t, int now, float dt, float seconds, const float sunToward[3], unsigned slabs){Tier &tier = state.tiers[t];const bool fire = t == 2;+ if (t == 1) scrollInherited(context, tier);if (fire) fireEmitting.clear(); // scheduleFire names them again belowsim.Step[0] = dt;sim.Step[1] = seconds;@@ -3307,7 +3352,10 @@ void step(ID3D11DeviceContext *context, unsigned t, int now, float dt, float sec// the front pushed off it drifts aside instead of fading at the cap's own spill rateif (volume.kind == Nuclear && volume.hold < 0.05f) sim.Thin[slab][0] = std::pow(0.5f, dt / VolumeShock::NukeDisperseHalfLife);else if (volume.kind == Nuclear && volume.live && secondsSince(volume, now) > VolumeShock::NukeFadeFrom) sim.Thin[slab][0] = std::pow(0.5f, dt / VolumeShock::NukeFadeHalfLife);- sim.Spill[slab][0] = std::pow(0.5f, dt / (CapSpillHalfLife + (LoosenedSpillHalfLife - CapSpillHalfLife) * (1 - volume.hold)));+ // (an inherited cloud lies mostly outside the young cap: at the cap's own 1 s it was gone 3 s after+ // the front that pushed it, so it fades as a cloud let go does, and at 1 s again for its last 3 s)+ sim.Spill[slab][0] = std::pow(0.5f, dt / (now < volume.oldCloudEnds ? VolumeShock::NukeDisperseHalfLife+ : CapSpillHalfLife + (LoosenedSpillHalfLife - CapSpillHalfLife) * (1 - volume.hold)));const bool rolls = (volume.kind == Structure && !volume.standing) || volume.kind == Launch || volume.kind == Muzzle;// (not a bomb's: its small mushroom's stem would fall out of it)// (a tank's: its dark base masses slump slowly onto the ground, which eats them; the weight goes@@ -3502,7 +3550,9 @@ void fillShocks(int now)// their own smoke, and the tank's fan is laid where the shell's front would blow it away.bool spares(const Volume &volume, int slot, const Shock &shock){- if (shock.owner == slot && shock.ownerBorn == volume.born) return true;+ // (an heir's too, the nuke's it took over from: that front passing its young cap let go of it, and+ // with the old timeline gone neither nuke made a mushroom. It still pushes the smoke: shockMask)+ if (shock.owner == slot && (shock.ownerBorn == volume.born || volume.inherited)) return true;if (std::abs(volume.born - shock.born) > 10) return false;const float dx = shock.at[0] - (volume.origin[0] + (volume.blast[0] + 0.5f) * volume.cell);const float dy = shock.at[1] - (volume.origin[1] + (volume.blast[1] + 0.5f) * volume.cell);@@ -3518,7 +3568,8 @@ float shockMask(const float low[3], const float high[3], float cell, int slot)for (size_t i = 0; i < fronts.size(); ++i) {const Front &front = fronts[i];const Shock &shock = *front.shock;- if (slot >= 0 && spares(volumes[slot], slot, shock)) continue;+ // (an inherited slab takes its own nuke's front: that is what pushes the old cloud in it)+ if (slot >= 0 && !volumes[slot].inherited && spares(volumes[slot], slot, shock)) continue;const float reach = 3.0f * (std::max)(front.width, 1.5f * cell);float nearest = 0, farthest = 0;for (unsigned k = 0; k < 3; ++k) {@@ -4411,6 +4462,27 @@ float joinRadius(const Volume &volume)// a gun's own FX all go off at its muzzle bone, the ground ring under itreturn volume.kind == Nuclear ? 500.0f : volume.kind == TankDeath ? 60.0f : volume.kind == Muzzle ? 14.0f : 30.0f * volume.scale;}+// The live nuke whose slab a new nuke at `where` takes over, or -1: the one whose box's middle it is+// within InheritReach of, or the nearest if no slab is free. (Only nukes live in this tier.)+int heirOf(const Coord3D &where, const TierShape &shape)+{+ int nearest = -1;+ float best = 1e30f;+ bool free = false;+ for (unsigned slot = shape.first; slot < shape.first + shape.slabs; ++slot) {+ const Volume &volume = volumes[slot];+ if (!volume.live) {+ free = true;+ continue;+ }+ const float dx = where.x - (volume.origin[0] + shape.gx * volume.cell * 0.5f), dy = where.y - (volume.origin[1] + shape.gy * volume.cell * 0.5f);+ if (dx * dx + dy * dy < best) {+ best = dx * dx + dy * dy;+ nearest = (int)slot;+ }+ }+ return !free || best <= VolumeShock::InheritReach * VolumeShock::InheritReach ? nearest : -1;+}// A tank's volume past 1.75 s holds only its smoulder, so it gives its slab up before any new blast does.// A gun's shot gives its slab up before anything.int rankOf(const Volume &volume)@@ -5048,11 +5120,13 @@ bool Takes(ParticleSystem *system)if (kindNow == TankDeath && building && !onBuilding) kindNow = Structure;// A nuke's own mushroom systems are first seen when they come into view, not when they start: from// the play camera its NukeMushroomCloudRing, 2 s on, was first seen 3.5 s on, started a nuke of its- // own, evicted the nuke before it and let go of its own nuke's cap. Its flare keeps 180 frames.- const bool lateMushroom = kind.trigger && kindNow == Nuclear && std::strcmp(own, "NukeFlare") && std::strcmp(own, "NukeGLAFlare");+ // own, evicted the nuke before it and let go of its own nuke's cap. A flare is a new nuke, unless it+ // goes off with the one it finds: at 180 frames a second nuke 3 s later joined, drew and pushed nothing.+ const bool flare = VolumeShock::nukeFlare(own);+ const bool lateMushroom = kind.trigger && kindNow == Nuclear && !flare;for (const Volume &volume : volumes) {if (!volume.live || volume.kind == Fire || seen < volume.born - 10- || seen > volume.born + (volume.kind == Nuclear ? (lateMushroom ? 600 : 180) // a nuke's stem comes 2 s after its flare+ || seen > volume.born + (volume.kind == Nuclear ? (flare ? VolumeShock::FlareJoinFrames : lateMushroom ? 600 : 180) // a nuke's stem comes 2 s after its flare: volume.kind == TankDeath || volume.kind == Structure ? 90 : 30)) continue;// a gun's shot takes its own FX only, and they join nothing else (a tank firing beside a dead// one keeps its shot)@@ -5119,11 +5193,13 @@ bool Takes(ParticleSystem *system)if (type == Launch && kind.scale < 1.2f && !structureAt(where, INVALID_ID)) fresh.scale = 0.6f;const int rank = rankOf(fresh);- // A free slab, else the one of the lowest rank whose blast is oldest; a new blast of a lower- // rank than every live one is dropped instead. Either way no billboards.- unsigned slot = shape.first;- while (slot < shape.first + shape.slabs && volumes[slot].live) ++slot;- if (slot == shape.first + shape.slabs) {+ // A nuke over a live nuke's cloud takes its slab as it stands. Otherwise a free slab, else the one+ // of the lowest rank whose blast is oldest; a new blast of a lower rank than every live one is+ // dropped instead. Either way no billboards.+ const int heir = type == Nuclear ? heirOf(where, shape) : -1;+ unsigned slot = heir >= 0 ? (unsigned)heir : shape.first;+ while (heir < 0 && slot < shape.first + shape.slabs && volumes[slot].live) ++slot;+ if (heir < 0 && slot == shape.first + shape.slabs) {slot = shape.first;for (unsigned i = shape.first + 1; i < shape.first + shape.slabs; ++i)if (rankOf(volumes[i]) < rankOf(volumes[slot])@@ -5147,9 +5223,10 @@ bool Takes(ParticleSystem *system)gunSystems.erase(shot);}}+ const Volume before = volume;volume = fresh;volume.live = true;- volume.reset = true;+ volume.reset = heir < 0 || before.reset; // (an heir's fields stay: the first step would have cleared the old cloud)volume.cell = cellOf(type, volume.scale);// A building's box is about two and a half footprints across, so the cell goes with its size: 3// units for an American power plant, about 6.5 for a War Factory or a Particle Cannon. None@@ -5163,6 +5240,14 @@ bool Takes(ParticleSystem *system)const float sideX = shape.gx * volume.cell, sideY = shape.gy * volume.cell;volume.origin[0] = where.x - sideX * 0.5f;volume.origin[1] = where.y - sideY * 0.5f;+ if (heir >= 0) {+ float shift[2];+ VolumeShock::inheritShift(where.x - (before.origin[0] + sideX * 0.5f), where.y - (before.origin[1] + sideY * 0.5f), volume.cell, shift);+ for (unsigned i = 0; i < 2; ++i) {+ volume.origin[i] = before.origin[i] + shift[i] * volume.cell;+ volume.scroll[i] = before.scroll[i] + (int)shift[i];+ }+ }// The box's floor under the lowest ground it covers, so smoke can run down into a valley; the// terrain itself is laid into the grid as solid (layFloor).float lowest = (std::min)(where.z, ground);@@ -5175,6 +5260,18 @@ bool Takes(ParticleSystem *system)volume.origin[2] = (std::max)(lowest, (std::min)(where.z, ground) - 3.0f * volume.cell) - volume.cell;volume.blast[0] = (shape.gx - 1) * 0.5f;volume.blast[1] = (shape.gy - 1) * 0.5f;+ if (heir >= 0) {+ const float up = std::floor((volume.origin[2] - before.origin[2]) / volume.cell + 0.5f);+ volume.origin[2] = before.origin[2] + up * volume.cell;+ volume.scroll[2] = before.scroll[2] + (int)up;+ volume.blast[0] = (where.x - volume.origin[0]) / volume.cell - 0.5f;+ volume.blast[1] = (where.y - volume.origin[1]) / volume.cell - 0.5f;+ volume.inherited = true;+ volume.oldCloudEnds = before.born + before.life - 3 * LOGICFRAMES_PER_SECOND;+ volume.oldCream = (std::max)(before.oldCream, smoothstep01(secondsSince(before, now), 3.0f, 12.0f));+ DEBUG_LOG(("VOLSMOKE: frame %d, nuke at (%.0f, %.0f) takes over slab %u from the nuke born at frame %d, the box moved (%d, %d, %d) cells\n",+ now, where.x, where.y, slot, before.born, volume.scroll[0], volume.scroll[1], volume.scroll[2]));+ }// at the blast's height, but never under the ground: the ground turns its pushconst float groundCell = (ground - volume.origin[2]) / volume.cell;volume.ground = groundCell;diff --git a/GeneralsMD/Code/Tests/test_volume_fire_policy.cpp b/GeneralsMD/Code/Tests/test_volume_fire_policy.cppindex 308ff0388..ed286f892 100644--- a/GeneralsMD/Code/Tests/test_volume_fire_policy.cpp+++ b/GeneralsMD/Code/Tests/test_volume_fire_policy.cpp@@ -248,6 +248,30 @@ TEST(volume_shock_nuclear_cloud_lasts_as_long_as_the_games_own)CHECK(NukeDisperseLife >= NukeLife - NukeFadeFrom - 1.0f);}+TEST(volume_shock_a_nuke_over_a_nukes_cloud_takes_its_slab)+{+ using namespace VolumeShock;+ CHECK(nukeFlare("NukeFlare"));+ CHECK(nukeFlare("NukeGLAFlare"));+ CHECK(!nukeFlare("NukeMushroomCloudRing"));+ CHECK(!nukeFlare("NukeBaikonurFlare"));+ float shift[2];+ // volshock's nuke 2, 148 units from nuke 1, stands in the box where it is+ inheritShift(130.0f, -70.0f, 10.0f, shift);+ CHECK_EQ(shift[0], 0.0f);+ CHECK_EQ(shift[1], 0.0f);+ // nuke 3, 434 from nuke 2: the box moves by whole cells to bring it InheritReach from the middle...+ inheritShift(-430.0f, -60.0f, 10.0f, shift);+ CHECK_EQ(shift[0], -23.0f);+ CHECK_EQ(shift[1], -3.0f);+ const float cap = 135.0f, wallFade = 384.0f;+ const float fresh = std::hypot(-430.0f - shift[0] * 10.0f, -60.0f - shift[1] * 10.0f);+ CHECK_NEAR(fresh, InheritReach, 10.0f);+ CHECK(fresh + cap < wallFade);+ // ...and the old cloud, now as far the other way, stays inside the walls' fade too+ CHECK(std::hypot(shift[0] * 10.0f, shift[1] * 10.0f) + cap < wallFade);+}+TEST(volume_shock_templates_that_start_a_front){using namespace VolumeShock;