Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5396,8 +5396,8 @@ Bool Pathfinder::adjustToLandingDestination(Object *obj, Coord3D *dest)
TheTerrainLogic->getMaximumPathfindExtent(&extent);
// If the object is off the map & the goal is off the map, it is a scripted setup, so just
// go to the dest.
if (!extent.isInRegionNoZ(*dest)) {
if (!extent.isInRegionNoZ(*obj->getPosition())) {
if (!extent.isInRegion(dest->asCoord2D())) {
if (!extent.isInRegion(obj->getPosition()->asCoord2D())) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2069,7 +2069,7 @@ bool GameLogic::onPlaceBeacon(MAYBE_UNUSED GameMessage *msg)
Coord3D pos = msg->getArgument( 0 )->location;
Region3D r;
TheTerrainLogic->getExtent(&r);
if (!r.isInRegionNoZ(pos))
if (!r.isInRegion(pos.asCoord2D()))
pos = TheTerrainLogic->findClosestEdgePoint(&pos);
const ThingTemplate *thing = TheThingFactory->findTemplate( msgPlayer->getPlayerTemplate()->getBeaconTemplate() );

Expand Down
9 changes: 9 additions & 0 deletions Core/Libraries/Include/Lib/IRegion2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,14 @@ struct IRegion2D

Int width() const { return hi.x - lo.x; }
Int height() const { return hi.y - lo.y; }

Bool isInRegion( Int x, Int y ) const { return (lo.x < x) && (x < hi.x) && (lo.y < y) && (y < hi.y); }

Bool isInRegion( const ICoord2D& point ) const { return isInRegion(point.x, point.y); }

Bool isInRegion( const IRegion2D& other ) const
{
return (lo.x < other.lo.x) && (other.hi.x < hi.x) &&
(lo.y < other.lo.y) && (other.hi.y < hi.y);
}
};
22 changes: 22 additions & 0 deletions Core/Libraries/Include/Lib/IRegion3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,26 @@ struct IRegion3D
Int width() const { return hi.x - lo.x; }
Int height() const { return hi.y - lo.y; }
Int depth() const { return hi.z - lo.z; }

Bool isInRegion( const ICoord2D& point ) const
{
return (lo.x < point.x) && (point.x < hi.x) &&
(lo.y < point.y) && (point.y < hi.y);
}

Bool isInRegion( Int x, Int y, Int z ) const
{
return (lo.x < x) && (x < hi.x) &&
(lo.y < y) && (y < hi.y) &&
(lo.z < z) && (z < hi.z);
}

Bool isInRegion( const ICoord3D& point ) const { return isInRegion(point.x, point.y, point.z); }

Bool isInRegion( const IRegion3D& other ) const
{
return (lo.x < other.lo.x) && (other.hi.x < hi.x) &&
(lo.y < other.lo.y) && (other.hi.y < hi.y) &&
(lo.z < other.lo.z) && (other.hi.z < hi.z);
}
};
9 changes: 9 additions & 0 deletions Core/Libraries/Include/Lib/Region2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,14 @@ struct Region2D

Real width() const { return hi.x - lo.x; }
Real height() const { return hi.y - lo.y; }

Bool isInRegion( Real x, Real y ) const { return (lo.x < x) && (x < hi.x) && (lo.y < y) && (y < hi.y); }

Bool isInRegion( const Coord2D& point ) const { return isInRegion(point.x, point.y); }

Bool isInRegion( const Region2D& other ) const
{
return (lo.x < other.lo.x) && (other.hi.x < hi.x) &&
(lo.y < other.lo.y) && (other.hi.y < hi.y);
}
};
23 changes: 16 additions & 7 deletions Core/Libraries/Include/Lib/Region3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,25 @@ struct Region3D
}
}

Bool isInRegionNoZ( const Coord3D &query ) const
Bool isInRegion( const Coord2D& point ) const
{
return (lo.x < query.x) && (query.x < hi.x) &&
(lo.y < query.y) && (query.y < hi.y);
return (lo.x < point.x) && (point.x < hi.x) &&
(lo.y < point.y) && (point.y < hi.y);
}

Bool isInRegion( const Coord3D &query ) const
Bool isInRegion( Real x, Real y, Real z ) const
{
return (lo.x < query.x) && (query.x < hi.x) &&
(lo.y < query.y) && (query.y < hi.y) &&
(lo.z < query.z) && (query.z < hi.z);
return (lo.x < x) && (x < hi.x) &&
(lo.y < y) && (y < hi.y) &&
(lo.z < z) && (z < hi.z);
}

Bool isInRegion( const Coord3D& point ) const { return isInRegion(point.x, point.y, point.z); }

Bool isInRegion( const Region3D& other ) const
{
return (lo.x < other.lo.x) && (other.hi.x < hi.x) &&
(lo.y < other.lo.y) && (other.hi.y < hi.y) &&
(lo.z < other.lo.z) && (other.hi.z < hi.z);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ LegalBuildCode BuildAssistant::isLocationLegalToBuild( const Coord3D *worldPos,
/* You just can't never build off the map, regardless of options. jba. */
Region3D mapExtent;
TheTerrainLogic->getMaximumPathfindExtent(&mapExtent);
if (!mapExtent.isInRegionNoZ(*worldPos)) {
if (!mapExtent.isInRegion(worldPos->asCoord2D())) {
return LBC_RESTRICTED_TERRAIN;
}

Expand Down
4 changes: 2 additions & 2 deletions Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ static void clampToMap(Coord3D *dest, PlayerType pt)
extent.hi.y -= PATHFIND_CELL_SIZE_F;
extent.lo.x += PATHFIND_CELL_SIZE_F;
extent.lo.y += PATHFIND_CELL_SIZE_F;
if (!extent.isInRegionNoZ(*dest)) {
if (!extent.isInRegion(dest->asCoord2D())) {
// clamp to in region. [8/28/2003]
if (dest->x < extent.lo.x) {
dest->x = extent.lo.x;
Expand Down Expand Up @@ -1558,7 +1558,7 @@ void clampWaypointPosition( Coord3D &position, Int margin )
mapExtent.lo.x += margin;
mapExtent.lo.y += margin;

if ( mapExtent.isInRegionNoZ( position ) == FALSE )
if ( mapExtent.isInRegion( position.asCoord2D() ) == FALSE )
{
if ( position.x > mapExtent.hi.x )
position.x = mapExtent.hi.x;
Expand Down
2 changes: 1 addition & 1 deletion Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3836,7 +3836,7 @@ void AIFollowWaypointPathState::computeGoal(Bool useGroupOffsets)
}
Region3D extent;
TheTerrainLogic->getMaximumPathfindExtent(&extent);
if (!extent.isInRegionNoZ(m_goalPosition)) {
if (!extent.isInRegion(m_goalPosition.asCoord2D())) {
setAdjustsDestination(false); // moving off the map.
ai->getCurLocomotor()->setAllowInvalidPosition(true); // allow it to move off the map.
m_appendGoalPosition = true; // Moving off the map.
Expand Down
4 changes: 2 additions & 2 deletions Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1685,7 +1685,7 @@ void Object::reactToTransformChange(const Matrix3D* oldMtx, const Coord3D* oldPo

Region3D mapExtent;
TheTerrainLogic->getExtent(&mapExtent);
if (mapExtent.isInRegionNoZ(*getPosition()))
if (mapExtent.isInRegion(getPosition()->asCoord2D()))
m_privateStatus &= ~OFF_MAP;
else
m_privateStatus |= OFF_MAP;
Expand Down Expand Up @@ -2588,7 +2588,7 @@ void Object::friend_notifyOfNewMapBoundary()

Region3D mapExtent;
TheTerrainLogic->getExtent(&mapExtent);
if (mapExtent.isInRegionNoZ(*getPosition()))
if (mapExtent.isInRegion(getPosition()->asCoord2D()))
m_privateStatus &= ~OFF_MAP;
else
m_privateStatus |= OFF_MAP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3973,7 +3973,7 @@ Bool PartitionManager::findPositionAround( const Coord3D *center,
TheTerrainLogic->getMaximumPathfindExtent(&extent);
// If the goal is off the map, it is a scripted setup, so just
// use the center.
if (!extent.isInRegionNoZ(*center)) {
if (!extent.isInRegion(center->asCoord2D())) {
*result = *center;
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1658,10 +1658,10 @@ Bool AIUpdateInterface::computePath( PathfindServicesInterface *pathServices, Co
m_retryPath = false;
Region3D extent;
TheTerrainLogic->getMaximumPathfindExtent(&extent);
if (!extent.isInRegionNoZ(*destination)) {
if (!extent.isInRegion(destination->asCoord2D())) {
// We're going off the map.
Coord3D pos = *getObject()->getPosition();
if (!extent.isInRegionNoZ(pos)) {
if (!extent.isInRegion(pos.asCoord2D())) {
// We're starting off the map. Since we're off the map, we can't pathfind so just build a path.
return computeQuickPath(destination);
}
Expand Down Expand Up @@ -3857,7 +3857,7 @@ void AIUpdateInterface::privateGuardPosition( const Coord3D *pos, GuardMode guar
// Clip to playable area.
Region3D r;
TheTerrainLogic->getExtent(&r);
if (!r.isInRegionNoZ(adjPos))
if (!r.isInRegion(adjPos.asCoord2D()))
adjPos = TheTerrainLogic->findClosestEdgePoint(&adjPos);
}
m_locationToGuard = adjPos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class ChinookHeadOffMapState : public State

Region3D mapRegion;
TheTerrainLogic->getExtentIncludingBorder( &mapRegion );
if (!mapRegion.isInRegionNoZ( *owner->getPosition() ))
if (!mapRegion.isInRegion( owner->getPosition()->asCoord2D() ))
{
TheGameLogic->destroyObject(owner);
return STATE_SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ Bool DeliverPayloadAIUpdate::isOffMap() const
Region3D mapRegion;
TheTerrainLogic->getExtentIncludingBorder( &mapRegion );

if (!mapRegion.isInRegionNoZ( *getObject()->getPosition() ))
if (!mapRegion.isInRegion( getObject()->getPosition()->asCoord2D() ))
return true;

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,7 @@ inline Bool isPointOnMap( const Coord3D *testPos )
{
Region3D mapRegion;
TheTerrainLogic->getExtent( &mapRegion );
return mapRegion.isInRegionNoZ( *testPos );
return mapRegion.isInRegion( testPos->asCoord2D() );

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ LegalBuildCode BuildAssistant::isLocationLegalToBuild( const Coord3D *worldPos,
/* You just can't never build off the map, regardless of options. jba. */
Region3D mapExtent;
TheTerrainLogic->getMaximumPathfindExtent(&mapExtent);
if (!mapExtent.isInRegionNoZ(*worldPos)) {
if (!mapExtent.isInRegion(worldPos->asCoord2D())) {
Comment thread
greptile-apps[bot] marked this conversation as resolved.
return LBC_RESTRICTED_TERRAIN;
}

Expand Down
4 changes: 2 additions & 2 deletions GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ static void clampToMap(Coord3D *dest, PlayerType pt)
extent.hi.y -= PATHFIND_CELL_SIZE_F;
extent.lo.x += PATHFIND_CELL_SIZE_F;
extent.lo.y += PATHFIND_CELL_SIZE_F;
if (!extent.isInRegionNoZ(*dest)) {
if (!extent.isInRegion(dest->asCoord2D())) {
// clamp to in region. [8/28/2003]
if (dest->x < extent.lo.x) {
dest->x = extent.lo.x;
Expand Down Expand Up @@ -1568,7 +1568,7 @@ void clampWaypointPosition( Coord3D &position, Int margin )
mapExtent.lo.x += margin;
mapExtent.lo.y += margin;

if ( mapExtent.isInRegionNoZ( position ) == FALSE )
if ( mapExtent.isInRegion( position.asCoord2D() ) == FALSE )
{
if ( position.x > mapExtent.hi.x )
position.x = mapExtent.hi.x;
Expand Down
6 changes: 3 additions & 3 deletions GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3939,9 +3939,9 @@ void AIFollowWaypointPathState::computeGoal(Bool useGroupOffsets)
Region3D extent;
TheTerrainLogic->getMaximumPathfindExtent(&extent);

if (extent.isInRegionNoZ(dest)) {
if (extent.isInRegion(dest.asCoord2D())) {
// The waypoint is on the map. Check & see if the adjusted position is off map [8/28/2003]
if (!extent.isInRegionNoZ(m_goalPosition)) {
if (!extent.isInRegion(m_goalPosition.asCoord2D())) {
// clamp to in region. [8/28/2003]
if (m_goalPosition.x < extent.lo.x+PATHFIND_CELL_SIZE_F) {
m_goalPosition.x = extent.lo.x+PATHFIND_CELL_SIZE_F;
Expand All @@ -3958,7 +3958,7 @@ void AIFollowWaypointPathState::computeGoal(Bool useGroupOffsets)
}
}

if (!extent.isInRegionNoZ(m_goalPosition)) {
if (!extent.isInRegion(m_goalPosition.asCoord2D())) {
setAdjustsDestination(false); // moving off the map.
ai->getCurLocomotor()->setAllowInvalidPosition(true); // allow it to move off the map.
m_appendGoalPosition = true; // Moving off the map.
Expand Down
4 changes: 2 additions & 2 deletions GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1845,7 +1845,7 @@ void Object::reactToTransformChange(const Matrix3D* oldMtx, const Coord3D* oldPo

Region3D mapExtent;
TheTerrainLogic->getExtent(&mapExtent);
if (mapExtent.isInRegionNoZ(*getPosition()))
if (mapExtent.isInRegion(getPosition()->asCoord2D()))
m_privateStatus &= ~OFF_MAP;
else
m_privateStatus |= OFF_MAP;
Expand Down Expand Up @@ -2876,7 +2876,7 @@ void Object::friend_notifyOfNewMapBoundary()

Region3D mapExtent;
TheTerrainLogic->getExtent(&mapExtent);
if (mapExtent.isInRegionNoZ(*getPosition()))
if (mapExtent.isInRegion(getPosition()->asCoord2D()))
m_privateStatus &= ~OFF_MAP;
else
m_privateStatus |= OFF_MAP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3983,7 +3983,7 @@ Bool PartitionManager::findPositionAround( const Coord3D *center,
TheTerrainLogic->getMaximumPathfindExtent(&extent);
// If the goal is off the map, it is a scripted setup, so just
// use the center.
if (!extent.isInRegionNoZ(*center)) {
if (!extent.isInRegion(center->asCoord2D())) {
*result = *center;
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1679,10 +1679,10 @@ Bool AIUpdateInterface::computePath( PathfindServicesInterface *pathServices, Co
m_retryPath = false;
Region3D extent;
TheTerrainLogic->getMaximumPathfindExtent(&extent);
if (!extent.isInRegionNoZ(*destination)) {
if (!extent.isInRegion(destination->asCoord2D())) {
// We're going off the map.
Coord3D pos = *getObject()->getPosition();
if (!extent.isInRegionNoZ(pos)) {
if (!extent.isInRegion(pos.asCoord2D())) {
// We're starting off the map. Since we're off the map, we can't pathfind so just build a path.
return computeQuickPath(destination);
}
Expand Down Expand Up @@ -4081,7 +4081,7 @@ void AIUpdateInterface::privateGuardPosition( const Coord3D *pos, GuardMode guar
// Clip to playable area.
Region3D r;
TheTerrainLogic->getExtent(&r);
if (!r.isInRegionNoZ(adjPos))
if (!r.isInRegion(adjPos.asCoord2D()))
adjPos = TheTerrainLogic->findClosestEdgePoint(&adjPos);
}
m_locationToGuard = adjPos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class ChinookHeadOffMapState : public State

Region3D mapRegion;
TheTerrainLogic->getExtentIncludingBorder( &mapRegion );
if( !mapRegion.isInRegionNoZ( *owner->getPosition() ) )
if( !mapRegion.isInRegion( owner->getPosition()->asCoord2D() ) )
{
TheGameLogic->destroyObject(owner);
return STATE_SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ Bool DeliverPayloadAIUpdate::isOffMap() const
Region3D mapRegion;
TheTerrainLogic->getExtentIncludingBorder( &mapRegion );

if (!mapRegion.isInRegionNoZ( *getObject()->getPosition() ))
if (!mapRegion.isInRegion( getObject()->getPosition()->asCoord2D() ))
return true;

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ Bool SpectreGunshipUpdate::isPointOffMap( const Coord3D& testPos ) const
Region3D mapRegion;
TheTerrainLogic->getExtentIncludingBorder( &mapRegion );

if (!mapRegion.isInRegionNoZ( testPos ))
if (!mapRegion.isInRegion( testPos.asCoord2D() ))
return true;

return false;
Expand Down
Loading