Пример #1
0
    private List <IGarrison> GetNearbyTargets()
    {
        List <IGarrison> result = new List <IGarrison>();

        if (this.Fortress.Occupant == null)
        {
            return(result);
        }
        float propertyValue  = this.Fortress.GetPropertyValue(SimulationProperties.MaximumNumberOfActionPoints);
        float propertyValue2 = this.Fortress.GetPropertyValue(SimulationProperties.ActionPointsSpent);

        if (propertyValue <= propertyValue2)
        {
            return(result);
        }
        DepartmentOfForeignAffairs agency = this.Fortress.Occupant.GetAgency <DepartmentOfForeignAffairs>();
        float num = float.MaxValue;

        foreach (Unit unit in this.Fortress.StandardUnits)
        {
            num = Mathf.Min(unit.GetPropertyValue(SimulationProperties.Movement), num);
        }
        if (num == 3.40282347E+38f || num < 3f)
        {
            return(result);
        }
        AILayer_Military.HasSaveAttackableTargetsNearby(this.Fortress, Mathf.CeilToInt(num + 1f), agency, out result, true);
        return(result);
    }
Пример #2
0
    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);
    }