cz.cuni.amis.pogamut.ut2004.agent.module.sensor
Class Items

Package class diagram package Items
java.lang.Object
  extended by cz.cuni.amis.pogamut.base.agent.module.AgentModule<AGENT>
      extended by cz.cuni.amis.pogamut.base.agent.module.SensorModule<UT2004Bot>
          extended by cz.cuni.amis.pogamut.ut2004.agent.module.sensor.Items
All Implemented Interfaces:
cz.cuni.amis.pogamut.base.component.IComponent

public class Items
extends cz.cuni.amis.pogamut.base.agent.module.SensorModule<UT2004Bot>

Memory module specialized on items on the map.

Apart from providing useful getters based on ItemType, ItemType.Group and ItemType.Category it also provides an optimistic approach for guessing whether some item is spawned inside the map via getSpawnedXYZ methods such as getSpawnedItems().

WARNING:There are methods that contains "reachable" in its name but it is totally unclear what UT2004 means by reachable!!! These methods are for experimenting purposes only.

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.

Author:
Juraj 'Loque' Simlovic, Jimmy

Nested Class Summary
protected  class Items.EndMessageListener
          EndMessage listener.
protected  class Items.ItemPickedUpListener
          ItemPickedUp listener.
protected  class Items.ItemsListener
           
protected  class Items.MapPointsListener
          MapPointsListObtained listener.
protected  class Items.NavPointListener
          MapPointsListObtained listener.
 
Field Summary
protected  AgentInfo agentInfo
          AgentInfo memory module.
protected  Items.EndMessageListener endMessageListener
           
protected  Items.ItemPickedUpListener itemPickedUpListener
           
protected  Items.ItemsListener itemsListener
           
protected  Items.MapPointsListener mapPointsListener
          MapPointsListObtained listener
protected  Items.NavPointListener navPointListener
           
protected  Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,NavPoint> navPoints
           
protected  List<NavPoint> navPointsToProcess
          Contains only navpoints that are visible so we can check whether they are spawning-points, if so - we may check whether the item is laying there or not to handle spawning times.
 
Fields inherited from class cz.cuni.amis.pogamut.base.agent.module.SensorModule
worldView
 
Fields inherited from class cz.cuni.amis.pogamut.base.agent.module.AgentModule
agent, controller, eventBus, log
 
Constructor Summary
Items(UT2004Bot bot)
          Constructor.
Items(UT2004Bot bot, AgentInfo agentInfo, Game game, Weaponry weaponry, Logger log)
          Constructor.
 
Method Summary
protected  void cleanUp()
           
protected  Items.ItemsListener createItemsListener(cz.cuni.amis.pogamut.base.communication.worldview.IWorldView worldView)
          This method is called from the constructor to hook a listener that updated the items field.
protected  Items.MapPointsListener createMapPointsListener(cz.cuni.amis.pogamut.base.communication.worldview.IWorldView worldView)
          This method is called from the constructor to create a listener that initialize items field from the MapPointListObtained event.
 Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getAllItems()
          Retrieves list of all items, which includes all known pickups and all visible thrown items.
 Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getAllItems(ItemType.Category category)
          Retrieves map of all items belonging to a specific 'category' of items, which includes all known pickups.
 Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getAllItems(ItemType.Group group)
          Retrieves map of all items belonging to a specific 'group' of items, which includes all known pickups.
 Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getAllItems(ItemType type)
          Retrieves list of all items of specific type.
 Item getItem(String stringUnrealId)
          Retrieves a specific item from the all items in the map.
 Item getItem(cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId id)
          Retrieves a specific item from the all items in the map.
 double getItemRespawnTime(Item item)
          Returns how fast are the items respawning based on their item type (in real seconds according to System.currentTimeMillis().
 double getItemRespawnTime(ItemType itemType)
          Returns how fast are the items respawning based on their item type (in real seconds according to System.currentTimeMillis().
 double getItemRespawnUT2004Time(Item item)
          Returns how fast are the items respawning based on their item type (in UT Time == UT seconds == UnrealUtils.UT2004_TIME_SPEED * 1 seconds).
 double getItemRespawnUT2004Time(ItemType itemType)
          Returns how fast are the items respawning based on their item type (in UT Time == UT seconds == UnrealUtils.UT2004_TIME_SPEED * 1 seconds).
 Item getKnownPickup(String stringUnrealId)
          Retrieves a specific pickup point.
 Item getKnownPickup(cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId id)
          Retrieves a specific pickup point.
 Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getKnownPickups()
          Retrieves list of all known item pickup points.
 Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getKnownPickups(ItemType.Category category)
          Retrieves map of all known pickups belonging to a specific 'category' of items, which includes all known pickups.
 Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getKnownPickups(ItemType.Group group)
          Retrieves map of all known pickups belonging to a specific 'group' of items, which includes all known pickups.
 Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getKnownPickups(ItemType type)
          Retrieves list of all known item pickup points of specific type.
 Item getRandomItem()
          Returns random item from 'all' items.
 Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getSpawnedItems()
          Uses isPickupSpawned(Item) to return all items that are believed to be currently spawned.
 Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getSpawnedItems(ItemType.Category category)
          Uses isPickupSpawned(Item) to return all items belonging to a specific 'category' that are believed to be currently spawned.
 Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getSpawnedItems(ItemType.Group group)
          Uses isPickupSpawned(Item) to return all items belonging to a specific 'group' that are believed to be currently spawned.
 Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getSpawnedItems(ItemType type)
          Uses isPickupSpawned(Item) to return all items of 'type' that are believed to be currently spawned.
 Item getVisibleItem(String stringUnrealId)
          Retrieves a specific item from the visible items in the map.
 Item getVisibleItem(cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId id)
          Retrieves a specific item from the visible items in the map.
 Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getVisibleItems()
          Retreives list of all visible items, which includes all visible known pickups and all visible thrown items.
 Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getVisibleItems(ItemType.Category category)
          Retrieves map of visible items belonging to a specific 'category' of items, which includes all known pickups.
 Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getVisibleItems(ItemType.Group group)
          Retrieves map of visible items belonging to a specific 'group' of items, which includes all known pickups.
 Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getVisibleItems(ItemType type)
          Retreives list of all visible items of specific type, which includes all visible known pickups and all visible thrown items.
 boolean isPickable(Item item)
          Method that determines whether 'item' is pickable in the current state of the bot.
 boolean isPickupSpawned(Item item)
          Tells, whether the given pickup point contains a spawned item.
 boolean isPickupSpawned(cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId itemId)
          Tells, whether the given pickup point contains a spawned item.
 
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
 

Field Detail

itemsListener

protected Items.ItemsListener itemsListener

mapPointsListener

protected Items.MapPointsListener mapPointsListener
MapPointsListObtained listener


navPoints

protected Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,NavPoint> navPoints

navPointsToProcess

protected List<NavPoint> navPointsToProcess
Contains only navpoints that are visible so we can check whether they are spawning-points, if so - we may check whether the item is laying there or not to handle spawning times.


navPointListener

protected Items.NavPointListener navPointListener

endMessageListener

protected Items.EndMessageListener endMessageListener

itemPickedUpListener

protected Items.ItemPickedUpListener itemPickedUpListener

agentInfo

protected AgentInfo agentInfo
AgentInfo memory module.

Constructor Detail

Items

public Items(UT2004Bot bot)
Constructor. Setups the memory module based on bot's world view.

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

Items

public Items(UT2004Bot bot,
             AgentInfo agentInfo,
             Game game,
             Weaponry weaponry,
             Logger log)
Constructor. Setups the memory module based on bot's world view.

Parameters:
bot - owner of the module that is using it
agentInfo - AgentInfo memory module
log - Logger to be used for logging runtime/debug info, if null is provided the module creates its own logger
Method Detail

isPickable

public boolean isPickable(Item item)
Method that determines whether 'item' is pickable in the current state of the bot. E.g., it asseses health for health items, ammo for weapons & ammo, etc.

Contributed by: David Holan

Parameters:
item -
Returns:

getRandomItem

public Item getRandomItem()
Returns random item from 'all' items.

Note that there is no need to provide all "getRandomXYZ(xyz)", just use MyCollections.getRandom(java.util.Collection).

Returns:

getAllItems

public Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getAllItems()
Retrieves list of all items, which includes all known pickups and all visible thrown items.

Note: The returned Map is unmodifiable and self updating throughout time. Once you obtain a specific Map of items from this module, the Map will get updated based on what happens within the map.

Returns:
List of all items. Note: Spawned items are included only.

getAllItems

public Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getAllItems(ItemType type)
Retrieves list of all items of specific type.

Note: The returned Map is unmodifiable and self updating throughout time. Once you obtain a specific Map of items from this module, the Map will get updated based on what happens within the map.

Returns:
List of all items of specific type. Note: Spawned items are included only.

getAllItems

public Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getAllItems(ItemType.Category category)
Retrieves map of all items belonging to a specific 'category' of items, which includes all known pickups.

Note: The returned Map is modifiable and is always constructed upon every invocation of this method.

WARNING: O(n) complexity!

Parameters:
category -
Returns:
Map of all items of a specific category.

getAllItems

public Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getAllItems(ItemType.Group group)
Retrieves map of all items belonging to a specific 'group' of items, which includes all known pickups.

Note: The returned Map is modifiable and is always constructed upon every invocation of this method.

WARNING: O(n) complexity!

Parameters:
group -
Returns:
Map of all items of a specific group.

getItem

public Item getItem(cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId id)
Retrieves a specific item from the all items in the map.

Once obtained it is self-updating based on what happens in the game.

Parameters:
id -
Returns:
A specific Item be it Spawned or Dropped (Dropped item must be visible though!).

getItem

public Item getItem(String stringUnrealId)
Retrieves a specific item from the all items in the map.

Once obtained it is self-updating based on what happens in the game.

Parameters:
stringUnrealId -
Returns:
A specific Item be it Spawned or Dropped (Dropped item must be visible though!).

getVisibleItems

public Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getVisibleItems()
Retreives list of all visible items, which includes all visible known pickups and all visible thrown items.

Note: The returned Map is unmodifiable and self updating throughout time. Once you obtain a specific Map of items from this module, the Map will get updated based on what happens within the map.

Returns:
List of all visible items. Note: Spawned items are included only.

getVisibleItems

public Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getVisibleItems(ItemType type)
Retreives list of all visible items of specific type, which includes all visible known pickups and all visible thrown items.

Note: The returned Map is unmodifiable and self updating throughout time. Once you obtain a specific Map of items from this module, the Map will get updated based on what happens within the map.

Returns:
List of all visible items of specific type. Note: Spawned items are included only.

getVisibleItems

public Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getVisibleItems(ItemType.Category category)
Retrieves map of visible items belonging to a specific 'category' of items, which includes all known pickups.

Note: The returned Map is modifiable and is always constructed upon every invocation of this method.

WARNING: O(n) complexity!

Parameters:
category -
Returns:
Map of visible items of a specific category.

getVisibleItems

public Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getVisibleItems(ItemType.Group group)
Retrieves map of visible items belonging to a specific 'group' of items, which includes all known pickups.

Note: The returned Map is modifiable and is always constructed upon every invocation of this method.

WARNING: O(n) complexity!

Parameters:
group -
Returns:
Map of visible items of a specific group.

getVisibleItem

public Item getVisibleItem(cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId id)
Retrieves a specific item from the visible items in the map. If item of specified id is not visible returns null.

Once obtained it is self-updating based on what happens in the game.

Parameters:
id -
Returns:
A specific Item be it Spawned or Dropped.

getVisibleItem

public Item getVisibleItem(String stringUnrealId)
Retrieves a specific item from the visible items in the map. If item of specified id is not visible returns null.

Once obtained it is self-updating based on what happens in the game.

Parameters:
stringUnrealId -
Returns:
A specific Item be it Spawned or Dropped.

getKnownPickups

public Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getKnownPickups()
Retrieves list of all known item pickup points.

Note: The returned Map is unmodifiable and self updating throughout time. Once you obtain a specific Map of items from this module, the Map will get updated based on what happens within the map.

Returns:
List of all items. Note: Empty pickups are included as well.
See Also:
isPickupSpawned(Item)

getKnownPickups

public Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getKnownPickups(ItemType type)
Retrieves list of all known item pickup points of specific type.

Note: The returned Map is unmodifiable and self updating throughout time. Once you obtain a specific Map of items from this module, the Map will get updated based on what happens within the map.

Returns:
List of all items of specific type. Note: Empty pickups are included as well.
See Also:
isPickupSpawned(Item)

getKnownPickups

public Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getKnownPickups(ItemType.Category category)
Retrieves map of all known pickups belonging to a specific 'category' of items, which includes all known pickups.

Note: The returned Map is modifiable and is always constructed upon every invocation of this method.

WARNING: O(n) complexity!

Parameters:
category -
Returns:
Map of known pickups of a specific category.

getKnownPickups

public Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getKnownPickups(ItemType.Group group)
Retrieves map of all known pickups belonging to a specific 'group' of items, which includes all known pickups.

Note: The returned Map is modifiable and is always constructed upon every invocation of this method.

WARNING: O(n) complexity!

Parameters:
group -
Returns:
Map of known pickups of a specific group.

getKnownPickup

public Item getKnownPickup(cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId id)
Retrieves a specific pickup point.

Once obtained it is self-updating based on what happens in the game.

Parameters:
id -
Returns:
A specific Item be it Spawned or Dropped (Dropped item must be visible though!).

getKnownPickup

public Item getKnownPickup(String stringUnrealId)
Retrieves a specific pickup point.

Once obtained it is self-updating based on what happens in the game.

Parameters:
stringUnrealId -
Returns:
A specific Item be it Spawned or Dropped (Dropped item must be visible though!).

getSpawnedItems

public Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getSpawnedItems()
Uses isPickupSpawned(Item) to return all items that are believed to be currently spawned.

WARNING: O(n) complexity!

Returns:
collection of spawned items

getSpawnedItems

public Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getSpawnedItems(ItemType type)
Uses isPickupSpawned(Item) to return all items of 'type' that are believed to be currently spawned.

WARNING: O(n) complexity!

Returns:
Map of spawned items of a specific type.

getSpawnedItems

public Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getSpawnedItems(ItemType.Category category)
Uses isPickupSpawned(Item) to return all items belonging to a specific 'category' that are believed to be currently spawned.

Note: The returned Map is modifiable and is always constructed upon every invocation of this method.

WARNING: O(n) complexity!

Parameters:
category -
Returns:
Map of spawned items of a specific category.

getSpawnedItems

public Map<cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId,Item> getSpawnedItems(ItemType.Group group)
Uses isPickupSpawned(Item) to return all items belonging to a specific 'group' that are believed to be currently spawned.

Note: The returned Map is modifiable and is always constructed upon every invocation of this method.

WARNING: O(n) complexity!

Parameters:
group -
Returns:
Map of spawned items of a specific group.

getItemRespawnUT2004Time

public double getItemRespawnUT2004Time(Item item)
Returns how fast are the items respawning based on their item type (in UT Time == UT seconds == UnrealUtils.UT2004_TIME_SPEED * 1 seconds).

Parameters:
item -
Returns:

getItemRespawnUT2004Time

public double getItemRespawnUT2004Time(ItemType itemType)
Returns how fast are the items respawning based on their item type (in UT Time == UT seconds == UnrealUtils.UT2004_TIME_SPEED * 1 seconds).

Parameters:
itemType -
Returns:

getItemRespawnTime

public double getItemRespawnTime(Item item)
Returns how fast are the items respawning based on their item type (in real seconds according to System.currentTimeMillis().

Parameters:
item -
Returns:

getItemRespawnTime

public double getItemRespawnTime(ItemType itemType)
Returns how fast are the items respawning based on their item type (in real seconds according to System.currentTimeMillis().

Parameters:
itemType -
Returns:

isPickupSpawned

public boolean isPickupSpawned(Item item)
Tells, whether the given pickup point contains a spawned item.

This implementation is guessing (optimistically) whether the item is spawned based on the last time we have seen it missing (bot has seen its spawning-navpoint but the item was not laying there).

Note that the guessing is not perfect, experiment with it or check the source code and possibly reimplement (probably copy-paste) to suit your needs.

Note that this method is working correctly only if items are respawning.

Parameters:
item - Item, for which its pickup point is to be examined.
Returns:
True, if the item is spawned; false if the pickup is empty.
See Also:
getKnownPickups(boolean,boolean)

isPickupSpawned

public boolean isPickupSpawned(cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId itemId)
Tells, whether the given pickup point contains a spawned item.

This implementation is guessing (optimistically) whether the item is spawned based on the last time we have seen it missing (saw its navpoint but the item was not laying there).

Note that the guessing is not perfect, experiment with it or check the source code and possibly reimplement to suit your needs.

Note that this method is working only if items are respawning.

Parameters:
itemId - Id of the item, for which its pickup point is to be examined.
Returns:
True, if the item is spawned; false if the pickup is empty.
See Also:
getKnownPickups(boolean,boolean)

createItemsListener

protected Items.ItemsListener createItemsListener(cz.cuni.amis.pogamut.base.communication.worldview.IWorldView worldView)
This method is called from the constructor to hook a listener that updated the items field.

It must:

  1. initialize itemsListener field
  2. hook the listener to the world view

By overriding this method you may provide your own listener that may wrap Items with your class adding new fields into them.

Parameters:
worldView -

createMapPointsListener

protected Items.MapPointsListener createMapPointsListener(cz.cuni.amis.pogamut.base.communication.worldview.IWorldView worldView)
This method is called from the constructor to create a listener that initialize items field from the MapPointListObtained event.

By overriding this method you may provide your own listener that may wrap Items with your class adding new fields into them.

Parameters:
worldView -
Returns:

cleanUp

protected void cleanUp()
Overrides:
cleanUp in class cz.cuni.amis.pogamut.base.agent.module.AgentModule<UT2004Bot>


Copyright © 2012 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.