コード例 #1
0
        /// <summary>
        /// Tests the paths between regions.
        /// </summary>
        /// <returns><c>true</c>, if paths between regions was accessable, <c>false</c> otherwise.</returns>
        /// <param name="allRegions">All regions.</param>
        /// <param name="canWalk">Can walk.</param>
        public bool TestPathsBetweenRegions(LandRegion[] allRegions, int[,] canWalk)
        {
            AStarAlgo aStar = new AStarAlgo(canWalk, canWalk.GetLength(0), canWalk.GetLength(1), false);

            for (int i = 0; i <= allRegions.GetLength(0); i++)
            {
                if (TestPathsBetweenBuildings(allRegions[i], canWalk))
                {
                    Point a = allRegions[i - 1].GetCastle().GetPosition();
                    Point b;
                    if (i == 0)
                    {
                        b = allRegions[allRegions.GetLength(0) - 1].GetCastle().GetPosition();
                    }
                    else
                    {
                        b = allRegions[i].GetCastle().GetPosition();
                    }

                    if (aStar.calculate(a, b).Count == 0)
                    {
                        return(false);
                    }
                }
                else
                {
                    Debug.Log("Cannot Walk between all buildings in region " + allRegions[i].ToString());
                    return(false);
                }
            }
            return(true);
        }
コード例 #2
0
    /// <summary>
    /// Constructor for Battlefield for battle with heroless units
    /// </summary>
    /// <param name="width">Width of battlefield</param>
    /// <param name="height">Height of battlefield</param>
    /// <param name="attacker">The attacking hero</param>
    /// <param name="defender">The defending units</param>
    /// <param name="canWalk">Canwalk</param>
    public BattleField(int width, int height, Hero attacker, UnitTree defender, int[,] canWalk)
    {
        Width    = width;
        Height   = height;
        Attacker = attacker;
        CanWalk  = canWalk;
        aStar    = new AStarAlgo(canWalk, width, height, true);

        attackingUnits = attacker.Units;
        defendingUnits = defender;

        Unit[] aUnits = attacker.Units.GetUnits();
        Unit[] dUnits = defender.GetUnits();

        int increment = height / UnitTree.TREESIZE;
        int place     = 0;

        unitsPos = new UnitAndAmount[width, height];
        for (int i = 0; i < UnitTree.TREESIZE; i++)
        {
            if (aUnits[i] != null)
            {
                UnitAndAmount atroop = new UnitAndAmount(attacker.Units, i);
                unitsPos[0, place] = atroop;
            }
            if (dUnits[i] != null)
            {
                UnitAndAmount dtroop = new UnitAndAmount(defender, i);
                unitsPos[width - 1, place] = dtroop;
            }
            place += increment;
        }
    }
コード例 #3
0
    public MovementManager(Reaction[,] reactions, int[,] canWalk, AStarAlgo aStar, GameManager gm)
    {
        this.aStar       = aStar;
        this.gameManager = gm;

        // MAPS:
        this.reactions = reactions;
        this.canWalk   = canWalk;
    }
コード例 #4
0
        /// <summary>
        /// Tests the paths between all buildings inside a given land-region.
        /// </summary>
        /// <returns><c>true</c>, if paths between buildings was accessable, <c>false</c> otherwise.</returns>
        /// <param name="region">Region.</param>
        /// <param name="canWalk">Can walk.</param>
        public bool TestPathsBetweenBuildings(LandRegion region, int[,] canWalk)
        {
            AStarAlgo aStar = new AStarAlgo(canWalk, canWalk.GetLength(0), canWalk.GetLength(1), false);

            Point castlePlacement = region.GetCastle().GetPosition();

            foreach (OverworldBuilding building in region.GetBuildings())
            {
                Point buildingPlacement = building.Origo;
                if (aStar.calculate(castlePlacement, buildingPlacement).Count == 0)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #5
0
 void Awake()
 {
     instance    = this;
     pathfinding = GetComponent <AStarAlgo>();
 }