Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace shiplib
- {
- public class Battery : ComponentBase, IEnergyComponent
- {
- [SecondaryStatusMax]
- public readonly double Capacity;
- public readonly double ChargePerSecond;
- [SecondaryStatus]
- public double CurrentCharge;
- public Battery(double capacity, double chargePerSecond /*TODO hex placement ?*/)
- {
- this.Capacity = capacity;
- this.ChargePerSecond = chargePerSecond;
- }
- #region IEnergyComponent
- public EnergyTickOrder Order { get { return EnergyTickOrder.Battery; } }
- public void Tick(EnergySupply supply, double dt)
- {
- if (CurrentCharge == Capacity)
- return;
- double available = supply.TakeAtMostFromAvailable(ChargePerSecond*dt);
- CurrentCharge += available;
- CurrentCharge = Math.Min(CurrentCharge, Capacity);
- }
- #endregion
- public double TakeAtMost(double requestedEnergy)
- {
- double taken = Math.Min(CurrentCharge, requestedEnergy);
- CurrentCharge -= taken;
- return taken;
- }
- }
- class BatteryFactory : IComponentFactory, IBatteryInfo, IComponentInfo, IBuildableComponent
- {
- public double Capacity { get; set; }
- public double ChargePerSecond { get; set; }
- public string Name { get { return "Battery"; } }
- public string Description { get { return "Stores energy."; } }
- public System.Collections.Generic.IEnumerable<HexCoord> Placement { get { return HexCoord.OneZeroHex; } }
- public ComponentCategory Category { get { return ComponentCategory.Energy; } }
- public double Cost { get { return 100; } }
- public double Weight { get { return 100; } }
- public IComponent Build()
- {
- return new Battery(Capacity, ChargePerSecond);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement