Skip to content

Commit aa8a943

Browse files
committed
Merge branch 'main' into IamInnocent-dev
2 parents c9dfe90 + 4be6dc4 commit aa8a943

File tree

13 files changed

+111
-6
lines changed

13 files changed

+111
-6
lines changed

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

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

2430+
//Check for water height in this area, create a dummy plane around the point
2431+
if (TheGlobalData->m_heightAboveTerrainIncludesWater) {
2432+
Vector3 outPos{ 0,0,0 };
2433+
if (TheTerrainLogic->pickWaterPlane(rayStart, rayEnd, intersection, outPos)) {
2434+
if (outPos.Z > intersection.Z) {
2435+
intersection = outPos;
2436+
}
2437+
}
2438+
}
2439+
24302440
world->x = intersection.X;
24312441
world->y = intersection.Y;
24322442
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
@@ -101,8 +101,11 @@ enum DamageType CPP_11(: Int)
101101
DAMAGE_SEISMIC,
102102
DAMAGE_RAD_BEAM,
103103
DAMAGE_TESLA,
104+
DAMAGE_JET_TORPEDO,
105+
DAMAGE_ANTI_SHIP,
104106

105107
// Specific damage types with special logic attached
108+
DAMAGE_TORPEDO, ///< can only attack units over water
106109
DAMAGE_CHRONO_GUN, ///< Disable target and remove them once health threshold is reached
107110
DAMAGE_CHRONO_UNRESISTABLE, ///< Used for recovery from CHRONO_GUN
108111
// 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
Bool m_allowSubdual;
7577
Bool m_allowAttract;
7678

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
@@ -921,6 +921,14 @@ void AIGroup::computeIndividualDestination( Coord3D *dest, const Coord3D *groupD
921921
dest->x = groupDest->x + v.x;
922922
dest->y = groupDest->y + v.y;
923923
dest->z = TheTerrainLogic->getLayerHeight( dest->x, dest->y, layer );
924+
925+
if (TheGlobalData->m_heightAboveTerrainIncludesWater) {
926+
// Put waypoints on water surface instead of ground
927+
if (Real waterZ = 0; TheTerrainLogic->isUnderwater(dest->x, dest->y, &waterZ)) {
928+
if (waterZ > dest->z) dest->z = waterZ;
929+
}
930+
}
931+
924932
AIUpdateInterface *ai = obj->getAIUpdateInterface();
925933
if (ai && ai->isDoingGroundMovement()) {
926934
if (isFormation) {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9069,6 +9069,13 @@ void Pathfinder::adjustCoordToCell(Int cellX, Int cellY, Bool centerInCell, Coor
90699069
pos.y = ((Real)cellY+0.05) * PATHFIND_CELL_SIZE_F;
90709070
}
90719071
pos.z = TheTerrainLogic->getLayerHeight( pos.x, pos.y, layer );
9072+
9073+
if (TheGlobalData->m_heightAboveTerrainIncludesWater) {
9074+
//Adjust to water surface
9075+
if (Real waterZ = 0; TheTerrainLogic->isUnderwater(pos.x, pos.y, &waterZ)) {
9076+
if (waterZ > pos.z) pos.z = waterZ;
9077+
}
9078+
}
90729079
}
90739080

90749081

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: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,14 @@ void MissileAIUpdateModuleData::buildFieldParse(MultiIniFieldParse& p)
136136
{ "KillSelfDelay", INI::parseDurationUnsignedInt, NULL, offsetof( MissileAIUpdateModuleData, m_killSelfDelay ) },
137137
{ "ZCorrectionFactor", INI::parseReal, NULL, offsetof(MissileAIUpdateModuleData, m_zDirFactor) },
138138
{ "ApplyLauncherBonus", INI::parseBool, NULL, offsetof(MissileAIUpdateModuleData, m_applyLauncherBonus) },
139+
{ "IsTorpedo", INI::parseBool, NULL, offsetof(MissileAIUpdateModuleData, m_isTorpedo) },
139140

140141
{ "AllowSubdual", INI::parseBool, NULL, offsetof(MissileAIUpdateModuleData, m_allowSubdual) },
141142
{ "AllowAttract", INI::parseBool, NULL, offsetof(MissileAIUpdateModuleData, m_allowAttract) },
142143

143144
{ "AllowRetargeting", INI::parseBool, NULL, offsetof(MissileAIUpdateModuleData, m_allowRetargeting) },
144145
{ "AllowRetargetingThroughFog", INI::parseBool, NULL, offsetof(MissileAIUpdateModuleData, m_allowRetargetingThroughFog) },
145-
146+
146147
{ 0, 0, 0, 0 }
147148
};
148149

@@ -703,7 +704,7 @@ void MissileAIUpdate::doAttackState(Bool turnOK, Bool randomPath)
703704
}
704705
}
705706

706-
if(curLoco && curLoco->getPreferredHeight() > 0)
707+
if(curLoco && (curLoco->getPreferredHeight() > 0 || curLoco->getPreferredHeight() < 0) )
707708
{
708709
// Am I close enough to the target to ignore my preferred height setting?
709710
Real distanceToTargetSquared = ThePartitionManager->getDistanceSquared( getObject(), getGoalPosition(), FROM_CENTER_2D );
@@ -981,6 +982,13 @@ UpdateSleepTime MissileAIUpdate::update()
981982
TheGameLogic->destroyObject(getObject());
982983
return UPDATE_SLEEP_FOREVER;
983984
}
985+
986+
// If treated as torpedo, explode when not over water
987+
const MissileAIUpdateModuleData* d = getMissileAIUpdateModuleData();
988+
if (d->m_isTorpedo && !getObject()->isOverWater()) {
989+
detonate();
990+
}
991+
984992
switch( m_state )
985993
{
986994
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
@@ -901,6 +901,11 @@ CanAttackResult WeaponSet::getAbleToUseWeaponAgainstTarget( AbleToAttackType att
901901
continue;
902902
}
903903

904+
// Torpedoes cannot attack units not above water
905+
if (weapon->getDamageType() == DAMAGE_TORPEDO && !victim->isOverWater()) {
906+
continue;
907+
}
908+
904909
return okResult;
905910
}
906911
}

0 commit comments

Comments
 (0)