Skip to content

Commit 5640360

Browse files
authored
Ship Improvements (#63)
More ship and water stuff, torpedo logic... Mouse and Radius cursor over water.
1 parent 30705c4 commit 5640360

File tree

13 files changed

+110
-5
lines changed

13 files changed

+110
-5
lines changed

Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2319,6 +2319,16 @@ void W3DView::screenToTerrain( const ICoord2D *screen, Coord3D *world )
23192319
intersection = bridgePt;
23202320
}
23212321

2322+
//Check for water height in this area, create a dummy plane around the point
2323+
if (TheGlobalData->m_heightAboveTerrainIncludesWater) {
2324+
Vector3 outPos{ 0,0,0 };
2325+
if (TheTerrainLogic->pickWaterPlane(rayStart, rayEnd, intersection, outPos)) {
2326+
if (outPos.Z > intersection.Z) {
2327+
intersection = outPos;
2328+
}
2329+
}
2330+
}
2331+
23222332
world->x = intersection.X;
23232333
world->y = intersection.Y;
23242334
world->z = intersection.Z;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,11 @@ enum DamageType CPP_11(: Int)
9797
DAMAGE_SEISMIC,
9898
DAMAGE_RAD_BEAM,
9999
DAMAGE_TESLA,
100+
DAMAGE_JET_TORPEDO,
101+
DAMAGE_ANTI_SHIP,
100102

101103
// Specific damage types with special logic attached
104+
DAMAGE_TORPEDO, ///< can only attack units over water
102105
DAMAGE_CHRONO_GUN, ///< Disable target and remove them once health threshold is reached
103106
DAMAGE_CHRONO_UNRESISTABLE, ///< Used for recovery from CHRONO_GUN
104107
// DAMAGE_ZOMBIE_VIRUS, // TODO

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class MissileAIUpdateModuleData : public AIUpdateModuleData
7171

7272
Bool m_applyLauncherBonus; ///< Apply the launcher's weapon bonus flags (for any non-detonate triggered weapon)
7373

74+
Bool m_isTorpedo; ///< die outside of water, strike objects from below.
75+
7476
MissileAIUpdateModuleData();
7577

7678
static void buildFieldParse(MultiIniFieldParse& p);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@ class TerrainLogic : public Snapshot,
288288

289289
virtual Drawable *pickBridge(const Vector3 &from, const Vector3 &to, Vector3 *pos);
290290

291+
// get water around a world point
292+
virtual bool pickWaterPlane(const Vector3 &from, const Vector3 &to, const Vector3 &aroundPos, Vector3 &outPos);
293+
291294
virtual void addBridgeToLogic(BridgeInfo *pInfo, Dict *props, AsciiString bridgeTemplateName); ///< Adds a bridge's logical info.
292295
virtual void addLandmarkBridgeToLogic(Object *bridgeObj); ///< Adds a bridge's logical info.
293296
virtual void deleteBridge( Bridge *bridge ); ///< remove a bridge

GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,14 @@ void AIGroup::computeIndividualDestination( Coord3D *dest, const Coord3D *groupD
542542
dest->x = groupDest->x + v.x;
543543
dest->y = groupDest->y + v.y;
544544
dest->z = TheTerrainLogic->getLayerHeight( dest->x, dest->y, layer );
545+
546+
if (TheGlobalData->m_heightAboveTerrainIncludesWater) {
547+
// Put waypoints on water surface instead of ground
548+
if (Real waterZ = 0; TheTerrainLogic->isUnderwater(dest->x, dest->y, &waterZ)) {
549+
if (waterZ > dest->z) dest->z = waterZ;
550+
}
551+
}
552+
545553
AIUpdateInterface *ai = obj->getAIUpdateInterface();
546554
if (ai && ai->isDoingGroundMovement()) {
547555
if (isFormation) {

GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8894,6 +8894,13 @@ void Pathfinder::adjustCoordToCell(Int cellX, Int cellY, Bool centerInCell, Coor
88948894
pos.y = ((Real)cellY+0.05) * PATHFIND_CELL_SIZE_F;
88958895
}
88968896
pos.z = TheTerrainLogic->getLayerHeight( pos.x, pos.y, layer );
8897+
8898+
if (TheGlobalData->m_heightAboveTerrainIncludesWater) {
8899+
//Adjust to water surface
8900+
if (Real waterZ = 0; TheTerrainLogic->isUnderwater(pos.x, pos.y, &waterZ)) {
8901+
if (waterZ > pos.z) pos.z = waterZ;
8902+
}
8903+
}
88978904
}
88988905

88998906

GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,6 +1975,34 @@ Drawable *TerrainLogic::pickBridge(const Vector3 &from, const Vector3 &to, Vecto
19751975
return(curDraw);
19761976
}
19771977

1978+
bool TerrainLogic::pickWaterPlane(const Vector3& from, const Vector3& to, const Vector3& aroundPos, Vector3 &outPos) {
1979+
Real waterZ{ 0 };
1980+
if (isUnderwater(aroundPos.X, aroundPos.Y, &waterZ)) {
1981+
Vector3 normal(0, 0, 1.0f);
1982+
Vector3 point(aroundPos.X, aroundPos.Y, waterZ);
1983+
1984+
PlaneClass plane(normal, point);
1985+
1986+
Real t;
1987+
plane.Compute_Intersection(from, to, &t);
1988+
Vector3 intersectPos;
1989+
intersectPos = from + (to - from) * t;
1990+
1991+
outPos.X = intersectPos.X;
1992+
outPos.Y = intersectPos.Y;
1993+
outPos.Z = intersectPos.Z;
1994+
1995+
return true;
1996+
}
1997+
else {
1998+
outPos.X = 0;
1999+
outPos.Y = 0;
2000+
outPos.Z = 0;
2001+
return false;
2002+
}
2003+
}
2004+
2005+
19782006
//-------------------------------------------------------------------------------------------------
19792007
/** Deletes the bridges list. */
19802008
//-------------------------------------------------------------------------------------------------

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ void MissileAIUpdateModuleData::buildFieldParse(MultiIniFieldParse& p)
131131
{ "KillSelfDelay", INI::parseDurationUnsignedInt, NULL, offsetof( MissileAIUpdateModuleData, m_killSelfDelay ) },
132132
{ "ZCorrectionFactor", INI::parseReal, NULL, offsetof(MissileAIUpdateModuleData, m_zDirFactor) },
133133
{ "ApplyLauncherBonus", INI::parseBool, NULL, offsetof(MissileAIUpdateModuleData, m_applyLauncherBonus) },
134+
{ "IsTorpedo", INI::parseBool, NULL, offsetof(MissileAIUpdateModuleData, m_isTorpedo) },
134135
{ 0, 0, 0, 0 }
135136
};
136137

@@ -633,7 +634,7 @@ void MissileAIUpdate::doAttackState(Bool turnOK, Bool randomPath)
633634
}
634635
}
635636

636-
if(curLoco && curLoco->getPreferredHeight() > 0)
637+
if(curLoco && (curLoco->getPreferredHeight() > 0 || curLoco->getPreferredHeight() < 0) )
637638
{
638639
// Am I close enough to the target to ignore my preferred height setting?
639640
Real distanceToTargetSquared = ThePartitionManager->getDistanceSquared( getObject(), getGoalPosition(), FROM_CENTER_2D );
@@ -840,6 +841,13 @@ UpdateSleepTime MissileAIUpdate::update()
840841
TheGameLogic->destroyObject(getObject());
841842
return UPDATE_SLEEP_FOREVER;
842843
}
844+
845+
// If treated as torpedo, explode when not over water
846+
const MissileAIUpdateModuleData* d = getMissileAIUpdateModuleData();
847+
if (d->m_isTorpedo && !getObject()->isOverWater()) {
848+
detonate();
849+
}
850+
843851
switch( m_state )
844852
{
845853
case PRELAUNCH:

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionExitUpdate/DefaultProductionExitUpdate.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ void DefaultProductionExitUpdate::exitObjectViaDoor( Object *newObj, ExitDoorTyp
8181
// make sure the point is on the terrain
8282
loc.Z = TheTerrainLogic ? TheTerrainLogic->getLayerHeight( loc.X, loc.Y, creationObject->getLayer() ) : 0.0f;
8383

84+
// If underwater use water height, fixes shipyards spawning ships under water
85+
if (Real waterZ = 0; TheTerrainLogic && TheTerrainLogic->isUnderwater(loc.X, loc.Y, &waterZ)) {
86+
if (waterZ > loc.Z) loc.Z = waterZ;
87+
}
88+
89+
8490
// we need it in Coord3D form
8591
createPoint.x = loc.X;
8692
createPoint.y = loc.Y;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,11 @@ CanAttackResult WeaponSet::getAbleToUseWeaponAgainstTarget( AbleToAttackType att
838838
continue;
839839
}
840840

841+
// Torpedoes cannot attack units not above water
842+
if (weapon->getDamageType() == DAMAGE_TORPEDO && !victim->isOverWater()) {
843+
continue;
844+
}
845+
841846
return okResult;
842847
}
843848
}

0 commit comments

Comments
 (0)