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
fix(gameengine): rockets hit what is under them, ai stops stacking buildings
Olcay Seyganeb95e061bdd9
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 6395750a2..646edb40f 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -35,7 +35,7 @@ found and fixed — EA's own, not port damage.**- The AI checks ten seconds of supply-line damage, not a third of one.- One AI decision read leftover memory, so identical matches played out differently.- Difficulty and AI money change build pace again; every order was pinned at three seconds.-- Computer bases no longer grow buildings inside buildings. When a spot in its plan was taken and it could find no free ground nearby, the computer put the building down on the taken spot anyway, straight through its own. It now looks outwards from the planned spot over ground its trucks could drive, bridges included, so a new building lands next to the base and not across a cliff or a river from it, and when there is truly no room it waits.+- Computer bases no longer grow buildings inside buildings. When a spot in its plan was taken and it could find no free ground nearby, the computer put the building down on the taken spot anyway, straight through its own. It now looks outwards from the planned spot over ground its trucks could drive, bridges included, so a new building lands next to the base and not across a cliff or a river from it, and when there is truly no room it waits. It still stacked them on sloping ground, which a player caught. The check for what already stands on a spot is taken at a height, and the computer's search took it at the height of the spot it started from, or at zero, so wherever the ground fell away a building standing there was below the check and did not count. A Hard USA put three pairs of supply drop zones exactly on top of each other in one match. Every building is checked at the ground it will stand on now: over the same four four-player matches, the pairs stacked or half inside each other went from five to none.- An urgent building it could not put up yet no longer stops the whole base. The computer always builds its most urgent request first, and when that request needed something it did not have, it built nothing else either: a Hard China that asked for a bunker before its barracks stood sat on 35,000 until well into the match. It now skips to the first urgent request it can actually build.- Hard USA opens the way a player does. It used to start on a barracks and hold its first power plant until a second dozer existed, so its first harvest came in at the 74 second mark. It now puts down the power plant and the supply centre straight away and the barracks after them. Over 20 Hard USA against Hard China matches on Tournament Desert, seats swapped both ways, USA won 15 where it won 10. The same opening was tried on China and lost it 17 matches instead of 10, and on GLA it decided too few matches to say anything, so both keep the opening they shipped with.- The computer no longer shoots at what it cannot see. Its units, and its base defences, used to auto-target through the fog of war - a hard exemption written into the code for computer players only. Stealth works against it now, and so does anything it has not scouted.@@ -399,7 +399,7 @@ found and fixed — EA's own, not port damage.**- Something flagged unselectable is unselectable. The flag existed and nothing read it.- A suicide unit pressed up against a building goes off. Touching the building's outline counted as having its view blocked, so it walked away to find a clear line of sight it never needed, came back, and did it again without ever detonating.- A nuclear missile hurts the whole of a big building. The blast measured to the middle of everything near it, so an airfield whose centre sat just outside the outer ring took nothing while half of it stood in the fire. Distance is now taken halfway between the nearest edge and the centre.-- Rockets curve into their target instead of snapping onto it. In the last few frames before impact a guided missile swung its nose straight at the target in one step, up to 40 degrees in a single frame, when the whole flight before that never turned more than 5. It now flies an arc from the heading it had to the spot where it meets the target, so a tank driving across its path is led rather than chased. In the same test battle no rocket turns more than 8 degrees in a frame, and all 101 land. Rockets fired at aircraft still fly straight at them: a helicopter is nearly as fast as the rocket, and on an arc the rocket flew past it and climbed away into the sky.+- Rockets curve into their target instead of snapping onto it. In the last few frames before impact a guided missile swung its nose straight at the target in one step, up to 40 degrees in a single frame, when the whole flight before that never turned more than 5. It now flies an arc from the heading it had to the spot where it meets the target, so a tank driving across its path is led rather than chased. In the same test battle no rocket turns more than 8 degrees in a frame, and all 101 land. Rockets fired at aircraft still fly straight at them: a helicopter is nearly as fast as the rocket, and on an arc the rocket flew past it and climbed away into the sky. A rocket whose target is behind it flies straight at it too. The arc to something behind the nose loops out past it, and when the target is on the ground under a helicopter the bottom of that loop is in the dirt: a Comanche hovering over a supply truck put all four missiles into the ground 23 to 47 away from it, while the same Comanche 250 away landed all four. Now the truck is down to 16 health of 300 five seconds in, where it had 136. Rockets fired at driving tanks and at aircraft land exactly where they did before.- Scuds come down from the top of their climb in a smooth curve, level at the top and steepest at the end, instead of tipping into a straight dive 200 short of the target. Over those last 200 a Scud now stays within 14 of that curve where the dive strayed by up to 49, and every one lands on the spot it was fired at; one in the old test came down 22 away.- Cancelling an order of Red Guard after the first soldier has walked out no longer refunds the order. One order is two soldiers for one price, and the refund came back whole, so the first one was free.- Double-clicking to grab everything of a kind grabs what a box would, not things you can only click one at a time.diff --git a/GeneralsMD/Code/Data/Scenarios/airbelow.txt b/GeneralsMD/Code/Data/Scenarios/airbelow.txtnew file mode 100644index 000000000..1c53eeecb--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/airbelow.txt@@ -0,0 +1,33 @@+# An aircraft right over a target that cannot shoot back: a Comanche spawned on top of a supply truck+# and a MiG on top of a troop crawler, tallied through the run. airbelowfar.txt is the same pair+# spawned 250 short of their targets.+#+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit+# -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 2 -takeover+# -side 0 FactionAmerica -side 1 FactionChina -seed 7 -maxframes 1500+# -scenario airbelow -logPrefix airbelow_+#+# Player report 2026-09-25: aircraft sometimes cannot hit an enemy right beneath them. Measured with+# a temporary log of every missile's distance from its victim when it went off. Before the fix the+# Comanche over the truck put 4 of 4 anti-tank missiles into the ground 23 to 47 away and the truck+# had 136 of 300 health at frame 150; from 250 away all 4 hit within 6. A goal behind the missile's+# nose now takes the straight chase: 3 of 4 hit, the fourth is the shot fired on the spawn frame, and+# the truck has 16 health at frame 150. The MiG's napalm missiles hit in both builds; inside 80 flat+# it does not fire at all, which is EA's minimum range, and it circles out and comes back.++30 spawn 1 ChinaVehicleSupplyTruck 1 start0:0:900+30 spawn 0 AmericaVehicleComanche 1 start0:0:900+30 spawn 1 ChinaVehicleTroopCrawler 1 start0:700:900+30 spawn 0 ChinaJetMIG 1 start0:700:900+60 attack 0 AmericaVehicleComanche 1 ChinaVehicleSupplyTruck+60 attack 0 ChinaJetMIG 1 ChinaVehicleTroopCrawler+150 tally 1 ChinaVehicleSupplyTruck+150 tally 1 ChinaVehicleTroopCrawler+300 tally 1 ChinaVehicleSupplyTruck+300 tally 1 ChinaVehicleTroopCrawler+450 tally 1 ChinaVehicleSupplyTruck+450 tally 1 ChinaVehicleTroopCrawler+900 tally 1 ChinaVehicleSupplyTruck+900 tally 1 ChinaVehicleTroopCrawler+1450 tally 1 ChinaVehicleSupplyTruck+1450 tally 1 ChinaVehicleTroopCrawlerdiff --git a/GeneralsMD/Code/Data/Scenarios/airbelowfar.txt b/GeneralsMD/Code/Data/Scenarios/airbelowfar.txtnew file mode 100644index 000000000..0ac017935--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/airbelowfar.txt@@ -0,0 +1,23 @@+# airbelow.txt with each aircraft spawned 250 short of its target, the comparison for it.+#+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit+# -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 2 -takeover+# -side 0 FactionAmerica -side 1 FactionChina -seed 7 -maxframes 1500+# -scenario airbelowfar -logPrefix airbelowfar_++30 spawn 1 ChinaVehicleSupplyTruck 1 start0:0:900+30 spawn 0 AmericaVehicleComanche 1 start0:0:650+30 spawn 1 ChinaVehicleTroopCrawler 1 start0:700:900+30 spawn 0 ChinaJetMIG 1 start0:700:650+60 attack 0 AmericaVehicleComanche 1 ChinaVehicleSupplyTruck+60 attack 0 ChinaJetMIG 1 ChinaVehicleTroopCrawler+150 tally 1 ChinaVehicleSupplyTruck+150 tally 1 ChinaVehicleTroopCrawler+300 tally 1 ChinaVehicleSupplyTruck+300 tally 1 ChinaVehicleTroopCrawler+450 tally 1 ChinaVehicleSupplyTruck+450 tally 1 ChinaVehicleTroopCrawler+900 tally 1 ChinaVehicleSupplyTruck+900 tally 1 ChinaVehicleTroopCrawler+1450 tally 1 ChinaVehicleSupplyTruck+1450 tally 1 ChinaVehicleTroopCrawlerdiff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cppindex 35b0311b4..5060c1023 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp@@ -682,8 +682,15 @@ LegalBuildCode BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPosUnsignedInt options,Player *thePlayer){- ObjectIterator *iter =- ThePartitionManager->iteratePotentialCollisions( worldPos,+ /* A building stands on the ground, and the collision test below is three dimensional, so it is asked+ at the ground under worldPos whatever height the caller passed. The computer's placement searches+ kept the height of the spot they started from, or passed 0, and a probe that floated above a+ building's roof found it clear: a Hard USA put three pairs of supply drop zones exactly on top of+ each other in one match. */+ Coord3D groundPos = *worldPos;+ groundPos.z = TheTerrainLogic->getGroundHeight( groundPos.x, groundPos.y );+ ObjectIterator *iter =+ ThePartitionManager->iteratePotentialCollisions( &groundPos,build->getTemplateGeometryInfo(),angle );Object *them;diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cppindex 9e1913c7b..8695fd5dc 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp@@ -194,8 +194,9 @@ static Real tryToOrientInThisDirection3D(Object* obj, Real maxTurnRate, const Ve//-------------------------------------------------------------------------------------------------// The turn this frame that keeps a projectile on the circle tangent to its nose through the goal. That// circle turns through twice the angle between nose and goal over its length, so a step of `step`-// units turns 2*step*sin(angle)/dist, the same every frame for a goal that stands still. Past a right-// angle no such circle reaches the goal, and a loop of diameter dist brings the nose round instead.+// units turns 2*step*sin(angle)/dist, the same every frame for a goal that stands still. A goal behind+// the nose is chased straight (Locomotor_projectileChasesStraight), so past a right angle is only a+// moving victim's meeting point, and a loop of diameter dist brings the nose round to it.// The step that arrives points straight at the goal.static Real calcArcTurnToGoal(const Vector3& nose, const Vector3& toGoal, Real step){@@ -250,10 +251,16 @@ Coord3D Locomotor_interceptOffset(const Coord3D& toVictim, const Coord3D& victim// within 11 of a helicopter, flew past it and climbed away with its nose 110 degrees off. Rockets at// helicopters and jets over 1800 frames stayed locked p95 20 frames on the straight chase and never drew// away; the arc took 26 and drew away 5 times, the arc onto the meeting point 35 and 17.-static Bool Locomotor_projectileChasesStraight(Object* obj)+// A goal behind the nose takes the straight chase too. The arc to it bulges past the goal on the far+// side, and when the goal is on the ground below that is underground: a Comanche hovering over a+// supply truck put 4 of 4 missiles into the dirt 23 to 47 away, where from 250 out all 4 hit.+static Bool Locomotor_projectileChasesStraight(Object* obj, const Vector3& toGoal){Object *victim = obj->getAI()->getGoalObject();- return victim && victim->isAboveTerrain();+ if (victim && victim->isAboveTerrain())+ return TRUE;++ return Vector3::Dot_Product(obj->getTransformMatrix()->Get_X_Vector(), toGoal) <= 0.0f;}//-------------------------------------------------------------------------------------------------@@ -1196,7 +1203,7 @@ void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalP{// Projectiles never stop braking once they start. jba.obj->setStatus( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_BRAKING ) );- // Projectiles cheat in 3 dimensions. Chasing an aircraft that is straight at it; otherwise along+ // Projectiles cheat in 3 dimensions. Chasing an aircraft, or a goal behind the nose, that is straight at it; otherwise along// the nose, so a missile flies the arc moveTowardsPositionThrust turns it onto instead of// kinking at the lock.dist = sqrt(dx*dx+dy*dy+dz*dz);@@ -1205,7 +1212,7 @@ void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalPvel = MIN_VEL;if (vel > dist)vel = dist; // do not overcompensate!- if (dist > 0.001f && Locomotor_projectileChasesStraight(obj))+ if (dist > 0.001f && Locomotor_projectileChasesStraight(obj, Vector3(dx, dy, dz))){pos.x += dx / dist * vel;pos.y += dy / dist * vel;@@ -2092,7 +2099,7 @@ void Locomotor::moveTowardsPositionThrust(Object* obj, PhysicsBehavior *physics,// we are at target.adjust = false;}- else if (obj->isKindOf(KINDOF_PROJECTILE) && !Locomotor_projectileChasesStraight(obj))+ else if (obj->isKindOf(KINDOF_PROJECTILE) && !Locomotor_projectileChasesStraight(obj, vel)){// the projectile cheat moves along the nose, so this turn is the path it flies. It bends// towards where a moving victim will be when the missile gets there rather than where the