Ejemplo n.º 1
0
 protected override bool TryGetArmyData()
 {
     if (base.TryGetArmyData())
     {
         return(true);
     }
     if (this.requestArmy != null)
     {
         if (this.requestArmy.State == BlackboardMessage.StateValue.Message_Canceled)
         {
             this.requestArmy = null;
             return(false);
         }
         this.requestArmy.SetPriority(base.Commander.GetPriority(this));
         if (this.requestArmy.ExecutionState == RequestUnitListMessage.RequestUnitListState.ArmyAvailable)
         {
             GameEntityGUID armyGUID = this.requestArmy.ArmyGUID;
             this.requestArmy.State   = BlackboardMessage.StateValue.Message_Success;
             this.requestArmy.TimeOut = 0;
             this.requestArmy         = null;
             AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(armyGUID);
             if (aidata == null)
             {
                 base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail;
                 return(false);
             }
             if (!aidata.AssignCommanderMission(this))
             {
                 base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail;
                 return(false);
             }
             base.AIDataArmyGUID = armyGUID;
             return(true);
         }
         else if (this.requestArmy.ExecutionState == RequestUnitListMessage.RequestUnitListState.Regrouping)
         {
             base.State = TickableState.NeedTick;
         }
         else if (this.requestArmy.ExecutionState == RequestUnitListMessage.RequestUnitListState.RegroupingPending)
         {
             base.State = TickableState.NoTick;
         }
         else if (this.requestArmy.ExecutionState == RequestUnitListMessage.RequestUnitListState.Pending)
         {
             base.State = TickableState.NoTick;
         }
     }
     else
     {
         this.SendArmyRequest();
     }
     return(false);
 }
    private void OrderTransferUnitToNewArmyTicketRaised(object sender, TicketRaisedEventArgs e)
    {
        this.createFirstArmyTicket = null;
        if (e.Result != PostOrderResponse.Processed)
        {
            for (int i = 0; i < this.UnitGuids.Length; i++)
            {
                IGameEntity gameEntity;
                if (this.gameEntityRepositoryService.TryGetValue(this.UnitGuids[i], out gameEntity))
                {
                    Unit unit = gameEntity as Unit;
                    if (unit != null && (double)unit.GetPropertyValue(SimulationProperties.Movement) < 0.001)
                    {
                        base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail;
                    }
                    return;
                }
            }
            base.Completion = AICommanderMission.AICommanderMissionCompletion.Initializing;
            return;
        }
        OrderTransferGarrisonToNewArmy orderTransferGarrisonToNewArmy = e.Order as OrderTransferGarrisonToNewArmy;
        AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(orderTransferGarrisonToNewArmy.ArmyGuid);

        if (aidata != null)
        {
            aidata.UnassignArmyMission();
            for (int j = 0; j < this.UnitGuids.Length; j++)
            {
                AIData_Unit aidata_Unit;
                this.aiDataRepository.TryGetAIData <AIData_Unit>(this.UnitGuids[j], out aidata_Unit);
                if (aidata_Unit == null)
                {
                    Diagnostics.LogWarning("[AICommanderMission_RegroupArmyAt] no AIData for Unit {0}", new object[]
                    {
                        this.UnitGuids[j].ToString()
                    });
                }
                else
                {
                    aidata_Unit.TryUnLockUnit(base.InternalGUID);
                }
            }
            base.AIDataArmyGUID = aidata.GameEntity.GUID;
            if (!aidata.AssignCommanderMission(this))
            {
                Diagnostics.LogWarning(string.Format("LOCKING Problem in [AICommanderMission_RegroupArmyAt]", new object[0]));
            }
        }
    }
Ejemplo n.º 3
0
    public virtual void ReadXml(XmlReader reader)
    {
        if (reader.ReadVersionAttribute() >= 2)
        {
            this.InternalGUID = reader.GetAttribute <ulong>("InternalGUID");
        }
        if (this.InternalGUID == GameEntityGUID.Zero)
        {
            this.InternalGUID = AIScheduler.Services.GetService <IAIEntityGUIDAIHelper>().GenerateAIEntityGUID();
        }
        this.Completion = (AICommanderMission.AICommanderMissionCompletion)reader.GetAttribute <int>("Completion");
        if (this.Completion == AICommanderMission.AICommanderMissionCompletion.Running)
        {
            this.Completion = AICommanderMission.AICommanderMissionCompletion.Initializing;
        }
        this.AIDataArmyGUID = new GameEntityGUID(reader.GetAttribute <ulong>("AIDataArmyGUID"));
        IDatabase <AICommanderMissionDefinition> database = Databases.GetDatabase <AICommanderMissionDefinition>(false);

        Diagnostics.Assert(database != null);
        StaticString staticString = reader.GetAttribute("MissionDefinition");

        if (!StaticString.IsNullOrEmpty(staticString))
        {
            this.MissionDefinition = database.GetValue(staticString);
        }
        else
        {
            this.Completion = AICommanderMission.AICommanderMissionCompletion.Fail;
            this.State      = TickableState.NoTick;
        }
        this.IsActive = reader.GetAttribute <bool>("IsActive");
        reader.ReadStartElement();
        if (this.AIDataArmyGUID != GameEntityGUID.Zero)
        {
            AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(this.AIDataArmyGUID);
            if (aidata != null)
            {
                aidata.AssignCommanderMission(this);
            }
        }
    }
Ejemplo n.º 4
0
    private bool CheckArmyGuid(GameEntityGUID guid)
    {
        if (guid == GameEntityGUID.Zero)
        {
            return(false);
        }
        AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(guid);

        if (aidata == null)
        {
            return(false);
        }
        if (aidata.Army.Empire != this.Commander.Empire)
        {
            this.ArmyLost();
            return(false);
        }
        if (aidata.CommanderMission != this && !aidata.AssignCommanderMission(this))
        {
            this.Completion = AICommanderMission.AICommanderMissionCompletion.Fail;
            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);
    }