Advertisement
Guest User

Untitled

a guest
Sep 1st, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.94 KB | None | 0 0
  1. using System;
  2.  
  3. namespace shiplib
  4. {
  5.     public class Battery : ComponentBase, IEnergyComponent
  6.     {
  7.         [SecondaryStatusMax]
  8.         public readonly double Capacity;
  9.         public readonly double ChargePerSecond;
  10.  
  11.         [SecondaryStatus]
  12.         public double CurrentCharge;
  13.  
  14.         public Battery(double capacity, double chargePerSecond /*TODO hex placement ?*/)
  15.         {
  16.             this.Capacity = capacity;
  17.             this.ChargePerSecond = chargePerSecond;
  18.         }
  19.  
  20.         #region IEnergyComponent
  21.         public EnergyTickOrder Order { get { return EnergyTickOrder.Battery; } }
  22.  
  23.         public void Tick(EnergySupply supply, double dt)
  24.         {
  25.             if (CurrentCharge == Capacity)
  26.                 return;
  27.             double available = supply.TakeAtMostFromAvailable(ChargePerSecond*dt);
  28.             CurrentCharge += available;
  29.             CurrentCharge = Math.Min(CurrentCharge, Capacity);
  30.         }
  31.         #endregion
  32.  
  33.         public double TakeAtMost(double requestedEnergy)
  34.         {
  35.             double taken = Math.Min(CurrentCharge, requestedEnergy);
  36.             CurrentCharge -= taken;
  37.             return taken;
  38.         }
  39.     }
  40.  
  41.     class BatteryFactory : IComponentFactory, IBatteryInfo, IComponentInfo, IBuildableComponent
  42.     {
  43.  
  44.         public double Capacity { get; set; }
  45.  
  46.         public double ChargePerSecond { get; set; }
  47.  
  48.         public string Name { get { return "Battery"; } }
  49.  
  50.         public string Description { get { return "Stores energy."; } }
  51.  
  52.         public System.Collections.Generic.IEnumerable<HexCoord> Placement { get { return  HexCoord.OneZeroHex; } }
  53.  
  54.         public ComponentCategory Category { get { return ComponentCategory.Energy; } }
  55.  
  56.         public double Cost { get { return 100; } }
  57.  
  58.         public double Weight { get { return 100; } }
  59.  
  60.         public IComponent Build()
  61.         {
  62.             return new Battery(Capacity, ChargePerSecond);
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement