public static void LinkageActivate(this MechComponent component, bool isInital) { ActivatableComponent activatable = component.componentDef.GetComponent <ActivatableComponent>(); if (activatable == null) { return; } Log.Debug?.TWL(0, "LinkageActivate " + component.defId); foreach (string toActivateBtn in activatable.Linkage.OnActivate.Activate) { Log.Debug?.WL(1, "searching " + toActivateBtn); foreach (MechComponent CompToActivate in component.parent.allComponents) { ActivatableComponent tactivatable = CompToActivate.componentDef.GetComponent <ActivatableComponent>(); if (tactivatable == null) { continue; } //if (tactivatable.CanBeactivatedManualy == false) { continue; }; if (tactivatable.ButtonName != toActivateBtn) { continue; } if (ActivatableComponent.isComponentActivated(CompToActivate) == true) { continue; } ; ActivatableComponent.activateComponent(CompToActivate, true, isInital); } } foreach (string toActivateBtn in activatable.Linkage.OnActivate.Deactivate) { foreach (MechComponent CompToDeactivate in component.parent.allComponents) { ActivatableComponent tactivatable = CompToDeactivate.componentDef.GetComponent <ActivatableComponent>(); if (tactivatable == null) { continue; } //if (tactivatable.CanBeactivatedManualy == false) { continue; }; if (tactivatable.ButtonName != toActivateBtn) { continue; } if (ActivatableComponent.isComponentActivated(CompToDeactivate) == false) { continue; } ; ActivatableComponent.deactivateComponent(CompToDeactivate); } } }
public static bool isActive(this MechComponent component) { return(ActivatableComponent.isComponentActivated(component)); }
public static void AIActivatableProc(AbstractActor unit) { try { if (unit.IsDead) { return; } if (unit.TeamId == unit.Combat.LocalPlayerTeamGuid) { Log.Debug?.Write(" not AI\n"); return; } HashSet <MechComponent> extreamlyUsefull = new HashSet <MechComponent>(); HashSet <MechComponent> Usefull = new HashSet <MechComponent>(); var AITime = System.Diagnostics.Stopwatch.StartNew(); // the code that you want to measure comes here var elapsedMs = AITime.ElapsedMilliseconds; int isVisibleTargets = 0; float offenceCoeff = 0f; float deffenceCoeff = 0f; unit.TargetsCalc(ref isVisibleTargets, ref offenceCoeff, ref deffenceCoeff); Mech mech = unit as Mech; float heatCoeff = 0f; float overheatCoeff = 0f; if (mech != null) { heatCoeff = mech.CurrentHeat / mech.OverheatLevel; overheatCoeff = mech.CurrentHeatAsRatio; } Log.Debug?.Write("AI activatable coeffs:" + unit.DisplayName + ":" + unit.GUID + "\n"); Log.Debug?.Write(" visible targets:" + isVisibleTargets + "\n"); Log.Debug?.Write(" offenceCoeff:" + offenceCoeff + "\n"); Log.Debug?.Write(" deffenceCoeff:" + deffenceCoeff + "\n"); Log.Debug?.Write(" heatCoeff:" + heatCoeff + "\n"); Log.Debug?.Write(" overheatCoeff:" + overheatCoeff + "\n"); bool isAnyLocationExposed = unit.IsAnyStructureExposed; Log.Debug?.Write(" isAnyLocationExposed:" + isAnyLocationExposed + "\n"); Log.Debug?.Write("Components:\n"); foreach (MechComponent component in unit.allComponents) { Log.Debug?.Write(" " + component.defId + "\n"); if (component.CanBeActivated() == false) { Log.Debug?.Write(" can't be activated\n"); continue; } ; if (component.isSensors()) { Log.Debug?.Write(" sensors\n"); if (isVisibleTargets == 0) { if (isAnyLocationExposed == false) { Log.Debug?.Write(" no visible targets. Sensors are extreamly usefull to detect them\n"); extreamlyUsefull.Add(component); } } else if (isVisibleTargets < 2) { if (isAnyLocationExposed == false) { Log.Debug?.Write(" low visible visible targets count. Sensors are usefull to detect additional targets\n"); Usefull.Add(component); } } } if (component.isCool()) { if (heatCoeff > Core.Settings.AIHeatCoeffCoeff) { Log.Debug?.Write(" cooling component and i'm heated. Usefull\n"); Usefull.Add(component); } if (overheatCoeff > Core.Settings.AIOverheatCoeffCoeff) { Log.Debug?.Write(" cooling component and i'm close to overheat. Very usefull\n"); extreamlyUsefull.Add(component); } } if (component.isSpeed()) { if (isAnyLocationExposed) { Log.Debug?.Write(" speed and i'm damaged. Need to flee. Very usefull\n"); extreamlyUsefull.Add(component); } else if (isVisibleTargets == 0) { Log.Debug?.Write(" speed and no visible targets. Need to find usefull\n"); Usefull.Add(component); } } if (component.isOffence()) { if ((isVisibleTargets > 1) && (isAnyLocationExposed)) { Log.Debug?.Write(" offence and i see target and damaged. Very usefull\n"); extreamlyUsefull.Add(component); } else if (offenceCoeff > Core.Settings.AIOffenceUsefullCoeff) { Log.Debug?.Write(" offence and i can make much damage. Very usefull\n"); extreamlyUsefull.Add(component); } else if (offenceCoeff > Core.Epsilon) { Log.Debug?.Write(" offence and i can make some damage. Usefull\n"); Usefull.Add(component); } } if (component.isDefence()) { if ((isVisibleTargets > 1) && (isAnyLocationExposed)) { Log.Debug?.Write(" defence and i see target and damaged. Very usefull\n"); extreamlyUsefull.Add(component); } else if (deffenceCoeff > Core.Settings.AIDefenceUsefullCoeff) { Log.Debug?.Write(" defence and i can suffer much damage. Very usefull\n"); extreamlyUsefull.Add(component); } else if (deffenceCoeff > Core.Epsilon) { Log.Debug?.Write(" defence and i suffer make some damage. Usefull\n"); Usefull.Add(component); } } } HashSet <MechComponent> stepDownComponents = new HashSet <MechComponent>(); foreach (MechComponent component in extreamlyUsefull) { if (component.isHeat()) { if (heatCoeff > Core.Settings.AIHeatCoeffCoeff) { Log.Debug?.Write(component.defId + " very usefull. But i'm heated\n"); stepDownComponents.Add(component); } else if (overheatCoeff > Core.Settings.AIOverheatCoeffCoeff) { Log.Debug?.Write(component.defId + " very usefull. But i'm overheated\n"); stepDownComponents.Add(component); } } } foreach (MechComponent component in stepDownComponents) { extreamlyUsefull.Remove(component); Usefull.Add(component); } Log.Debug?.Write("Activation:\n"); foreach (MechComponent component in unit.allComponents) { Log.Debug?.Write(" " + component.defId + "\n"); bool needToBeActivated = false; if (extreamlyUsefull.Contains(component)) { Log.Debug?.Write(" very usefull\n"); if (component.isFailDanger() == false) { Log.Debug?.Write(" not danger\n"); needToBeActivated = true; } else { Log.Debug?.Write(" FailChance:" + component.FailChance() + "\n"); if ((component.isDamaged() == false) || (isAnyLocationExposed == true)) { if (component.FailChance() < Core.Settings.AIComponentExtreamlyUsefulModifyer) { needToBeActivated = true; Log.Debug?.Write(" not big danger. Can be activated\n"); } } else { Log.Debug?.Write(" component is damaged and have no exposed locations. Danger level increase\n"); if (component.FailChance() < Core.Settings.AIComponentUsefullModifyer) { needToBeActivated = true; Log.Debug?.Write(" not big danger. Can be activated\n"); } } } } if (Usefull.Contains(component)) { Log.Debug?.Write(" usefull\n"); if (component.isFailDanger() == false) { Log.Debug?.Write(" not danger\n"); needToBeActivated = true; } else { Log.Debug?.Write(" FailChance:" + component.FailChance() + "\n"); if ((component.isDamaged() == false) || (isAnyLocationExposed == true)) { if (component.FailChance() < Core.Settings.AIComponentUsefullModifyer) { needToBeActivated = true; Log.Debug?.Write(" not big danger. Can be activated\n"); } } else { Log.Debug?.Write(" component is damaged and have no exposed locations. Danger level increase will not activate.\n"); } } } if (needToBeActivated) { if (ActivatableComponent.isComponentActivated(component)) { Log.Debug?.Write(" already active\n"); if (unit.AICheatRoll()) { bool isSuccess = ActivatableComponent.rollFail(component, false, true); if (isSuccess == false) { Log.Debug?.Write(" deactivating due to high possible fail\n"); ActivatableComponent.deactivateComponent(component); } else { component.setAIRollPassed(true); } } } else { Log.Debug?.Write(" activating\n"); if (unit.AICheatRoll()) { bool isSuccess = ActivatableComponent.rollFail(component, false, true); if (isSuccess == false) { Log.Debug?.Write(" not activate due to high possible fail\n"); } else { component.setAIRollPassed(true); ActivatableComponent.activateComponent(component, false, false); } } else { ActivatableComponent.activateComponent(component, false, false); } } } else { if (ActivatableComponent.isComponentActivated(component)) { Log.Debug?.Write(" not active\n"); } else { Log.Debug?.Write(" deactivating\n"); ActivatableComponent.deactivateComponent(component); } } } AITime.Stop(); Log.Debug?.Write("AI activatable time:" + AITime.ElapsedMilliseconds + " msec\n"); } catch (Exception e) { Log.WriteCritical("AI activatable exception:" + e.ToString() + "\n"); } }
public string BuildText() { StringBuilder builder = new StringBuilder(); for (int index = 0; index < components.Count; ++index) { if (index != 0) { builder.Append("\n"); } ; if (index == SelectedComponent) { builder.Append("->"); } MechComponent component = components[index]; builder.Append(component.UIName); if (component.IsFunctional == false) { builder.Append(" !__/CAE.NonFunctional/__!"); continue; } if (component.DamageLevel >= ComponentDamageLevel.Penalized) { builder.Append(" !__/CAE.Damaged/__!"); } if (ActivatableComponent.isOutOfCharges(components[index])) { builder.Append(" !__/CAE.OutOfCharges/__!"); continue; } ActivatableComponent activatable = component.componentDef.GetComponent <ActivatableComponent>(); if (activatable.ChargesCount != 0) { if (activatable.ChargesCount > 0) { builder.Append(" __/CAE.CHARGES/__:" + ActivatableComponent.getChargesCount(component)); } } if (ActivatableComponent.isComponentActivated(component)) { builder.Append(" " + activatable.ActivationMessage + " "); if (activatable.CanBeactivatedManualy == false) { if (component.parent is Mech) { float neededHeat = (activatable.AutoDeactivateOverheatLevel > CustomActivatableEquipment.Core.Epsilon) ? activatable.AutoDeactivateOverheatLevel * (float)(component.parent as Mech).OverheatLevel : activatable.AutoDeactivateOnHeat; builder.Append("__/CAE.HEAT/__:" + (component.parent as Mech).CurrentHeat + "/" + neededHeat); } } } else { builder.Append(" " + activatable.DeactivationMessage + " "); if (activatable.AutoActivateOnHeat > CustomActivatableEquipment.Core.Epsilon) { if (component.parent is Mech) { float neededHeat = (activatable.AutoActivateOnOverheatLevel > CustomActivatableEquipment.Core.Epsilon) ? activatable.AutoActivateOnOverheatLevel * (float)(component.parent as Mech).OverheatLevel : activatable.AutoActivateOnHeat; builder.Append("__/CAE.HEAT/__:" + (component.parent as Mech).CurrentHeat + "/" + neededHeat); } } } float failChance = ActivatableComponent.getEffectiveComponentFailChance(component); if (failChance > Core.Epsilon) { builder.Append(" __/CAE.FAIL/__:" + Math.Round(failChance * 100f) + "%"); } } return(builder.ToString()); }