示例#1
0
    private bool POIAccessible(PointOfInterest POI)
    {
        IGameService              service            = Services.GetService <IGameService>();
        IPathfindingService       service2           = service.Game.Services.GetService <IPathfindingService>();
        IWorldPositionningService service3           = service.Game.Services.GetService <IWorldPositionningService>();
        PathfindingContext        pathfindingContext = new PathfindingContext(GameEntityGUID.Zero, base.Empire, PathfindingMovementCapacity.Ground | PathfindingMovementCapacity.FrozenWater);

        pathfindingContext.RefreshProperties(1f, float.PositiveInfinity, false, false, float.PositiveInfinity, float.PositiveInfinity);
        foreach (WorldPosition worldPosition in WorldPosition.GetDirectNeighbourTiles(POI.WorldPosition))
        {
            if (Amplitude.Unity.Framework.Application.Preferences.EnableModdingTools)
            {
                Diagnostics.Log("ELCP {0} AICommander_Victory POIAccessible checking {1}/{2}", new object[]
                {
                    base.Empire,
                    POI.WorldPosition,
                    worldPosition
                });
            }
            if ((!service3.IsWaterTile(worldPosition) || service3.IsFrozenWaterTile(worldPosition)) && service2.IsTileStopable(worldPosition, pathfindingContext, PathfindingFlags.IgnoreArmies | PathfindingFlags.IgnoreFogOfWar, null) && service2.IsTransitionPassable(worldPosition, POI.WorldPosition, pathfindingContext, PathfindingFlags.IgnoreArmies | PathfindingFlags.IgnoreFogOfWar | PathfindingFlags.IgnorePOI, null))
            {
                if (Amplitude.Unity.Framework.Application.Preferences.EnableModdingTools)
                {
                    Diagnostics.Log("valid");
                }
                return(true);
            }
            if (Amplitude.Unity.Framework.Application.Preferences.EnableModdingTools)
            {
                Diagnostics.Log("not valid");
            }
        }
        return(false);
    }
    private bool POIAccessible()
    {
        IGameService              service  = Services.GetService <IGameService>();
        IPathfindingService       service2 = service.Game.Services.GetService <IPathfindingService>();
        IWorldPositionningService service3 = service.Game.Services.GetService <IWorldPositionningService>();

        foreach (WorldPosition worldPosition in WorldPosition.GetDirectNeighbourTiles(this.POI.WorldPosition))
        {
            if ((!service3.IsWaterTile(worldPosition) || service3.IsFrozenWaterTile(worldPosition)) && service2.IsTileStopable(worldPosition, PathfindingMovementCapacity.Ground | PathfindingMovementCapacity.FrozenWater, PathfindingFlags.IgnoreArmies | PathfindingFlags.IgnoreFogOfWar) && service2.IsTransitionPassable(worldPosition, this.POI.WorldPosition, PathfindingMovementCapacity.Ground | PathfindingMovementCapacity.FrozenWater, PathfindingFlags.IgnoreArmies | PathfindingFlags.IgnoreFogOfWar))
            {
                return(true);
            }
        }
        return(false);
    }
示例#3
0
 public void AddDistrict(District district)
 {
     if (district == null)
     {
         throw new ArgumentNullException("district");
     }
     if (!district.GUID.IsValid)
     {
         Diagnostics.LogError("Cannot add district with invalid guid.");
         return;
     }
     if (this.districts.Exists((District item) => item.GUID == district.GUID))
     {
         Diagnostics.Assert(district.City == this);
         Diagnostics.LogWarning("Cannot add district twice to the same city, ignoring...");
         return;
     }
     if (district.City != null)
     {
         Diagnostics.Assert(district.City != this);
         Diagnostics.LogWarning("Cannot add district already linked to another city, ignoring...");
         return;
     }
     this.districts.Add(district);
     district.City = this;
     base.AddChild(district);
     if (district.Type != DistrictType.Exploitation)
     {
         this.ExtensionCount++;
     }
     if (this.DryDockPosition == WorldPosition.Invalid)
     {
         IWorldPositionningService service = this.gameService.Game.Services.GetService <IWorldPositionningService>();
         if (service.IsWaterTile(district.WorldPosition) && !service.IsFrozenWaterTile(district.WorldPosition))
         {
             GridMap <byte>        map  = (this.gameService.Game as global::Game).World.Atlas.GetMap(WorldAtlas.Maps.Terrain) as GridMap <byte>;
             Map <TerrainTypeName> map2 = (this.gameService.Game as global::Game).World.Atlas.GetMap(WorldAtlas.Tables.Terrains) as Map <TerrainTypeName>;
             byte         value         = map.GetValue(district.WorldPosition);
             StaticString empty         = StaticString.Empty;
             if (map2.Data.TryGetValue((int)value, ref empty) && empty.ToString().IndexOf("InlandWater") == -1)
             {
                 this.DryDockPosition = district.WorldPosition;
             }
         }
     }
     this.OnCityDistrictCollectionChange(CollectionChangeAction.Add, district);
 }
    protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
    {
        if (this.TypeOfDiplomaticRelation == "VillageQuest" && (!(aiBehaviorTree.AICommander.Empire is MajorEmpire) || !aiBehaviorTree.AICommander.Empire.GetAgency <DepartmentOfScience>().CanParley()))
        {
            return(State.Failure);
        }
        if (this.DiplomacyLayer == null && aiBehaviorTree.AICommander.Empire is MajorEmpire)
        {
            AIEntity_Empire entity = aiBehaviorTree.AICommander.AIPlayer.GetEntity <AIEntity_Empire>();
            this.DiplomacyLayer = entity.GetLayer <AILayer_Diplomacy>();
        }
        IGameService service = Services.GetService <IGameService>();

        Diagnostics.Assert(service != null);
        Army army;

        if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) > AIArmyMission.AIArmyMissionErrorCode.None)
        {
            return(State.Failure);
        }
        if (!aiBehaviorTree.Variables.ContainsKey(this.TargetListVarName))
        {
            return(State.Failure);
        }
        List <IWorldPositionable> list = aiBehaviorTree.Variables[this.TargetListVarName] as List <IWorldPositionable>;

        if (list == null || list.Count == 0)
        {
            aiBehaviorTree.ErrorCode = 10;
            return(State.Failure);
        }
        List <IWorldPositionable> list2 = null;

        if (this.TypeOfTarget == AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.Army)
        {
            list2 = list.FindAll((IWorldPositionable match) => match is Army);
        }
        else if (this.TypeOfTarget == AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.Ruin)
        {
            list2 = this.Execute_GetRuins(aiBehaviorTree, army, service, list);
        }
        else if (this.TypeOfTarget == AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.Village)
        {
            list2 = this.Execute_GetVillages(aiBehaviorTree, army, service, list);
        }
        else if (this.TypeOfTarget > AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.Village && this.TypeOfTarget < AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.VolcanoformerDevice)
        {
            list2 = this.Execute_GetKaijus(aiBehaviorTree, army, service, list);
        }
        else if (this.TypeOfTarget == AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.VolcanoformerDevice)
        {
            list2 = this.Execute_GetVolcanoformers(aiBehaviorTree, army, service, list);
        }
        else if (this.TypeOfTarget == AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.Fortress)
        {
            list2 = this.Execute_GetFortresses(aiBehaviorTree, army, service, list);
        }
        else if (this.TypeOfTarget == AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.Any)
        {
            list2 = new List <IWorldPositionable>(list);
        }
        if (army.Empire is MinorEmpire || army.Empire is NavalEmpire)
        {
            for (int i = list2.Count - 1; i >= 0; i--)
            {
                Garrison garrison = list2[i] as Garrison;
                if (garrison != null && garrison.Hero != null && garrison.Hero.IsSkillUnlocked("HeroSkillLeaderMap07"))
                {
                    list2.RemoveAt(i);
                }
            }
        }
        IGameEntityRepositoryService service2 = service.Game.Services.GetService <IGameEntityRepositoryService>();
        IWorldPositionningService    service3 = service.Game.Services.GetService <IWorldPositionningService>();
        bool flag = false;

        if (this.TypeOfDiplomaticRelation == "VillageQuest")
        {
            flag = true;
        }
        if (!string.IsNullOrEmpty(this.TypeOfDiplomaticRelationVariableName) && aiBehaviorTree.Variables.ContainsKey(this.TypeOfDiplomaticRelationVariableName))
        {
            this.TypeOfDiplomaticRelation = (aiBehaviorTree.Variables[this.TypeOfDiplomaticRelationVariableName] as string);
        }
        DepartmentOfForeignAffairs departmentOfForeignAffairs = null;
        bool canAttack = false;

        if (this.TypeOfDiplomaticRelation == "Enemy")
        {
            departmentOfForeignAffairs = aiBehaviorTree.AICommander.Empire.GetAgency <DepartmentOfForeignAffairs>();
            canAttack = true;
        }
        else if (this.TypeOfDiplomaticRelation == "DangerForMe")
        {
            departmentOfForeignAffairs = aiBehaviorTree.AICommander.Empire.GetAgency <DepartmentOfForeignAffairs>();
            canAttack = false;
        }
        for (int j = list2.Count - 1; j >= 0; j--)
        {
            if (!AIBehaviorTreeNode_Decorator_SelectTarget.ValidateTarget(army, list2[j] as IGameEntity, departmentOfForeignAffairs, canAttack, service2, service3))
            {
                list2.RemoveAt(j);
            }
            else if (list2[j] is IGarrison && departmentOfForeignAffairs != null && this.DiplomacyLayer != null && (list2[j] as IGarrison).Empire is MajorEmpire && this.DiplomacyLayer.GetPeaceWish((list2[j] as IGarrison).Empire.Index))
            {
                if (!(list2[j] is Army) || !(list2[j] as Army).IsPrivateers)
                {
                    list2.RemoveAt(j);
                }
            }
            else if (flag && list2[j] is Village && !this.ValidQuestVillage(list2[j] as Village, army))
            {
                list2.RemoveAt(j);
            }
        }
        IWorldPositionningService worldPositionService = service.Game.Services.GetService <IWorldPositionningService>();

        if (list2 != null && list2.Count != 0)
        {
            bool flag2;
            if (this.TypeOfTarget == AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.Ruin || this.TypeOfTarget == AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.Fortress)
            {
                flag2 = army.SimulationObject.Tags.Contains("MovementCapacitySail");
            }
            else
            {
                flag2 = army.HasSeafaringUnits();
            }
            Diagnostics.Assert(worldPositionService != null);
            if (!flag2)
            {
                list2.RemoveAll((IWorldPositionable element) => worldPositionService.IsWaterTile(element.WorldPosition));
            }
            if (army.IsSeafaring)
            {
                list2.RemoveAll((IWorldPositionable element) => !worldPositionService.IsWaterTile(element.WorldPosition));
                list2.RemoveAll((IWorldPositionable element) => worldPositionService.IsFrozenWaterTile(element.WorldPosition));
            }
        }
        if (list2 != null && list2.Count != 0)
        {
            if (list2.Count > 1)
            {
                list2.Sort((IWorldPositionable left, IWorldPositionable right) => worldPositionService.GetDistance(left.WorldPosition, army.WorldPosition).CompareTo(worldPositionService.GetDistance(right.WorldPosition, army.WorldPosition)));
            }
            if (aiBehaviorTree.Variables.ContainsKey(this.Output_TargetVarName))
            {
                aiBehaviorTree.Variables[this.Output_TargetVarName] = list2[0];
            }
            else
            {
                aiBehaviorTree.Variables.Add(this.Output_TargetVarName, list2[0]);
            }
        }
        else if (aiBehaviorTree.Variables.ContainsKey(this.Output_TargetVarName))
        {
            aiBehaviorTree.Variables.Remove(this.Output_TargetVarName);
        }
        State result;

        if (this.Inverted)
        {
            if (list2 != null && list2.Count != 0)
            {
                result = State.Failure;
            }
            else
            {
                result = State.Success;
            }
        }
        else if (list2 != null && list2.Count != 0)
        {
            result = State.Success;
        }
        else
        {
            aiBehaviorTree.ErrorCode = 10;
            result = State.Failure;
        }
        return(result);
    }