com.b3dgs.lionengine.game.strategy.ability
Class AbstractProducerAbility<TTile extends AbstractPathTile,TSkill extends AbstractSkill<TTile,TSkill,TAttr>,TAttr extends AbstractAttributes>

java.lang.Object
  extended by com.b3dgs.lionengine.game.strategy.ability.AbstractProducerAbility<TTile,TSkill,TAttr>
Type Parameters:
TTile - tile type used.
TSkill - skill type used.
TAttr - attributes type used.
All Implemented Interfaces:
ProducerAbility<TTile,TSkill,TAttr>

public abstract class AbstractProducerAbility<TTile extends AbstractPathTile,TSkill extends AbstractSkill<TTile,TSkill,TAttr>,TAttr extends AbstractAttributes>
extends java.lang.Object
implements ProducerAbility<TTile,TSkill,TAttr>

This is the main implementation of the producer ability. This object can be used by any kind of unit which will receive the ability of production. It also supports rally point (when unit is produced, it will reach this point).


Field Summary
protected  AbstractEntryHandler<TTile,TSkill,TAttr> entrys
          Entry handler reference.
 
Constructor Summary
AbstractProducerAbility(AbstractBuilding<TTile,TSkill,TAttr> building, AbstractEntryHandler<TTile,TSkill,TAttr> handler)
          Create a new attacker ability.
 
Method Summary
 void addToProductionQueue(java.lang.String name, int time)
          Add an element to the production queue.
abstract  boolean canBeProduced()
          Condition to make production finished (entry exit from production).
abstract  boolean canProduce()
          Condition to start production.
 java.lang.String getProducingElement()
          Get name of current producing element.
 int getProductionProgress()
          Get production progress in percent.
 int getQueueLength()
          Get size of production queue.
protected abstract  AbstractUnit<TTile,TSkill,TAttr> getUnitToProduce(java.lang.String name)
          Get unit to produce reference from its name.
abstract  void onCanNotProduce()
          Action called when producer can't produce.
abstract  void onProduced(AbstractUnit<TTile,TSkill,TAttr> unit)
          Action called when production is done.
abstract  void onProducing()
          Action called on producing.
 void setRallyLocation(int tx, int ty)
          Rally location in tile.
 void stopProduction()
          Stop any production.
 void updateProduction()
          Update production routine.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

entrys

protected final AbstractEntryHandler<TTile extends AbstractPathTile,TSkill extends AbstractSkill<TTile,TSkill,TAttr>,TAttr extends AbstractAttributes> entrys
Entry handler reference.

Constructor Detail

AbstractProducerAbility

public AbstractProducerAbility(AbstractBuilding<TTile,TSkill,TAttr> building,
                               AbstractEntryHandler<TTile,TSkill,TAttr> handler)
Create a new attacker ability.

Parameters:
building - concerned building reference.
handler - entry handler reference.
Method Detail

addToProductionQueue

public void addToProductionQueue(java.lang.String name,
                                 int time)
Description copied from interface: ProducerAbility
Add an element to the production queue. It works as a FIFO (First In, First Out). Production will be stopped when the list is empty. In this case, getProductionProgress() will return -1. Production list stores only entity name. You have to return the corresponding instance by overriding this function: getUnitToProduce(String name).

Specified by:
addToProductionQueue in interface ProducerAbility<TTile extends AbstractPathTile,TSkill extends AbstractSkill<TTile,TSkill,TAttr>,TAttr extends AbstractAttributes>
Parameters:
name - entry name to produce.
time - production time.

getUnitToProduce

protected abstract AbstractUnit<TTile,TSkill,TAttr> getUnitToProduce(java.lang.String name)
Get unit to produce reference from its name.

Parameters:
name - unit name.
Returns:
unit reference.

updateProduction

public void updateProduction()
Description copied from interface: ProducerAbility
Update production routine.

Specified by:
updateProduction in interface ProducerAbility<TTile extends AbstractPathTile,TSkill extends AbstractSkill<TTile,TSkill,TAttr>,TAttr extends AbstractAttributes>

stopProduction

public void stopProduction()
Description copied from interface: ProducerAbility
Stop any production.

Specified by:
stopProduction in interface ProducerAbility<TTile extends AbstractPathTile,TSkill extends AbstractSkill<TTile,TSkill,TAttr>,TAttr extends AbstractAttributes>

setRallyLocation

public void setRallyLocation(int tx,
                             int ty)
Description copied from interface: ProducerAbility
Rally location in tile.

Specified by:
setRallyLocation in interface ProducerAbility<TTile extends AbstractPathTile,TSkill extends AbstractSkill<TTile,TSkill,TAttr>,TAttr extends AbstractAttributes>
Parameters:
tx - horizontal tile index.
ty - vertical tile index.

getProductionProgress

public int getProductionProgress()
Description copied from interface: ProducerAbility
Get production progress in percent. If it returns -1, it means that there are not any active production.

Specified by:
getProductionProgress in interface ProducerAbility<TTile extends AbstractPathTile,TSkill extends AbstractSkill<TTile,TSkill,TAttr>,TAttr extends AbstractAttributes>
Returns:
percent of progress.

getProducingElement

public java.lang.String getProducingElement()
Description copied from interface: ProducerAbility
Get name of current producing element.

Specified by:
getProducingElement in interface ProducerAbility<TTile extends AbstractPathTile,TSkill extends AbstractSkill<TTile,TSkill,TAttr>,TAttr extends AbstractAttributes>
Returns:
name of current producing element.

getQueueLength

public int getQueueLength()
Description copied from interface: ProducerAbility
Get size of production queue.

Specified by:
getQueueLength in interface ProducerAbility<TTile extends AbstractPathTile,TSkill extends AbstractSkill<TTile,TSkill,TAttr>,TAttr extends AbstractAttributes>
Returns:
number of remaining products.

canProduce

public abstract boolean canProduce()
Condition to start production.

Returns:
true if able to produce.

canBeProduced

public abstract boolean canBeProduced()
Condition to make production finished (entry exit from production).

Returns:
true if can terminate production.

onCanNotProduce

public abstract void onCanNotProduce()
Action called when producer can't produce.


onProducing

public abstract void onProducing()
Action called on producing.


onProduced

public abstract void onProduced(AbstractUnit<TTile,TSkill,TAttr> unit)
Action called when production is done.

Parameters:
unit - unit produced.