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): repair base defence targeting and disabled-state bugs
Olcay Seygan9656868dd9d7
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a2db20001..e29301841 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -436,6 +436,17 @@ found and fixed — EA's own, not port damage.**- A Chinese silo researching an upgrade while its missile charged drew both bars and both countdowns in the same row of pixels. They stack now.- Units moving diagonally ran up to 40% faster than their own stat sheet.- Garrisoned infantry and base defences only ever range-checked one of their weapons.+- A Gattling Cannon, a Patriot battery or a Stinger Site no longer locks onto a tank it cannot reach. Each has a short-range ground gun (225) and a longer anti-air one (350 to 400), and the air gun's reach counted for ground targets: a tank at 300 became the target, the turret swung after it, nothing fired, and a helicopter overhead that the air gun could have hit went untouched until the tank left or died.+- Patriot batteries aim at the aircraft they shoot at. The lift they add to lob a missile over a ground target was added to every target, so against a helicopter the launcher pointed up to 40 degrees above it.+- An EMP or a Hacker no longer leaves a Bunker or a Fire Base shooting. The blast switched the building off and left the soldiers inside alone, and they kept firing out of it for as long as it was dark.+- Soldiers in a Bunker fire at the edge of their range. One already standing at a firing slot measured his reach from the other, empty slots, so at the edge he let go of a target he could hit, picked it up again and never fired. Your own Bunkers measured from the middle of the building and ignored enemies at the edge altogether, where a computer player's did not.+- A Stinger Site's soldiers stay at the site. A computer player's soldier followed a reversing tank across the map and stood wherever it died, never to return, and yours ran out several hundred paces to hit back at whoever had shot a neighbour.+- A computer player's GLA tunnel no longer empties under a helicopter. A strafing Comanche made itself the tunnel's target, and the rebels inside poured out after an attacker none of them could shoot.+- An EMPed or unpowered defence stops acting as if it were fighting. A Gattling Cannon hit mid-burst spun its barrels for the whole blackout, and one ordered to attack while it had no power spun up without firing a shot. It drops its target now, can't be given a new one until it is back, and picks one again when it is.+- A vehicle knocked out by an EMP while its turret was turning goes quiet. The turret's motor sound only ever stopped when the turret next moved, so it looped for the whole time the vehicle sat dead.+- A Fire Base can be ordered to attack what only the soldiers inside it can hit. The base's own howitzer answered first, and a howitzer hits nothing in the air and nothing within 50 of the base, so Missile Defenders inside got no attack cursor on a Comanche.+- A defence that picked its own target moves on once that target is as good as dead. When the shots already in the air were enough to finish it, a Gattling Cannon held its fire and kept aiming at it, for up to three and a half seconds, while the next tank drove up. It lets go and takes the next one.+- The green beam between Patriot batteries means a battery is really joining in. A shot called every idle battery within 200 to fire a volley at the same target, and the beams went out to batteries that could not: one without power, one knocked out by an EMP, one already busy with its own target, one the target was too far from. None of them fired. A battery shooting down a missile called the rest in too, with a weapon that cannot hit missiles. Only a battery able to hit the target from where it stands is called now. A battery whose target died after one missile of its volley also kept the longer assist range for its own shots until it next emptied a volley; it drops it when the target goes.- Killing something with poison or toxin credited nobody with experience or score.- Healing a unit counted as attacking it, so guards chased the wrong target.- A supply centre could stop accepting trucks permanently.diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.hindex 1fc6de170..584864842 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h@@ -445,6 +445,7 @@ public:void setTurretTargetPosition(WhichTurretType tur, const Coord3D* pos);void setTurretEnabled(WhichTurretType tur, Bool enabled);void recenterTurret(WhichTurretType tur);+ void stopTurretsTurning(); ///< every turret stops its move loop and rotate lookBool isTurretEnabled( WhichTurretType tur ) const;Bool isTurretInNaturalPosition(WhichTurretType tur) const;diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AssistedTargetingUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AssistedTargetingUpdate.hindex bb29cee39..09a7c0cab 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AssistedTargetingUpdate.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AssistedTargetingUpdate.h@@ -71,7 +71,7 @@ public:virtual UpdateSleepTime update( void );- Bool isFreeToAssist() const;+ Bool isFreeToAssist( const Object *victimObject ) const;void assistAttack( const Object *requestingObject, Object *victimObject );private:@@ -79,6 +79,7 @@ private:const ThingTemplate *m_laserFromAssisted;const ThingTemplate *m_laserToTarget;+ ObjectID m_assistVictimID; ///< who the weapon lock was taken for, until the lock is let go};diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.hindex a6e7bba8e..2c6727a95 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h@@ -617,6 +617,7 @@ public:void setDisabled( DisabledType type );void setDisabledUntil( DisabledType type, UnsignedInt frame );Bool isDisabledByType( DisabledType type ) const { return TEST_DISABLEDMASK( m_disabledMask, type ); }+ Bool isAIHaltedByDisable() const; ///< disabled in a way that stops this object's AI from updating at allUnsignedInt getDisabledUntil( DisabledType type = DISABLED_ANY ) const;diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/TurretAI.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/TurretAI.hindex 5059da270..22b927751 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/TurretAI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/TurretAI.h@@ -300,6 +300,7 @@ public:Bool isTurretInNaturalPosition() const;void setTurretEnabled( Bool enabled );+ void stopTurning(); ///< silence the move loop and drop the rotate look, for when nothing will update this turret for a whileBool isTurretEnabled() const { return m_enabled; }/**diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Weapon.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Weapon.hindex a9c1a48f7..5ffabd9a7 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Weapon.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Weapon.h@@ -628,6 +628,7 @@ public:*/Bool isWithinAttackRange(const Object *source, const Object *target) const;Bool isWithinAttackRange(const Object *source, const Coord3D* pos) const;+ Bool isWithinAttackRangeFromFirePoint(const Object *source, const Object *victim, const Coord3D *victimPos) const; ///< also from the best free fire point of a garrison the source is insideBool isTooClose(const Object *source, const Object *target) const;Bool isTooClose(const Object *source, const Coord3D *pos) const;diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/WeaponSet.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/WeaponSet.hindex dec9d8880..4dc6495e6 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/WeaponSet.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/WeaponSet.h@@ -268,6 +268,7 @@ public:Weapon* getWeaponInWeaponSlot(WeaponSlotType wslot) const;+ static Int getVictimAntiMask(const Object* victim);static ModelConditionFlags getModelConditionForWeaponSlot(WeaponSlotType wslot, WeaponSetConditionType a);};diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/ActionManager.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/ActionManager.cppindex 2cef29b57..a6eecdc1a 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/ActionManager.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/ActionManager.cpp@@ -749,6 +749,29 @@ Bool ActionManager::canEnterObject( const Object *obj, const Object *objectToEnt}+// ------------------------------------------------------------------------------------------------+/** The best answer any soldier firing out of obj gives, or ATTACKRESULT_NOT_POSSIBLE */+// ------------------------------------------------------------------------------------------------+static CanAttackResult getCanPassengersAttackObject( const Object *obj, const Object *objectToAttack, CommandSourceType commandSource, AbleToAttackType attackType )+{+ const ContainModuleInterface *contain = obj->getContain();+ if( !contain || !contain->isPassengerAllowedToFire() )+ return ATTACKRESULT_NOT_POSSIBLE;++ const ContainedItemsList *passengers = contain->getContainedItemsList();+ for( ContainedItemsList::const_iterator it = passengers->begin(); it != passengers->end(); ++it )+ {+ const Object *passenger = *it;+ if( !passenger->isAbleToAttack() )+ continue;++ CanAttackResult result = passenger->getAbleToAttackSpecificObject( attackType, objectToAttack, commandSource );+ if( result == ATTACKRESULT_POSSIBLE || result == ATTACKRESULT_POSSIBLE_AFTER_MOVING )+ return result;+ }+ return ATTACKRESULT_NOT_POSSIBLE;+}+// ------------------------------------------------------------------------------------------------// ------------------------------------------------------------------------------------------------CanAttackResult ActionManager::getCanAttackObject( const Object *obj, const Object *objectToAttack, CommandSourceType commandSource, AbleToAttackType attackType )@@ -764,9 +787,28 @@ CanAttackResult ActionManager::getCanAttackObject( const Object *obj, const Objereturn ATTACKRESULT_NOT_POSSIBLE;}+ // an EMPed or unpowered defence takes the order into an attack its AI will not run until it is back+ if( obj->isKindOf( KINDOF_STRUCTURE ) && obj->isAIHaltedByDisable() )+ {+ return ATTACKRESULT_NOT_POSSIBLE;+ }+//has any weapons that are capable of inflicting damage. Special damage types are rejected//such as hack weapons... others can be added.CanAttackResult result = obj->getAbleToAttackSpecificObject( attackType, objectToAttack, commandSource );++ // A Fire Base's own howitzer answers first, and it is ground-only with a minimum range of 50, so its+ // "invalid shot" ended the question before the soldiers inside were asked: no attack cursor on a+ // Comanche with Missile Defenders in the base. The group order already hands the attack to every+ // passenger who can take it. The old rider fallback below only ran on NOT_POSSIBLE, and only asked+ // the rider nearest the target.+ if( result != ATTACKRESULT_POSSIBLE && result != ATTACKRESULT_POSSIBLE_AFTER_MOVING )+ {+ CanAttackResult passengerResult = getCanPassengersAttackObject( obj, objectToAttack, commandSource, attackType );+ if( passengerResult != ATTACKRESULT_NOT_POSSIBLE )+ return passengerResult;+ }+if( result != ATTACKRESULT_NOT_POSSIBLE ){//Kris: August 5, 2003@@ -825,20 +867,6 @@ CanAttackResult ActionManager::getCanAttackObject( const Object *obj, const Obje}}}- else if( result == ATTACKRESULT_NOT_POSSIBLE )// oh dear me. The wierd case of a garrisoncontainer being a KINDOF_SPAWNS_ARE_THE_WEAPONS... the AmericaBuildingFirebase- {- ContainModuleInterface *contain = obj->getContain();- if ( contain )- {- Object *rider = contain->getClosestRider( objectToAttack->getPosition() );- if ( rider )- {- result = rider->getAbleToAttackSpecificObject( attackType, objectToAttack, commandSource );- if( result != ATTACKRESULT_NOT_POSSIBLE )- return result;- }- }- }}return ATTACKRESULT_NOT_POSSIBLE;diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cppindex 32246f0d0..c20149b2f 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp@@ -45,6 +45,7 @@#include "GameLogic/AIPathfind.h"#include "GameLogic/AIPlayer.h" // for the per-frame AI profile the slow-frame report prints#include "GameLogic/Weapon.h"+#include "GameLogic/WeaponSet.h"extern void addIcon(const Coord3D *pos, Real width, Int numFramesDuration, RGBColor color);@@ -581,7 +582,12 @@ public:if (w == NULL)continue;- if (w->isWithinAttackRange(m_obj, objOther))+ // a weapon that cannot target this kind of thing does not bring it into range+ if ((w->getAntiMask() & WeaponSet::getVictimAntiMask(objOther)) == 0)+ continue;++ // a garrisoned soldier idles at the middle of the building and shoots from its edge+ if (w->isWithinAttackRangeFromFirePoint(m_obj, objOther, objOther->getPosition())){return true;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cppindex a06366643..ffaf5207b 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp@@ -2632,7 +2632,15 @@ StateReturnType AIAttackApproachTargetState::onEnter()}}- // Check here: If we are a player, and we got to this state via an ai command (ie we auto-acquired),+ // A Stinger soldier is its site's weapon. Its SlavedUpdate has no guard range, so nothing ever walks+ // it home: a computer player's soldier followed a reversing tank across the map and stood wherever+ // the tank died. Like the site, it shoots what is in range or nothing.+ if (source->isKindOf(KINDOF_SPAWNS_ARE_THE_WEAPONS))+ {+ return STATE_FAILURE;+ }++ // Check here: If we are a player, and we got to this state via an ai command (ie we auto-acquired),// we don't want to chase the unit. isAllowedToChase is set when we are in a deploy and attack state (troop crawler).// Kris (July 2003): If we are retaliating... don't fail out!if( ai->getCurrentStateID() != AI_GUARD_RETALIATE )@@ -5573,6 +5581,17 @@ StateReturnType AIAttackAimAtTargetState::update()// if (m_isAttackingObject && source->canCrushOrSquish(victim)) {// return STATE_SUCCESS;// }++ // The fire state holds the round when the victim is already paid for, and falls back to aiming,+ // which is fine for a unit that leaves this state; a turret's aim never does. A Gattling Cannon+ // that had picked the tank itself went silent until the booking lapsed, with a second tank+ // driving up. Let go of a target we chose ourselves: the scan that chose it passes over doomed+ // ones. An order is kept, as the fire state promises.+ if (m_isAttackingObject && sourceAI->getLastCommandSource() == CMD_FROM_AI &&+ IncomingDamageTracker::isSpokenFor(victim, source->getID()))+ {+ return STATE_FAILURE;+ }return STATE_CONTINUE;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AITNGuard.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AITNGuard.cppindex 073a91573..2d7d9492d 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AITNGuard.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AITNGuard.cpp@@ -188,6 +188,13 @@ AITNGuardMachine::~AITNGuardMachine()return visionRange;}+//--------------------------------------------------------------------------------------+static Bool isAbleToFightFromTunnel(const Object *owner, const Object *victim)+{+ CanAttackResult result = owner->getAbleToAttackSpecificObject(ATTACK_TUNNEL_NETWORK_GUARD, victim, CMD_FROM_AI);+ return result == ATTACKRESULT_POSSIBLE || result == ATTACKRESULT_POSSIBLE_AFTER_MOVING;+}+//--------------------------------------------------------------------------------------Bool AITNGuardMachine::lookForInnerTarget(void){@@ -211,8 +218,12 @@ Bool AITNGuardMachine::lookForInnerTarget(void)if (!ownerPlayer) return false; // should never happen, but hey. jba.TunnelTracker *tunnels = ownerPlayer->getTunnelSystem();if (tunnels==NULL) return false;- if (tunnels->getCurNemesis()) {- setNemesisID(tunnels->getCurNemesis()->getID());+ // The tunnel's nemesis is whoever last hit it, aircraft included, and its gun's goal is whatever the+ // gun shoots at. Neither was asked whether this unit can fight it, so a Comanche strafing a tunnel+ // emptied it of rebels who could not shoot back. The attacked-tunnel scan below always asked.+ Object *nemesis = tunnels->getCurNemesis();+ if (nemesis && isAbleToFightFromTunnel(owner, nemesis)) {+ setNemesisID(nemesis->getID());return true; // Transitions to AITNGuardInnerState.}const std::list<ObjectID> *allTunnels = tunnels->getContainerList();@@ -222,7 +233,7 @@ Bool AITNGuardMachine::lookForInnerTarget(void)// Check for attacking.if (currentTunnel->getAI()) {Object *victim = currentTunnel->getAI()->getGoalObject();- if (owner->getRelationship(victim) == ENEMIES) {+ if (owner->getRelationship(victim) == ENEMIES && isAbleToFightFromTunnel(owner, victim)) {setNemesisID(victim->getID());return true;}@@ -625,8 +636,8 @@ StateReturnType AITNGuardReturnState::update( void )if (tunnels) {Object *nemesis = tunnels->getCurNemesis();- if (nemesis) {- // Check distance.+ if (nemesis && isAbleToFightFromTunnel(getMachineOwner(), nemesis)) {+ // Check distance.//Coord3D dist;//Coord3D curPos;//dist.set()diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cppindex 758b91faa..6362b4349 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp@@ -37,6 +37,7 @@#include "Common/Xfer.h"#include "GameLogic/GameLogic.h"+#include "GameLogic/IncomingDamage.h"#include "GameLogic/Module/AIUpdate.h"#include "GameLogic/Object.h"#include "GameLogic/PartitionManager.h"@@ -794,12 +795,26 @@ void TurretAI::startRotOrPitchSound()*/void TurretAI::stopRotOrPitchSound(){- if (m_turretRotOrPitchSound.isCurrentlyPlaying())+ if (m_turretRotOrPitchSound.isCurrentlyPlaying()){TheAudio->removeAudioEvent(m_turretRotOrPitchSound.getPlayingHandle());}}+//-------------------------------------------------------------------------------------------------+/**+ * Only updateTurretAI starts and stops the move loop and sets the rotate look, and an EMPed or+ * unpowered owner's AI does not update, so a turret caught mid-turn kept both for the whole outage.+ * The next update that turns the turret starts them again.+ */+void TurretAI::stopTurning()+{+ m_playRotSound = false;+ m_playPitchSound = false;+ stopRotOrPitchSound();+ getOwner()->clearModelConditionState(MODELCONDITION_TURRET_ROTATE);+}+#ifdef INTER_TURRET_DELAY//----------------------------------------------------------------------------------------------------------void TurretAI::getOtherTurretWeaponInfo(Int& numSelf, Int& numSelfReloading, Int& numSelfReady, Int& numOther, Int& numOtherReloading, Int& numOtherReady) const@@ -850,6 +865,11 @@ Bool TurretAI::friend_isAnyWeaponInRangeOf(const Object* o) constif (w == NULL || !isWeaponSlotOnTurret((WeaponSlotType)i))continue;+ // an anti-air gun's reach must not keep a tank as the target of a ground gun that cannot reach it:+ // the turret sat in its aim state swinging after the tank and ignored the aircraft it could hit+ if ((w->getAntiMask() & WeaponSet::getVictimAntiMask(o)) == 0)+ continue;+if (w->isWithinAttackRange(getOwner(), o)// srj sez: not sure if we want to do this or not.// jba sez: no, don't do this. isWithinAttackRange checks terrain los now, and@@ -990,6 +1010,7 @@ StateReturnType TurretAIAimTurretState::update()Bool preventing = false;TurretTargetType targetType = turret->friend_getTurretTarget(enemy, enemyPosition);Object *enemyForDistanceCheckOnly = enemy; // Note: Do not use this anywhere except for the range check.+ Bool aimingAtGround = (targetType != TARGET_OBJECT); // a position, or a building; decided before enemy is nulledBool nothingInRange = false;switch (targetType)@@ -1029,6 +1050,15 @@ StateReturnType TurretAIAimTurretState::update()return STATE_FAILURE;}+ // The fire state holds the round on a victim already paid for and hands back to this state, which+ // never looks for another target, so a turret that had picked the target on its own sat silent+ // until the booking lapsed. Drop it; hold scans again, and its scan passes over doomed targets.+ if (turret->friend_getTargetWasSetByIdleMood() && IncomingDamageTracker::isSpokenFor(enemy, obj->getID()))+ {+ turret->setTurretTargetObject(NULL, FALSE);+ return STATE_FAILURE;+ }+// aim turret towards enemy (turret angle is relative to its parent object)if (enemy->isKindOf(KINDOF_BRIDGE)){@@ -1060,6 +1090,8 @@ StateReturnType TurretAIAimTurretState::update()preventing = enemyAI && enemyAI->isTemporarilyPreventingAimSuccess();+ aimingAtGround = enemy->isKindOf(KINDOF_IMMOBILE);+// don't use 'enemy' after this point, just the position. to help// enforce this, we'll null it out.enemy = NULL;@@ -1146,13 +1178,9 @@ StateReturnType TurretAIAimTurretState::update()desiredPitch = turret->getMinPitch();}if (turret->getGroundUnitPitch() > 0) {- Bool adjust = false;- if (!enemy) {- adjust = true; // adjust for ground targets.- }- if (enemy && enemy->isKindOf(KINDOF_IMMOBILE)) {- adjust = true;- }+ // enemy is always NULL by now, so testing it here raised the aim against every aircraft too:+ // a Patriot launched 40 degrees above the helicopter it was shooting at+ Bool adjust = aimingAtGround;if (enemyAI && enemyAI->isDoingGroundMovement()) {adjust = true;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Body/ActiveBody.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Body/ActiveBody.cppindex 3e0ea512a..87f6d2301 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Body/ActiveBody.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Body/ActiveBody.cpp@@ -754,7 +754,9 @@ void ActiveBody::attemptDamage( DamageInfo *damageInfo )continue;}//If we have AI and we're mobile, then assist!- if( !them->isKindOf( KINDOF_IMMOBILE ))+ // A Stinger soldier only looks mobile: it belongs at its site, and retaliating sent it after+ // whoever had shot a neighbour, several hundred out.+ if( !them->isKindOf( KINDOF_IMMOBILE ) && !them->isKindOf( KINDOF_SPAWNS_ARE_THE_WEAPONS )){//But only if we can attack it!CanAttackResult result = them->getAbleToAttackSpecificObject( ATTACK_NEW_TARGET, damager, CMD_FROM_AI );diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/GarrisonContain.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/GarrisonContain.cppindex a85be9e6a..703122e98 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/GarrisonContain.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/GarrisonContain.cpp@@ -1719,6 +1719,12 @@ Bool GarrisonContain::isPassengerAllowedToFire( ObjectID id ) constif ( self && self->isDisabledByType( DISABLED_SUBDUED ) )return FALSE;+ // An EMP or a hacker disables the building and not the infantry inside it, so a Bunker or a Fire Base+ // that had gone dark kept shooting through every fire point. Patch 1.01 silenced a Stinger Site's+ // soldiers under EMP for the same reason (Object::setDisabledUntil).+ if ( self && ( self->isDisabledByType( DISABLED_EMP ) || self->isDisabledByType( DISABLED_HACKED ) ) )+ return FALSE;+return TRUE;} // end isPassengerAllowedToFirediff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cppindex 52b5f1751..1fc49b626 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp@@ -2138,6 +2138,17 @@ void Object::setDisabled( DisabledType type )setDisabledUntil(type, FOREVER);}+//-------------------------------------------------------------------------------------------------+Bool Object::isAIHaltedByDisable() const+{+ if( !m_ai )+ return FALSE;++ DisabledMaskType halting = m_disabledMask;+ halting.clear( m_ai->getDisabledTypesToProcess() );+ return halting.any();+}+//-------------------------------------------------------------------------------------------------void Object::setDisabledUntil( DisabledType type, UnsignedInt frame ){@@ -2192,6 +2203,16 @@ void Object::setDisabledUntil( DisabledType type, UnsignedInt frame )m_disabledTillFrame[ type ] = frame;m_disabledMask.set( type, frame > TheGameLogic->getFrame() );+ // A building's AI does not run while it is EMPed, hacked, subdued or out of power, so the attack it+ // was in never exited and kept its look: a Gattling Cannon spun its barrels through the whole EMP.+ // Selling a building idles it the same way, and it picks a target again once it is back.+ if( isAIHaltedByDisable() )+ {+ m_ai->stopTurretsTurning();+ if( isKindOf( KINDOF_STRUCTURE ) )+ m_ai->aiIdle( CMD_FROM_AI );+ }+if( m_drawable ){if( isDisabled() )diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cppindex 35bde5988..fa891506f 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp@@ -812,6 +812,18 @@ void AIUpdateInterface::recenterTurret(WhichTurretType tur)}}+//=============================================================================+void AIUpdateInterface::stopTurretsTurning()+{+ for (Int i = 0; i < MAX_TURRETS; ++i)+ {+ if (m_turretAI[i])+ {+ m_turretAI[i]->stopTurning();+ }+ }+}+//=============================================================================Bool AIUpdateInterface::isTurretEnabled( WhichTurretType tur ) const{diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AssistedTargetingUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AssistedTargetingUpdate.cppindex 5aef18f03..894de258a 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AssistedTargetingUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AssistedTargetingUpdate.cpp@@ -72,6 +72,7 @@ AssistedTargetingUpdate::AssistedTargetingUpdate( Thing *thing, const ModuleData{m_laserFromAssisted = NULL;m_laserToTarget = NULL;+ m_assistVictimID = INVALID_ID;}//-------------------------------------------------------------------------------------------------@@ -82,15 +83,31 @@ AssistedTargetingUpdate::~AssistedTargetingUpdate( void )//-------------------------------------------------------------------------------------------------//--------------------------------------------------------------------------------------------------Bool AssistedTargetingUpdate::isFreeToAssist() const+Bool AssistedTargetingUpdate::isFreeToAssist( const Object *victimObject ) const{- // The reload times of my two weapons are tied together, so Ready is indicitive of either.+ const AssistedTargetingUpdateModuleData *md = getAssistedTargetingUpdateModuleData();const Object *me = getObject();if( !me->isAbleToAttack() )return FALSE;// This will cover under construction among other things+ // An underpowered, EMPed or hacked battery has no running AI to take the order, and one already on a+ // target of its own is not free. Both used to draw the beams and never fire the clip.+ if( me->isDisabled() || me->testStatus( OBJECT_STATUS_IS_ATTACKING ) )+ return FALSE;++ // The reload times of my two weapons are tied together, so Ready is indicitive of either.Bool ready = me->getCurrentWeapon() && me->getCurrentWeapon()->getStatus() == READY_TO_FIRE;- return ready;+ if( !ready )+ return FALSE;++ // The lock forces the assisting weapon whatever the victim is, so that weapon has to be able to hit it+ // from here. A requester firing at aircraft 350 out and asking 200 further reaches past the assist+ // weapon's 450, and a requester shooting down a missile asks with a weapon the assist one is not.+ Weapon *assistWeapon = me->getWeaponInWeaponSlot( md->m_weaponSlot );+ return (assistWeapon->getAntiMask() & WeaponSet::getVictimAntiMask( victimObject )) != 0+ && assistWeapon->isWithinTargetPitch( me, victimObject )+ && assistWeapon->isWithinAttackRange( me, victimObject )+ && assistWeapon->estimateWeaponDamage( me, victimObject ) > 0.0f;}//-------------------------------------------------------------------------------------------------@@ -105,6 +122,8 @@ void AssistedTargetingUpdate::assistAttack( const Object *requestingObject, Obje// lock it just till the weapon is empty or the attack is "done"me->setWeaponLock( md->m_weaponSlot, LOCKED_TEMPORARILY );me->getAI()->aiAttackObject( victimObject, md->m_clipSize, CMD_FROM_AI );+ m_assistVictimID = victimObject->getID();+ setWakeFrame( me, UPDATE_SLEEP_NONE );if( m_laserFromAssisted )@@ -154,6 +173,25 @@ UpdateSleepTime AssistedTargetingUpdate::update( void )// victim was drawn with the template meant for the beam from the spotter.m_laserToTarget = TheThingFactory->findTemplate( d->m_laserToTargetName );+ if( m_assistVictimID == INVALID_ID )+ return UPDATE_SLEEP_FOREVER;++ // Only the last shot of a clip lets go of the lock. An assist that ended any other way, the victim+ // killed by somebody else after one missile, left the battery shooting its own targets with the+ // long-range assist weapon until it next emptied a clip.+ Object *me = getObject();+ WeaponSlotType currentSlot;+ me->getCurrentWeapon( ¤tSlot );+ if( me->isCurWeaponLocked() && currentSlot == d->m_weaponSlot )+ {+ Object *goal = me->getAI()->getGoalObject();+ if( me->testStatus( OBJECT_STATUS_IS_ATTACKING ) && goal && goal->getID() == m_assistVictimID )+ return UPDATE_SLEEP_NONE;++ me->releaseWeaponLock( LOCKED_TEMPORARILY );+ }++ m_assistVictimID = INVALID_ID;return UPDATE_SLEEP_FOREVER;}@@ -171,19 +209,23 @@ void AssistedTargetingUpdate::crc( Xfer *xfer )// ------------------------------------------------------------------------------------------------/** Xfer method* Version Info:- * 1: Initial version */+ * 1: Initial version+ * 2: m_assistVictimID */// ------------------------------------------------------------------------------------------------void AssistedTargetingUpdate::xfer( Xfer *xfer ){// version- XferVersion currentVersion = 1;+ XferVersion currentVersion = 2;XferVersion version = currentVersion;xfer->xferVersion( &version, currentVersion );// extend base classUpdateModule::xfer( xfer );+ if( version >= 2 )+ xfer->xferObjectID( &m_assistVictimID );+} // end xfer// ------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cppindex e20c221ee..0c99b26cd 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp@@ -2302,6 +2302,28 @@ Bool Weapon::isWithinAttackRange(const Object *source, const Object *target) conreturn false;}+//-------------------------------------------------------------------------------------------------+Bool Weapon::isWithinAttackRangeFromFirePoint(const Object *source, const Object *victim, const Coord3D *victimPos) const+{+ // A garrisoned soldier shoots from the fire point closest to the target, but the point he already+ // stands on is not free, so the best-point test never offers it. Measured from the other points+ // alone, a Bunker soldier at his own point dropped a target he could hit, picked it up again and+ // never fired. Where he stands counts too.+ Bool fromHere = victim ? isWithinAttackRange( source, victim ) : isWithinAttackRange( source, victimPos );+ if( fromHere )+ return TRUE;++ const Object *containedBy = source->getContainedBy();+ ContainModuleInterface *contain = containedBy ? containedBy->getContain() : NULL;+ if( !contain || !contain->isGarrisonable() || !contain->isEnclosingContainerFor( source ) )+ return FALSE;++ Coord3D targetPos = *victimPos;+ Coord3D goalPos;+ return contain->calcBestGarrisonPosition( &goalPos, &targetPos )+ && isSourceObjectWithGoalPositionWithinAttackRange( source, &goalPos, victim, &targetPos );+}+//-------------------------------------------------------------------------------------------------Bool Weapon::isTooClose(const Object *source, const Object *target) const{@@ -2983,7 +3005,7 @@ static void makeAssistanceRequest( Object *requestOf, void *userData )return;// and say yes- if( !assistModule->isFreeToAssist() )+ if( !assistModule->isFreeToAssist( requestData->m_victimObject ) )return;assistModule->assistAttack( requestData->m_requestingObject, requestData->m_victimObject );diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/WeaponSet.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/WeaponSet.cppindex 0af994b83..afe7e0efd 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/WeaponSet.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/WeaponSet.cpp@@ -373,7 +373,7 @@ void WeaponSet::updateWeaponSet(const Object* obj)}//--------------------------------------------------------------------------------------------------static Int getVictimAntiMask(const Object* victim)+Int WeaponSet::getVictimAntiMask(const Object* victim){if( victim->isKindOf( KINDOF_SMALL_MISSILE ) ){@@ -667,27 +667,12 @@ CanAttackResult WeaponSet::getAbleToUseWeaponAgainstTarget( AbleToAttackType attif ( weaponToTestForRange ){hasAWeapon = TRUE;- if ((m_totalAntiMask & targetAntiMask) == 0)//we don't care to check for this weapon+ // this weapon's own mask, not every weapon's together: with the combined mask, a Gattling Cannon's+ // 400-range anti-air gun counted a tank at 300 as in range of the 225-range ground gun+ if ((weaponToTestForRange->getAntiMask() & targetAntiMask) == 0)continue;- Bool handled = FALSE;- ContainModuleInterface *contain = containedBy ? containedBy->getContain() : NULL;- if( contain && contain->isGarrisonable() && contain->isEnclosingContainerFor( source ))- { // non enclosing garrison containers do not use firepoints. Lorenzen, 6/11/03- //For contained things, we need to fake-move objects to the best garrison point in order- //to get precise range checks.- Coord3D targetPos = *pos;- Coord3D goalPos;- if( contain->calcBestGarrisonPosition( &goalPos, &targetPos) )- {- withinAttackRange = weaponToTestForRange->isSourceObjectWithGoalPositionWithinAttackRange( source, &goalPos, victim, &targetPos );- handled = TRUE;- }- }- else if( victim )- withinAttackRange = weaponToTestForRange->isWithinAttackRange( source, victim );- else- withinAttackRange = weaponToTestForRange->isWithinAttackRange( source, pos );+ withinAttackRange = weaponToTestForRange->isWithinAttackRangeFromFirePoint( source, victim, pos );if( withinAttackRange ){hasAWeaponInRange = TRUE;