Exemple #1
0
    //create wall
    private void CreateWall(CityCell cell, CityCell otherCell, CityDirection direction)
    {
        CityWall wall = Instantiate(wallPrefab) as CityWall;

        wall.Initialize(cell, otherCell, direction);
        if (otherCell != null)
        {
            wall = Instantiate(wallPrefab) as CityWall;
            wall.Initialize(otherCell, cell, direction.getOpposite());
        }
    }
Exemple #2
0
        public TownGeometry GetTownGeometry(TownOptions options)
        {
            var geometry = new TownGeometry();

            var buildingShapes = new List <Polygon> ();

            foreach (var patch in Patches.Where(p => p.Area != null))
            {
                buildingShapes.AddRange(patch.Area.GetGeometry());
            }

            var buildingPlacer = new BuildingPlacer(buildingShapes);
            var buildings      = buildingPlacer.PopulateBuildings();

            geometry.Buildings.AddRange(buildings);
            if (options.Walls)
            {
                geometry.Walls.AddRange(CityWall.GetEdges().Union(Castle.Wall.GetEdges()).Distinct());
                geometry.Towers.AddRange(CityWall.Towers.Union(Castle.Wall.Towers));
                geometry.Gates.AddRange(CityWall.Gates.Union(Castle.Wall.Gates));
            }
            else
            {
                var castleWall = CityWall.GetEdges().Union(Castle.Wall.GetEdges()).Distinct().SelectMany(e => new [] { e.A, e.B }).Where(w => Castle.Patch.Shape.Vertices.Contains(w)).ToList();
                var towers     = CityWall.Towers.Union(Castle.Wall.Towers).Intersect(castleWall);
                var gates      = CityWall.Gates.Union(Castle.Wall.Gates).Intersect(castleWall);
                geometry.Walls.AddRange(Edge.FromPointList(castleWall));
                geometry.Towers.AddRange(towers);
                geometry.Gates.AddRange(gates);
            }
            geometry.Roads.AddRange(Roads);
            geometry.Roads.AddRange(Streets);

            geometry.Overlay.AddRange(Patches);
            geometry.Water.AddRange(Patches.Where(p => p.Water).Select(p => p.Shape));
            geometry.WaterBorder = new Polygon(WaterBorder);

            return(geometry);
        }
Exemple #3
0
        private List <List <Vector2> > TidyUpRoads(List <List <Vector2> > roads)
        {
            var roadEdges = roads.SelectMany(RoadToEdges).Distinct().ToList();

            var arteries = new List <List <Vector2> > ();

            while (roadEdges.Any())
            {
                var edge = roadEdges[0];
                roadEdges.RemoveAt(0);

                var attached = false;
                foreach (var artery in arteries)
                {
                    if (artery[0].Equals(edge.B))
                    {
                        artery.Insert(0, edge.A);
                        attached = true;
                        break;
                    }

                    if (artery.Last().Equals(edge.A))
                    {
                        artery.Add(edge.B);
                        attached = true;
                        break;
                    }
                }

                if (!attached)
                {
                    arteries.Add(new List <Vector2> {
                        edge.A, edge.B
                    });
                }
            }

            var smoothed = new List <List <Vector2> > ();

            foreach (var tidyRoad in arteries)
            {
                var smoothedRoad = tidyRoad.SmoothVertexList(3);

                for (var i = 0; i < tidyRoad.Count; i++)
                {
                    var originalPoint   = tidyRoad[i];
                    var smoothedPoint   = smoothedRoad[i];
                    var affectedPatches = Patches.Where(p => p.Shape.Vertices.Contains(originalPoint)).ToList();
                    foreach (var affectedPatch in affectedPatches)
                    {
                        affectedPatch.Shape.ReplaceVertex(originalPoint, smoothedPoint);
                    }

                    if (CityWall.Circumference.Contains(originalPoint))
                    {
                        CityWall.ReplaceWallPoint(originalPoint, smoothedPoint);
                    }

                    if (Castle.Wall.Circumference.Contains(originalPoint))
                    {
                        Castle.Wall.ReplaceWallPoint(originalPoint, smoothedPoint);
                    }

                    var gateIndex = Gates.IndexOf(originalPoint);
                    if (gateIndex >= 0)
                    {
                        Gates[gateIndex] = smoothedPoint;
                    }
                }

                smoothed.Add(smoothedRoad);
            }

            return(smoothed);
        }
Exemple #4
0
        private async Task <City> CreateCity(ApplicationUser user)
        {
            //Get the upgrade costs which will be used to create the buildings
            BuildingUpgradeCost warehouseCost = await _unitOfWork.UpgradeCosts.FindUpgradeCost("Warehouse", 1);

            BuildingUpgradeCost silverMineCost = await _unitOfWork.UpgradeCosts.FindUpgradeCost("SilverMine", 1);

            BuildingUpgradeCost stoneMineCost = await _unitOfWork.UpgradeCosts.FindUpgradeCost("StoneMine", 1);

            BuildingUpgradeCost lumberCost = await _unitOfWork.UpgradeCosts.FindUpgradeCost("Lumber", 1);

            BuildingUpgradeCost farmCost = await _unitOfWork.UpgradeCosts.FindUpgradeCost("Farm", 1);

            BuildingUpgradeCost cityWallCost = await _unitOfWork.UpgradeCosts.FindUpgradeCost("CityWall", 1);

            BuildingUpgradeCost cityhallCost = await _unitOfWork.UpgradeCosts.FindUpgradeCost("CityHall", 1);

            BuildingUpgradeCost barrackCost = await _unitOfWork.UpgradeCosts.FindUpgradeCost("Barrack", 1);

            //Create the buildings
            Warehouse          warehouse  = Warehouse.Create(warehouseCost);
            ResourceProduction silverMine = ResourceProduction.CreateResourceProductionBuilding(silverMineCost);

            silverMine.ResourceType = ResourceType.silver;
            ResourceProduction stoneMine = ResourceProduction.CreateResourceProductionBuilding(stoneMineCost);

            stoneMine.ResourceType = ResourceType.stone;
            ResourceProduction lumber = ResourceProduction.CreateResourceProductionBuilding(lumberCost);

            lumber.ResourceType = ResourceType.wood;
            Farm     farm     = Farm.Create(farmCost);
            CityWall cityWall = CityWall.Create(cityWallCost);
            CityHall cityHall = CityHall.Create(cityhallCost);
            Barrack  barrack  = Barrack.Create(barrackCost);

            //Add the buildings to the city
            City city = new City
            {
                CityName  = $"{user.UserName}'s city",
                Resources = new Resources
                {
                    Wood       = 1000,
                    Stone      = 1000,
                    Silver     = 1000,
                    Population = 100
                },
                UserId             = user.Id,
                User               = user,
                SilverProductionId = silverMine.Id,
                SilverProduction   = silverMine,
                StoneProductionId  = stoneMine.Id,
                StoneProduction    = stoneMine,
                WoodProductionId   = lumber.Id,
                WoodProduction     = lumber,
                BarrackId          = barrack.Id,
                Barrack            = barrack,
                FarmId             = farm.Id,
                Farm               = farm,
                CityWallId         = cityWall.Id,
                CityWall           = cityWall,
                CityHallId         = cityHall.Id,
                CityHall           = cityHall,
                WarehouseId        = warehouse.Id,
                Warehouse          = warehouse
            };

            return(city);
        }
Exemple #5
0
 public List <CityWall> getOwnedUnitsOfThisType(CityWall unit)
 {
     return(ownedUnits [typeof(CityWall)].Cast <CityWall> ().ToList());
 }
Exemple #6
0
 public void addOwnedUnit(CityWall unit)
 {
     ownedUnits [typeof(CityWall)].Add(unit);
     ownedUnits [typeof(Unit)].Add(unit);
 }