private bool CanMoveTo_Cardinal__CanOccupy(int targetX, int targetY, BlocksetBlockBehavior curBehavior, BlocksetBlockBehavior blockedTarget, bool checkElevation, byte curElevation) { // Get the x/y/map of the target block Map.GetXYMap(targetX, targetY, out int outX, out int outY, out Map outMap); Map.Layout.Block targetBlock = outMap.GetBlock_InBounds(outX, outY); // Check occupancy permission if ((targetBlock.Passage & LayoutBlockPassage.AllowOccupancy) == 0) { return(false); } // Check block behaviors BlocksetBlockBehavior targetBehavior = targetBlock.BlocksetBlock.Behavior; if (targetBehavior == BlocksetBlockBehavior.Surf || targetBehavior == blockedTarget) { return(false); } // Check elevation byte targetElevations = targetBlock.Elevations; if (checkElevation && !ElevationCheck(curBehavior, targetBehavior, curElevation, targetElevations)) { return(false); } byte newElevation = GetElevationIfMovedTo(curElevation, targetElevations); // Check if we can pass through objs at the position if (CollidesWithAny_InBounds(outMap, outX, outY, newElevation)) { return(false); } return(true); }
private bool CanPassThroughDiagonally(int x, int y, byte elevation, LayoutBlockPassage diagonalPassage, BlocksetBlockBehavior blockedCardinal1, BlocksetBlockBehavior blockedCardinal2, BlocksetBlockBehavior blockedDiagonal) { // Get the x/y/map of the block Map.GetXYMap(x, y, out int outX, out int outY, out Map outMap); Map.Layout.Block block = outMap.GetBlock_InBounds(outX, outY); // Check occupancy permission if ((block.Passage & diagonalPassage) == 0) { return(false); } // Check block behaviors BlocksetBlockBehavior blockBehavior = block.BlocksetBlock.Behavior; if (blockBehavior == blockedCardinal1 || blockBehavior == blockedCardinal2 || blockBehavior == blockedDiagonal) { return(false); } // Check if we can pass through objs at the position (only checks current elevation, not the target elevation or any other elevations) if (CollidesWithAny_InBounds(outMap, outX, outY, elevation)) { return(false); } return(true); }
// Southwest/Southeast/Northwest/Northeast private bool CanMoveTo_Diagonal(int targetX, int targetY, LayoutBlockPassage neighbor1Passage, int neighbor1X, int neighbor1Y, LayoutBlockPassage neighbor2Passage, int neighbor2X, int neighbor2Y, BlocksetBlockBehavior blockedCurrentCardinal1, BlocksetBlockBehavior blockedCurrentCardinal2, BlocksetBlockBehavior blockedCurrentDiagonal, BlocksetBlockBehavior blockedTargetCardinal1, BlocksetBlockBehavior blockedTargetCardinal2, BlocksetBlockBehavior blockedTargetDiagonal, BlocksetBlockBehavior blockedNeighbor1, BlocksetBlockBehavior blockedNeighbor2) { // Current block - return false if we are blocked Position p = Pos; Map.Layout.Block curBlock = Map.GetBlock_CrossMap(p.X, p.Y); BlocksetBlockBehavior curBehavior = curBlock.BlocksetBlock.Behavior; if (curBehavior == blockedCurrentCardinal1 || curBehavior == blockedCurrentCardinal2 || curBehavior == blockedCurrentDiagonal) { return(false); } // Target block - return false if we are blocked Map.GetXYMap(targetX, targetY, out int targetOutX, out int targetOutY, out Map targetOutMap); Map.Layout.Block targetBlock = targetOutMap.GetBlock_InBounds(targetOutX, targetOutY); if ((targetBlock.Passage & LayoutBlockPassage.AllowOccupancy) == 0) { return(false); } // Check block behaviors BlocksetBlockBehavior targetBehavior = targetBlock.BlocksetBlock.Behavior; if (targetBehavior == BlocksetBlockBehavior.Surf || targetBehavior == blockedTargetCardinal1 || targetBehavior == blockedTargetCardinal2 || targetBehavior == blockedTargetDiagonal) { return(false); } // Check elevation byte curElevation = p.Elevation; byte targetElevations = targetBlock.Elevations; if (!ElevationCheck(curBehavior, targetBehavior, curElevation, targetElevations)) { return(false); } byte newElevation = GetElevationIfMovedTo(curElevation, targetElevations); // Check if we can pass through objs at the position if (CollidesWithAny_InBounds(targetOutMap, targetOutX, targetOutY, newElevation)) { return(false); } // Target's neighbors - check if we can pass through them diagonally if (!CanPassThroughDiagonally(neighbor1X, neighbor1Y, curElevation, neighbor1Passage, blockedTargetCardinal2, blockedTargetCardinal1, blockedNeighbor1) || !CanPassThroughDiagonally(neighbor2X, neighbor2Y, curElevation, neighbor2Passage, blockedTargetCardinal1, blockedTargetCardinal2, blockedNeighbor2)) { return(false); } return(true); }
// West/East private bool CanMoveTo_Cardinal_ConsiderStairs(int targetX, int targetY, bool allowSurf, BlocksetBlockBehavior blockedCurrent, BlocksetBlockBehavior blockedTarget, BlocksetBlockBehavior upBehavior, BlocksetBlockBehavior downBehavior) { // Current block - return false if we are blocked Position p = Pos; Map.Layout.Block curBlock = Map.GetBlock_InBounds(p.X, p.Y); BlocksetBlockBehavior curBehavior = curBlock.BlocksetBlock.Behavior; if (curBehavior == blockedCurrent) { return(false); } // Stairs - check if we can go up a stair that's above our target Map.GetXYMap(targetX, targetY - 1, out int upStairX, out int upStairY, out Map upStairMap); Map.Layout.Block upStairBlock = upStairMap.GetBlock_InBounds(upStairX, upStairY); if ((upStairBlock.Passage & LayoutBlockPassage.AllowOccupancy) != 0) { BlocksetBlockBehavior upStairBehavior = upStairBlock.BlocksetBlock.Behavior; if (upStairBehavior == upBehavior) { // Check if we can pass through objs on the position byte newElevation = Overworld.GetElevationIfMovedTo(p.Elevation, upStairBlock.Elevations); if (CollidesWithAny_InBounds(upStairMap, upStairX, upStairY, newElevation)) { return(false); } return(true); } } bool canChangeElevation = false; // Stairs - If we are on a down stair, then we will be going to the block diagonally below us if (curBehavior == downBehavior) { canChangeElevation = true; targetY++; } else if (curBehavior == upBehavior) { canChangeElevation = true; } // Target block - return false if we are blocked if (!CanMoveTo_Cardinal__CanOccupy(targetX, targetY, allowSurf, curBehavior, blockedTarget, !canChangeElevation, p.Elevation)) { return(false); } return(true); }
// South/North private bool CanMoveTo_Cardinal(int targetX, int targetY, bool allowSurf, BlocksetBlockBehavior blockedCurrent, BlocksetBlockBehavior blockedTarget) { // Current block - return false if we are blocked Position p = Pos; Map.Layout.Block curBlock = Map.GetBlock_InBounds(p.X, p.Y); BlocksetBlockBehavior curBehavior = curBlock.BlocksetBlock.Behavior; if (curBehavior == blockedCurrent) { return(false); } // Target block - return false if we are blocked if (!CanMoveTo_Cardinal__CanOccupy(targetX, targetY, allowSurf, curBehavior, blockedTarget, true, p.Elevation)) { return(false); } return(true); }
private void ApplyStairMovement(Position curPos, BlocksetBlockBehavior upBehavior, BlocksetBlockBehavior downBehavior) { Map.Layout.Block curBlock = Map.GetBlock_InBounds(curPos.X, curPos.Y); BlocksetBlockBehavior curBehavior = curBlock.BlocksetBlock.Behavior; if (curBehavior == downBehavior) { Pos.Y++; } Position newPos = Pos; int newX = newPos.X; int newY = newPos.Y; Map.Layout.Block upStairBlock = Map.GetBlock_CrossMap(newX, newY - 1, out _, out _, out _); BlocksetBlockBehavior upStairBehavior = upStairBlock.BlocksetBlock.Behavior; if (upStairBehavior == upBehavior) { Pos.Y--; Pos.YOffset = StairYOffset; return; } Map.Layout.Block newBlock = Map.GetBlock_CrossMap(newX, newY, out _, out _, out _); BlocksetBlockBehavior newBehavior = newBlock.BlocksetBlock.Behavior; if (newBehavior == downBehavior) { Pos.YOffset = StairYOffset; } else { Pos.YOffset = 0; } }