예제 #1
0
파일: BaseDistCalc.cs 프로젝트: MK4H/MHUrho
        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);
            }
        }
예제 #2
0
파일: Chicken.cs 프로젝트: MK4H/MHUrho
            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);
            }
예제 #3
0
            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);
            }
예제 #4
0
파일: Chicken.cs 프로젝트: MK4H/MHUrho
            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);
            }
예제 #5
0
파일: Chicken.cs 프로젝트: MK4H/MHUrho
            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);
            }
예제 #6
0
파일: Chicken.cs 프로젝트: MK4H/MHUrho
            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);
            }
예제 #7
0
파일: Keep.cs 프로젝트: MK4H/MHUrho
        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);
        }
예제 #8
0
            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);
            }
예제 #9
0
        //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);
        }
예제 #10
0
파일: TempNode.cs 프로젝트: MK4H/MHUrho
 public void Accept(INodeVisitor visitor, ITileNode source, MovementType movementType)
 {
     visitor.Visit(source, this, movementType);
 }
예제 #11
0
 void INodeVisitor.Visit(ITempNode source, ITileNode target, MovementType movementType)
 {
     canPass = GetTime(source, target, movementType, out resTime);
 }
예제 #12
0
파일: Chicken.cs 프로젝트: MK4H/MHUrho
 protected override bool CanTeleport(IBuildingNode source, ITileNode target)
 {
     return(CanPassToTileNode(target));
 }
예제 #13
0
파일: Chicken.cs 프로젝트: MK4H/MHUrho
 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);
 }
예제 #14
0
파일: Chicken.cs 프로젝트: MK4H/MHUrho
 protected override bool CanPass(ITileNode source, IBuildingNode target)
 {
     return(CanPassToBuildingNode(target));
 }
예제 #15
0
파일: Node.cs 프로젝트: MK4H/MHUrho
 public abstract void Accept(INodeVisitor visitor, ITileNode source, MovementType movementType);
예제 #16
0
파일: BaseDistCalc.cs 프로젝트: MK4H/MHUrho
 protected abstract bool CanPass(IBuildingNode source, ITileNode target);
예제 #17
0
파일: BaseDistCalc.cs 프로젝트: MK4H/MHUrho
 protected abstract bool CanTeleport(IBuildingNode source, ITileNode target);
예제 #18
0
파일: TileNode.cs 프로젝트: MK4H/MHUrho
 public Vector3 GetEdgePosition(ITileNode other)
 {
     //NOTE: If this is slow, cache it at construction
     return(Map.GetBorderBetweenTiles(Tile, other.Tile));
 }