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.

feat(gameengine): shots spread over the target, missiles ease and weave

Olcay Seygan22838d056061
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d0dcb50d4..2eae19e8e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -752,6 +752,9 @@ found and fixed — EA's own, not port damage.**
- A nuclear missile hurts the whole of a big building. The blast measured to the middle of everything near it, so an airfield whose centre sat just outside the outer ring took nothing while half of it stood in the fire. Distance is now taken halfway between the nearest edge and the centre.
- Rockets curve into their target instead of snapping onto it. In the last few frames before impact a guided missile swung its nose straight at the target in one step, up to 40 degrees in a single frame, when the whole flight before that never turned more than 5. It now flies an arc from the heading it had to the spot where it meets the target, so a tank driving across its path is led rather than chased. In the same test battle no rocket turns more than 8 degrees in a frame, and all 101 land. Rockets fired at aircraft still fly straight at them: a helicopter is nearly as fast as the rocket, and on an arc the rocket flew past it and climbed away into the sky. A rocket whose target is behind it flies straight at it too. The arc to something behind the nose loops out past it, and when the target is on the ground under a helicopter the bottom of that loop is in the dirt: a Comanche hovering over a supply truck put all four missiles into the ground 23 to 47 away from it, while the same Comanche 250 away landed all four. Now the truck is down to 16 health of 300 five seconds in, where it had 136. Rockets fired at driving tanks and at aircraft land exactly where they did before. A rocket fired at a soldier on the move now goes where he will be when it gets there. Rockets at infantry fly at a spot on the ground rather than at the man, and a soldier walking across the line of fire had left that spot before the rocket came down. A Stinger Site shooting at twelve Rangers walking past it killed three in each of six matches where it used to kill one, and took 627 health off the squad where it took 447. A rocket at someone standing still lands where it always did. A replay recorded before this change, with rockets fired at moving infantry, will not play back the same.
- Scuds come down from the top of their climb in a smooth curve, level at the top and steepest at the end, instead of tipping into a straight dive 200 short of the target. Over those last 200 a Scud now stays within 14 of that curve where the dive strayed by up to 49, and every one lands on the spot it was fired at; one in the old test came down 22 away.
+- Scuds and Tomahawks roll over the top of their climb instead of kinking. A missile climbs straight for a set distance and then turns towards its target, and it used to start that turn at full rate in a single frame: a Scud went from flying straight to 2.2 degrees a frame, and a Tomahawk's nose jumped 2 degrees at once. The turn now comes in over the next 40 units of flight, never more than 0.3 degrees a frame harder than the frame before for a Scud and 0.6 for a Tomahawk. They land where they did and take about a tenth of a second longer to get there.
+- Shots hit the whole of a target, not one spot on it. Every rocket, shell and bullet fired at a tank or a building aimed at the same point, its foot or its middle, so a salvo of Tomahawks went into one hole and every tracer met the target at the same place. Each shot now picks its own point somewhere on the target's body, and a small target spreads them over a small body. A shot that hit before still hits; only where it lands moves.
+- Missiles weave a little in flight, a few degrees either side and each on its own beat, so a salvo no longer flies in perfect step. The weave fades out as a missile closes in, and it lands where it would have without it. Missiles at aircraft fly the straight chase as before.
- Cancelling an order of Red Guard after the first soldier has walked out no longer refunds the order. One order is two soldiers for one price, and the refund came back whole, so the first one was free.
- Double-clicking to grab everything of a kind grabs what a box would, not things you can only click one at a time.
- A bounty pays what the percentage says. Rounding up a fraction that was already a whole number paid a dollar extra on every kill.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h
index 065bbde2d..74d4b8d12 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h
@@ -391,6 +391,13 @@ public:
*/
inline void setDiveDistance(Real dist) { m_diveDistance = dist; }
+ /**
+ a projectile flies to its goal moved by this much: the shot's point on its victim and a missile's
+ sway. MissileAIUpdate sets it every frame before the missile moves and the move spends it, so it
+ is not saved.
+ */
+ inline void setChaseOffset(const Coord3D& offset) { m_chaseOffset = offset; }
+
/**
when off (the default), units slow down as they approach their target.
@@ -526,6 +533,7 @@ private:
Real m_preferredHeight;
Real m_preferredHeightDamping;
Real m_diveDistance; ///< see setDiveDistance
+ Coord3D m_chaseOffset; ///< see setChaseOffset
Real m_angleOffset;
Real m_offsetIncrement;
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/DumbProjectileBehavior.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/DumbProjectileBehavior.h
index c0e3db213..53e9f8bcc 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/DumbProjectileBehavior.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/DumbProjectileBehavior.h
@@ -114,6 +114,7 @@ private:
VecCoord3D m_flightPath; ///< The frame by frame flight path in a Bezier curve
Coord3D m_flightPathStart; ///< where flight path started (in case we must regen it)
Coord3D m_flightPathEnd; ///< where flight path ends (in case we must regen it)
+ Coord3D m_aimOffset; ///< the shot's point on the victim, in the victim's frame (Weapon::bodyOffsetFromPoint)
Real m_flightPathSpeed; ///< flight path speed (in case we must regen it)
Real m_launchSlope; ///< rise over run of the barrel at launch, 0 for a level or lowered barrel
Int m_flightPathSegments; ///< number of segments in the flightpath (in case we must regen it)
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/MissileAIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/MissileAIUpdate.h
index e7196ae20..4ec814f5d 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/MissileAIUpdate.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/MissileAIUpdate.h
@@ -121,10 +121,13 @@ private:
ObjectID m_launcherID; ///< ID of object that launched us (INVALID_ID if not yet launched)
ObjectID m_victimID; ///< ID of object that I am rocketing towards (INVALID_ID if not yet launched)
UnsignedInt m_fuelExpirationDate; ///< how long 'til we run out of fuel
- Real m_noTurnDistLeft; ///< when zero, ok to start turning
+ Real m_noTurnDistLeft; ///< when zero, ok to start turning; below zero while the turn eases in
Real m_maxAccel;
Coord3D m_originalTargetPos; ///< When firing uphill, we aim high to clear the brow of the hill. jba.
Coord3D m_prevPos;
+ Coord3D m_aimOffset; ///< the shot's point on the victim, in the victim's frame (Weapon::bodyOffsetFromPoint)
+
+ void updateChaseOffset();
WeaponBonusConditionFlags m_extraBonusFlags;
const WeaponTemplate* m_detonationWeaponTmpl; ///< weapon to fire at end (or null)
const ParticleSystemTemplate* m_exhaustSysTmpl;
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Weapon.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Weapon.h
index 6ed1aaa4e..dc133ead4 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Weapon.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Weapon.h
@@ -762,6 +762,12 @@ public:
Int specificBarrelToUse
);
+ /// a random point on the object's body, from the logic stream: where a shot at the object aims
+ static void randomPointOnBody(const Object* victim, Coord3D& point);
+ /// a point as an offset in the object's own frame, and back, so the point turns with the object
+ static void bodyOffsetFromPoint(const Object* victim, const Coord3D& point, Coord3D& offset);
+ static void pointFromBodyOffset(const Object* victim, const Coord3D& offset, Coord3D& point);
+
/**
special purpose call for jets in airfields: directly set the ammoinclip to a certain
percentage full (note that percent=1.0 is full, NOT percent=100.0!). this will end up
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp
index 5e1ef473a..9c690a503 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp
@@ -128,6 +128,7 @@ DumbProjectileBehavior::DumbProjectileBehavior( Thing *thing, const ModuleData*
m_launchSlope = 0;
m_flightPathStart.zero();
m_flightPathEnd.zero();
+ m_aimOffset.zero();
m_currentFlightPathStep = 0;
m_extraBonusFlags = 0;
@@ -368,12 +369,17 @@ void DumbProjectileBehavior::projectileFireAtObjectOrPosition( const Object *vic
Real weaponSpeed = detWeap ? detWeap->getWeaponSpeed() : 0.0f;
Real minWeaponSpeed = detWeap ? detWeap->getMinWeaponSpeed() : 0.0f;
- // if an object, aim at the center, not the ground part
- Coord3D victimPosToUse;
+ // At an object, the weapon has picked the shot's point on its body (Weapon::randomPointOnBody) and
+ // the shell flies there. A bridge's attack point is not on it, so a shell at a bridge aims at its
+ // center, not the ground part.
+ Coord3D victimPosToUse = *victimPos;
+ m_aimOffset.zero();
if (victim)
- victim->getGeometryInfo().getCenterPosition(*victim->getPosition(), victimPosToUse);
- else
- victimPosToUse = *victimPos;
+ {
+ if (victim->isKindOf(KINDOF_BRIDGE))
+ victim->getGeometryInfo().getCenterPosition(*victim->getPosition(), victimPosToUse);
+ Weapon::bodyOffsetFromPoint(victim, victimPosToUse, m_aimOffset);
+ }
if( detWeap && detWeap->isScaleWeaponSpeed() )
{
@@ -668,7 +674,7 @@ UpdateSleepTime DumbProjectileBehavior::update()
if (victim)
{
Coord3D newVictimPos;
- victim->getGeometryInfo().getCenterPosition(*victim->getPosition(), newVictimPos);
+ Weapon::pointFromBodyOffset(victim, m_aimOffset, newVictimPos);
Coord3D delta;
delta.x = newVictimPos.x - m_flightPathEnd.x;
delta.y = newVictimPos.y - m_flightPathEnd.y;
@@ -805,7 +811,8 @@ void DumbProjectileBehavior::xfer( Xfer *xfer )
// without veterancy or horde bonus, and the detonated flag, so a DetonateCallsKill shell cannot
// go off a second time
// version 4 adds the barrel's slope at launch, which a lobbed shell's path starts along
- XferVersion currentVersion = 4;
+ // version 5 adds the shot's point on its victim, which a shell following the victim keeps to
+ XferVersion currentVersion = 5;
XferVersion version = currentVersion;
xfer->xferVersion( &version, currentVersion );
@@ -868,6 +875,9 @@ void DumbProjectileBehavior::xfer( Xfer *xfer )
if( version >= 4 )
xfer->xferReal( &m_launchSlope );
+ if( version >= 5 )
+ xfer->xferCoord3D( &m_aimOffset );
+
// the path itself is a vector of points that is not saved; rebuild it from the start, end and
// segment count that are, so the step we just read means something
if( xfer->getXferMode() == XFER_LOAD && m_flightPathSegments > 0 )
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp
index 0002093a8..6d8a339fc 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp
@@ -823,6 +823,7 @@ Locomotor::Locomotor(const LocomotorTemplate* tmpl)
m_preferredHeight = m_template->m_preferredHeight;
m_preferredHeightDamping = m_template->m_preferredHeightDamping;
m_diveDistance = 0.0f;
+ m_chaseOffset.zero();
m_angleOffset = GameLogicRandomValueReal(-PI/6, PI/6);
m_offsetIncrement = (PI/40) * (GameLogicRandomValueReal(0.8f, 1.2f)/m_template->m_wanderLengthFactor);
@@ -860,6 +861,7 @@ Locomotor::Locomotor(const Locomotor& that)
m_preferredHeight = that.m_preferredHeight;
m_preferredHeightDamping = that.m_preferredHeightDamping;
m_diveDistance = that.m_diveDistance;
+ m_chaseOffset = that.m_chaseOffset;
m_angleOffset = that.m_angleOffset;
m_offsetIncrement = that.m_offsetIncrement;
m_yawRate = that.m_yawRate;
@@ -889,6 +891,7 @@ Locomotor& Locomotor::operator=(const Locomotor& that)
m_preferredHeight = that.m_preferredHeight;
m_preferredHeightDamping = that.m_preferredHeightDamping;
m_diveDistance = that.m_diveDistance;
+ m_chaseOffset = that.m_chaseOffset;
m_yawRate = that.m_yawRate;
m_driveAccelX = that.m_driveAccelX;
m_driveAccelY = that.m_driveAccelY;
@@ -1205,10 +1208,15 @@ Real Locomotor::calcWheelTurnRadius(const Object* obj) const
}
//-------------------------------------------------------------------------------------------------
-void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalPos,
+void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& chasedPos,
Real onPathDistToGoal, Real desiredSpeed, Bool *blocked,
const Coord3D *faceTarget, Bool fighting, Real bendDist, Real bendCos)
{
+ // spent by this move, so a locomotor the set switches away from carries none into a later one
+ Coord3D goalPos = chasedPos;
+ goalPos.add(&m_chaseOffset);
+ m_chaseOffset.zero();
+
setFlag(MAINTAIN_POS_IS_VALID, false);
BodyDamageType bdt = obj->getBodyModule()->getDamageState();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp
index e531aa861..52060be31 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp
@@ -53,6 +53,16 @@
const Real BIGNUM = 99999.0f;
+// How far past DistanceToTravelBeforeTurning a missile goes while its turn eases in: half the climb,
+// and no more than this. A missile that climbs a few units before turning barely eases at all.
+const Real MAX_TURN_EASE_DIST = 40.0f;
+
+static Real turnEaseDistance(const MissileAIUpdateModuleData* d)
+{
+ Real dist = d->m_initialDist * 0.5f;
+ return dist < MAX_TURN_EASE_DIST ? dist : MAX_TURN_EASE_DIST;
+}
+
#ifdef _INTERNAL
// for occasional debugging...
//#pragma optimize("", off)
@@ -132,6 +142,7 @@ MissileAIUpdate::MissileAIUpdate( Thing *thing, const ModuleData* moduleData ) :
m_fuelExpirationDate = 0;
m_noTurnDistLeft = d->m_initialDist;
m_prevPos = *getObject()->getPosition();
+ m_aimOffset.zero();
m_maxAccel = BIGNUM;
m_detonationWeaponTmpl = NULL;
m_exhaustSysTmpl = NULL;
@@ -288,9 +299,12 @@ void MissileAIUpdate::projectileFireAtObjectOrPosition( const Object *victim, co
// ick. const-cast is evil. fix. (srj)
aiMoveToObject(const_cast<Object*>(victim), CMD_FROM_AI );
m_originalTargetPos = *victim->getPosition();
- m_isTrackingTarget = TRUE;// Remember that I was originally shot at a moving object, so if the
+ m_isTrackingTarget = TRUE;// Remember that I was originally shot at a moving object, so if the
// target dies I can do something cool.
m_victimID = victim->getID();
+ // the weapon's point on the victim (Weapon::randomPointOnBody); a bridge's attack point is not on it
+ if (!victim->isKindOf(KINDOF_BRIDGE))
+ Weapon::bodyOffsetFromPoint(victim, *victimPos, m_aimOffset);
}
else
{
@@ -574,6 +588,23 @@ void MissileAIUpdate::doAttackState(Bool turnOK)
{
curLoco->setMaxAcceleration(m_maxAccel);
curLoco->setMaxTurnRate(turnOK ? BIGNUM : 0);
+ // The turn after the no-turn climb comes in over a short distance. A missile turns by
+ // thrusting across its velocity, so its turn per frame is in proportion to its acceleration,
+ // and its top speed does not move with it. The nose, which the climb held still while the
+ // flight drifted a degree or two off it, comes round with the turn rate. Given both whole
+ // the frame the climb ended, a Scud went from flying straight to 2.2 degrees a frame and a
+ // Tomahawk's nose jumped 2 degrees at once.
+ const Real easeDist = turnEaseDistance(d);
+ if (turnOK && easeDist > 0.0f && -m_noTurnDistLeft < easeDist)
+ {
+ Real s = -m_noTurnDistLeft / easeDist;
+ if (s < 0.0f)
+ s = 0.0f;
+ s = s * s * (3.0f - 2.0f * s);
+ BodyDamageType damage = getObject()->getBodyModule()->getDamageState();
+ curLoco->setMaxAcceleration(curLoco->getMaxAcceleration(damage) * s);
+ curLoco->setMaxTurnRate(curLoco->getMaxTurnRate(damage) * s);
+ }
}
}
@@ -649,6 +680,25 @@ void MissileAIUpdate::doKillState(void)
curLoco->setMaxAcceleration(m_maxAccel);
curLoco->setMaxTurnRate(BIGNUM);
}
+ // At its point on the victim the missile goes off. The move it was given is to the victim's own
+ // position, its foot, which a point up on the body never reaches, so it would never go idle, and
+ // it came to rest there touching nothing: Rocket Buggies at supply trucks hung over a third of
+ // their rockets on the trucks' roofs.
+ if (getGoalObject() != NULL)
+ {
+ Coord3D aim;
+ Weapon::pointFromBodyOffset(getGoalObject(), m_aimOffset, aim);
+ Real closeEnough = curLoco->getMaxSpeedForCondition(BODY_PRISTINE);
+ const Coord3D* pos = obj->getPosition();
+ // over the point and on the body: the height the locomotor holds over a goal is its own
+ if (sqr(aim.x - pos->x) + sqr(aim.y - pos->y) < sqr(closeEnough)
+ && ThePartitionManager->getDistanceSquared(obj, getGoalObject(), FROM_BOUNDINGSPHERE_3D) < sqr(closeEnough))
+ {
+ obj->setPosition(&aim);
+ detonate();
+ return;
+ }
+ }
if (isIdle()) {
// we finished the move
if (getGoalObject()!=NULL) {
@@ -661,7 +711,8 @@ void MissileAIUpdate::doKillState(void)
Real distanceToTargetSq = ThePartitionManager->getDistanceSquared( getObject(), getGoalObject(), FROM_BOUNDINGSPHERE_3D);
//DEBUG_LOG(("Distance to target %f, closeEnough %f\n", sqrt(distanceToTargetSq), closeEnough));
if (distanceToTargetSq < closeEnough*closeEnough) {
- Coord3D pos = *getGoalObject()->getPosition();
+ Coord3D pos;
+ Weapon::pointFromBodyOffset(getGoalObject(), m_aimOffset, pos);
getObject()->setPosition(&pos);
detonate();
} else{
@@ -688,6 +739,58 @@ void MissileAIUpdate::doDeadState()
}
}
+//-------------------------------------------------------------------------------------------------
+// Where the locomotor steers this frame, as an offset from the goal: the shot's point on the victim,
+// turned with it, and a light sway. The sway swings the aim from side to side by a few degrees, so
+// its sideways offset grows with the distance to the goal; the missile's own turning smooths it into
+// a gentle weave about a unit or two wide. It fades in over half a second of the attack, so it never
+// kicks the turn off the climb, and out from SWAY_FADE_FAR to SWAY_FADE_NEAR of the goal, so the
+// end of the flight and the lock are the same as before. Each missile starts the swing at its own
+// point of it, so a salvo does not sway in step. A missile at an aircraft flies the straight chase.
+//-------------------------------------------------------------------------------------------------
+void MissileAIUpdate::updateChaseOffset()
+{
+ const Real SWAY_ANGLE = 0.08f; // radians of aim either side, between four and five degrees
+ const Real SWAY_PERIOD = 60.0f; // logic frames for one swing and back
+ const Real SWAY_FADE_IN = 30.0f; // logic frames from the start of the attack
+ const Real SWAY_FADE_FAR = 150.0f;
+ const Real SWAY_FADE_NEAR = 60.0f;
+
+ Coord3D offset;
+ offset.zero();
+ Object* victim = m_isTrackingTarget ? getGoalObject() : NULL;
+ Coord3D goal = victim ? *victim->getPosition() : *getGoalPosition();
+ if (victim)
+ {
+ Coord3D aim;
+ Weapon::pointFromBodyOffset(victim, m_aimOffset, aim);
+ offset.set(aim.x - goal.x, aim.y - goal.y, aim.z - goal.z);
+ }
+
+ if (m_state == ATTACK && !(victim && victim->isAboveTerrain()))
+ {
+ const Coord3D* pos = getObject()->getPosition();
+ Real dx = goal.x - pos->x;
+ Real dy = goal.y - pos->y;
+ Real dist = sqrtf(dx*dx + dy*dy);
+ Real fadeIn = (Real)(TheGameLogic->getFrame() - m_stateTimestamp) / SWAY_FADE_IN;
+ Real fadeOut = (dist - SWAY_FADE_NEAR) / (SWAY_FADE_FAR - SWAY_FADE_NEAR);
+ Real fade = clamp(0.0f, fadeIn, 1.0f) * clamp(0.0f, fadeOut, 1.0f);
+ if (fade > 0.0f)
+ {
+ fade = fade * fade * (3.0f - 2.0f * fade);
+ // in turns, the golden angle apart from one object ID to the next
+ Real turns = (Real)(TheGameLogic->getFrame() % (UnsignedInt)SWAY_PERIOD) / SWAY_PERIOD + 0.381966f * (Real)(getObject()->getID() % 1024);
+ turns -= floorf(turns);
+ Real side = SWAY_ANGLE * fade * Sin(2.0f * PI * turns);
+ offset.x -= dy * side;
+ offset.y += dx * side;
+ }
+ }
+
+ getCurLocomotor()->setChaseOffset(offset);
+}
+
//-------------------------------------------------------------------------------------------------
/**
* Simulate one frame of a missile's behavior
@@ -695,7 +798,8 @@ void MissileAIUpdate::doDeadState()
UpdateSleepTime MissileAIUpdate::update()
{
Coord3D newPos = *getObject()->getPosition();
- if (m_noTurnDistLeft > 0.0f && m_state >= IGNITION)
+ // counted on past the climb, below zero, while the turn eases in
+ if (m_noTurnDistLeft > -turnEaseDistance(getMissileAIUpdateModuleData()) && m_state >= IGNITION)
{
Real distThisTurn = sqrtf(sqr(newPos.x-m_prevPos.x) + sqr(newPos.y-m_prevPos.y) + sqr(newPos.z-m_prevPos.z));
m_noTurnDistLeft -= distThisTurn;
@@ -720,9 +824,10 @@ UpdateSleepTime MissileAIUpdate::update()
// ick. const-cast is evil. fix. (srj)
aiMoveToObject(const_cast<Object*>(victim), CMD_FROM_AI );
m_originalTargetPos = *victim->getPosition();
- m_isTrackingTarget = TRUE;// Remember that I was originally shot at a moving object, so if the
+ m_isTrackingTarget = TRUE;// Remember that I was originally shot at a moving object, so if the
// target dies I can do something cool.
m_victimID = victim->getID();
+ m_aimOffset.zero();
}
}
}
@@ -775,6 +880,7 @@ UpdateSleepTime MissileAIUpdate::update()
break;
}
+ updateChaseOffset();
/*UpdateSleepTime ret =*/ AIUpdateInterface::update();
#if 1
@@ -893,7 +999,8 @@ void MissileAIUpdate::crc( Xfer *xfer )
void MissileAIUpdate::xfer( Xfer *xfer )
{
// version
- const XferVersion currentVersion = 6;
+ // 7: m_aimOffset
+ const XferVersion currentVersion = 7;
XferVersion version = currentVersion;
xfer->xferVersion( &version, currentVersion );
@@ -958,6 +1065,9 @@ void MissileAIUpdate::xfer( Xfer *xfer )
if( version>= 6 )
xfer->xferBool( &m_isJammed );
+ if( version >= 7 )
+ xfer->xferCoord3D( &m_aimOffset );
+
} // end xfer
// ------------------------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp
index 5d2ba6114..f507eb07b 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp
@@ -986,11 +986,22 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate
}
}
+ // where on the victim this shot lands (Weapon::randomPointOnBody); a bridge keeps its attack point.
+ // Drawn whether or not anything is drawn, as it comes from the logic stream.
+ Coord3D aimPos;
+ const Bool aimsOnBody = victimObj != NULL && !victimObj->isKindOf( KINDOF_BRIDGE );
+ if( aimsOnBody )
+ Weapon::randomPointOnBody( victimObj, aimPos );
+
// call this even if FXList is null, because this also handles stuff like Gun Barrel Recoil
if (sourceObj && sourceObj->getDrawable())
{
Coord3D targetPos;
- if( victimObj )
+ if( aimsOnBody )
+ {
+ targetPos = aimPos;
+ }
+ else if( victimObj )
{
victimObj->getGeometryInfo().getCenterPosition( *victimObj->getPosition(), targetPos );
}
@@ -1223,7 +1234,8 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate
}
else
{
- pui->projectileLaunchAtObjectOrPosition(victimObj, &projectileDestination, sourceObj, wslot, specificBarrelToUse, this, m_projectileExhausts[v]);
+ // a projectile that follows its victim flies to the shot's point on it
+ pui->projectileLaunchAtObjectOrPosition(victimObj, aimsOnBody ? &aimPos : &projectileDestination, sourceObj, wslot, specificBarrelToUse, this, m_projectileExhausts[v]);
}
if( victimObj )
pui->projectileLeadVictim( victimObj );
@@ -3386,6 +3398,51 @@ void Weapon::processRequestAssistance( const Object *requestingObject, Object *v
}
}
+//-------------------------------------------------------------------------------------------------
+// A shot at an object used to aim at one spot of it, its foot or its middle, so every rocket, shell
+// and tracer at a tank met it in the same place. Each shot now picks a point of its own inside the
+// object's geometry, kept off the box's edges and corners, which are mostly air round a real model:
+// seven tenths of the footprint and the middle seven tenths of the height. Only where it lands moves.
+// A small object spreads its shots over a small body.
+//-------------------------------------------------------------------------------------------------
+/*static*/ void Weapon::randomPointOnBody(const Object* victim, Coord3D& point)
+{
+ const Real FOOTPRINT_SHARE = 0.7f;
+ const Real HEIGHT_MARGIN = 0.15f;
+ const GeometryInfo& geom = victim->getGeometryInfo();
+ Coord3D local;
+ geom.makeRandomOffsetWithinFootprint(local);
+ local.x *= FOOTPRINT_SHARE;
+ local.y *= FOOTPRINT_SHARE;
+ Real low = -geom.getMaxHeightBelowPosition();
+ Real high = geom.getMaxHeightAbovePosition();
+ local.z = GameLogicRandomValueReal(low + (high - low) * HEIGHT_MARGIN, high - (high - low) * HEIGHT_MARGIN);
+ pointFromBodyOffset(victim, local, point);
+}
+
+//-------------------------------------------------------------------------------------------------
+/*static*/ void Weapon::bodyOffsetFromPoint(const Object* victim, const Coord3D& point, Coord3D& offset)
+{
+ Real c = Cos(victim->getOrientation());
+ Real s = Sin(victim->getOrientation());
+ Real dx = point.x - victim->getPosition()->x;
+ Real dy = point.y - victim->getPosition()->y;
+ offset.x = dx * c + dy * s;
+ offset.y = dy * c - dx * s;
+ offset.z = point.z - victim->getPosition()->z;
+}
+
+//-------------------------------------------------------------------------------------------------
+/*static*/ void Weapon::pointFromBodyOffset(const Object* victim, const Coord3D& offset, Coord3D& point)
+{
+ Real c = Cos(victim->getOrientation());
+ Real s = Sin(victim->getOrientation());
+ point = *victim->getPosition();
+ point.x += offset.x * c - offset.y * s;
+ point.y += offset.x * s + offset.y * c;
+ point.z += offset.z;
+}
+
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void Weapon::getFiringLineOfSightOrigin(const Object* source, Coord3D& origin) const