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(gamelogic): airfield takeoff, thrown-out infantry crash, bus damage

Olcay Seygane4cfff68a44b
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp
index bf59b6fe4..fa55217f7 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp
@@ -3913,6 +3913,12 @@ void AIGroup::setMineClearingDetail( Bool set )
Bool AIGroup::setWeaponLockForGroup( WeaponSlotType weaponSlot, WeaponLockType lockType )
{
+ // The slot comes from a player's command (MSG_DO_WEAPON*, MSG_SWITCH_WEAPONS), and every member
+ // indexes its weapon array with it. Out of range is a doctored command, refused the same way on
+ // every machine since it is the command, not local state, that decides.
+ if( weaponSlot < PRIMARY_WEAPON || weaponSlot >= WEAPONSLOT_COUNT )
+ return false;
+
Bool any = false;
std::list<Object *>::iterator i;
for( i = m_memberList.begin(); i != m_memberList.end(); ++i )
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
index 0d52f7499..984bdb516 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
@@ -906,8 +906,12 @@ StateReturnType AIStateMachine::updateStateMachine()
return status;
}
- m_temporaryState->onExit(EXIT_NORMAL);
- m_temporaryState = NULL;
+ // the state's own update can clear() the machine, which already exited and dropped it
+ if (m_temporaryState)
+ {
+ m_temporaryState->onExit(EXIT_NORMAL);
+ m_temporaryState = NULL;
+ }
}
StateReturnType retType = StateMachine::updateStateMachine();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Body/UndeadBody.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Body/UndeadBody.cpp
index 2590a0722..d042d4c8a 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Body/UndeadBody.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Body/UndeadBody.cpp
@@ -105,17 +105,18 @@ void UndeadBody::attemptDamage( DamageInfo *damageInfo )
/* Whether this hit is lethal has to be asked of the damage that will actually land, not of the
number the weapon carries. Armour, damage type multipliers and the veterancy bonus all sit
between the two, so a Battle Bus took its second life off shots that its armour would have
- shrugged off, and survived ones that were going to kill it. */
+ shrugged off, and survived ones that were going to kill it. The damage scalar belongs in the
+ test too: under Hold the Line a bus gave up its first life to a hit it would have survived. */
+ const Real landed = estimateDamage( damageInfo->in ) * getDamageScalar();
if( damageInfo->in.m_damageType != DAMAGE_UNRESISTABLE
&& !m_isSecondLife
- && estimateDamage( damageInfo->in ) >= getHealth()
+ && landed >= getHealth()
&& IsHealthDamagingDamage(damageInfo->in.m_damageType)
&& isSecondLifeDeath( getObject(), damageInfo )
)
{
// clamp what lands, for the same reason as the test above: armour applied after a raw clamp
// to health-1 still killed, ran the die modules, and then revived the bus anyway
- Real landed = estimateDamage( damageInfo->in ) * getDamageScalar();
if( landed > getHealth() - 1 && landed > 0.0f )
damageInfo->in.m_amount *= ( getHealth() - 1 ) / landed;
shouldStartSecondLife = TRUE;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
index 26b40c675..72d89ffb5 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
@@ -6734,6 +6734,8 @@ Bool Object::canProduceUpgrade( const UpgradeTemplate *upgrade )
{
// We need to have the button to make the upgrade. CommandSets are a weird Logic/Client hybrid.
const CommandSet *set = TheControlBar->findCommandSet(getCommandSetString());
+ if( set == NULL )
+ return FALSE; // a Supply Drop Zone, a GLA hole or a captured Oil Derrick has no command set
for( Int buttonIndex = 0; buttonIndex < MAX_COMMANDS_PER_SET; buttonIndex++ )
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/ChinookAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/ChinookAIUpdate.cpp
index 4ce94face..be032c080 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/ChinookAIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/ChinookAIUpdate.cpp
@@ -1071,9 +1071,14 @@ Bool ChinookAIUpdate::chooseLocomotorSet(LocomotorSetType wst)
UpdateSleepTime ChinookAIUpdate::update()
{
ParkingPlaceBehaviorInterface* pp = getPP(m_airfieldForHealing);
+ ContainModuleInterface* contain = getObject()->getContain();
+ const Bool waitingToEnterOrExit = contain && contain->hasObjectsWantingToEnterOrExit();
if (pp != NULL)
{
- if (m_flightStatus == CHINOOK_LANDED &&
+ // Healed on the pad with infantry still walking up to board or waiting to get off: stay down
+ // for them, or it lifts off and the boarders stand under it and the leavers stay aboard.
+ if (m_flightStatus == CHINOOK_LANDED &&
+ !waitingToEnterOrExit &&
!m_hasPendingCommand &&
getObject()->getBodyModule()->getHealth() == getObject()->getBodyModule()->getMaxHealth())
{
@@ -1115,12 +1120,10 @@ UpdateSleepTime ChinookAIUpdate::update()
// have to call our parent's isIdle, because we override it to never return true
// when we have a pending command...
- ContainModuleInterface* contain = getObject()->getContain();
if( contain )
{
if (SupplyTruckAIUpdate::isIdle())
{
- Bool waitingToEnterOrExit = contain->hasObjectsWantingToEnterOrExit();
if (m_hasPendingCommand)
{
AICommandParms parms(AICMD_MOVE_TO_POSITION, CMD_FROM_AI); // values don't matter, will be wiped by next line