private void DecomposeAppliedTemplates(SerializableCityData cityData, ICity newCity)
        {
            if (cityData.AppliedFreeBuildings != null)
            {
                var appliedBuildings = new List <IBuildingTemplate>();

                foreach (var templateName in cityData.AppliedFreeBuildings)
                {
                    var templateOfName = AvailableBuildingTemplates.Where(
                        template => template.name.Equals(templateName)
                        ).FirstOrDefault();

                    if (templateOfName == null)
                    {
                        throw new InvalidOperationException(string.Format(
                                                                "CityData.AppliedBuildingTemplates contained invalid building name {0}", templateName
                                                                ));
                    }

                    appliedBuildings.Add(templateOfName);
                }

                FreeBuildingApplier.OverrideTemplatesAppliedToCity(newCity, appliedBuildings);
            }
        }
        public void ComposeCities(SerializableMapData mapData)
        {
            mapData.Cities = new List <SerializableCityData>();

            foreach (var city in CityFactory.AllCities)
            {
                var cityData = new SerializableCityData()
                {
                    Name             = city.Name,
                    Location         = CityLocationCanon.GetOwnerOfPossession(city).Coordinates,
                    Owner            = CityPossessionCanon.GetOwnerOfPossession(city).Template.Name,
                    Population       = city.Population,
                    FoodStockpile    = city.FoodStockpile,
                    CultureStockpile = city.CultureStockpile,
                    YieldFocus       = city.YieldFocus,
                    Hitpoints        = city.CombatFacade.CurrentHitpoints,
                    CurrentMovement  = city.CombatFacade.CurrentMovement
                };

                var activeProject = city.ActiveProject;

                if (activeProject != null)
                {
                    cityData.ActiveProject = new SerializableProjectData()
                    {
                        BuildingToConstruct = activeProject.BuildingToConstruct != null ? activeProject.BuildingToConstruct.name : null,
                        UnitToConstruct     = activeProject.UnitToConstruct != null ? activeProject.UnitToConstruct.name : null,

                        Progress = activeProject.Progress
                    };
                }

                cityData.AppliedFreeBuildings = FreeBuildingApplier.GetTemplatesAppliedToCity(city)
                                                .Select(template => template.name)
                                                .ToList();

                mapData.Cities.Add(cityData);
            }
        }
        private void DecomposeActiveProject(SerializableCityData cityData, ICity newCity)
        {
            if (cityData.ActiveProject != null)
            {
                if (cityData.ActiveProject.BuildingToConstruct != null)
                {
                    var buildingTemplate = AvailableBuildingTemplates.Where(
                        template => template.name.Equals(cityData.ActiveProject.BuildingToConstruct)
                        ).First();

                    newCity.ActiveProject = ProjectFactory.ConstructProject(buildingTemplate);
                }
                else
                {
                    var unitTemplate = AvailableUnitTemplates.Where(
                        template => template.name.Equals(cityData.ActiveProject.UnitToConstruct)
                        ).First();

                    newCity.ActiveProject = ProjectFactory.ConstructProject(unitTemplate);
                }

                newCity.ActiveProject.Progress = cityData.ActiveProject.Progress;
            }
        }