private List <IGarrison> GetNearbyTargets() { List <IGarrison> result = new List <IGarrison>(); if (this.Fortress.Occupant == null) { return(result); } float propertyValue = this.Fortress.GetPropertyValue(SimulationProperties.MaximumNumberOfActionPoints); float propertyValue2 = this.Fortress.GetPropertyValue(SimulationProperties.ActionPointsSpent); if (propertyValue <= propertyValue2) { return(result); } DepartmentOfForeignAffairs agency = this.Fortress.Occupant.GetAgency <DepartmentOfForeignAffairs>(); float num = float.MaxValue; foreach (Unit unit in this.Fortress.StandardUnits) { num = Mathf.Min(unit.GetPropertyValue(SimulationProperties.Movement), num); } if (num == 3.40282347E+38f || num < 3f) { return(result); } AILayer_Military.HasSaveAttackableTargetsNearby(this.Fortress, Mathf.CeilToInt(num + 1f), agency, out result, true); return(result); }
private static bool ValidateTarget(Army myArmy, IGameEntity gameEntity, DepartmentOfForeignAffairs departmentOfForeignAffairs, bool canAttack, IGameEntityRepositoryService gameEntityRepositoryService, IWorldPositionningService worldPositionningService) { if (gameEntity == null) { return(false); } if (!gameEntityRepositoryService.Contains(gameEntity.GUID)) { return(false); } if (departmentOfForeignAffairs != null) { IGarrison garrison = gameEntity as IGarrison; if (gameEntity is Kaiju) { garrison = (gameEntity as Kaiju).GetActiveTroops(); gameEntity = garrison; } IWorldPositionable worldPositionable = gameEntity as IWorldPositionable; Region region = worldPositionningService.GetRegion(worldPositionable.WorldPosition); if (garrison == null || worldPositionable == null) { return(false); } if (canAttack) { if (!departmentOfForeignAffairs.CanAttack(gameEntity) || garrison.Empire.Index == myArmy.Empire.Index) { return(false); } } else if (!departmentOfForeignAffairs.IsEnnemy(garrison.Empire)) { return(false); } if ((garrison.Empire is MinorEmpire || garrison is Village) && region != null && region.IsRegionColonized() && departmentOfForeignAffairs != null && departmentOfForeignAffairs.IsEnnemy(region.Owner)) { return(false); } } Army army = gameEntity as Army; if (army != null) { if (myArmy.Empire is LesserEmpire && !(army.Empire is MajorEmpire)) { return(false); } District district = worldPositionningService.GetDistrict(army.WorldPosition); if (district != null && district.Type != DistrictType.Exploitation && army.Empire == district.Empire) { return(false); } if (!myArmy.HasSeafaringUnits() && army.IsNaval) { return(false); } } return(true); }
protected override IEnumerator OnShow(params object[] parameters) { yield return(base.OnShow(parameters)); ISessionService service = Services.GetService <ISessionService>(); int lobbyData = service.Session.GetLobbyData <int>("NumberOfMajorFactions", 0); this.scoreGraphsPanel.HideUnknownEmpires = true; EmpireInfo[] array = new EmpireInfo[lobbyData]; for (int i = 0; i < lobbyData; i++) { array[i] = EmpireInfo.Read(service.Session, i); if (array[i].IsActiveOrLocalPlayer && array[i].EmpireEliminated) { this.scoreGraphsPanel.HideUnknownEmpires = false; } } Services.GetService <IEndTurnService>().GameClientStateChange += this.EndTurnService_GameClientStateChange; DepartmentOfForeignAffairs agency = base.PlayerController.Empire.GetAgency <DepartmentOfForeignAffairs>(); if (agency != null) { agency.DiplomaticRelationStateChange += this.DepartmentOfForeignAffairs_DiplomaticRelationStateChange; } this.scoreGraphsPanel.Show(new object[] { array }); this.RefreshContent(); yield break; }
private void EventService_EventRaise(object sender, EventRaiseEventArgs eventArgs) { EventEmpireEliminated eventEmpireEliminated = eventArgs.RaisedEvent as EventEmpireEliminated; if (eventEmpireEliminated == null) { return; } Amplitude.Unity.Game.Empire eliminatedEmpire = eventEmpireEliminated.EliminatedEmpire; DepartmentOfForeignAffairs agency = eliminatedEmpire.GetAgency <DepartmentOfForeignAffairs>(); Diagnostics.Assert(agency != null); for (int i = 0; i < this.majorEmpires.Length; i++) { global::Empire empire = this.majorEmpires[i]; if (i != eliminatedEmpire.Index) { DiplomaticRelation diplomaticRelation = agency.GetDiplomaticRelation(empire); Diagnostics.Assert(diplomaticRelation != null && diplomaticRelation.State != null); if (diplomaticRelation.State.Name != DiplomaticRelationState.Names.Dead) { OrderChangeDiplomaticRelationState order = new OrderChangeDiplomaticRelationState(eliminatedEmpire.Index, i, DiplomaticRelationState.Names.Dead); this.PlayerController.PostOrder(order); } } } }
public static float GetCampDefenseLocalPriority(Camp camp, float unitRatioBoost, int simulatedUnitsCount = -1) { if (camp == null) { return(0f); } DepartmentOfForeignAffairs agency = camp.Empire.GetAgency <DepartmentOfForeignAffairs>(); if (agency.IsInWarWithSomeone() && AILayer_Military.AreaIsSave(camp.WorldPosition, 12, agency, false)) { return(0f); } if (camp.City.BesiegingEmpire != null) { return(0f); } float normalizedScore = 0f; float num; if (simulatedUnitsCount >= 0) { num = (float)simulatedUnitsCount / (float)camp.MaximumUnitSlot; } else { num = (float)camp.StandardUnits.Count / (float)camp.MaximumUnitSlot; } float normalizedScore2 = AILayer.Boost(normalizedScore, (1f - num) * unitRatioBoost); float developmentRatioOfCamp = AIScheduler.Services.GetService <IEntityInfoAIHelper>().GetDevelopmentRatioOfCamp(camp); return(AILayer.Boost(normalizedScore2, (1f - developmentRatioOfCamp) * AILayer_Military.cityDevRatioBoost)); }
public void ComputeContinentOccupation(global::Empire empire, int continentID, out int numberOfAlliesOnContinent, out int numberOfEnnemiesOnContinent) { numberOfAlliesOnContinent = 0; numberOfEnnemiesOnContinent = 0; DepartmentOfForeignAffairs agency = empire.GetAgency <DepartmentOfForeignAffairs>(); int[] regionList = this.world.Continents[continentID].RegionList; for (int i = 0; i < regionList.Length; i++) { Region region = this.world.Regions[i]; if (region.City != null) { DiplomaticRelation diplomaticRelation = agency.GetDiplomaticRelation(region.City.Empire); if (diplomaticRelation.State != null) { if (diplomaticRelation.State.Name == DiplomaticRelationState.Names.War || diplomaticRelation.State.Name == DiplomaticRelationState.Names.ColdWar || diplomaticRelation.State.Name == DiplomaticRelationState.Names.Truce) { numberOfEnnemiesOnContinent++; } if (diplomaticRelation.State.Name == DiplomaticRelationState.Names.Peace || diplomaticRelation.State.Name == DiplomaticRelationState.Names.Alliance) { numberOfAlliesOnContinent++; } } } } }
public override void RefreshContent() { base.RefreshContent(); if (base.Empire == null) { return; } if (this.SelectedEmpire == null) { return; } this.DiplomaticRelationshipDisk.RefreshContent(); this.TheirEmpirePointsValueLabel.Text = this.FormatEmpirePoints(this.SelectedEmpire, false); DepartmentOfForeignAffairs agency = this.SelectedEmpire.GetAgency <DepartmentOfForeignAffairs>(); this.MarketplaceBannedIcon.AgeTransform.Visible = agency.IsBannedFromMarket(); this.BlackSpotVictimIcon.AgeTransform.Visible = agency.IsBlackSpotVictim(); this.RefreshDiplomaticAbilities(); this.MyTermOptionsPanel.RefreshContent(); this.TheirTermOptionsPanel.RefreshContent(); this.ContractPanel.RefreshContent(); bool flag = this.PlayerDiplomaticRelationWithOther.State.Name != DiplomaticRelationState.Names.Dead; this.MyTermOptionsPanel.AgeTransform.Enable = (flag && this.interactionsAllowed); this.TheirTermOptionsPanel.AgeTransform.Enable = (flag && this.interactionsAllowed); this.ContractPanel.AgeTransform.Enable = (flag && this.interactionsAllowed); this.RefreshButtons(); if (flag && this.DiplomaticContract != null) { Diagnostics.Assert(this.DiplomaticContract.EmpireWhichReceives.Index == this.SelectedEmpire.Index, "The current selected empire ({0}) does not match the current receiver empire ({1}).", new object[] { this.DiplomaticContract.EmpireWhichReceives, this.SelectedEmpire }); bool flag2 = this.DiplomaticContract.Terms.Count > 0 && this.DiplomaticContract.GetPropositionMethod() == DiplomaticTerm.PropositionMethod.Negotiation; this.DealApprovalGroup.Visible = true; this.DealApprovalGroup.Enable = flag2; if (this.SelectedEmpire.IsControlledByAI) { this.DealApprovalGauge.AgeTransform.Visible = flag2; } else { this.DealApprovalGauge.AgeTransform.Visible = false; } this.RefreshApprovalSlider(); this.OfferTitleLabel.Text = "%NegotiationMakeAnOfferTitle"; if (this.DiplomaticContract.Terms.Count > 0 && this.DiplomaticContract.GetPropositionMethod() == DiplomaticTerm.PropositionMethod.Declaration) { this.OfferTitleLabel.Text = "%NegotiationDeclareTitle"; } } else { this.DealApprovalGroup.Visible = false; } }
public static bool IsRegionValidForExploration(global::Empire empire, int regionIndex) { Diagnostics.Assert(AIScheduler.Services != null); IWorldAtlasAIHelper service = AIScheduler.Services.GetService <IWorldAtlasAIHelper>(); Diagnostics.Assert(service != null); if (empire != null) { DepartmentOfForeignAffairs agency = empire.GetAgency <DepartmentOfForeignAffairs>(); if (agency != null && !agency.CanMoveOn(regionIndex, false)) { return(false); } } DepartmentOfTheInterior agency2 = empire.GetAgency <DepartmentOfTheInterior>(); if (agency2 != null) { bool flag = false; for (int i = 0; i < agency2.Cities.Count; i++) { if (agency2.Cities[i].Region.ContinentID == service.Regions[regionIndex].ContinentID) { flag = true; break; } } if (agency2.Cities.Count == 0) { flag = true; } if (!flag) { DepartmentOfCreepingNodes agency3 = empire.GetAgency <DepartmentOfCreepingNodes>(); if (agency3 != null) { using (List <CreepingNode> .Enumerator enumerator = agency3.Nodes.GetEnumerator()) { while (enumerator.MoveNext()) { if (!enumerator.Current.IsUnderConstruction && AILayer_Exploration.IsTravelAllowedInNode(empire, enumerator.Current) && enumerator.Current.Region.ContinentID == service.Regions[regionIndex].ContinentID) { flag = true; break; } } } } } if (!flag) { return(false); } } return(!service.IsRegionExplored(empire.Index, regionIndex, 0.95f)); }
public override State CheckCondition(QuestBehaviour questBehaviour, GameEvent gameEvent, params object[] parameters) { if (this.RegionIndex != -1) { IGameService service = Services.GetService <IGameService>(); Diagnostics.Assert(service != null); global::Game game = service.Game as global::Game; if (game == null) { return(State.Failure); } IWorldPositionningService service2 = service.Game.Services.GetService <IWorldPositionningService>(); global::Empire empire; if (gameEvent != null) { empire = (gameEvent.Empire as global::Empire); } else { empire = questBehaviour.Initiator; } DepartmentOfForeignAffairs agency = empire.GetAgency <DepartmentOfForeignAffairs>(); Diagnostics.Assert(agency != null); for (int i = 0; i < game.Empires.Length; i++) { if (i != empire.Index && (this.IgnoredEmpiresIndex == null || !this.IgnoredEmpiresIndex.Contains(i))) { global::Empire empire2 = game.Empires[i]; bool flag; if (empire2 is MajorEmpire) { DiplomaticRelation diplomaticRelation = agency.GetDiplomaticRelation(empire2); Diagnostics.Assert(diplomaticRelation != null); Diagnostics.Assert(diplomaticRelation.State != null); flag = (diplomaticRelation.State.Name == DiplomaticRelationState.Names.ColdWar || diplomaticRelation.State.Name == DiplomaticRelationState.Names.War || diplomaticRelation.State.Name == DiplomaticRelationState.Names.Unknown); } else { flag = true; } if (flag) { DepartmentOfDefense agency2 = empire2.GetAgency <DepartmentOfDefense>(); for (int j = 0; j < agency2.Armies.Count; j++) { if ((this.IncludeNaval || !agency2.Armies[j].IsNaval) && (int)service2.GetRegionIndex(agency2.Armies[j].WorldPosition) == this.RegionIndex) { return(State.Success); } } } } } } return(State.Failure); }
public override void RefreshContent() { base.RefreshContent(); this.RelationshipGroup.RefreshContent(); this.RefreshDiplomaticAbilities(); DepartmentOfForeignAffairs agency = this.AmbassadorEmpire.GetAgency <DepartmentOfForeignAffairs>(); this.MarketplaceBannedIcon.AgeTransform.Visible = agency.IsBannedFromMarket(); this.BlackSpotVictimIcon.AgeTransform.Visible = agency.IsBlackSpotVictim(); }
private float GetTargetPower(IWorldPositionable worldPositionable, int size, global::Empire myEmpire, IGameService service) { DepartmentOfForeignAffairs agency = myEmpire.GetAgency <DepartmentOfForeignAffairs>(); float num = 0f; if (worldPositionable is KaijuGarrison) { num += (worldPositionable as KaijuGarrison).GetPropertyValue(SimulationProperties.MilitaryPower); } else if (worldPositionable is Kaiju && (worldPositionable as Kaiju).OnGarrisonMode()) { num += (worldPositionable as Kaiju).GetActiveTroops().GetPropertyValue(SimulationProperties.MilitaryPower); } if (size > 0) { foreach (global::Empire empire in (service.Game as global::Game).Empires) { if (empire is KaijuEmpire) { KaijuEmpire kaijuEmpire = empire as KaijuEmpire; if (kaijuEmpire != null && kaijuEmpire.Region != null) { KaijuCouncil agency2 = kaijuEmpire.GetAgency <KaijuCouncil>(); if (agency2 != null && agency2.Kaiju != null && agency2.Kaiju.IsTamed() && agency2.Kaiju.OnGarrisonMode() && this.worldPositionningService.GetDistance(worldPositionable.WorldPosition, agency2.Kaiju.WorldPosition) <= size && agency.IsEnnemy(agency2.Kaiju.MajorEmpire)) { num += agency2.Kaiju.KaijuGarrison.GetPropertyValue(SimulationProperties.MilitaryPower); } } } } List <City> list = new List <City>(); foreach (WorldPosition worldPosition in new WorldCircle(worldPositionable.WorldPosition, size).GetWorldPositions(this.worldPositionningService.World.WorldParameters)) { Army armyAtPosition = this.worldPositionningService.GetArmyAtPosition(worldPosition); if (armyAtPosition != null && !armyAtPosition.IsFomorian && agency.IsEnnemy(armyAtPosition.Empire)) { num += armyAtPosition.GetPropertyValue(SimulationProperties.MilitaryPower); } District district = this.worldPositionningService.GetDistrict(worldPosition); if (district != null && district.Empire != null && district.City != null && agency.IsEnnemy(district.Empire)) { if (district.Type == DistrictType.Camp) { num += district.City.Camp.GetPropertyValue(SimulationProperties.MilitaryPower); } else if (!list.Contains(district.City)) { num += district.City.GetPropertyValue(SimulationProperties.MilitaryPower); list.Add(district.City); } } } } return(num); }
public static bool AreaIsSave(WorldPosition pos, int size, DepartmentOfForeignAffairs departmentOfForeignAffairs, out float rangescore, out float incomingMP, bool NavalOnly = false) { incomingMP = 0f; rangescore = 0f; if (size < 1) { return(true); } List <global::Empire> list = new List <global::Empire>(Array.FindAll <global::Empire>((Services.GetService <IGameService>().Game as global::Game).Empires, (global::Empire match) => match is MajorEmpire && departmentOfForeignAffairs.IsAtWarWith(match))); if (list.Count < 1) { return(true); } bool result = true; IWorldPositionningService service = Services.GetService <IGameService>().Game.Services.GetService <IWorldPositionningService>(); foreach (global::Empire empire in list) { List <IGarrison> list2 = new List <IGarrison>(); DepartmentOfDefense agency = empire.GetAgency <DepartmentOfDefense>(); DepartmentOfTheInterior agency2 = empire.GetAgency <DepartmentOfTheInterior>(); if (!NavalOnly) { list2.AddRange(agency.Armies.ToList <Army>().FindAll((Army match) => !match.IsSeafaring && !match.IsSettler).Cast <IGarrison>()); list2.AddRange(agency2.Cities.Cast <IGarrison>()); list2.AddRange(agency2.Camps.Cast <IGarrison>()); list2.AddRange(agency2.ConvertedVillages.Cast <IGarrison>()); } if (NavalOnly) { list2.AddRange(agency.Armies.ToList <Army>().FindAll((Army match) => match.IsNaval && !match.IsSettler).Cast <IGarrison>()); list2.AddRange(agency2.OccupiedFortresses.Cast <IGarrison>()); } foreach (IGarrison garrison in list2) { if (garrison.UnitsCount > 0 && garrison is IWorldPositionable) { float num = (float)service.GetDistance((garrison as IWorldPositionable).WorldPosition, pos); if (num <= (float)size) { incomingMP += garrison.GetPropertyValue(SimulationProperties.MilitaryPower); result = false; float num2 = 1f - num / (float)size; if (num2 > rangescore) { rangescore = num2; } } } } } return(result); }
protected BehaviorNodeReturnCode CollectOpportunityArmies(BaseNavyArmy army) { Army navy = army.Garrison as Army; NavyArmy navyArmy = army as NavyArmy; if (navyArmy == null || navy == null || !(navy.Empire is MajorEmpire)) { return(BehaviorNodeReturnCode.Failure); } float num = navy.GetPropertyValue(SimulationProperties.Movement); if (num < 0.01f) { num = 1f; } List <IGarrison> list = new List <IGarrison>(); DepartmentOfForeignAffairs agency = navy.Empire.GetAgency <DepartmentOfForeignAffairs>(); AILayer_Military.HasSaveAttackableTargetsNearby(navy, Mathf.CeilToInt(num), agency, out list, true); if (list.Count == 0) { return(BehaviorNodeReturnCode.Failure); } list.Sort((IGarrison left, IGarrison right) => this.worldPositionService.GetDistance((left as IWorldPositionable).WorldPosition, navy.WorldPosition).CompareTo(this.worldPositionService.GetDistance((right as IWorldPositionable).WorldPosition, navy.WorldPosition))); foreach (IGarrison garrison in list) { IGameEntityWithWorldPosition gameEntityWithWorldPosition = garrison as IGameEntityWithWorldPosition; IGarrisonWithPosition garrisonWithPosition = garrison as IGarrisonWithPosition; if (gameEntityWithWorldPosition != null && garrisonWithPosition != null) { WorldPosition validTileToAttack = base.GetValidTileToAttack(army, gameEntityWithWorldPosition); navyArmy.PathToSecondaryTarget = base.ComputePathToPosition(army, validTileToAttack, navyArmy.PathToSecondaryTarget); if (navyArmy.PathToSecondaryTarget != null) { if (navyArmy.PathToSecondaryTarget.ControlPoints != null && navyArmy.PathToSecondaryTarget.ControlPoints.Length != 0) { return(BehaviorNodeReturnCode.Failure); } Diagnostics.Log("ELCP {0}/{1} found opportunitytarget {2} with path {3}", new object[] { navy.Empire, navy.LocalizedName, garrison.LocalizedName, navyArmy.PathToSecondaryTarget }); navyArmy.OpportunityAttackableTarget = garrisonWithPosition; return(BehaviorNodeReturnCode.Success); } } } return(BehaviorNodeReturnCode.Failure); }
public static bool AreaIsSave(WorldPosition pos, int size, DepartmentOfForeignAffairs departmentOfForeignAffairs, bool NavalOnly = false, bool ignoreColdwar = false) { if (size < 1) { return(true); } List <global::Empire> list = new List <global::Empire>(); if (ignoreColdwar) { list.AddRange(Array.FindAll <global::Empire>((Services.GetService <IGameService>().Game as global::Game).Empires, (global::Empire match) => match is MajorEmpire && departmentOfForeignAffairs.IsAtWarWith(match))); } else { list.AddRange(Array.FindAll <global::Empire>((Services.GetService <IGameService>().Game as global::Game).Empires, (global::Empire match) => match is MajorEmpire && !departmentOfForeignAffairs.IsFriend(match))); } if (list.Count == 0) { return(true); } IWorldPositionningService service = Services.GetService <IGameService>().Game.Services.GetService <IWorldPositionningService>(); foreach (global::Empire empire in list) { List <IGarrison> list2 = new List <IGarrison>(); DepartmentOfDefense agency = empire.GetAgency <DepartmentOfDefense>(); DepartmentOfTheInterior agency2 = empire.GetAgency <DepartmentOfTheInterior>(); if (!NavalOnly) { list2.AddRange(agency.Armies.ToList <Army>().FindAll((Army match) => !match.IsSeafaring && !match.IsSettler).Cast <IGarrison>()); list2.AddRange(agency2.Cities.Cast <IGarrison>()); list2.AddRange(agency2.Camps.Cast <IGarrison>()); list2.AddRange(agency2.ConvertedVillages.Cast <IGarrison>()); } if (NavalOnly) { list2.AddRange(agency.Armies.ToList <Army>().FindAll((Army match) => match.IsNaval && !match.IsSettler).Cast <IGarrison>()); list2.AddRange(agency2.OccupiedFortresses.Cast <IGarrison>()); } foreach (IGarrison garrison in list2) { if (garrison.UnitsCount > 0 && garrison is IWorldPositionable && service.GetDistance((garrison as IWorldPositionable).WorldPosition, pos) <= size) { return(false); } } } return(true); }
public static bool IsKnownByLookingPlayer(Empire empire, Empire empireLooking) { if (empire.Index == empireLooking.Index) { return(true); } DepartmentOfForeignAffairs agency = empireLooking.GetAgency <DepartmentOfForeignAffairs>(); if (agency != null) { DiplomaticRelation diplomaticRelation = agency.GetDiplomaticRelation(empire); return(diplomaticRelation != null && diplomaticRelation.State != null && diplomaticRelation.State.Name != DiplomaticRelationState.Names.Unknown); } return(false); }
public static float GetCityDefenseLocalPriority(City city, float unitRatioBoost, int simulatedUnitsCount = -1) { if (city == null) { return(0f); } bool flag = false; DepartmentOfForeignAffairs agency = city.Empire.GetAgency <DepartmentOfForeignAffairs>(); if (!agency.IsInWarWithSomeone() && !AIScheduler.Services.GetService <IWorldAtlasAIHelper>().IsRegionPacified(city.Empire, city.Region)) { return(0f); } if (agency.IsInWarWithSomeone() && city.BesiegingEmpire == null) { flag = !AILayer_Military.AreaIsSave(city.WorldPosition, 10, agency, false); } float num = 0f; float num2; if (simulatedUnitsCount >= 0) { num2 = (float)simulatedUnitsCount / (float)city.MaximumUnitSlot; } else { num2 = (float)city.StandardUnits.Count / (float)city.MaximumUnitSlot; } num = AILayer.Boost(num, (1f - num2) * unitRatioBoost); if (city.BesiegingEmpire != null) { float propertyValue = city.GetPropertyValue(SimulationProperties.MaximumCityDefensePoint); float num3 = city.GetPropertyValue(SimulationProperties.CityDefensePoint) / propertyValue; num3 = 1f - num3; num = AILayer.Boost(num, num3 * AILayer_Military.cityDefenseUnderSiegeBoost); } else { float developmentRatioOfCity = AIScheduler.Services.GetService <IEntityInfoAIHelper>().GetDevelopmentRatioOfCity(city); num = AILayer.Boost(num, (1f - developmentRatioOfCity) * AILayer_Military.cityDevRatioBoost); if (flag) { num = AILayer.Boost(num, 0.5f); } } return(num); }
private void UpdateBorderStatusOfRegion(global::Empire empire, Region region, AIRegionData regionData) { DepartmentOfForeignAffairs agency = empire.GetAgency <DepartmentOfForeignAffairs>(); regionData.BorderWithEnnemy = 0; regionData.BorderWithAllied = 0; regionData.BorderWithMe = 0; regionData.BorderWithNeutral = 0; regionData.OverallBorderSize = 0; for (int i = 0; i < regionData.BorderByEmpireIndex.Length; i++) { regionData.BorderByEmpireIndex[i] = 0; } for (int j = 0; j < region.Borders.Length; j++) { int num = region.Borders[j].WorldPositions.Length; regionData.OverallBorderSize += num; Region region2 = this.worldPositionService.GetRegion(region.Borders[j].NeighbourRegionIndex); global::Empire owner = region2.Owner; if (owner != null && owner is MajorEmpire) { regionData.BorderByEmpireIndex[owner.Index] += num; if (owner == empire) { regionData.BorderWithMe += num; } else if (agency != null) { DiplomaticRelation diplomaticRelation = agency.GetDiplomaticRelation(owner); if (diplomaticRelation.State.Name == DiplomaticRelationState.Names.ColdWar || diplomaticRelation.State.Name == DiplomaticRelationState.Names.War) { regionData.BorderWithEnnemy += num; } else { regionData.BorderWithAllied += num; } } } else { regionData.BorderWithNeutral += num; } } }
protected override IEnumerator OnHide(bool instant) { this.scoreGraphsPanel.Hide(false); if (base.PlayerController != null && base.PlayerController.Empire != null) { DepartmentOfForeignAffairs departmentOfForeignAffairs = base.PlayerController.Empire.GetAgency <DepartmentOfForeignAffairs>(); if (departmentOfForeignAffairs != null) { departmentOfForeignAffairs.DiplomaticRelationStateChange -= this.DepartmentOfForeignAffairs_DiplomaticRelationStateChange; } } IEndTurnService endTurnService = Services.GetService <IEndTurnService>(); endTurnService.GameClientStateChange -= this.EndTurnService_GameClientStateChange; yield return(base.OnHide(instant)); yield break; }
private void PostOrderGetAIDiplomaticTermsEvaluation() { MajorEmpire majorEmpire = this.selectedEmpire as MajorEmpire; MajorEmpire majorEmpire2 = base.Empire as MajorEmpire; if (majorEmpire == null || majorEmpire2 == null) { return; } List <DiplomaticTerm> list = new List <DiplomaticTerm>(); DepartmentOfForeignAffairs.GetAllAvailableDiplomaticTerm(this.DiplomaticContract, base.Empire, this.SelectedEmpire, ref list); DepartmentOfForeignAffairs.GetAllAvailableDiplomaticTerm(this.DiplomaticContract, this.SelectedEmpire, base.Empire, ref list); OrderGetAIDiplomaticTermEvaluation order = new OrderGetAIDiplomaticTermEvaluation(majorEmpire, majorEmpire2, list.ToArray()); Ticket ticket; base.PlayerController.PostOrder(order, out ticket, new EventHandler <TicketRaisedEventArgs>(this.OnPostOrderGetAIDiplomaticTermsEvaluationResponse)); }
protected bool MayEndureRetaliationAnotherTurn(BaseNavyArmy army) { Army army2 = army.Garrison as Army; if (army2 != null && army2.IsPrivateers) { return(true); } District district = this.worldPositionService.GetDistrict(army.Garrison.WorldPosition); if (district != null) { if (district.City.Empire == army.Garrison.Empire) { return(true); } float propertyValue = district.City.GetPropertyValue(SimulationProperties.DefensivePower); float propertyValue2 = district.City.GetPropertyValue(SimulationProperties.CoastalDefensivePower); if (propertyValue + propertyValue2 <= 0f) { return(true); } DepartmentOfForeignAffairs agency = district.City.Empire.GetAgency <DepartmentOfForeignAffairs>(); if (agency != null) { DiplomaticRelation diplomaticRelation = agency.GetDiplomaticRelation(army.Garrison.Empire); if (diplomaticRelation != null && diplomaticRelation.HasActiveAbility(DiplomaticAbilityDefinition.ImmuneToDefensiveImprovements)) { return(true); } } float num = (propertyValue + propertyValue2) / (float)army.Garrison.UnitsCount; foreach (Unit unit in army.Garrison.Units) { float propertyValue3 = unit.GetPropertyValue(SimulationProperties.Health); if (propertyValue3 - num < num * 2f) { return(false); } } return(true); } return(true); }
private bool OtherEmpireCreepingNodeAtPosition(global::Empire empire, WorldPosition worldPosition) { if (!worldPosition.IsValid) { return(false); } PointOfInterest pointOfInterest = base.WorldPositionningService.GetPointOfInterest(worldPosition); if (pointOfInterest == null || pointOfInterest.CreepingNodeGUID == GameEntityGUID.Zero) { return(false); } CreepingNode creepingNode = null; base.GameEntityRepositoryService.TryGetValue <CreepingNode>(pointOfInterest.CreepingNodeGUID, out creepingNode); if (creepingNode != null && empire != null && creepingNode.Empire != null && pointOfInterest.Empire.Index != empire.Index && creepingNode.DismantlingArmy == null) { if (!ELCPUtilities.UseELCPPeacefulCreepingNodes) { return(true); } if (pointOfInterest.CreepingNodeGUID != GameEntityGUID.Zero && pointOfInterest.Empire != empire) { if (pointOfInterest.Empire == null) { return(true); } if (!(pointOfInterest.Empire is MajorEmpire)) { return(true); } DepartmentOfForeignAffairs agency = empire.GetAgency <DepartmentOfForeignAffairs>(); if (agency == null) { return(true); } if (!agency.IsFriend(pointOfInterest.Empire)) { return(true); } } } return(false); }
public static Army GetMaxHostileArmy(global::Empire empire, int regionIndex) { Services.GetService <IGameService>().Game.Services.GetService <IQuestManagementService>(); Army army = null; DepartmentOfForeignAffairs agency = empire.GetAgency <DepartmentOfForeignAffairs>(); if (agency == null) { return(null); } foreach (Army army2 in Intelligence.GetVisibleArmiesInRegion(regionIndex, empire)) { if (army2.Empire != empire && !army2.IsSeafaring && agency.CanAttack(army2) && (army == null || army2.GetPropertyValue(SimulationProperties.MilitaryPower) > army.GetPropertyValue(SimulationProperties.MilitaryPower))) { army = army2; } } return(army); }
protected bool HasOtherEmpireClosedTheirBorders() { IGameService service = Services.GetService <IGameService>(); Diagnostics.Assert(service != null); Diagnostics.Assert(service.Game != null); Diagnostics.Assert(service.Game is global::Game); global::Game game = service.Game as global::Game; Diagnostics.Assert(game.Empires.Length > this.DiplomaticRelation.OtherEmpireIndex); global::Empire empire = (service.Game as global::Game).Empires[this.DiplomaticRelation.OtherEmpireIndex]; DepartmentOfForeignAffairs agency = empire.GetAgency <DepartmentOfForeignAffairs>(); Diagnostics.Assert(agency != null); DiplomaticRelation diplomaticRelation = agency.GetDiplomaticRelation(this.Empire); Diagnostics.Assert(diplomaticRelation != null); return(diplomaticRelation.HasActiveAbility(DiplomaticAbilityDefinition.CloseBorders)); }
public static bool RegionContainsHostileArmies(global::Empire empire, int regionIndex) { if (empire == null) { return(false); } DepartmentOfForeignAffairs agency = empire.GetAgency <DepartmentOfForeignAffairs>(); if (agency == null) { return(false); } bool flag = agency.IsInWarWithSomeone(); IGameService service = Services.GetService <IGameService>(); service.Game.Services.GetService <IQuestManagementService>(); Diagnostics.Assert(service != null); Region region = service.Game.Services.GetService <IWorldPositionningService>().GetRegion(regionIndex); if (flag && region != null && (region.City == null || region.City.Empire != empire)) { if (region.City == null) { foreach (Army army in Intelligence.GetArmiesInRegion(regionIndex)) { if ((army.Empire is MinorEmpire || army.Empire is LesserEmpire) && agency.CanAttack(army)) { return(true); } } } return(false); } foreach (Army army2 in Intelligence.GetVisibleArmiesInRegion(regionIndex, empire)) { if (army2.Empire != empire && agency.CanAttack(army2)) { return(true); } } return(false); }
private List <IWorldPositionable> Execute_GetVillages(AIBehaviorTree aiBehaviorTree, Army army, IGameService gameService, List <IWorldPositionable> unfilteredTargetList) { List <IWorldPositionable> list = new List <IWorldPositionable>(); for (int i = 0; i < unfilteredTargetList.Count; i++) { PointOfInterest pointOfInterest = unfilteredTargetList[i] as PointOfInterest; if (pointOfInterest != null && !(pointOfInterest.Type != "Village") && pointOfInterest.Region != null && pointOfInterest.Region.MinorEmpire != null) { BarbarianCouncil agency = pointOfInterest.Region.MinorEmpire.GetAgency <BarbarianCouncil>(); if (agency != null) { Village villageAt = agency.GetVillageAt(pointOfInterest.WorldPosition); if (villageAt != null && !villageAt.HasBeenPacified && this.TypeOfDiplomaticRelation != "VillageConvert" && pointOfInterest.PointOfInterestImprovement != null && !villageAt.HasBeenInfected) { list.Add(villageAt); } else if (this.TypeOfDiplomaticRelation == "VillageConvert" && army.Empire is MajorEmpire && army.Empire.SimulationObject.Tags.Contains(AILayer_Village.TagConversionTrait) && villageAt.HasBeenPacified && DepartmentOfTheInterior.IsArmyAbleToConvert(army, true) && !villageAt.HasBeenConverted && !villageAt.HasBeenInfected) { DepartmentOfForeignAffairs agency2 = aiBehaviorTree.AICommander.Empire.GetAgency <DepartmentOfForeignAffairs>(); City city = villageAt.Region.City; if (city != null && city.Empire != aiBehaviorTree.AICommander.Empire) { DiplomaticRelation diplomaticRelation = agency2.GetDiplomaticRelation(city.Empire); if (diplomaticRelation == null || diplomaticRelation.State.Name != DiplomaticRelationState.Names.War || (diplomaticRelation.State.Name == DiplomaticRelationState.Names.War && pointOfInterest.PointOfInterestImprovement == null)) { goto IL_1FB; } } float num; army.Empire.GetAgency <DepartmentOfTheTreasury>().TryGetResourceStockValue(army.Empire.SimulationObject, DepartmentOfTheTreasury.Resources.EmpirePoint, out num, false); if (AILayer_Village.GetVillageConversionCost(army.Empire as MajorEmpire, villageAt) * 2f < num) { list.Add(villageAt); } } } } IL_1FB :; } return(list); }
public override void Execute(Army army, global::PlayerController playerController, out Ticket ticket, EventHandler <TicketRaisedEventArgs> ticketRaisedEventHandler, params object[] parameters) { ticket = null; IGameEntity gameEntity = null; ArmyAction.FailureFlags.Clear(); for (int i = 0; i < parameters.Length; i++) { if (parameters[i] is IGameEntity) { gameEntity = (parameters[i] as IGameEntity); break; } if (parameters[i] is List <IGameEntity> ) { List <IGameEntity> list = parameters[i] as List <IGameEntity>; bool flag = false; for (int j = 0; j < list.Count; j++) { if (this.CanAttackGameEntity(army, list[j], ref flag, ref ArmyAction.FailureFlags)) { gameEntity = list[j]; break; } } break; } } if (gameEntity != null) { DepartmentOfForeignAffairs agency = army.Empire.GetAgency <DepartmentOfForeignAffairs>(); Diagnostics.Assert(agency != null); if (agency.CanAttack(gameEntity) || army.IsPrivateers) { OrderAttack orderAttack = new OrderAttack(army.Empire.Index, army.GUID, gameEntity.GUID); orderAttack.NumberOfActionPointsToSpend = base.GetCostInActionPoints(); Diagnostics.Assert(playerController != null); playerController.PostOrder(orderAttack, out ticket, ticketRaisedEventHandler); } } }
private static float ComputeMyNavyImportance(global::Empire empire) { DepartmentOfForeignAffairs agency = empire.GetAgency <DepartmentOfForeignAffairs>(); IGameService service = Services.GetService <IGameService>(); Diagnostics.Assert(service != null); global::Game game = service.Game as global::Game; Diagnostics.Assert(game != null); IAIEmpireDataAIHelper service2 = AIScheduler.Services.GetService <IAIEmpireDataAIHelper>(); float num = 0f; float num2 = 0f; for (int i = 0; i < game.Empires.Length; i++) { AIEmpireData aiempireData; if (service2.TryGet(i, out aiempireData)) { float navalMilitaryPower = aiempireData.NavalMilitaryPower; if (game.Empires[i] == empire) { num += navalMilitaryPower; } else if (agency.IsFriend(game.Empires[i])) { num += navalMilitaryPower; } else { num2 += navalMilitaryPower; } } } float result = 2f; if (num2 != 0f) { result = num / num2; } return(result); }
public override void Execute(Army army, global::PlayerController playerController, out Ticket ticket, EventHandler <TicketRaisedEventArgs> ticketRaisedEventHandler, params object[] parameters) { ticket = null; PointOfInterest pointOfInterest = null; if (parameters != null && parameters.Length != 0 && parameters[0] is PointOfInterest) { pointOfInterest = (parameters[0] as PointOfInterest); } else if (parameters != null && parameters.Length != 0 && parameters[0] is Village) { pointOfInterest = (parameters[0] as Village).PointOfInterest; } DepartmentOfForeignAffairs agency = army.Empire.GetAgency <DepartmentOfForeignAffairs>(); DiplomaticRelation diplomaticRelation = null; if (pointOfInterest != null && pointOfInterest.Empire != null) { diplomaticRelation = agency.GetDiplomaticRelation(pointOfInterest.Empire); } ArmyAction.FailureFlags.Clear(); if (diplomaticRelation == null || diplomaticRelation.State == null || diplomaticRelation.State.Name != DiplomaticRelationState.Names.Alliance) { OrderConvertVillage orderConvertVillage = new OrderConvertVillage(army.Empire.Index, army.GUID, pointOfInterest.WorldPosition); orderConvertVillage.NumberOfActionPointsToSpend = base.GetCostInActionPoints(); Diagnostics.Assert(playerController != null); playerController.PostOrder(orderConvertVillage, out ticket, ticketRaisedEventHandler); } else if (pointOfInterest != null && pointOfInterest.Empire != null && pointOfInterest.Empire is MajorEmpire) { IGuiService service = Services.GetService <IGuiService>(); service.GetGuiPanel <WarDeclarationModalPanel>().Show(new object[] { pointOfInterest.Empire, "Convert" }); } }
protected void FillVisibleArmiesAround(IGarrisonWithPosition garrison, List <Army> targetArmies) { DepartmentOfForeignAffairs agency = garrison.Empire.GetAgency <DepartmentOfForeignAffairs>(); IGameService service = Services.GetService <IGameService>(); Diagnostics.Assert(service != null); global::Game game = service.Game as global::Game; int num = Mathf.RoundToInt(garrison.GetPropertyValue(SimulationProperties.VisionRange)); for (int i = 0; i < game.Empires.Length; i++) { global::Empire empire = game.Empires[i]; if (garrison.Empire != empire) { if (!(empire is MajorEmpire) || !agency.IsFriend(empire)) { DepartmentOfDefense agency2 = empire.GetAgency <DepartmentOfDefense>(); if (agency2 != null) { for (int j = 0; j < agency2.Armies.Count; j++) { Army army = agency2.Armies[j]; if (army.UnitsCount != 0) { if (!army.IsCamouflaged || this.visibilityService.IsWorldPositionDetectedFor(army.WorldPosition, garrison.Empire)) { if (this.worldPositionService.GetDistance(army.WorldPosition, garrison.WorldPosition) <= num) { targetArmies.Add(army); } } } } } } } } }
public List <DiplomaticRelationScore.ModifiersData> GetPriceModifiers() { List <DiplomaticRelationScore.ModifiersData> list = new List <DiplomaticRelationScore.ModifiersData>(); global::Empire payingEmpire = this.GetPayingEmpire(); Diagnostics.Assert(payingEmpire != null); global::Empire empire = (payingEmpire != this.Term.EmpireWhichProvides) ? this.Term.EmpireWhichProvides : this.Term.EmpireWhichReceives; Diagnostics.Assert(empire != null); DepartmentOfForeignAffairs agency = payingEmpire.GetAgency <DepartmentOfForeignAffairs>(); Diagnostics.Assert(agency != null); DiplomaticRelation diplomaticRelation = agency.GetDiplomaticRelation(empire); foreach (DiplomaticRelationScore.ModifiersData modifiersData in diplomaticRelation.DiplomaticRelationScore.MofifiersDatas) { if (this.TermGuiElement != null && this.TermGuiElement.PriceModifierCategories.Contains(modifiersData.Category) && Mathf.Abs(modifiersData.TotalValue) > 0.1f) { list.Add(modifiersData); } } return(list); }