Skip to content

Commit

Permalink
Scrapped small reactor idea for now.
Browse files Browse the repository at this point in the history
Reactor injector can now change power level, affects total power output and also fuel efficiency.
  • Loading branch information
Epicguru committed May 30, 2020
1 parent 5ed278f commit 5505cff
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 15 deletions.
6 changes: 6 additions & 0 deletions Languages/English/Keyed/Keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<AA.On>on</AA.On>
<AA.Off>off</AA.Off>
<AA.Enabled>enabled</AA.Enabled>
<AA.Active>active</AA.Active>
<AA.NotActive>not active</AA.NotActive>
<AA.Turn>turn</AA.Turn> <!-- As in 'turn' machine on or off. -->
<AA.Name>name</AA.Name>
<AA.Power>power</AA.Power>
Expand Down Expand Up @@ -86,4 +88,8 @@
<AA.AFMPowerLevel>Change power level</AA.AFMPowerLevel>
<AA.AFMPowerLevelDesc>Current power level: {0}% speed, uses {1} watts.\nChange in power level only takes effect once the current alloy is completed.</AA.AFMPowerLevelDesc>

<!-- Reactor injector -->
<AA.RIPowerLevel>Change power level</AA.RIPowerLevel>
<AA.RIPowerLevelDesc>Current power level: {0}%, consumes {1} canisters per day.</AA.RIPowerLevelDesc>

</LanguageData>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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)
{
Expand All @@ -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();
}
}
Expand Down
32 changes: 27 additions & 5 deletions Source/AntimatterAnnihilation/Buildings/Building_PowerConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using UnityEngine;
using Verse;
using Verse.Noise;

namespace AntimatterAnnihilation.Buildings
{
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -149,6 +187,7 @@ public override void Tick()
if (Beam == null)
return;

FuelComp.CustomFuelBurnRate = FuelBurnRate;
Beam.BeamVisible = IsRunning;
//CauseRedraw();

Expand All @@ -164,6 +203,39 @@ public override void Tick()
}
}

public override void ExposeData()
{
base.ExposeData();

Scribe_Values.Look(ref PowerMode, "injectorPowerMode");
}

public override IEnumerable<Gizmo> 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;
Expand Down Expand Up @@ -197,7 +269,7 @@ private Vector3 GetOffset(out float angle)
}

private List<Thing> tempThings = new List<Thing>();
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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ public class CompRefuelableConditional : CompRefuelable
public event Action<CompRefuelableConditional> 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()
{
Expand All @@ -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);
}
}
}

Expand All @@ -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;
}
}
}
Binary file modified Source/Content/Models/Reactor.blend
Binary file not shown.

0 comments on commit 5505cff

Please sign in to comment.