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): homeless armed jets burn out, airfield search reserves one

Olcay Seygan3cbf84ed147d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index db019c495..e53632dbe 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -693,6 +693,8 @@ found and fixed, EA's own, not port damage.**
- Two jets on one airfield could deadlock waiting for each other; now they go.
- Losing the airfield no longer leaves its aircraft circling rubble forever.
+- A jet looking for a new airfield no longer locks parking spaces it never uses. The search booked a space at every airfield it looked at on the way to the nearest, and each of those stayed booked for that jet until it died: an empty spot on the tarmac no other plane could land on and the airfield could not build into.
+- A jet whose airfield is gone no longer haunts your base. One that still had a bomb or a missile on board was let off the fuel clock EA gives every homeless jet, so with every other airfield full it hung over the ruin for the rest of the match, half dead and never repaired: a damaged Aurora orbiting a base of ten full airfields. It now circles the ruin with the empty ones, checks every second for a free spot, lands on the first that opens and goes down when its fuel runs out. A jet a map places in the air without an airfield still waits instead.
- Repaired aircraft fly to the rally point instead of hovering over the pad.
- Infantry leaving a captured building follow its rally point too.
- The Spectre gunship's crosshair answers your right click. Its gun only walked its fire toward a new spot while it was already shooting, so moving the crosshair onto ground the gun could not reach that moment froze the fire on the old spot for the rest of the orbit. Now the cannon rakes across to every click inside the target circle and the howitzer follows it there; a click outside the circle stops at its edge, as before, and the plane keeps circling where you called it. It also opens up on enemies anywhere in the circle when the crosshair sits on empty ground, which EA had only let the computer's gunships do. Yours and the computer's now follow the same rules. Measured on Alpine Assault: moved three times in one orbit, the first move had shells on the new spot under two seconds after the click, and four Battlemasters parked in the circle were all dead before the plane left.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/BehaviorModule.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/BehaviorModule.h
index 5720d25a8..86e4d235d 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/BehaviorModule.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/BehaviorModule.h
@@ -240,7 +240,9 @@ public:
};
virtual Bool shouldReserveDoorWhenQueued(const ThingTemplate* thing) const = 0;
virtual Bool hasAvailableSpaceFor(const ThingTemplate* thing) const = 0;
- virtual Bool hasReservedSpace(ObjectID id) const = 0;
+ virtual Bool hasReservedSpace(ObjectID id) const = 0;
+ /// would reserveSpace(id, ...) succeed? asks without reserving, and without the helipad shortcut
+ virtual Bool canReserveSpace(ObjectID id) const = 0;
virtual Int getSpaceIndex( ObjectID id ) const = 0;
virtual Bool reserveSpace(ObjectID id, Real parkingOffset, PPInfo* info) = 0;
virtual void releaseSpace(ObjectID id) = 0;
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/FlightDeckBehavior.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/FlightDeckBehavior.h
index 8add4163b..3b5e6b91e 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/FlightDeckBehavior.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/FlightDeckBehavior.h
@@ -134,7 +134,8 @@ public:
// ParkingPlaceBehaviorInterface
virtual Bool shouldReserveDoorWhenQueued(const ThingTemplate* thing) const;
virtual Bool hasAvailableSpaceFor(const ThingTemplate* thing) const;
- virtual Bool hasReservedSpace(ObjectID id) const;
+ virtual Bool hasReservedSpace(ObjectID id) const;
+ virtual Bool canReserveSpace(ObjectID id) const;
virtual Int getSpaceIndex( ObjectID id ) const;
virtual Bool reserveSpace(ObjectID id, Real parkingOffset, PPInfo* info);
virtual void releaseSpace(ObjectID id);
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/JetAIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/JetAIUpdate.h
index 762bf7f91..15f4b66ac 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/JetAIUpdate.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/JetAIUpdate.h
@@ -114,6 +114,7 @@ public:
const Coord3D* friend_getProducerLocation() const { return &m_producerLocation; }
Real friend_getOutOfAmmoDamagePerSecond() const { return getJetAIUpdateModuleData()->m_outOfAmmoDamagePerSecond; }
+ Bool friend_hadAirfield() const { return getFlag(HAD_AIRFIELD); }
Bool friend_keepsParkingSpaceWhenAirborne() const { return getJetAIUpdateModuleData()->m_keepsParkingSpaceWhenAirborne; }
Bool friend_needsRunway() const { return getJetAIUpdateModuleData()->m_needsRunway; }
Real friend_getTakeoffDistForMaxLift() const { return getJetAIUpdateModuleData()->m_takeoffDistForMaxLift; }
@@ -172,7 +173,8 @@ private:
USE_SPECIAL_RETURN_LOCO,
ALLOW_CIRCLING,
ALLOW_INTERRUPT_AND_RESUME_OF_CUR_STATE_FOR_RELOAD,
- TAXI_IN_PROGRESS
+ TAXI_IN_PROGRESS,
+ HAD_AIRFIELD ///< it has belonged to an airfield at some point, so it was not placed on the map without one
};
Coord3D m_producerLocation; ///< remember this, so that if our producer dies, we have a place to circle aimlessly
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ParkingPlaceBehavior.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ParkingPlaceBehavior.h
index f5f4932e2..b676fd917 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ParkingPlaceBehavior.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ParkingPlaceBehavior.h
@@ -139,6 +139,7 @@ public:
virtual Bool shouldReserveDoorWhenQueued(const ThingTemplate* thing) const;
virtual Bool hasAvailableSpaceFor(const ThingTemplate* thing) const;
virtual Bool hasReservedSpace(ObjectID id) const;
+ virtual Bool canReserveSpace(ObjectID id) const;
virtual Int getSpaceIndex( ObjectID id ) const;
virtual Bool reserveSpace(ObjectID id, Real parkingOffset, PPInfo* info);
virtual void releaseSpace(ObjectID id);
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/FlightDeckBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/FlightDeckBehavior.cpp
index 3b156db6a..ebf4563ae 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/FlightDeckBehavior.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/FlightDeckBehavior.cpp
@@ -376,6 +376,13 @@ Bool FlightDeckBehavior::hasReservedSpace(ObjectID id) const
return false;
}
+//-------------------------------------------------------------------------------------------------
+// what reserveSpace would answer, without taking the space (see ParkingPlaceBehavior::canReserveSpace)
+Bool FlightDeckBehavior::canReserveSpace(ObjectID id) const
+{
+ return hasReservedSpace(id) || hasAvailableSpaceFor(NULL);
+}
+
//-------------------------------------------------------------------------------------------------
Int FlightDeckBehavior::getSpaceIndex( ObjectID id ) const
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp
index 3a9e4013f..438ba0b27 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp
@@ -240,6 +240,38 @@ Bool ParkingPlaceBehavior::hasReservedSpace(ObjectID id) const
return false;
}
+//-------------------------------------------------------------------------------------------------
+/* What reserveSpace would answer, without taking the space: the airfield search asked by reserving,
+ so every airfield it tried on the way to the nearest kept a space for that jet until it died.
+ A dead occupant counts as gone, as purgeDead would make it. Helicopters need a space here too
+ (they park on it), so there is no helipad shortcut as in hasAvailableSpaceFor. */
+Bool ParkingPlaceBehavior::canReserveSpace(ObjectID id) const
+{
+ if (!m_gotInfo || id == INVALID_ID)
+ return false;
+
+ for (std::vector<ParkingPlaceInfo>::const_iterator it = m_spaces.begin(); it != m_spaces.end(); ++it)
+ {
+ if (it->m_objectInSpace == id)
+ return true;
+ }
+
+ for (std::vector<ParkingPlaceInfo>::const_iterator it = m_spaces.begin(); it != m_spaces.end(); ++it)
+ {
+ if (it->m_objectInSpace != INVALID_ID)
+ {
+ Object* obj = TheGameLogic->findObjectByID(it->m_objectInSpace);
+ if (obj == NULL || obj->isEffectivelyDead())
+ return true;
+ }
+ else if (!it->m_reservedForExit)
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
//-------------------------------------------------------------------------------------------------
Int ParkingPlaceBehavior::getSpaceIndex( ObjectID id ) const
{
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 3a31985a9..c5bdf3e0c 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp
@@ -277,10 +277,10 @@ protected:
#endif
virtual Bool allow(Object *objOther)
{
+ // ask, don't reserve: EA reserved here, so every airfield the search tried on its way to the
+ // nearest kept a space for this jet, empty on the ground and closed to everyone, until it died
ParkingPlaceBehaviorInterface* pp = getPP(objOther->getID());
- if (pp != NULL && pp->reserveSpace(m_id, 0.0f, NULL))
- return true;
- return false;
+ return pp != NULL && pp->canReserveSpace(m_id);
}
};
@@ -306,7 +306,12 @@ static Object* findSuitableAirfield(Object* jet)
filters[numFilters++] = &filterMapStatus;
filters[numFilters] = NULL;
- return ThePartitionManager->getClosestObject( jet, HUGE_DIST, FROM_CENTER_2D, filters );
+ // the one it picked is reserved, as the filter used to do, so nobody takes the space on the way there
+ Object* airfield = ThePartitionManager->getClosestObject( jet, HUGE_DIST, FROM_CENTER_2D, filters );
+ ParkingPlaceBehaviorInterface* pp = airfield ? getPP(airfield->getID()) : NULL;
+ if (pp != NULL && !pp->reserveSpace(jet->getID(), 0.0f, NULL))
+ return NULL;
+ return airfield;
}
//-------------------------------------------------------------------------------------------------
@@ -469,7 +474,11 @@ public:
// it might not have an owning airfield, and it might be trying to return
// simply due to being idle, not out of ammo. so check and don't die in that
// case, but just punt back out to idle.
- if (!jetAI->isOutOfSpecialReloadAmmo() && jet->getProducerID() == INVALID_ID)
+ // Only a jet that never had an airfield, though. Returning for landing clears the producer of
+ // one whose airfield is gone, and that jet, still carrying a bomb, used to be punted out here
+ // too: idle, back ten seconds later, punted again, never burning and never landing, a damaged
+ // Aurora orbiting a full base for the rest of the match. It circles the ruin with the rest now.
+ if (!jetAI->isOutOfSpecialReloadAmmo() && jet->getProducerID() == INVALID_ID && !jetAI->friend_hadAirfield())
{
return STATE_FAILURE;
}
@@ -2185,6 +2194,8 @@ UpdateSleepTime JetAIUpdate::update()
Object* jet = getObject();
ParkingPlaceBehaviorInterface* pp = getPP(getObject()->getProducerID());
+ if (pp != NULL)
+ setFlag(HAD_AIRFIELD, true);
// 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