Skip to content

Commit 7cfe37d

Browse files
committed
Torpedo Mechanics Integration
1 parent 83875fd commit 7cfe37d

File tree

9 files changed

+60
-8
lines changed

9 files changed

+60
-8
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ class DumbProjectileBehavior : public UpdateModule, public ProjectileUpdateInter
103103
virtual Bool projectileShouldCollideWithWater() const override;
104104
virtual Bool projectileShouldDetonateOnGround() const { return false; }
105105
virtual void setShrapnelLaunchID(ObjectID shrapnelLaunchID) { m_shrapnelLaunchID = shrapnelLaunchID; }
106+
virtual void friend_refreshUpdate() { refreshUpdate(); }
107+
108+
virtual void refreshUpdate() { setWakeFrame(getObject(), UPDATE_SLEEP_NONE); }
106109

107110
protected:
108111

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ class FreeFallProjectileBehavior : public UpdateModule, public ProjectileUpdateI
106106
virtual bool projectileShouldCollideWithWater() const override;
107107
virtual Bool projectileShouldDetonateOnGround() const { return getFreeFallProjectileBehaviorModuleData()->m_detonateOnGround; }
108108
virtual void setShrapnelLaunchID(ObjectID shrapnelLaunchID) { m_shrapnelLaunchID = shrapnelLaunchID; }
109+
virtual void friend_refreshUpdate() { refreshUpdate(); }
110+
111+
virtual void refreshUpdate() { setWakeFrame(getObject(), UPDATE_SLEEP_NONE); }
109112

110113
protected:
111114

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ class MissileAIUpdate : public AIUpdateInterface, public ProjectileUpdateInterfa
121121
virtual bool projectileShouldCollideWithWater() const override;
122122
virtual Bool projectileShouldDetonateOnGround() const { return false; }
123123
virtual void setShrapnelLaunchID(ObjectID shrapnelLaunchID) { m_shrapnelLaunchID = shrapnelLaunchID; }
124+
virtual void friend_refreshUpdate() { refreshUpdate(); }
125+
126+
virtual void refreshUpdate() { setWakeFrame(getObject(), UPDATE_SLEEP_NONE); }
124127

125128
virtual Bool processCollision(PhysicsBehavior *physics, Object *other); ///< Returns true if the physics collide should apply the force. Normally not. jba.
126129

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ class NeutronMissileUpdate : public UpdateModule,
111111
virtual const Coord3D* getTargetPosition();
112112
virtual Bool projectileShouldDetonateOnGround() const { return TRUE; } // Yes, we should detonate on ground if we are aiming at a moving object
113113
virtual void setShrapnelLaunchID(ObjectID shrapnelLaunchID) {}
114+
virtual void friend_refreshUpdate() { refreshUpdate(); }
115+
116+
virtual void refreshUpdate() { setWakeFrame(getObject(), UPDATE_SLEEP_NONE); }
114117

115118
virtual UpdateSleepTime update();
116119
virtual void onDelete( void );

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ class ProjectileUpdateInterface
280280
virtual void setShrapnelLaunchID(ObjectID shrapnelLaunchID) = 0;
281281
virtual Bool projectileShouldDetonateOnGround() const = 0;
282282
virtual Bool projectileShouldCollideWithWater() const { return false; };
283+
virtual void friend_refreshUpdate() = 0;
283284

284285
virtual Object* getTargetObject() = 0;
285286
virtual const Coord3D* getTargetPosition() = 0;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,7 @@ class Object : public Thing, public Snapshot
850850
void doObjectLocomotorUpdate();
851851
void doSlowDeathLayerUpdate(Bool hitTree);
852852
void doSlowDeathRefreshUpdate();
853+
void doOverWaterUpdate();
853854

854855
void setIsMobMember(Bool set) { m_isMobMember = set; }
855856
void setMobUpdateRefreshed(Bool set) { m_mobJustUpdated = set; }

GeneralsMD/Code/GameEngine/Source/Common/Thing/Thing.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,15 @@ Real Thing::getHeightAboveTerrainOrWater() const
343343
Real waterZ;
344344
if (TheTerrainLogic->isUnderwater(pos->x, pos->y, &waterZ))
345345
{
346+
if(!m_cachedIsOverWater && AsObject(this))
347+
AsObject(this)->doOverWaterUpdate();
346348
m_cachedAltitudeAboveTerrainOrWater = pos->z - waterZ;
347349
m_cachedIsOverWater = TRUE;
348350
}
349351
else
350352
{
353+
if(m_cachedIsOverWater && AsObject(this))
354+
AsObject(this)->doOverWaterUpdate();
351355
m_cachedAltitudeAboveTerrainOrWater = getHeightAboveTerrain();
352356
m_cachedIsOverWater = FALSE;
353357
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9292,6 +9292,24 @@ void Object::doSlowDeathLayerUpdate(Bool hitTree)
92929292
}
92939293
}
92949294

9295+
9296+
//-------------------------------------------------------------------------------------------------
9297+
void Object::doOverWaterUpdate()
9298+
{
9299+
// Currently only torpedos needs update checks
9300+
if(!isKindOf(KINDOF_PROJECTILE))
9301+
return;
9302+
9303+
for (BehaviorModule** m = m_behaviors; *m; ++m)
9304+
{
9305+
ProjectileUpdateInterface *pui = (*m)->getProjectileUpdateInterface();
9306+
if( pui )
9307+
{
9308+
pui->friend_refreshUpdate();
9309+
}
9310+
}
9311+
}
9312+
92959313
//-------------------------------------------------------------------------------------------------
92969314
Bool Object::isDozerDoingAnyTasks() const
92979315
{

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ UpdateSleepTime MissileAIUpdate::update()
10761076
}
10771077

10781078
// If torpedo, update target location
1079-
if (d->m_isTorpedo && m_isTrackingTarget) {
1079+
if (d->m_isTorpedo && m_isTrackingTarget && !m_isJammed) {
10801080
Object * targetUnit = TheGameLogic->findObjectByID(m_victimID);
10811081
if (targetUnit != nullptr && !targetUnit->isEffectivelyDead()) {
10821082
Coord3D targetPos = *targetUnit->getPosition();
@@ -1278,7 +1278,8 @@ void MissileAIUpdate::airborneTargetGone()
12781278
// by the Weapon that fired me. The safest thing for me to do in this state is to just run out of gas.
12791279

12801280
// IamInnocent - Added Missile retargeting if current target is gone
1281-
if(getMissileAIUpdateModuleData()->m_allowRetargeting)
1281+
const MissileAIUpdateModuleData* d = getMissileAIUpdateModuleData();
1282+
if(d->m_allowRetargeting)
12821283
{
12831284
Object *obj = getObject();
12841285
const Object *source = obj;
@@ -1303,7 +1304,7 @@ void MissileAIUpdate::airborneTargetGone()
13031304
filters[numFilters++] = &filterMapStatus;
13041305
filters[numFilters++] = &filterAlive;
13051306
filters[numFilters++] = &filterStealth;
1306-
if(!getMissileAIUpdateModuleData()->m_allowRetargetingThroughFog)
1307+
if(!d->m_allowRetargetingThroughFog)
13071308
filters[numFilters++] = &filterFogged;
13081309
filters[numFilters] = NULL;
13091310

@@ -1324,12 +1325,27 @@ void MissileAIUpdate::airborneTargetGone()
13241325
{
13251326
continue;
13261327
}
1327-
1328-
getStateMachine()->setGoalPosition(curVictim->getPosition());
1328+
1329+
Coord3D targetPos = *curVictim->getPosition();
1330+
if (d->m_isTorpedo) {
1331+
Locomotor* curLoco = getCurLocomotor();
1332+
if (curLoco)
1333+
{
1334+
targetPos.z = getTorpedoTargetHeight(targetPos, curLoco);
1335+
}
1336+
}
1337+
1338+
getStateMachine()->setGoalPosition(&targetPos);
13291339
getStateMachine()->setGoalObject(curVictim);
1330-
aiMoveToObject(curVictim, CMD_FROM_AI );
1331-
m_originalTargetPos = *curVictim->getPosition();
1332-
m_isTrackingTarget = TRUE;
1340+
if (!d->m_isTorpedo) {
1341+
aiMoveToObject(curVictim, CMD_FROM_AI);
1342+
}
1343+
else {
1344+
aiMoveToPosition(&targetPos, CMD_FROM_AI);
1345+
}
1346+
m_originalTargetPos = targetPos;
1347+
m_isTrackingTarget = TRUE;// Remember that I was originally shot at a moving object, so if the
1348+
// target dies I can do something cool.
13331349
m_victimID = curVictim->getID();
13341350

13351351
return;

0 commit comments

Comments
 (0)