Skip to content

Commit

Permalink
Merge branch 'MiniReactor' into Develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Epicguru committed May 30, 2020
2 parents 473138c + 5505cff commit 5594fe0
Show file tree
Hide file tree
Showing 27 changed files with 3,768 additions and 3,413 deletions.
4 changes: 4 additions & 0 deletions Defs/Buildings/Production/AlloyFusionMachine.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ See the in-game wiki for more information and how to use.</description>
<basePowerConsumption>300</basePowerConsumption>
<transmitsPower>false</transmitsPower>
</li>
<li Class="CompProperties_Glower"> <!-- A Harmony patch ensures that this only glows when required. -->
<glowRadius>6</glowRadius>
<glowColor>(255,248,214,255)</glowColor>
</li>
</comps>
<constructionSkillPrerequisite>10</constructionSkillPrerequisite>
<researchPrerequisites>
Expand Down
4 changes: 4 additions & 0 deletions Defs/Buildings/Production/CompositeRefiner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ See the in-game wiki for more information and how to use.</description>
<basePowerConsumption>1500</basePowerConsumption>
<transmitsPower>false</transmitsPower>
</li>
<li Class="CompProperties_Glower"> <!-- A Harmony patch ensures that this only glows when required. -->
<glowRadius>5</glowRadius>
<glowColor>(245,198,255,255)</glowColor>
</li>
</comps>
<constructionSkillPrerequisite>7</constructionSkillPrerequisite>
<researchPrerequisites>
Expand Down
4 changes: 4 additions & 0 deletions Defs/Buildings/Special/M3G_UMIN.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ Firing the beam of energy creates a huge electromagnetic pulse in both the area
<doSelfDischarge>false</doSelfDischarge>
<doInspectorInfo>false</doInspectorInfo>
</li>
<li Class="CompProperties_Glower"> <!-- A Harmony patch ensures that this only glows when required. -->
<glowRadius>9</glowRadius>
<glowColor>(255,232,142,255)</glowColor>
</li>
</comps>
<researchPrerequisites>
<li>R_Megumin_AA</li>
Expand Down
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>
2 changes: 2 additions & 0 deletions Source/AntimatterAnnihilation/AntimatterAnnihilation.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
<Compile Include="Effects\RailgunEffectComp.cs" />
<Compile Include="Effects\SpawnedEffect.cs" />
<Compile Include="Effects\UpBeam.cs" />
<Compile Include="Patches\Patch_CompGlower.cs" />
<Compile Include="Patches\Patch_AvoidGrid.cs" />
<Compile Include="Patches\Patch_BatteryComp_AmountCanAccept.cs" />
<Compile Include="Patches\Patch_BatteryComp_SetStoredEnergyPct.cs" />
Expand All @@ -144,6 +145,7 @@
<Compile Include="ThingComps\CompRefuelableConditional.cs" />
<Compile Include="UI\UI_PowerNetConsole.cs" />
<Compile Include="Utils\Extensions.cs" />
<Compile Include="Utils\IConditionalGlower.cs" />
<Compile Include="Utils\IResettable.cs" />
<Compile Include="Utils\ObjectPool.cs" />
<Compile Include="Utils\RecoilManager.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace AntimatterAnnihilation.Buildings
{
public class Building_AlloyFusionMachine : Building_TrayPuller
public class Building_AlloyFusionMachine : Building_TrayPuller, IConditionalGlower
{
public const int TICKS_PER_FRAME = 3;
public const int FRAME_COUNT = 20;
Expand Down Expand Up @@ -43,6 +43,17 @@ private static void LoadGraphics(Building thing)
}
}

public CompGlower CompGlower
{
get
{
if (_compGlower == null)
_compGlower = this.TryGetComp<CompGlower>();

return _compGlower;
}
}
private CompGlower _compGlower;
public CompPowerTrader PowerTraderComp
{
get
Expand Down Expand Up @@ -92,6 +103,13 @@ public int UraniumToFill
return MAX_URANIUM_STORED - storedUranium;
}
}
public bool ShouldBeGlowingNow
{
get
{
return IsActive;
}
}

private Graphic activeGraphic;
private bool isActiveInt = true;
Expand Down Expand Up @@ -146,7 +164,12 @@ public override void Tick()
UpdatePowerDraw();

// Update active/running state.
bool oldActive = this.IsActive;
UpdateActiveState();
if (oldActive != this.IsActive)
{
CompGlower?.ReceiveCompSignal("PowerTurnedOn"); // Obviously the power hasn't actually just been turned on, but it's just a way to trigger UpdateLit to be called.
}

// Pull resources as long as there is power.
UpdatePullResources();
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@

namespace AntimatterAnnihilation.Buildings
{
public class Building_CompositeRefiner : Building_TrayPuller
public class Building_CompositeRefiner : Building_TrayPuller, IConditionalGlower
{
public bool ShouldBeGlowingNow
{
get
{
return GetShouldBeRunning();
}
}

public CompPowerTrader PowerTraderComp
{
get
Expand All @@ -16,6 +24,16 @@ public CompPowerTrader PowerTraderComp
}
}
private CompPowerTrader _powerTraderComp;
public CompGlower CompGlower
{
get
{
if (_compGlower == null)
this._compGlower = base.GetComp<CompGlower>();
return _compGlower;
}
}
private CompGlower _compGlower;
public IntVec3 OutputPos
{
get
Expand Down Expand Up @@ -50,6 +68,7 @@ public int MissingAntimatter
public int ProductionTicks;

private ulong tickCount;
private bool lastFrameRunning;

public override void SpawnSetup(Map map, bool respawningAfterLoad)
{
Expand Down Expand Up @@ -91,6 +110,12 @@ public override void Tick()
}
}

if (lastFrameRunning != isRunning)
{
CompGlower?.ReceiveCompSignal("PowerTurnedOn"); // Obviously the power hasn't actually just been turned on, but it's just a way to trigger UpdateLit to be called.
}
lastFrameRunning = isRunning;

if (tickCount % 120 == 0 && PowerTraderComp.PowerOn)
{
Building_InputTray lt = null;
Expand Down
25 changes: 24 additions & 1 deletion Source/AntimatterAnnihilation/Buildings/Building_Megumin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace AntimatterAnnihilation.Buildings
{
public class Building_Megumin : Building
public class Building_Megumin : Building, IConditionalGlower
{
[TweakValue("AntimatterAnnihilation")]
public static bool DoSolarFlare = true;
Expand All @@ -29,6 +29,13 @@ public class Building_Megumin : Building
public static float EXPLOSION_PEN = 0.7f;
public static float CHARGE_WATT_DAYS = 600 * 5; // Requires 5 fully-powered batteries to charge (semi-instantly). Otherwise it will take longer depending on power production.

public bool ShouldBeGlowingNow
{
get
{
return IsPoweringUp;
}
}
public CompEquippable GunComp
{
get
Expand Down Expand Up @@ -59,6 +66,16 @@ public CompRefuelableConditional FuelComp
}
}
private CompRefuelableConditional _compRefuelable;
public CompGlower CompGlower
{
get
{
if (_compGlower == null)
this._compGlower = base.GetComp<CompGlower>();
return _compGlower;
}
}
private CompGlower _compGlower;
public Verb AttackVerb
{
get
Expand Down Expand Up @@ -232,6 +249,9 @@ private void StartPowerUpSequence()

// Do particle effects.
chargeEffect?.Play(true);

// Enable glow start.
CompGlower?.ReceiveCompSignal("PowerTurnedOn");
}

private void StartRealAttack()
Expand Down Expand Up @@ -280,6 +300,9 @@ private void StopFireLaser()
{
beam.IsActive = false;
soundSustainer?.End();

// Turn off glow.
CompGlower?.ReceiveCompSignal("PowerTurnedOn");
}

private void DoEasterEgg()
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
Loading

0 comments on commit 5594fe0

Please sign in to comment.