public override void GetTextToShow(ArcenDoubleCharacterBuffer buffer) { base.GetTextToShow(buffer); if (this.Item == null) { buffer.Add("NULL"); return; } buffer.Add(this.Item.Name); WorldSide localSide = World_AIW2.Instance.GetLocalSide(); if (localSide.UnlockedTechs.Contains(this.Item)) { buffer.Add("\n").Add("(Unlocked)"); } else { buffer.Add("\n").Add("(").Add(this.Item.ScienceCost).Add(")"); if (localSide.GetCanResearch(this.Item, false, false) == ArcenRejectionReason.SideDoesNotHavePrerequisiteTech) { buffer.Add("\n").Add("(Locked)"); } } }
public override MouseHandlingResult HandleClick() { if (this.TypeToBuild == null) { return(MouseHandlingResult.PlayClickDeniedSound); } else { if (Window_InGameTechTypeIconMenu.Instance.IsOpen) { WorldSide localSide = World_AIW2.Instance.GetLocalPlayerSide(); if (localSide.GetCanResearch(this.TypeToBuild.TechPrereq, false, false) != ArcenRejectionReason.Unknown) { return(MouseHandlingResult.PlayClickDeniedSound); } GameCommand command = GameCommand.Create(GameCommandType.UnlockTech); command.RelatedSide = World_AIW2.Instance.GetLocalPlayerSide(); command.RelatedTech = this.TypeToBuild.TechPrereq; World_AIW2.Instance.QueueGameCommand(command, true); return(MouseHandlingResult.None); } else { if (this.TypeToBuild.MetalFlows[MetalFlowPurpose.SelfConstruction] != null) { Engine_AIW2.Instance.PlacingEntityType = this.TypeToBuild; } else { GameCommand command = GameCommand.Create(GameCommandType.AlterBuildQueue); command.RelatedEntityType = this.TypeToBuild; command.RelatedMagnitude = 1; if (Engine_AIW2.Instance.PresentationLayer.GetAreInputFlagsActive(ArcenInputFlags.Subtractive)) { command.RelatedMagnitude = -command.RelatedMagnitude; } Engine_AIW2.Instance.DoForSelected(SelectionCommandScope.CurrentPlanet_UnlessViewingGalaxy, delegate(GameEntity selected) { if (selected.TypeData != this.TypeDoingTheBuilding) { return(DelReturn.Continue); } command.RelatedEntityIDs.Add(selected.PrimaryKeyID); return(DelReturn.Continue); }); if (command.RelatedEntityIDs.Count > 0) { World_AIW2.Instance.QueueGameCommand(command, true); } } } } return(MouseHandlingResult.None); }
public override void HandleClick() { WorldSide localSide = World_AIW2.Instance.GetLocalSide(); if (localSide.GetCanResearch(this.Item, false, false) != ArcenRejectionReason.Unknown) { return; } GameCommand command = GameCommand.Create(GameCommandType.UnlockTech); command.RelatedSide = World_AIW2.Instance.GetLocalSide(); command.RelatedTech = this.Item; World_AIW2.Instance.QueueGameCommand(command); }
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 } }
public override void UpdateContent(ArcenUIWrapperedUnityImage Image, ArcenUI_Image.SubImageGroup SubImages, SubTextGroup SubTexts) { GameEntityTypeData typeData = this.TypeToBuild; if (typeData == null) { return; } WorldSide localSide = World_AIW2.Instance.GetLocalPlayerSide(); Planet planet = Engine_AIW2.Instance.NonSim_GetPlanetBeingCurrentlyViewed(); CombatSide localCombatSide = planet.Combat.GetSideForWorldSide(localSide); int debugStage = -1; try { debugStage = 1; debugStage = 2; SubImages[INDEX_ICON_NO_FLAIR].WrapperedImage.UpdateWith(null, true); SubImages[INDEX_ICON_FLAIR_ONLY].WrapperedImage.UpdateWith(typeData.GUISprite_Icon_White, true); // uncomment if you want a crazy experiment with icons varying in size over time //float size = ( World_AIW2.Instance.GameSecond * 10 ) % 100; //if ( size < 1 ) // size = 1; //SubImages[INDEX_ICON_FLAIR_ONLY].WrapperedImage.SetSize( size, size / 2 ); // uncomment if you want to try vertically centering non-flair icons instead of leaving the gap at the bottom //if ( typeData.GUISprite_Flair == null ) // SubImages[INDEX_ICON_FLAIR_ONLY].WrapperedImage.SetOffset( 0, 5 ); debugStage = 4; SubImages[INDEX_FLAIR].WrapperedImage.UpdateWith(typeData.GUISprite_Flair, true); debugStage = 5; bool showFuel = typeData.BalanceStats.SquadFuelConsumption > 0 && localSide.NetFuel < typeData.BalanceStats.SquadFuelConsumption; SubImages[INDEX_FUEL].WrapperedImage.UpdateToShowOrHide(showFuel); debugStage = 6; bool showPower = typeData.BalanceStats.SquadPowerConsumption > 0 && localCombatSide.NetPower < typeData.BalanceStats.SquadPowerConsumption; SubImages[INDEX_POWER].WrapperedImage.UpdateToShowOrHide(showPower); debugStage = 7; bool showScience = false; bool showLocked = false; bool showUnlocked = false; if (this.ButtonMode == Mode.Tech) { if (typeData.TechPrereq == null) { // shouldn't really be on the tech menu anyway } else { if (localSide.GetHasResearched(typeData.TechPrereq)) { showUnlocked = true; } else if (localSide.GetCanResearch(typeData.TechPrereq, true, false) != ArcenRejectionReason.Unknown) { showLocked = true; } else if (localSide.GetCanResearch(typeData.TechPrereq, false, false) != ArcenRejectionReason.Unknown) { showScience = true; } } } SubImages[INDEX_SCIENCE].WrapperedImage.UpdateToShowOrHide(showScience); //uncomment if you want a crazy experiemnt replacing this icon with a fuel icon //SubImages[INDEX_SCIENCE].WrapperedImage.SetBundleAndPathInBundle( "arcenui", "assets/icons/officialgui/resources/fuel.png" ); SubImages[INDEX_LOCKED].WrapperedImage.UpdateToShowOrHide(showLocked); Image.SetColor(showLocked ? ColorMath.LightGray : ColorMath.White); SubImages[INDEX_UNLOCKED].WrapperedImage.UpdateToShowOrHide(showUnlocked); debugStage = 8; bool showActiveKeyboardColumnIndicator = false; if (this.ButtonMode == Mode.Build) { showActiveKeyboardColumnIndicator = this.ColumnIndex == Window_InGameBuildTypeIconMenu.Instance.CurrentTypeIndex; } else if (this.ButtonMode == Mode.Tech) { showActiveKeyboardColumnIndicator = this.ColumnIndex == Window_InGameTechTypeIconMenu.Instance.CurrentTypeIndex; } SubImages[INDEX_ACTIVE_KEYBOARD_COLUMN].WrapperedImage.UpdateToShowOrHide(showActiveKeyboardColumnIndicator); debugStage = 15; int markLevel = typeData.Balance_MarkLevel.Ordinal; if (markLevel < 0 || markLevel > 5) { markLevel = 0; } SubImages[INDEX_MARK_LEVEL].WrapperedImage.UpdateWith(markLevel <= 0 ? null : Window_InGameOutlineSidebar.Sprite_MarkLevels[markLevel], true); } catch (Exception e) { ArcenDebugging.ArcenDebugLog("Exception in UpdateContent (image) at stage " + debugStage + ":" + e.ToString(), Verbosity.ShowAsError); } debugStage = -1; try { debugStage = 1; ArcenUIWrapperedTMProText text = SubTexts[TEXT_INDEX_UPPER_LEFT].Text; debugStage = 2; ArcenDoubleCharacterBuffer buffer = text.StartWritingToBuffer(); if (typeData != null) { switch (this.ButtonMode) { case Mode.Build: case Mode.Queue: if (planet != null) { int remainingCap = localCombatSide.GetRemainingCap(typeData); text.SetFontSize(12); buffer.Add(remainingCap); if (remainingCap <= 0) { text.SetColor(ColorMath.LightRed); } else { text.SetColor(ColorMath.White); } } break; case Mode.Tech: if (typeData.TechPrereq == null) { break; } if (localSide.GetHasResearched(typeData.TechPrereq)) { break; } int cost = typeData.TechPrereq.ScienceCost; buffer.Add(cost); if (cost > localSide.StoredScience) { text.SetColor(ColorMath.LightRed); } else { text.SetColor(ColorMath.White); } break; } } text.FinishWritingToBuffer(); debugStage = 3; text = SubTexts[TEXT_INDEX_ABOVE_BUTTON].Text; debugStage = 4; buffer = text.StartWritingToBuffer(); if (this.ButtonMode == Mode.Queue) { GameEntity builder = null; Engine_AIW2.Instance.DoForSelected(SelectionCommandScope.CurrentPlanet_UnlessViewingGalaxy, delegate(GameEntity selected) { if (selected.TypeData != this.TypeDoingTheBuilding) { return(DelReturn.Continue); } if (builder != null) { // only show time display when there's only one builder, otherwise it's not clear what should be shown builder = null; return(DelReturn.Break); } builder = selected; return(DelReturn.Continue); }); debugStage = 5; if (builder != null && builder.BuildQueue != null) { BuildQueueItem item = builder.BuildQueue.GetQueueItemFor(typeData); if (item != null) { bool showTimer = item.MetalSpentOnCurrentIteration > 0 && item.NumberBuiltThisLoop < item.NumberToBuildEachLoop; if (showTimer) { FInt metalLeft = typeData.BalanceStats.SquadMetalCost - item.MetalSpentOnCurrentIteration; FInt metalRate = builder.TypeData.MetalFlows[MetalFlowPurpose.BuildingShipsInternally].EffectiveThroughput; if (metalLeft > 0 && metalRate > 0) { FInt secondsLeft = metalLeft / metalRate; buffer.Add(Engine_Universal.ToHoursAndMinutesString(secondsLeft.IntValue)); } } } } } debugStage = 6; text.FinishWritingToBuffer(); } catch (Exception e) { ArcenDebugging.ArcenDebugLog("Exception in UpdateContent (text) at stage " + debugStage + ":" + e.ToString(), Verbosity.ShowAsError); } }