Skip to content

Commit deab866

Browse files
authored
Ships (#60)
1 parent 13328fb commit deab866

File tree

27 files changed

+538
-121
lines changed

27 files changed

+538
-121
lines changed

Generals/Code/GameEngine/Include/GameLogic/AIPathfind.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ class Pathfinder : PathfindServicesInterface, public Snapshot
809809
const Object *obj, Int attackDistance);
810810

811811
Path *buildActualPath( const Object *obj, LocomotorSurfaceTypeMask acceptableSurfaces,
812-
const Coord3D *fromPos, PathfindCell *goalCell, Bool center, Bool blocked ); ///< Work backwards from goal cell to construct final path
812+
const Coord3D *fromPos, PathfindCell *goalCell, Bool center, Bool blocked, Int requireWaterLevel ); ///< Work backwards from goal cell to construct final path
813813
Path *buildGroundPath( Bool isCrusher,const Coord3D *fromPos, PathfindCell *goalCell,
814814
Bool center, Int pathDiameter ); ///< Work backwards from goal cell to construct final path
815815
Path *buildHierachicalPath( const Coord3D *fromPos, PathfindCell *goalCell); ///< Work backwards from goal cell to construct final path

GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ class GlobalData : public SubsystemInterface
335335
Real m_MinDistFromEdgeOfMapForBuild;
336336
Real m_SupplyBuildBorder;
337337
Real m_allowedHeightVariationForBuilding; ///< how "flat" is still flat enough to build on
338+
Real m_allowedHeightVariationForBuildingShipyard; ///< how "flat" is still flat enough to build on
338339
Real m_MinLowEnergyProductionSpeed;
339340
Real m_MaxLowEnergyProductionSpeed;
340341
Real m_LowEnergyPenaltyModifier;
@@ -586,7 +587,7 @@ class GlobalData : public SubsystemInterface
586587
//AudioEventRTS m_chronoDisableSoundLoop;
587588

588589
DeathTypeFlags m_defaultExcludedDeathTypes;
589-
590+
Bool m_heightAboveTerrainIncludesWater;
590591

591592
// the trailing '\' is included!
592593
const AsciiString &getPath_UserData() const { return m_userDataDir; }

GeneralsMD/Code/GameEngine/Include/Common/KindOf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ enum KindOfType CPP_11(: Int)
191191
KINDOF_SUPERHEAVY_VEHICLE,
192192

193193
KINDOF_TELEPORTER,
194+
KINDOF_SHIPYARD,
194195

195196
KINDOF_EXTRA1,
196197
KINDOF_EXTRA2,

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class Path : public MemoryPoolObject, public Snapshot
155155
void appendNode( const Coord3D *pos, PathfindLayerEnum layer ); ///< Create a new node at the end of the path
156156
void setBlockedByAlly(Bool blocked) {m_blockedByAlly = blocked;}
157157
Bool getBlockedByAlly(void) {return m_blockedByAlly;}
158-
void optimize( const Object *obj, LocomotorSurfaceTypeMask acceptableSurfaces, Bool blocked ); ///< Optimize the path to discard redundant nodes
158+
void optimize( const Object *obj, LocomotorSurfaceTypeMask acceptableSurfaces, Bool blocked, Int requiredWaterLevel); ///< Optimize the path to discard redundant nodes
159159

160160
void optimizeGroundPath( Bool crusher, Int diameter ); ///< Optimize the ground path to discard redundant nodes
161161

@@ -343,6 +343,9 @@ class PathfindCell
343343
Bool getPinched(void) const {return m_pinched;}
344344
void setPinched(Bool pinch) {m_pinched = pinch; }
345345

346+
Short getWaterLevel(void) const { return m_waterLevel; }
347+
void setWaterLevel(Short level) { m_waterLevel = level; }
348+
346349
Bool allocateInfo(const ICoord2D &pos);
347350
void releaseInfo(void);
348351
Bool hasInfo(void) const {return m_info!=NULL;}
@@ -373,6 +376,8 @@ class PathfindCell
373376
UnsignedByte m_flags:4; ///< what type of units are in or moving through this cell.
374377
UnsignedByte m_connectsToLayer:4; ///< This cell can pathfind onto this layer, if > LAYER_TOP.
375378
UnsignedByte m_layer:4; ///< Layer of this cell.
379+
//This is added for ship pathing
380+
Short m_waterLevel:8; ///< how far away is this cell from land (distance transform), capped at 15
376381
};
377382

378383
typedef PathfindCell *PathfindCellP;
@@ -673,7 +678,7 @@ class Pathfinder : PathfindServicesInterface, public Snapshot
673678

674679
void setIgnoreObstacleID( ObjectID objID ); ///< if non-zero, the pathfinder will ignore the given obstacle
675680

676-
Bool validMovementPosition( Bool isCrusher, LocomotorSurfaceTypeMask acceptableSurfaces, PathfindCell *toCell, PathfindCell *fromCell = NULL ); ///< Return true if given position is a valid movement location
681+
Bool validMovementPosition( Bool isCrusher, LocomotorSurfaceTypeMask acceptableSurfaces, Int requiredWaterLevel, PathfindCell *toCell, PathfindCell *fromCell = NULL ); ///< Return true if given position is a valid movement location
677682
Bool validMovementPosition( Bool isCrusher, PathfindLayerEnum layer, const LocomotorSet& locomotorSet, Int x, Int y ); ///< Return true if given position is a valid movement location
678683
Bool validMovementPosition( Bool isCrusher, PathfindLayerEnum layer, const LocomotorSet& locomotorSet, const Coord3D *pos ); ///< Return true if given position is a valid movement location
679684
Bool validMovementTerrain( PathfindLayerEnum layer, const Locomotor* locomotor, const Coord3D *pos ); ///< Return true if given position is a valid movement location
@@ -686,7 +691,7 @@ class Pathfinder : PathfindServicesInterface, public Snapshot
686691

687692
Bool isLinePassable( const Object *obj, LocomotorSurfaceTypeMask acceptableSurfaces,
688693
PathfindLayerEnum layer, const Coord3D& startWorld, const Coord3D& endWorld,
689-
Bool blocked, Bool allowPinched ); ///< Return true if the straight line between the given points is passable
694+
Bool blocked, Bool allowPinched, Int requiredWaterDepth); ///< Return true if the straight line between the given points is passable
690695

691696
void moveAlliesAwayFromDestination( Object *obj,const Coord3D& destination);
692697

@@ -817,7 +822,7 @@ class Pathfinder : PathfindServicesInterface, public Snapshot
817822
const Object *obj, Int attackDistance);
818823

819824
Path *buildActualPath( const Object *obj, LocomotorSurfaceTypeMask acceptableSurfaces,
820-
const Coord3D *fromPos, PathfindCell *goalCell, Bool center, Bool blocked ); ///< Work backwards from goal cell to construct final path
825+
const Coord3D *fromPos, PathfindCell *goalCell, Bool center, Bool blocked, Int requiredWaterLevel ); ///< Work backwards from goal cell to construct final path
821826
Path *buildGroundPath( Bool isCrusher,const Coord3D *fromPos, PathfindCell *goalCell,
822827
Bool center, Int pathDiameter ); ///< Work backwards from goal cell to construct final path
823828
Path *buildHierachicalPath( const Coord3D *fromPos, PathfindCell *goalCell); ///< Work backwards from goal cell to construct final path
@@ -888,7 +893,7 @@ inline void Pathfinder::worldToGrid( const Coord3D *pos, ICoord2D *cellIndex )
888893

889894
inline Bool Pathfinder::validMovementPosition( Bool isCrusher, PathfindLayerEnum layer, const LocomotorSet& locomotorSet, Int x, Int y )
890895
{
891-
return validMovementPosition( isCrusher, locomotorSet.getValidSurfaces(), getCell( layer, x, y ) );
896+
return validMovementPosition( isCrusher, locomotorSet.getValidSurfaces(), locomotorSet.getRequiredWaterLevel(), getCell(layer, x, y));
892897
}
893898

894899
inline Bool Pathfinder::validMovementPosition( Bool isCrusher, PathfindLayerEnum layer, const LocomotorSet& locomotorSet, const Coord3D *pos )

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ enum LocomotorAppearance CPP_11(: Int)
5959
LOCO_CLIMBER, // human climber - backs down cliffs.
6060
LOCO_OTHER,
6161
LOCO_MOTORCYCLE,
62-
62+
LOCO_SHIP,
6363
LOCOMOTOR_APPEARANCE_COUNT
6464
};
6565

@@ -84,7 +84,7 @@ static const char *const TheLocomotorAppearanceNames[] =
8484
"CLIMBER",
8585
"OTHER",
8686
"MOTORCYCLE",
87-
87+
"SHIP",
8888
NULL
8989
};
9090
static_assert(ARRAY_SIZE(TheLocomotorAppearanceNames) == LOCOMOTOR_APPEARANCE_COUNT + 1, "Array size");
@@ -218,6 +218,8 @@ class LocomotorTemplate : public Overridable
218218
Real m_rudderCorrectionRate;
219219
Real m_elevatorCorrectionDegree;
220220
Real m_elevatorCorrectionRate;
221+
222+
Int m_requiredWaterLevel; ///< for LOCO_SHIP, how deep the water must be
221223
};
222224

223225
typedef OVERRIDE<LocomotorTemplate> LocomotorTemplateOverride;
@@ -321,6 +323,9 @@ class Locomotor : public MemoryPoolObject, public Snapshot
321323

322324
void setPreferredHeight( Real height ) { m_preferredHeight = height; }
323325

326+
//Returns 0 for non SHIP locomotors
327+
inline Int getRequireWaterLevel() const { return m_template->m_appearance == LOCO_SHIP ? m_template->m_requiredWaterLevel : 0; };
328+
324329
#ifdef CIRCLE_FOR_LANDING
325330
/**
326331
if we are climbing/diving more than this, circle as needed rather

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class LocomotorSet : public Snapshot
8080
LocomotorVector m_locomotors;
8181
LocomotorSurfaceTypeMask m_validLocomotorSurfaces;
8282
Bool m_downhillOnly;
83+
Int m_requiredWaterLevel; // for ships, if there are multiple water locomotors the lowest allowed value is used
8384

8485
LocomotorSet(const LocomotorSet& that);
8586
LocomotorSet& operator=(const LocomotorSet& that);
@@ -105,5 +106,6 @@ class LocomotorSet : public Snapshot
105106

106107
LocomotorSurfaceTypeMask getValidSurfaces() const { return m_validLocomotorSurfaces; }
107108
Bool isDownhillOnly( void ) const { return m_downhillOnly; };
109+
Int getRequiredWaterLevel() const { return m_requiredWaterLevel; };
108110

109111
};

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class DumbProjectileBehavior : public UpdateModule, public ProjectileUpdateInter
9696
virtual void projectileNowJammed() {}
9797
virtual Object* getTargetObject();
9898
virtual const Coord3D* getTargetPosition();
99+
virtual Bool projectileShouldCollideWithWater() const override;
99100

100101
protected:
101102

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class FreeFallProjectileBehavior : public UpdateModule, public ProjectileUpdateI
102102
virtual void projectileNowJammed() {}
103103
virtual Object* getTargetObject();
104104
virtual const Coord3D* getTargetPosition();
105+
virtual bool projectileShouldCollideWithWater() const override;
105106

106107
protected:
107108

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class MissileAIUpdate : public AIUpdateInterface, public ProjectileUpdateInterfa
109109
virtual void projectileNowJammed();///< We lose our Object target and scatter to the ground
110110
virtual Object* getTargetObject();
111111
virtual const Coord3D* getTargetPosition();
112+
virtual bool projectileShouldCollideWithWater() const override;
112113

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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ class ProjectileUpdateInterface
266266
virtual Bool projectileHandleCollision(Object *other) = 0;
267267
virtual void setFramesTillCountermeasureDiversionOccurs( UnsignedInt frames ) = 0; ///< Number of frames till missile diverts to countermeasures.
268268
virtual void projectileNowJammed() = 0;
269+
virtual Bool projectileShouldCollideWithWater() const { return false; };
269270

270271
virtual Object* getTargetObject() = 0;
271272
virtual const Coord3D* getTargetPosition() = 0;

0 commit comments

Comments
 (0)