Skip to content

Commit 3575a82

Browse files
committed
fix turning in place behavior
1 parent 3a56ab0 commit 3575a82

3 files changed

Lines changed: 42 additions & 1 deletion

File tree

GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ class Locomotor : public MemoryPoolObject, public Snapshot
264264

265265
AsciiString getTemplateName() const { return m_template->m_name;}
266266
Real getMinSpeed() const { return m_template->m_minSpeed;}
267+
Real getMinTurnSpeed() const { return m_template->m_minTurnSpeed;} ///< must be going >= this speed to turn (0 = can turn in place)
267268
Real getAccelPitchLimit() const { return m_template->m_accelPitchLimit;} ///< Maximum amount we will pitch up or down under acceleration (including recoil.)
268269
Real getDecelPitchLimit() const { return m_template->m_decelPitchLimit;} ///< Maximum amount we will pitch down under deceleration (including recoil.)
269270
Real getBounceKick() const { return m_template->m_bounceKick;} ///< How much simulating rough terrain "bounces" a wheel up.

GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SpecialAbilityUpdate.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class SpecialAbilityUpdateModuleData : public UpdateModuleData
7676
Bool m_approachRequiresLOS;
7777
Bool m_needToFaceTarget;
7878
Bool m_persistenceRequiresRecharge;
79+
Real m_facingAngleTolerance; ///< heading delta (radians) considered "facing target" for locomotors that can't turn in place
7980

8081
const ParticleSystemTemplate *m_disableFXParticleSystem;
8182
AudioEventRTS m_packSound;
@@ -113,6 +114,7 @@ class SpecialAbilityUpdateModuleData : public UpdateModuleData
113114
m_preTriggerUnstealthFrames = 0;
114115
m_needToFaceTarget = TRUE;
115116
m_persistenceRequiresRecharge = FALSE;
117+
m_facingAngleTolerance = 0.1f; // ~5.7 degrees
116118
}
117119

118120
static void buildFieldParse(MultiIniFieldParse& p)
@@ -159,6 +161,7 @@ class SpecialAbilityUpdateModuleData : public UpdateModuleData
159161
{ "ApproachRequiresLOS", INI::parseBool, nullptr, offsetof( SpecialAbilityUpdateModuleData, m_approachRequiresLOS ) },
160162
{ "NeedToFaceTarget", INI::parseBool, nullptr, offsetof( SpecialAbilityUpdateModuleData, m_needToFaceTarget ) },
161163
{ "PersistenceRequiresRecharge",INI::parseBool, nullptr, offsetof( SpecialAbilityUpdateModuleData, m_persistenceRequiresRecharge ) },
164+
{ "FacingAngleTolerance", INI::parseAngleReal, nullptr, offsetof( SpecialAbilityUpdateModuleData, m_facingAngleTolerance ) },
162165
{ 0, 0, 0, 0 }
163166
};
164167
p.add(dataFieldParse);

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpecialAbilityUpdate.cpp

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050

5151
#include "GameLogic/AIPathfind.h"
5252
#include "GameLogic/GameLogic.h"
53+
#include "GameLogic/Locomotor.h"
5354
#include "GameLogic/Object.h"
5455
#include "GameLogic/PartitionManager.h"
5556
#include "GameLogic/Weapon.h"
@@ -1903,6 +1904,23 @@ Bool SpecialAbilityUpdate::isFacing()
19031904
{
19041905
if( !m_facingComplete && m_facingInitiated)
19051906
{
1907+
Locomotor *loco = ai->getCurLocomotor();
1908+
if( loco && loco->getMinTurnSpeed() > 0.0f )
1909+
{
1910+
//This locomotor can't turn in place (e.g. wings); we're moving toward the
1911+
//target to turn. Consider facing complete once our heading is within tolerance.
1912+
const SpecialAbilityUpdateModuleData* data = getSpecialAbilityUpdateModuleData();
1913+
Real relAngle = ThePartitionManager->getRelativeAngle2D( getObject(), &m_targetPos );
1914+
if( fabs( relAngle ) <= data->m_facingAngleTolerance )
1915+
{
1916+
m_facingComplete = true;
1917+
ai->aiIdle( CMD_FROM_AI ); //stop the short move; ready to launch
1918+
return false;
1919+
}
1920+
//Still turning (while moving).
1921+
return true;
1922+
}
1923+
19061924
if( ai->isIdle() )
19071925
{
19081926
//We finished facing the target
@@ -1969,7 +1987,26 @@ void SpecialAbilityUpdate::startFacing()
19691987
}
19701988
else if( m_targetPos.x || m_targetPos.y || m_targetPos.z ) //It's zero if not used...
19711989
{
1972-
ai->aiFacePosition( &m_targetPos, CMD_FROM_AI );
1990+
Locomotor *loco = ai->getCurLocomotor();
1991+
if( loco && loco->getMinTurnSpeed() > 0.0f )
1992+
{
1993+
//This locomotor can't turn in place (e.g. wings); facing in place does nothing.
1994+
const SpecialAbilityUpdateModuleData* data = getSpecialAbilityUpdateModuleData();
1995+
if( fabs( ThePartitionManager->getRelativeAngle2D( getObject(), &m_targetPos ) ) <= data->m_facingAngleTolerance )
1996+
{
1997+
//Already pointed at the target -- no need to move.
1998+
m_facingComplete = true;
1999+
}
2000+
else
2001+
{
2002+
//Move toward the target so the locomotor turns us; isFacing() stops us once aligned.
2003+
ai->aiMoveToPosition( &m_targetPos, CMD_FROM_AI );
2004+
}
2005+
}
2006+
else
2007+
{
2008+
ai->aiFacePosition( &m_targetPos, CMD_FROM_AI );
2009+
}
19732010
}
19742011
}
19752012

0 commit comments

Comments
 (0)