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.

fix(gameengine): one signal a second, and smoke you can see and tint

Olcay Seyganba919e151a0f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fadb53f59..d3bccc244 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -504,6 +504,7 @@ found and fixed — EA's own, not port damage.**
- Off in one place. `ShowAllyCursors = no` in `Options.ini` stops both halves: nothing is sent from your machine and nothing is drawn on it.
- Alt+Z, Alt+X and Alt+C put up a puff of smoke where your mouse is. Red says attack here, blue says defend here, yellow says look at this. Point at the radar instead and the smoke goes up on that spot of the map.
- Your allies see the smoke and their radar blinks at the spot, and the message area says who sent it. Three seconds later the smoke has cleared, so the call you made a minute ago is never still standing next to the one you are making now. Enemies see none of it.
+- One signal a second per player. Hammering the key gets you the first puff and nothing else, and a teammate who tries it cannot bury your screen in smoke either, because every machine in the game holds everyone to the same limit.
## The options screen has pages
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp
index 4b0362317..4c97a231c 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp
@@ -975,11 +975,13 @@ void ParticleSystemInfo::tintAllColors( Color tintColor )
rgb.setFromInt(tintColor);
//This tints all but the first colorKey!!!
+ // setFromInt has already brought each channel to 0..1; dividing by 255 again here turned every
+ // tint into black, which nobody saw because only the beacon's never-taken fallback called it
for (int key = 1; key < MAX_KEYFRAMES; ++key )
{
- m_colorKey[ key ].color.red *= (Real)(rgb.red ) / 255.0f;
- m_colorKey[ key ].color.green *= (Real)(rgb.green) / 255.0f;
- m_colorKey[ key ].color.blue *= (Real)(rgb.blue ) / 255.0f;
+ m_colorKey[ key ].color.red *= rgb.red;
+ m_colorKey[ key ].color.green *= rgb.green;
+ m_colorKey[ key ].color.blue *= rgb.blue;
}
} // end loadPostProcess
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
index 8d47b214c..707335d95 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
@@ -424,6 +424,26 @@ static const Real SIGNAL_SECONDS = 3.0f;
/// the smoke is fed for the first half of the signal and its last puff fades out over the second
static const UnsignedInt SIGNAL_HALF_FRAMES = (UnsignedInt)( SIGNAL_SECONDS * LOGICFRAMES_PER_SECOND / 2 );
+static const UnsignedInt SIGNAL_COOLDOWN_FRAMES = LOGICFRAMES_PER_SECOND;
+
+// The beacon template draws a column nine units wide that needs five seconds to climb, which at the
+// signal's three seconds and the default camera height is a dark speck. Measured on screen, not
+// derived: these make it a plume a tank's width across that a player finds at a glance.
+static const Real SIGNAL_SMOKE_SIZE_SCALE = 5.0f;
+static const Real SIGNAL_SMOKE_DENSITY_SCALE = 3.0f;
+static const Real SIGNAL_SMOKE_RISE_SCALE = 3.0f;
+static const Real SIGNAL_SMOKE_ALPHA_MIN = 0.6f;
+static const Real SIGNAL_SMOKE_ALPHA_MAX = 0.8f;
+
+//-------------------------------------------------------------------------------------------------
+/** Is a signal on this frame too soon after the player's last one? A last frame ahead of now is
+ * left over from an earlier match, whose clock ran further, and holds nothing back. */
+//-------------------------------------------------------------------------------------------------
+Bool Signal_isThrottled( UnsignedInt now, UnsignedInt lastSignalFrame )
+{
+ return now >= lastSignalFrame && now - lastSignalFrame < SIGNAL_COOLDOWN_FRAMES;
+}
+
//-------------------------------------------------------------------------------------------------
/** This message handles dispatches object command messages to the
* appropriate objects.
@@ -2075,6 +2095,14 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )
if( kind < 0 || kind >= SIGNAL_KIND_COUNT )
break;
+ // one a second per player, held here rather than at the key so every machine applies it
+ // to every sender, including one that was built without it
+ static UnsignedInt lastSignalFrame[ MAX_PLAYER_COUNT ];
+ Int senderIndex = thisPlayer->getPlayerIndex();
+ if( Signal_isThrottled( getFrame(), lastSignalFrame[ senderIndex ] ) )
+ break;
+ lastSignalFrame[ senderIndex ] = getFrame();
+
Player *localPlayer = ThePlayerList->getLocalPlayer();
Bool mutualAllies = thisPlayer->getRelationship( localPlayer->getDefaultTeam() ) == ALLIES &&
localPlayer->getRelationship( thisPlayer->getDefaultTeam() ) == ALLIES;
@@ -2090,10 +2118,17 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )
{
smoke->setPosition( &pos );
smoke->tintAllColors( look.smokeColor );
+ // the tint leaves the first key alone, and in this template that key is an orange flash
+ smoke->m_colorKey[ 0 ].color = smoke->m_colorKey[ 1 ].color;
smoke->setFiniteSystemLifetime( SIGNAL_HALF_FRAMES );
smoke->setLifetimeRange( SIGNAL_HALF_FRAMES, SIGNAL_HALF_FRAMES );
// the template's second alpha key is its fade to nothing, timed for a five second puff
smoke->m_alphaKey[ 1 ].frame = SIGNAL_HALF_FRAMES;
+ smoke->m_alphaKey[ 0 ].var.setRange( SIGNAL_SMOKE_ALPHA_MIN, SIGNAL_SMOKE_ALPHA_MAX );
+ smoke->setSizeMultiplier( SIGNAL_SMOKE_SIZE_SCALE );
+ smoke->setBurstCountMultiplier( SIGNAL_SMOKE_DENSITY_SCALE );
+ Coord3D rise = { 1.0f, 1.0f, SIGNAL_SMOKE_RISE_SCALE };
+ smoke->setVelocityMultiplier( &rise );
}
TheRadar->createEvent( &pos, look.radarEvent, SIGNAL_SECONDS );
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 36ef1c93c..936d6f33a 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -1046,6 +1046,37 @@ TEST(each_signal_key_drops_its_own_smoke)
CHECK( Command_signalKindForMeta( GameMessage::MSG_META_PLACE_BEACON ) == SIGNAL_KIND_COUNT );
}
+/* GameLogicDispatch.cpp: one signal a second per player. */
+extern Bool Signal_isThrottled( UnsignedInt now, UnsignedInt lastSignalFrame );
+
+TEST(a_signal_waits_a_second_after_the_last_one)
+{
+ CHECK( Signal_isThrottled( 1000, 1000 ) );
+ CHECK( Signal_isThrottled( 1029, 1000 ) );
+ CHECK( !Signal_isThrottled( 1030, 1000 ) );
+
+ /* a frame left over from a longer earlier match does not silence the new one */
+ CHECK( !Signal_isThrottled( 40, 50000 ) );
+}
+
+/* ParticleSys.cpp: tinting a white key by a colour gives that colour. RGBColor::setFromInt already
+ scales to 0..1 and the tint divided by 255 again, so every tinted system came out black. */
+#include "GameClient/ParticleSys.h"
+
+TEST(a_tinted_particle_key_takes_the_tint_colour)
+{
+ ParticleSystemInfo info;
+ info.m_colorKey[ 1 ].color.red = 1.0f;
+ info.m_colorKey[ 1 ].color.green = 1.0f;
+ info.m_colorKey[ 1 ].color.blue = 1.0f;
+
+ info.tintAllColors( 0xFF8000 );
+
+ CHECK_NEAR( info.m_colorKey[ 1 ].color.red, 1.0f, 0.001f );
+ CHECK_NEAR( info.m_colorKey[ 1 ].color.green, 128.0f / 255.0f, 0.001f );
+ CHECK_NEAR( info.m_colorKey[ 1 ].color.blue, 0.0f, 0.001f );
+}
+
/* DrawnPath.cpp: the drawn curve is measured by arc length, not by segment, so the stations divide
the whole line however uneven the hand that drew it was. */
#include "Common/DrawnPath.h"