public static void AppendDangerousTerrainText(MoveStatusPreview __instance, AbstractActor actor, Vector3 worldPos) { try { MapTerrainDataCell cell = Combat.EncounterLayerData.GetCellAt(worldPos).relatedTerrainCell; bool isLandingZone = SplatMapInfo.IsDropshipLandingZone(cell.terrainMask), isDangerous = SplatMapInfo.IsDangerousLocation(cell.terrainMask); if (!isLandingZone && !isDangerous) { return; } DesignMaskDef mask = Combat.MapMetaData.GetPriorityDesignMask(cell); if (mask == null) { return; } string title = mask.Description.Name, text = mask.Description.Details; CombatUIConstantsDef desc = Combat.Constants.CombatUIConstants; if (isDangerous) { title += " <#FF0000>(" + desc.DangerousLocationDesc.Name + ")"; text += " <#FF0000>" + desc.DangerousLocationDesc.Details; if (isLandingZone) { text += " " + desc.DrophipLocationDesc.Details; } } else { title += " <#FF0000>(" + desc.DrophipLocationDesc.Name + ")"; text += " <#FF0000>" + desc.DrophipLocationDesc.Details; } CombatHUDInfoSidePanel sidePanel = (CombatHUDInfoSidePanel)SidePanelProp?.GetValue(__instance, null); sidePanel?.ForceShowSingleFrame(new Text(title), new Text(text), null, false); } catch (Exception ex) { Error(ex); } }
private bool IsCellImpassableOrDeepWater(MapTerrainDataCell cellData) { TerrainMaskFlags terrainMask = cellData.terrainMask; bool isImpassableOrDeepWater = SplatMapInfo.IsImpassable(terrainMask) || (SplatMapInfo.IsDeepWater(terrainMask) && !cellData.MapEncounterLayerDataCell.HasBuilding); if (isImpassableOrDeepWater) { Main.LogDebug("[PFM.IsCellImpassableOrDeepWater] Tile is impassable or deep water"); return(true); } return(false); }
public static bool IsLocationSafe(CombatGameState combat, Vector3 point) { MapTerrainDataCell dataCell = combat.MapMetaData.GetCellAt(point); return(!(SplatMapInfo.IsDropshipLandingZone(dataCell.terrainMask) || SplatMapInfo.IsDropPodLandingZone(dataCell.terrainMask) || SplatMapInfo.IsDangerousLocation(dataCell.terrainMask))); }
/// <summary> /// Finds a path from any of start to goal, such that the path has no links that are steeper than the unit's maxGrade. /// </summary> /// <returns>The path.</returns> /// <param name="startPointList">List of PointWithDistances for points to start from</param> /// <param name="snappedGoalPoint">HexPoint3 to go to</param> /// <param name="unit">moving unit</param> /// <param name="moveType">move type - walk, sprint</param> /// <param name="targetRadius">how close to get to the target</param> /// <param name="actorAware">Discard nodes where other actors reside</param> public static List <PointWithCost> FindPath(List <PointWithCost> startPointList, HexPoint3 snappedGoalPoint, AbstractActor unit, MoveType moveType, float targetRadius, bool actorAware) { MapMetaData mapMetaData = unit.Combat.MapMetaData; HexGrid hexGrid = unit.Combat.HexGrid; unit.Pathing.MoveType = moveType; List <AbstractActor> actors = null; bool startedInEncounterBounds = false; BattleTech.Designed.EncounterBoundaryChunkGameLogic boundaryChunk = unit.Combat.EncounterLayerData.encounterBoundaryChunk; for (int spi = 0; spi < startPointList.Count; ++spi) { PointWithCost sp = startPointList[spi]; //Vector3 wp = HexPoint3ToWorldPoint(sp.point, hexGrid); if (boundaryChunk.IsInEncounterBounds(unit.CurrentPosition)) { startedInEncounterBounds = true; break; } } actorAware = unit.BehaviorTree.GetBehaviorVariableValue(BehaviorVariableName.Bool_EnableLongRangePathfindingBeActorAware).BoolVal ? true : actorAware; if (actorAware) { actors = unit.Combat.AllActors; actors.Remove(unit); } List <PointWithCost> path = new List <PointWithCost>(); HeapQueue <PointWithCost> openHeap = new HeapQueue <PointWithCost>(); Dictionary <HexPoint3, float> bestCostDict = new Dictionary <HexPoint3, float>(); Dictionary <HexPoint3, PointWithCost> bestPrevPoint = new Dictionary <HexPoint3, PointWithCost>(); Vector3 worldGoalPoint = HexPoint3ToWorldPoint(snappedGoalPoint, hexGrid); float bestPathCost = float.MaxValue; bool anyPathFound = false; PointWithCost bestGoalPoint = new PointWithCost(new HexPoint3(-4000, -4000), float.MaxValue, float.MaxValue); for (int startIndex = 0; startIndex < startPointList.Count; ++startIndex) { PointWithCost pwd = startPointList[startIndex]; openHeap.Push(pwd); bestCostDict[pwd.point] = pwd.cost; bestPrevPoint[pwd.point] = null; Vector3 wp = HexPoint3ToWorldPoint(pwd.point, hexGrid); if ((pwd.point.Equals(snappedGoalPoint)) || (AIUtil.Get2DDistanceBetweenVector3s(wp, worldGoalPoint) < targetRadius)) { if (pwd.cost < bestPathCost) { anyPathFound = true; bestPathCost = pwd.cost; bestGoalPoint = pwd; } } } while (!openHeap.IsEmpty()) { PointWithCost ptWithCost = openHeap.PopMinimum(); if (ptWithCost.estimatedTotalCost > bestPathCost) { continue; } Vector3 worldPoint = HexPoint3ToWorldPoint(ptWithCost.point, hexGrid); if (actorAware && CheckForOccupiedPoint(actors, worldPoint)) { continue; } if (startedInEncounterBounds && (!boundaryChunk.IsInEncounterBounds(worldPoint))) { continue; } for (int direction = 0; direction < 6; ++direction) { HexPoint3 neighborHexPoint = ptWithCost.point.Step(direction, 1); Vector3 neighborWorldPoint = HexPoint3ToWorldPoint(neighborHexPoint, hexGrid); if ((!mapMetaData.IsWithinBounds(neighborWorldPoint)) || (unit.Pathing.CurrentGrid.FindBlockerReciprocal(worldPoint, neighborWorldPoint))) { continue; } Debug.DrawLine(worldPoint, neighborWorldPoint, Color.yellow, 15.0f); float linkCost = unit.Pathing.CurrentGrid.GetTerrainModifiedCost(worldPoint, neighborWorldPoint); float newCost = ptWithCost.cost + linkCost; if (newCost >= bestPathCost) { continue; } if ((!bestCostDict.ContainsKey(neighborHexPoint)) || (newCost < bestCostDict[neighborHexPoint])) { bestCostDict[neighborHexPoint] = newCost; bestPrevPoint[neighborHexPoint] = ptWithCost; if ((neighborHexPoint.Equals(snappedGoalPoint)) || ((neighborWorldPoint - worldGoalPoint).magnitude < targetRadius)) { if (newCost < bestPathCost) { anyPathFound = true; bestPathCost = newCost; bestGoalPoint = new PointWithCost(neighborHexPoint, newCost, 0.0f); } } else { Vector3 remainingDistance = (worldGoalPoint - neighborWorldPoint); float estRemainingCost = remainingDistance.magnitude; openHeap.Push(new PointWithCost(neighborHexPoint, newCost, newCost + estRemainingCost)); } } } } if (anyPathFound) { PointWithCost p = bestGoalPoint; path.Add(p); while (bestPrevPoint.ContainsKey(p.point)) { PointWithCost prevPoint = bestPrevPoint[p.point]; if ((prevPoint == null) || (path.Contains(prevPoint))) { break; } path.Insert(0, prevPoint); p = prevPoint; } } else { // draw the failed path data const int SIDES = 3; const float RADIUS = 12; foreach (PointWithCost startPoint in startPointList) { Vector3 worldStartPoint = HexPoint3ToWorldPoint(startPoint.point, hexGrid); for (int i = 0; i < SIDES; ++i) { float dx0 = RADIUS * Mathf.Cos(i * Mathf.PI * 2 / SIDES); float dz0 = RADIUS * Mathf.Sin(i * Mathf.PI * 2 / SIDES); float dx1 = RADIUS * Mathf.Cos((i + 1) * Mathf.PI * 2 / SIDES); float dz1 = RADIUS * Mathf.Sin((i + 1) * Mathf.PI * 2 / SIDES); Vector3 wp0 = new Vector3(worldStartPoint.x + dx0, 0, worldStartPoint.z + dz0); Vector3 wp1 = new Vector3(worldStartPoint.x + dx1, 0, worldStartPoint.z + dz1); Debug.DrawLine(wp0, wp1, Color.magenta, 15.0f); } } Vector3 worldEndPoint = HexPoint3ToWorldPoint(snappedGoalPoint, hexGrid); Color orangeColor = new Color(1.0f, 0.5f, 0.0f); for (int i = 0; i < SIDES; ++i) { float dx0 = RADIUS * Mathf.Cos(i * Mathf.PI * 2 / SIDES); float dz0 = RADIUS * Mathf.Sin(i * Mathf.PI * 2 / SIDES); float dx1 = RADIUS * Mathf.Cos((i + 1) * Mathf.PI * 2 / SIDES); float dz1 = RADIUS * Mathf.Sin((i + 1) * Mathf.PI * 2 / SIDES); Vector3 wp0 = new Vector3(worldEndPoint.x + dx0, 0, worldEndPoint.z + dz0); Vector3 wp1 = new Vector3(worldEndPoint.x + dx1, 0, worldEndPoint.z + dz1); Debug.DrawLine(wp0, wp1, orangeColor, 15.0f); } } int removedCount = 0; // Now, check to see if the end of the path is in "danger". If it is, prune until it's not, which might lead to an empty path. while (path.Count > 0) { PointWithCost lastHexPoint = path[path.Count - 1]; Vector3 lastWorldPoint = HexPoint3ToWorldPoint(lastHexPoint.point, hexGrid); MapTerrainDataCell dataCell = unit.Combat.MapMetaData.GetCellAt(lastWorldPoint); if (SplatMapInfo.IsDropshipLandingZone(dataCell.terrainMask) || SplatMapInfo.IsDangerousLocation(dataCell.terrainMask) || SplatMapInfo.IsDropPodLandingZone(dataCell.terrainMask)) { path.RemoveAt(path.Count - 1); ++removedCount; } else { break; } } if (removedCount > 0) { if (path.Count == 0) { BehaviorNode.LogAI(unit, string.Format("DANGER TRIM: removed all {0} points, bracing", removedCount)); } else { BehaviorNode.LogAI(unit, string.Format("DANGER TRIM: removed {0} points, moving to {1}", removedCount, path[path.Count - 1])); } } return(path); }