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); }
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 bool HasRetaliationFor(WorldPosition position, global::Empire empire = null) { GridMap <byte> gridMap = this.world.Atlas.GetMap(WorldAtlas.Maps.DefensiveTower) as GridMap <byte>; Diagnostics.Assert(gridMap != null); byte b = gridMap.GetValue(position); if (empire != null) { b &= (byte)(~(byte)empire.Bits); } if (b != 0) { if (empire == null) { return(true); } DepartmentOfForeignAffairs agency = empire.GetAgency <DepartmentOfForeignAffairs>(); if (agency == null) { return(true); } for (int i = 0; i < base.Game.Empires.Length; i++) { global::Empire empire2 = base.Game.Empires[i]; if (((int)b & empire2.Bits) != 0) { DiplomaticRelation diplomaticRelation = agency.GetDiplomaticRelation(empire2); if (diplomaticRelation == null || !diplomaticRelation.HasActiveAbility(DiplomaticAbilityDefinition.ImmuneToDefensiveImprovements)) { return(true); } } } } return(false); }
public static List <GuiElement> GetFilteredDiplomaticAbilityGuiElements(global::Empire thisEmpire, global::Empire otherEmpire) { IGuiPanelHelper guiPanelHelper = Services.GetService <global::IGuiService>().GuiPanelHelper; Diagnostics.Assert(guiPanelHelper != null, "Unable to access GuiPanelHelper"); DepartmentOfForeignAffairs agency = thisEmpire.GetAgency <DepartmentOfForeignAffairs>(); DiplomaticRelation diplomaticRelation = agency.GetDiplomaticRelation(otherEmpire); List <GuiElement> list = new List <GuiElement>(); bool flag = false; bool flag2 = false; ReadOnlyCollection <DiplomaticAbility> diplomaticAbilities = diplomaticRelation.DiplomaticAbilities; GuiElement item; for (int i = 0; i < diplomaticAbilities.Count; i++) { StaticString name = diplomaticAbilities[i].Name; if (name == DiplomaticAbilityDefinition.CloseBorders && !thisEmpire.SimulationObject.Tags.Contains("SeasonEffectDiplomacy1")) { flag = true; } else if (diplomaticAbilities[i].IsActive) { IDownloadableContentService service = Services.GetService <IDownloadableContentService>(); if (!(name == DiplomaticAbilityDefinition.ImmuneToDefensiveImprovements) || service.IsShared(DownloadableContent13.ReadOnlyName)) { if (guiPanelHelper.TryGetGuiElement("DiplomaticAbility" + name, out item)) { list.Add(item); } } } } DepartmentOfForeignAffairs agency2 = otherEmpire.GetAgency <DepartmentOfForeignAffairs>(); DiplomaticRelation diplomaticRelation2 = agency2.GetDiplomaticRelation(thisEmpire); if (diplomaticRelation2.HasActiveAbility(DiplomaticAbilityDefinition.CloseBorders) && !otherEmpire.SimulationObject.Tags.Contains("SeasonEffectDiplomacy1")) { flag2 = true; } if (flag && flag2) { if (guiPanelHelper.TryGetGuiElement("DiplomaticAbilityMutualCloseBorders", out item)) { list.Add(item); } } else if (flag) { if (guiPanelHelper.TryGetGuiElement("DiplomaticAbilityPersonaNonGrata", out item)) { list.Add(item); } } else if (flag2 && guiPanelHelper.TryGetGuiElement("DiplomaticAbilityLockedOut", out item)) { list.Add(item); } if (diplomaticRelation2.HasActiveAbility(DiplomaticAbilityDefinition.MarketBan) && guiPanelHelper.TryGetGuiElement("DiplomaticAbilityMarketBanner", out item)) { list.Add(item); } return(list); }
private void RefreshVisibility() { Diagnostics.Assert(this.majorEmpires != null); for (int i = 0; i < this.majorEmpires.Length; i++) { Diagnostics.Assert(this.empireExplorationBits != null && this.empireVibilityBits != null && this.lastEmpireExplorationBits != null); Diagnostics.Assert(this.empireDetectionBits != null); this.lastEmpireExplorationBits[i] = this.empireExplorationBits[i]; this.empireExplorationBits[i] = this.majorEmpires[i].Bits; this.empireVibilityBits[i] = this.majorEmpires[i].Bits; this.empireDetectionBits[i] = this.majorEmpires[i].Bits; DepartmentOfForeignAffairs agency = this.majorEmpires[i].GetAgency <DepartmentOfForeignAffairs>(); for (int j = 0; j < this.majorEmpires.Length; j++) { if (j != i) { bool flag = false; bool flag2 = false; bool flag3 = false; DepartmentOfScience agency2 = this.majorEmpires[j].GetAgency <DepartmentOfScience>(); Diagnostics.Assert(agency2 != null); if (agency2.GetTechnologyState(this.technologyDefinitionDrakkenEndQuestReward) == DepartmentOfScience.ConstructibleElement.State.Researched) { flag2 = true; flag3 = true; } else if (agency2.GetTechnologyState(this.technologyDefinitionDrakkenVisionDuringFirstTurn) == DepartmentOfScience.ConstructibleElement.State.Researched && base.Game.Turn == 0) { flag2 = true; flag = true; flag3 = true; } DiplomaticRelation diplomaticRelation = agency.GetDiplomaticRelation(this.majorEmpires[j]); if (diplomaticRelation != null) { flag |= (diplomaticRelation.HasActiveAbility(DiplomaticAbilityDefinition.MapExchange) || (ELCPUtilities.SpectatorMode && this.majorEmpires[j].ELCPIsEliminated)); flag2 |= diplomaticRelation.HasActiveAbility(DiplomaticAbilityDefinition.VisionExchange); } if (this.EnableDetection) { StaticString tag = this.stealVisionFromEmpireTags[i]; if (this.majorEmpires[j].SimulationObject.Tags.Contains(tag)) { flag2 = true; flag3 = true; } } if (flag2) { this.empireVibilityBits[i] |= this.majorEmpires[j].Bits; } if (flag) { this.empireExplorationBits[i] |= this.majorEmpires[j].Bits; } if (flag3) { this.empireDetectionBits[i] |= this.majorEmpires[j].Bits; } if (flag2 || flag || flag3) { if ((this.NeedRefreshBits & this.majorEmpires[j].Bits) != 0) { this.NeedRefreshBits |= 1 << i; } if ((this.NeedRefreshBits & this.majorEmpires[i].Bits) != 0) { this.NeedRefreshBits |= 1 << j; } } } } } for (int k = 0; k < this.majorEmpires.Length; k++) { MajorEmpire majorEmpire = this.majorEmpires[k]; Diagnostics.Assert(this.empireExplorationBits != null && this.lastEmpireExplorationBits != null); if (this.lastEmpireExplorationBits[k] != this.empireExplorationBits[k]) { Diagnostics.Assert(this.explorationMap != null && this.explorationMap.Data != null); for (int l = 0; l < this.explorationMap.Data.Length; l++) { if ((this.explorationMap.Data[l] & (short)majorEmpire.Bits) != 0) { short[] data = this.explorationMap.Data; int num = l; int num2 = num; data[num2] |= (short)this.empireExplorationBits[k]; } } } } short num3 = Convert.ToInt16(~this.NeedRefreshBits); for (int m = 0; m < this.publicVisibilityMap.Data.Length; m++) { short[] data2 = this.publicVisibilityMap.Data; int num4 = m; int num5 = num4; data2[num5] &= num3; short[] data3 = this.privateVisibilityMap.Data; int num6 = m; int num7 = num6; data3[num7] &= num3; if (this.EnableDetection) { short[] data4 = this.publicDetectionMap.Data; int num8 = m; int num9 = num8; data4[num9] &= num3; short[] data5 = this.privateDetectionMap.Data; int num10 = m; int num11 = num10; data5[num11] &= num3; } } for (int n = 0; n < this.gameEntities.Count; n++) { this.RefreshLineOfSight(this.gameEntities[n], this.NeedRefreshBits); } for (int num12 = 0; num12 < this.visibilityProviders.Count; num12++) { this.RefreshLineOfSight(this.visibilityProviders[num12], this.NeedRefreshBits); } this.NeedRefreshBits = 0; }
private bool UpdateSafetyData(global::Empire empire, AISafetyData safetyData) { DepartmentOfTheInterior agency = empire.GetAgency <DepartmentOfTheInterior>(); DepartmentOfForeignAffairs agency2 = empire.GetAgency <DepartmentOfForeignAffairs>(); DepartmentOfScience agency3 = empire.GetAgency <DepartmentOfScience>(); if (agency.Cities.Count <= 0) { return(false); } bool result = false; for (int i = 0; i < this.world.Regions.Length; i++) { Region region = this.world.Regions[i]; if (region.City != null && region.City.Empire != null) { global::Empire empire2 = base.Game.Empires[region.City.Empire.Index]; DiplomaticRelation diplomaticRelation = agency2.GetDiplomaticRelation(empire2); if (empire2 != empire && (diplomaticRelation.State.Name == DiplomaticRelationState.Names.Unknown || diplomaticRelation.HasActiveAbility(DiplomaticAbilityDefinition.ColdWarAttackArmies) || diplomaticRelation.HasActiveAbility(DiplomaticAbilityDefinition.AttackArmies))) { if (safetyData.SafeRegionIndexes.Contains(i)) { safetyData.SafeRegionIndexes.Remove(i); result = true; } if (!safetyData.UnsafeRegionIndexes.Contains(i)) { safetyData.UnsafeRegionIndexes.Add(i); result = true; } } else if (empire2 == empire) { if (safetyData.UnsafeRegionIndexes.Contains(i)) { safetyData.UnsafeRegionIndexes.Remove(i); result = true; } if (!safetyData.SafeRegionIndexes.Contains(i)) { safetyData.SafeRegionIndexes.Add(i); result = true; } } } else { if (safetyData.SafeRegionIndexes.Contains(i)) { safetyData.SafeRegionIndexes.Remove(i); result = true; } if (safetyData.UnsafeRegionIndexes.Contains(i)) { safetyData.UnsafeRegionIndexes.Remove(i); result = true; } } } if (!safetyData.CanGoOnWater && agency3.HaveResearchedShipTechnology()) { safetyData.CanGoOnWater = true; result = true; } return(result); }