private WorldPosition GetBestAttackPosition(Army army, Garrison target, IWorldPositionable targetWorldPositionable) { bool flag = this.worldPositionningService.IsWaterTile(targetWorldPositionable.WorldPosition); WorldPosition worldPosition = army.WorldPosition; float num = 0f; float num2 = 0f; this.intelligenceAiHelper.EstimateMPInBattleground(army, worldPosition, target, ref num2, ref num); if (num == 0f) { num = 1f; } float num3 = num2 / num; float num4 = 0f; float num5 = 0f; WorldOrientation orientation = this.worldPositionningService.GetOrientation(targetWorldPositionable.WorldPosition, army.WorldPosition); WorldOrientation direction = orientation.Rotate(-1); WorldPosition neighbourTile = this.worldPositionningService.GetNeighbourTile(targetWorldPositionable.WorldPosition, direction, 1); if (neighbourTile.IsValid && this.worldPositionningService.IsWaterTile(neighbourTile) == flag && this.pathfindingService.IsTransitionPassable(neighbourTile, targetWorldPositionable.WorldPosition, army, OrderAttack.AttackFlags, null) && this.pathfindingService.IsTileStopableAndPassable(neighbourTile, army, PathfindingFlags.IgnoreFogOfWar, null) && this.pathfindingService.IsTransitionPassable(neighbourTile, army.WorldPosition, army, OrderAttack.AttackFlags, null)) { this.intelligenceAiHelper.EstimateMPInBattleground(army, neighbourTile, target, ref num5, ref num4); if (num5 == 0f) { num5 = 1f; } float num6 = num5 / num4; if (num3 < num6) { num3 = num6; num2 = num5; num = num4; worldPosition = neighbourTile; } } WorldOrientation direction2 = orientation.Rotate(1); WorldPosition neighbourTile2 = this.worldPositionningService.GetNeighbourTile(targetWorldPositionable.WorldPosition, direction2, 1); if (neighbourTile2.IsValid && this.worldPositionningService.IsWaterTile(neighbourTile2) == flag && this.pathfindingService.IsTransitionPassable(neighbourTile2, targetWorldPositionable.WorldPosition, army, OrderAttack.AttackFlags, null) && this.pathfindingService.IsTileStopableAndPassable(neighbourTile2, army, PathfindingFlags.IgnoreFogOfWar, null) && this.pathfindingService.IsTransitionPassable(neighbourTile2, army.WorldPosition, army, OrderAttack.AttackFlags, null)) { this.intelligenceAiHelper.EstimateMPInBattleground(army, neighbourTile2, target, ref num5, ref num4); if (num5 == 0f) { num5 = 1f; } float num7 = num5 / num4; if (num3 < num7) { num2 = num5; num = num4; worldPosition = neighbourTile2; } } return(worldPosition); }
private void GenerateBattleZone(WorldPosition attackerPosition, WorldOrientation orientation) { World world = (base.GameService.Game as global::Game).World; IGlobalPositionningService globalPositionningService = null; if (globalPositionningService == null) { WorldView worldView = Services.GetService <Amplitude.Unity.View.IViewService>().CurrentView as WorldView; if (worldView != null && worldView.CurrentWorldViewTechnique != null) { globalPositionningService = worldView.CurrentWorldViewTechnique.Services.GetService <IGlobalPositionningService>(); } } if (!attackerPosition.IsValid) { return; } WorldPosition worldPosition = attackerPosition; DeploymentArea deploymentArea = new DeploymentArea(worldPosition, orientation, world.WorldParameters); deploymentArea.Initialize(this.DeploymentAreaWidth, this.DeploymentAreaDepth); WorldArea worldArea = new WorldArea(deploymentArea.GetWorldPositions(world.WorldParameters)); WorldOrientation forward = orientation.Rotate(3); DeploymentArea deploymentArea2 = new DeploymentArea(WorldPosition.GetNeighbourTile(worldPosition, orientation, 1), forward, world.WorldParameters); deploymentArea2.Initialize(this.DeploymentAreaWidth, this.DeploymentAreaDepth); WorldArea worldArea2 = new WorldArea(deploymentArea2.GetWorldPositions(world.WorldParameters)); WorldArea worldArea3 = new WorldArea(worldArea.Grow(world.WorldParameters)); worldArea3 = worldArea3.Union(worldArea2.Grow(world.WorldParameters)); WorldPatch worldPatch = globalPositionningService.GetWorldPatch(attackerPosition); this.GenerateGeometry(worldPatch, attackerPosition, worldArea3, worldArea, worldArea2); }
private void FollowEdges(Army currentArmy, int roamingRegionIndex, WorldPosition startingPosition, WorldOrientation lastOrientation, int direction, out WorldPosition nextDestination, out WorldOrientation nextOrientation) { nextOrientation = lastOrientation.Rotate(3); nextOrientation = nextOrientation.Rotate(direction); nextDestination = this.worldPositionningService.GetNeighbourTile(startingPosition, nextOrientation, 1); for (int i = 0; i < 6; i++) { if (this.CheckPosition(currentArmy, roamingRegionIndex, nextDestination)) { return; } nextOrientation = nextOrientation.Rotate(direction); nextDestination = this.worldPositionningService.GetNeighbourTile(startingPosition, nextOrientation, 1); } nextDestination = WorldPosition.Invalid; }
public IEnumerable <Army> GetArmiesInEncounterZone(WorldPosition attackerPosition, WorldOrientation attackDirection) { int deploymentAreaWidth = Amplitude.Unity.Runtime.Runtime.Registry.GetValue <int>("Gameplay/Battle/DeploymentAreaWidth", 3); int deploymentAreaDepth = Amplitude.Unity.Runtime.Runtime.Registry.GetValue <int>("Gameplay/Battle/DeploymentAreaDepth", 2); DeploymentArea area = new DeploymentArea(attackerPosition, attackDirection, this.world.WorldParameters); area.Initialize(deploymentAreaWidth, deploymentAreaDepth); WorldArea attackerDeploymentArea = new WorldArea(area.GetWorldPositions(this.world.WorldParameters)); WorldOrientation battleZone2Orientation = attackDirection.Rotate(3); WorldPosition center2 = WorldPosition.GetNeighbourTile(attackerPosition, attackDirection, 1); area = new DeploymentArea(center2, battleZone2Orientation, this.world.WorldParameters); area.Initialize(deploymentAreaWidth, deploymentAreaDepth); WorldArea defenderDeploymentArea = new WorldArea(area.GetWorldPositions(this.world.WorldParameters)); WorldArea battleArea = new WorldArea(attackerDeploymentArea.Grow(this.world.WorldParameters)); battleArea = battleArea.Union(defenderDeploymentArea.Grow(this.world.WorldParameters)); foreach (WorldPosition worldPosition in battleArea) { Army army = this.worldAtlasArmies.GetValue(worldPosition); if (army != null) { yield return(army); } } yield break; }
private Wind GetNewWindPreferences() { string seasonType = this.seasonService.GetCurrentSeason().SeasonDefinition.SeasonType; Droplist droplist; if (!this.droplistDatabase.TryGetValue("DroplistWindDirectionChange" + seasonType + this.weatherDifficulty, out droplist)) { Diagnostics.LogError("Fail getting wind direction droplist."); return(this.Wind); } Droplist droplist2; if (!this.droplistDatabase.TryGetValue("DroplistWindStrengthChange" + seasonType + this.weatherDifficulty, out droplist2)) { Diagnostics.LogError("Fail getting wind strength droplist."); return(this.Wind); } Droplist droplist3; DroppableInteger droppableInteger = droplist.Pick(null, out droplist3, new object[0]) as DroppableInteger; DroppableInteger droppableInteger2 = droplist2.Pick(null, out droplist3, new object[0]) as DroppableInteger; WorldOrientation worldOrientation = (WorldOrientation)this.Wind.Direction; if (worldOrientation > WorldOrientation.SouthEast || worldOrientation < WorldOrientation.East) { Diagnostics.LogError("ELCP [Server]: Wind orientation {0} at turn {1} is invalid for some reason! Resetting to WorldOrientation.East", new object[] { worldOrientation, this.game.Turn }); worldOrientation = WorldOrientation.East; } worldOrientation = worldOrientation.Rotate(droppableInteger.Value); return(new Wind((int)worldOrientation, droppableInteger2.Value)); }
public WorldPosition GetRandomValidArmyPosition(Village village) { WorldOrientation orientation = (WorldOrientation)this.random.Next(0, 6); WorldPosition result = WorldPosition.Invalid; for (int i = 0; i < 6; i++) { WorldOrientation direction = orientation.Rotate(i); WorldPosition neighbourg = this.worldPositionningService.GetNeighbourTile(village.WorldPosition, direction, 1); int regionIndex = (int)this.worldPositionningService.GetRegionIndex(neighbourg); if (regionIndex == village.Region.Index) { if (DepartmentOfDefense.CheckWhetherTargetPositionIsValidForUseAsArmySpawnLocation(neighbourg, PathfindingMovementCapacity.Ground | PathfindingMovementCapacity.Water)) { global::Empire[] empires = (this.GameService.Game as global::Game).Empires; int j = 0; while (j < empires.Length) { global::Empire empire = empires[j]; if (!(empire is KaijuEmpire)) { goto IL_106; } KaijuEmpire kaijuEmpire = empire as KaijuEmpire; if (kaijuEmpire == null) { goto IL_106; } KaijuCouncil agency = kaijuEmpire.GetAgency <KaijuCouncil>(); if (agency == null || agency.Kaiju == null || !(agency.Kaiju.WorldPosition == neighbourg)) { goto IL_106; } IL_145: j++; continue; IL_106: if (!(empire is MajorEmpire)) { goto IL_145; } MajorEmpire majorEmpire = empire as MajorEmpire; if (majorEmpire == null || majorEmpire.TamedKaijus.Any((Kaiju m) => m.WorldPosition == neighbourg)) { goto IL_145; } goto IL_145; } District district = this.worldPositionningService.GetDistrict(neighbourg); if (district == null || !District.IsACityTile(district)) { result = neighbourg; break; } } } } return(result); }
public void ComputeCountByOrientation(WorldPosition position, ref int[] countByOrientation) { int regionIndex = (int)this.WorldPositionningService.GetRegionIndex(position); for (int i = 0; i < 6; i++) { countByOrientation[i] = 0; } for (int j = 0; j < countByOrientation.Length; j++) { WorldOrientation worldOrientation = (WorldOrientation)j; int num = j; int num2 = (int)worldOrientation.Rotate(3); WorldPosition worldPosition = position; WorldPosition worldPosition2 = this.WorldPositionningService.GetNeighbourTile(worldPosition, worldOrientation.Rotate(1), 1); if (!this.IsTileValidForExtension(worldPosition2, worldOrientation, regionIndex, 1)) { worldPosition2 = WorldPosition.Invalid; } WorldPosition worldPosition3 = this.WorldPositionningService.GetNeighbourTile(worldPosition, worldOrientation.Rotate(-1), 1); if (!this.IsTileValidForExtension(worldPosition3, worldOrientation, regionIndex, -1)) { worldPosition3 = WorldPosition.Invalid; } while (worldPosition.IsValid && (worldPosition3.IsValid || worldPosition2.IsValid)) { WorldPosition neighbourTile = this.WorldPositionningService.GetNeighbourTile(worldPosition, worldOrientation, 1); if (!this.IsTileValidForExtension(neighbourTile, worldOrientation, regionIndex, 0)) { break; } WorldPosition worldPosition4 = WorldPosition.Invalid; if (worldPosition2.IsValid) { countByOrientation[num]++; worldPosition4 = this.WorldPositionningService.GetNeighbourTile(worldPosition2, worldOrientation, 1); if (!this.IsTileValidForExtension(worldPosition4, worldOrientation, regionIndex, 1)) { worldPosition4 = WorldPosition.Invalid; } } WorldPosition worldPosition5 = WorldPosition.Invalid; if (worldPosition3.IsValid) { countByOrientation[num2]++; worldPosition5 = this.WorldPositionningService.GetNeighbourTile(worldPosition3, worldOrientation, 1); if (!this.IsTileValidForExtension(worldPosition5, worldOrientation, regionIndex, -1)) { worldPosition5 = WorldPosition.Invalid; } } worldPosition = neighbourTile; worldPosition2 = worldPosition4; worldPosition3 = worldPosition5; } } }
protected WorldPosition GetValidTileToAttack(ArmyWithTask navalArmy, IGameEntityWithWorldPosition entityWithPosition) { WorldPosition worldPosition = entityWithPosition.WorldPosition; Fortress fortress = entityWithPosition as Fortress; if (fortress != null) { worldPosition = this.GetBestFacilitiesToAttack(navalArmy, fortress); } City city = entityWithPosition as City; if (city != null) { return(this.GetBestDistrictToAttack(navalArmy, city)); } Army army = navalArmy.Garrison as Army; if (army == null) { return(WorldPosition.Invalid); } bool flag = this.worldPositionService.IsWaterTile(worldPosition); bool isSeafaring = army.IsSeafaring; WorldOrientation worldOrientation = this.worldPositionService.GetOrientation(worldPosition, army.WorldPosition); for (int i = 0; i < 6; i++) { WorldPosition neighbourTile = this.worldPositionService.GetNeighbourTile(worldPosition, worldOrientation, 1); bool flag2 = this.worldPositionService.IsWaterTile(neighbourTile); if ((isSeafaring || !army.IsNaval || flag == flag2) && neighbourTile.IsValid && ((!isSeafaring && flag == flag2) || this.worldPositionService.IsOceanTile(neighbourTile)) && this.pathfindingService.IsTransitionPassable(neighbourTile, worldPosition, army, OrderAttack.AttackFlags, null) && this.pathfindingService.IsTileStopableAndPassable(neighbourTile, army, PathfindingFlags.IgnoreFogOfWar, null)) { return(neighbourTile); } if (i % 2 == 0) { worldOrientation = worldOrientation.Rotate(-(i + 1)); } else { worldOrientation = worldOrientation.Rotate(i + 1); } } return(WorldPosition.Invalid); }
private void ApplyWindToWeatherMap() { this.UpdateWeatherOnArmies(false); WorldOrientation worldOrientation = (WorldOrientation)this.Wind.Direction; if (worldOrientation > WorldOrientation.SouthEast || worldOrientation < WorldOrientation.East) { Diagnostics.LogError("ELCP [Client]: Wind orientation {0} at turn {1} is invalid for some reason! Resetting to WorldOrientation.East", new object[] { worldOrientation, this.game.Turn }); worldOrientation = WorldOrientation.East; } if (this.Wind.Strength < 0) { Diagnostics.LogError("ELCP [Client]: Wind Strength {0} at turn {1} is invalid for some reason! Resetting to 0", new object[] { this.Wind.Strength, this.game.Turn }); this.Wind = new Wind((int)worldOrientation, 0); } if (Amplitude.Unity.Framework.Application.Preferences.EnableModdingTools) { Diagnostics.Log("ELCP: Applying new Wind {0} {1} at turn {2}", new object[] { worldOrientation, this.Wind.Strength, this.game.Turn }); } worldOrientation = worldOrientation.Rotate(3); GridMap <byte> gridMap = new GridMap <byte>(string.Empty, this.weatherMap.Width, this.weatherMap.Height, null); WorldPosition invalid = WorldPosition.Invalid; WorldPosition worldPosition = WorldPosition.Invalid; short num = 0; while ((int)num < gridMap.Height) { invalid.Row = num; short num2 = 0; while ((int)num2 < gridMap.Width) { invalid.Column = num2; worldPosition = this.worldPositionService.GetNeighbourTileFullCyclic(invalid, worldOrientation, this.Wind.Strength); byte value = this.weatherMap.GetValue(worldPosition); gridMap.SetValue(invalid, value); num2 += 1; } num += 1; } this.weatherMap.Data = gridMap.Data; this.UpdateWeatherOnArmies(true); this.modificationDate++; }
private WorldPosition GetValidTileToAttack(WorldPosition maintAttackedPosition, Army army) { District district = this.worldPositionningService.GetDistrict(army.WorldPosition); bool flag = this.worldPositionningService.IsWaterTile(maintAttackedPosition); WorldOrientation worldOrientation = this.worldPositionningService.GetOrientation(maintAttackedPosition, army.WorldPosition); for (int i = 0; i < 6; i++) { WorldPosition neighbourTile = this.worldPositionningService.GetNeighbourTile(maintAttackedPosition, worldOrientation, 1); if (this.worldPositionningService.IsWaterTile(neighbourTile) == flag && this.pathfindingService.IsTransitionPassable(neighbourTile, maintAttackedPosition, army, OrderAttack.AttackFlags, null) && this.pathfindingService.IsTileStopableAndPassable(neighbourTile, army, PathfindingFlags.IgnoreFogOfWar, null)) { District district2 = this.worldPositionningService.GetDistrict(neighbourTile); if (district2 != null && district2.City.Empire.Index == army.Empire.Index && district2.City.BesiegingEmpire != null && District.IsACityTile(district2)) { if (district != null && District.IsACityTile(district) && district.City.GUID == district2.City.GUID) { return(neighbourTile); } } else { if (district == null || !District.IsACityTile(district) || district.City.BesiegingEmpire == null) { return(neighbourTile); } if (district2 != null && District.IsACityTile(district2) && district.City.GUID == district2.City.GUID) { return(neighbourTile); } } } if (i % 2 == 0) { worldOrientation = worldOrientation.Rotate(-(i + 1)); } else { worldOrientation = worldOrientation.Rotate(i + 1); } } return(WorldPosition.Invalid); }
private bool CheckIfPositionIsABorder(int roamingRegionIndex, WorldPosition startingPosition) { WorldOrientation worldOrientation = WorldOrientation.East; for (int i = 0; i < 6; i++) { WorldPosition neighbourTile = this.worldPositionningService.GetNeighbourTile(startingPosition, worldOrientation, 1); if ((int)this.worldPositionningService.GetRegionIndex(neighbourTile) != roamingRegionIndex) { return(true); } worldOrientation = worldOrientation.Rotate(1); } return(false); }
private void RunForwardIfPossible(Army currentArmy, int roamingRegionIndex, WorldPosition startingPosition, WorldOrientation lastOrientation, int direction, out WorldPosition nextDestination, out WorldOrientation nextOrientation) { nextOrientation = lastOrientation; nextDestination = this.worldPositionningService.GetNeighbourTile(startingPosition, nextOrientation, 1); for (int i = 0; i < 6; i++) { if (this.CheckPosition(currentArmy, roamingRegionIndex, nextDestination) && this.pathfindingService.IsTransitionPassable(startingPosition, nextDestination, currentArmy, PathfindingFlags.IgnoreFogOfWar, null)) { return; } nextOrientation = nextOrientation.Rotate(direction); nextDestination = this.worldPositionningService.GetNeighbourTile(startingPosition, nextOrientation, 1); } nextDestination = WorldPosition.Invalid; }
public static WorldPosition GetValidArmySpawningPosition(Army army, IWorldPositionningService worldPositionningService, IPathfindingService pathfindingService) { WorldOrientation worldOrientation = WorldOrientation.East; for (int i = 0; i < 6; i++) { WorldPosition neighbourTile = worldPositionningService.GetNeighbourTile(army.WorldPosition, worldOrientation, 1); if (neighbourTile.IsValid && !worldPositionningService.IsWaterTile(neighbourTile) && pathfindingService.IsTransitionPassable(army.WorldPosition, neighbourTile, army, PathfindingFlags.IgnoreFogOfWar, null) && pathfindingService.IsTileStopableAndPassable(neighbourTile, army, PathfindingFlags.IgnoreFogOfWar, null)) { return(neighbourTile); } worldOrientation = worldOrientation.Rotate(1); } return(WorldPosition.Invalid); }
public Amplitude.Unity.Game.Orders.Order CreateArmyFromFortress(BaseNavyArmy army) { if (!this.IsFortress(army)) { return(null); } WorldPosition armyPosition = WorldPosition.Invalid; WorldOrientation orientation = WorldOrientation.East; if (army.MainAttackableTarget != null) { orientation = this.worldPositionService.GetOrientation(army.Garrison.WorldPosition, army.MainAttackableTarget.WorldPosition); } Fortress fortress = army.Garrison as Fortress; for (int i = 0; i < 6; i++) { WorldPosition neighbourTile = this.worldPositionService.GetNeighbourTile(fortress.WorldPosition, orientation.Rotate(i), 1); if (DepartmentOfDefense.CheckWhetherTargetPositionIsValidForUseAsArmySpawnLocation(neighbourTile, PathfindingMovementCapacity.Water)) { armyPosition = neighbourTile; break; } } if (!armyPosition.IsValid) { for (int j = 0; j < fortress.Facilities.Count; j++) { for (int k = 0; k < 6; k++) { WorldPosition neighbourTile2 = this.worldPositionService.GetNeighbourTile(fortress.Facilities[j].WorldPosition, (WorldOrientation)k, 1); if (DepartmentOfDefense.CheckWhetherTargetPositionIsValidForUseAsArmySpawnLocation(neighbourTile2, PathfindingMovementCapacity.Water)) { armyPosition = neighbourTile2; break; } } } } GameEntityGUID[] array = new GameEntityGUID[army.Garrison.StandardUnits.Count]; for (int l = 0; l < army.Garrison.StandardUnits.Count; l++) { array[l] = army.Garrison.StandardUnits[l].GUID; } return(new OrderTransferGarrisonToNewArmy(army.Garrison.Empire.Index, army.Garrison.GUID, array, armyPosition, null, false, true, true)); }
private bool IsExtensionInterestingAt(WorldPosition extensionPosition, WorldOrientation currentDirection, int localRow, int centerRegionIndex) { WorldPosition neighbourTile = this.WorldPositionningService.GetNeighbourTile(extensionPosition, currentDirection, 1); if (!this.WorldPositionningService.IsExploitable(neighbourTile, 0) || (int)this.WorldPositionningService.GetRegionIndex(neighbourTile) != centerRegionIndex) { return(false); } if (localRow == 0 || localRow == 1) { neighbourTile = this.WorldPositionningService.GetNeighbourTile(extensionPosition, currentDirection.Rotate(1), 1); if (!this.WorldPositionningService.IsExploitable(neighbourTile, 0) || (int)this.WorldPositionningService.GetRegionIndex(neighbourTile) != centerRegionIndex) { return(false); } } if (localRow == 0 || localRow == -1) { neighbourTile = this.WorldPositionningService.GetNeighbourTile(extensionPosition, currentDirection.Rotate(-1), 1); if (!this.WorldPositionningService.IsExploitable(neighbourTile, 0) || (int)this.WorldPositionningService.GetRegionIndex(neighbourTile) != centerRegionIndex) { return(false); } } return(true); }
protected override bool TryGetArmyData() { if (this.createFirstArmyTicket != null) { return(false); } if (base.AIDataArmyGUID.IsValid) { return(true); } if (this.currentTicket != null) { return(false); } IGameEntity gameEntity; if (!this.gameEntityRepositoryService.TryGetValue(this.SourceGuid, out gameEntity)) { base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail; return(false); } for (int i = this.UnitGuids.Length - 1; i >= 0; i--) { AIData_Unit aidata_Unit; this.aiDataRepository.TryGetAIData <AIData_Unit>(this.UnitGuids[i], out aidata_Unit); if (aidata_Unit == null) { Diagnostics.LogWarning("[AICommanderMission_RegroupArmyAt] no AIData for Unit {0}", new object[] { this.UnitGuids[i].ToString() }); } else { if (aidata_Unit.IsUnitLocked() && !aidata_Unit.IsUnitLockedByMe(base.InternalGUID)) { WorldPosition worldPosition = WorldPosition.Invalid; if (aidata_Unit.Unit.Garrison is IWorldPositionable) { worldPosition = (aidata_Unit.Unit.Garrison as IWorldPositionable).WorldPosition; } Diagnostics.LogWarning(string.Format("{1} {2} LOCKING: Unit shouldn't be in use, current unit state: {0}", aidata_Unit.GetLockingStateString(), base.Commander.Empire, worldPosition)); base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail; return(false); } if (aidata_Unit.Unit.UnitDesign.Tags.Contains(DownloadableContent9.TagSolitary)) { Diagnostics.LogWarning("You cannot regroup Colossus or Solitary unit with something else."); base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail; return(false); } } } IGarrison garrison = gameEntity as IGarrison; if (garrison == null) { base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail; return(false); } if (this.AICommanderRegroupArmies != null && this.AICommanderRegroupArmies.RequestUnitListMessageID != 0UL) { RequestUnitListMessage requestUnitListMessage = base.Commander.AIPlayer.Blackboard.GetMessage(this.AICommanderRegroupArmies.RequestUnitListMessageID) as RequestUnitListMessage; if (requestUnitListMessage == null) { base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail; return(false); } requestUnitListMessage.ExecutionState = RequestUnitListMessage.RequestUnitListState.Regrouping; } bool flag = false; for (int j = 0; j < this.UnitGuids.Length; j++) { if (!garrison.ContainsUnit(this.UnitGuids[j])) { flag = true; break; } } if (flag) { List <GameEntityGUID> list = new List <GameEntityGUID>(); for (int k = 0; k < this.UnitGuids.Length; k++) { if (garrison.ContainsUnit(this.UnitGuids[k])) { list.Add(this.UnitGuids[k]); } } this.UnitGuids = list.ToArray(); } if (this.UnitGuids.Length == 0) { base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail; return(false); } WorldPosition armyPosition = WorldPosition.Invalid; Army army = gameEntity as Army; if (army != null) { AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(gameEntity.GUID); Diagnostics.Assert(aidata != null); if (army.GetPropertyValue(SimulationProperties.Movement) <= 0f) { return(false); } if (aidata.CommanderMission != null) { aidata.CommanderMission.Interrupt(); } if (aidata.Army.IsInEncounter || aidata.Army.IsLocked) { return(false); } if (aidata.Army.StandardUnits.Count != this.UnitGuids.Length) { armyPosition = AILayer_ArmyRecruitment.GetValidArmySpawningPosition(aidata.Army, this.worldPositionningService, this.pathfindingService); int num = (int)base.Commander.Empire.GetPropertyValue(SimulationProperties.ArmyUnitSlot); if (aidata.Army.StandardUnits.Count > num) { Array.Resize <GameEntityGUID>(ref this.UnitGuids, num); } } else { if (!aidata.AssignCommanderMission(this)) { base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail; return(false); } base.AIDataArmyGUID = gameEntity.GUID; return(true); } } else if (gameEntity is Village) { Village village = gameEntity as Village; if (village.IsInEncounter) { return(false); } WorldPosition worldPosition2 = village.WorldPosition; WorldOrientation worldOrientation = WorldOrientation.East; if (this.AICommanderRegroupArmies.FinalPosition.IsValid) { worldOrientation = this.worldPositionningService.GetOrientation(worldPosition2, this.AICommanderRegroupArmies.FinalPosition); } for (int l = 0; l < 6; l++) { WorldPosition neighbourTile = this.worldPositionningService.GetNeighbourTile(worldPosition2, worldOrientation, 1); if (DepartmentOfDefense.CheckWhetherTargetPositionIsValidForUseAsArmySpawnLocation(neighbourTile, PathfindingMovementCapacity.Ground | PathfindingMovementCapacity.Water) && this.pathfindingService.IsTransitionPassable(village.WorldPosition, neighbourTile, this.pathfindingContext, PathfindingFlags.IgnoreFogOfWar, null) && this.pathfindingService.IsTilePassable(neighbourTile, this.pathfindingContext, (PathfindingFlags)0, null) && this.pathfindingService.IsTileStopable(neighbourTile, this.pathfindingContext, (PathfindingFlags)0, null)) { if (this.worldPositionningService.GetArmyAtPosition(neighbourTile) == null) { armyPosition = neighbourTile; break; } } else { worldOrientation = worldOrientation.Rotate(1); } } } else if (gameEntity is City) { City city = gameEntity as City; if (city.IsInEncounter) { return(false); } if (!DepartmentOfTheInterior.TryGetWorldPositionForNewArmyFromCity(city, this.pathfindingService, this.pathfindingContext, out armyPosition)) { return(false); } } else { Diagnostics.LogError(string.Format("[AICommanderMission_RegroupArmyAt] The garrison {0} is not valid.", garrison.GUID)); } if (armyPosition.IsValid) { if (army != null && army.WorldPath != null && army.WorldPath.Destination != army.WorldPosition) { OrderGoTo orderGoTo = new OrderGoTo(army.Empire.Index, army.GUID, army.WorldPosition); orderGoTo.Flags = (PathfindingFlags)0; base.Commander.Empire.PlayerControllers.AI.PostOrder(orderGoTo, out this.currentTicket, new EventHandler <TicketRaisedEventArgs>(this.MoveOrder_TicketRaised)); if (this.currentTicket != null) { return(false); } if (!this.orderExecuted) { Diagnostics.LogError("[AICommanderMission_RegroupArmyAt] new cancelation move order was not executed, from {0} to {1}", new object[] { army.WorldPosition, army.WorldPosition }); return(false); } } for (int m = 0; m < this.UnitGuids.Length; m++) { AIData_Unit aidata_Unit2; this.aiDataRepository.TryGetAIData <AIData_Unit>(this.UnitGuids[m], out aidata_Unit2); if (aidata_Unit2 == null) { Diagnostics.LogWarning("[AICommanderMission_RegroupArmyAt] no AIData for Unit {0}", new object[] { this.UnitGuids[m].ToString() }); } else if (!aidata_Unit2.IsUnitLockedByMe(base.InternalGUID)) { aidata_Unit2.TryLockUnit(base.InternalGUID, base.GetType().ToString(), AIData_Unit.AIDataReservationExtraTag.Regrouping, base.Commander.GetPriority(this)); } } OrderTransferGarrisonToNewArmy order = new OrderTransferGarrisonToNewArmy(base.Commander.Empire.Index, this.SourceGuid, this.UnitGuids, armyPosition, "Regroup", false, true, true); base.Commander.Empire.PlayerControllers.Server.PostOrder(order, out this.createFirstArmyTicket, new EventHandler <TicketRaisedEventArgs>(this.OrderTransferUnitToNewArmyTicketRaised)); } return(false); }
protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters) { Army army; if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) != AIArmyMission.AIArmyMissionErrorCode.None) { return(State.Failure); } Region region = null; if (aiBehaviorTree.Variables.ContainsKey(this.TargetCity) || !string.IsNullOrEmpty(this.TargetCity)) { City city = aiBehaviorTree.Variables[this.TargetCity] as City; if (city != null) { region = city.Region; } } if (region == null) { if (string.IsNullOrEmpty(this.TargetRegionVarName) || !aiBehaviorTree.Variables.ContainsKey(this.TargetRegionVarName)) { aiBehaviorTree.LogError("Target region variable '{0}' not initialized.", new object[] { this.TargetRegionVarName }); return(State.Failure); } int num = (int)aiBehaviorTree.Variables[this.TargetRegionVarName]; region = this.worldPositionningService.World.Regions[num]; if (region == null) { aiBehaviorTree.LogError("Target region index '{0}' is not valid.", new object[] { num }); return(State.Failure); } } if (region.City == null || region.City.Empire != army.Empire) { if (aiBehaviorTree.AICommander.Empire is MajorEmpire) { List <Village> list = (aiBehaviorTree.AICommander.Empire as MajorEmpire).ConvertedVillages.FindAll((Village match) => match.Region == region); for (int i = list.Count - 1; i >= 0; i--) { if (list[i].IsInEncounter) { list.RemoveAt(i); } } if (list.Count != 0) { int num2 = this.random.Next(0, list.Count); Village village = list[num2]; num2 = this.random.Next(0, 6); WorldOrientation worldOrientation = (WorldOrientation)num2; for (int j = 0; j < 6; j++) { WorldPosition neighbourTile = this.worldPositionningService.GetNeighbourTile(village.WorldPosition, worldOrientation, 1); if (this.pathfindingService.IsTileStopableAndPassable(neighbourTile, army, PathfindingFlags.IgnoreFogOfWar, null)) { this.AddOutputPositionToBehaviorTree(aiBehaviorTree, neighbourTile); return(State.Success); } worldOrientation = worldOrientation.Rotate(1); } } } this.AddOutputPositionToBehaviorTree(aiBehaviorTree, this.GetFurthestPositionInRegion(army, region)); return(State.Success); } City city2 = region.City; if (!city2.IsInEncounter) { int num3 = this.random.Next(0, city2.Districts.Count); for (int k = 0; k < city2.Districts.Count; k++) { District district = city2.Districts[(k + num3) % city2.Districts.Count]; if (this.pathfindingService.IsTileStopableAndPassable(district.WorldPosition, army, PathfindingFlags.IgnoreFogOfWar, null) && (city2.BesiegingEmpire == null || !District.IsACityTile(district))) { this.AddOutputPositionToBehaviorTree(aiBehaviorTree, district.WorldPosition); return(State.Success); } } } this.AddOutputPositionToBehaviorTree(aiBehaviorTree, this.GetFurthestPositionInRegion(army, region)); return(State.Success); }
protected void SpawnArmy(QuestBehaviour questBehaviour) { if (!string.IsNullOrEmpty(this.ArmyDroplist)) { IGameService service = Services.GetService <IGameService>(); if (service == null || service.Game == null) { Diagnostics.LogError("Failed to retrieve the game service."); return; } global::Game game = service.Game as global::Game; if (game == null) { Diagnostics.LogError("Failed to cast gameService.Game to Game."); return; } IDatabase <Droplist> database = Databases.GetDatabase <Droplist>(false); if (database == null) { return; } string text = this.ArmyDroplist; if (this.ArmyDroplistSuffix != string.Empty) { text = text + "_" + this.ArmyDroplistSuffix; } Droplist droplist; if (!database.TryGetValue(text, out droplist)) { Diagnostics.LogError("Cannot retrieve drop list '{0}' in quest definition '{1}'", new object[] { text, questBehaviour.Quest.QuestDefinition.Name }); return; } if (!string.IsNullOrEmpty(this.EmpireArmyOwnerVarName)) { global::Empire empire = null; object obj; if (questBehaviour.TryGetQuestVariableValueByName <object>(this.EmpireArmyOwnerVarName, out obj)) { if (obj is global::Empire) { empire = (obj as global::Empire); } else if (obj is int) { empire = game.Empires[(int)obj]; } if (empire != null) { this.EmpireArmyOwner = empire; } } } global::Empire empire2 = this.EmpireArmyOwner; if (empire2 == null || empire2 is LesserEmpire || this.UseBehaviorInitiatorEmpire) { empire2 = questBehaviour.Initiator; } if (this.UseBehaviorInitiatorEmpire) { this.EmpireArmyOwner = questBehaviour.Initiator; } if (this.EmpireArmyOwner is MajorEmpire && (this.EmpireArmyOwner as MajorEmpire).ELCPIsEliminated) { return; } Droplist droplist2; DroppableArmyDefinition droppableArmyDefinition = droplist.Pick(empire2, out droplist2, new object[0]) as DroppableArmyDefinition; if (droppableArmyDefinition != null) { int num = 0; if (this.ScaleWithMaxEra) { num = DepartmentOfScience.GetMaxEraNumber() - 1; } int val = 0; IDatabase <AnimationCurve> database2 = Databases.GetDatabase <AnimationCurve>(false); AnimationCurve animationCurve; if (database2 != null && database2.TryGetValue(QuestBehaviourTreeNode_Action_SpawnArmy.questUnitLevelEvolution, out animationCurve)) { float propertyValue = questBehaviour.Initiator.GetPropertyValue(SimulationProperties.GameSpeedMultiplier); val = (int)animationCurve.EvaluateWithScaledAxis((float)game.Turn, propertyValue, 1f); val = Math.Max(0, Math.Min(100, val)); } num = Math.Max(num, val); StaticString[] array = Array.ConvertAll <string, StaticString>(droppableArmyDefinition.UnitDesigns, (string input) => input); bool flag = false; IDatabase <UnitDesign> database3 = Databases.GetDatabase <UnitDesign>(false); for (int i = 0; i < array.Length; i++) { UnitDesign unitDesign; if (database3.TryGetValue(array[i], out unitDesign) && unitDesign != null && unitDesign.Tags.Contains(DownloadableContent16.TagSeafaring)) { flag = true; break; } } IEnumerable <WorldPosition> enumerable = null; questBehaviour.TryGetQuestVariableValueByName <WorldPosition>(this.ForbiddenSpawnLocationVarName, out enumerable); List <WorldPosition> list = this.SpawnLocations.ToList <WorldPosition>().Randomize(null); IWorldPositionningService service2 = game.Services.GetService <IWorldPositionningService>(); IPathfindingService service3 = game.Services.GetService <IPathfindingService>(); Diagnostics.Assert(service2 != null); WorldPosition worldPosition = WorldPosition.Invalid; if (!questBehaviour.Quest.QuestDefinition.IsGlobal) { PathfindingMovementCapacity pathfindingMovementCapacity = PathfindingMovementCapacity.Water; if (!flag) { pathfindingMovementCapacity |= PathfindingMovementCapacity.Ground; } for (int j = 0; j < list.Count; j++) { WorldPosition worldPosition2 = list[j]; if (DepartmentOfDefense.CheckWhetherTargetPositionIsValidForUseAsArmySpawnLocation(worldPosition2, pathfindingMovementCapacity)) { if (enumerable != null) { if (enumerable.Contains(worldPosition2)) { goto IL_330; } this.AddPositionToForbiddenSpawnPosition(questBehaviour, worldPosition2); } worldPosition = worldPosition2; break; } IL_330 :; } if (!service3.IsTileStopable(worldPosition, PathfindingMovementCapacity.Ground | PathfindingMovementCapacity.Water, PathfindingFlags.IgnoreFogOfWar)) { worldPosition = WorldPosition.Invalid; } if (!worldPosition.IsValid && list.Count > 0) { List <WorldPosition> list2 = new List <WorldPosition>(); Queue <WorldPosition> queue = new Queue <WorldPosition>(); worldPosition = list[0]; bool flag2 = false; if (worldPosition.IsValid) { flag2 = service2.IsWaterTile(worldPosition); } do { if (queue.Count > 0) { worldPosition = queue.Dequeue(); } for (int k = 0; k < 6; k++) { WorldPosition neighbourTileFullCyclic = service2.GetNeighbourTileFullCyclic(worldPosition, (WorldOrientation)k, 1); if (!list2.Contains(neighbourTileFullCyclic) && list2.Count < 19) { queue.Enqueue(neighbourTileFullCyclic); list2.Add(neighbourTileFullCyclic); } } if (!DepartmentOfDefense.CheckWhetherTargetPositionIsValidForUseAsArmySpawnLocation(worldPosition, pathfindingMovementCapacity) || !service3.IsTileStopable(worldPosition, PathfindingMovementCapacity.Ground | PathfindingMovementCapacity.Water, PathfindingFlags.IgnoreFogOfWar) || flag2 != service2.IsWaterTile(worldPosition)) { worldPosition = WorldPosition.Invalid; } }while (worldPosition == WorldPosition.Invalid && queue.Count > 0); } if (!worldPosition.IsValid) { string format = "Cannot find a valid position to spawn on: {0}"; object[] array2 = new object[1]; array2[0] = string.Join(",", list.Select(delegate(WorldPosition position) { WorldPosition worldPosition3 = position; return(worldPosition3.ToString()); }).ToArray <string>()); Diagnostics.LogError(format, array2); return; } } OrderSpawnArmy orderSpawnArmy; if (worldPosition.IsValid) { list.Clear(); list.Add(worldPosition); WorldOrientation worldOrientation = WorldOrientation.East; for (int l = 0; l < 6; l++) { WorldPosition neighbourTile = service2.GetNeighbourTile(worldPosition, worldOrientation, 1); bool flag3 = flag == service2.IsWaterTile(neighbourTile); if (neighbourTile.IsValid && flag3 && service3.IsTileStopable(worldPosition, PathfindingMovementCapacity.Ground | PathfindingMovementCapacity.Water, PathfindingFlags.IgnoreFogOfWar)) { list.Add(neighbourTile); } worldOrientation = worldOrientation.Rotate(1); } orderSpawnArmy = new OrderSpawnArmy(this.EmpireArmyOwner.Index, list.ToArray(), num, true, this.CanMoveOnSpawn, true, questBehaviour.Quest.QuestDefinition.IsGlobal || this.ForceGlobalArmySymbol, array); } else { orderSpawnArmy = new OrderSpawnArmy(this.EmpireArmyOwner.Index, list.ToArray(), num, true, this.CanMoveOnSpawn, true, questBehaviour.Quest.QuestDefinition.IsGlobal || this.ForceGlobalArmySymbol, array); } orderSpawnArmy.GameEntityGUID = this.ArmyGUID; Diagnostics.Log("Posting order: {0} at {1}", new object[] { orderSpawnArmy.ToString(), worldPosition }); if (!string.IsNullOrEmpty(this.TransferResourceName) && this.TransferResourceAmount > 0) { Ticket ticket; this.EmpireArmyOwner.PlayerControllers.Server.PostOrder(orderSpawnArmy, out ticket, new EventHandler <TicketRaisedEventArgs>(this.OrderSpawnArmy_TicketRaised)); return; } this.EmpireArmyOwner.PlayerControllers.Server.PostOrder(orderSpawnArmy); } } }