Exemple #1
0
        protected static Int32 CompareValues(GameEntity Left, GameEntity Right, bool SortDescending, FInt leftValue, FInt rightValue, String fieldName, ArcenCharacterBuffer debugBuffer)
        {
            int val = leftValue.CompareTo(rightValue);

            if (val == 0)
            {
                return(0);
            }
            bool leftWon = SortDescending ? val > 0 : val < 0;

            if (val != 0 && debugBuffer != null)
            {
                LogCompareValues(debugBuffer, Left, Right, fieldName, leftWon, leftValue.ReadableString, rightValue.ReadableString);
            }
            return(leftWon ? -1 : 1);
        }
        protected static TargetComparisonResult CompareValues(GameEntity Left, GameEntity Right, bool SortDescending, FInt leftValue, FInt rightValue, String fieldName, ArcenCharacterBuffer debugBuffer)
        {
            int val = leftValue.CompareTo(rightValue);

            if (val == 0)
            {
                return(TargetComparisonResult.NoPreference);
            }
            bool leftWon = SortDescending ? val > 0 : val < 0;

            if (debugBuffer != null)
            {
                LogCompareValues(debugBuffer, Left, Right, fieldName, leftWon, leftValue.ReadableString, rightValue.ReadableString);
            }
            return(leftWon ? TargetComparisonResult.PreferLeft : TargetComparisonResult.PreferRight);
        }
Exemple #3
0
        public void ComputeCurrentState()
        {
            switch (this.Type)
            {
                #region Victory
            case ObjectiveType.Victory:
            {
                GameEntity masterController = World_AIW2.Instance.GetFirstEntityMatching(SpecialEntityType.AIKingUnit, EntityRollupType.KingUnits);
                if (masterController == null)
                {
                    this.State = ObjectiveState.Met;
                    break;
                }
                if (masterController.Combat.Planet.HumansHaveBasicIntel)
                {
                    this.State = ObjectiveState.NeedToAchieve;
                    this.RelatedPlanets.Add(masterController.Combat.Planet);
                    break;
                }
                this.State = ObjectiveState.NeedToFind;
            }
            break;

                #endregion
                #region GainFleetStrength
            case ObjectiveType.GainFleetStrength:
            {
                WorldSide  localSide = World_AIW2.Instance.GetLocalPlayerSide();
                GameEntity ark       = localSide.Entities.GetFirstMatching(SpecialEntityType.HumanKingUnit);
                if (ark == null)
                {
                    this.State = ObjectiveState.NotApplicable;
                    break;
                }
                List <BuildMenu>          menus             = ark.TypeData.BuildMenus;
                List <GameEntityTypeData> produceableTypes  = new List <GameEntityTypeData>();
                List <GameEntityTypeData> researchableTypes = new List <GameEntityTypeData>();
                bool foundAnyCurrentlyProduceable           = false;
                bool foundAnyTechsCurrentlyResearchable     = false;
                for (int i = 0; i < menus.Count; i++)
                {
                    BuildMenu menu = menus[i];
                    for (int j = 0; j < menu.List.Count; j++)
                    {
                        GameEntityTypeData item = menu.List[j];
                        if (item.BalanceStats.SquadFuelConsumption <= 0)
                        {
                            continue;
                        }
                        ArcenRejectionReason reason = localSide.GetCanBuildAnother(item);
                        switch (reason)
                        {
                        case ArcenRejectionReason.SideDoesNotHaveEnoughCap:
                            continue;

                        case ArcenRejectionReason.SideDoesNotHavePrerequisiteTech:
                            if (item.TechPrereq.NotOnMainTechMenu)
                            {
                                continue;
                            }
                            ArcenRejectionReason techRejectionReason = localSide.GetCanResearch(item.TechPrereq, false, false);
                            switch (techRejectionReason)
                            {
                            case ArcenRejectionReason.SideDoesNotHavePrerequisiteTech:
                                continue;

                            case ArcenRejectionReason.Unknown:
                                foundAnyTechsCurrentlyResearchable = true;
                                break;
                            }
                            researchableTypes.Add(item);
                            continue;

                        case ArcenRejectionReason.Unknown:
                            foundAnyCurrentlyProduceable = true;
                            break;
                        }
                        produceableTypes.Add(item);
                    }
                }
                this.State = ObjectiveState.NeedToAchieve;
                if (foundAnyCurrentlyProduceable)
                {
                    this.SubType = ObjectiveSubType.GainFleetStrength_ThroughProduction;
                    for (int i = 0; i < produceableTypes.Count; i++)
                    {
                        GameEntityTypeData entityType = produceableTypes[i];
                        if (localSide.GetCanBuildAnother(entityType) != ArcenRejectionReason.Unknown)
                        {
                            continue;
                        }
                        this.RelatedEntityTypes.Add(entityType);
                    }
                    this.RelatedEntityTypes.Sort(delegate(GameEntityTypeData Left, GameEntityTypeData Right)
                        {
                            FInt leftValue  = Left.BalanceStats.StrengthPerSquad * localSide.GetRemainingCap(Left);
                            FInt rightValue = Right.BalanceStats.StrengthPerSquad * localSide.GetRemainingCap(Right);
                            return(rightValue.CompareTo(leftValue));
                        });
                }
                else if (produceableTypes.Count > 0)
                {
                    this.SubType = ObjectiveSubType.GainFleetStrength_ThroughFuel;
                    GetPotentialCapturePlanets(localSide);
                    this.RelatedPlanets.Sort(delegate(Planet Left, Planet Right)
                        {
                            return(Right.ResourceOutputs[ResourceType.Fuel].CompareTo(Left.ResourceOutputs[ResourceType.Fuel]));
                        });
                }
                else if (foundAnyTechsCurrentlyResearchable)
                {
                    this.SubType = ObjectiveSubType.GainFleetStrength_ThroughSpendingScience;
                    for (int i = 0; i < researchableTypes.Count; i++)
                    {
                        GameEntityTypeData entityType = researchableTypes[i];
                        if (localSide.GetCanResearch(entityType.TechPrereq, false, false) != ArcenRejectionReason.Unknown)
                        {
                            continue;
                        }
                        this.RelatedEntityTypes.Add(entityType);
                    }
                    this.RelatedEntityTypes.Sort(delegate(GameEntityTypeData Left, GameEntityTypeData Right)
                        {
                            return(Right.BalanceStats.StrengthPerCap.CompareTo(Left.BalanceStats.StrengthPerCap));
                        });
                }
                else if (researchableTypes.Count > 0)
                {
                    this.SubType = ObjectiveSubType.GainFleetStrength_ThroughScience;
                    GetPotentialCapturePlanets(localSide);
                    this.RelatedPlanets.Sort(delegate(Planet Left, Planet Right)
                        {
                            FInt LeftValue  = Left.ResourceOutputs[ResourceType.Science] - Left.ScienceGatheredBySideIndex[localSide.SideIndex];
                            FInt RightValue = Right.ResourceOutputs[ResourceType.Science] - Right.ScienceGatheredBySideIndex[localSide.SideIndex];
                            return(RightValue.CompareTo(LeftValue));
                        });
                }
                else
                {
                    this.State = ObjectiveState.NotApplicable;
                }
            }
            break;

                #endregion
                #region ExploreGalaxy
            case ObjectiveType.ExploreGalaxy:
            {
                GetKnownPlanetsWithAtLeastOneUnitOf(WorldSideType.AI, EntityRollupType.ScramblesSensors);
                this.RelatedPlanets.Sort(delegate(Planet Left, Planet Right)
                    {
                        return(Left.OriginalHopsToHumanHomeworld.CompareTo(Right.OriginalHopsToHumanHomeworld));
                    });
                if (this.RelatedPlanets.Count > 0)
                {
                    this.State = ObjectiveState.NeedToAchieve;
                }
            }
            break;

                #endregion
                #region ClaimFlagship
            case ObjectiveType.ClaimFlagship:
            {
                GetKnownPlanetsWithAtLeastOneUnitOf(WorldSideType.NaturalObject, "Flagship");
                this.RelatedPlanets.Sort(delegate(Planet Left, Planet Right)
                    {
                        return(Left.OriginalHopsToHumanHomeworld.CompareTo(Right.OriginalHopsToHumanHomeworld));
                    });
                if (this.RelatedPlanets.Count > 0)
                {
                    this.State = ObjectiveState.NeedToAchieve;
                }
            }
            break;

                #endregion
                #region GetBonusShipType
            case ObjectiveType.GetBonusShipType:
            {
                GetKnownPlanetsWithAtLeastOneUnitOf(WorldSideType.AI, "AdvancedResearchStation");
                this.RelatedPlanets.Sort(delegate(Planet Left, Planet Right)
                    {
                        return(Left.OriginalHopsToHumanHomeworld.CompareTo(Right.OriginalHopsToHumanHomeworld));
                    });
                if (this.RelatedPlanets.Count > 0)
                {
                    this.State = ObjectiveState.NeedToAchieve;
                }
            }
            break;

                #endregion
                #region DestroyAIPReducer
            case ObjectiveType.DestroyAIPReducer:
            {
                GetKnownPlanetsWithAtLeastOneUnitOf(WorldSideType.AI, "DataCenter");
                this.RelatedPlanets.Sort(delegate(Planet Left, Planet Right)
                    {
                        return(Left.OriginalHopsToHumanHomeworld.CompareTo(Right.OriginalHopsToHumanHomeworld));
                    });
                if (this.RelatedPlanets.Count > 0)
                {
                    this.State = ObjectiveState.NeedToAchieve;
                }
            }
            break;
                #endregion
            }
        }