Package name.moore.kevin.ze.components
Class accumulator
java.lang.Object
name.moore.kevin.ze.components.accumulator
- All Implemented Interfaces:
com.simsilica.es.EntityComponent
A component that can stores up energy upto a predefined limit.
Once at the pre-determined limit, the accumulator will not accept any more energy and will return offered amounts. A discharge (which can only happen once the accumulator is at its limit) releases the stored energy and the store is back to zero. This is used for things like weapons which only fire once fully charged.
The accumulator can also be set (via the constructor) to collect only the first amount of energy offered, but still only to the limit. This is used in hulls.
- Author:
- Kevin Moore
<dev@kevin.moore.name>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate org.jscience.physics.amount.Amount<javax.measure.quantity.Energy>private booleanTrue to indicate no more energy will be accepted and ready to call discharge().private org.jscience.physics.amount.Amount<javax.measure.quantity.Energy>private booleanMode to accept only one charge, and consider the accumulator fully charged. -
Constructor Summary
ConstructorsConstructorDescriptionaccumulator(org.jscience.physics.amount.Amount<javax.measure.quantity.Energy> limit)accumulator(org.jscience.physics.amount.Amount<javax.measure.quantity.Energy> limit, boolean once) -
Method Summary
Modifier and TypeMethodDescriptionorg.jscience.physics.amount.Amount<javax.measure.quantity.Energy>charge(org.jscience.physics.amount.Amount<javax.measure.quantity.Energy> offered)Store energy and return any unused energy; this happens when the accumulator is at its limit ie full.org.jscience.physics.amount.Amount<javax.measure.quantity.Energy>Release all the accumulated energy, but only if fully charged.org.jscience.physics.amount.Amount<javax.measure.quantity.Energy>discharge(boolean force)Discharge the accumulated energy even if not fully charged.org.jscience.physics.amount.Amount<javax.measure.quantity.Energy>getLimit()toString()
-
Field Details
-
limit
private org.jscience.physics.amount.Amount<javax.measure.quantity.Energy> limit -
accumulated
private org.jscience.physics.amount.Amount<javax.measure.quantity.Energy> accumulated -
charged
private boolean chargedTrue to indicate no more energy will be accepted and ready to call discharge(). -
once
private boolean onceMode to accept only one charge, and consider the accumulator fully charged.
-
-
Constructor Details
-
accumulator
public accumulator(org.jscience.physics.amount.Amount<javax.measure.quantity.Energy> limit)- Parameters:
limit- maximum storage amount
-
accumulator
public accumulator(org.jscience.physics.amount.Amount<javax.measure.quantity.Energy> limit, boolean once)- Parameters:
limit- maximum storage amountonce- can only be charged once before being discharged.
-
-
Method Details
-
getLimit
public org.jscience.physics.amount.Amount<javax.measure.quantity.Energy> getLimit()- Returns:
- maximum storage amount
-
charge
public org.jscience.physics.amount.Amount<javax.measure.quantity.Energy> charge(org.jscience.physics.amount.Amount<javax.measure.quantity.Energy> offered)Store energy and return any unused energy; this happens when the accumulator is at its limit ie full.Offer a negative energy to remove or use energy from the accumulator
- Parameters:
offered- energy to add to the accumulator- Returns:
- any unused energy
-
discharge
public org.jscience.physics.amount.Amount<javax.measure.quantity.Energy> discharge()Release all the accumulated energy, but only if fully charged.- Returns:
- all the current stored energy
-
discharge
public org.jscience.physics.amount.Amount<javax.measure.quantity.Energy> discharge(boolean force)Discharge the accumulated energy even if not fully charged.- Parameters:
force- true- Returns:
- all the current stored energy
-
toString
-