mirror of
https://github.com/Xevion/RimWorld-Hydroponics-Expanded.git
synced 2025-12-08 14:08:16 -06:00
Add dynamic power usage via Stage setter
This commit is contained in:
@@ -12,10 +12,31 @@ namespace HydroponicsExpanded {
|
|||||||
[StaticConstructorOnStartup]
|
[StaticConstructorOnStartup]
|
||||||
public class BuildingDenseHydroponicsBasin : Building_PlantGrower, IThingHolder, IPlantToGrowSettable {
|
public class BuildingDenseHydroponicsBasin : Building_PlantGrower, IThingHolder, IPlantToGrowSettable {
|
||||||
private ThingOwner _innerContainer;
|
private ThingOwner _innerContainer;
|
||||||
private int _capacity = 4;
|
private int _capacity = 4; // Modified by CapacityExtension DefModExtension
|
||||||
private float _highestGrowth = 0f;
|
private float _highestGrowth = 0f;
|
||||||
|
private CompPowerTrader _compPowerTrader;
|
||||||
|
|
||||||
private HydroponicsStage _stage = HydroponicsStage.Sowing;
|
private HydroponicsStage _stage = HydroponicsStage.Sowing;
|
||||||
|
|
||||||
|
public HydroponicsStage Stage {
|
||||||
|
get => _stage;
|
||||||
|
private set {
|
||||||
|
switch (value) {
|
||||||
|
case HydroponicsStage.Sowing:
|
||||||
|
case HydroponicsStage.Harvest:
|
||||||
|
_compPowerTrader.PowerOutput = _compPowerTrader.Props.idlePowerDraw;
|
||||||
|
break;
|
||||||
|
case HydroponicsStage.Grow:
|
||||||
|
_compPowerTrader.PowerOutput = _compPowerTrader.Props.PowerConsumption;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException();
|
||||||
|
}
|
||||||
|
|
||||||
|
_stage = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public BuildingDenseHydroponicsBasin() {
|
public BuildingDenseHydroponicsBasin() {
|
||||||
_innerContainer = new ThingOwner<Thing>(this, false);
|
_innerContainer = new ThingOwner<Thing>(this, false);
|
||||||
}
|
}
|
||||||
@@ -48,14 +69,14 @@ namespace HydroponicsExpanded {
|
|||||||
if (capacityReached) {
|
if (capacityReached) {
|
||||||
SoundStarter.PlayOneShot(SoundDefOf.CryptosleepCasket_Accept,
|
SoundStarter.PlayOneShot(SoundDefOf.CryptosleepCasket_Accept,
|
||||||
new TargetInfo(Position, Map));
|
new TargetInfo(Position, Map));
|
||||||
_stage = HydroponicsStage.Grow;
|
Stage = HydroponicsStage.Grow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GrowTick() {
|
private void GrowTick() {
|
||||||
// If there are no plants stored, reset the growth % and move back to the sowing stage.
|
// If there are no plants stored, reset the growth % and move back to the sowing stage.
|
||||||
if (_innerContainer.Count == 0) {
|
if (_innerContainer.Count == 0) {
|
||||||
_stage = HydroponicsStage.Sowing;
|
Stage = HydroponicsStage.Sowing;
|
||||||
_highestGrowth = 0f;
|
_highestGrowth = 0f;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -78,7 +99,7 @@ namespace HydroponicsExpanded {
|
|||||||
|
|
||||||
// When growth is complete, move to the harvesting stage.
|
// When growth is complete, move to the harvesting stage.
|
||||||
if (growthTrackingPlant.LifeStage == PlantLifeStage.Mature)
|
if (growthTrackingPlant.LifeStage == PlantLifeStage.Mature)
|
||||||
_stage = HydroponicsStage.Harvest;
|
Stage = HydroponicsStage.Harvest;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HarvestTick() {
|
private void HarvestTick() {
|
||||||
@@ -111,7 +132,7 @@ namespace HydroponicsExpanded {
|
|||||||
|
|
||||||
// All plants have been harvested. Switch back to sowing stage.
|
// All plants have been harvested. Switch back to sowing stage.
|
||||||
if (_innerContainer.Count == 0)
|
if (_innerContainer.Count == 0)
|
||||||
_stage = HydroponicsStage.Sowing;
|
Stage = HydroponicsStage.Sowing;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void TickStage(HydroponicsStage stage) {
|
private void TickStage(HydroponicsStage stage) {
|
||||||
@@ -237,6 +258,8 @@ namespace HydroponicsExpanded {
|
|||||||
public override void SpawnSetup(Map map, bool respawningAfterLoad) {
|
public override void SpawnSetup(Map map, bool respawningAfterLoad) {
|
||||||
base.SpawnSetup(map, respawningAfterLoad);
|
base.SpawnSetup(map, respawningAfterLoad);
|
||||||
|
|
||||||
|
_compPowerTrader = GetComp<CompPowerTrader>();
|
||||||
|
|
||||||
var modExtension = def.GetModExtension<CapacityExtension>();
|
var modExtension = def.GetModExtension<CapacityExtension>();
|
||||||
if (modExtension != null) {
|
if (modExtension != null) {
|
||||||
_capacity = modExtension.capacity;
|
_capacity = modExtension.capacity;
|
||||||
|
|||||||
Reference in New Issue
Block a user