/// <summary>
        /// Check all possible regions around the start region of a unit and add them to a ConcurrentBag.
        /// </summary>
        /// <returns>The adjacent regions.</returns>
        /// <param name="regionManagerC">Region manager c.</param>
        /// <param name="position">PositionI of the region.</param>
        private ConcurrentBag <RegionPosition> GetAdjacentRegions(RegionManagerController regionManagerC, RegionPosition position)
        {
            var list        = new ConcurrentBag <RegionPosition>();
            var surlist     = LogicRules.SurroundRegions;
            var regionSizeX = Constants.REGION_SIZE_X / 2;
            var regionSizeY = Constants.REGION_SIZE_Y / 2;

            if (position.RegionX <= regionSizeX && position.RegionY <= regionSizeY)
            {
                var tempReg = position + surlist[LogicRules.SurroundRegions.Length];
                if (regionManagerC.GetRegion(tempReg).Exist)
                {
                    list.Add(tempReg);
                }

                for (int index = 0; index < 2; ++index)
                {
                    tempReg = position + surlist[index];
                    if (regionManagerC.GetRegion(tempReg).Exist)
                    {
                        list.Add(tempReg);
                    }
                }
            }
            else if (position.RegionX > regionSizeX && position.RegionY <= regionSizeY)
            {
                for (int index = 1; index < 4; ++index)
                {
                    var tempReg = position + surlist[index];
                    if (regionManagerC.GetRegion(tempReg).Exist)
                    {
                        list.Add(tempReg);
                    }
                }
            }
            else if (position.RegionX > regionSizeX && position.RegionY > regionSizeY)
            {
                for (int index = 3; index < 7; ++index)
                {
                    var tempReg = position + surlist[index];
                    if (regionManagerC.GetRegion(tempReg).Exist)
                    {
                        list.Add(tempReg);
                    }
                }
            }
            else
            {
                for (int index = 5; index < 8; ++index)
                {
                    var tempReg = position + surlist[index];
                    if (regionManagerC.GetRegion(tempReg).Exist)
                    {
                        list.Add(tempReg);
                    }
                }
            }
            return(list);
        }
        /// <summary>
        /// Check all possible spawn locations around a building.
        /// Check surrounding area around the building for units, if there is a free location this will be returned.
        /// </summary>
        /// <returns>The free field.</returns>
        /// <param name="position">IPosition of the current selected building..</param>
        /// <param name="regionManagerC">Region manager c.</param>
        private PositionI GetFreeField(PositionI position, RegionManagerController regionManagerC)
        {
            foreach (var surpos in LogicRules.GetSurroundedFields(position))
            {
                var td = regionManagerC.GetRegion(surpos.RegionPosition).GetTerrain(surpos.CellPosition);
                var ed = regionManagerC.GetRegion(surpos.RegionPosition).GetEntity(surpos.CellPosition);

                if (td.Walkable && ed == null)
                {
                    return(surpos);
                }
            }
            return(null);
        }
        /// <summary>
        /// Gets the adjacent regions, which can be affected.
        /// </summary>
        /// <returns>The adjacent regions.</returns>
        /// <param name="regionManagerC">Region manager c.</param>
        /// <param name="position">Current Position od the selected building.</param>
        /// <param name="buildpoint">PositionI from the new unit.</param>
        private ConcurrentBag <RegionPosition> GetAdjacentRegions(RegionManagerController regionManagerC, RegionPosition position, PositionI buildpoint)
        {
            var list        = new ConcurrentBag <RegionPosition>();
            var surlist     = LogicRules.SurroundRegions;
            var regionSizeX = Constants.REGION_SIZE_X;
            var regionSizeY = Constants.REGION_SIZE_Y;

            var currentpos    = LogicRules.GetSurroundedFields(buildpoint);
            var currentregion = regionManagerC.RegionManager.GetRegion(buildpoint.RegionPosition);

            foreach (var checkingpos in currentpos)
            {
                if (regionManagerC.GetRegion(checkingpos.RegionPosition) != currentregion)
                {
                    list.Add(regionManagerC.RegionManager.GetRegion(checkingpos.RegionPosition).RegionPosition);
                }
            }
            return(list);
        }
Exemple #4
0
        /// <summary>
        /// Check all possible spawn locations around a building.
        /// Check surrounding area around the building for units, if there is a free location this will be returned.
        /// </summary>
        /// <returns>The free field.</returns>
        /// <param name="position">IPosition of the current selected building..</param>
        /// <param name="regionManagerC">Region manager c.</param>
        private PositionI GetFreeField(PositionI position, RegionManagerController regionManagerC)
        {
            foreach (var surpos in LogicRules.GetSurroundedFields(position))
            {
                var td = regionManagerC.GetRegion(surpos.RegionPosition).GetTerrain(surpos.CellPosition);
                var ed = regionManagerC.GetRegion(surpos.RegionPosition).GetEntity(surpos.CellPosition);

                if (td.Walkable && ed == null)
                {
                    return surpos;
                }
            }
            return null;
        }
Exemple #5
0
        /// <summary>
        /// Gets the adjacent regions, which can be affected.
        /// </summary>
        /// <returns>The adjacent regions.</returns>
        /// <param name="regionManagerC">Region manager c.</param>
        /// <param name="position">Current Position od the selected building.</param>
        /// <param name="buildpoint">PositionI from the new unit.</param>
        private ConcurrentBag<RegionPosition> GetAdjacentRegions(RegionManagerController regionManagerC, RegionPosition position, PositionI buildpoint)
        {
            var list = new ConcurrentBag<RegionPosition>();
            var surlist = LogicRules.SurroundRegions;
            var regionSizeX = Constants.REGION_SIZE_X;
            var regionSizeY = Constants.REGION_SIZE_Y;

            var currentpos = LogicRules.GetSurroundedFields(buildpoint);
            var currentregion = regionManagerC.RegionManager.GetRegion(buildpoint.RegionPosition);

            foreach (var checkingpos in currentpos)
            {
                if (regionManagerC.GetRegion(checkingpos.RegionPosition) != currentregion)
                {
                    list.Add(regionManagerC.RegionManager.GetRegion(checkingpos.RegionPosition).RegionPosition);
                }
            }
            return list;
        }
Exemple #6
0
        /// <summary>
        /// Check all possible regions around the start region of a unit and add them to a ConcurrentBag.
        /// </summary>
        /// <returns>The adjacent regions.</returns>
        /// <param name="regionManagerC">Region manager c.</param>
        /// <param name="position">PositionI of the region.</param>
        private ConcurrentBag<RegionPosition> GetAdjacentRegions(RegionManagerController regionManagerC, RegionPosition position)
        {
            var list = new ConcurrentBag<RegionPosition>();
            var surlist = LogicRules.SurroundRegions;
            var regionSizeX = Constants.REGION_SIZE_X / 2;
            var regionSizeY = Constants.REGION_SIZE_Y / 2;

            if (position.RegionX <= regionSizeX && position.RegionY <= regionSizeY)
            {
                var tempReg = position + surlist[LogicRules.SurroundRegions.Length];
                if (regionManagerC.GetRegion(tempReg).Exist)
                {
                    list.Add(tempReg);
                }

                for (int index = 0; index < 2; ++index)
                {
                    tempReg = position + surlist[index];
                    if (regionManagerC.GetRegion(tempReg).Exist)
                    {
                        list.Add(tempReg);
                    }
                }
            }
            else if (position.RegionX > regionSizeX && position.RegionY <= regionSizeY)
            {
                for (int index = 1; index < 4; ++index)
                {
                    var tempReg = position + surlist[index];
                    if (regionManagerC.GetRegion(tempReg).Exist)
                    {
                        list.Add(tempReg);
                    }
                }
            }
            else if (position.RegionX > regionSizeX && position.RegionY > regionSizeY)
            {
                for (int index = 3; index < 7; ++index)
                {
                    var tempReg = position + surlist[index];
                    if (regionManagerC.GetRegion(tempReg).Exist)
                    {
                        list.Add(tempReg);
                    }
                }
            }
            else
            {
                for (int index = 5; index < 8; ++index)
                {
                    var tempReg = position + surlist[index];
                    if (regionManagerC.GetRegion(tempReg).Exist)
                    {
                        list.Add(tempReg);
                    }
                }
            }
            return list;
        }
Exemple #7
0
        /// <summary>
        /// Gets the adjacent regions, which can be affected.
        /// </summary>
        /// <returns>The adjacent regions.</returns>
        /// <param name="regionManagerC">Region manager c.</param>
        /// <param name="position">Current Position od the selected building.</param>
        /// <param name="buildpoint">PositionI from the new unit.</param>
        private ConcurrentBag <RegionPosition> GetAdjacentRegions(RegionManagerController regionManagerC, RegionPosition position, PositionI buildpoint)
        {
            var list        = new ConcurrentBag <RegionPosition>();
            var surlist     = LogicRules.SurroundRegions;
            var regionSizeX = Constants.REGION_SIZE_X;
            var regionSizeY = Constants.REGION_SIZE_Y;

            if (buildpoint.CellPosition.CellX <= m_drawArea)
            {
                var tempReg = position + surlist[LogicRules.SurroundRegions.Length - 1];
                if (regionManagerC.GetRegion(tempReg).Exist)
                {
                    list.Add(tempReg);
                }

                for (int index = 0; index < 4; ++index)
                {
                    tempReg = position + surlist[index];
                    if (regionManagerC.GetRegion(tempReg).Exist)
                    {
                        list.Add(tempReg);
                    }
                }
            }
            else if (buildpoint.CellPosition.CellY <= m_drawArea)
            {
                for (int index = 5; index < LogicRules.SurroundRegions.Length; ++index)
                {
                    var tempReg = position + surlist[index];
                    if (regionManagerC.GetRegion(tempReg).Exist)
                    {
                        list.Add(tempReg);
                    }
                }

                var reg = position + surlist[0];
                if (regionManagerC.GetRegion(reg).Exist)
                {
                    list.Add(reg);
                }
                reg = position + surlist[1];
                if (regionManagerC.GetRegion(reg).Exist)
                {
                    list.Add(reg);
                }
            }
            else if (buildpoint.CellPosition.CellX >= regionSizeX - m_drawArea)
            {
                for (int index = 1; index < 6; ++index)
                {
                    var tempReg = position + surlist[index];
                    if (regionManagerC.GetRegion(tempReg).Exist)
                    {
                        list.Add(tempReg);
                    }
                }
            }
            else if (buildpoint.CellPosition.CellY >= regionSizeY - m_drawArea)
            {
                for (int index = 3; index < LogicRules.SurroundRegions.Length; ++index)
                {
                    var tempReg = position + surlist[index];
                    if (regionManagerC.GetRegion(tempReg).Exist)
                    {
                        list.Add(tempReg);
                    }
                }
            }
            return(list);
        }
        /// <summary>
        /// Gets the adjacent regions, which can be affected.
        /// </summary>
        /// <returns>The adjacent regions.</returns>
        /// <param name="regionManagerC">Region manager c.</param>
        /// <param name="position">Current Position od the selected building.</param>
        /// <param name="buildpoint">PositionI from the new unit.</param>
        private ConcurrentBag<RegionPosition> GetAdjacentRegions(RegionManagerController regionManagerC, RegionPosition position, PositionI buildpoint)
        {
            var list = new ConcurrentBag<RegionPosition>();
            var surlist = LogicRules.SurroundRegions;
            var regionSizeX = Constants.REGION_SIZE_X;
            var regionSizeY = Constants.REGION_SIZE_Y;

            if (buildpoint.CellPosition.CellX <= m_drawArea)
            {
                var tempReg = position + surlist[LogicRules.SurroundRegions.Length - 1];
                if (regionManagerC.GetRegion(tempReg).Exist)
                {
                    list.Add(tempReg);
                }

                for (int index = 0; index < 4; ++index)
                {
                    tempReg = position + surlist[index];
                    if (regionManagerC.GetRegion(tempReg).Exist)
                    {
                        list.Add(tempReg);
                    }
                }
            }
            else if (buildpoint.CellPosition.CellY <= m_drawArea)
            {
                for (int index = 5; index < LogicRules.SurroundRegions.Length; ++index)
                {
                    var tempReg = position + surlist[index];
                    if (regionManagerC.GetRegion(tempReg).Exist)
                    {
                        list.Add(tempReg);
                    }
                }

                var reg = position + surlist[0];
                if (regionManagerC.GetRegion(reg).Exist)
                {
                    list.Add(reg);
                }
                reg = position + surlist[1];
                if (regionManagerC.GetRegion(reg).Exist)
                {
                    list.Add(reg);
                }
            }
            else if (buildpoint.CellPosition.CellX >= regionSizeX - m_drawArea)
            {
                for (int index = 1; index < 6; ++index)
                {
                    var tempReg = position + surlist[index];
                    if (regionManagerC.GetRegion(tempReg).Exist)
                    {
                        list.Add(tempReg);
                    }
                }
            }
            else if (buildpoint.CellPosition.CellY >= regionSizeY - m_drawArea)
            {
                for (int index = 3; index < LogicRules.SurroundRegions.Length; ++index)
                {
                    var tempReg = position + surlist[index];
                    if (regionManagerC.GetRegion(tempReg).Exist)
                    {
                        list.Add(tempReg);
                    }
                }
            }
            return list;
        }