using Arcen.Universal; using Arcen.AIW2.Core; using System; using System.Collections.Generic; using UnityEngine; using TMPro; namespace Arcen.AIW2.External { public class Window_InGameHoverPlanetInfo : WindowControllerAbstractBase { public static Window_InGameHoverPlanetInfo Instance; public Window_InGameHoverPlanetInfo() { this.OnlyShowInGame = true; Instance = this; } public static bool IsDrawing = false; public class bPanel : ImageButtonAbstractBase { public static bPanel Instance; public bPanel() { Instance = this; } public ArcenUI_ImageButton MyElement; private SubTextGroup SubTexts; private string NextTextToShow = string.Empty; private string WrappedNextTextToShow = string.Empty; private string LastTextToShow = string.Empty; private bool NeedsToResize = true; private float LastRequestedWidth; private float LastRequestedHeight; private bool hasSetCanvasOffset = false; public void ClearMyself() { this.LastTextToShow = string.Empty; this.NextTextToShow = string.Empty; this.NeedsToResize = true; } private ArcenDoubleCharacterBuffer textBuffer = new ArcenDoubleCharacterBuffer(); public override void UpdateContentFromVolatile( ArcenUIWrapperedUnityImage Image, ArcenUI_Image.SubImageGroup _SubImages, SubTextGroup _SubTexts ) { if ( !this.GetShouldBeHidden() ) { textBuffer.EnsureResetForNextUpdate(); this.GetTextToRender( textBuffer ); string newText = textBuffer.GetStringAndResetForNextUpdate(); if ( newText == null ) newText = string.Empty; if ( newText != this.LastTextToShow ) { this.NextTextToShow = newText; this.NeedsToResize = true; } } Window_InGameHoverPlanetInfo.Instance.myXPositionScale = GameSettings.Current.GetFloatBySetting( "SidebarScale" ); this.SubTexts = _SubTexts; this.DoResizeIfNeeded(); } public override bool GetShouldBeHidden() { if ( Engine_AIW2.Instance.CurrentGameViewMode != GameViewMode.GalaxyMapView ) return true; if ( GameEntityTypeData.CurrentlyHoveredOver != null ) return true; if ( GameEntity_Base.CurrentlyHoveredOver != null ) return true; if ( Planet.CurrentlyHoveredOver == null && GalaxyMapPlanetLinkBase.CurrentlyHoveredOver == null ) return true; if ( InputCaching.CalculateShouldTooltipsBeSuppressed() ) return true; return false; } public void UpdateTextIfNeeded() { string nextText = this.WrappedNextTextToShow; if ( this.LastTextToShow.Length <= 0 && nextText.Length <= 0 ) { this.ClearMyself(); return; } try { if ( this.LastTextToShow != nextText ) { this.LastTextToShow = nextText; ArcenDoubleCharacterBuffer buffer = this.SubTexts[0].Text.StartWritingToBuffer(); buffer.Add( this.LastTextToShow ); this.SubTexts[0].Text.FinishWritingToBuffer(); this.NeedsToResize = true; this.DoResizeIfNeeded(); } } catch ( Exception e ) { ArcenDebugging.ArcenDebugLog( "Exception in UpdateContentFromVolatile for the single text element:" + e.ToString(), Verbosity.ShowAsError ); } } #region GetTextToRender public void GetTextToRender( ArcenDoubleCharacterBuffer buffer ) { if ( InputCaching.CalculateShouldTooltipsBeSuppressed() ) return; int debugStage = 0; try { IsDrawing = false; debugStage = 1; if ( Engine_AIW2.Instance.CurrentGameViewMode != GameViewMode.GalaxyMapView ) return; if ( Planet.CurrentlyHoveredOver == null && GalaxyMapPlanetLinkBase.CurrentlyHoveredOver == null ) return; if ( GameEntityTypeData.CurrentlyHoveredOver != null ) return; if ( GameEntity_Base.CurrentlyHoveredOver != null ) return; debugStage = 2; Planet relatedPlanet = Planet.CurrentlyHoveredOver; GalaxyMapPlanetLinkBase link = GalaxyMapPlanetLinkBase.CurrentlyHoveredOver; if ( relatedPlanet == null ) { if ( link != null ) { GetTextForPlanetLink( buffer, link ); return; } else { return; } } bool isShowingAbbreviatedVersion = !GameSettings.Current.GetBoolBySetting( "ShowShipAndPlanetDetailModeByDefault" ); if ( InputCaching.CalculateShouldToggleShipAndPlanetTooltipDetailMode() ) isShowingAbbreviatedVersion = !isShowingAbbreviatedVersion; IsDrawing = true; debugStage = 3; buffer.Add( "Planet " ); debugStage = 4; buffer.Add( relatedPlanet.Name ); buffer.Add( "" ); debugStage = 41; if ( relatedPlanet.IntelLevel <= PlanetIntelLevel.Unexplored ) { buffer.Add( ", Unexplored" ); buffer.Add( "\nWe have no vision of this planet. Either capture nearby planets or Hack this planet to gain vision. " ); buffer.Add(relatedPlanet.IntelLevel.ToString()); } else { if ( relatedPlanet.IntelLevel == PlanetIntelLevel.ExploredByNaturalMeans ) { int lastVisionTime = World_AIW2.Instance.GameSecond - relatedPlanet.GetGameSecondLastHadVision(); //Chris notes: hmm, if GetDoHumansHaveVision() gives true then this might be odd. We shall see. buffer.Add( "\nExplored: We are seeing old data for this planet; it was last viewed " ); buffer.Add( lastVisionTime ); buffer.Add( " seconds ago."); } else if ( relatedPlanet.IntelLevel == PlanetIntelLevel.ExploredByDistantHacking ) { int lastVisionTime = World_AIW2.Instance.GameSecond - relatedPlanet.GetGameSecondLastHadVision(); //Chris notes: hmm, if GetDoHumansHaveVision() gives true then this might be odd. We shall see. buffer.Add( "\nExplored By Spy Nanites: We are seeing old data for this planet; it was last explored by hacking " ); buffer.Add( lastVisionTime ); buffer.Add( " seconds ago." ); } if ( relatedPlanet.IntelLevel == PlanetIntelLevel.CurrentlyWatched) { buffer.Add( "\nWatched: We are seeing current data for this planet. " ); } if ( relatedPlanet.IntelLevel == PlanetIntelLevel.WatchedUntilReconquered) { if ( relatedPlanet.GetControllingFaction().Type == FactionType.AI ) buffer.Add( "\nWatched: We will see current data unless the loses and then reconquers this planet. " ); else buffer.Add( "\nWatched: We will see current data unless the AI reconquers this planet. " ); } if ( relatedPlanet.IntelLevel == PlanetIntelLevel.PermanentlyWatched) { buffer.Add( "\nPermanently Watched: We will always see current data for this planet. " ); } debugStage = 5; Faction owner = relatedPlanet.GetControllingFaction(); if ( owner.Type == FactionType.AI ) { buffer.Add( " (" ); relatedPlanet.MarkLevelForAIOnly.WriteStartColorHexTo( buffer ); buffer.Add( relatedPlanet.MarkLevelForAIOnly.Abbreviation ); relatedPlanet.MarkLevelForAIOnly.WriteEndColorHexTo( buffer ); buffer.Add( ")" ); } debugStage = 6; if ( owner.Type == FactionType.NaturalObject ) { if ( relatedPlanet.UnderInfluenceOfFactionIndex == -1 ) buffer.Add( " Neutral Territory" ); else { Faction influencer = World_AIW2.Instance.GetFactionByIndex(relatedPlanet.UnderInfluenceOfFactionIndex); buffer.Add(" Owned by "); buffer.Add( ""); buffer.Add( influencer.GetDisplayName() ); buffer.Add( "." ); } } else { buffer.Add( " Owned By " ); if ( owner.SpecialFactionData != null ) { buffer.Add( "" ); buffer.Add( owner.GetDisplayName() ); buffer.Add( "." ); } } debugStage = 7; Faction playerFaction = World_AIW2.Instance.GetLocalPlayerFaction(); PlanetFaction playerPlanetFaction = relatedPlanet.GetPlanetFactionForFaction( playerFaction ); if( playerPlanetFaction.AIPLeftFromControlling > FInt.Zero) buffer.Add(" Capturing this planet would cost ").Add( playerPlanetFaction.AIPLeftFromControlling.ToString(), "FF0000").Add( " AIP."); int threatStrengthInt, hostileStrengthMinusThreatInt, myTotalStrength, myMobileStrength, myAndAlliedTotalStrength, myAndAlliedMobileStrength; Faction hostileFaction; string myOrAlliedColor; string alliedColor; Window_InGameHoverPlanetInfo.GetPlanetFactionalData( relatedPlanet, out threatStrengthInt, out hostileStrengthMinusThreatInt, out myTotalStrength, out myMobileStrength, out myAndAlliedTotalStrength, out myAndAlliedMobileStrength, out myOrAlliedColor, out alliedColor, out hostileFaction, true ); //Player strength if ( myTotalStrength > 0 ) { buffer.StartColor( myOrAlliedColor ); buffer.Add( "\nYour Mobile Strength: " ); buffer.Add( ArcenExternalUIUtilities.StrengthTextIcon ); ArcenExternalUIUtilities.WriteRoundedNumberWithSuffix( buffer, myMobileStrength, true, true ); buffer.Add( "Your Immobile Strength: " ).Add( ArcenExternalUIUtilities.StrengthTextIcon ); ArcenExternalUIUtilities.WriteRoundedNumberWithSuffix( buffer, myTotalStrength - myMobileStrength, true, true ); buffer.EndColor(); } int alliedTotalStrength = myAndAlliedTotalStrength - myTotalStrength; int alliedMobileStrength = myAndAlliedMobileStrength - myMobileStrength; //Allied strength if ( alliedTotalStrength > 0 ) { buffer.StartColor( alliedColor ); buffer.Add( "\nAllied Mobile Strength: " ); buffer.Add( ArcenExternalUIUtilities.StrengthTextIcon ); ArcenExternalUIUtilities.WriteRoundedNumberWithSuffix( buffer, alliedMobileStrength, true, true ); buffer.Add( "Allied Immobile Strength: " ).Add( ArcenExternalUIUtilities.StrengthTextIcon ); ArcenExternalUIUtilities.WriteRoundedNumberWithSuffix( buffer, alliedTotalStrength - alliedMobileStrength, true, true ); buffer.EndColor(); } //hostile strength minus thread if ( hostileStrengthMinusThreatInt > 0 || threatStrengthInt > 0 ) { if ( hostileFaction != null ) buffer.StartColor( hostileFaction.TeamCenterColor.ColorHexBrighter ); else buffer.StartColor( "ffffff" ); buffer.Add( "\nEnemy Guard Strength: " ); buffer.Add( ArcenExternalUIUtilities.StrengthTextIcon ); ArcenExternalUIUtilities.WriteRoundedNumberWithSuffix( buffer, hostileStrengthMinusThreatInt, true, true ); if (! GameSettings.Current.GetBoolBySetting( "GalaxyMinimalFogOfWar" ) && relatedPlanet.IntelLevel < PlanetIntelLevel.CurrentlyWatched) buffer.Add("?"); buffer.Add( "Enemy Threat Strength: " ).Add( ArcenExternalUIUtilities.StrengthTextIcon ); ArcenExternalUIUtilities.WriteRoundedNumberWithSuffix( buffer, threatStrengthInt, true, true ); if (! GameSettings.Current.GetBoolBySetting( "GalaxyMinimalFogOfWar" ) && relatedPlanet.IntelLevel < PlanetIntelLevel.CurrentlyWatched) buffer.Add("?"); buffer.EndColor(); } debugStage = 71; if ( GameSettings.Current.GetBoolBySetting( "Debug_WriteCounterattackInfoInPlanetTooltips" ) ) { buffer.Add( "\nCounterattack Debug Info:" ) .Add( " Unspent Budget: " ).Add( relatedPlanet.AICounterattackUnspentBudget.ToFloatNonSim().ToString( "0.##" ) ) .Add( " Timer: " ).Add( relatedPlanet.AICountdownTimerForCounterattack ) .Add( " Would Be Stalled By: " ).Add( (relatedPlanet.AICounterattackToBeStalledByPlayerStrengthOf / 1000f).ToString( "0.000" ) ) .Add( " Player Strength Here: " ).Add( (relatedPlanet.PlayerStrengthHereForBlockingAICounterAttacks / 1000f).ToString( "0.000" ) ) .Add( " Stalled: " ).Add( relatedPlanet.AICounterAttacksCurrentlyStalled ? "yes" : "no" ) .Add( " Required To Send: " ).Add( (relatedPlanet.AIStrengthRequiredToSend / 1000f).ToString( "0.000" ) ) .Add( " Insufficient To Send: " ).Add( relatedPlanet.AICounterAttacksNotSufficientToTryToSend ? "yes" : "no" ) .Add( " Forces stored: " ).Add( (relatedPlanet.PrecalculatedAICounterattackForcesStrength / 1000f).ToString( "0.000" ) ) .Add( " Wave Normal: " ).Add( relatedPlanet.ShipGroup_WavesFromHere_Normal == null ? "null" : relatedPlanet.ShipGroup_WavesFromHere_Normal.InternalName ) .Add( " Wave Guardians: " ).Add( relatedPlanet.ShipGroup_WavesFromHere_Guardians == null ? "null" : relatedPlanet.ShipGroup_WavesFromHere_Guardians.InternalName ) .Add( " Wave Dire Guardians: " ).Add( relatedPlanet.ShipGroup_WavesFromHere_DireGuardians == null ? "null" : relatedPlanet.ShipGroup_WavesFromHere_DireGuardians.InternalName ) ; } debugStage = 8; for ( ResourceType resource = ResourceType.None + 1; resource < ResourceType.Length; resource++ ) { int resourceOutput = 0; string colorAndIcon = ""; switch ( resource ) { case ResourceType.Hacking: resourceOutput = relatedPlanet.GetHackingLeftForFaction( playerFaction.FactionIndex ).IntValue; if ( isShowingAbbreviatedVersion && resourceOutput <= 0 ) continue; colorAndIcon = ArcenExternalUIUtilities.HackingTextColorAndIcon; break; case ResourceType.Science: resourceOutput = relatedPlanet.GetScienceLeftForFaction( playerFaction.FactionIndex ).IntValue; if ( isShowingAbbreviatedVersion && resourceOutput <= 0 ) continue; colorAndIcon = ArcenExternalUIUtilities.ScienceTextColorAndIcon; break; case ResourceType.Energy: relatedPlanet.DoForEntities( EntityRollupType.EnergyProducers, delegate ( GameEntity_Squad entity ) { resourceOutput += entity.DataForMark.ResourceProduction[ResourceType.Energy].IntValue; return DelReturn.Continue; } ); if ( isShowingAbbreviatedVersion && ( playerPlanetFaction == relatedPlanet.GetControllingPlanetFaction() || resourceOutput <= 0 ) ) continue; colorAndIcon = ArcenExternalUIUtilities.EnergyTextColorAndIcon; break; case ResourceType.Metal: if ( isShowingAbbreviatedVersion && playerPlanetFaction == relatedPlanet.GetControllingPlanetFaction() ) continue; relatedPlanet.DoForEntities( EntityRollupType.MetalProducers, delegate ( GameEntity_Squad entity ) { resourceOutput += entity.DataForMark.ResourceProduction[ResourceType.Metal].IntValue; return DelReturn.Continue; } ); colorAndIcon = ArcenExternalUIUtilities.MetalTextColorAndIcon; break; } buffer.Add( "\n" ); buffer.Add( colorAndIcon ).Add( "" ).Add( resource.ToString() ).Add( ": " ).Add( "" ).Add( resourceOutput.ToString( "#,##0" ) ); } } debugStage = 30; { buffer.Add( "\n" ).Add( FontSizes.MUCH_SMALLER_SIZE_PLUS_A_TAD_STRING).Add( "Hold " ).Add( InputActionTypeDataTable.Instance.GetHumanReadableKeyComboForAction( "SuppressTooltips" ) ).Add( " to hide all tooltips. " ); buffer.Add( "Hold " ).Add( InputActionTypeDataTable.Instance.GetHumanReadableKeyComboForAction( "ToggleShipAndPlanetTooltipDetailMode" ) ); if ( isShowingAbbreviatedVersion ) buffer.Add( " to see a more-detailed tooltip." ); else buffer.Add( " to see a less-detailed tooltip." ); } } catch ( Exception e ) { ArcenDebugging.ArcenDebugLog( "Exception in planet tooltip text generation at stage " + debugStage + ":" + e.ToString(), Verbosity.ShowAsError ); } } private void GetTextForPlanetLink( ArcenDoubleCharacterBuffer buffer, GalaxyMapPlanetLinkBase link ) { Planet firstPlanet = link.PlanetOne; Planet secondPlanet = link.PlanetTwo; Planet aiPlanetOrNull; bool hasGate; GalaxyMapLinkUtils.DetectAiAndWarpGateAdjacencyToPlayer( firstPlanet, secondPlanet, out aiPlanetOrNull, out hasGate ); if ( aiPlanetOrNull != null ) { Planet humanPlanet = aiPlanetOrNull == secondPlanet ? firstPlanet : secondPlanet; Faction aiFaction = aiPlanetOrNull.GetControllingFaction(); string aiName = aiFaction.GetDisplayName(); var aiColor = aiFaction.TeamCenterColor.ColorHex; if ( hasGate ) { bool foundWavesAgainstThisPlanet = false; WaveUtils.DoForKnownWavesAgainstHumanHomeworlds( wave => { Planet targetPlanet = World_AIW2.Instance.GetPlanetByIndex( wave.targetPlanetIdx ); Planet sourcePlanet = World_AIW2.Instance.GetPlanetByIndex( wave.planetWithWarpGateIdx ); if ( targetPlanet == humanPlanet && sourcePlanet == aiPlanetOrNull ) { if ( !foundWavesAgainstThisPlanet ) { buffer.StartColor( Color.red ).Add( $"Incoming wave!" ).EndColor().NewLine(); } foundWavesAgainstThisPlanet = true; buffer.Add( wave.ToString() ).NewLine(); } return DelReturn.Continue; } ); if ( !foundWavesAgainstThisPlanet ) { buffer.StartColor( Color.yellow ).Add( $"Active {aiName} Warp Gate on {aiPlanetOrNull.Name}!" ).EndColor().NewLine(); buffer.Add( $"Possible {aiName} attack waves on planet {humanPlanet.Name} from wormhole {aiPlanetOrNull.Name}" ).NewLine(); } } else { buffer.Add( $"Destroyed {aiName} Warp Gate on {aiPlanetOrNull.Name}." ).NewLine(); buffer.Add( $"Attack waves on planet {humanPlanet.Name} from wormhole {aiPlanetOrNull.Name} are suppressed." ).NewLine(); } buffer.NewLine(); } buffer.StartColor( "aaaaaa" ).Add( $"Wormhole between planets {firstPlanet.Name} and {secondPlanet.Name}" ).EndColor(); } #endregion public override void OnMainThreadUpdate() { this.UpdatePositionAndSize(); } public void UpdatePositionAndSize() { //if ( this.GetShouldBeHidden() ) // return; if ( !this.hasSetCanvasOffset ) { if ( this.MyElement != null && this.MyElement.Window != null && this.MyElement.Window.Canvas ) { this.hasSetCanvasOffset = true; this.MyElement.Window.Canvas.sortingOrder = 32767; //as high as it will go, so this is always on top! } } try { float screenXPixel = 230 * (Window_InGameHoverEntityInfo.Instance == null ? 1f : Window_InGameHoverEntityInfo.Instance.myXPositionScale); float screenYPixel = 0; if ( this.MyElement != null && this.MyElement.Window != null ) this.MyElement.Window.IsAutomaticPositioningDisabled = true; Vector3 worldSpacePoint = ArcenUI.Instance.guiCamera.ScreenToWorldPoint( new Vector3( screenXPixel, screenYPixel, ArcenUI.POSITION_Z ) ); if ( Window_InGameSidebarShips.Instance != null ) worldSpacePoint.x = Window_InGameSidebarShips.Instance.GetWorldSpaceMaxX( 5f * (Window_InGameHoverEntityInfo.Instance == null ? 1f : Window_InGameHoverEntityInfo.Instance.myXPositionScale), false ); SubText groupZero = this.SubTexts[0]; if ( groupZero == null || groupZero.Obj == null || groupZero.Obj.transform == null || groupZero.Obj.transform.parent == null ) return; Vector2 sizeDelta = ((RectTransform)groupZero.Obj.transform.parent).GetWorldSpaceSize(); float width = sizeDelta.x; float height = sizeDelta.y; float maxXPixel = ArcenUI.Instance.world_BottomRight.x - width; float maxYPixel = ArcenUI.Instance.world_BottomRight.y + height; worldSpacePoint.x = Mathf.Min( worldSpacePoint.x, maxXPixel ); worldSpacePoint.y = Mathf.Max( worldSpacePoint.y, maxYPixel ); if ( this.MyElement != null && this.MyElement.Window != null && this.MyElement.Window.Canvas ) this.MyElement.Window.CanvasT.position = worldSpacePoint; } catch ( Exception ) { } //be silent on this, I guess } public override void SetElement( ArcenUI_Element Element ) { this.MyElement = (ArcenUI_ImageButton)Element; this.MyElement.Window.MaxDeltaTimeBeforeUpdates = 0; } public override void OnUpdate() { this.DoResizeIfNeeded(); base.OnUpdate(); } private float lastGeneralTooltipScale = 1f; private const int BASE_TOOLTIP_WIDTH = 600; public void DoResizeIfNeeded() { float newGeneralTooltipScale = GameSettings.Current.GetFloatBySetting( "PlanetTooltipScale" ); bool hasScaleMismatch = newGeneralTooltipScale != lastGeneralTooltipScale; if ( hasScaleMismatch ) this.NeedsToResize = true; if ( this.MyElement != null && this.NeedsToResize && this.SubTexts != null && this.SubTexts[1].Obj.activeInHierarchy && this.NextTextToShow != null && this.NextTextToShow.Length > 0 ) { this.NeedsToResize = false; this.lastGeneralTooltipScale = newGeneralTooltipScale; string text = this.NextTextToShow; if ( hasScaleMismatch ) { this.SubTexts[1].ReferenceText.rectTransform.UI_SetWidth( BASE_TOOLTIP_WIDTH / newGeneralTooltipScale ); this.SubTexts[0].Obj.transform.parent.localScale = new Vector3( newGeneralTooltipScale, newGeneralTooltipScale, newGeneralTooltipScale ); } Vector2 messageSize = Mat.V2_Zero; if ( text != null && text.Length > 0 ) messageSize = ArcenUI.Instance.CalculateSizeOfTextMeshProUGUIText( this.SubTexts[1].ReferenceText, ref text, 0f ); this.WrappedNextTextToShow = this.NextTextToShow;// text; float textInset = 6 * newGeneralTooltipScale; this.LastRequestedWidth = textInset + messageSize.x + textInset; this.LastRequestedHeight = textInset + messageSize.y + textInset; float referenceSideLength = 50 / newGeneralTooltipScale; float xScale = this.LastRequestedWidth / referenceSideLength; float yScale = this.LastRequestedHeight / referenceSideLength; ArcenUI_Image.SubImage subImage = this.MyElement.SubImages[0]; subImage.Img.rectTransform.sizeDelta = new Vector2( referenceSideLength * xScale, referenceSideLength * yScale ); this.UpdateTextIfNeeded(); this.UpdatePositionAndSize(); } } } #region GetPlanetFactionalData public static void GetPlanetFactionalData( Planet planet, out int threatStrengthInt, out int hostileStrengthMinusThreatInt, out int myTotalStrength, out int myMobileStrength, out int myAndAlliedTotalStrength, out int myAndAlliedMobileStrength, out string myOrAlliedColor, out string alliedColor, out Faction hostileFaction, bool IsForTooltips ) { PlanetFaction localFaction = planet.GetLocalPlayerFaction(); threatStrengthInt = 0; hostileStrengthMinusThreatInt = 0; hostileFaction = null; myOrAlliedColor = "ffffff"; alliedColor = "ffffff"; myTotalStrength = 0; myMobileStrength = 0; myAndAlliedTotalStrength = 0; myAndAlliedMobileStrength = 0; if ( planet.GetControllingFaction().Type == FactionType.Player ) threatStrengthInt = localFaction.DataByStance[FactionStance.Hostile].TotalStrengthVisible; //you have vision here since you own the planet else { if ( planet.IntelLevel <= PlanetIntelLevel.Unexplored ) return; if ( GameSettings.Current.GetBoolBySetting( "GalaxyMinimalFogOfWar" )) { //Show more detailed information, even if you can't really see it according to the rules threatStrengthInt = localFaction.DataByStance[FactionStance.Hostile].RelativeToHumanTeam_ThreatStrength; hostileStrengthMinusThreatInt = localFaction.DataByStance[FactionStance.Hostile].TotalStrength; } else { threatStrengthInt = localFaction.DataByStance[FactionStance.Hostile].RelativeToHumanTeam_ThreatStrengthVisible; hostileStrengthMinusThreatInt = localFaction.DataByStance[FactionStance.Hostile].TotalStrengthVisible; } hostileStrengthMinusThreatInt -= threatStrengthInt; } myTotalStrength = localFaction.DataByStance[FactionStance.Self].TotalStrength; myMobileStrength = localFaction.DataByStance[FactionStance.Self].MobileStrength; myAndAlliedTotalStrength = myTotalStrength + localFaction.DataByStance[FactionStance.Friendly].TotalStrength;; myAndAlliedMobileStrength = myMobileStrength + localFaction.DataByStance[FactionStance.Friendly].MobileStrength; if ( threatStrengthInt <= 0 && hostileStrengthMinusThreatInt <= 0 && myAndAlliedTotalStrength <= 0 && threatStrengthInt <= 0 ) return; if ( myTotalStrength > 0 ) myOrAlliedColor = localFaction.Faction.TeamCenterColor.GetColorHexBrighter( IsForTooltips ); if ( myAndAlliedTotalStrength > 0 ) { //calculate the strongest ally's color; if we have no strength here, also use that for "my" color int strongestAlliedStrength = 0; PlanetFaction alliedFaction; for ( int j = 0; j < planet.Factions.Count; j++ ) { alliedFaction = planet.Factions[j]; if ( !alliedFaction.GetIsFriendlyTowards( localFaction ) || alliedFaction == localFaction ) //don't count ourselves as an allied faction continue; if ( alliedFaction.DataByStance[FactionStance.Self].TotalStrength <= 0 ) continue; if ( alliedFaction.DataByStance[FactionStance.Self].TotalStrength > strongestAlliedStrength ) { alliedColor = alliedFaction.Faction.TeamCenterColor.GetColorHexBrighter( IsForTooltips ); strongestAlliedStrength = alliedFaction.DataByStance[FactionStance.Self].TotalStrength; if ( myTotalStrength == 0 ) myOrAlliedColor = alliedFaction.Faction.TeamCenterColor.GetColorHexBrighter( IsForTooltips ); } } } if ( hostileStrengthMinusThreatInt > 0 || threatStrengthInt > 0 ) { PlanetFaction enemyFaction; for ( int j = 0; j < planet.Factions.Count; j++ ) { enemyFaction = planet.Factions[j]; if ( !enemyFaction.GetIsHostileTowards( localFaction ) ) continue; if ( GameSettings.Current.GetBoolBySetting( "GalaxyMinimalFogOfWar" )) { if ( enemyFaction.DataByStance[FactionStance.Self].TotalStrength <= 0 ) continue; } else { if ( enemyFaction.DataByStance[FactionStance.Self].TotalStrengthVisible <= 0 ) continue; } if ( planet.GetControllingPlanetFaction() == enemyFaction ) { hostileFaction = enemyFaction.Faction; break; } if ( planet.UnderInfluenceOfFactionIndex != -1 ) { Faction influencer = World_AIW2.Instance.GetFactionByIndex(planet.UnderInfluenceOfFactionIndex); if ( planet.GetPlanetFactionForFaction(influencer) == enemyFaction ) { hostileFaction = influencer; break; } } } if ( hostileFaction == null ) { int strengthOfStrongestEnemy = 0; for ( int j = 0; j < planet.Factions.Count; j++ ) { enemyFaction = planet.Factions[j]; if ( !enemyFaction.GetIsHostileTowards( localFaction ) ) continue; int strengthToCheck = enemyFaction.DataByStance[FactionStance.Self].TotalStrengthVisible; if ( GameSettings.Current.GetBoolBySetting( "GalaxyMinimalFogOfWar" )) strengthToCheck = enemyFaction.DataByStance[FactionStance.Self].TotalStrength; if ( strengthToCheck < strengthOfStrongestEnemy ) continue; hostileFaction = enemyFaction.Faction; break; } } } } #endregion } }