예제 #1
0
        private void OnCivGainedCity(Tuple <ICivilization, ICity> data)
        {
            var civ  = data.Item1;
            var city = data.Item2;

            if (CapitalCityCanon.GetCapitalOfCiv(civ) == null)
            {
                CapitalCityCanon.SetCapitalOfCiv(civ, city);
            }
        }
        public bool AreCivilizationsConnected(ICivilization civOne, ICivilization civTwo)
        {
            var capitalOne = CapitalCityCanon.GetCapitalOfCiv(civOne);
            var capitalTwo = CapitalCityCanon.GetCapitalOfCiv(civTwo);

            var capitalOneLocation = CityLocationCanon.GetOwnerOfPossession(capitalOne);
            var capitalTwoLocation = CityLocationCanon.GetOwnerOfPossession(capitalTwo);

            return(HexPathfinder.GetShortestPathBetween(
                       capitalOneLocation, capitalTwoLocation, ConnectionPathCostLogic.BuildCivConnectionPathCostFunction(civOne, civTwo)
                       ) != null);
        }
        public float GetBorderExpansionModifierForCity(ICity city)
        {
            float localBuildingModifiers = BuildingPossessionCanon.GetPossessionsOfOwner(city).Sum(
                building => building.Template.LocalBorderExpansionModifier
                );

            var cityOwner = CityPossessionCanon.GetOwnerOfPossession(city);

            var citiesOfOwner = CityPossessionCanon.GetPossessionsOfOwner(cityOwner).ToArray();

            var buildingsOfOwner = new List <IBuilding>();

            foreach (var ownedCity in citiesOfOwner)
            {
                buildingsOfOwner.AddRange(BuildingPossessionCanon.GetPossessionsOfOwner(ownedCity));
            }

            float globalBuildingModifiers = buildingsOfOwner.Sum(building => building.Template.GlobalBorderExpansionModifier);

            var policyBonuses = SocialPolicyCanon.GetPolicyBonusesForCiv(cityOwner);

            float policyModifiers = policyBonuses.Sum(bonuses => bonuses.CityBorderExpansionModifier);

            if (CapitalCityCanon.GetCapitalOfCiv(cityOwner) == city)
            {
                policyModifiers += policyBonuses.Sum(bonuses => bonuses.CapitalBorderExpansionModifier);
            }

            return(1f + localBuildingModifiers + globalBuildingModifiers + policyModifiers);
        }
        public bool IsCityConnectedToCapital(ICity city)
        {
            var cityOwner = CityPossessionCanon.GetOwnerOfPossession(city);

            var capitalOfOwner = CapitalCityCanon.GetCapitalOfCiv(cityOwner);

            if (capitalOfOwner == city)
            {
                return(true);
            }

            if (capitalOfOwner == null)
            {
                return(false);
            }

            var cityLocation    = CityLocationCanon.GetOwnerOfPossession(city);
            var capitalLocation = CityLocationCanon.GetOwnerOfPossession(capitalOfOwner);

            var pathTo = HexPathfinder.GetShortestPathBetween(
                cityLocation, capitalLocation, ConnectionPathCostLogic.BuildCapitalConnectionPathCostFunction(cityOwner)
                );

            return(pathTo != null);
        }
예제 #5
0
        public void ReturnFocusToPlayer(IPlayer player)
        {
            var civOfPlayer = player.ControlledCiv;

            var capital = CapitalCityCanon.GetCapitalOfCiv(civOfPlayer);

            if (capital != null)
            {
                var capitalLocation = CityLocationCanon.GetOwnerOfPossession(capital);

                GameCamera.SnapToCell(capitalLocation);
            }
            else
            {
                var unitsOf = UnitPossessionCanon.GetPossessionsOfOwner(civOfPlayer);

                var cityBuilder = unitsOf.Where(unit => CanBuildCityLogic.CanUnitBuildCity(unit)).FirstOrDefault();

                if (cityBuilder != null)
                {
                    GameCamera.SnapToCell(UnitPositionCanon.GetOwnerOfPossession(cityBuilder));
                }
                else if (unitsOf.Any())
                {
                    GameCamera.SnapToCell(UnitPositionCanon.GetOwnerOfPossession(unitsOf.FirstOrDefault()));
                }
            }
        }
예제 #6
0
        public T GetValueForCity(ICity city)
        {
            T retval = default(T);

            var cityOwner = CityPossessionCanon.GetOwnerOfPossession(city);

            var ownerCapital = CapitalCityCanon.GetCapitalOfCiv(cityOwner);

            if (city == ownerCapital)
            {
                IEnumerable <T> capitalValues = SocialPolicyCanon
                                                .GetPolicyBonusesForCiv(cityOwner)
                                                .Select(bonuses => DataForExtraction.PolicyCapitalBonusesExtractor(bonuses));

                if (capitalValues.Any())
                {
                    retval = DataForExtraction.Aggregator(
                        retval, capitalValues.Aggregate(DataForExtraction.Aggregator)
                        );
                }
            }

            IEnumerable <T> cityValues = SocialPolicyCanon
                                         .GetPolicyBonusesForCiv(cityOwner)
                                         .Select(bonuses => DataForExtraction.PolicyCityBonusesExtractor(bonuses));

            if (cityValues.Any())
            {
                retval = DataForExtraction.Aggregator(
                    retval, cityValues.Aggregate(DataForExtraction.Aggregator)
                    );
            }

            if (DataForExtraction.BuildingLocalBonusesExtractor != null)
            {
                foreach (var building in BuildingPossessionCanon.GetPossessionsOfOwner(city))
                {
                    retval = DataForExtraction.Aggregator(
                        retval, DataForExtraction.BuildingLocalBonusesExtractor(building.Template)
                        );
                }
            }

            if (DataForExtraction.BuildingGlobalBonusesExtractor != null)
            {
                foreach (var building in GetGlobalBuildings(cityOwner))
                {
                    retval = DataForExtraction.Aggregator(
                        retval, DataForExtraction.BuildingGlobalBonusesExtractor(building.Template)
                        );
                }
            }

            return(DataForExtraction.Aggregator(DataForExtraction.UnitaryValue, retval));
        }
        private void BuildUnitsFromBonuses(ICivilization civ, ISocialPolicyBonusesData bonuses)
        {
            var civCapital = CapitalCityCanon.GetCapitalOfCiv(civ);

            var capitalLocation = CityLocationCanon.GetOwnerOfPossession(civCapital);

            foreach (var templateToBuild in bonuses.FreeUnits)
            {
                var validCell = GetValidNearbyCell(capitalLocation, templateToBuild, civ);

                UnitFactory.BuildUnit(validCell, templateToBuild, civ);
            }
        }
예제 #8
0
        public void ComposeCapitalCities(SerializableMapData mapData)
        {
            for (int i = 0; i < CivFactory.AllCivilizations.Count; i++)
            {
                var civ     = CivFactory.AllCivilizations[i];
                var civData = mapData.Civilizations[i];

                var civCapital = CapitalCityCanon.GetCapitalOfCiv(civ);

                if (civCapital != null)
                {
                    var capitalLocation = CityLocationCanon.GetOwnerOfPossession(civCapital);

                    civData.CapitalLocation = capitalLocation.Coordinates;
                }
                else
                {
                    civData.CapitalLocation = null;
                }
            }
        }
예제 #9
0
 public bool CanBuildGreatPerson(GreatPersonType type, ICivilization owner)
 {
     return(CapitalCityCanon.GetCapitalOfCiv(owner) != null);
 }