diff --git a/Languages/English/Keyed/Keys.xml b/Languages/English/Keyed/Keys.xml index aff76fb..9161c93 100644 --- a/Languages/English/Keyed/Keys.xml +++ b/Languages/English/Keyed/Keys.xml @@ -5,6 +5,8 @@ on off enabled +active +not active turn name power @@ -86,4 +88,8 @@ Change power level Current power level: {0}% speed, uses {1} watts.\nChange in power level only takes effect once the current alloy is completed. + +Change power level +Current power level: {0}%, consumes {1} canisters per day. + \ No newline at end of file diff --git a/Source/AntimatterAnnihilation/Buildings/Building_AntimatterReactor.cs b/Source/AntimatterAnnihilation/Buildings/Building_AntimatterReactor.cs index 82651fc..7f953ff 100644 --- a/Source/AntimatterAnnihilation/Buildings/Building_AntimatterReactor.cs +++ b/Source/AntimatterAnnihilation/Buildings/Building_AntimatterReactor.cs @@ -68,9 +68,9 @@ public bool IsHorizontal public float BuildingDamage = 25; public float PawnDamage = 6.5f; public int UpdateInterval = 20; // Every 20 ticks, so 3 times a second. + public Building_ReactorInjector CurrentInjector { get; private set; } private List<(IntVec3 cell, byte weight)> avoidance = new List<(IntVec3 cell, byte weight)>(); - private Building_ReactorInjector currentInjector; private int injectorRot; private int tickCounter; private long updateTick; @@ -155,13 +155,13 @@ public void RegisterInput(Building_ReactorInjector injector, int injRot) // Assumes that the injector is valid (correct side, aligned properly). tickCounter = 0; - if (currentInjector != null && currentInjector != injector) + if (CurrentInjector != null && CurrentInjector != injector) { // Two injectors?! // TODO handle (explode?) } - currentInjector = injector; + CurrentInjector = injector; this.injectorRot = injRot; tickCounter = 0; if (!IsRunning) @@ -173,10 +173,10 @@ public void RegisterInput(Building_ReactorInjector injector, int injRot) public void RemoveInput(Building_ReactorInjector injector) { - if (currentInjector != injector) + if (CurrentInjector != injector) return; - currentInjector = null; + CurrentInjector = null; if (IsRunning) { @@ -189,14 +189,14 @@ public override void Tick() { base.Tick(); - if(tickCounter < TicksToShutdownWithNoInput && currentInjector != null) + if(tickCounter < TicksToShutdownWithNoInput && CurrentInjector != null) tickCounter++; - if (tickCounter == TicksToShutdownWithNoInput) + if (tickCounter >= TicksToShutdownWithNoInput) { if (IsRunning) { IsRunning = false; - currentInjector = null; + CurrentInjector = null; CauseRedraw(); } } diff --git a/Source/AntimatterAnnihilation/Buildings/Building_PowerConverter.cs b/Source/AntimatterAnnihilation/Buildings/Building_PowerConverter.cs index 7dadc1f..3719bce 100644 --- a/Source/AntimatterAnnihilation/Buildings/Building_PowerConverter.cs +++ b/Source/AntimatterAnnihilation/Buildings/Building_PowerConverter.cs @@ -6,6 +6,19 @@ namespace AntimatterAnnihilation.Buildings [StaticConstructorOnStartup] public class Building_PowerConverter : Building { + public static float BasePowerOutput = 30000; + public static float PowerOutputMulti { get; set; } = 1f; + + private float PowerOutput + { + get + { + float reactorMulti = this.CurrentReactor?.CurrentInjector?.PowerOutputMultiplier ?? 1f; + + return BasePowerOutput * PowerOutputMulti * reactorMulti; + } + } + private static Graphic normal, running; private const int MAX_TICKS_SINCE_INPUT = 30; @@ -38,34 +51,43 @@ public bool HasInput return ticksSinceHasInput < MAX_TICKS_SINCE_INPUT; } } + public Building_AntimatterReactor CurrentReactor { get; private set; } private int ticksSinceHasInput; public override void Tick() { + if (CurrentReactor != null && CurrentReactor.Destroyed) + CurrentReactor = null; + if (ticksSinceHasInput < MAX_TICKS_SINCE_INPUT) { ticksSinceHasInput++; } - else if (ticksSinceHasInput != 69420) + else { - ticksSinceHasInput = 69420; - CauseRedraw(); + CurrentReactor = null; + if (ticksSinceHasInput != 69420) + { + ticksSinceHasInput = 69420; + CauseRedraw(); + } } var trader = PowerComp as CompPowerTrader; - trader.PowerOutput = HasInput ? 30000 : 0; + trader.PowerOutput = HasInput ? (PowerOutput) : 0; base.Tick(); } public void GiveInput(Building_AntimatterReactor r) { + ticksSinceHasInput = 0; + CurrentReactor = r; if (!HasInput) { CauseRedraw(); } - ticksSinceHasInput = 0; } public void CauseRedraw(Map map = null) diff --git a/Source/AntimatterAnnihilation/Buildings/Building_ReactorInjector.cs b/Source/AntimatterAnnihilation/Buildings/Building_ReactorInjector.cs index 7f12430..2668c7f 100644 --- a/Source/AntimatterAnnihilation/Buildings/Building_ReactorInjector.cs +++ b/Source/AntimatterAnnihilation/Buildings/Building_ReactorInjector.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using UnityEngine; using Verse; +using Verse.Noise; namespace AntimatterAnnihilation.Buildings { @@ -76,6 +77,43 @@ public override Graphic Graphic } public EnergyBeam Beam { get; private set; } public IntVec3 BeamExploreDirection { get; private set; } + public byte PowerMode; + + public float FuelBurnRate + { + get + { + switch (PowerMode) + { + case 0: + return 1.5f; + case 1: + return 2f; + case 2: + return 4f; + default: + return 1.5f; + } + } + } + + public float PowerOutputMultiplier + { + get + { + switch (PowerMode) + { + case 0: + return 1f; // 30 KW, 1.5 fuel per day. + case 1: + return 1.5f; // 45 KW, 2 fuel per day (more efficient, but uses all the fuel 1 accelerator produces so no extra). + case 2: + return 4f; // 120 KW, 4 fuel per day (the most efficient, but requires at least 2 accelerators). + default: + return 1f; + } + } + } public int MaxBeamLength = 10; @@ -149,6 +187,7 @@ public override void Tick() if (Beam == null) return; + FuelComp.CustomFuelBurnRate = FuelBurnRate; Beam.BeamVisible = IsRunning; //CauseRedraw(); @@ -164,6 +203,39 @@ public override void Tick() } } + public override void ExposeData() + { + base.ExposeData(); + + Scribe_Values.Look(ref PowerMode, "injectorPowerMode"); + } + + public override IEnumerable GetGizmos() + { + foreach (var g in base.GetGizmos()) + { + yield return g; + } + + var cmd2 = new Command_Action(); + cmd2.defaultLabel = "AA.RIPowerLevel".Translate(); + cmd2.defaultDesc = "AA.RIPowerLevelDesc".Translate($"{PowerOutputMultiplier*100:F0}", $"{FuelBurnRate:F1}"); + cmd2.icon = PowerMode == 2 ? Content.PowerLevelHigh : PowerMode == 1 ? Content.PowerLevelMedium : Content.PowerLevelLow; + cmd2.action = () => + { + PowerMode++; + if (PowerMode >= 3) + PowerMode = 0; + }; + + yield return cmd2; + } + + public override string GetInspectString() + { + return base.GetInspectString() + $"\n{"AA.RIPowerLevelDesc".Translate($"{PowerOutputMultiplier * 100:F0}", $"{FuelBurnRate:F1}")}"; + } + private Vector3 GetOffset(out float angle) { var rot = base.Rotation; @@ -197,7 +269,7 @@ private Vector3 GetOffset(out float angle) } private List tempThings = new List(); - public float UpdateDamageAndInjection(float maxDst) // The action is a hacky workaround to not being able to do 'out int realDst' + public float UpdateDamageAndInjection(float maxDst) { avoidance.Clear(); diff --git a/Source/AntimatterAnnihilation/ThingComps/CompRefuelableConditional.cs b/Source/AntimatterAnnihilation/ThingComps/CompRefuelableConditional.cs index ae9a216..a9ea4a9 100644 --- a/Source/AntimatterAnnihilation/ThingComps/CompRefuelableConditional.cs +++ b/Source/AntimatterAnnihilation/ThingComps/CompRefuelableConditional.cs @@ -18,6 +18,15 @@ public class CompRefuelableConditional : CompRefuelable public event Action OnRunOutOfFuel; public bool IsConditionPassed { get; private set; } + public float CustomFuelBurnRate { get; set; } = 0f; + + public float RealFuelConsumeRate + { + get + { + return CustomFuelBurnRate > 0f ? CustomFuelBurnRate : Props.fuelConsumptionRate; + } + } public override void CompTick() { @@ -27,7 +36,14 @@ public override void CompTick() if (consume) { // Base tick consumes fuel using default conditions (must be switched on). - base.CompTick(); + if (CustomFuelBurnRate <= 0f) + { + base.CompTick(); + } + else + { + base.ConsumeFuel(CustomFuelBurnRate / 60000f); + } } } @@ -54,5 +70,21 @@ public void SetFuelLevel(float fuelLevel) fInfo.SetValue(this, fuelLevel); } + + public override string CompInspectStringExtra() + { + string str = Props.FuelLabel + ": " + Fuel.ToStringDecimalIfSmall() + " / " + Props.fuelCapacity.ToStringDecimalIfSmall(); + if (!Props.consumeFuelOnlyWhenUsed && HasFuel) + { + float daysRemaining = Fuel / RealFuelConsumeRate; + int ticksRemaining = (int)(daysRemaining * 60000); + str = str + " (" + ticksRemaining.ToStringTicksToPeriod() + ")"; + } + if (!HasFuel && !Props.outOfFuelMessage.NullOrEmpty()) + str += $"\n{Props.outOfFuelMessage} ({GetFuelCountToFullyRefuel()}x {Props.fuelFilter.AnyAllowedDef.label})"; + if (Props.targetFuelLevelConfigurable) + str = str + ("\n" + "ConfiguredTargetFuelLevel".Translate(TargetFuelLevel.ToStringDecimalIfSmall())); + return str; + } } } \ No newline at end of file diff --git a/Source/Content/Models/Reactor.blend b/Source/Content/Models/Reactor.blend index 69f2ffb..36ebd1d 100644 Binary files a/Source/Content/Models/Reactor.blend and b/Source/Content/Models/Reactor.blend differ