protected sealed override bool GetTime(IBuildingNode source, ITileNode target, MovementType movementType, out float time) { switch (movementType) { case MovementType.Linear: if (!CanPass(source, target)) { time = -1; return(false); } time = GetLinearTime(source.Position, target.Position); return(true); case MovementType.Teleport: if (!CanTeleport(source, target)) { time = -1; return(false); } time = GetTeleportTime(source, target); return(true); default: time = -1; return(false); } }
protected override bool CanTeleport(IBuildingNode source, ITileNode target) { if (base.CanTeleport(source, target)) { return(true); } if (!Instance.myType.PassableTileTypes.Contains(target.Tile.Type)) { return(false); } CanBreakThrough.Add(target.Tile); return(true); }
protected override bool CanPass(ITileNode source, IBuildingNode target) { if (base.CanPass(source, target)) { return(true); } if (!CanPassToBuilding(target)) { return(false); } CanBreakThrough.Add(Map.GetContainingTile(target.Position)); return(true); }
protected override bool CanPass(ITileNode source, ITileNode target) { if (!CanPassToTileNode(target)) { return(false); } //If the edge is diagonal and there are buildings on both sides of the edge, dont go there return(source.Tile.MapLocation.X == target.Tile.MapLocation.X || source.Tile.MapLocation.Y == target.Tile.MapLocation.Y || Map.GetTileByMapLocation(new IntVector2(source.Tile.MapLocation.X, target.Tile.MapLocation.Y)) .Building == null || Map.GetTileByMapLocation(new IntVector2(target.Tile.MapLocation.X, source.Tile.MapLocation.Y)) .Building == null); }
protected override bool CanTeleport(ITileNode source, ITileNode target) { if (base.CanTeleport(source, target)) { return(true); } if (!CanPassToTile(target)) { return(false); } CanBreakThrough.Add(target.Tile); return(true); }
bool CanPassToTile(ITileNode target) { if (!Instance.myType.PassableTileTypes.Contains(target.Tile.Type)) { return(false); } if (target.Tile.Building != null && (target.Tile.Building.Player == Level.NeutralPlayer || Instance.Unit.Player.IsFriend(target.Tile.Building.Player))) { return(false); } return(true); }
void CreatePathfindingNodes() { for (int y = Building.Rectangle.Top; y < Building.Rectangle.Bottom; y++) { for (int x = Building.Rectangle.Left; x < Building.Rectangle.Right; x++) { ITile tile = Level.Map.GetTileByTopLeftCorner(x, y); Vector3 position = new Vector3(tile.Center.X, GetHeightAt(tile.Center.X, tile.Center.Y).Value, tile.Center.Y); IBuildingNode node = Level.Map.PathFinding.CreateBuildingNode(Building, position, KeepTag); nodes.Add(tile, node); } } //Connect roof edges foreach (var tileAndNode in nodes) { ITile tile = tileAndNode.Key; IBuildingNode node = tileAndNode.Value; foreach (var neighbour in tile.GetNeighbours()) { if (neighbour == null) { continue; } //Connect to neighbor roof nodes if (nodes.TryGetValue(neighbour, out IBuildingNode neighbourNode)) { node.CreateEdge(neighbourNode, MovementType.Linear); } //Connects just to own nodes, does not connect to other buildings. } } //Connect to tile in front var buildingFrontTile = Level.Map.GetContainingTile(Building.Center + Building.Forward * 2); ITileNode tileNode = Level.Map.PathFinding.GetTileNode(TileInFront); IBuildingNode buildingNode = nodes[buildingFrontTile]; tileNode.CreateEdge(buildingNode, MovementType.Teleport); buildingNode.CreateEdge(tileNode, MovementType.Teleport); }
protected override bool CanPass(ITileNode source, ITileNode target) { if (base.CanPass(source, target)) { return(true); } if (!CanPassToTile(target)) { return(false); } //Diagonal if (source.Tile.MapLocation.X != target.Tile.MapLocation.X && source.Tile.MapLocation.Y != target.Tile.MapLocation.Y) { //Blocked by own or neutral buildings we can't destroy var building1 = Map .GetTileByMapLocation(new IntVector2(source.Tile.MapLocation.X, target.Tile.MapLocation.Y)) .Building; var building2 = Map .GetTileByMapLocation(new IntVector2(target.Tile.MapLocation.X, source.Tile.MapLocation.Y)) .Building; if (building1 != null && building2 != null && (building1.Player == Level.NeutralPlayer || Instance.Unit.Player.IsFriend(building1.Player)) && (building2.Player == Level.NeutralPlayer || Instance.Unit.Player.IsFriend(building2.Player))) { return(false); } } CanBreakThrough.Add(target.Tile); return(true); }
//These methods are for the user to reimplement /// <summary> /// Gets if it is possible to get from <paramref name="source"/> TILE node to <paramref name="target"/> TILE node, /// if true, then returns the time needed in <paramref name="time"/> /// </summary> /// <param name="source">Source node</param> /// <param name="target">Target node</param> /// <param name="movementType">Movement type from <paramref name="source"/> to <paramref name="target"/>.</param> /// <param name="time">Result time it will take to get from <paramref name="source"/> to <paramref name="target"/></param> /// <returns>If it is possible to get to the</returns> protected virtual bool GetTime(ITileNode source, ITileNode target, MovementType movementType, out float time) { time = -1; return(false); }
public void Accept(INodeVisitor visitor, ITileNode source, MovementType movementType) { visitor.Visit(source, this, movementType); }
void INodeVisitor.Visit(ITempNode source, ITileNode target, MovementType movementType) { canPass = GetTime(source, target, movementType, out resTime); }
protected override bool CanTeleport(IBuildingNode source, ITileNode target) { return(CanPassToTileNode(target)); }
bool CanPassToTileNode(ITileNode target) { //Is passable and is not covered by a building return(Instance.myType.PassableTileTypes.Contains(target.Tile.Type) && target.Tile.Building == null); }
protected override bool CanPass(ITileNode source, IBuildingNode target) { return(CanPassToBuildingNode(target)); }
public abstract void Accept(INodeVisitor visitor, ITileNode source, MovementType movementType);
protected abstract bool CanPass(IBuildingNode source, ITileNode target);
protected abstract bool CanTeleport(IBuildingNode source, ITileNode target);
public Vector3 GetEdgePosition(ITileNode other) { //NOTE: If this is slow, cache it at construction return(Map.GetBorderBetweenTiles(Tile, other.Tile)); }