public void SetBlockMaskAt(SegmentLocation segmentLocation, BlockMask blockMask)
        {
            if (IsLocationInRange(segmentLocation))
            {
                // can't place block on obstructed air as its an item!
                if (GetBlockMaskAt(segmentLocation) == BlockHelper.BlockMasks.AirBlocked)
                {
                    return;
                }

                // can't delete block with item above it!
                if (blockMask == BlockHelper.BlockMasks.Air)
                {
                    if (GetBlockMaskAt(segmentLocation.TranslateAndClone(new Vector3(0, 1, 0))) ==
                        BlockHelper.BlockMasks.AirBlocked)
                    {
                        return;
                    }
                }

                GetRenderSegmentAt(segmentLocation).Blocks[
                    segmentLocation.BlockX, segmentLocation.RenderSegmentBlockMaskIndex, segmentLocation.BlockZ] =
                    blockMask;

                // Mark all around it as dirty.
                SetLocationDirty(segmentLocation);
                SetLocationDirty(segmentLocation.TranslateAndClone(WorldDirection.Up));
                SetLocationDirty(segmentLocation.TranslateAndClone(WorldDirection.Down));
                SetLocationDirty(segmentLocation.TranslateAndClone(WorldDirection.North));
                SetLocationDirty(segmentLocation.TranslateAndClone(WorldDirection.East));
                SetLocationDirty(segmentLocation.TranslateAndClone(WorldDirection.South));
                SetLocationDirty(segmentLocation.TranslateAndClone(WorldDirection.West));
            }
        }
 public void SetLocationPassable(SegmentLocation segmentLocation)
 {
     if (IsLocationInRange(segmentLocation))
     {
         RemoveFlagAt(segmentLocation, BlockMask.IsObstacle);
     }
 }
 public void SetLocationObstructed(SegmentLocation segmentLocation)
 {
     if (IsLocationInRange(segmentLocation))
     {
         SetFlagAt(segmentLocation, BlockMask.IsObstacle);
     }
 }
 public void SetLocationDirty(SegmentLocation segmentLocation)
 {
     if (IsLocationInRange(segmentLocation))
     {
         GetRenderSegmentAt(segmentLocation).Dirty = true;
     }
 }
 public void RemoveFlagAt(SegmentLocation segmentLocation, BlockMask flag)
 {
     if (IsLocationInRange(segmentLocation))
     {
         SetBlockMaskAt(segmentLocation, GetBlockMaskAt(segmentLocation) & ~flag);
     }
 }
        // GETS
        public Segment GetSegmentAt(SegmentLocation segmentLocation)
        {
            if (IsLocationInRange(segmentLocation))
            {
                return(Segments[segmentLocation.SegmentX, segmentLocation.SegmentZ]);
            }

            return(_nullSegment);
        }
        public bool DoesLocationObscureDirection(SegmentLocation segmentLocation, Vector3 direction)
        {
            if (IsLocationInRange(segmentLocation))
            {
                return(BlockHelper.DoesBlockMaskObscureFromDirection(GetBlockMaskAt(segmentLocation), direction));
            }

            return(false);
        }
        public bool IsLocationObstructed(SegmentLocation segmentLocation)
        {
            if (IsLocationInRange(segmentLocation))
            {
                return(BlockHelper.IsBlockAnObstacle(GetBlockMaskAt(segmentLocation)));
            }

            return(true);
        }
        public BlockMask GetBlockMaskAt(SegmentLocation segmentLocation)
        {
            if (IsLocationInRange(segmentLocation))
            {
                return
                    (GetRenderSegmentAt(segmentLocation).Blocks[
                         segmentLocation.BlockX, segmentLocation.RenderSegmentBlockMaskIndex, segmentLocation.BlockZ]);
            }

            return(BlockHelper.BlockMasks.Null);
        }
 // QUERIES
 public bool IsLocationBlockedExcludeItems(SegmentLocation segmentLocation)
 {
     if (GetBlockMaskAt(segmentLocation) == BlockHelper.BlockMasks.AirBlocked)
     {
         return(false);
     }
     else
     {
         return(IsLocationObstructed(segmentLocation));
     }
 }
        public bool IsLocationInRange(SegmentLocation segmentLocation)
        {
            if (segmentLocation.WorldLocation.X < 0 || segmentLocation.WorldLocation.Y < 0 ||
                segmentLocation.WorldLocation.Z < 0)
            {
                return(false);
            }
            if (segmentLocation.WorldLocation.X >= Segments.GetLength(0) * WorldGlobal.RenderSegmentSize.X ||
                segmentLocation.WorldLocation.Z >= Segments.GetLength(1) * WorldGlobal.RenderSegmentSize.Z ||
                segmentLocation.WorldLocation.Y >= WorldGlobal.SegmentSize.Y)
            {
                return(false);
            }

            return(true);
        }
        public bool IsLocationWalkable(SegmentLocation segmentLocation)
        {
            if (IsLocationInRange(segmentLocation))
            {
                if (IsLocationObstructed(segmentLocation))
                {
                    return(false);
                }

                BlockMask blockBelow = GetBlockMaskAt(segmentLocation.TranslateAndClone(WorldDirection.Down));

                if (BlockHelper.IsBlock(blockBelow) || BlockHelper.HasTopRamp(blockBelow))
                {
                    return(true);
                }
            }

            return(false);
        }
 // SETS
 public void ClearItemsObstacleFlag(SegmentLocation segmentLocation)
 {
     GetRenderSegmentAt(segmentLocation).Blocks[
         segmentLocation.BlockX, segmentLocation.RenderSegmentBlockMaskIndex, segmentLocation.BlockZ] =
         BlockHelper.BlockMasks.Air;
 }
 public SegmentRender GetRenderSegmentAt(SegmentLocation segmentLocation)
 {
     return(GetSegmentAt(segmentLocation).RenderSegments[segmentLocation.RenderSegmentIndex]);
 }