public bool IsBlocked(BoundingBox box) { int num = Terrain.ToCell(box.Min.X); int num2 = MathUtils.Max(Terrain.ToCell(box.Min.Y), 0); int num3 = Terrain.ToCell(box.Min.Z); int num4 = Terrain.ToCell(box.Max.X); int num5 = MathUtils.Min(Terrain.ToCell(box.Max.Y), 255); int num6 = Terrain.ToCell(box.Max.Z); for (int i = num; i <= num4; i++) { for (int j = num3; j <= num6; j++) { TerrainChunk chunkAtCell = SubsystemTerrain.Terrain.GetChunkAtCell(i, j); if (chunkAtCell == null) { continue; } int num7 = TerrainChunk.CalculateCellIndex(i & 0xF, num2, j & 0xF); int num8 = num2; while (num8 <= num5) { int cellValueFast = chunkAtCell.GetCellValueFast(num7); int num9 = Terrain.ExtractContents(cellValueFast); if (num9 != 0) { Block block = BlocksManager.Blocks[num9]; if (block.ShouldAvoid(cellValueFast)) { return(true); } if (block.IsCollidable) { Vector3 v = new Vector3(i, num8, j); BoundingBox[] customCollisionBoxes = block.GetCustomCollisionBoxes(SubsystemTerrain, cellValueFast); for (int k = 0; k < customCollisionBoxes.Length; k++) { BoundingBox boundingBox = customCollisionBoxes[k]; if (box.Intersection(new BoundingBox(v + boundingBox.Min, v + boundingBox.Max))) { return(true); } } } } num8++; num7++; } } } return(false); }
public static bool SmoothingRaycastFunction_Support(int value, float distance) { int num = Terrain.ExtractContents(value); Block block = BlocksManager.Blocks[num]; if (block.ShouldAvoid(value)) { return(true); } if (!block.IsCollidable) { return(true); } return(false); }
public bool IsTerrainSafeToGo(Vector3 position, Vector3 direction) { Vector3 vector = position + new Vector3(0f, 0.1f, 0f) + ((direction.LengthSquared() < 1.2f) ? new Vector3(direction.X, 0f, direction.Z) : (1.2f * Vector3.Normalize(new Vector3(direction.X, 0f, direction.Z)))); for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { if (!(Vector3.Dot(direction, new Vector3(i, 0f, j)) > 0f)) { continue; } for (int num = 0; num >= -2; num--) { int cellValue = m_subsystemTerrain.Terrain.GetCellValue(Terrain.ToCell(vector.X) + i, Terrain.ToCell(vector.Y) + num, Terrain.ToCell(vector.Z) + j); Block block = BlocksManager.Blocks[Terrain.ExtractContents(cellValue)]; if (block.ShouldAvoid(cellValue)) { return(false); } if (block.IsCollidable) { break; } } } } Vector3 vector2 = position + new Vector3(0f, 0.1f, 0f) + ((direction.LengthSquared() < 1f) ? new Vector3(direction.X, 0f, direction.Z) : (1f * Vector3.Normalize(new Vector3(direction.X, 0f, direction.Z)))); bool flag = true; int num2 = TakeRisks ? 7 : 5; for (int num3 = 0; num3 >= -num2; num3--) { int cellValue2 = m_subsystemTerrain.Terrain.GetCellValue(Terrain.ToCell(vector2.X), Terrain.ToCell(vector2.Y) + num3, Terrain.ToCell(vector2.Z)); Block block2 = BlocksManager.Blocks[Terrain.ExtractContents(cellValue2)]; if ((block2.IsCollidable || block2.BlockIndex == 18) && !block2.ShouldAvoid(cellValue2)) { flag = false; break; } } if (flag) { return(false); } return(true); }
public void AddNeighbor(DynamicArray <Vector3> neighbors, Vector3 p, int dx, int dz) { float y = p.Y; float num = p.Y; int num2 = Terrain.ToCell(p.X) + dx; int num3 = Terrain.ToCell(p.Y); int num4 = Terrain.ToCell(p.Z) + dz; int cellValue = SubsystemTerrain.Terrain.GetCellValue(num2, num3, num4); int num5 = Terrain.ExtractContents(cellValue); Block block = BlocksManager.Blocks[num5]; if (block.ShouldAvoid(cellValue)) { return; } if (block.IsCollidable) { float blockWalkingHeight = GetBlockWalkingHeight(block, cellValue); if (blockWalkingHeight > 0.5f && (block.NoAutoJump || block.NoSmoothRise)) { return; } y = (float)num3 + blockWalkingHeight; num = (float)num3 + blockWalkingHeight; } else { bool flag = false; for (int num6 = -1; num6 >= -4; num6--) { int cellValue2 = SubsystemTerrain.Terrain.GetCellValue(num2, num3 + num6, num4); int num7 = Terrain.ExtractContents(cellValue2); Block block2 = BlocksManager.Blocks[num7]; if (block2.ShouldAvoid(cellValue2)) { return; } if (block2.IsCollidable) { y = num3 + num6 + 1; flag = true; break; } } if (!flag) { return; } } int num8 = (dx == 0 || dz == 0) ? 2 : 3; Vector3 vector = new Vector3(p.X, num + 0.01f, p.Z); Vector3 v = new Vector3((float)num2 + 0.5f, num + 0.01f, (float)num4 + 0.5f); Vector3 v2 = 1f / (float)num8 * (v - vector); for (int i = 1; i <= num8; i++) { Vector3 v3 = vector + i * v2; BoundingBox box = new BoundingBox(v3 - new Vector3(Request.BoxSize.X / 2f + 0.01f, 0f, Request.BoxSize.Z / 2f + 0.01f), v3 + new Vector3(Request.BoxSize.X / 2f - 0.01f, Request.BoxSize.Y, Request.BoxSize.Z / 2f - 0.01f)); if (IsBlocked(box)) { return; } } neighbors.Add(new Vector3((float)num2 + 0.5f, y, (float)num4 + 0.5f)); }