cz.cuni.amis.pogamut.ut2004.agent.module.sensomotoric
Class Weaponry

java.lang.Object
  extended by cz.cuni.amis.pogamut.base.agent.module.AgentModule<AGENT>
      extended by cz.cuni.amis.pogamut.base.agent.module.SensomotoricModule<UT2004Bot>
          extended by cz.cuni.amis.pogamut.ut2004.agent.module.sensomotoric.Weaponry
All Implemented Interfaces:
IComponent

public class Weaponry
extends SensomotoricModule<UT2004Bot>

Memory module specialized on info about the bot's weapon inventory.

It listens to various events that provides information about weapons the bot picks up as well as weapon's ammo grouping it together and providing Weapon abstraction of bot's weaponry.

It also provides a way for easy weapon changing via changeWeapon(ItemType) and changeWeapon(Weapon).

It is designed to be initialized inside IUT2004BotController.prepareBot(UT2004Bot) method call and may be used since IUT2004BotController.botInitialized(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.ConfigChange, cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.InitedMessage) is called.

Hardened version - immune to NPEs (hopefully).


Field Summary
 
Fields inherited from class cz.cuni.amis.pogamut.base.agent.module.SensomotoricModule
act, worldView
 
Fields inherited from class cz.cuni.amis.pogamut.base.agent.module.AgentModule
agent, controller, eventBus, log
 
Constructor Summary
Weaponry(UT2004Bot bot)
          Constructor.
Weaponry(UT2004Bot bot, ItemDescriptors itemDescriptors)
          Constructor.
Weaponry(UT2004Bot bot, ItemDescriptors descriptors, LogCategory moduleLog)
          Constructor.
 
Method Summary
 boolean changeWeapon(ItemType weaponType)
          Changes the weapon the bot is currently holding (if the bot has the weapon and its ammo > 0).
 boolean changeWeapon(Weapon weapon)
          Changes the weapon the bot is currently holding (if the weapon's ammo is > 0).
protected  void cleanUp()
          Hook where to perform clean up of data structures of the module.
 int getAmmo(ItemType ammoOrWeaponType)
          Returns an amount of ammo of 'ammoOrWeaponType' the bot currently has.
 java.util.Map<ItemType,java.lang.Integer> getAmmos()
          Returns a map with current state of ammo (ammo for owned weapons as well as ammo for weapons that the bot do not have yet).
 int getCurrentAlternateAmmo()
          Tells, how much ammo is in the agent's inventory for current weapon for alternate firing mode.
 int getCurrentAmmo()
          Tells, how much ammo is in the agent's inventory for current weapon - primary + (if has different secondary ammo type) alternate (secondary).
 int getCurrentPrimaryAmmo()
          Tells, how much ammo is in the agent's inventory for current weapon.
 Weapon getCurrentWeapon()
          Retrieves current weapon from the agent's inventory.
 WeaponDescriptor getDescriptorForId(UnrealId inventoryWeaponId)
          Returns WeaponDescriptor for a given inventory UnrealId of the weapon.
 ItemType getItemTypeForId(UnrealId inventoryWeaponId)
          Returns an item type for a given inventory UnrealId of the weapon.
 java.util.Map<ItemType,Weapon> getLoadedMeleeWeapons()
          Retrieves loaded melee weapons from the agent's inventory.
 java.util.Map<ItemType,Weapon> getLoadedRangedWeapons()
          Retrieves loaded ranged weapons from the agent's inventory.
 java.util.Map<ItemType,Weapon> getLoadedWeapons()
          Retrieves all loaded weapons from the agent's inventory.
 java.util.Map<ItemType,Weapon> getMeleeWeapons()
          Retrieves melee weapons from the agent's inventory.
 int getPrimaryWeaponAmmo(ItemType weaponType)
          Returns an amount of primary ammo of a given 'weaponType' the bot currently has.
 ItemType getPrimaryWeaponAmmoType(ItemType weaponType)
          Return primary-ammo ItemType for a weapon.
 java.util.Map<ItemType,Weapon> getRangedWeapons()
          Retrieves ranged weapons from the agent's inventory.
 int getSecondaryWeaponAmmo(ItemType weaponType)
          Returns an amount of secondary ammo of a given 'weaponType' the bot currently has.
 ItemType getSecondaryWeaponAmmoType(ItemType weaponType)
          Return secondary-ammo ItemType for a weapon.
 Weapon getWeapon(ItemType weaponType)
          Returns Weapon instance for given 'weaponType' if the bot posses it.
 int getWeaponAmmo(ItemType weaponType)
          Returns an amount of primary+secondary ammo of a given 'weaponType' the bot currently has.
 WeaponDescriptor getWeaponDescriptor(ItemType weaponType)
          Returns a WeaponDescriptor for a given 'weaponType' (if it is not a weapon, returns null).
 ItemType getWeaponForAmmo(ItemType priOrSecAmmoType)
          Returns weaponType for a given ammoType (regardles whether it is primary or secondary ammo type).
 UnrealId getWeaponInventoryId(ItemType weaponType)
          Returns inventory UnrealId of the weapon the bot has inside its inventory (if the bot does not have it, returns null).
 UnrealId getWeaponInventoryId(WeaponDescriptor weaponDescriptor)
          Returns inventory UnrealId of the weapon the bot has inside its inventory (if the bot does not have it, returns null).
 java.util.Map<ItemType,Weapon> getWeapons()
          Retrieves all weapons from the agent's inventory.
 boolean hasAmmo(ItemType ammoType)
          Tells whether the bot has an ammo of 'ammoType'.
 boolean hasAmmoForWeapon(ItemType weaponType)
          Alias for hasWeaponAmmo(ItemType).
 boolean hasLoadedMeleeWeapon()
          Tells, whether the agent has any loaded melee weapon in the inventory.
 boolean hasLoadedRangedWeapon()
          Tells, whether the agent has any loaded ranged weapon in the inventory.
 boolean hasLoadedWeapon()
          Tells, whether the agent has any loaded weapon in the inventory.
 boolean hasLoadedWeapon(ItemType weapon)
          Whether the bot possess 'weapon' that has primary or secondary ammo.
 boolean hasLowAmmoForWeapon(ItemType weaponType, double lowRatio)
          Tells whether the bot has low-ammo for "weaponType" (either primary/secondary).
 boolean hasPrimaryLoadedWeapon(ItemType weapon)
          Whether the bot possess 'weapon' that has primary ammo.
 boolean hasPrimaryLowAmmoForWeapon(ItemType weaponType, double lowRatio)
          Tells whether the bot has primary low-ammo for "weaponType"
 boolean hasPrimaryWeaponAmmo(ItemType weaponType)
          Tells whether the bot has a primary ammo for a given 'weaponType'.
 boolean hasSecondaryAmmoType(ItemType weaponType)
          Whether the weapon has secondary ammo different from the primary.
 boolean hasSecondaryLoadedWeapon(ItemType weapon)
          Whether the bot possess 'weapon' that has secondary ammo.
 boolean hasSecondaryLowAmmoForWeapon(ItemType weaponType, double lowRatio)
          Tells whether the bot has secondary low-ammo for "weaponType"
 boolean hasSecondaryWeaponAmmo(ItemType weaponType)
          Tells whether the bot has a secondary ammo for a given 'weaponType'.
 boolean hasWeapon(ItemType.Group weaponGroup)
          Tells, whether a weapon from the specific group is in the agent's inventory.
 boolean hasWeapon(ItemType weaponType)
          Tells, whether specific weapon is in the agent's inventory.
 boolean hasWeaponAmmo(ItemType weaponType)
          Tells whether the bot has an ammo (either primary or secondary) for a given 'weaponType'.
 boolean isLoaded(ItemType.Group weaponGroup)
          Tells, whether a weapon from a specific group is in the agent's inventory && is loaded (has at least 1 primary or secondary ammo).
 boolean isLoaded(ItemType weaponType)
          Tells, whether specific weapon is in the agent's inventory && is loaded (has at least 1 primary or secondary ammo).
 
Methods inherited from class cz.cuni.amis.pogamut.base.agent.module.AgentModule
getComponentId, getLog, getState, initComponentId, isRunning, kill, pause, reset, resume, start, stop, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Weaponry

public Weaponry(UT2004Bot bot)
Constructor. Setups the memory module for a given bot.

Parameters:
bot - owner of the module that is using it

Weaponry

public Weaponry(UT2004Bot bot,
                ItemDescriptors itemDescriptors)
Constructor. Setups the memory module for a given bot.

Parameters:
bot - owner of the module that is using it
agentInfo - AgentInfo memory module.
itemDescriptors - ItemDescriptors memory module.

Weaponry

public Weaponry(UT2004Bot bot,
                ItemDescriptors descriptors,
                LogCategory moduleLog)
Constructor. Setups the memory module for a given bot.

Parameters:
bot - owner of the module that is using it
agentInfo - AgentInfo memory module.
itemDescriptors - ItemDescriptors memory module.
moduleLog -
Method Detail

getDescriptorForId

public WeaponDescriptor getDescriptorForId(UnrealId inventoryWeaponId)
Returns WeaponDescriptor for a given inventory UnrealId of the weapon.

Note that there exists two types of UnrealId for every weapon:

  1. item unreal id (i.e. from Item)
  2. inventory unreal id (i.e. id of the weapon inside bot's inventory from AddInventoryMsg)

Parameters:
inventoryWeaponId -
Returns:
weapon descriptor

getItemTypeForId

public ItemType getItemTypeForId(UnrealId inventoryWeaponId)
Returns an item type for a given inventory UnrealId of the weapon.

Note that there exists two types of UnrealId for every weapon:

  1. item unreal id (i.e. from Item)
  2. inventory unreal id (i.e. id of the weapon inside bot's inventory from AddInventoryMsg)

Parameters:
inventoryWeaponId -
Returns:

getWeaponInventoryId

public UnrealId getWeaponInventoryId(ItemType weaponType)
Returns inventory UnrealId of the weapon the bot has inside its inventory (if the bot does not have it, returns null).

Note that there exists two types of UnrealId for every weapon:

  1. item unreal id (i.e. from Item)
  2. inventory unreal id (i.e. id of the weapon inside bot's inventory from AddInventoryMsg)
This (inventory) unreal id is the one that must be used together with ChangeWeapon command.

Parameters:
weaponType -
Returns:
inventory unreal id (or null if the bot does not have the weapon)

getWeaponInventoryId

public UnrealId getWeaponInventoryId(WeaponDescriptor weaponDescriptor)
Returns inventory UnrealId of the weapon the bot has inside its inventory (if the bot does not have it, returns null).

Note that there exists two types of UnrealId for every weapon:

  1. item unreal id (i.e. from Item)
  2. inventory unreal id (i.e. id of the weapon inside bot's inventory from AddInventoryMsg)
This (inventory) unreal id is the one that must be used together with ChangeWeapon command.

Parameters:
weaponType -
Returns:
inventory unreal id (or null if the bot does not have the weapon)

changeWeapon

public boolean changeWeapon(ItemType weaponType)
Changes the weapon the bot is currently holding (if the bot has the weapon and its ammo > 0).

Parameters:
weaponType -
Returns:
whether we have changed the weapon (i.e., we have some ammo for it), or we already have it prepared (i.e., is our current weapon)

changeWeapon

public boolean changeWeapon(Weapon weapon)
Changes the weapon the bot is currently holding (if the weapon's ammo is > 0).

Parameters:
weapon -
Returns:
whether we have changed the weapon (i.e., we have some ammo for it), or we already have it prepared (i.e., is our current weapon).

getAmmo

public int getAmmo(ItemType ammoOrWeaponType)
Returns an amount of ammo of 'ammoOrWeaponType' the bot currently has.

If an ammo type is passed - exact number is returned.

If an weapon type is passed - its primary + secondary ammo amount is returned.

If an invalid 'ammoType' is passed, 0 is returned.

Parameters:
ammoType -
Returns:
amount of ammo of 'ammoType'

getPrimaryWeaponAmmo

public int getPrimaryWeaponAmmo(ItemType weaponType)
Returns an amount of primary ammo of a given 'weaponType' the bot currently has.

If an invalid 'weaponType' is passed, 0 is returned.

Parameters:
weaponType -
Returns:
amount of primary ammo of the given 'weaponType'

getSecondaryWeaponAmmo

public int getSecondaryWeaponAmmo(ItemType weaponType)
Returns an amount of secondary ammo of a given 'weaponType' the bot currently has.

If an invalid 'weaponType' is passed, 0 is returned.

Parameters:
weaponType -
Returns:
amount of secondary ammo of the given 'weaponType'

getWeaponAmmo

public int getWeaponAmmo(ItemType weaponType)
Returns an amount of primary+secondary ammo of a given 'weaponType' the bot currently has.

If an invalid 'weaponType' is passed, 0 is returned.

Parameters:
weaponType -
Returns:
amount of primary+secondary ammo of the given 'weaponType'

hasLowAmmoForWeapon

public boolean hasLowAmmoForWeapon(ItemType weaponType,
                                   double lowRatio)
Tells whether the bot has low-ammo for "weaponType" (either primary/secondary).

Low ammo is: currAmmmo / maxAmmo < lowRatio

Parameters:
weaponType -
lowRatio -
Returns:

hasSecondaryLowAmmoForWeapon

public boolean hasSecondaryLowAmmoForWeapon(ItemType weaponType,
                                            double lowRatio)
Tells whether the bot has secondary low-ammo for "weaponType"

Low ammo is: currAmmmo / maxAmmo < lowRatio

Parameters:
weaponType -
lowRatio -
Returns:

hasPrimaryLowAmmoForWeapon

public boolean hasPrimaryLowAmmoForWeapon(ItemType weaponType,
                                          double lowRatio)
Tells whether the bot has primary low-ammo for "weaponType"

Low ammo is: currAmmmo / maxAmmo < lowRatio

Parameters:
weaponType -
lowRatio -
Returns:

hasAmmo

public boolean hasAmmo(ItemType ammoType)
Tells whether the bot has an ammo of 'ammoType'.

If an invalid 'ammoType' is passed, false is returned.

Parameters:
ammoType -
Returns:
True, if the bot has at least one ammo of 'ammoType'.

hasAmmoForWeapon

public boolean hasAmmoForWeapon(ItemType weaponType)
Alias for hasWeaponAmmo(ItemType).

Parameters:
weaponType -
Returns:
True, if the bot has any ammo for a 'weaponType'.
See Also:
hasWeaponAmmo(ItemType)

hasWeaponAmmo

public boolean hasWeaponAmmo(ItemType weaponType)
Tells whether the bot has an ammo (either primary or secondary) for a given 'weaponType'.

If an invalid 'weaponType' is passed, false is returned.

Parameters:
weaponType -
Returns:
True, if the bot has any ammo for a 'weaponType'.

hasPrimaryWeaponAmmo

public boolean hasPrimaryWeaponAmmo(ItemType weaponType)
Tells whether the bot has a primary ammo for a given 'weaponType'.

If an invalid 'weaponType' is passed, false is returned.

Parameters:
weaponType -
Returns:
True, if the bot has primary ammo for a 'weaponType'.

hasSecondaryWeaponAmmo

public boolean hasSecondaryWeaponAmmo(ItemType weaponType)
Tells whether the bot has a secondary ammo for a given 'weaponType'.

If an invalid 'weaponType' is passed, false is returned.

Parameters:
weaponType -
Returns:
True, if the bot has secondary ammo for a 'weaponType'.

hasWeapon

public boolean hasWeapon(ItemType weaponType)
Tells, whether specific weapon is in the agent's inventory.

If an invalid 'weaponType' is passed, false is returned.

Parameters:
weaponType - type of the weapon
Returns:
True, if the requested weapon is present; false otherwise.

hasWeapon

public boolean hasWeapon(ItemType.Group weaponGroup)
Tells, whether a weapon from the specific group is in the agent's inventory.

If an invalid 'weaponGroup' is passed, false is returned.

Parameters:
weaponGroup - group of the weapon
Returns:
True, if the requested weapon is present; false otherwise.

isLoaded

public boolean isLoaded(ItemType weaponType)
Tells, whether specific weapon is in the agent's inventory && is loaded (has at least 1 primary or secondary ammo).

If an invalid 'weaponType' is passed, false is returned.

Parameters:
weaponType - type of the weapon
Returns:
True, if the requested weapon is present && is loaded; false otherwise.

isLoaded

public boolean isLoaded(ItemType.Group weaponGroup)
Tells, whether a weapon from a specific group is in the agent's inventory && is loaded (has at least 1 primary or secondary ammo).

If an invalid 'weaponGroup' is passed, false is returned.

Parameters:
weaponType - type of the weapon
Returns:
True, if the requested weapon is present && is loaded; false otherwise.

hasSecondaryAmmoType

public boolean hasSecondaryAmmoType(ItemType weaponType)
Whether the weapon has secondary ammo different from the primary.

If an invalid 'weaponType' is passed, false is returned.

Parameters:
weaponType -
Returns:

getWeaponDescriptor

public WeaponDescriptor getWeaponDescriptor(ItemType weaponType)
Returns a WeaponDescriptor for a given 'weaponType' (if it is not a weapon, returns null).

The descriptor can be used to reason about the weapon suitability for actual combat.

Parameters:
weaponType -
Returns:
weapon descriptor

getCurrentWeapon

public Weapon getCurrentWeapon()
Retrieves current weapon from the agent's inventory.

Returns:
Current weapon from inventory; or null upon no current weapon.
See Also:
getCurrentPrimaryAmmo(), getCurrentAlternateAmmo(), AgentInfo.getCurrentWeapon()

getCurrentAmmo

public int getCurrentAmmo()
Tells, how much ammo is in the agent's inventory for current weapon - primary + (if has different secondary ammo type) alternate (secondary).

Returns:
Amount of ammo in the inventory.
See Also:
getCurrentPrimaryAmmo(), getCurrentAlternateAmmo(), AgentInfo.getCurrentAmmo()

getCurrentPrimaryAmmo

public int getCurrentPrimaryAmmo()
Tells, how much ammo is in the agent's inventory for current weapon.

Returns:
Amount of primary ammo for the current weapon.
See Also:
getCurrentAlternateAmmo(), AgentInfo.getCurrentAmmo()

getCurrentAlternateAmmo

public int getCurrentAlternateAmmo()
Tells, how much ammo is in the agent's inventory for current weapon for alternate firing mode. (If the weapon consumes primary ammo for alternate firing mode it returns the same number as getCurrentPrimaryAmmo().

Returns:
Amount of ammo in the inventory for alternate fire mode.
See Also:
getCurrentPrimaryAmmo(), AgentInfo.getCurrentSecondaryAmmo()

getWeapons

public java.util.Map<ItemType,Weapon> getWeapons()
Retrieves all weapons from the agent's inventory.

NOTE: Returned map can't be modified.

NOTE: The Weapon instance is invalidated by BotKilled event, discard the instance upon bot's death.

Returns:
List of all available weapons from inventory.
See Also:
hasLoadedWeapon(), getLoadedMeleeWeapons(), getLoadedRangedWeapons()

getWeapon

public Weapon getWeapon(ItemType weaponType)
Returns Weapon instance for given 'weaponType' if the bot posses it.

Parameters:
weaponType -
Returns:
Weapon
See Also:
getWeapons()

getLoadedWeapons

public java.util.Map<ItemType,Weapon> getLoadedWeapons()
Retrieves all loaded weapons from the agent's inventory.

Note: Shield guns are never treated as loaded weapons, though they are usually loaded, i.e. ready to be fired.

NOTE: Returned map can't be modified.

NOTE: The Weapon instance is invalidated by BotKilled event, discard the instance upon bot's death.

Returns:
List of all available weapons from inventory.
See Also:
hasLoadedWeapon(), getLoadedMeleeWeapons(), getLoadedRangedWeapons()

getMeleeWeapons

public java.util.Map<ItemType,Weapon> getMeleeWeapons()
Retrieves melee weapons from the agent's inventory.

NOTE: Returned map can't be modified.

NOTE: The Weapon instance is invalidated by BotKilled event, discard the instance upon bot's death.

Returns:
List of all available melee weapons from inventory.
See Also:
getLoadedMeleeWeapons()

getRangedWeapons

public java.util.Map<ItemType,Weapon> getRangedWeapons()
Retrieves ranged weapons from the agent's inventory.

NOTE: Returned map can't be modified.

NOTE: The Weapon instance is invalidated by BotKilled event, discard the instance upon bot's death.

Returns:
List of all available ranged weapons from inventory.
See Also:
getLoadedRangedWeapons()

getLoadedMeleeWeapons

public java.util.Map<ItemType,Weapon> getLoadedMeleeWeapons()
Retrieves loaded melee weapons from the agent's inventory.

NOTE: Returned map can't be modified.

NOTE: The Weapon instance is invalidated by BotKilled event, discard the instance upon bot's death.

Returns:
List of all available melee weapons from inventory.
See Also:
getMeleeWeapons()

getLoadedRangedWeapons

public java.util.Map<ItemType,Weapon> getLoadedRangedWeapons()
Retrieves loaded ranged weapons from the agent's inventory.

NOTE: Returned map can't be modified.

NOTE: The Weapon instance is invalidated by BotKilled event, discard the instance upon bot's death.

Returns:
List of all available loaded ranged weapons from inventory.
See Also:
getRangedWeapons()

getAmmos

public java.util.Map<ItemType,java.lang.Integer> getAmmos()
Returns a map with current state of ammo (ammo for owned weapons as well as ammo for weapons that the bot do not have yet).

NOTE: Returned map can't be modified.

Returns:

hasLoadedWeapon

public boolean hasLoadedWeapon()
Tells, whether the agent has any loaded weapon in the inventory.

Note: Shield guns are never treated as loaded weapons, though they are usually loaded, i.e. ready to be fired.

Returns:
True, if there is a loaded weapon in the inventory.
See Also:
getLoadedWeapons()

hasLoadedRangedWeapon

public boolean hasLoadedRangedWeapon()
Tells, whether the agent has any loaded ranged weapon in the inventory.

Returns:
True, if there is a loaded ranged weapon in the inventory.
See Also:
getLoadedRangedWeapons()

hasLoadedMeleeWeapon

public boolean hasLoadedMeleeWeapon()
Tells, whether the agent has any loaded melee weapon in the inventory.

Note: Shield guns are never treated as loaded weapons, though they are usually loaded, i.e. ready to be fired.

Returns:
True, if there is a loaded melee weapon in the inventory.
See Also:
getLoadedMeleeWeapons()

hasLoadedWeapon

public boolean hasLoadedWeapon(ItemType weapon)
Whether the bot possess 'weapon' that has primary or secondary ammo.

Parameters:
weapon -
Returns:

hasPrimaryLoadedWeapon

public boolean hasPrimaryLoadedWeapon(ItemType weapon)
Whether the bot possess 'weapon' that has primary ammo.

Parameters:
weapon -
Returns:

hasSecondaryLoadedWeapon

public boolean hasSecondaryLoadedWeapon(ItemType weapon)
Whether the bot possess 'weapon' that has secondary ammo.

Parameters:
weapon -
Returns:

getWeaponForAmmo

public ItemType getWeaponForAmmo(ItemType priOrSecAmmoType)
Returns weaponType for a given ammoType (regardles whether it is primary or secondary ammo type).

Parameters:
priOrSecAmmoType -
Returns:

getPrimaryWeaponAmmoType

public ItemType getPrimaryWeaponAmmoType(ItemType weaponType)
Return primary-ammo ItemType for a weapon.

Parameters:
weaponType -
Returns:

getSecondaryWeaponAmmoType

public ItemType getSecondaryWeaponAmmoType(ItemType weaponType)
Return secondary-ammo ItemType for a weapon.

Parameters:
weaponType -
Returns:

cleanUp

protected void cleanUp()
Description copied from class: AgentModule
Hook where to perform clean up of data structures of the module.

Called from AgentModule.stop(), AgentModule.kill(), AgentModule.reset().

Overrides:
cleanUp in class AgentModule<UT2004Bot>