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

java.lang.Object
  extended by cz.cuni.amis.pogamut.ut2004.agent.module.sensor.WeaponPrefs

public class WeaponPrefs
extends java.lang.Object

Class that allows you to easily define weapon preferences for your bot as well as time how often you may change your weapon.

Use this class in IUT2004BotController.prepareBot(UT2004Bot), i.e., use methods such as addGeneralPref(ItemType, boolean), newPrefsRange(double), WeaponPrefsRange.add(ItemType, boolean).

Preferences are never automatically wiped out!


Field Summary
protected  UT2004Bot bot
           
protected  WeaponPrefsRange generalPrefs
           
protected  WeaponPrefs onlyGeneral
           
protected  java.util.List<WeaponPrefsRange> prefs
           
protected  Weaponry weaponry
           
 
Constructor Summary
  WeaponPrefs(Weaponry weaponry, UT2004Bot bot)
           
protected WeaponPrefs(Weaponry weaponry, UT2004Bot bot, WeaponPrefsRange generalPrefs)
           
 
Method Summary
 WeaponPrefs addGeneralPref(ItemType weapon, boolean usePrimaryMode)
          Adds another weapon as "the least preferable" one into general-preferences (used if no weapons are found for a given range) You may define weapons from the most preferred to the least preferred by sequentially calling this method.
 WeaponPrefs addGeneralPref(Weapon weapon, boolean usePrimaryMode)
          Adds another weapon as "the least preferable" one into general-preferences (used if no weapons are found for a given range) You may define weapons from the most preferred to the least preferred by sequentially calling this method.
 WeaponPrefs asGeneralOnly()
          Return weapon preferences that has only "general" weapon preferences, might come in handy.
 void clearAllPrefs()
          Removes all weapon preferences.
protected  WeaponPrefsRange getPreviousRange(WeaponPrefsRange weaponPrefsRange)
          Get range that is right after "weaponPrefsRange".
 WeaponPref getWeaponPreference()
          Return the best weapon according ONLY general preferences.
 WeaponPref getWeaponPreference(double distance)
          Return the best weapon the bot has for a given distance (choosing right weapon preferances for a given distance).
 WeaponPref getWeaponPreference(double distance, ItemType... forbiddenWeapons)
          Return the best weapon the bot has for a given distance (choosing right weapon preferances for a given distance).
 WeaponPref getWeaponPreference(double distance, WeaponPref... forbiddenWeapons)
          Return the best weapon the bot has for a given distance (choosing right weapon preferances for a given distance).
 WeaponPref getWeaponPreference(ILocated target)
          Return the best weapon the bot has to shoot at given location (choosing right weapon preferances for a given distance).
 WeaponPref getWeaponPreference(ILocated target, ItemType... forbiddenWeapons)
          Return the best weapon the bot has to shoot at given location (choosing right weapon preferances for a given distance).
 WeaponPref getWeaponPreference(ILocated target, WeaponPref... forbiddenWeapons)
          Return the best weapon the bot has to shoot at given location (choosing right weapon preferances for a given distance).
 WeaponPref getWeaponPreference(ItemType... forbiddenWeapons)
          Return the best weapon according ONLY general preferences.
 WeaponPref getWeaponPreference(WeaponPref... forbiddenWeapons)
          Return the best weapon according ONLY general preferences.
 WeaponPrefsRange getWeaponPreferences(double distance)
          Get preferences for a given distance.
 WeaponPrefsRange newPrefsRange(double maxDistance)
          Creates new WeaponPrefsRange, these weapon will be used when the target is at "maxDistance" afar.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

prefs

protected java.util.List<WeaponPrefsRange> prefs

weaponry

protected Weaponry weaponry

bot

protected UT2004Bot bot

generalPrefs

protected WeaponPrefsRange generalPrefs

onlyGeneral

protected WeaponPrefs onlyGeneral
Constructor Detail

WeaponPrefs

public WeaponPrefs(Weaponry weaponry,
                   UT2004Bot bot)

WeaponPrefs

protected WeaponPrefs(Weaponry weaponry,
                      UT2004Bot bot,
                      WeaponPrefsRange generalPrefs)
Method Detail

asGeneralOnly

public WeaponPrefs asGeneralOnly()
Return weapon preferences that has only "general" weapon preferences, might come in handy.

WARNING: returned prefs are IMMUTABLE! You can't invoke method newPrefsRange(double), addGeneralPref(ItemType, boolean) or addGeneralPref(Weapon, boolean).

Returns:

clearAllPrefs

public void clearAllPrefs()
Removes all weapon preferences.


addGeneralPref

public WeaponPrefs addGeneralPref(ItemType weapon,
                                  boolean usePrimaryMode)
Adds another weapon as "the least preferable" one into general-preferences (used if no weapons are found for a given range) You may define weapons from the most preferred to the least preferred by sequentially calling this method.

Parameters:
weapon - weapon to be used
usePrimaryMode - true == use primary firing mode, false == use secondary firing mode

addGeneralPref

public WeaponPrefs addGeneralPref(Weapon weapon,
                                  boolean usePrimaryMode)
Adds another weapon as "the least preferable" one into general-preferences (used if no weapons are found for a given range) You may define weapons from the most preferred to the least preferred by sequentially calling this method.

Parameters:
weapon - weapon to be used
usePrimaryMode - true == use primary firing mode, false == use secondary firing mode

newPrefsRange

public WeaponPrefsRange newPrefsRange(double maxDistance)
Creates new WeaponPrefsRange, these weapon will be used when the target is at "maxDistance" afar. Lower bound (minDistance) is then define by previous WeaponPrefsRange object (if such exist, otherwise it is 0).

Parameters:
maxDistance -
Returns:

getWeaponPreferences

public WeaponPrefsRange getWeaponPreferences(double distance)
Get preferences for a given distance.

Distance may be negative == will choose only from the general preferences.

If no "ranges" are defined (no newPrefsRange(double) has been used), it returns generalPrefs.

Parameters:
distance -
Returns:

getPreviousRange

protected WeaponPrefsRange getPreviousRange(WeaponPrefsRange weaponPrefsRange)
Get range that is right after "weaponPrefsRange".

Parameters:
weaponPrefsRange -
Returns:

getWeaponPreference

public WeaponPref getWeaponPreference(double distance,
                                      ItemType... forbiddenWeapons)
Return the best weapon the bot has for a given distance (choosing right weapon preferances for a given distance).

May return null if "general preferences are not defined" or the bot does not have ammo to any of defined weapons.

Note that it may actually return "forbiddenWeapon" in the case that the bot does not have ammo for any other "more preferred" weapon but has ammo for some of forbiddenWeapon.

If distance < 0, only general preferences will be used.

Parameters:
distance -
forbiddenWeapons - optionally, you may define weapons which bot should not choose (i.e. ItemType.ROCKET_LAUNCHER)
Returns:

getWeaponPreference

public WeaponPref getWeaponPreference(ILocated target,
                                      ItemType... forbiddenWeapons)
Return the best weapon the bot has to shoot at given location (choosing right weapon preferances for a given distance).

May return null if "general preferences are not defined" or the bot does not have ammo to any of defined weapons.

If target is null, only general preferences will be used.

Parameters:
target -
forbiddenWeapons - optionally, you may define weapons which bot should not choose (i.e. ItemType.ROCKET_LAUNCHER)
Returns:

getWeaponPreference

public WeaponPref getWeaponPreference(ItemType... forbiddenWeapons)
Return the best weapon according ONLY general preferences.

Parameters:
forbiddenWeapons - optionally, you may define weapons which bot should not choose (i.e. ItemType.ROCKET_LAUNCHER)
Returns:

getWeaponPreference

public WeaponPref getWeaponPreference(double distance,
                                      WeaponPref... forbiddenWeapons)
Return the best weapon the bot has for a given distance (choosing right weapon preferances for a given distance).

May return null if "general preferences are not defined" or the bot does not have ammo to any of defined weapons.

Note that it may actually return "forbiddenWeapon" in the case that the bot does not have ammo for any other "more preferred" weapon but has ammo for some of forbiddenWeapon.

If distance < 0, only general preferences will be used.

Parameters:
distance -
forbiddenWeapons - optionally, you may define weapons which bot should not choose (i.e. WeaponPref#ROCKET_LAUNCHER)
Returns:

getWeaponPreference

public WeaponPref getWeaponPreference(ILocated target,
                                      WeaponPref... forbiddenWeapons)
Return the best weapon the bot has to shoot at given location (choosing right weapon preferances for a given distance).

May return null if "general preferences are not defined" or the bot does not have ammo to any of defined weapons.

If target is null, only general preferences will be used.

Parameters:
target -
forbiddenWeapons - optionally, you may define weapons which bot should not choose.
Returns:

getWeaponPreference

public WeaponPref getWeaponPreference(WeaponPref... forbiddenWeapons)
Return the best weapon according ONLY general preferences.

Parameters:
forbiddenWeapons - optionally, you may define weapons which bot should not choose.
Returns:

getWeaponPreference

public WeaponPref getWeaponPreference(double distance)
Return the best weapon the bot has for a given distance (choosing right weapon preferances for a given distance).

May return null if "general preferences are not defined" or the bot does not have ammo to any of defined weapons.

If distance < 0, only general preferences will be used.

Parameters:
distance -
Returns:

getWeaponPreference

public WeaponPref getWeaponPreference(ILocated target)
Return the best weapon the bot has to shoot at given location (choosing right weapon preferances for a given distance).

May return null if "general preferences are not defined" or the bot does not have ammo to any of defined weapons.

If target is null, only general preferences will be used.

Parameters:
target -
Returns:

getWeaponPreference

public WeaponPref getWeaponPreference()
Return the best weapon according ONLY general preferences.

Returns: