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.

feat(turkiye): kargu drones retarget onto targets nobody is after

Olcay Seyganfa40b18a7a80
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3ca8981aa..9bd3eb153 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -146,7 +146,7 @@ found and fixed — EA's own, not port damage.**
- The Korkut is air defense and nothing else. Its cannons reach 350 into the air and no longer fire at the ground, where they used to outrange the Altay; three Korkut that cut down eight Rangers without a scratch now lose to them, and still shoot down three Comanches untouched. The Kizilelma's missiles hit the ground as well as the air, and it costs 1800 instead of 2200. It carried 380 health on a Raptor's frame and shot a Raptor down in 29 seconds while the Raptor needed 86 for it; at the Raptor's 160 the duel is even and the dearer jet loses on price. The Akinci drops its own bomb, one a sortie; it had been dropping the Aurora's. With 420 health no ground air defense paid for itself against it. At 200 a Gattling Tank or a Missile Defender beats it for the money and a Quad Cannon breaks even.
- Every Turkish unit has its own command bar with only buttons that work: no drone buttons on the Altay and the Cobra, no TOW on the Cobra, no rocket pods on the Bayraktar, no flash-bang switch on the Mehmetcik. The Barracks sells Capture Building, so the Mehmetcik's capture button works.
- Turkiye's first rank buys its own power, a Minefield a cargo plane sows wherever you point, beside the Spy Drone and Fuel Resupply, which keeps the drones over the target longer. Rank 3 offers a loitering munition that dives on whatever it is pointed at, Electronic Blinding, which shuts every enemy radar in the area off for 30 seconds, and Rapid Deployment, six Mehmetcik and two Sungur gunners by parachute. The top rank buys the Swarm Strike: ten munitions over a wide circle, each on a different target and the most expensive first, so a column of tanks loses its tanks and the riflemen walking beside them are left standing. Beside it sit the Fire Mission, 36 heavy shells from off the map, and the Commando Raid, a Maroon Beret and two spotter teams dropped behind the enemy's lines. The American Paradrop, Leaflet Drop, Spectre gunship and CIA intelligence are gone from the Headquarters and the power bar.
-- Turkiye has a superweapon: the Kargu Drone Base. It costs 5000, draws 10 power, opens once you have a Factory and a Radar Tower, counts against the lobby's superweapon limit like the Particle Cannon, the nuke and the Scud Storm, and every player watches its five-minute countdown. The base is an airfield with two runways and four hangars, and you tell it from Turkiye's own airfield at a glance because it wears China's. Fire it and sixteen kamikaze drones take off in a stream, one down each runway in turn every quarter of a second, roll, lift off and climb, and all sixteen are in the air under six seconds after you fire. Then they fly straight across the map where everyone can see them coming. Each goes for one of the sixteen most expensive things inside the target circle, tips into its dive about 120 short and hits for 700, 11,200 for the whole swarm. With fewer targets than drones the spares go round again, dearest first, and a drone whose target died on the way takes the dearest enemy left in the circle. They are aircraft, so anti-air shoots them down on the way in. The last one hits fourteen seconds after you fire. Fired across Twilight Flame into an undefended American base, the swarm killed two of eight Crusaders and three of six Humvees, took 35% off the War Factory, 43% off the two power plants and 19% off the Command Center. The Turkish computer builds and fires it on every difficulty: Hard as soon as it can pay, about fifteen minutes in on that map, Medium after seventeen minutes and Easy after thirty, the same clock America's plans keep for their Particle Cannon. China's airfield and the Hellfire drone are on loan, and the announcer calls it a Scud Storm until Turkiye has art and voices of its own.
+- Turkiye has a superweapon: the Kargu Drone Base. It costs 5000, draws 10 power, opens once you have a Factory and a Radar Tower, counts against the lobby's superweapon limit like the Particle Cannon, the nuke and the Scud Storm, and every player watches its five-minute countdown. The base is an airfield with two runways and four hangars, and you tell it from Turkiye's own airfield at a glance because it wears China's. Fire it and sixteen kamikaze drones take off in a stream, one down each runway in turn every quarter of a second, roll, lift off and climb, and all sixteen are in the air under six seconds after you fire. Then they fly straight across the map where everyone can see them coming. Each goes for one of the sixteen most expensive things inside the target circle, tips into its dive about 120 short and hits for 700, 11,200 for the whole swarm. Every target in the circle gets one drone before any gets a second, and the spares go round again dearest first. A drone whose target died on the way takes the dearest enemy in the circle that no other drone is already after, and doubles up only when every one has a drone coming. They are aircraft, so anti-air shoots them down on the way in. The last one hits fourteen seconds after you fire. Fired across Twilight Flame into an undefended American base, the swarm killed two of eight Crusaders and three of six Humvees, took 35% off the War Factory, 43% off the two power plants and 19% off the Command Center. The Turkish computer builds and fires it on every difficulty: Hard as soon as it can pay, about fifteen minutes in on that map, Medium after seventeen minutes and Easy after thirty, the same clock America's plans keep for their Particle Cannon. China's airfield and the Hellfire drone are on loan, and the announcer calls it a Scud Storm until Turkiye has art and voices of its own.
- Two engineers on one building put it up in half the time, three in a third.
- The Koral electronic warfare vehicle jams everything within 400 of it. Enemy drones and spotters inside the field go nearly blind, and guided missiles fired into it lose their lock and fly wide.
- The Maroon Beret is a hero against every side. He is camouflaged, sees 350 for the artillery from inside the camouflage, and carries Burton's knife and timed and remote charges. He no longer hijacks supply trucks, which used him up for good and found nothing to take from America.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/JetAIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/JetAIUpdate.h
index 1a80c9c63..762bf7f91 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/JetAIUpdate.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/JetAIUpdate.h
@@ -140,6 +140,8 @@ public:
void friend_purgePendingCommand();
/// a kamikaze whose target dies on the way looks for another here, and dives here when there is none
void friend_setKamikazeArea( const Coord3D *pos ) { m_kamikazeArea = *pos; }
+ /// what a kamikaze was last sent at, held on the runway or flown: its most recent order's target
+ ObjectID friend_getKamikazeTargetID() const { return m_mostRecentCommand.getTargetObjectID(); }
/// put on its runway's threshold with its space reserved, it starts the takeoff roll now
void friend_takeOffNow();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp
index e7175ba3d..26fdd9fb5 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp
@@ -32,6 +32,7 @@
#include "Common/ActionManager.h"
#include "Common/GlobalData.h"
#include "Common/MiscAudio.h"
+#include "Common/Player.h"
#include "Common/ThingFactory.h"
#include "Common/ThingTemplate.h"
#include "GameClient/Drawable.h"
@@ -2153,6 +2154,27 @@ void JetAIUpdate::getProducerLocation()
}
+//-------------------------------------------------------------------------------------------------
+/// a kamikaze looking for a new target weighs this many of the dearest in its area
+static const Int KAMIKAZE_RETARGET_CANDIDATES = 32;
+
+/// what the other live drones of one kind and owner are heading for
+struct KamikazeHeadings
+{
+ const Object* self;
+ std::vector<ObjectID> targets;
+};
+
+static void collectKamikazeHeading(Object* obj, void* userData)
+{
+ KamikazeHeadings* headings = (KamikazeHeadings*)userData;
+ // the template itself: isEquivalentTo would take the jet a drone is a reskin of as well
+ if (obj == headings->self || obj->isEffectivelyDead() ||
+ obj->getTemplate()->getFinalOverride() != headings->self->getTemplate()->getFinalOverride())
+ return;
+ headings->targets.push_back(obj->getAIUpdateInterface()->getJetAIUpdate()->friend_getKamikazeTargetID());
+}
+
//-------------------------------------------------------------------------------------------------
UpdateSleepTime JetAIUpdate::update()
{
@@ -2164,18 +2186,32 @@ UpdateSleepTime JetAIUpdate::update()
ParkingPlaceBehaviorInterface* pp = getPP(getObject()->getProducerID());
- // a kamikaze whose target is gone takes the dearest enemy left in the area it was sent to, or dives
- // into the area, rather than flying home with its one shot (notifyVictimIsDead) to land and wait
+ // a kamikaze whose target is gone takes the dearest enemy left in the area it was sent to that no
+ // other drone of its swarm is heading for, the dearest of all when every one has a drone already, or
+ // dives into the area, rather than flying home with its one shot (notifyVictimIsDead) to land and wait
if (d->m_kamikazeRange > 0.0f && getFlag(ALLOW_AIR_LOCO) && !getFlag(TAKEOFF_IN_PROGRESS) &&
!getFlag(LANDING_IN_PROGRESS) && !getFlag(HAS_PENDING_COMMAND) && AIUpdateInterface::isIdle())
{
std::vector<Object*> found;
- Weapon_findMostValuableEnemies(jet, &m_kamikazeArea, d->m_kamikazeRange, 1, found);
- DEBUG_LOG(("KAMIKAZE frame %d '%s' %d lost its target at (%.0f,%.0f), %s\n", TheGameLogic->getFrame(), jet->getTemplate()->getName().str(),
- jet->getID(), jet->getPosition()->x, jet->getPosition()->y, found.empty() ? "dives into the area" : found.front()->getTemplate()->getName().str()));
+ Weapon_findMostValuableEnemies(jet, &m_kamikazeArea, d->m_kamikazeRange, KAMIKAZE_RETARGET_CANDIDATES, found);
+ KamikazeHeadings headings;
+ headings.self = jet;
+ jet->getControllingPlayer()->iterateObjects(collectKamikazeHeading, &headings);
+ Object* pick = found.empty() ? NULL : found.front();
+ for (std::vector<Object*>::const_iterator it = found.begin(); it != found.end(); ++it)
+ {
+ if (std::find(headings.targets.begin(), headings.targets.end(), (*it)->getID()) == headings.targets.end())
+ {
+ pick = *it;
+ break;
+ }
+ }
+ DEBUG_LOG(("KAMIKAZE frame %d '%s' %d lost its target at (%.0f,%.0f), %s %d\n", TheGameLogic->getFrame(), jet->getTemplate()->getName().str(),
+ jet->getID(), jet->getPosition()->x, jet->getPosition()->y, pick ? pick->getTemplate()->getName().str() : "dives into the area",
+ pick ? (Int)pick->getID() : 0));
// a script's order, as the scramble gave (ParkingPlaceBehavior::launchScramble), so it chases
- if (!found.empty())
- aiAttackObject(found.front(), NO_MAX_SHOTS_LIMIT, CMD_FROM_SCRIPT);
+ if (pick)
+ aiAttackObject(pick, NO_MAX_SHOTS_LIMIT, CMD_FROM_SCRIPT);
else
aiAttackPosition(&m_kamikazeArea, NO_MAX_SHOTS_LIMIT, CMD_FROM_SCRIPT);
}