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(gameengine): the computer takes vehicles instead of shooting them
Olcay Seyganc374b62557a6
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ff913bf17..e0f90ef93 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -39,6 +39,7 @@ found and fixed — EA's own, not port damage.**- 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.- It scouts. There was no such thing as scouting in the computer opponent - it never needed to look, because it could already see everything. One cheap unit now tours the enemy start positions and keeps going round for the rest of the match, replaced out of spare change when it dies. Every difficulty scouts; an opponent that never looks reads as broken, not as easy. And it tours on purpose rather than in a circle: it goes to whichever base it has gone longest without seeing, nearest first, and it does not walk across the map to look again at something it looked at a minute ago - it stays and watches instead. Two scouts never trail each other round the same lap.- It takes the oil derricks instead of blowing them up. An oil derrick pays whoever owns it and costs one infantryman to walk in - and the computer used to march past the neutral ones and shell yours, which is the one thing you can do with a derrick that earns nobody anything. It now keeps a cheap infantryman doing the rounds of every derrick, refinery and hospital it has found, takes them, and when there is nothing left to take it leaves him standing on the last one instead of walking him home. And it no longer picks a capturable building as a target of its own accord: it can still be ordered to level one, and one that shoots back is still shot back at.+- It steals your tanks. A hijacker costs a few hundred and walks off with whatever it touches, and no computer opponent had ever bought one: not one shipped skirmish plan asks for it. A GLA computer now keeps a thief on call as soon as one of your vehicles comes within walking distance, and sends it at the nearest one rather than the richest, because the Humvee it reaches is worth more than the Overlord it dies halfway to. Black Lotus works the same ground on the same terms: she hacks a vehicle that is already in front of her, and does not cross the map to shut one down for a few seconds.- Nor does it know which start position you took. It used to read that straight off the lobby, for every player, from the first second. Now it works it out: each position it has not looked at is a suspect, and the odds are simply how many opponents are still unaccounted for over how many places they could be - three of you on an eight-position map is 3 in 7 for each. Every empty position its scout crosses off makes the rest likelier, 3 in 6, then 3 in 5. When the numbers meet, it stops looking: three opponents with three places left to be is not a guess, and walking over to confirm it would waste the trip. On a two-player map that is true from the start, so nothing changed there - it never wastes a second hunting for an address it can work out by subtraction. Where it has not worked you out yet, it attacks the position you are most likely to be on, and finds out on arrival.- Nor does it read your base off the map. Where your base is, what it is worth, which supply dock to expand to and where to aim a superweapon all came off a walk of your object list, in the shroud, from the first second of the match. The computer now only counts what it can see, plus the buildings it has already found - buildings do not walk away. Before it has scouted you, all it knows is where you started, which is on the map preview anyway.diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cppindex 7b4e26b33..48a5cbec6 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp@@ -6600,6 +6600,32 @@ void AIPlayer::queueCapturer( void )* standing next to it. */static const Real VEHICLE_HACK_REACH = 250.0f;+/** How far a thief will go for one, measured from the thief, or from the base while we have none.+ * Wider than the hack, because the prize is permanent and the walk is the whole plan. Not the+ * whole map, which is what the first draft allowed: with the shroud not yet up on frame 7, every+ * computer player in the match went shopping for a hijacker to send at an enemy dozer standing on+ * the far side of it. */+static const Real HIJACK_REACH = 700.0f;++/** Could this player buy this unit if it were asking a factory right now?+ *+ * A computer player keeps canBuildUnits false between team orders, and allowedToBuild refuses+ * every non-structure while it is, so a plain canBuild here answers "no" for a reason that has+ * nothing to do with the unit: a Toxin General with a barracks, an arms dealer and 17,000 in the+ * bank reported no buildable hijacker on every pass of a fifteen-thousand-frame match.+ * queueSupportUnit flips the same flag around its own factory lookup; this is that trick moved to+ * the question in front of it. cheapestScoutTemplate and cheapestCapturerTemplate ask without it+ * and so find their unit only on the passes where the flag happens to be up - left as they are+ * because both were measured with that in them. */+static Bool couldBuildUnit( Player *player, const ThingTemplate *tmpl )+{+ const Bool wasAllowed = player->getCanBuildUnits();+ player->setCanBuildUnits( TRUE );+ const Bool answer = player->canBuild( tmpl );+ player->setCanBuildUnits( wasAllowed );+ return answer;+}+//----------------------------------------------------------------------------------------------------------/** This one takes a vehicle by walking into it. Asked of the object rather than of a faction table,* so it lands on the GLA Hijacker and on anything a mod gave the same collide to. */@@ -6624,7 +6650,7 @@ static const ThingTemplate *cheapestHijackerTemplate( Player *player )for( const ThingTemplate *t = TheThingFactory->firstTemplate(); t; t = t->friend_getNextTemplate() ){- if( !t->isKindOf( KINDOF_INFANTRY ) || !player->canBuild( t ) )+ if( !t->isKindOf( KINDOF_INFANTRY ) || !couldBuildUnit( player, t ) )continue;const Int cost = t->calcCostToBuild( player );@@ -6682,7 +6708,7 @@ Object *AIPlayer::findHijacker( void )//----------------------------------------------------------------------------------------------------------/**- * The closest enemy vehicle in sight, or none within reach. reach <= 0 is the whole map.+ * The closest enemy vehicle in sight, or none within reach.** A vehicle goes back to SHROUDED the moment our vision leaves it, so observerKnowsAbout reads here* as "we can see it now" - the only honest rule for a target that drives off while we walk to it.@@ -6734,7 +6760,7 @@ Object *AIPlayer::nearestStealableVehicle( const Coord3D *from, Real reach )const Real dx = at->x - from->x;const Real dy = at->y - from->y;const Real distSqr = dx*dx + dy*dy;- if( reach > 0.0f && distSqr > reachSqr )+ if( distSqr > reachSqr )continue;if( best == NULL || distSqr < bestDistSqr ){@@ -6817,13 +6843,16 @@ void AIPlayer::doHijack( void )if( thief )from = *thief->getPosition();- Object *target = nearestStealableVehicle( &from, 0.0f );+ Object *target = nearestStealableVehicle( &from, HIJACK_REACH );if( target == NULL )- return; // nothing in sight; the thief waits where it is rather than walk into the fog+ return; // nothing in reach; the thief waits where it is rather than walk into the fogif( thief == NULL ){- // only pay for one when there is something to spend it on+ // Only pay for one when there is something to spend it on. It shares the one support-unit+ // slot with the scout and the capturer, so a match that keeps losing scouts keeps the thief+ // waiting - which is the right order of priorities and the reason there is never more than+ // one of these walking about.queueSupportUnit( cheapestHijackerTemplate( m_player ), "HIJACK" );return;}