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);
        }
Exemplo n.º 2
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));
        }
        public int GetCombatStrengthOfCity(ICity city)
        {
            int retval = Config.BaseCombatStrength + Mathf.RoundToInt(Config.CombatStrengthPerPopulation * city.Population);

            foreach (var building in BuildingPossessionCanon.GetPossessionsOfOwner(city))
            {
                retval += building.Template.CityCombatStrengthBonus;
            }

            return(retval);
        }
Exemplo n.º 4
0
        private bool HillCandidateFilter_ScoreIncreasing(IHexCell cell)
        {
            if (NodeLocationCanon.GetPossessionsOfOwner(cell).Any())
            {
                return(false);
            }

            return(cell.Shape == CellShape.Flatlands && cell.Vegetation == CellVegetation.None && (
                       cell.Terrain == CellTerrain.Desert || cell.Terrain == CellTerrain.Tundra ||
                       cell.Terrain == CellTerrain.Snow
                       ));
        }
Exemplo n.º 5
0
        public bool CanHandleCommandOnUnit(AbilityCommandRequest command, IUnit unit)
        {
            var unitOwner = UnitPossessionCanon.GetOwnerOfPossession(unit);

            var unitLocation = UnitPositionCanon.GetOwnerOfPossession(unit);

            bool hasRightType = command.Type == AbilityCommandType.AnnexAdjacentTerritory;

            bool unitInOwnerTerritory = CivTerritoryLogic.GetCivClaimingCell(unitLocation) == unitOwner;

            bool hasAnyCities = CityPossessionCanon.GetPossessionsOfOwner(unitOwner).Any();

            return(hasRightType && unitInOwnerTerritory && hasAnyCities);
        }
Exemplo n.º 6
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()));
                }
            }
        }
Exemplo n.º 7
0
        public T GetValueForCiv(ICivilization civ)
        {
            var retval = DataForExtraction.UnitaryValue;

            var policyBonuses = SocialPolicyCanon.GetPolicyBonusesForCiv(civ);

            var policyValues = policyBonuses.Select(bonuses => DataForExtraction.PolicyExtractor(bonuses));

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

            if (DataForExtraction.GlobalBuildingExtractor != null)
            {
                var citiesOf = CityPossessionCanon.GetPossessionsOfOwner(civ);

                var buildingsOf = citiesOf.SelectMany(
                    city => BuildingPossessionCanon.GetPossessionsOfOwner(city)
                    ).ToList();

                foreach (var building in buildingsOf)
                {
                    retval = DataForExtraction.Aggregator(
                        retval, DataForExtraction.GlobalBuildingExtractor(building.Template)
                        );
                }
            }

            return(retval);
        }
Exemplo n.º 8
0
        private Func <IHexCell, bool> GetLakeCandidateFilter(MapRegion region)
        {
            return(delegate(IHexCell cell) {
                if (cell.Terrain != CellTerrain.Snow && cell.Terrain != CellTerrain.Desert &&
                    !cell.Terrain.IsWater() && ModLogic.CanChangeTerrainOfCell(cell, CellTerrain.FreshWater)
                    )
                {
                    bool surroundedByLandOrLakes = Grid.GetNeighbors(cell).All(
                        neighbor => neighbor.Terrain != CellTerrain.ShallowWater &&
                        neighbor.Terrain != CellTerrain.DeepWater
                        );

                    bool hasResourceNode = NodePositionCanon.GetPossessionsOfOwner(cell).Any();

                    bool fewNearbylakes = Grid.GetCellsInRadius(cell, 2).Count(
                        nearby => nearby.Terrain == CellTerrain.FreshWater
                        ) < MaxNearbyLakes;

                    bool noAdjacentDesert = !Grid.GetNeighbors(cell).Any(neighbor => neighbor.Terrain == CellTerrain.Desert);

                    return surroundedByLandOrLakes && !hasResourceNode && fewNearbylakes && noAdjacentDesert;
                }
                else
                {
                    return false;
                }
            });
        }
Exemplo n.º 9
0
        public IEnumerable <IPromotion> GetGlobalPromotionsOfCiv(ICivilization civ)
        {
            if (civ == null)
            {
                throw new ArgumentNullException("civ");
            }

            var retval = new List <IPromotion>();

            foreach (var city in CityPossessionCanon.GetPossessionsOfOwner(civ))
            {
                foreach (var building in BuildingPossessionCanon.GetPossessionsOfOwner(city))
                {
                    retval.AddRange(building.Template.GlobalPromotions);
                }
            }

            foreach (var policy in SocialPolicyCanon.GetPoliciesUnlockedFor(civ))
            {
                retval.AddRange(policy.Bonuses.GlobalPromotions);
            }

            foreach (var policyTree in SocialPolicyCanon.GetTreesUnlockedFor(civ))
            {
                retval.AddRange(policyTree.UnlockingBonuses.GlobalPromotions);

                if (SocialPolicyCanon.IsTreeCompletedByCiv(policyTree, civ))
                {
                    retval.AddRange(policyTree.CompletionBonuses.GlobalPromotions);
                }
            }

            return(retval);
        }
        public bool IsTemplateValidForCity(IBuildingTemplate template, ICity city, ICivilization cityOwner)
        {
            if (template.Type != BuildingType.NationalWonder && template.Type != BuildingType.WorldWonder)
            {
                return(true);
            }

            var citiesOfOwner = CityPossessionCanon.GetPossessionsOfOwner(cityOwner);

            foreach (var otherCity in citiesOfOwner)
            {
                if (otherCity != city && otherCity.ActiveProject != null && otherCity.ActiveProject.BuildingToConstruct == template)
                {
                    return(false);
                }
            }

            IEnumerable <ICity> citiesToCheck = template.Type == BuildingType.NationalWonder ? citiesOfOwner : CityFactory.AllCities;

            foreach (var otherCity in citiesToCheck)
            {
                var buildingsOf = BuildingPossessionCanon.GetPossessionsOfOwner(otherCity);

                if (buildingsOf.Any(building => building.Template == template))
                {
                    return(false);
                }
            }

            return(true);
        }
        public YieldSummary GetTotalYieldForCity(ICity city, YieldSummary additionalBonuses)
        {
            if (city == null)
            {
                throw new ArgumentNullException("city");
            }

            var retval = CityCenterYieldLogic.GetYieldOfCityCenter(city);

            foreach (var cell in CellPossessionCanon.GetPossessionsOfOwner(city))
            {
                if (!cell.SuppressSlot && cell.WorkerSlot.IsOccupied)
                {
                    retval += GetYieldOfCellForCity(cell, city);
                }
            }

            foreach (var building in BuildingPossessionCanon.GetPossessionsOfOwner(city))
            {
                retval += GetYieldOfBuildingForCity(building, city);
            }

            retval += GetYieldOfUnemployedPersonForCity(city) * UnemploymentLogic.GetUnemployedPeopleInCity(city);

            return(retval * (YieldSummary.Ones + additionalBonuses));
        }
        public override void Refresh()
        {
            if (ObjectToDisplay == null)
            {
                return;
            }

            foreach (var display in InstantiatedDisplays)
            {
                Destroy(display.gameObject);
            }
            InstantiatedDisplays.Clear();

            foreach (var tile in PossessionCanon.GetPossessionsOfOwner(ObjectToDisplay))
            {
                if (tile.SuppressSlot)
                {
                    continue;
                }

                var newSlot = Container.InstantiatePrefabForComponent <WorkerSlotDisplay>(SlotDisplayPrefab);

                newSlot.Owner         = ObjectToDisplay;
                newSlot.SlotToDisplay = tile.WorkerSlot;

                newSlot.transform.SetParent(SlotDisplayContainer, false);
                newSlot.gameObject.transform.position = Camera.main.WorldToScreenPoint(tile.AbsolutePosition);
                newSlot.gameObject.SetActive(true);

                InstantiatedDisplays.Add(newSlot);
            }
        }
        /// <inheritdoc/>
        public YieldSummary GetYieldMultipliersForCity(ICity city)
        {
            if (city == null)
            {
                throw new ArgumentNullException("city");
            }

            var baseModifier = YieldSummary.Empty;

            foreach (var building in BuildingPossessionCanon.GetPossessionsOfOwner(city))
            {
                baseModifier += building.CityYieldModifier;
            }

            return(baseModifier);
        }
        /// <inheritdoc/>
        public YieldSummary GetYieldMultipliersForCivilization(ICivilization civ)
        {
            if (civ == null)
            {
                throw new ArgumentNullException("civilization");
            }

            var retval = YieldSummary.Empty;

            foreach (var city in CityPossessionCanon.GetPossessionsOfOwner(civ))
            {
                foreach (var building in BuildingPossessionCanon.GetPossessionsOfOwner(city))
                {
                    retval += building.CivilizationYieldModifier;
                }
            }

            int civHappiness = CivHappinessLogic.GetNetHappinessOfCiv(civ);

            if (civHappiness < 0)
            {
                var goldAndProductionLoss = civHappiness * CivConfig.YieldLossPerUnhappiness;

                retval[YieldType.Gold]       += goldAndProductionLoss;
                retval[YieldType.Production] += goldAndProductionLoss;
            }

            if (GoldenAgeCanon.IsCivInGoldenAge(civ))
            {
                retval += CivConfig.GoldenAgeProductionModifiers;
            }

            return(retval);
        }
        public bool ShouldCivBeDefeated(ICivilization civ)
        {
            if (!IsActive || !CivsToCheck.Contains(civ))
            {
                return(false);
            }

            var citiesOfCiv = CityPossessionCanon.GetPossessionsOfOwner(civ);
            var unitsOfCiv  = UnitPossessionCanon.GetPossessionsOfOwner(civ);

            if (CivConfig.DefeatMode == CivilizationDefeatMode.NoMoreCities)
            {
                var settlers = unitsOfCiv.Where(unit => CanBuildCityLogic.CanUnitBuildCity(unit));

                return(!citiesOfCiv.Any() && !settlers.Any());
            }
            else if (CivConfig.DefeatMode == CivilizationDefeatMode.NoMoreCitiesOrUnits)
            {
                return(!citiesOfCiv.Any() && !unitsOfCiv.Any());
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Exemplo n.º 16
0
        private bool IsUnitInCity(IUnit unit)
        {
            var unitLocation   = UnitPositionCanon.GetOwnerOfPossession(unit);
            var cityAtLocation = CityLocationCanon.GetPossessionsOfOwner(unitLocation).FirstOrDefault();

            return(cityAtLocation != null);
        }
Exemplo n.º 17
0
 private void OnCityBeingDestroyed(ICity city)
 {
     foreach (var building in PossessionCanon.GetPossessionsOfOwner(city).ToArray())
     {
         DestroyBuilding(building);
     }
 }
 private bool CandidateFilter(IHexCell cell)
 {
     return(!RiverCanon.HasRiver(cell) &&
            !NodeLocationCanon.GetPossessionsOfOwner(cell).Any() &&
            ModLogic.CanChangeTerrainOfCell(cell, CellTerrain.ShallowWater) &&
            Grid.GetNeighbors(cell).Any(neighbor => neighbor.Terrain == CellTerrain.ShallowWater) &&
            !Grid.GetNeighbors(cell).Any(neighbor => neighbor.Terrain == CellTerrain.FreshWater));
 }
        /// <inheritdoc/>
        public IEnumerable <IHexCell> GetAllCellsAvailableToCity(ICity city)
        {
            var retval = new HashSet <IHexCell>();

            foreach (var tile in PossessionCanon.GetPossessionsOfOwner(city))
            {
                foreach (var neighbor in HexGrid.GetNeighbors(tile))
                {
                    if (IsCellAvailable(city, neighbor))
                    {
                        retval.Add(neighbor);
                    }
                }
            }

            return(retval);
        }
Exemplo n.º 20
0
        public bool IsUnitGarrisoned(IUnit unit)
        {
            var unitLocation = UnitPositionCanon.GetOwnerOfPossession(unit);

            var citiesAt = CityLocationCanon.GetPossessionsOfOwner(unitLocation);

            return(citiesAt.Any());
        }
        private void OnCellBecameExploredByCiv(Tuple <IHexCell, ICivilization> data)
        {
            var cityAtCell = CityLocationCanon.GetPossessionsOfOwner(data.Item1).FirstOrDefault();

            if (cityAtCell != null && ExplorationCanon.IsCellExplored(data.Item1))
            {
                CitySummaryManager.BuildSummaryForCity(cityAtCell);
            }
        }
Exemplo n.º 22
0
        public override void Refresh()
        {
            if (ObjectToDisplay == null)
            {
                return;
            }

            DisplayBuildings(PossessionCanon.GetPossessionsOfOwner(ObjectToDisplay));
        }
Exemplo n.º 23
0
        private void OnImprovementRemovedFromLocation(Tuple <IImprovement, IHexCell> dataTuple)
        {
            var location = dataTuple.Item2;

            var nodeAtLocation = ResourceNodeLocationCanon.GetPossessionsOfOwner(location).FirstOrDefault();

            if (nodeAtLocation == null)
            {
                return;
            }

            var civOwningCell = CivTerritoryLogic.GetCivClaimingCell(location);

            if (civOwningCell != null)
            {
                ResourceTransferCanon.SynchronizeResourceForCiv(nodeAtLocation.Resource, civOwningCell);
            }
        }
Exemplo n.º 24
0
        private bool IsMovementValidForConnection(IHexCell fromCell, IHexCell toCell, ICivilization civOne, ICivilization civTwo)
        {
            if (toCell.Terrain.IsWater())
            {
                if (fromCell.Terrain.IsWater())
                {
                    return(true);
                }

                var cityAtFromCell = CityLocationCanon.GetPossessionsOfOwner(fromCell).FirstOrDefault();
                if (cityAtFromCell == null)
                {
                    return(false);
                }

                var cityOwner = CityPossessionCanon.GetOwnerOfPossession(cityAtFromCell);
                if (cityOwner != civOne && cityOwner != civTwo)
                {
                    return(false);
                }

                return(IsCityValidHarbor(cityAtFromCell));
            }
            else if (toCell.HasRoads)
            {
                return(true);
            }
            else
            {
                var cityAtToCell = CityLocationCanon.GetPossessionsOfOwner(toCell).FirstOrDefault();
                if (cityAtToCell == null)
                {
                    return(false);
                }

                var cityOwner = CityPossessionCanon.GetOwnerOfPossession(cityAtToCell);
                if (cityOwner != civOne && cityOwner != civTwo)
                {
                    return(false);
                }

                return(!fromCell.Terrain.IsWater() || toCell.Terrain.IsWater() || IsCityValidHarbor(cityAtToCell));
            }
        }
        public void SubscribeFreeBuildingToCiv(
            IEnumerable <IBuildingTemplate> validTemplates, ICivilization civ
            )
        {
            if (IsActive)
            {
                foreach (var city in CityPossessionCanon.GetPossessionsOfOwner(civ))
                {
                    if (FreeBuildingApplier.CanApplyFreeBuildingToCity(validTemplates, city))
                    {
                        FreeBuildingApplier.ApplyFreeBuildingToCity(validTemplates, city);

                        return;
                    }
                }
            }

            PendingFreeBuildingsOfCiv.AddElementToList(civ, validTemplates);
        }
Exemplo n.º 26
0
        public float GetNextGoldenAgeCostForCiv(ICivilization civ)
        {
            int cityCount = CityPossessionCanon.GetPossessionsOfOwner(civ).Count();

            float modifierFromCities = 1f + cityCount * CivConfig.GoldenAgePerCityMultiplier;

            float costFromPreviousAges = CivConfig.GoldenAgeCostPerPreviousAge * GetPreviousGoldenAgesForCiv(civ);

            return((CivConfig.GoldenAgeBaseCost + costFromPreviousAges) * modifierFromCities);
        }
Exemplo n.º 27
0
        public IEnumerable <IHexCell> GetCellsClaimedByCiv(ICivilization civ)
        {
            var retval = new List <IHexCell>();

            foreach (var city in CityPossessionCanon.GetPossessionsOfOwner(civ))
            {
                retval.AddRange(CityTerritoryCanon.GetPossessionsOfOwner(city));
            }

            return(retval);
        }
        public int GetStartingExperienceForUnit(IUnit unit, ICity producingCity)
        {
            int retval = 0;

            foreach (var building in BuildingPossessionCanon.GetPossessionsOfOwner(producingCity))
            {
                retval += building.Template.BonusExperience;
            }

            return(retval);
        }
        public int GetLocalHappinessOfCity(ICity city)
        {
            if (city == null)
            {
                throw new ArgumentNullException("city");
            }

            int retval = 0;

            foreach (var building in BuildingPossessionCanon.GetPossessionsOfOwner(city))
            {
                retval += building.Template.LocalHappiness;
            }

            retval += Mathf.FloorToInt(
                city.Population * CityModifiers.PerPopulationHappiness.GetValueForCity(city)
                );

            return(retval);
        }
Exemplo n.º 30
0
        private IEnumerable <IBuilding> GetGlobalBuildings(ICivilization civ)
        {
            var retval = new List <IBuilding>();

            foreach (var city in CityPossessionCanon.GetPossessionsOfOwner(civ))
            {
                retval.AddRange(BuildingPossessionCanon.GetPossessionsOfOwner(city));
            }

            return(retval);
        }