예제 #1
0
        /// <summary>
        /// Gets the region depending on the region position.
        /// </summary>
        /// <returns>The region.</returns>
        /// <param name="regionPosition">Region position.</param>
        public Region GetRegion(RegionPosition regionPosition)
        {
            if (Regions.ContainsKey(regionPosition))
            {
                return Regions[regionPosition];
            }
            var region = new Region(regionPosition);

            return region;
        }
예제 #2
0
파일: Region.cs 프로젝트: Lopt/ascendancy
 /// <summary>
 /// Initializes a new instance of the <see cref="Core.Models.Region"/> class.
 /// </summary>
 /// <param name="region">Region which should be copied.</param>
 public Region(Region region)
 {
     m_regionPosition = region.m_regionPosition;
     m_terrains = region.m_terrains;
     m_entities = region.m_entities;
     m_territory = region.m_territory;
     m_actions = new DatedActions();
     m_actions.Actions = new LinkedList<Core.Models.Action>();
     m_exist = region.m_exist;
     m_mutex = region.m_mutex;
 }
예제 #3
0
        public void MapRegion()
        {
            // Test with a RegionPosition as Input
            var regionPosition = new RegionPosition(new Position(new LatLon(50.97695325, 11.02396488)));
            var region = new Core.Models.Region(regionPosition);

            Assert.IsNotNull(region);
            Assert.IsInstanceOf<Core.Models.Region>(region);

            // Test with a Region as Input
            var region2 = new Region(region);

            Assert.IsNotNull(region2);
            Assert.IsInstanceOf<Core.Models.Region>(region2);
            Assert.AreEqual(region.RegionPosition, region2.RegionPosition);

            // Test with a RegionPosition and an TerrainDefinition as Input
            int[] res = { 0, 0, 0, 0, 0 };
            var terDef = new Core.Models.Definitions.TerrainDefinition(Core.Models.Definitions.EntityType.Grassland, res, true, true, 4, 5, 6);
            // var region3 = new Region(regionPosition, TerDef);
        }
예제 #4
0
        public void MapRegion()
        {
            // Test with a RegionPosition as Input
            var regionPosition = new RegionPosition(new Position(new LatLon(50.97695325, 11.02396488)));
            var region         = new Core.Models.Region(regionPosition);

            Assert.IsNotNull(region);
            Assert.IsInstanceOf <Core.Models.Region>(region);

            // Test with a Region as Input
            var region2 = new Region(region);

            Assert.IsNotNull(region2);
            Assert.IsInstanceOf <Core.Models.Region>(region2);
            Assert.AreEqual(region.RegionPosition, region2.RegionPosition);

            // Test with a RegionPosition and an TerrainDefinition as Input
            int[] res    = { 0, 0, 0, 0, 0 };
            var   terDef = new Core.Models.Definitions.TerrainDefinition(Core.Models.Definitions.EntityType.Grassland, res, true, true, 4, 5, 6);
            // var region3 = new Region(regionPosition, TerDef);
        }
예제 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Client.Common.Views.RegionViewHex"/> class.
        /// </summary>
        /// <param name="region">The Region to draw.</param>
        public RegionViewHex(Region region)
            : base(region)
        {
            var tileMapInfo = new CCTileMapInfo(Common.Constants.ClientConstants.TILEMAP_FILE_HEX);
            m_tileMap = new CCTileMap(tileMapInfo);

            m_terrainLayer = m_tileMap.LayerNamed(ClientConstants.LAYER_TERRAIN);
            m_buildingLayer = m_tileMap.LayerNamed(ClientConstants.LAYER_BUILDING);
            m_menueLayer = m_tileMap.LayerNamed(ClientConstants.LAYER_MENU);
            m_indicatorLayer = m_tileMap.LayerNamed(ClientConstants.LAYER_INDICATOR);

            m_drawNodes = new Dictionary<Account, CCDrawNode>();

            m_childs = new Dictionary<LayerTypes, CCNode>();
            m_childs[LayerTypes.Terrain] = m_tileMap.TileLayersContainer;
            m_childs[LayerTypes.Building] = null;
            m_childs[LayerTypes.Unit] = new CCNode();
            m_childs[LayerTypes.Border] = new CCNode();
            m_childs[LayerTypes.Indicator] = null; // new CCNode();
            m_childs[LayerTypes.Menu] = null; // new CCNode();

            Init();
            LoadRegionViewAsync();
        }
예제 #6
0
        /// <summary>
        /// Loads the terrain async over the network controller and adds the region to the world.
        /// </summary>
        /// <returns>The function as task.</returns>
        /// <param name="region">Region which should be loaded.</param>
        public async Task LoadTerrainAsync(Region region)
        {
            TerrainDefinition[,] terrain = await NetworkController.Instance.LoadTerrainsAsync(region.RegionPosition);

            if (terrain != null)
            {
                region.AddTerrain(terrain);
            }
            try
            {
                World.Instance.RegionManager.AddRegion(region);
            }
            catch
            {
            }
        }
예제 #7
0
 /// <summary>
 /// Adds an region.
 /// </summary>
 /// <param name="region">Region which should be added.</param>
 public void AddRegion(Region region)
 {
     Regions[region.RegionPosition] = region;
 }
예제 #8
0
 /// <summary>
 /// Destroy the building and undo the functionality.
 /// </summary>
 /// <param name="entity">Current entity.</param>
 /// <param name="regionPos">Region position.</param>
 /// <param name="action">Action which is currently done.</param>
 /// <param name="regionManagerC">Region manager controller.</param>
 public static void DestroyBuilding(Entity entity, Region regionPos, Action action, Controllers.RegionManagerController regionManagerC)
 {
     // TODO: in pseudo klasse kapseln und generischer lösen
     switch ((long)entity.DefinitionID)
     {
         case (long)Models.Definitions.EntityType.Headquarter:
             regionPos.FreeClaimedTerritory(LogicRules.GetSurroundedPositions(entity.Position, Constants.HEADQUARTER_TERRITORY_RANGE), entity.Owner);
             DecreaseWholeStorage(entity.Owner);
             DisableBuildOptions(entity.DefinitionID, entity.Owner);
             entity.Owner.TerritoryBuildings.Remove(entity.Position);
             // TODO: bessere lösung als alles neu claimen finden
             foreach (var building in entity.Owner.TerritoryBuildings)
             {
                 var list = new HashSet<PositionI>();
                 var range = 0;
                 if (building.Value == (long)Definitions.EntityType.Headquarter)
                 {
                     range = Constants.HEADQUARTER_TERRITORY_RANGE;
                 }
                 else if (building.Value == (long)Definitions.EntityType.GuardTower)
                 {
                     range = Constants.GUARDTOWER_TERRITORY_RANGE;
                 }
                 list = GetSurroundedPositions(building.Key, range);
                 var region = building.Key.RegionPosition;
                 regionManagerC.GetRegion(region).ClaimTerritory(list, entity.Owner, region, regionManagerC.RegionManager);
             }
             // DestroyAllBuildingsWithoutTerritory(entity.Owner, action, regionManagerC);
             break;
         case (long)Models.Definitions.EntityType.GuardTower:
             regionPos.FreeClaimedTerritory(LogicRules.GetSurroundedPositions(entity.Position, Constants.GUARDTOWER_TERRITORY_RANGE), entity.Owner);
             entity.Owner.TerritoryBuildings.Remove(entity.Position);
             // TODO: bessere lösung als alles neu claimen finden
             foreach (var building in entity.Owner.TerritoryBuildings)
             {
                 var list = new HashSet<PositionI>();
                 var range = 0;
                 if (building.Value == (long)Definitions.EntityType.Headquarter)
                 {
                     range = Constants.HEADQUARTER_TERRITORY_RANGE;
                 }
                 else if (building.Value == (long)Definitions.EntityType.GuardTower)
                 {
                     range = Constants.GUARDTOWER_TERRITORY_RANGE;
                 }
                 list = GetSurroundedPositions(building.Key, range);
                 var region = building.Key.RegionPosition;
                 regionManagerC.GetRegion(region).ClaimTerritory(list, entity.Owner, region, regionManagerC.RegionManager);
             }
             // DestroyAllBuildingsWithoutTerritory(entity.Owner, action, regionManagerC);
             break;
         case (long)Models.Definitions.EntityType.Barracks:
             var count = 0;
             foreach (var element in entity.Owner.Buildings)
             {
                 if (entity.Owner.Buildings.ContainsValue(element.Value))
                 {
                     count++;
                 }
             }
             if (count == 1)
             {
                 DisableBuildOptions(entity.DefinitionID, entity.Owner);
             }
             entity.Owner.Buildings.Remove(entity.Position);
             break;
         case (long)Models.Definitions.EntityType.Furnace:
             DecreaseResourceGeneration(entity.Owner, action.ActionTime, entity.Position, regionManagerC);
             entity.Owner.Buildings.Remove(entity.Position);
             break;
         case (long)Models.Definitions.EntityType.Factory:
             entity.Owner.Buildings.Remove(entity.Position);
             break;
         case (long)Models.Definitions.EntityType.Attachment:
             entity.Owner.Buildings.Remove(entity.Position);
             break;
         case (long)Models.Definitions.EntityType.Hospital:
             entity.Owner.Buildings.Remove(entity.Position);
             break;
         case (long)Models.Definitions.EntityType.TradingPost:
             entity.Owner.Buildings.Remove(entity.Position);
             break;
         case (long)Models.Definitions.EntityType.Tent:
             DecreaseMaxPopulation(entity.Owner, entity);
             entity.Owner.Buildings.Remove(entity.Position);
             break;
         case (long)Models.Definitions.EntityType.Lab:
             DecreaseResourceGeneration(entity.Owner, action.ActionTime, entity.Position, regionManagerC);
             entity.Owner.Buildings.Remove(entity.Position);
             break;
         case (long)Models.Definitions.EntityType.Scrapyard:
             DecreaseScrap(entity.Owner, entity);
             entity.Owner.Buildings.Remove(entity.Position);
             break;
     }
 }