protected bool HasSecondaryTarget(BaseNavyArmy army) { NavyArmy navyArmy = army as NavyArmy; if (navyArmy == null) { return(false); } if (navyArmy.SecondaryTarget == null) { return(false); } if (navyArmy.SecondaryTarget.Type == BehaviorOpportunity.OpportunityType.Ruin) { PointOfInterest pointOfInterest = this.worldPositionService.GetPointOfInterest(navyArmy.SecondaryTarget.OpportunityPosition); if (!this.CouldSearch(army, pointOfInterest)) { navyArmy.SecondaryTarget = null; } } else if (navyArmy.SecondaryTarget.Type == BehaviorOpportunity.OpportunityType.Orbs) { IOrbAIHelper service = AIScheduler.Services.GetService <IOrbAIHelper>(); OrbSpawnInfo orbSpawnInfo; if (!service.TryGetOrbSpawnInfoAt(navyArmy.SecondaryTarget.OpportunityPosition, out orbSpawnInfo) || orbSpawnInfo.CurrentOrbCount == 0f) { navyArmy.SecondaryTarget = null; } } else if (navyArmy.SecondaryTarget.Score <= 0.1f) { navyArmy.SecondaryTarget = null; } return(navyArmy.SecondaryTarget != null); }
public BehaviorNodeReturnCode SelectBestOpportunity(BaseNavyArmy army) { NavyArmy navyArmy = army as NavyArmy; if (navyArmy == null) { return(BehaviorNodeReturnCode.Failure); } float num = 0.1f; BehaviorOpportunity secondaryTarget = null; for (int i = 0; i < navyArmy.Opportunities.Count; i++) { if (navyArmy.Opportunities[i].Score > num) { num = navyArmy.Opportunities[i].Score; secondaryTarget = navyArmy.Opportunities[i]; } } navyArmy.SecondaryTarget = secondaryTarget; if (navyArmy.SecondaryTarget == null) { return(BehaviorNodeReturnCode.Failure); } return(BehaviorNodeReturnCode.Success); }
protected bool IsOpportunityGoodEnough(BaseNavyArmy army) { if (!this.HasSecondaryTarget(army)) { return(false); } NavyArmy navyArmy = army as NavyArmy; return(navyArmy != null && this.IsDetourWorthChecking(army, navyArmy.SecondaryTarget.OpportunityPosition)); }
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 Amplitude.Unity.Game.Orders.Order MoveToSafe(BaseNavyArmy army) { if (!base.HasMovementLeft(army)) { return(null); } NavyArmy navyArmy = army as NavyArmy; if (navyArmy == null) { return(null); } return(base.FollowPath(army, navyArmy.PathToSafePosition)); }
public Amplitude.Unity.Game.Orders.Order MoveSecondary(BaseNavyArmy army) { if (!base.HasMovementLeft(army)) { return(null); } NavyArmy navyArmy = army as NavyArmy; if (navyArmy == null) { return(null); } return(base.FollowPath(army, navyArmy.PathToSecondaryTarget)); }
protected override bool IsMainTransfer(ArmyWithTask army) { NavyArmy navyArmy = army as NavyArmy; if (navyArmy != null) { NavyTask_Reinforcement navyTask_Reinforcement = navyArmy.NavyLayer.FindTask <NavyTask_Reinforcement>((NavyTask_Reinforcement match) => match.TargetGuid == army.Garrison.GUID); if (navyTask_Reinforcement == null || navyTask_Reinforcement.AssignedArmy == null || navyTask_Reinforcement.AssignedArmy.Garrison == null || navyTask_Reinforcement.AssignedArmy.Garrison.GUID != army.MainAttackableTarget.GUID) { return(true); } } return(base.IsMainTransfer(army)); }
public BehaviorNodeReturnCode GatherOpportunities(BaseNavyArmy army) { NavyArmy navyArmy = army as NavyArmy; if (navyArmy == null) { return(BehaviorNodeReturnCode.Failure); } navyArmy.Opportunities.Clear(); this.ComputeOpportunityScore_PointOfInterest(army); this.ComputeOpportunityScore_Orbs(army); navyArmy.Opportunities.Sort((BehaviorOpportunity left, BehaviorOpportunity right) => - 1 * left.Score.CompareTo(right.Score)); return(BehaviorNodeReturnCode.Success); }
protected Amplitude.Unity.Game.Orders.Order GotoAndAttackOpportunity(ArmyWithTask army) { NavyArmy navyArmy = army as NavyArmy; if (navyArmy == null || navyArmy.OpportunityAttackableTarget == null) { return(null); } Army army2 = navyArmy.Garrison as Army; Diagnostics.Log("ELCP {0}/{1} succesfull GotoAndAttackOpportunity", new object[] { army2.Empire, army2.LocalizedName }); return(new OrderGoToAndAttack(army.Garrison.Empire.Index, army.Garrison.GUID, navyArmy.OpportunityAttackableTarget.GUID, navyArmy.PathToSecondaryTarget)); }
private void ComputeOpportunityScore_PointOfInterest(BaseNavyArmy army) { NavyArmy navyArmy = army as NavyArmy; if (navyArmy == null) { return; } Army army2 = army.Garrison as Army; if (army2 != null && army2.HasCatspaw) { return; } for (int i = 0; i < this.worldPositionService.World.Regions.Length; i++) { if (this.worldPositionService.World.Regions[i].IsOcean) { for (int j = 0; j < this.worldPositionService.World.Regions[i].PointOfInterests.Length; j++) { PointOfInterest pointOfInterest = this.worldPositionService.World.Regions[i].PointOfInterests[j]; float num = this.ComputeOpportunityTurnOverhead(army, pointOfInterest.WorldPosition); if ((army.CurrentMainTask == null || this.IsDetourWorthChecking(army, num)) && this.CouldSearch(army, pointOfInterest) && this.IsCloseEnoughToOrigin(army, pointOfInterest.WorldPosition, 2f)) { HeuristicValue heuristicValue = new HeuristicValue(0f); heuristicValue.Add(1f, "constant", new object[0]); HeuristicValue heuristicValue2 = new HeuristicValue(0f); float operand = 1f; heuristicValue2.Add(operand, "Factor from xml(constant for now)", new object[0]); heuristicValue2.Multiply(num, "Nb turn added by opportunity", new object[0]); heuristicValue2.Add(1f, "Constant to avoid divide by 0", new object[0]); heuristicValue.Divide(heuristicValue2, "Distance factor", new object[0]); navyArmy.Opportunities.Add(new BehaviorOpportunity { OpportunityPosition = pointOfInterest.WorldPosition, Score = heuristicValue, Type = BehaviorOpportunity.OpportunityType.Ruin }); } } } } }
public BehaviorNodeReturnCode ComputePathToSecondary(BaseNavyArmy army) { if (!this.HasSecondaryTarget(army)) { return(BehaviorNodeReturnCode.Failure); } NavyArmy navyArmy = army as NavyArmy; if (navyArmy == null) { return(BehaviorNodeReturnCode.Failure); } navyArmy.PathToSecondaryTarget = base.ComputePathToPosition(army, navyArmy.SecondaryTarget.OpportunityPosition, navyArmy.PathToSecondaryTarget); if (navyArmy.PathToSecondaryTarget == null) { navyArmy.SecondaryTarget = null; return(BehaviorNodeReturnCode.Failure); } return(BehaviorNodeReturnCode.Success); }
public BehaviorNodeReturnCode ComputePathToSafe(BaseNavyArmy army) { if (!this.HasSafeTarget(army)) { return(BehaviorNodeReturnCode.Failure); } NavyArmy navyArmy = army as NavyArmy; if (navyArmy == null) { return(BehaviorNodeReturnCode.Failure); } navyArmy.PathToSafePosition = base.ComputePathToPosition(army, navyArmy.SafePosition, navyArmy.PathToSafePosition); if (navyArmy.PathToSafePosition == null) { navyArmy.SafePosition = WorldPosition.Invalid; return(BehaviorNodeReturnCode.Failure); } return(BehaviorNodeReturnCode.Success); }
private void ComputeOpportunityScore_Orbs(BaseNavyArmy army) { NavyArmy navyArmy = army as NavyArmy; if (navyArmy == null) { return; } IOrbAIHelper service = AIScheduler.Services.GetService <IOrbAIHelper>(); for (int i = 0; i < service.OrbSpawns.Count; i++) { OrbSpawnInfo orbSpawnInfo = service.OrbSpawns[i]; if (orbSpawnInfo != null && orbSpawnInfo.CurrentOrbCount != 0f) { HeuristicValue heuristicValue = orbSpawnInfo.EmpireNeedModifier[army.Garrison.Empire.Index]; if (heuristicValue > 0f) { float num = this.ComputeOpportunityTurnOverhead(army, orbSpawnInfo.WorldPosition); if ((army.CurrentMainTask == null || this.IsDetourWorthChecking(army, num)) && this.worldPositionService.IsOceanTile(orbSpawnInfo.WorldPosition) && this.IsCloseEnoughToOrigin(army, orbSpawnInfo.WorldPosition, 1f)) { HeuristicValue heuristicValue2 = new HeuristicValue(0f); heuristicValue2.Add(heuristicValue, "Orb position eval", new object[0]); float orbDistanceExponent = service.GetOrbDistanceExponent(army.Garrison.Empire); HeuristicValue heuristicValue3 = new HeuristicValue(0f); heuristicValue3.Add(num, "Nb turn added by opportunity", new object[0]); heuristicValue3.Power(orbDistanceExponent, "From xml registry", new object[0]); heuristicValue3.Add(1f, "avoid divide by 0", new object[0]); heuristicValue2.Divide(heuristicValue3, "DistanceFactor", new object[0]); navyArmy.Opportunities.Add(new BehaviorOpportunity { OpportunityPosition = orbSpawnInfo.WorldPosition, Score = heuristicValue2, Type = BehaviorOpportunity.OpportunityType.Orbs }); } } } } }
protected bool HasReinforcementClose(BaseNavyArmy army) { NavyArmy navyArmy = army as NavyArmy; if (navyArmy == null || navyArmy.NavyLayer == null) { return(false); } NavyTask_Reinforcement navyTask_Reinforcement = navyArmy.NavyLayer.FindTask <NavyTask_Reinforcement>((NavyTask_Reinforcement match) => match.TargetGuid == army.Garrison.GUID); if (navyTask_Reinforcement != null && navyTask_Reinforcement.AssignedArmy != null) { float num = (float)this.worldPositionService.GetDistance(navyTask_Reinforcement.AssignedArmy.Garrison.WorldPosition, army.Garrison.WorldPosition); BaseNavyArmy baseNavyArmy = navyTask_Reinforcement.AssignedArmy as BaseNavyArmy; float num2 = num / baseNavyArmy.GetMaximumMovement(); if (num2 < 2f) { return(true); } } return(false); }
public BehaviorNodeReturnCode SelectSafePosition(BaseNavyArmy army) { NavyArmy navyArmy = army as NavyArmy; if (navyArmy == null) { return(BehaviorNodeReturnCode.Failure); } Region region; if (navyArmy.Commander != null) { region = navyArmy.Commander.RegionData.WaterRegion; } else { region = this.worldPositionService.GetRegion(army.Garrison.WorldPosition); } int num = -1; float num2 = 0f; for (int i = 0; i < region.Borders.Length; i++) { Region region2 = this.worldPositionService.GetRegion(region.Borders[i].NeighbourRegionIndex); if (!region2.IsOcean) { if (region2.City == null || region2.City.Empire == army.Garrison.Empire) { float num3 = 1f; if (region2.City != null) { num3 += 10f; } if (num3 > num2) { num2 = num3; num = i; } } } } if (num < 0) { return(BehaviorNodeReturnCode.Failure); } Region region3 = this.worldPositionService.GetRegion(region.Borders[num].NeighbourRegionIndex); int num4 = -1; float num5 = float.MaxValue; for (int j = 0; j < region3.Borders.Length; j++) { if (region3.Borders[j].NeighbourRegionIndex == region.Index) { for (int k = 0; k < region3.Borders[j].WorldPositions.Length; k++) { int distance = this.worldPositionService.GetDistance(army.Garrison.WorldPosition, region3.Borders[j].WorldPositions[k]); if ((float)distance < num5) { num5 = (float)distance; num4 = k; num = j; } } } } if (num4 < 0) { return(BehaviorNodeReturnCode.Failure); } navyArmy.SafePosition = region3.Borders[num].WorldPositions[num4]; if (!navyArmy.SafePosition.IsValid) { return(BehaviorNodeReturnCode.Failure); } return(BehaviorNodeReturnCode.Success); }
protected bool HasSafeTarget(BaseNavyArmy army) { NavyArmy navyArmy = army as NavyArmy; return(navyArmy != null && navyArmy.SafePosition.IsValid && this.IsSafe(army.Garrison.Empire, navyArmy.SafePosition) && this.NearCommanderRegion(army, navyArmy.SafePosition)); }