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): the radar warning distance was never a distance

Olcay Seygan2ccaf6839ecd
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 535ae0c88..f68738760 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -383,6 +383,7 @@ found and fixed — EA's own, not port damage.**
- A mission script that waits for a line of speech to finish waits the same length of time on every machine. It used to ask the sound hardware how long the file was, so a player whose sound card was not working, or was turned off, got the answer zero and walked straight through waits that everyone else sat out. That is a different game on two screens, and a replay that stops matching the machine that recorded it. The length now comes out of the file itself: measured on one line of speech, a silent machine said 0 milliseconds and a machine with sound said 3,285. Both say 3,285 now.
- Laying a foundation costs less the further up the map you build. Flattening the ground under a new building scanned every row of the map from the bottom edge up to the building, threw all of them away bar the ones actually under it, and did that once per column. It works out the rows it needs now. The ground comes out identical, down to the last unit of height.
- EVA announcements that were queued behind another one no longer go quiet. A request waits its turn and expires if its turn never comes, and the sum that worked out when that was could wrap round to zero, retiring the announcement on the frame it was asked for.
+- "Your base is under attack" fires for the attack you are actually under. The check that decides whether a warning is a repeat of one you just heard was computing something that was not a distance at all, so an attack on the far side of the map could silence the warning for one at your front door, and two hits on the same building could each get their own.
- Two tanks shelling the same spot no longer wipe a scorch mark off the far side of the map. With the ground already carrying its full quota of marks, a repeat crater threw the oldest one away and then declined to add itself, so a mark vanished and nothing replaced it.
- Heat haze wobbles in both directions. The vertical part of the distortion was rolled, clipped against the top and bottom of the screen, and then never used - every shimmer pulled the picture along one diagonal.
- One tree in ten stood dead still in the breeze. The number that picks which way a tree sways was drawn from a range one short at the bottom, and the bottom of that range is the slot meaning "no sway at all".
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp
index aba4a39d2..75bb0dae7 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp
@@ -374,6 +374,11 @@ RecorderClass::RecorderClass()
m_nextFrame = 0;
m_wasDesync = FALSE;
//
+ // playbackFile allocates this and nothing ever freed it: three replays watched in one sitting
+ // left three of them behind. It was also never set to anything before the first playback, so
+ // handleCRCMessage read whatever was on the heap if a CRC arrived first.
+ //
+ m_crcInfo = NULL;
init(); // just for the heck of it.
}
@@ -382,6 +387,8 @@ RecorderClass::RecorderClass()
* Destructor
*/
RecorderClass::~RecorderClass() {
+ delete m_crcInfo;
+ m_crcInfo = NULL;
}
/**
@@ -418,6 +425,10 @@ void RecorderClass::reset() {
}
m_fileName.clear();
+ // the playback that owned it is over; playbackFile makes a fresh one for the next
+ delete m_crcInfo;
+ m_crcInfo = NULL;
+
init();
}
@@ -1143,6 +1154,7 @@ Bool RecorderClass::playbackFile(AsciiString filename)
}
#endif
+ delete m_crcInfo; // a replay started without a reset in between would leak the last one
m_crcInfo = NEW CRCInfo;
m_crcInfo->setLocalPlayer(header.localPlayerIndex);
REPLAY_CRC_INTERVAL = m_gameInfo.getCRCInterval();
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/Radar.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/Radar.cpp
index 75deb9c87..443eac3e5 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/System/Radar.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/Radar.cpp
@@ -1323,9 +1323,16 @@ Bool Radar::tryEvent( RadarEventType event, const Coord3D *pos )
if( m_event[ i ].type == event )
{
- // get distance from our new event location to this event location in 2D
- Real distSquared = m_event[ i ].worldLoc.x - pos->x * m_event[ i ].worldLoc.x - pos->x +
- m_event[ i ].worldLoc.y - pos->y * m_event[ i ].worldLoc.y - pos->y;
+ //
+ // Distance from the new event to this one, in 2D. There were no brackets here at all,
+ // so what it worked out was x - (px*x) - px + y - (py*y) - py: not a distance, not even
+ // a positive number most of the time. The test below it therefore answered at random,
+ // which is why two attacks on opposite ends of the map could suppress each other's
+ // warning while two on the same building both got one.
+ //
+ const Real dx = m_event[ i ].worldLoc.x - pos->x;
+ const Real dy = m_event[ i ].worldLoc.y - pos->y;
+ Real distSquared = dx * dx + dy * dy;
if( distSquared <= closeEnoughDistanceSq )
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp
index 3cb2396c5..2b9e7dcc0 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp
@@ -1043,8 +1043,15 @@ static void handleStartingCashSelection()
if (myGame)
{
- Int selIndex;
+ //
+ // Uninitialised, and the getter leaves it alone when there is nothing selected or no window to
+ // ask - so what got handed to GadgetComboBoxGetItemData as a list index was whatever had been
+ // on the stack.
+ //
+ Int selIndex = -1;
GadgetComboBoxGetSelectedPos(comboBoxStartingCash, &selIndex);
+ if (selIndex < 0)
+ return;
Money startingCash;
startingCash.deposit( (UnsignedInt)GadgetComboBoxGetItemData( comboBoxStartingCash, selIndex ), FALSE );
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayString.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayString.cpp
index cff51c361..388bff859 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayString.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayString.cpp
@@ -315,7 +315,14 @@ void W3DDisplayString::setFont( GameFont *font )
// set the font in our renderer
m_textRenderer.Set_Font( static_cast<FontCharsClass *>(m_font->fontData) );
- m_textRendererHotKey.Set_Font( static_cast<FontCharsClass *>(TheFontLibrary->getFont(font->nameString,font->pointSize, TRUE)->fontData) );
+ //
+ // The hotkey underline is drawn in the bold cut of the same font, and the library hands back
+ // null when it has not got one - a font set that ships without its bold face, or a malformed
+ // one that failed to load. This read straight through that.
+ //
+ GameFont *boldFont = TheFontLibrary->getFont( font->nameString, font->pointSize, TRUE );
+ m_textRendererHotKey.Set_Font( boldFont ? static_cast<FontCharsClass *>(boldFont->fontData)
+ : static_cast<FontCharsClass *>(m_font->fontData) );
// recompute extents for text with new font
computeExtents();