private void SelectCreepingNodes() { global::Empire empire = this.PlayerControllerRepositoryService.ActivePlayerController.Empire as global::Empire; if (this.City.Empire.Index == empire.Index && empire.SimulationObject.Tags.Contains("FactionTraitMimics1")) { DepartmentOfCreepingNodes agency = empire.GetAgency <DepartmentOfCreepingNodes>(); if (agency.Nodes.Count > 0) { ReadOnlyCollection <IWorldEntityWithCulling> readOnlyCollection; if (this.worldEntityCullingService.TryGetVisibleEntities <WorldCreepingNode>(out readOnlyCollection)) { for (int i = 0; i < readOnlyCollection.Count; i++) { WorldCreepingNode worldCreepingNode = readOnlyCollection[i] as WorldCreepingNode; if (worldCreepingNode != null && worldCreepingNode.CreepingNode != null && worldCreepingNode.CreepingNode.Empire.Index == empire.Index) { this.ELCPDrawCreepingNode(worldCreepingNode.CreepingNode); } } return; } for (int j = 0; j < agency.Nodes.Count; j++) { CreepingNode creepingNode = agency.Nodes[j]; this.ELCPDrawCreepingNode(creepingNode); } } } }
private float ComputeDestroyInterest(CreepingNode target, AIEntity_Empire entityEmpire, Army army) { float normalizedScore = 0.1f; AILayer_Diplomacy layer = entityEmpire.GetLayer <AILayer_Diplomacy>(); if (layer != null) { float num = layer.GetWantWarScore(target.Empire); float num2 = layer.GetAllyScore(target.Empire); if (num2 > 0.5f || num < 0.25f || layer.GetPeaceWish(target.Empire.Index)) { return(-1f); } num = (num - 0.25f) / 0.75f; num2 = (num2 - 0.5f) / 0.5f; float boostFactor = 0.2f * (num - num2); normalizedScore = AILayer.Boost(normalizedScore, boostFactor); } float propertyValue = army.Empire.GetPropertyValue(SimulationProperties.MilitaryPower); float num3 = target.Empire.GetPropertyValue(SimulationProperties.MilitaryPower); if (num3 == 0f) { num3 = 1f; } float num4 = propertyValue / num3; if (num4 < 1f) { return(-1f); } float boostFactor2 = Mathf.Clamp01(num4 / 2f) * 0.2f; return(AILayer.Boost(normalizedScore, boostFactor2)); }
private void ListNearbyCreepingNodesFiltered(Army army) { if (army == null) { throw new ArgumentNullException("army"); } this.creepingNodes.Clear(); IGameService service = Services.GetService <IGameService>(); Diagnostics.Assert(service != null); global::Game game = service.Game as global::Game; Diagnostics.Assert(game != null); IWorldPositionningService service2 = service.Game.Services.GetService <IWorldPositionningService>(); Diagnostics.Assert(service2 != null); IGameEntityRepositoryService service3 = service.Game.Services.GetService <IGameEntityRepositoryService>(); Diagnostics.Assert(service3 != null); List <StaticString> list = new List <StaticString>(); List <WorldPosition> neighbours = army.WorldPosition.GetNeighbours(game.World.WorldParameters); for (int i = 0; i < neighbours.Count; i++) { PointOfInterest pointOfInterest = service2.GetPointOfInterest(neighbours[i]); if (pointOfInterest != null && pointOfInterest.CreepingNodeGUID != GameEntityGUID.Zero) { CreepingNode creepingNode = null; if (service3.TryGetValue <CreepingNode>(pointOfInterest.CreepingNodeGUID, out creepingNode) && this.CanToggleOverCreepingNode(army, creepingNode, ref list) && !this.creepingNodes.Contains(creepingNode)) { this.creepingNodes.Add(creepingNode); } } } }
public void RefreshContent(CreepingNode creepingNode, GameObject client) { if (creepingNode != null) { this.selectionClient = client; this.CreepingNodeWorldPosition = creepingNode.WorldPosition; this.DestroyedArmyIcon.Visible = false; this.title.AgeTransform.PixelMarginLeft = this.DestroyedArmyIcon.PixelMarginRight; string text = creepingNode.PointOfInterest.CreepingNodeImprovement.Name; GuiElement guiElement; if (Services.GetService <global::IGuiService>().GuiPanelHelper.TryGetGuiElement(creepingNode.PointOfInterest.CreepingNodeImprovement.Name, out guiElement)) { text = guiElement.Title; if (guiElement is ExtendedGuiElement) { ExtendedGuiElement extendedGuiElement = guiElement as ExtendedGuiElement; if (extendedGuiElement.TooltipElement != null) { text = extendedGuiElement.Title; } } } this.title.Text = text; this.ShowLocationAttackerButton.Visible = false; this.ShowLocationAttackerButton.Enable = false; } }
public override void Deactivate() { base.Deactivate(); WorldCircle worldCircle = new WorldCircle(base.WorldPosition, base.WorldEffectDefinition.Range); List <short> list = new List <short>(); WorldPosition[] worldPositions = worldCircle.GetWorldPositions(base.WorldEffectManager.WorldPositionningService.World.WorldParameters); for (int i = 0; i < worldPositions.Length; i++) { short regionIndex = base.WorldEffectManager.WorldPositionningService.GetRegionIndex(worldPositions[i]); if (!list.Contains(regionIndex)) { Region region = base.WorldEffectManager.WorldPositionningService.GetRegion(worldPositions[i]); if (region.City != null) { for (int j = 0; j < region.City.Districts.Count; j++) { District district = region.City.Districts[j]; if (this.descriptorsAppliedOnDistrict.ContainsKey(district.WorldPosition)) { List <string> list2 = this.descriptorsAppliedOnDistrict[district.WorldPosition]; for (int k = 0; k < list2.Count; k++) { StaticString descriptorNames = list2[k]; district.RemoveDescriptorByName(descriptorNames); } } district.Refresh(false); } } list.Add(regionIndex); } } worldPositions = new WorldCircle(base.WorldPosition, base.WorldEffectDefinition.Range + 1).GetWorldPositions(base.WorldEffectManager.WorldPositionningService.World.WorldParameters); for (int l = 0; l < worldPositions.Length; l++) { PointOfInterest pointOfInterest = base.WorldEffectManager.WorldPositionningService.GetPointOfInterest(worldPositions[l]); if (pointOfInterest != null) { if (pointOfInterest.CreepingNodeGUID != GameEntityGUID.Zero) { IGameEntity gameEntity = null; if (base.WorldEffectManager.GameEntityRepositoryService.TryGetValue(pointOfInterest.CreepingNodeGUID, out gameEntity)) { CreepingNode creepingNode = gameEntity as CreepingNode; if (!creepingNode.IsUnderConstruction) { creepingNode.ReApplyFIMSEOnCreepingNode(); } } } else if (pointOfInterest.SimulationObject.Tags.Contains(Village.ConvertedVillage)) { DepartmentOfTheInterior.ReApplyFIMSEOnConvertedVillage(pointOfInterest.Empire, pointOfInterest); } } } }
private bool IsMessageValid(CreepingNodeBuyoutMessage message) { IGameEntity gameEntity = null; if (!this.gameEntityRepositoryService.TryGetValue(message.NodeGUID, out gameEntity)) { return(false); } CreepingNode creepingNode = gameEntity as CreepingNode; return(creepingNode != null && creepingNode.IsUnderConstruction); }
private List <District> GetAffectedDistrict() { List <District> list = new List <District>(); WorldCircle worldCircle = new WorldCircle(base.WorldPosition, base.WorldEffectDefinition.Range); List <short> list2 = new List <short>(); WorldPosition[] worldPositions = worldCircle.GetWorldPositions(base.WorldEffectManager.WorldPositionningService.World.WorldParameters); for (int i = 0; i < worldPositions.Length; i++) { short regionIndex = base.WorldEffectManager.WorldPositionningService.GetRegionIndex(worldPositions[i]); if (!list2.Contains(regionIndex)) { Region region = base.WorldEffectManager.WorldPositionningService.GetRegion(worldPositions[i]); if (region.City != null) { foreach (District district in region.City.Districts) { if (base.HasAnEffectOnPosition(district.WorldPosition)) { list.Add(district); } } } list2.Add(regionIndex); } } worldPositions = new WorldCircle(base.WorldPosition, base.WorldEffectDefinition.Range + 1).GetWorldPositions(base.WorldEffectManager.WorldPositionningService.World.WorldParameters); for (int j = 0; j < worldPositions.Length; j++) { PointOfInterest pointOfInterest = base.WorldEffectManager.WorldPositionningService.GetPointOfInterest(worldPositions[j]); if (pointOfInterest != null) { if (pointOfInterest.CreepingNodeGUID != GameEntityGUID.Zero) { IGameEntity gameEntity = null; if (base.WorldEffectManager.GameEntityRepositoryService.TryGetValue(pointOfInterest.CreepingNodeGUID, out gameEntity)) { CreepingNode creepingNode = gameEntity as CreepingNode; if (!creepingNode.IsUnderConstruction) { creepingNode.ReApplyFIMSEOnCreepingNode(); } } } else if (pointOfInterest.SimulationObject.Tags.Contains(Village.ConvertedVillage)) { DepartmentOfTheInterior.ReApplyFIMSEOnConvertedVillage(pointOfInterest.Empire, pointOfInterest); } } } return(list); }
private void CreateCreepingNodeHexFidsIFN(CreepingNode node, WorldArea worldArea) { if (this.worldEntityHelperContent != null) { return; } WorldView worldView = base.ViewService.CurrentView as WorldView; DefaultWorldViewTechnique defaultWorldViewTechnique = worldView.CurrentWorldViewTechnique as DefaultWorldViewTechnique; if (defaultWorldViewTechnique == null) { return; } GameObject gameObject = null; if (!base.WorldEntityFactoryService.TryGetValue(node.PointOfInterest.GUID, out gameObject)) { return; } WorldPatch worldPatch = null; Transform parent = gameObject.transform.parent; while (worldPatch == null && parent != null) { worldPatch = parent.GetComponent <WorldPatch>(); parent = parent.parent; } if (worldPatch == null) { return; } AbstractTerrainPatchRenderer abstractTerrainPatchRenderer = null; bool flag = worldPatch.TryGetPatchRenderer <AbstractTerrainPatchRenderer>(out abstractTerrainPatchRenderer); if (!flag || abstractTerrainPatchRenderer == null) { return; } this.worldEntityHelperContent = new WorldEntityHelper.WorldEntityHelperContent(); InstanciedMeshBlock orCreateInstanciedMeshBlock = this.worldEntityHelperContent.GetOrCreateInstanciedMeshBlock(defaultWorldViewTechnique.HxTechniqueGraphicData.InstanciedMeshHolders, PrimitiveLayerMask.Fids, InstanciedMeshHelpers.PositionForwardScaleZPixelsPerInstance); InstanciedMeshBlock orCreateInstanciedMeshBlock2 = this.worldEntityHelperContent.GetOrCreateInstanciedMeshBlock(defaultWorldViewTechnique.HxTechniqueGraphicData.InstanciedMeshHolders, PrimitiveLayerMask.Fids, InstanciedMeshHelpers.PositionTexCoordWorldScaleTextureScalePixelsPerInstance); for (int i = 0; i < worldArea.WorldPositions.Count; i++) { Vector3 absoluteWorldPosition2D = abstractTerrainPatchRenderer.GlobalPositionningService.GetAbsoluteWorldPosition2D(worldArea.WorldPositions[i]); absoluteWorldPosition2D.x -= abstractTerrainPatchRenderer.OffsetX; absoluteWorldPosition2D.z -= abstractTerrainPatchRenderer.OffsetZ; InstancingHelper.SpawnOnePrefab(abstractTerrainPatchRenderer, defaultWorldViewTechnique, defaultWorldViewTechnique.HxTechniqueGraphicData.AllResourceFidsGraphicDatas.CityExploitationHexaData, absoluteWorldPosition2D, (int)worldArea.WorldPositions[i].Row, (int)worldArea.WorldPositions[i].Column, null, PrimitiveLayerMask.Fids, ref orCreateInstanciedMeshBlock, PrimitiveLayerMask.Fids, ref orCreateInstanciedMeshBlock2, false, 0, 0); } this.worldEntityHelperContent.CloseInstanciedMeshBlockIFN(abstractTerrainPatchRenderer); this.worldEntityHelperContent.Show(); }
private void ReleaseKaijuArmyActions() { DepartmentOfDefense agency = this.Empire.GetAgency <DepartmentOfDefense>(); SimulationDescriptor value = this.SimulationDescriptorDatabase.GetValue(DepartmentOfTheInterior.ArmyStatusBesiegerDescriptorName); this.KaijuArmy.RemoveDescriptor(value); if (this.KaijuArmy.IsEarthquaker) { this.KaijuArmy.SetEarthquakerStatus(false, false, null); } if (this.KaijuArmy.PillageTarget.IsValid) { DepartmentOfDefense.StopPillage(this.KaijuArmy); } if (this.KaijuArmy.IsAspirating) { agency.StopAspirating(this.KaijuArmy); } if (this.KaijuArmy.IsDismantlingDevice) { ITerraformDeviceRepositoryService service = this.gameService.Game.Services.GetService <ITerraformDeviceRepositoryService>(); TerraformDevice device = service[this.KaijuArmy.DismantlingDeviceTarget] as TerraformDevice; agency.StopDismantelingDevice(this.KaijuArmy, device); } if (this.KaijuArmy.IsDismantlingCreepingNode) { CreepingNode creepingNode = null; if (this.gameEntityRepositoryService.TryGetValue <CreepingNode>(this.KaijuArmy.DismantlingCreepingNodeTarget, out creepingNode)) { agency.StopDismantelingCreepingNode(this.KaijuArmy, creepingNode); } } IWorldPositionningService service2 = this.gameService.Game.Services.GetService <IWorldPositionningService>(); Region region = service2.GetRegion(this.KaijuArmy.WorldPosition); if (region.City != null && region.City.Empire != this.Empire) { DepartmentOfTheInterior agency2 = region.City.Empire.GetAgency <DepartmentOfTheInterior>(); if (agency2 != null) { if (region.City.BesiegingEmpire == this.Empire && agency2.NeedToStopSiege(region.City)) { agency2.StopSiege(region.City); } agency2.StopNavalSiege(region.City, this.KaijuArmy); } IVisibilityService service3 = this.gameService.Game.Services.GetService <IVisibilityService>(); service3.NotifyVisibilityHasChanged(this.Empire); } }
private CreepingNode GetCreepingNodeFromPOI(PointOfInterest pointOfInterest) { CreepingNode result = null; if (pointOfInterest != null && pointOfInterest.CreepingNodeGUID != GameEntityGUID.Zero) { IGameService service = Services.GetService <IGameService>(); Diagnostics.Assert(service != null); IGameEntityRepositoryService service2 = service.Game.Services.GetService <IGameEntityRepositoryService>(); Diagnostics.Assert(service2 != null); service2.TryGetValue <CreepingNode>(pointOfInterest.CreepingNodeGUID, out result); return(result); } return(result); }
public override void Execute(Army army, global::PlayerController playerController, out Ticket ticket, EventHandler <TicketRaisedEventArgs> ticketRaisedEventHandler, params object[] parameters) { ticket = null; if (army == null || playerController == null) { return; } CreepingNode creepingNode = null; if (parameters != null && parameters.Length > 0) { if (parameters[0] is CreepingNode) { creepingNode = (parameters[0] as CreepingNode); } if (parameters[0] is Village) { PointOfInterest pointOfInterest = (parameters[0] as Village).PointOfInterest; creepingNode = this.GetCreepingNodeFromPOI(pointOfInterest); } else if (parameters[0] is PointOfInterest) { PointOfInterest pointOfInterest = parameters[0] as PointOfInterest; creepingNode = this.GetCreepingNodeFromPOI(pointOfInterest); } } List <StaticString> list = new List <StaticString>(); if (creepingNode == null || !this.CanToggleOverCreepingNode(army, creepingNode, ref list)) { return; } if (creepingNode.DismantlingArmy == null) { if (army.IsDismantlingCreepingNode) { OrderToggleDismantleCreepingNode order = new OrderToggleDismantleCreepingNode(army.Empire.Index, army.GUID, army.DismantlingCreepingNodeTarget, false); playerController.PostOrder(order, out ticket, ticketRaisedEventHandler); } OrderToggleDismantleCreepingNode order2 = new OrderToggleDismantleCreepingNode(army.Empire.Index, army.GUID, creepingNode.GUID, true); playerController.PostOrder(order2, out ticket, ticketRaisedEventHandler); } else if (creepingNode.DismantlingArmy == army) { OrderToggleDismantleCreepingNode order3 = new OrderToggleDismantleCreepingNode(army.Empire.Index, army.GUID, creepingNode.GUID, false); playerController.PostOrder(order3, out ticket, ticketRaisedEventHandler); } }
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); }
private void CreateNodeBoundaryIFN(CreepingNode node, WorldArea nodeArea) { Diagnostics.Assert(node != null); Diagnostics.Assert(nodeArea != null); if (base.WorldEntityFactoryService == null) { return; } if (!this.nodeBoundryObjects.ContainsKey(node.GUID)) { UnityEngine.Object @object = Resources.Load("Prefabs/Cities/VillageBoundary"); if (@object != null) { GameObject gameObject = UnityEngine.Object.Instantiate(@object) as GameObject; if (gameObject != null) { Diagnostics.Assert(base.GlobalPositionningService != null); Diagnostics.Assert(base.WorldPositionningService != null); GameObject gameObject2 = null; if (base.WorldEntityFactoryService.TryGetValue(node.PointOfInterest.GUID, out gameObject2)) { gameObject.transform.parent = gameObject2.transform; gameObject.transform.localPosition = new Vector3(0f, 0.03f, 0f); WorldAreaHexagonRenderer component = gameObject.GetComponent <WorldAreaHexagonRenderer>(); Diagnostics.Assert(component != null); if (component == null) { return; } Color color = (node.Empire == null) ? Color.grey : node.Empire.Color; component.SetColor(color); component.SetWorldArea(nodeArea.WorldPositions, node.WorldPosition, base.GlobalPositionningService); component.SetMaterialSelectionStatus(false, true, true); component.SetOnDestroyLaunchAutokillAnimation(0.5f); this.nodeBoundryObjects.Add(node.GUID, gameObject); } } } } }
private bool CanToggleOverCreepingNode(Army army, CreepingNode creepingNode, ref List <StaticString> failureFlags) { if (army == null || creepingNode == null || creepingNode.Empire == army.Empire) { failureFlags.Add(ArmyAction.NoCanDoWhileHidden); return(false); } if (creepingNode.DismantlingArmy != null) { if (creepingNode.DismantlingArmy == army) { return(true); } failureFlags.Add(ArmyAction.NoCanDoWhileHidden); return(false); } else { IGameService service = Services.GetService <IGameService>(); Diagnostics.Assert(service != null); IWorldPositionningService service2 = service.Game.Services.GetService <IWorldPositionningService>(); Diagnostics.Assert(service2 != null); Army armyAtPosition = service2.GetArmyAtPosition(creepingNode.WorldPosition); if (creepingNode != null && creepingNode.DismantlingArmy == null && armyAtPosition != null && creepingNode.Empire.Index != army.Empire.Index) { failureFlags.Add(ArmyAction.NoCanDoWhileHidden); return(false); } if (creepingNode.Empire != army.Empire && army.Empire is MajorEmpire) { DiplomaticRelation diplomaticRelation = army.Empire.GetAgency <DepartmentOfForeignAffairs>().DiplomaticRelations[creepingNode.Empire.Index]; if (diplomaticRelation != null && diplomaticRelation.State != null && (diplomaticRelation.State.Name == DiplomaticRelationState.Names.Alliance || diplomaticRelation.State.Name == DiplomaticRelationState.Names.Peace || diplomaticRelation.State.Name == DiplomaticRelationState.Names.Truce)) { failureFlags.Add(ArmyAction.NoCanDoWhileHidden); return(false); } } return(true); } }
private void SelectCreepingNodes(int DrawCount = 1) { if (this.CheckNodes && this.departmentOfCreepingNodes.Nodes.Count > 0 && this.departmentOfCreepingNodes.Nodes.Count > this.nodeBoundryObjects.Count) { ReadOnlyCollection <IWorldEntityWithCulling> readOnlyCollection; if (this.NodesToDraw.Count == 0 && this.worldEntityCullingService.TryGetVisibleEntities <WorldCreepingNode>(out readOnlyCollection)) { new List <CreepingNode>(); for (int i = 0; i < readOnlyCollection.Count; i++) { WorldCreepingNode worldCreepingNode = readOnlyCollection[i] as WorldCreepingNode; if (worldCreepingNode != null && worldCreepingNode.CreepingNode != null && worldCreepingNode.CreepingNode.Empire.Index == this.City.Empire.Index && !this.nodeBoundryObjects.ContainsKey(worldCreepingNode.CreepingNode.GUID)) { this.NodesToDraw.Add(worldCreepingNode.CreepingNode); } } int num; for (int j = 0; j < this.departmentOfCreepingNodes.Nodes.Count; j = num + 1) { if (!this.nodeBoundryObjects.ContainsKey(this.departmentOfCreepingNodes.Nodes[j].GUID)) { this.NodesToDraw.Add(this.departmentOfCreepingNodes.Nodes[j]); } num = j; } } while (this.NodesToDraw.Count > 0 && DrawCount > 0) { CreepingNode creepingNode = this.NodesToDraw[0]; this.NodesToDraw.RemoveAt(0); if (!this.nodeBoundryObjects.ContainsKey(creepingNode.GUID)) { this.ELCPDrawCreepingNode(creepingNode); DrawCount--; } } } }
private void ELCPDrawCreepingNode(CreepingNode creepingNode) { WorldArea worldArea = new WorldArea(); if (base.WorldPositionningService != null) { int fidsiextractionRange = creepingNode.NodeDefinition.FIDSIExtractionRange; int index = creepingNode.PointOfInterest.Region.Index; for (int i = 0; i < creepingNode.ExploitedTiles.Count; i++) { if (creepingNode.ExploitedTiles[i].IsValid && (int)base.WorldPositionningService.GetRegionIndex(creepingNode.ExploitedTiles[i]) == creepingNode.PointOfInterest.Region.Index && base.WorldPositionningService.GetDistrict(creepingNode.ExploitedTiles[i]) == null && !base.WorldPositionningService.HasRidge(creepingNode.ExploitedTiles[i])) { this.ResourceRendererService.Add(creepingNode.ExploitedTiles[i]); worldArea.WorldPositions.Add(creepingNode.ExploitedTiles[i]); } } if (worldArea.WorldPositions.Count == 0) { worldArea.WorldPositions.Add(creepingNode.WorldPosition); } this.CreateNodeBoundaryIFN(creepingNode, worldArea); this.CreateCreepingNodeHexFidsIFN(creepingNode, worldArea); } }
private void SelectTarget() { this.battleTarget = null; if (this.LastHighlightedWorldPosition == WorldPosition.Invalid) { return; } if (!base.VisibilityService.IsWorldPositionVisibleFor(this.LastHighlightedWorldPosition, this.Army.Empire)) { return; } Region region = base.WorldPositionningService.GetRegion(this.LastHighlightedWorldPosition); if (region == null || this.battleTarget != null) { return; } PointOfInterest pointOfInterest = region.PointOfInterests.FirstOrDefault((PointOfInterest match) => match.WorldPosition == this.LastHighlightedWorldPosition); if (pointOfInterest != null && (pointOfInterest.Type == Fortress.Citadel || pointOfInterest.Type == Fortress.Facility)) { Fortress fortressAt = region.NavalEmpire.GetAgency <PirateCouncil>().GetFortressAt(pointOfInterest.WorldPosition); this.battleTarget = fortressAt; } if (region != null) { District district = null; if (region.City != null && region.City.Empire != this.Army.Empire) { district = region.City.Districts.FirstOrDefault((District match) => match.WorldPosition == this.LastHighlightedWorldPosition); } if (district != null && district.Type != DistrictType.Exploitation) { this.battleTarget = district; } } if (this.battleTarget == null && region != null && region.City != null && region.City.Camp != null && region.City.Camp.WorldPosition == this.LastHighlightedWorldPosition && region.City.Empire != this.Army.Empire) { this.battleTarget = region.City.Camp; } if (this.battleTarget == null) { Army armyAtPosition = base.WorldPositionningService.GetArmyAtPosition(this.LastHighlightedWorldPosition); if (armyAtPosition != null && (!armyAtPosition.IsCamouflaged || base.VisibilityService.IsWorldPositionDetectedFor(this.LastHighlightedWorldPosition, this.Army.Empire))) { this.battleTarget = armyAtPosition; } } if (region != null && this.battleTarget == null) { pointOfInterest = region.PointOfInterests.FirstOrDefault((PointOfInterest match) => match.WorldPosition == this.LastHighlightedWorldPosition); if (pointOfInterest != null) { if (pointOfInterest.CreepingNodeGUID != GameEntityGUID.Zero) { CreepingNode creepingNode = null; base.GameEntityRepositoryService.TryGetValue <CreepingNode>(pointOfInterest.CreepingNodeGUID, out creepingNode); if (creepingNode != null) { if (creepingNode.Empire.Index != this.Army.Empire.Index) { if (ELCPUtilities.UseELCPPeacefulCreepingNodes) { DepartmentOfForeignAffairs agency = this.Army.Empire.GetAgency <DepartmentOfForeignAffairs>(); if (agency != null && agency.IsFriend(creepingNode.Empire)) { if (pointOfInterest.Type == "QuestLocation") { this.battleTarget = pointOfInterest; } else if (pointOfInterest.Type == "Village") { IQuestManagementService service = base.GameService.Game.Services.GetService <IQuestManagementService>(); IQuestRepositoryService service2 = base.GameService.Game.Services.GetService <IQuestRepositoryService>(); IEnumerable <QuestMarker> markersByBoundTargetGUID = service.GetMarkersByBoundTargetGUID(pointOfInterest.GUID); bool flag = false; foreach (QuestMarker questMarker in markersByBoundTargetGUID) { Quest quest; if (service2.TryGetValue(questMarker.QuestGUID, out quest) && quest.EmpireBits == this.Army.Empire.Bits) { Village villageAt = region.MinorEmpire.GetAgency <BarbarianCouncil>().GetVillageAt(pointOfInterest.WorldPosition); this.battleTarget = villageAt; flag = true; break; } } if (!flag) { this.battleTarget = creepingNode; } } else { this.battleTarget = creepingNode; } } } else { this.battleTarget = creepingNode; } } else if (pointOfInterest.Type == "QuestLocation" || pointOfInterest.Type == "NavalQuestLocation") { this.battleTarget = pointOfInterest; } } } else if (pointOfInterest.Type == "Village") { Village villageAt2 = region.MinorEmpire.GetAgency <BarbarianCouncil>().GetVillageAt(pointOfInterest.WorldPosition); this.battleTarget = villageAt2; } else if (pointOfInterest.Type == "QuestLocation" || pointOfInterest.Type == "NavalQuestLocation") { this.battleTarget = pointOfInterest; } } } if (region != null && this.battleTarget == null && region.KaijuEmpire != null && region.Kaiju != null) { KaijuGarrison kaijuGarrison = region.Kaiju.KaijuGarrison; if (kaijuGarrison.WorldPosition == this.LastHighlightedWorldPosition) { this.battleTarget = kaijuGarrison; } } if (this.battleTarget == null) { TerraformDevice deviceAtPosition = (base.GameService.Game as global::Game).GetService <ITerraformDeviceService>().GetDeviceAtPosition(this.LastHighlightedWorldPosition); if (deviceAtPosition != null) { this.battleTarget = deviceAtPosition; } } }
public override void RefreshContent() { base.RefreshContent(); this.filter = CityOptionsPanel.OptionCategory.Default; for (int i = 0; i < this.FilterTable.GetChildren().Count; i++) { AgeControlToggle ageControlToggle = this.filterToggles[i]; if (ageControlToggle.State) { this.filter |= this.filtersByToggle[ageControlToggle]; } } DepartmentOfIndustry agency = this.City.Empire.GetAgency <DepartmentOfIndustry>(); IEnumerable <DepartmentOfIndustry.ConstructibleElement> availableConstructibleElementsAsEnumerable = agency.ConstructibleElementDatabase.GetAvailableConstructibleElementsAsEnumerable(new StaticString[0]); this.filteredElement.Clear(); foreach (DepartmentOfIndustry.ConstructibleElement constructibleElement in availableConstructibleElementsAsEnumerable) { CityOptionsPanel.OptionCategory optionCategory = CityOptionsPanel.OptionCategory.Buildings; if (!(constructibleElement.Category == CampConstructibleActionDefinition.ReadOnlyCategory)) { if (constructibleElement.Category == CityImprovementDefinition.ReadOnlyCategory) { optionCategory = CityOptionsPanel.OptionCategory.Buildings; } else if (constructibleElement.Category == CityConstructibleActionDefinition.ReadOnlyCategory) { optionCategory = CityOptionsPanel.OptionCategory.Buildings; } else if (constructibleElement.Category == CityImprovementDefinition.ReadOnlyNationalCategory) { optionCategory = CityOptionsPanel.OptionCategory.Buildings; } else if (constructibleElement.Category == DistrictImprovementDefinition.ReadOnlyCategory) { optionCategory = CityOptionsPanel.OptionCategory.Expand; } else if (constructibleElement.Category == PointOfInterestImprovementDefinition.ReadOnlyCategory) { optionCategory = CityOptionsPanel.OptionCategory.Expand; } else if (constructibleElement.Category == UnitDesign.ReadOnlyCategory) { optionCategory = CityOptionsPanel.OptionCategory.Unit; if (constructibleElement is UnitDesign && (constructibleElement as UnitDesign).Hidden) { continue; } } else if (constructibleElement.Category == BoosterGeneratorDefinition.ReadOnlyCategory) { optionCategory = CityOptionsPanel.OptionCategory.Booster; } else if (constructibleElement.Category == ConstructibleDistrictDefinition.ReadOnlyCategory) { optionCategory = CityOptionsPanel.OptionCategory.Expand; } if ((optionCategory & this.filter) != CityOptionsPanel.OptionCategory.Default) { this.lastFailureFlags.Clear(); agency.GetConstructibleState(this.City, constructibleElement, ref this.lastFailureFlags); DepartmentOfTheTreasury.CheckConstructiblePrerequisites(this.City, constructibleElement, ref this.lastFailureFlags, new string[] { ConstructionFlags.Disable, ConstructionFlags.Discard }); if (!this.lastFailureFlags.Contains(ConstructionFlags.Discard)) { if (!this.lastFailureFlags.Contains(ConstructionFlags.Disable) && !this.AuthorizeExpand && optionCategory == CityOptionsPanel.OptionCategory.Expand) { this.lastFailureFlags.Add(ConstructionFlags.Disable); } if (this.City.IsInfected) { Diagnostics.Assert(this.City.LastNonInfectedOwner != null); if (StaticString.IsNullOrEmpty(constructibleElement.SubCategory) || !constructibleElement.SubCategory.Equals(DepartmentOfTheInterior.InfectionAllowedSubcategory)) { continue; } if (constructibleElement is CityConstructibleActionDefinition) { CityConstructibleActionDefinition cityConstructibleActionDefinition = constructibleElement as CityConstructibleActionDefinition; if (cityConstructibleActionDefinition.Action.Name == "IntegrateFaction" && (string.IsNullOrEmpty(cityConstructibleActionDefinition.InfectedAffinityConstraint) || !cityConstructibleActionDefinition.InfectedAffinityConstraint.Equals(this.city.LastNonInfectedOwner.Faction.Affinity.Name) || this.City.LastNonInfectedOwner.Faction.GetIntegrationDescriptorsCount() <= 0 || this.departmentOfPlanificationAndDevelopment.HasIntegratedFaction(this.City.LastNonInfectedOwner.Faction))) { continue; } } } if (constructibleElement is CityConstructibleActionDefinition && (constructibleElement as CityConstructibleActionDefinition).Action.Name == "PurgeTheLand") { bool flag = false; PointOfInterest[] pointOfInterests = this.City.Region.PointOfInterests; for (int j = 0; j < pointOfInterests.Length; j++) { if (pointOfInterests[j].CreepingNodeGUID != GameEntityGUID.Zero) { IGameEntity gameEntity = null; if (this.gameEntityRepositoryService.TryGetValue(pointOfInterests[j].CreepingNodeGUID, out gameEntity)) { CreepingNode creepingNode = gameEntity as CreepingNode; if (creepingNode != null && creepingNode.Empire.Index != this.City.Empire.Index && !this.departmentOfForeignAffairs.IsFriend(creepingNode.Empire)) { flag = true; break; } } } } if (!flag) { continue; } } if (constructibleElement is PointOfInterestImprovementDefinition) { this.CheckPointOfInterestImprovementPrerequisites((PointOfInterestImprovementDefinition)constructibleElement, ref this.lastFailureFlags); if (this.lastFailureFlags.Contains(ConstructionFlags.Discard)) { continue; } } this.filteredElement.Add(new CityOptionsPanel.ProductionConstruction(constructibleElement, this.playerControllerRepository.ActivePlayerController.Empire as global::Empire, this.guiSubCategorySorting, this.lastFailureFlags.ToArray())); } } } } this.filteredElement.Sort(); this.OptionsTable.Height = this.optionsTableMinHeight; this.OptionsTable.ReserveChildren(this.filteredElement.Count, this.ConstructibleItemPrefab, "Option"); this.OptionsTable.RefreshChildrenIList <CityOptionsPanel.ProductionConstruction>(this.filteredElement, this.constructibleItemRefreshDelegate, true, false); this.OptionsTable.ArrangeChildren(); this.OptionsScrollview.OnPositionRecomputed(); this.OptionsTable.Enable = (!this.IsOtherEmpire && this.interactionsAllowed); }
public bool IsExploitable(WorldPosition position, int bits = 0) { byte terrainType = this.GetTerrainType(position); StaticString terrainTypeMappingName = this.GetTerrainTypeMappingName(terrainType); if (!StaticString.IsNullOrEmpty(terrainTypeMappingName)) { TerrainTypeMapping terrainTypeMapping = null; if (this.terrainTypeMappingDatabase != null && this.terrainTypeMappingDatabase.TryGetValue(terrainTypeMappingName, out terrainTypeMapping) && terrainTypeMapping.Layers != null && terrainTypeMapping.Layers.Length > 0) { for (int i = 0; i < terrainTypeMapping.Layers.Length; i++) { if (terrainTypeMapping.Layers[i].Type == WorldPositionning.LayerTypeConstruction && terrainTypeMapping.Layers[i].Name == WorldPositionning.LayerNameNotExploitable) { return(false); } } } } GridMap <bool> gridMap = this.World.Atlas.GetMap(WorldAtlas.Maps.Ridges) as GridMap <bool>; if (gridMap != null && gridMap.GetValue(position)) { return(false); } Region region = this.GetRegion(position); if (region != null && region.PointOfInterests != null) { int j = 0; while (j < region.PointOfInterests.Length) { PointOfInterest pointOfInterest = region.PointOfInterests[j]; if (pointOfInterest.WorldPosition != position) { j++; } else { Diagnostics.Assert(pointOfInterest != null); Diagnostics.Assert(pointOfInterest.PointOfInterestDefinition != null); Diagnostics.Assert(pointOfInterest.PointOfInterestDefinition.PointOfInterestTemplate != null); if (WorldPositionning.NonConvertedVillagesArentExploitable && pointOfInterest.Type == "Village") { if (!pointOfInterest.SimulationObject.Tags.Contains(BarbarianCouncil.VillageStatusConverted) && pointOfInterest.CreepingNodeGUID == GameEntityGUID.Zero) { return(false); } IGameEntity gameEntity; if (pointOfInterest.CreepingNodeGUID != GameEntityGUID.Zero && this.GameEntityRepositoryService.TryGetValue(pointOfInterest.CreepingNodeGUID, out gameEntity)) { CreepingNode creepingNode = gameEntity as CreepingNode; if (creepingNode.IsUnderConstruction) { return(false); } } } string text; if (pointOfInterest.PointOfInterestDefinition.PointOfInterestTemplate.Properties != null && pointOfInterest.PointOfInterestDefinition.PointOfInterestTemplate.Properties.TryGetValue(WorldPositionning.PreventsDistrictTypeExploitationConstruction, out text)) { return(false); } break; } } } return(true); }
private void RefreshCreepingNode(AgeTransform tableitem, CreepingNode creepingNode, int index) { CreepingNodeContructionCompletedLine component = tableitem.GetComponent <CreepingNodeContructionCompletedLine>(); component.RefreshContent(creepingNode, base.gameObject); }
protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters) { if (!this.downloadableContentService.IsShared(DownloadableContent20.ReadOnlyName)) { return(State.Failure); } Army army; AIArmyMission.AIArmyMissionErrorCode armyUnlessLocked = base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army); if (armyUnlessLocked != AIArmyMission.AIArmyMissionErrorCode.None) { return(State.Failure); } if (!aiBehaviorTree.Variables.ContainsKey(this.TargetListVarName)) { return(State.Failure); } if (!string.IsNullOrEmpty(this.OpportunityMaximumTurnName) && aiBehaviorTree.Variables.ContainsKey(this.OpportunityMaximumTurnName)) { this.OpportunityMaximumTurn = (float)aiBehaviorTree.Variables[this.OpportunityMaximumTurnName]; } List <IWorldPositionable> list = aiBehaviorTree.Variables[this.TargetListVarName] as List <IWorldPositionable>; if (list == null) { aiBehaviorTree.ErrorCode = 10; return(State.Failure); } if (list.Count == 0) { aiBehaviorTree.ErrorCode = 10; return(State.Failure); } AIEntity_Empire entity = aiBehaviorTree.AICommander.AIPlayer.GetEntity <AIEntity_Empire>(); float num = 0.1f; float propertyValue = army.GetPropertyValue(SimulationProperties.MaximumMovement); PointOfInterest pointOfInterest = null; for (int i = 0; i < list.Count; i++) { PointOfInterest pointOfInterest2 = list[i] as PointOfInterest; if (pointOfInterest2 != null) { if (pointOfInterest2.CreepingNodeImprovement != null) { CreepingNode creepingNode = null; IGameEntity gameEntity = null; if (this.gameEntityRepositoryService.TryGetValue(pointOfInterest2.CreepingNodeGUID, out gameEntity)) { creepingNode = (gameEntity as CreepingNode); } if (creepingNode != null) { if (DepartmentOfDefense.CanDismantleCreepingNode(army, creepingNode, false)) { float num2 = 0.5f; if (entity != null) { num2 = this.ComputeDestroyInterest(creepingNode, entity, army) * 0.5f; } if (num2 >= 0f) { float num3 = (float)this.worldPositionningService.GetDistance(army.WorldPosition, pointOfInterest2.WorldPosition); float num4 = num3 / propertyValue; if (num4 <= this.MaximumTurnDistance) { float num5 = 0.5f - num4 / this.MaximumTurnDistance; num2 = AILayer.Boost(num2, num5 * 0.5f); float life = creepingNode.Life; float maxLife = creepingNode.MaxLife; num2 = AILayer.Boost(num2, (1f - life / maxLife) * 0.2f); if (num2 > num) { num = num2; pointOfInterest = pointOfInterest2; } } } } } } } } if (pointOfInterest != null) { if (this.OpportunityMaximumTurn > 0f) { int num6 = 0; int num7 = 0; if (aiBehaviorTree.Variables.ContainsKey(this.OpportunityMainTargetPosition)) { WorldPosition mainTargetPosition = (WorldPosition)aiBehaviorTree.Variables[this.OpportunityMainTargetPosition]; if (!AIBehaviorTreeNode_Decorator_EvaluateOpportunity.IsDetourWorthCheckingFast(this.worldPositionningService, army, pointOfInterest.WorldPosition, mainTargetPosition, out num7, out num6)) { return(State.Failure); } } } if (aiBehaviorTree.Variables.ContainsKey(this.Output_TargetVarName)) { aiBehaviorTree.Variables[this.Output_TargetVarName] = pointOfInterest; } else { aiBehaviorTree.Variables.Add(this.Output_TargetVarName, pointOfInterest); } return(State.Success); } return(State.Failure); }
public static bool CheckWhetherCanSelectCreepingNode(global::Empire empire, CreepingNode node) { return(empire != null && node != null && node.Empire.Index == empire.Index); }
protected override IEnumerator OnShow(params object[] parameters) { if (this.context == null || !(this.context is CreepingNode)) { base.AgeTransform.Visible = false; } else { CreepingNode creepingNode = this.context as CreepingNode; this.StatusLabel.Text = string.Empty; base.AgeTransform.Height = this.StatusLabel.AgeTransform.Height; this.DefenseGaugeGroup.Visible = true; float life = creepingNode.Life; float maxLife = creepingNode.MaxLife; bool flag = creepingNode.DismantlingArmy != null; float num = 0f; int num2 = 0; float num3 = life; float num4 = life; if (flag) { IGameEntity gameEntity; if (this.gameEntityRepositoryService.TryGetValue(creepingNode.DismantlingArmyGUID, out gameEntity)) { Army army = gameEntity as Army; if (army != null) { num = army.GetPropertyValue(SimulationProperties.CreepingNodeDismantlePower); } } if (num > 0f) { num2 = Mathf.CeilToInt(life / num); } num *= -1f; num3 += num; this.DefenseProgress.TintColor = this.DismantlingColor; this.StatusLabel.Text = AgeLocalizer.Instance.LocalizeString("%FeatureDismantleNodeDismantlingStateTitle"); } else { num = creepingNode.NodeDefinition.GrowthPerTurn; if (num > 0f) { num2 = Mathf.CeilToInt((maxLife - life) / num); } num4 += num; this.DefenseProgress.TintColor = this.RecoveryColor; this.StatusLabel.Text = AgeLocalizer.Instance.LocalizeString("%FeatureDismantleNodeRecoveringStateTitle"); } AgePrimitiveLabel statusLabel = this.StatusLabel; string text = statusLabel.Text; statusLabel.Text = string.Concat(new string[] { text, " (", num2.ToString(), AgeLocalizer.Instance.LocalizeString("%TurnSymbol"), ")" }); this.DefenseGauge.AgeTransform.PercentRight = Mathf.Clamp(life / maxLife, 0f, 1f) * 100f; this.DefenseProgress.AgeTransform.PercentLeft = Mathf.Clamp(num3 / maxLife, 0f, 1f) * 100f; this.DefenseProgress.AgeTransform.PercentRight = Mathf.Clamp(num4 / maxLife, 0f, 1f) * 100f; base.AgeTransform.Height += this.DefenseGaugeGroup.Height; if (num3 != maxLife) { this.DefenseProgress.AgeTransform.Visible = true; } else { this.DefenseProgress.AgeTransform.Visible = false; } if (this.StatusLabel.AgeTransform.PixelMarginTop == this.TitleLabel.AgeTransform.PixelMarginTop) { this.StatusLabel.AgeTransform.PixelMarginLeft = 2f * this.TitleLabel.AgeTransform.PixelMarginLeft + this.TitleLabel.Font.ComputeTextWidth(AgeLocalizer.Instance.LocalizeString(this.TitleLabel.Text), this.TitleLabel.ForceCaps, false); } } yield return(base.OnShow(parameters)); IDownloadableContentService service = Services.GetService <IDownloadableContentService>(); base.AgeTransform.Visible = (this.StatusLabel.Text != string.Empty && service.IsShared(DownloadableContent20.ReadOnlyName)); yield break; }