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(w3ddevice): pick the ground when the camera is inside the height box

Olcay Seygan3be7b1b2ec83
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 002ad271d..2f714129e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -704,6 +704,7 @@ found and fixed — EA's own, not port damage.**
- Play it the way it shipped. Options > Controls has a Mouse and Keyboard box with two answers. Modern is this game as it is now. Legacy is the 2003 game: left click selects and orders, right click deselects, a right drag scrolls the map, a middle drag turns the camera, and the command bar answers the game's own letter for each button, painted in the button's corner the way the grid keys are. Holding Ctrl makes a click force fire, at the ground or at your own units. Those letters are the English game's even when the words are Turkish: the translation marks every label's first letter, which would have put K on three GLA structures and S on five. The promotion screen's number keys and the general's power keys are this game's additions, so under Legacy their labels are gone and the number keys pick your groups again. Every key comes from the game's own key map, so the grid keys, the two-key structures, Alt+Z signals, Ctrl+Z barracks, Tab, box select filters, formation lines, zoom to cursor and clickable health bars all stand down. It changes the moment you press Accept, even in the middle of a match, and it only changes your own screen.
- The lines from your selection to where it is headed can be switched off. Options > Gameplay has an Order Lines box, on by default. Off, a selected unit shows no line to its goal and none through its queue, but the marker on every point it is headed for stays, so an attack move or a string of waypoints is still there to see. The line you draw while dragging a formation still shows, because that one is the order being given. It changes the moment you press Accept.
- Zoom to cursor is a box on Options > Controls again, on by default, for anyone who would rather the wheel zoomed on the middle of the screen. It also stopped fighting you. The camera corrected itself a frame after each step of the zoom, so the ground slid off the cursor and was pulled back the whole way in, and the last pull landed after the zoom had finished, as a small jump towards the cursor. And a wheel spun over a spot with no ground under it, out past the edge of the map, threw the camera to the corner of the map. The ground under the cursor stays under it on every frame now, and a spot with no ground zooms on the middle of the screen.
+- Orders land where you clicked when the camera is right down on the ground. Zoomed all the way in, a right click sent the units to the corner of the map instead of to the spot under the pointer, and the marker and the line went there with them. The game works out what you clicked on by firing a line from the camera at the ground, and that line was thrown away whenever the camera itself had dropped below the height of the tallest hill on the map - so it went wrong on hilly maps first and stayed fine on flat ones, which is why it looked random.
- Click through the command bar wherever its metal is not. The bar is three shaped plates with sloped tops and cut corners, but it caught clicks over the whole rectangle each plate sits in, so a unit standing in the sky above the radar's slope, or in the notch beside the command grid, could not be clicked or ordered to. Between 3 and 22 percent of each plate's rectangle is empty, depending on the side and the panel. Those parts belong to the battlefield now, and the buttons and metal still take every click they did.
- Drag the camera across the radar. Press on the radar and keep the button down, and the camera follows the cursor over the map until you let go; before, it jumped once per click, so crossing the map meant clicking your way over it. The button that moves the camera with a click is the one that drags it, left under Modern and right under Legacy, and with nothing selected either one does. Run the left button off the side of the radar and the camera waits at the edge of the map. It keeps following while the arrow keys are scrolling too, which used to leave the drag dead until the key came up. A selection box dragged onto the radar from the battlefield leaves the camera where it is.
- Widescreen resolutions are back in the options menu, and the list works during a match. It was greyed out the moment a game started, because changing it rebuilt the menus and then pushed the main menu over whatever you were playing. It rebuilds the menus for later and leaves you on the battlefield with the command bar back up.
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp
index 882f96c9d..42de020b6 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp
@@ -759,10 +759,13 @@ bool BaseHeightMapRenderObjClass::Cast_Ray(RayCollisionTestClass & raytest)
if (CollisionMath::Collide(lineseg,hbox,&result))
{ //ray intersects terrain or starts inside the terrain.
+ // StartBad means the ray already begins inside the box, so there is nothing to clip and
+ // P0 stands as it is. Treating it as a failure left hasP0 false and threw the whole cast
+ // away, which is what a camera zoomed below the box ceiling did to every ground click.
+ hasP0 = true;
if (!result.StartBad) //check if start point inside terrain
{
newP0 = P0 != result.ContactPoint;
- hasP0 = true;
P0 = result.ContactPoint; //make intersection point the new start of the ray.
}
@@ -772,19 +775,17 @@ bool BaseHeightMapRenderObjClass::Cast_Ray(RayCollisionTestClass & raytest)
result.StartBad=false;
lineseg2.Set(lineseg.Get_P1(),lineseg.Get_P0()); //reverse line segment
if (CollisionMath::Collide(lineseg2,hbox,&result))
- { if (!result.StartBad) //check if end point inside terrain
+ { hasP1 = true;
+ if (!result.StartBad) //check if end point inside terrain
{
newP1 = P1 != result.ContactPoint;
- hasP1 = true;
P1 = result.ContactPoint; //make intersection point the new end pont of ray
}
}
}
- // Narrowing has stopped moving the ends, so another pass would search the same box. The
- // old test broke on the box missing instead, which let a first pass that hit nothing on
- // p>0 carry the previous pass's cell range into the triangle search below.
- if (!newP0 || !newP1)
+ // The ray never reached the box, so there is no cell range to search.
+ if (!hasP0 || !hasP1)
break;
// Take the 2D bounding box of ray and check heights
@@ -820,6 +821,12 @@ bool BaseHeightMapRenderObjClass::Cast_Ray(RayCollisionTestClass & raytest)
Vector3 maxPt(MAP_XY_FACTOR*(EndCellX+1), MAP_XY_FACTOR*(EndCellY+1), MAP_HEIGHT_SCALE*(maxHt+1));
MinMaxAABoxClass mmbox(minPt, maxPt);
hbox.Init(mmbox);
+
+ // Narrowing has stopped moving the ends, so another pass would search the same box. The
+ // cell range above is computed first either way, so an end that needed no clipping still
+ // leaves a range behind instead of the previous pass's.
+ if (!newP0 && !newP1)
+ break;
}
// Neither end was ever placed on the terrain box, so there is nothing to search.