Esempio n. 1
0
        protected override List <MovementAlgorithmTile> AddSuccessor(MovementAlgorithmTile ActiveNode, float OffsetX, float OffsetY, int LayerIndex)
        {
            List <MovementAlgorithmTile> ListTerrainSuccessor = new List <MovementAlgorithmTile>();
            List <int> ListLayerPossibility;

            Map.GetNextLayerIndex(new Vector3(ActiveNode.Position.X, ActiveNode.Position.Y, LayerIndex), (int)OffsetX, (int)OffsetY, 1f, 15, out ListLayerPossibility);

            foreach (int ActiveLayerIndex in ListLayerPossibility)
            {
                MovementAlgorithmTile ActiveTile = GetTile(ActiveNode.Position.X + OffsetX, ActiveNode.Position.X + OffsetY, ActiveLayerIndex);
                //Wall
                if (ActiveTile == null || ActiveTile.MVEnterCost == -1 || ActiveTile.MovementCost == -1 ||
                    ActiveTile.TerrainTypeIndex == UnitStats.TerrainWallIndex || ActiveTile.TerrainTypeIndex == UnitStats.TerrainVoidIndex)
                {
                    continue;
                }

                //If the NewNode is the parent, skip it.
                if (ActiveNode.ParentTemp == null)
                {
                    //Used for an undefined map or if you don't need to calculate the whole map.
                    //ListSuccessors.Add(new AStarNode(ActiveNode, AX, AY));
                    ActiveTile.ParentTemp = ActiveNode;
                    ListTerrainSuccessor.Add(ActiveTile);
                }
            }

            return(ListTerrainSuccessor);
        }
Esempio n. 2
0
        private void ComputeNewHoverPath()
        {
            ListMovedOverTerrain.Clear();
            ListMovedOverPoint.Clear();

            MovementAlgorithmTile CurrentTerrain = Map.GetTerrain(Map.CursorPosition.X, Map.CursorPosition.Y, (int)Map.CursorPosition.Z);

            do
            {
                if (!ListMovedOverTerrain.Contains(CurrentTerrain))
                {
                    ListMovedOverTerrain.Add(CurrentTerrain);
                    ListMovedOverPoint.Add(new Vector3(CurrentTerrain.Position.X, CurrentTerrain.Position.Y, CurrentTerrain.LayerIndex));
                    if (CurrentTerrain.Position == ActiveSquad.Position)
                    {
                        CurrentTerrain = null;
                    }
                    else
                    {
                        CurrentTerrain = CurrentTerrain.ParentReal;
                    }
                }
                else
                {
                    CurrentTerrain = null;
                }
            }while (CurrentTerrain != null);

            ListMovedOverTerrain.Reverse();
            ListMovedOverPoint.Reverse();
        }
Esempio n. 3
0
        private void AddHoverChoice()
        {
            int MaxMV = Map.GetSquadMaxMovement(ActiveSquad);//Maximum distance you can reach.

            MaxMV += ActiveSquad.CurrentLeader.Boosts.MovementModifier;

            MovementAlgorithmTile LastTerrin = Map.GetTerrain(ActiveSquad);
            float CurrentMVCost = 0;

            for (int T = 1; T < ListMovedOverTerrain.Count; T++)
            {
                MovementAlgorithmTile ActiveTerrain = ListMovedOverTerrain[T];
                CurrentMVCost += Map.Pathfinder.GetMVCost(ActiveSquad, ActiveSquad.CurrentLeader.UnitStat, LastTerrin, ActiveTerrain);
            }

            MovementAlgorithmTile NextTerrain = Map.GetTerrain(Map.CursorPosition.X, Map.CursorPosition.Y, (int)Map.CursorPosition.Z);

            CurrentMVCost += Map.Pathfinder.GetMVCost(ActiveSquad, ActiveSquad.CurrentLeader.UnitStat, LastTerrin, NextTerrain);

            if (CurrentMVCost <= MaxMV)
            {
                ListMovedOverTerrain.Add(NextTerrain);
                ListMovedOverPoint.Add(Map.CursorPosition);
            }
            else
            {
                ComputeNewHoverPath();
            }
        }
Esempio n. 4
0
        protected override List <MovementAlgorithmTile> AddSuccessor(MovementAlgorithmTile ActiveNode, float OffsetX, float OffsetY, int LayerIndex)
        {
            List <MovementAlgorithmTile> ListTerrainSuccessor = new List <MovementAlgorithmTile>();
            List <int> ListLayerPossibility;
            int        NextRegularMovementLayerIndex = Map.GetNextLayerIndex(new Vector3(ActiveNode.Position.X, ActiveNode.Position.Y, LayerIndex), (int)(ActiveNode.Position.X + OffsetX), (int)(ActiveNode.Position.Y + OffsetY), 1f, 15, out ListLayerPossibility);

            foreach (int ActiveLayerIndex in ListLayerPossibility)
            {
                if (Map.CheckForObstacleAtPosition(new Vector3(ActiveNode.Position.X + OffsetX, ActiveNode.Position.Y + OffsetY, ActiveLayerIndex), Vector3.Zero))
                {
                    continue;
                }

                MovementAlgorithmTile ActiveTile = GetTile(ActiveNode.Position.X + OffsetX, ActiveNode.Position.Y + OffsetY, ActiveLayerIndex);
                //Wall
                if (ActiveTile == null || ActiveTile.MVEnterCost == -1 || ActiveTile.MovementCost == -1 ||
                    ActiveTile.TerrainTypeIndex == UnitStats.TerrainWallIndex || ActiveTile.TerrainTypeIndex == UnitStats.TerrainVoidIndex)
                {
                    continue;
                }

                if (!AllowGoThroughGround && ActiveLayerIndex < NextRegularMovementLayerIndex && ActiveLayerIndex != NextRegularMovementLayerIndex && ListLayerPossibility.Contains(LayerIndex))
                {
                    continue;
                }
                //If the NewNode is the parent, skip it.
                //Used for an undefined map or if you don't need to calculate the whole map.
                //ListSuccessors.Add(new AStarNode(ActiveNode, AX, AY));
                ActiveTile.LayerIndex = ActiveLayerIndex;
                ListTerrainSuccessor.Add(ActiveTile);
            }

            return(ListTerrainSuccessor);
        }
Esempio n. 5
0
        public void AddDrawablePath(List <MovementAlgorithmTile> ListPoint)
        {
            for (int P = 1; P < ListPoint.Count; P++)
            {
                MovementAlgorithmTile ActivePoint = ListPoint[P];
                MovementAlgorithmTile Previous    = ListPoint[P - 1];
                MovementAlgorithmTile Next        = null;
                if (P + 1 < ListPoint.Count)
                {
                    Next = ListPoint[P + 1];
                }

                int          X               = (int)ActivePoint.Position.X;
                int          Y               = (int)ActivePoint.Position.Y;
                float        Z               = Map.LayerManager.ListLayer[ActivePoint.LayerIndex].ArrayTerrain[X, Y].Position.Z * 32 + (ActivePoint.LayerIndex * 32) + 0.1f;
                Map2D        GroundLayer     = Map.LayerManager.ListLayer[ActivePoint.LayerIndex].LayerGrid;
                DrawableTile ActiveTerrain   = GroundLayer.GetTile(X, Y);
                Terrain3D    ActiveTerrain3D = ActiveTerrain.Terrain3DInfo;

                ListDrawableArrowPerColor.Add(ActiveTerrain3D.CreateTile3D(0, GetCursorTextureOffset(Previous, ActivePoint, Next),
                                                                           X * Map.TileSize.X, Y * Map.TileSize.Y, Z, Z + 0.15f, Map.TileSize, new List <Texture2D>()
                {
                    Map.sprCursorPath
                }, Z, Z, Z, Z, 0)[0]);
            }
        }
Esempio n. 6
0
        private void ProcessLine(MovementAlgorithmTile StartNode, Vector2 DestinationPosition, int DestinationLayerIndex)
        {
            MovementAlgorithmTile CurrentTerrain = StartNode;
            MovementAlgorithmTile NextTerrain    = Map.GetTerrain(StartNode.Position.X, StartNode.Position.Y, StartNode.LayerIndex);
            Vector3 Diff = new Vector3(DestinationPosition.X - StartNode.Position.X, DestinationPosition.Y - StartNode.Position.Y, DestinationLayerIndex - StartNode.LayerIndex);

            Diff.Normalize();
            int   NextX    = (int)StartNode.Position.X;
            int   NextY    = (int)StartNode.Position.Y;
            int   NextZ    = StartNode.LayerIndex;
            float Progress = 0;

            while (NextTerrain != null)
            {
                Progress += 1;
                NextX     = (int)(StartNode.Position.X + Progress * Diff.X);
                NextY     = (int)(StartNode.Position.Y + Progress * Diff.Y);
                NextZ     = (int)(StartNode.LayerIndex + Progress * Diff.Z);

                if (NextX < 0 || NextX >= Map.MapSize.X || NextY < 0 || NextY >= Map.MapSize.Y || NextZ < 0 || NextZ >= Map.LayerManager.ListLayer.Count)
                {
                    return;
                }

                NextTerrain = Map.GetTerrain(NextX, NextY, NextZ);

                if (ListRefusedAttackTerrain.Contains(NextTerrain))
                {
                    return;
                }

                if (!ListAllAttackTerrain.Contains(NextTerrain))
                {
                    NextTerrain.LayerIndex = NextZ;
                    ListAllAttackTerrain.Add(NextTerrain);

                    if (IsTerrainBlocking(NextTerrain))
                    {
                        ListRefusedAttackTerrain.Add(NextTerrain);
                        ListUsableAttackTerrain.Add(CurrentTerrain);
                        return;
                    }
                    else if (IsTerrainAttackable(NextTerrain))
                    {
                        ListUsableAttackTerrain.Add(NextTerrain);
                    }
                }

                CurrentTerrain = NextTerrain;
            }
        }
Esempio n. 7
0
        protected override List <MovementAlgorithmTile> AddSuccessor(MovementAlgorithmTile ActiveNode, float OffsetX, float OffsetY, int LayerIndex)
        {
            List <MovementAlgorithmTile> ListTerrainSuccessor = new List <MovementAlgorithmTile>();
            MovementAlgorithmTile        ActiveTile           = GetTile(ActiveNode.Position.X + OffsetX, ActiveNode.Position.X + OffsetY, LayerIndex);

            //Wall
            if (ActiveTile == null || ActiveTile.MVEnterCost == -1 || ActiveTile.MovementCost == -1 ||
                ActiveTile.TerrainTypeIndex == UnitStats.TerrainWallIndex || ActiveTile.TerrainTypeIndex == UnitStats.TerrainVoidIndex)
            {
                return(ListTerrainSuccessor);
            }

            //If the NewNode is the parent, skip it.
            if (ActiveNode.ParentTemp == null)
            {
                //Used for an undefined map or if you don't need to calculate the whole map.
                //ListSuccessors.Add(new AStarNode(ActiveNode, AX, AY));
                ActiveTile.ParentTemp = ActiveNode;
                ListTerrainSuccessor.Add(ActiveTile);
            }

            return(ListTerrainSuccessor);
        }
Esempio n. 8
0
        public void ComputeAttackTargets()
        {
            ListAllAttackTerrain.Clear();
            ListRefusedAttackTerrain.Clear();
            ListUsableAttackTerrain.Clear();

            MovementAlgorithmTile ActiveTerrain = Map.GetTerrain(ActiveSquad.Position.X, ActiveSquad.Position.Y, (int)ActiveSquad.Position.Z);

            ListAllAttackTerrain.Add(Map.GetTerrain(ActiveSquad.Position.X, ActiveSquad.Position.Y, (int)ActiveSquad.Position.Z));
            ActiveTerrain.LayerIndex = (int)ActiveTerrain.Position.Z;

            //Start Right, go downward
            Vector2 TestedFinalPos = new Vector2(Map.MapSize.X, ActiveSquad.Position.Y);

            do
            {
                for (int L = 0; L < Map.LayerManager.ListLayer.Count; ++L)
                {
                    ProcessLine(ActiveTerrain, TestedFinalPos, L);
                }
            }while (++TestedFinalPos.Y < Map.MapSize.Y);

            //Start bottom right, go bottom left
            do
            {
                for (int L = 0; L < Map.LayerManager.ListLayer.Count; ++L)
                {
                    ProcessLine(ActiveTerrain, TestedFinalPos, L);
                }
            }while (--TestedFinalPos.X >= 0);

            //Start bottom left, go upper left
            do
            {
                for (int L = 0; L < Map.LayerManager.ListLayer.Count; ++L)
                {
                    ProcessLine(ActiveTerrain, TestedFinalPos, L);
                }
            }while (--TestedFinalPos.Y >= 0);

            //Start upper left, go upper right
            do
            {
                for (int L = 0; L < Map.LayerManager.ListLayer.Count; ++L)
                {
                    ProcessLine(ActiveTerrain, TestedFinalPos, L);
                }
            }while (++TestedFinalPos.X < Map.MapSize.X);

            //Start upper right, go back to start
            do
            {
                for (int L = 0; L < Map.LayerManager.ListLayer.Count; ++L)
                {
                    ProcessLine(ActiveTerrain, TestedFinalPos, L);
                }
            }while (++TestedFinalPos.Y < ActiveSquad.Position.Y);

            //Aim for the ceiling
            for (int X = 0; X < Map.MapSize.X; ++X)
            {
                for (int Y = 0; Y < Map.MapSize.Y; ++Y)
                {
                    ProcessLine(ActiveTerrain, new Vector2(X, Y), Map.LayerManager.ListLayer.Count - 1);
                }
            }
        }
Esempio n. 9
0
 private bool IsTerrainBlocking(MovementAlgorithmTile ActiveTerrain)
 {
     return(ActiveTerrain.TerrainTypeIndex == UnitStats.TerrainWallIndex);
 }
Esempio n. 10
0
 private bool IsTerrainAttackable(MovementAlgorithmTile ActiveTerrain)
 {
     return(ActiveTerrain.TerrainTypeIndex == UnitStats.TerrainLandIndex);
 }
Esempio n. 11
0
 public override float GetMVCost(UnitMapComponent MapComponent, UnitStats UnitStat, MovementAlgorithmTile CurrentNode, MovementAlgorithmTile TerrainToGo)
 {
     return(TerrainToGo.MVMoveCost);
 }
Esempio n. 12
0
 public string GetTerrainType(MovementAlgorithmTile ActiveTerrain)
 {
     return(ListTerrainType[ActiveTerrain.TerrainTypeIndex]);
 }
Esempio n. 13
0
        public override float GetMVCost(UnitMapComponent MapComponent, UnitStats UnitStat, MovementAlgorithmTile CurrentNode, MovementAlgorithmTile TerrainToGo)
        {
            float MovementCostToNeighbor = 0;

            if (MapComponent.CurrentMovement == "Air")
            {
                if (Map.GetTerrainLetterAttribute(UnitStat, "Air") == 'C' || Map.GetTerrainLetterAttribute(UnitStat, "Air") == 'D' || Map.GetTerrainLetterAttribute(UnitStat, "Air") == '-')
                {
                    MovementCostToNeighbor += 0.5f;
                }
                else
                {
                    MovementCostToNeighbor += 1;
                }
            }
            else
            {
                char TerrainCharacter = Map.GetTerrainLetterAttribute(UnitStat, Map.GetTerrainType(TerrainToGo));

                if ((TerrainCharacter == 'C' || TerrainCharacter == 'D' || TerrainCharacter == '-') && Map.GetTerrainType(TerrainToGo) != "Land")
                {
                    MovementCostToNeighbor += TerrainToGo.MVMoveCost + 0.5f;
                }
                else if (TerrainCharacter == 'S' && TerrainToGo.MVMoveCost > 1)
                {
                    MovementCostToNeighbor += TerrainToGo.MVMoveCost / 2;
                }
                else
                {
                    MovementCostToNeighbor += TerrainToGo.MVMoveCost;
                }

                if (TerrainToGo.TerrainTypeIndex != GetTile(CurrentNode.Position.X, CurrentNode.Position.Y, MapComponent.LayerIndex).TerrainTypeIndex)
                {
                    MovementCostToNeighbor += TerrainToGo.MVEnterCost;
                }
            }

            return(MovementCostToNeighbor);
        }
Esempio n. 14
0
        public override float GetMVCost(UnitMapComponent MapComponent, UnitStats UnitStat, MovementAlgorithmTile CurrentNode, MovementAlgorithmTile TerrainToGo)
        {
            float MovementCostToNeighbor = 0;

            if (MapComponent.CurrentMovement == UnitStats.TerrainAir)
            {
                if (Map.GetTerrainLetterAttribute(UnitStat, UnitStats.TerrainAir) == 'C' ||
                    Map.GetTerrainLetterAttribute(UnitStat, UnitStats.TerrainAir) == 'D' ||
                    Map.GetTerrainLetterAttribute(UnitStat, UnitStats.TerrainAir) == '-')
                {
                    MovementCostToNeighbor += 0.5f;
                }
                else
                {
                    MovementCostToNeighbor += 1;
                }
            }
            else
            {
                string TerrainType = Map.GetTerrainType(TerrainToGo);

                if (!UnitStat.ListTerrainChoices.Contains(TerrainType))
                {
                    return(-1);
                }

                char TerrainCharacter = Map.GetTerrainLetterAttribute(UnitStat, TerrainType);

                if ((TerrainCharacter == 'C' || TerrainCharacter == 'D' || TerrainCharacter == '-') && TerrainType != UnitStats.TerrainLand)
                {
                    MovementCostToNeighbor += TerrainToGo.MVMoveCost + 0.5f;
                }
                else if (TerrainCharacter == 'S' && TerrainToGo.MVMoveCost > 1)
                {
                    MovementCostToNeighbor += TerrainToGo.MVMoveCost / 2;
                }
                else
                {
                    MovementCostToNeighbor += TerrainToGo.MVMoveCost;
                }

                if (TerrainToGo.TerrainTypeIndex != GetTile(CurrentNode.Position.X, CurrentNode.Position.Y, (int)MapComponent.Z).TerrainTypeIndex)
                {
                    MovementCostToNeighbor += TerrainToGo.MVEnterCost;
                }
            }

            return(MovementCostToNeighbor);
        }
Esempio n. 15
0
        private Point GetCursorTextureOffset(MovementAlgorithmTile Previous, MovementAlgorithmTile Current, MovementAlgorithmTile Next)
        {
            Point TextureOffset = Point.Zero;

            if (Next == null)
            {
                if (Previous != null && Previous.Position.X < Current.Position.X)//Right
                {
                    TextureOffset.X = 32 * 3;
                }
                else if (Previous != null && Previous.Position.X > Current.Position.X)//Left
                {
                    TextureOffset.X = 32 * 4;
                }
                else if (Previous != null && Previous.Position.Y < Current.Position.Y)//Down
                {
                    TextureOffset.X = 32 * 5;
                }
                else if (Previous != null && Previous.Position.Y > Current.Position.Y)//Up
                {
                    TextureOffset.X = 32 * 2;
                }
            }
            else if (Current.Position.X < Next.Position.X)                        //Going Right
            {
                if (Previous != null && Previous.Position.Y < Current.Position.Y) //Down Right
                {
                    TextureOffset.X = 32 * 9;
                }
                else if (Previous != null && Previous.Position.Y > Current.Position.Y)//Up Right
                {
                    TextureOffset.X = 32 * 8;
                }
                else
                {
                    TextureOffset.X = 32 * 1;
                }
            }
            else if (Current.Position.X > Next.Position.X)                        //Going Left
            {
                if (Previous != null && Previous.Position.Y < Current.Position.Y) //Down Left
                {
                    TextureOffset.X = 32 * 7;
                }
                else if (Previous != null && Previous.Position.Y > Current.Position.Y)//Up Left
                {
                    TextureOffset.X = 32 * 6;
                }
                else
                {
                    TextureOffset.X = 32 * 1;
                }
            }
            else if (Current.Position.Y < Next.Position.Y)                        //Going Down
            {
                if (Previous != null && Previous.Position.X < Current.Position.X) //Right Down
                {
                    TextureOffset.X = 32 * 6;
                }
                else if (Previous != null && Previous.Position.X > Current.Position.X)//Left Down
                {
                    TextureOffset.X = 32 * 8;
                }
                else
                {
                    TextureOffset.X = 32 * 0;
                }
            }
            else if (Current.Position.Y > Next.Position.Y)                        //Going Up
            {
                if (Previous != null && Previous.Position.X < Current.Position.X) //Right Up
                {
                    TextureOffset.X = 32 * 7;
                }
                else if (Previous != null && Previous.Position.X > Current.Position.X)//Left Up
                {
                    TextureOffset.X = 32 * 9;
                }
                else
                {
                    TextureOffset.X = 32 * 0;
                }
            }

            return(TextureOffset);
        }