/// <summary> /// Updates the Cyclops power index. This manages engine efficiency as well as the power cost of using Silent Running, Sonar, and Defense Shield. /// </summary> /// <param name="cyclops">The cyclops.</param> /// <param name="auxUpgradeConsoles">The aux upgrade consoles.</param> internal static void UpdatePowerSpeedRating(ref SubRoot cyclops, IList <AuxUpgradeConsole> auxUpgradeConsoles) { Equipment modules = cyclops.upgradeConsole.modules; int powerIndex = GetPowerIndex(modules, auxUpgradeConsoles); int speedIndex = GetSpeedIndex(modules, auxUpgradeConsoles); // Speed modules can affect power rating too float nextPowerRating = Mathf.Max(0.01f, EnginePowerRatings[powerIndex] - speedIndex * EnginePowerPenalty); if (LastKnownPowerRating != nextPowerRating) { cyclops.silentRunningPowerCost = SilentRunningPowerCosts[powerIndex]; cyclops.sonarPowerCost = SonarPowerCosts[powerIndex]; cyclops.shieldPowerCost = ShieldPowerCosts[powerIndex]; LastKnownPowerRating = nextPowerRating; cyclops.SetPrivateField("currPowerRating", nextPowerRating); // Inform the new power rating just like the original method would. ErrorMessage.AddMessage(Language.main.GetFormat("PowerRatingNowFormat", nextPowerRating)); } if (LastKnownSpeedIndex == -1) { // Store the original values before we start to change them // This will only run once var motorMode = cyclops.GetComponentInChildren <CyclopsMotorMode>(); OriginalSpeeds[0] = motorMode.motorModeSpeeds[0]; OriginalSpeeds[1] = motorMode.motorModeSpeeds[1]; OriginalSpeeds[2] = motorMode.motorModeSpeeds[2]; } if (speedIndex > SpeedIndexCount) { speedIndex = SpeedIndexCount; // Limit to Max ErrorMessage.AddMessage($"Speed rating already at maximum"); } if (LastKnownSpeedIndex != speedIndex) { float SlowMultiplier = 1f; float StandardMultiplier = 1f; float FlankMultiplier = 1f; // Calculate the speed multiplier with diminishing returns for (int s = 0; s < speedIndex; s++) { SlowMultiplier += SlowSpeedBonuses[s]; StandardMultiplier += StandardSpeedBonuses[s]; FlankMultiplier += FlankSpeedBonuses[s]; } // These will apply when changing speed modes var motorMode = cyclops.GetComponentInChildren <CyclopsMotorMode>(); motorMode.motorModeSpeeds[0] = OriginalSpeeds[0] * SlowMultiplier; motorMode.motorModeSpeeds[1] = OriginalSpeeds[1] * StandardMultiplier; motorMode.motorModeSpeeds[2] = OriginalSpeeds[2] * FlankMultiplier; // These will apply immediately var subControl = cyclops.GetComponentInChildren <SubControl>(); CyclopsMotorMode.CyclopsMotorModes currentMode = subControl.cyclopsMotorMode.cyclopsMotorMode; subControl.BaseForwardAccel = motorMode.motorModeSpeeds[(int)currentMode]; LastKnownSpeedIndex = speedIndex; ErrorMessage.AddMessage($"Speed rating is now at {(StandardMultiplier * 100):00}%"); if (speedIndex == SpeedIndexCount) { ErrorMessage.AddMessage($"Maximum speed rating reached"); } } }