private Vector2 CalculateMessageSize(ref string message) { if (this.SubTexts == null) { return(Vector2.zero); } TextMeshProUGUI text = this.SubTexts[1].ReferenceText; TMP_TextInfo info = text.GetTextInfo(message); buffer_CalculateMessageSize.EnsureResetForNextUpdate(); Vector2 result = Vector2.zero; int newLinesToSkip = 0; for (int i = 0; i < info.lineCount; i++) { TMP_LineInfo lineInfo = info.lineInfo[i]; float lineLength = lineInfo.maxAdvance + 20; // fudge factor because it always seems to sell itself a little short result.x = Mathf.Max(result.x, lineLength); result.y += lineInfo.lineHeight; if (i > 0) { if (lineInfo.length < 5) // empty lines tend to about 3.8 long, for some reason { newLinesToSkip = 2; } if (newLinesToSkip > 0) { newLinesToSkip--; } else { buffer_CalculateMessageSize.Add('\n'); } } ArcenCharacterBuffer debugBuffer = new ArcenCharacterBuffer(); for (int j = lineInfo.firstCharacterIndex; j <= lineInfo.lastCharacterIndex; j++) { debugBuffer.Add(message[j]); buffer_CalculateMessageSize.Add(message[j]); } } message = buffer_CalculateMessageSize.GetStringAndResetForNextUpdate(); return(result); }
protected static void LogCompareValues(ArcenCharacterBuffer debugBuffer, GameEntity Left, GameEntity Right, String fieldName, bool LeftWon, String leftValueString, String rightValueString) { GameEntity winner = LeftWon ? Left : Right; GameEntity loser = LeftWon ? Right : Left; ArcenCharacterBuffer buffer = debugBuffer; buffer.Add("\n\t") .Add("preferring ") .Add(winner.TypeData.InternalName) .Add(" to ") .Add(loser.TypeData.InternalName) .Add(" because ") .Add(fieldName) .Add(" is ") .Add(LeftWon ? leftValueString : rightValueString) .Add(" to ") .Add(LeftWon ? rightValueString : leftValueString); }
public virtual void DoPreSortLogic(EntitySystem Weapon, List <GameEntity> Targets, ArcenCharacterBuffer TracingBuffer, ArcenSimContext Context) { tracing = TracingBuffer != null; TargetSorter_Base.TracingBuffer = TracingBuffer; if (tracing) { TracingBuffer.Add("FindTarget:").Add(Weapon.ParentEntity.TypeData.InternalName).Add(" : ").Add(Weapon.TypeData.InternalName); } if (SniperRange == null) { SniperRange = Balance_RangeTable.Instance.GetRowByName("Sniper", false, null); LongRange = Balance_RangeTable.Instance.GetRowByName("Long", false, null); MediumRange = Balance_RangeTable.Instance.GetRowByName("Medium", false, null); ShortRange = Balance_RangeTable.Instance.GetRowByName("Short", false, null); ShieldDefense = Balance_DefenseTable.Instance.GetRowByName("Shields", false, null); StructureDefense = Balance_DefenseTable.Instance.GetRowByName("Structure", false, null); } }
public Planet GetCurrentTargetPlanet(ArcenSimContext Context, GameEntity hideout, List <GameEntity> hideoutFleet) { #region Tracing bool tracing = SpecialForcesPlanning.tracing; ArcenCharacterBuffer tracingBuffer = SpecialForcesPlanning.tracingBuffer; #endregion Planet hideoutPlanet = World_AIW2.Instance.GetPlanetByIndex(hideout.LongRangePlanningData.CurrentPlanetIndex); Planet currentTargetPlanet = World_AIW2.Instance.GetPlanetByIndex(hideout.LongRangePlanningData.SpecialTargetPlanetIndex); FInt hideoutFleetStrength = FInt.Zero; hideoutFleet.Clear(); for (int i = 0; i < hideoutFleet.Count; i++) { GameEntity entity = hideoutFleet[i]; if (entity.LongRangePlanningData.CoordinatorID != hideout.PrimaryKeyID) { continue; } hideoutFleet.Add(entity); hideoutFleetStrength += entity.TypeData.BalanceStats.StrengthPerSquad + entity.LongRangePlanningData.StrengthOfContents; } #region Tracing if (tracing) { tracingBuffer.Add("\n").Add("SpecialForcesRouting considering hideout on ").Add(hideoutPlanet.Name).Add("; fleet strength = ").Add(hideoutFleetStrength.ReadableString); } #endregion bestTargetFound_Index = -1; bestTargetFound_Danger = FInt.Zero; hideoutPlanet.DoForPlanetsWithinXHops(Context, 3, delegate(Planet planet, int Distance) { FInt danger = planet.LongRangePlanningData.HumanTotalStrength - planet.LongRangePlanningData.AITotalStrength; if (danger < FInt.Zero && -danger < planet.LongRangePlanningData.AITotalStrength / 2) { #region Tracing if (tracing) { tracingBuffer.Add("\n").Add("rejecting target ").Add(planet.Name).Add(" because danger too low: ").Add(danger.ReadableString); } #endregion return(DelReturn.Continue); } if (bestTargetFound_Index >= 0 && bestTargetFound_Danger >= danger) { #region Tracing if (tracing) { tracingBuffer.Add("\n").Add("rejecting target ").Add(planet.Name).Add(" because danger lower than current best target: ").Add(danger.ReadableString); } #endregion return(DelReturn.Continue); } #region Tracing if (tracing) { tracingBuffer.Add("\n").Add("current best target = ").Add(planet.Name).Add("; danger: ").Add(danger.ReadableString); } #endregion bestTargetFound_Index = planet.PlanetIndex; bestTargetFound_Danger = danger; return(DelReturn.Continue); }, delegate(Planet planet) { if (planet.LongRangePlanningData.ControllingSide.Type != hideout.LongRangePlanningData.Side.WorldSide.Type) { #region Tracing if (tracing) { tracingBuffer.Add("\n").Add("Refusing to flood into ").Add(planet.Name).Add(" because not controlled by same side"); } #endregion return(PropogationEvaluation.No); } FInt danger = planet.LongRangePlanningData.HumanTotalStrength - planet.LongRangePlanningData.AITotalStrength; if (danger >= hideoutFleetStrength * 2) { #region Tracing if (tracing) { tracingBuffer.Add("\n").Add("Refusing to flood into ").Add(planet.Name).Add(" because too much danger: ").Add(danger.ReadableString); } #endregion return(PropogationEvaluation.No); } if (danger >= hideoutFleetStrength * 1) { #region Tracing if (tracing) { tracingBuffer.Add("\n").Add("Refusing to flood through ").Add(planet.Name).Add(" because too much danger: ").Add(danger.ReadableString); } #endregion return(PropogationEvaluation.SelfButNotNeighbors); } return(PropogationEvaluation.Yes); }); FInt currentTargetPlanetDanger = currentTargetPlanet.LongRangePlanningData.HumanTotalStrength - currentTargetPlanet.LongRangePlanningData.AITotalStrength; if (bestTargetFound_Index < 0 || bestTargetFound_Danger <= (currentTargetPlanetDanger * 2)) { bestTargetFound_Index = currentTargetPlanet.PlanetIndex; bestTargetFound_Danger = currentTargetPlanetDanger; } return(World_AIW2.Instance.GetPlanetByIndex(bestTargetFound_Index)); }
public void Sort(EntitySystem Weapon, List <GameEntity> Targets, ArcenCharacterBuffer TracingBuffer) { tracing = TracingBuffer != null; TargetSorterBase.TracingBuffer = TracingBuffer; if (tracing) { TracingBuffer.Add("FindTarget:").Add(Weapon.ParentEntity.TypeData.InternalName).Add(" : ").Add(Weapon.TypeData.InternalName); } for (int i = 0; i < Targets.Count; i++) { GameEntity entity = Targets[i]; entity.Working_FindTargetOnly_Distance = Weapon.ParentEntity.GetDistanceTo(entity, false); AssignShotsToKillData(Weapon, entity); if (tracing) { if (entity.Working_FindTargetOnly_DebugBuffer == null) { entity.Working_FindTargetOnly_DebugBuffer = new ArcenCharacterBuffer(); } entity.Working_FindTargetOnly_DebugBuffer.Clear(); } } Comparison <GameEntity> comparisonDelegate = DelegateHelper_FindTarget_Comparison; GameEntity champion = Targets[0]; if (tracing) { TracingBuffer.Add("\n\t").Add("starting with first item: ").Add(champion.TypeData.InternalName); } int championIndex = 0; for (int i = 1; i < Targets.Count; i++) { GameEntity challenger = Targets[i]; if (comparisonDelegate(champion, challenger) <= 0) { continue; } champion = challenger; championIndex = i; } if (championIndex != 0) { GameEntity temp = Targets[0]; Targets[0] = champion; Targets[championIndex] = temp; } //this.WorkingEntityList_GetTarget.Sort( comparisonDelegate ); //GameEntity result = this.WorkingEntityList_GetTarget[0]; //if ( debugging ) //{ // for ( int i = 0; i < this.WorkingEntityList_GetTarget.Count; i++ ) // { // GameEntity entity = this.WorkingEntityList_GetTarget[i]; // debugBuffer.Add( "\n" ) // .Add( i ) // .Add( ":" ) // .Add( entity.TypeData.InternalName ) // .Add( "\t" ) // .Add( entity.Working_FindTargetOnly_DebugBuffer.ToString() ); // } //} }
public override void UpdateContent(ArcenUIWrapperedUnityImage Image, ArcenUI_Image.SubImageGroup _SubImages, SubTextGroup _SubTexts) { this.SubImages = _SubImages; this.SubTexts = _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 ); if (GameEntity.CurrentlyHoveredOver != null) { this.PanelMode = Mode.ActualUnit; } else if (Window_InGameTechTabMenu.Instance.IsOpen) { this.PanelMode = Mode.Tech; } else if (Window_InGameBuildTabMenu.Instance.IsOpen) { this.PanelMode = Mode.Build; } TextId.SubjectSummary.Set(typeData.Name, string.Empty); try { int markLevel = typeData.Balance_MarkLevel == null ? 0 : typeData.Balance_MarkLevel.Ordinal; if (markLevel <= 0) { ImageId.MarkLevel.Hide(); } else { ImageId.MarkLevel.Set(Window_InGameOutlineSidebar.Sprite_MarkLevels[markLevel], string.Empty); } if (this.PanelMode == Mode.Tech && typeData.TechPrereq != null) { bool unlocked = localSide.GetHasResearched(typeData.TechPrereq); ImageId.Locked.ChangeVisibility(!unlocked); ImageId.Unlocked.ChangeVisibility(unlocked); ImageId.Science.Show(); TextId.Science.Set(typeData.TechPrereq.ScienceCost, string.Empty); } else { ImageId.Locked.Hide(); ImageId.Unlocked.Hide(); ImageId.Science.Hide(); TextId.Science.Hide(); } if (typeData.BalanceStats.SquadFuelConsumption > 0) { ImageId.Fuel.Show(); ImageId.Power.Hide(); TextId.FuelOrPower.Set(typeData.BalanceStats.SquadFuelConsumption, string.Empty); } else if (typeData.BalanceStats.SquadPowerConsumption > 0) { ImageId.Fuel.Hide(); ImageId.Power.Show(); TextId.FuelOrPower.Set(typeData.BalanceStats.SquadPowerConsumption, string.Empty); } else { ImageId.Fuel.Hide(); ImageId.Power.Hide(); TextId.FuelOrPower.Hide(); } if (typeData.BalanceStats.SquadMetalCost > 0) { ImageId.Metal.Show(); TextId.Metal.Set(typeData.BalanceStats.SquadMetalCost, string.Empty); } else { ImageId.Metal.Hide(); TextId.Metal.Hide(); } int cap = typeData.BalanceStats.SquadsPerCap; if (cap <= 0) { ImageId.Cap.Hide(); TextId.Cap.Hide(); } else { ImageId.Cap.Show(); TextId.Cap.Set(cap, string.Empty); } ImageId.Strength.Show(); TextId.Strength.Set(typeData.BalanceStats.StrengthPerSquad.IntValue, string.Empty); SystemEntry.SubEntry mainOffensiveWeaponSystemSubEntry = null; EntitySystemTypeData cloakSystem = null; EntitySystemTypeData tachyonSystem = null; EntitySystemTypeData tractorSystem = null; EntitySystemTypeData gravitySystem = null; for (int i = 0; i < typeData.SystemEntries.Count; i++) { SystemEntry entry = typeData.SystemEntries[i]; if (entry.SubEntries.Count <= 0) { continue; } SystemEntry.SubEntry subEntry = entry.SubEntries[0]; if (mainOffensiveWeaponSystemSubEntry == null && subEntry.GetDPS() > 0) { mainOffensiveWeaponSystemSubEntry = subEntry; } EntitySystemTypeData systemData = subEntry.SystemData; if (cloakSystem == null && subEntry.BalanceStats.SquadCloakingPoints > 0) { cloakSystem = systemData; } if (tachyonSystem == null && subEntry.BalanceStats.TachyonPoints > 0) { tachyonSystem = systemData; } if (tractorSystem == null && subEntry.BalanceStats.TractorPoints > 0) { tractorSystem = systemData; } if (gravitySystem == null && subEntry.BalanceStats.GravityPoints > 0) { gravitySystem = systemData; } } if (mainOffensiveWeaponSystemSubEntry != null) { SystemEntry.SubEntry systemSubEntry = mainOffensiveWeaponSystemSubEntry; EntitySystemTypeData systemData = systemSubEntry.SystemData; Balance_WeaponType weaponData = systemData.Balance_WeaponType; ImageId.Attack.Set(systemData.Balance_WeaponType.CounterType); TextId.Attack.Set(systemSubEntry.GetDPS().IntValue, systemData.Balance_WeaponType.CounterType.StatTooltip); ImageId.Range.Set(weaponData.Range); ImageId.EngineDamage.Set(weaponData.Balance_EngineDamageType); ImageId.Paralysis.Set(weaponData.Balance_ParalysisClass); ImageId.Ion.Set(weaponData.Balance_IonClass); ImageId.Implosion.Set(weaponData.Balance_ImplosionClass); ImageId.Nuclear.Set(systemData.Balance_NuclearClass); } else { ImageId.Attack.Hide(); TextId.Attack.Hide(); ImageId.Range.Hide(); ImageId.EngineDamage.Hide(); ImageId.Paralysis.Hide(); ImageId.Ion.Hide(); ImageId.Implosion.Hide(); ImageId.Nuclear.Hide(); } ImageId.Defense.Set(typeData.Balance_Defense); int totalMaxHP = (typeData.BalanceStats.HullPoints + typeData.BalanceStats.ShieldPoints) * typeData.Balance_ShipsPerSquad; GameEntity entity = GameEntity.CurrentlyHoveredOver; if (this.PanelMode == Mode.ActualUnit && entity != null && (entity.HullPointsLost > 0 || entity.ShieldPointsLost > 0 || entity.SquadShipsLost > 0 || entity.SelfBuildingMetalRemaining > 0)) { float percent; if (entity.SelfBuildingMetalRemaining <= 0) { int totalCurrentHP = (typeData.BalanceStats.HullPoints + typeData.BalanceStats.ShieldPoints) * (typeData.Balance_ShipsPerSquad - 1); totalCurrentHP += (entity.GetCurrentHullPoints() + entity.GetCurrentShieldPoints()); percent = ((float)totalCurrentHP / (float)totalMaxHP) * 100; } else { percent = (1f - ((float)entity.SelfBuildingMetalRemaining / (float)typeData.BalanceStats.SquadMetalCost)) * 100; } string percentMask; if (entity.SelfBuildingMetalRemaining > 0 || entity.HasNotYetBeenFullyClaimed) { percentMask = "#,##0.0"; } else { percentMask = "#,##0"; } int totalHPForDisplay = totalMaxHP; string suffix = ArcenExternalUIUtilities.GetRoundedNumberWithSuffix(ref totalHPForDisplay, true); ArcenCharacterBuffer textBuffer = new ArcenCharacterBuffer(); textBuffer.Add(totalHPForDisplay.ToString("#,##0")); textBuffer.Add(suffix); textBuffer.Add(" ("); textBuffer.Add(percent.ToString(percentMask)); textBuffer.Add("%)"); string text = textBuffer.ToString(); TextId.Defense.Set(text, typeData.Balance_Defense.StatTooltip); } else { TextId.Defense.Set(totalMaxHP, typeData.Balance_Defense.StatTooltip); } ImageId.Speed.Set(typeData.Balance_Speed); ImageId.EngineDamageResistance.Set(typeData.Balance_EngineHealthType); ImageId.ParalysisResistance.Set(typeData.Balance_ParalysisResistance); ImageId.IonResistance.Set(typeData.Balance_IonResistance); ImageId.ImplosionResistance.Set(typeData.Balance_ImplosionResistance); ImageId.NuclearResistance.Set(typeData.Balance_NuclearResistance); ImageId.Cloak.Set(cloakSystem == null ? null : cloakSystem.Balance_CloakingType); ImageId.Tachyon.Set(tachyonSystem == null ? null : tachyonSystem.Balance_TachyonType); ImageId.Tractor.Set(tractorSystem == null ? null : tractorSystem.Balance_TractorType); ImageId.TractorResistance.Set(typeData.Balance_TractorResistanceType); ImageId.Gravity.Set(gravitySystem == null ? null : gravitySystem.Balance_GravityType); ImageId.GravityResistance.Set(typeData.Balance_GravityResistanceType); TextId.Description.Set(typeData.Description, string.Empty); } catch (Exception e) { ArcenDebugging.ArcenDebugLog("Exception in UpdateContent after " + (LastWrittenWasImageInsteadOfText ? "image " + LastImageIDWritten : "text " + LastTextIDWritten) + ":" + e.ToString(), Verbosity.ShowAsError); } }