cz.cuni.pogamut.Client
Class AgentInventory

java.lang.Object
  extended by cz.cuni.pogamut.Client.AgentInventory
All Implemented Interfaces:
RcvMsgListener, java.util.EventListener

public class AgentInventory
extends java.lang.Object
implements RcvMsgListener

AgentInventory serves to keep info about the weapons agent is carrying it provides usefull methods which can be used to determine suitability of visible ammo or to able to switch among possesed weapons

Some profiling should take place here - don't know which operation will be the most used, so I tried to KISS - "keep it simple and stupid":)


Field Summary
private  int currentWeapon
           
private  java.util.ArrayList<AddAmmo> extraAmmo
           
private static int melee
           
private  java.util.logging.Logger platformLog
           
private  java.util.ArrayList<AddWeapon> weapons
           
 
Constructor Summary
AgentInventory(AgentBody body, java.util.logging.Logger logger)
          body is necessary for registering of listeners for events logger is just to log to the same file
 
Method Summary
protected  void addWeapon(AddWeapon newWeapon)
          adds new Weapon to weapons - after AIN GB message if the bot collected any extra ammo for the weapon, add it to the weapon.currentAmmo
protected  void addWeaponToWeapons(AddWeapon newWeapon)
          Adds newWeapon ammo to the ammo of weapon of the same type in the inventory if the weapon was the first agent got (at the game start), set it as current
 boolean anyLoaded()
           
protected  void collectAmmo(AddAmmo ammo)
          Method to set takes care about picking-up an ammo
 java.util.ArrayList<AddWeapon> getAllWeapons()
          provides an access to weapons
NOT SYNCHRONIZED!!!
 AddWeapon getBetterWeapon(Triple from, Triple to)
          returns null, if bot has no weapon, that is better than the one he already holds according to the distance from the target
returns better weapon, if there is any loaded
NOTE!
 java.util.ArrayList<AddWeapon> getCopyOfAllWeapons()
          get copies of weapons - to handle them by user
 AddWeapon getCurrentWeapon()
          return AddWeapon with the weapon agent is currently holding
 AddWeapon getWeapon()
          get any loaded weapon from loaded weapons
 AddWeapon getWeapon(boolean isMelee)
          get weapon of desired type (melee/ranged) from loaded weapons can't give you Shield Gun!
 AddWeapon getWeaponOfType(ItemType type)
           
 boolean hasWeaponOfType(ItemType type)
           
protected  void changeWeapon(ChangedWeapon change)
          when bot changes weapon - message about change arrives, change index of current weapon
 int numberOfLoadedWeapons()
          returns number of loaded weapons
 int numberOfWeapons()
          returns number of weapons
private  void processSelf(Self selfMsg)
          update current ammo in the current weapon
update current weapon - like when agent thrown it away
everything is according to info in self
 void receiveMessage(RcvMsgEvent e)
          listener for events - handels incomming messages ADD_AMMO - add collected ammo to inventory ADD_WEAPON - add weapon to inventory ADD_SPECIAL - nothing yet, place to add whatever developper needs SELF - correction of current ammo and current weapon - when bot fires it is no other way to find out how much ammo he has left CHANGED_WEAPON - bot changed weapon - reflect it to inventory
 void restartInventory()
          restarts inventory after agent's death
 boolean suitableAmmo(Ammo ammo)
          To test, whether Ammo of type is suitable for one of collected weapons it is not AddAmmo, because we want to know it for ammo which is still on the floor
 java.lang.String toString()
           
protected  void zeroAmmo(int ID)
          zero ammo - set weapon to unloaded
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

weapons

private java.util.ArrayList<AddWeapon> weapons

extraAmmo

private java.util.ArrayList<AddAmmo> extraAmmo

platformLog

private java.util.logging.Logger platformLog

currentWeapon

private int currentWeapon

melee

private static int melee
Constructor Detail

AgentInventory

public AgentInventory(AgentBody body,
                      java.util.logging.Logger logger)
body is necessary for registering of listeners for events logger is just to log to the same file

Parameters:
body -
logger -
Method Detail

restartInventory

public void restartInventory()
restarts inventory after agent's death


anyLoaded

public boolean anyLoaded()
Returns:
true if agent possess any loaded weapon (shield gun doesn't count)

addWeapon

protected void addWeapon(AddWeapon newWeapon)
adds new Weapon to weapons - after AIN GB message if the bot collected any extra ammo for the weapon, add it to the weapon.currentAmmo

Parameters:
newWeapon -

addWeaponToWeapons

protected void addWeaponToWeapons(AddWeapon newWeapon)
Adds newWeapon ammo to the ammo of weapon of the same type in the inventory if the weapon was the first agent got (at the game start), set it as current

Parameters:
newWeapon -

getWeapon

public AddWeapon getWeapon(boolean isMelee)
get weapon of desired type (melee/ranged) from loaded weapons

can't give you Shield Gun! (not considered as a weapon)

Parameters:
isMelee -
Returns:
melee or ranged loaded weapon

getWeapon

public AddWeapon getWeapon()
get any loaded weapon from loaded weapons

Returns:
loaded weapon

zeroAmmo

protected void zeroAmmo(int ID)
zero ammo - set weapon to unloaded

Parameters:
ID -

collectAmmo

protected void collectAmmo(AddAmmo ammo)
Method to set takes care about picking-up an ammo

Parameters:
ammo -

suitableAmmo

public boolean suitableAmmo(Ammo ammo)
To test, whether Ammo of type is suitable for one of collected weapons it is not AddAmmo, because we want to know it for ammo which is still on the floor

Parameters:
ammo -
Returns:
true if the supplied ammo is suitable for a weapon in inventory

changeWeapon

protected void changeWeapon(ChangedWeapon change)
when bot changes weapon - message about change arrives, change index of current weapon

Parameters:
change -

getCurrentWeapon

public AddWeapon getCurrentWeapon()
return AddWeapon with the weapon agent is currently holding

Returns:
agent current weapon

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

processSelf

private void processSelf(Self selfMsg)
update current ammo in the current weapon
update current weapon - like when agent thrown it away
everything is according to info in self


receiveMessage

public void receiveMessage(RcvMsgEvent e)
listener for events - handels incomming messages

Specified by:
receiveMessage in interface RcvMsgListener

hasWeaponOfType

public boolean hasWeaponOfType(ItemType type)
Returns:
true if bot has weapon of specified ItemType

getWeaponOfType

public AddWeapon getWeaponOfType(ItemType type)
Returns:
true if bot has weapon of specified ItemType

numberOfWeapons

public int numberOfWeapons()
returns number of weapons

Returns:
count weapons

numberOfLoadedWeapons

public int numberOfLoadedWeapons()
returns number of loaded weapons

Returns:
count loaded weapons

getBetterWeapon

public AddWeapon getBetterWeapon(Triple from,
                                 Triple to)
returns null, if bot has no weapon, that is better than the one he already holds according to the distance from the target
returns better weapon, if there is any loaded
NOTE! better weapon doesn't means necessarily the best agent takes only in account distance and information in ItemCathegories which are rough guessed

returns weapon with the lowest effectiveDist big enough to shoot at player - so for close player picks up flak cannon:)

Parameters:
from -
to -
Returns:
null if has not better weapon or has it already equiped, weapon if there is a better loaded weapon in inventory

getAllWeapons

public java.util.ArrayList<AddWeapon> getAllWeapons()
provides an access to weapons
NOT SYNCHRONIZED!!! - better use getCopyOfAllWeapons - get clone so noone can change it during work better to use predefined methods

Returns:
list of agents weapons - both loaded and unloaded

getCopyOfAllWeapons

public java.util.ArrayList<AddWeapon> getCopyOfAllWeapons()
get copies of weapons - to handle them by user

Returns:
copy of the current instance of weapons