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

java.lang.Object
  extended by com.b3dgs.lionengine.game.purviews.Configurable
      extended by com.b3dgs.lionengine.game.Entity
          extended by com.b3dgs.lionengine.game.strategy.AbstractEntry<TTile,TSkill,TAttr>
              extended by com.b3dgs.lionengine.game.strategy.AbstractUnit<TTile,TSkill,TAttr>
Type Parameters:
TTile - tile type used.
TSkill - skill type used.
TAttr - attributes type used.
All Implemented Interfaces:
Animator, Collisionable, Mirrorable, Pathfindable
Direct Known Subclasses:
AbstractEnemy, AbstractHero

public abstract class AbstractUnit<TTile extends AbstractPathTile,TSkill extends AbstractSkill<TTile,TSkill,TAttr>,TAttr extends AbstractAttributes>
extends AbstractEntry<TTile,TSkill,TAttr>
implements Pathfindable

This class represents the main type for any kind of units. It has the ability of moving arround the map, avoiding any obstacle. It should be used for more specific unit such as builder, attacker...

See Also:
Pathfindable

Field Summary
 Damages damages
          Unit damages.
protected  Pathfindable pathfindable
           
 
Fields inherited from class com.b3dgs.lionengine.game.strategy.AbstractEntry
anim, animName, attr, icon, id, lastAttacker, life, map, offsetX, offsetY, sprite
 
Fields inherited from class com.b3dgs.lionengine.game.Entity
collisionable, height, mirrorable, width, x, xOld, y, yOld
 
Constructor Summary
AbstractUnit(java.lang.String data, PathBasedMap<TTile> map, java.awt.image.BufferedImage surface, TAttr attr)
          Create a new unit.
 
Method Summary
 boolean assignDestination(int tx, int ty)
          Assign a specified location; will move automaticaly until reach it.
 void clearIgnoredID()
          Clear all ignored id.
 void follow(AbstractEntry<TTile,TSkill,TAttr> entry)
          Define a target to follow.
 int getAngle()
          Get and from current orientation.
 float getMoveX()
          Get horizontal current speed.
 float getMoveY()
          Get vertical current speed.
 Orientation getOrientation()
          Get current orientation.
 Orientation getOrientationOld()
          Get previous orientation.
 float getSpeedX()
          Get horizontal speed.
 float getSpeedY()
          Get vertical speed.
 AbstractEntry<TTile,TSkill,TAttr> getTarget()
          Get entry target.
 int getX()
          Get position x.
 int getXInTile()
          Get horizontal tile location.
 int getY()
          Get position y.
 int getYInTile()
          Get vertical tile location.
 boolean hasReachedDestination()
          Check if has reached destination.
 void ignoreID(int id, boolean state)
          Ignore an id while searching pathfinding.
 boolean isIgnoredID(int id)
          Check if id is ignored.
 boolean isMoving()
          Check is its moving.
 void manualMove(float dx, float dy, float extrp)
          Move to specified destination only on call.
abstract  void onArrived()
          Action called when entry has reached destination.
abstract  void onDied()
          Action called when entry lost its vitality, or has been destroyed.
abstract  void onMove()
          Action called when entry is moving.
abstract  void onStartMove()
          Action called just before starting to move.
 boolean pathExists(int tx, int ty)
          Check if a path exists bewteen entity and destination.
 void place(int tx, int ty)
          Set specific location in tile.
 void pointTo(AbstractEntry<TTile,TSkill,TAttr> entry)
          Adjust orientation to face to specified entry.
 void pointTo(int dx, int dy)
          Adjust orientation to face to specified tile.
 void setArrived(boolean arrived)
          Set arrived state (used to separate the arriving & arrived case).
 void setHackNSlash(boolean state)
          Deprecated. 
 void setOrientation(Orientation orientation)
          Set specific orientation.
 void setSpeed(float speedX, float speedY)
          Set move speed.
 void setTarget(AbstractEntry<TTile,TSkill,TAttr> entry)
          Set entry target.
 void stop()
          Stop any action, reset all states.
 void stopMoves()
          Stop any pathfinding movements.
 void update(Keyboard keyboard, Mouse mouse, float extrp)
          This function can be overrided, be you should call super.update first, as it already does standard updates (updateMirror & updateMoves).
 void updateMirror()
          Deprecated. Call update function instead, as it override it. Call it manually only if you plan a specific update.
 void updateMoves(float extrp)
          Deprecated. Call update function instead, as it override it. Call it manually only if you plan a specific update.
 
Methods inherited from class com.b3dgs.lionengine.game.strategy.AbstractEntry
addSkill, applyOrder, applyOrder, getAnimState, getDistance, getDistance, getFieldOfView, getFrame, getHeight, getHeightInTile, getLayer, getLayerOld, getOrderedSkill, getOwnerID, getRealFrame, getSkill, getSkills, getWidth, getWidthInTile, getXOffset, getYOffset, hasChangedLayer, isActive, isAlive, isOver, isRemoved, isSelected, isUnselected, isVisible, onHit, onKilled, onOrdered, onOrderedFail, onSelection, play, play, play, remove, removeRef, removeSkill, render, setActive, setAlive, setAnimation, setFieldOfView, setFrame, setLayer, setLayerChanged, setOrderedSkill, setOver, setOwnerID, setSelection, setSkipLastFrameOnReverse, setVisibility, stopAnimation, unselect, updateAnimation
 
Methods inherited from class com.b3dgs.lionengine.game.Entity
backupCoord, cancelMirror, collide, collide, getCancelMirror, getCollision, getMirror, getRay, getXOld, getXReal, getYOld, getYReal, invertYAxis, mirror, move, renderCollision, updateCollision
 
Methods inherited from class com.b3dgs.lionengine.game.purviews.Configurable
checkInstruction, getAnim, getCollArea, getData, getDataBool, getDataInt, getDataString, getRange, loadData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

damages

public final Damages damages
Unit damages.


pathfindable

protected final Pathfindable pathfindable
Constructor Detail

AbstractUnit

public AbstractUnit(java.lang.String data,
                    PathBasedMap<TTile> map,
                    java.awt.image.BufferedImage surface,
                    TAttr attr)
Create a new unit.

Parameters:
data - unit data file path.
map - map reference.
surface - building image file path.
attr - attributes reference.
Method Detail

manualMove

public void manualMove(float dx,
                       float dy,
                       float extrp)
Description copied from interface: Pathfindable
Move to specified destination only on call.

Specified by:
manualMove in interface Pathfindable
Parameters:
dx - destination x.
dy - destination y.
extrp - extrapolation value.

assignDestination

public boolean assignDestination(int tx,
                                 int ty)
Description copied from interface: Pathfindable
Assign a specified location; will move automaticaly until reach it. Location is as tile (not in real value).

Specified by:
assignDestination in interface Pathfindable
Parameters:
tx - destination x (in tile map).
ty - destination y (in tile map).
Returns:
true if target found and valid.

stopMoves

public void stopMoves()
Description copied from interface: Pathfindable
Stop any pathfinding movements.

Specified by:
stopMoves in interface Pathfindable

follow

public void follow(AbstractEntry<TTile,TSkill,TAttr> entry)
Define a target to follow. Entry will move to target location. Automaticaly updated if target is moving.

Parameters:
entry - target.

stop

public void stop()
Stop any action, reset all states.


setTarget

public void setTarget(AbstractEntry<TTile,TSkill,TAttr> entry)
Set entry target.

Parameters:
entry - entry target.

getTarget

public AbstractEntry<TTile,TSkill,TAttr> getTarget()
Get entry target.

Returns:
entry target.

update

public void update(Keyboard keyboard,
                   Mouse mouse,
                   float extrp)
This function can be overrided, be you should call super.update first, as it already does standard updates (updateMirror & updateMoves).

Overrides:
update in class AbstractEntry<TTile extends AbstractPathTile,TSkill extends AbstractSkill<TTile,TSkill,TAttr>,TAttr extends AbstractAttributes>
Parameters:
keyboard - keyboard reference.
mouse - mouse reference.
extrp - extrapolation value.

updateMirror

@Deprecated
public void updateMirror()
Deprecated. Call update function instead, as it override it. Call it manually only if you plan a specific update.

Description copied from interface: Mirrorable
Update mirror and apply it if necessary.

Specified by:
updateMirror in interface Mirrorable
Overrides:
updateMirror in class Entity

updateMoves

@Deprecated
public void updateMoves(float extrp)
Deprecated. Call update function instead, as it override it. Call it manually only if you plan a specific update.

Description copied from interface: Pathfindable
Update automatic moves if has.

Specified by:
updateMoves in interface Pathfindable
Parameters:
extrp - extrapolation value.

place

public void place(int tx,
                  int ty)
Description copied from class: AbstractEntry
Set specific location in tile.

Specified by:
place in interface Pathfindable
Overrides:
place in class AbstractEntry<TTile extends AbstractPathTile,TSkill extends AbstractSkill<TTile,TSkill,TAttr>,TAttr extends AbstractAttributes>
Parameters:
tx - horizontal tile location.
ty - vertical tile location.

ignoreID

public void ignoreID(int id,
                     boolean state)
Description copied from interface: Pathfindable
Ignore an id while searching pathfinding. It allows to not be blocked by this id.

Specified by:
ignoreID in interface Pathfindable
Parameters:
id - id to ignore.
state - true to ignore, false else.

isIgnoredID

public boolean isIgnoredID(int id)
Description copied from interface: Pathfindable
Check if id is ignored.

Specified by:
isIgnoredID in interface Pathfindable
Parameters:
id - id to check.
Returns:
true if ignored, false else.

clearIgnoredID

public void clearIgnoredID()
Description copied from interface: Pathfindable
Clear all ignored id.

Specified by:
clearIgnoredID in interface Pathfindable

pathExists

public boolean pathExists(int tx,
                          int ty)
Description copied from interface: Pathfindable
Check if a path exists bewteen entity and destination.

Specified by:
pathExists in interface Pathfindable
Parameters:
tx - destination x (in tile map).
ty - destination y (in tile map).
Returns:
true if path exists.

setArrived

public void setArrived(boolean arrived)
Description copied from interface: Pathfindable
Set arrived state (used to separate the arriving & arrived case).

Specified by:
setArrived in interface Pathfindable
Parameters:
arrived - arrived state.

isMoving

public boolean isMoving()
Description copied from interface: Pathfindable
Check is its moving.

Specified by:
isMoving in interface Pathfindable
Returns:
true if moving.

hasReachedDestination

public boolean hasReachedDestination()
Description copied from interface: Pathfindable
Check if has reached destination.

Specified by:
hasReachedDestination in interface Pathfindable
Returns:
true if destination has been reached.

setSpeed

public void setSpeed(float speedX,
                     float speedY)
Description copied from interface: Pathfindable
Set move speed.

Specified by:
setSpeed in interface Pathfindable
Parameters:
speedX - horizontal speed.
speedY - vertical speed.

getSpeedX

public float getSpeedX()
Description copied from interface: Pathfindable
Get horizontal speed.

Specified by:
getSpeedX in interface Pathfindable
Returns:
horizontal speed.

getSpeedY

public float getSpeedY()
Description copied from interface: Pathfindable
Get vertical speed.

Specified by:
getSpeedY in interface Pathfindable
Returns:
vertical speed.

getMoveX

public float getMoveX()
Description copied from interface: Pathfindable
Get horizontal current speed.

Specified by:
getMoveX in interface Pathfindable
Returns:
horizontal current speed.

getMoveY

public float getMoveY()
Description copied from interface: Pathfindable
Get vertical current speed.

Specified by:
getMoveY in interface Pathfindable
Returns:
vertical current speed.

getX

public int getX()
Description copied from class: Entity
Get position x.

Specified by:
getX in interface Pathfindable
Overrides:
getX in class Entity
Returns:
position x.

getY

public int getY()
Description copied from class: Entity
Get position y.

Specified by:
getY in interface Pathfindable
Overrides:
getY in class Entity
Returns:
position y.

getXInTile

public int getXInTile()
Description copied from class: AbstractEntry
Get horizontal tile location.

Specified by:
getXInTile in interface Pathfindable
Overrides:
getXInTile in class AbstractEntry<TTile extends AbstractPathTile,TSkill extends AbstractSkill<TTile,TSkill,TAttr>,TAttr extends AbstractAttributes>
Returns:
horizontal tile location.

getYInTile

public int getYInTile()
Description copied from class: AbstractEntry
Get vertical tile location.

Specified by:
getYInTile in interface Pathfindable
Overrides:
getYInTile in class AbstractEntry<TTile extends AbstractPathTile,TSkill extends AbstractSkill<TTile,TSkill,TAttr>,TAttr extends AbstractAttributes>
Returns:
vertical tile location.

getOrientation

public Orientation getOrientation()
Get current orientation.

Returns:
current orientation.

getOrientationOld

public Orientation getOrientationOld()
Get previous orientation.

Returns:
previous orientation.

setOrientation

public void setOrientation(Orientation orientation)
Set specific orientation.

Parameters:
orientation - new orientation.

pointTo

public void pointTo(AbstractEntry<TTile,TSkill,TAttr> entry)
Adjust orientation to face to specified entry.

Parameters:
entry - entry to face.

pointTo

public void pointTo(int dx,
                    int dy)
Adjust orientation to face to specified tile.

Parameters:
dx - horizontal tile to face.
dy - vertical tile to face.

getAngle

public int getAngle()
Get and from current orientation.

Returns:
angle.

setHackNSlash

@Deprecated
public final void setHackNSlash(boolean state)
Deprecated. 

Description copied from interface: Pathfindable
Set specific case for hacknslash game (controling one unit).

Specified by:
setHackNSlash in interface Pathfindable
Parameters:
state - state.

onStartMove

public abstract void onStartMove()
Action called just before starting to move.


onMove

public abstract void onMove()
Action called when entry is moving.


onArrived

public abstract void onArrived()
Action called when entry has reached destination.


onDied

public abstract void onDied()
Action called when entry lost its vitality, or has been destroyed.