Class PointAOE

java.lang.Object
squidpony.squidai.PointAOE
All Implemented Interfaces:
Serializable, AOE

public class PointAOE
extends Object
implements AOE, Serializable
An AOE type that has a center Coord only and only affects that single Coord. Useful if you need an AOE implementation for something that does not actually affect an area. This will produce doubles for its findArea() method which are equal to 1.0. This class doesn't use any other SquidLib class to create its area of effect. Created by Tommy Ettinger on 7/13/2015.
See Also:
Serialized Form
  • Constructor Summary

    Constructors 
    Constructor Description
    PointAOE​(Coord center)  
    PointAOE​(Coord center, int minRange, int maxRange)  
  • Method Summary

    Modifier and Type Method Description
    OrderedMap<Coord,​Double> findArea()
    This is how an AOE interacts with anything that uses it.
    Coord getCenter()  
    AimLimit getLimitType()
    Gets the AimLimit enum that can be used to restrict points this checks (defaults to null if not set).
    int getMaxRange()
    The maximum inclusive range that the AOE can be shift()-ed to using the distance measurement from radiusType.
    Radius getMetric()
    Used to determine distance from origin for the purposes of selecting a target location that is within the bounds of minRange and maxRange.
    int getMinRange()
    The minimum inclusive range that the AOE can be shift()-ed to using the distance measurement from radiusType.
    Coord getOrigin()
    Get the position from which the AOE originates, which may be related to the location of the AOE's effect, as for lines, cones, and other emitted effects, or may be unrelated except for determining which enemies can be seen or targeted from a given origin point (as for distant effects that radiate from a chosen central point, but have a maxRange at which they can deliver that effect).
    Reach getReach()
    Gets the same values returned by getLimitType(), getMinRange(), getMaxRange(), and getMetric() bundled into one Reach object.
    OrderedMap<Coord,​ArrayList<Coord>> idealLocations​(Collection<Coord> targets, Collection<Coord> requiredExclusions)
    Returns a OrderedMap of Coord keys and ArrayList of Coord values, where each Coord key is an ideal location to hit as many of the Points in targets as possible without hitting any Points in requiredExclusions, and each value is the collection of targets that will be hit if the associated key is used.
    OrderedMap<Coord,​ArrayList<Coord>> idealLocations​(Collection<Coord> priorityTargets, Collection<Coord> lesserTargets, Collection<Coord> requiredExclusions)
    A variant of idealLocations that takes two groups of desirable targets, and will rate locations by how many priorityTargets are in the AOE, then by how many lesserTargets are in the AOE, and will only consider locations that do not affect a Coord in requiredExclusions.
    boolean mayContainTarget​(Collection<Coord> targets)
    Given a Set of Points that the producer of the AOE wants to include in the region of this AOE, this method does a quick approximation to see if there is any possibility that the AOE as currently configured might include one of those Points within itself.
    void setCenter​(Coord center)  
    void setLimitType​(AimLimit limitType)
    You can use limitType to restrict any Points that might be processed based on the given origin (which will be used as the geometric origin for any calculations this makes) with AimLimit values having the following meanings: AimLimit.FREE makes no restrictions; it is equivalent here to passing null for limit. AimLimit.EIGHT_WAY will only consider Points to be valid targets if they are along a straight line with an angle that is a multiple of 45 degrees, relative to the positive x axis.
    void setMap​(char[][] map)
    This must be called before any other methods, and takes a char[][] with '#' for walls, anything else for floors.
    void setMaxRange​(int maxRange)
    The maximum inclusive range that the AOE can be shift()-ed to using the distance measurement from radiusType.
    void setMetric​(Radius metric)
    Used to determine distance from origin for the purposes of selecting a target location that is within the bounds of minRange and maxRange.
    void setMinRange​(int minRange)
    The minimum inclusive range that the AOE can be shift()-ed to using the distance measurement from radiusType.
    void setOrigin​(Coord origin)
    Set the position from which the AOE originates, which may be related to the location of the AOE's effect, as for lines, cones, and other emitted effects, or may be unrelated except for determining which enemies can be seen or targeted from a given origin point (as for distant effects that radiate from a chosen central point, but have a maxRange at which they can deliver that effect).
    void setReach​(Reach reach)
    Sets the same values as setLimitType(), setMinRange(), setMaxRange(), and setMetric() using one Reach object.
    void shift​(Coord aim)
    After an AOE has been constructed, it may need to have the affected area shifted over to a different position without changing any other properties of the AOE.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • getCenter

      public Coord getCenter()
    • setCenter

      public void setCenter​(Coord center)
    • shift

      public void shift​(Coord aim)
      Description copied from interface: AOE
      After an AOE has been constructed, it may need to have the affected area shifted over to a different position without changing any other properties of the AOE. Some AOE implementations may have an origin where the AOE starts emanating from, but the origin will not be affected by this method; instead the cell specified by target must be enough on its own to select a different target area without the producer of the AOE needing to move.
      Specified by:
      shift in interface AOE
      Parameters:
      aim - a that will be used to change the location of the AOE without its producer needing to move
    • mayContainTarget

      public boolean mayContainTarget​(Collection<Coord> targets)
      Description copied from interface: AOE
      Given a Set of Points that the producer of the AOE wants to include in the region of this AOE, this method does a quick approximation to see if there is any possibility that the AOE as currently configured might include one of those Points within itself. It does not do a full, detailed scan, nor does it count how many opponents might be included. It does not check the map to verify that there is any sort of path to a target. It is recommended that the Set of Points consist only of enemies that are within FOV, which cuts down a lot on the amount of checks this needs to make; if the game doesn't restrict the player's FOV, this is still recommended (just with a larger FOV radius) because it prevents checking enemies on the other side of the map and through multiple walls.
      Specified by:
      mayContainTarget in interface AOE
      Parameters:
      targets - a Collection (usually a Set) of Points that are desirable targets to include in this AOE
      Returns:
      true if there could be at least one target within the AOE, false otherwise. Very approximate.
    • idealLocations

      public OrderedMap<Coord,​ArrayList<Coord>> idealLocations​(Collection<Coord> targets, Collection<Coord> requiredExclusions)
      Description copied from interface: AOE
      Returns a OrderedMap of Coord keys and ArrayList of Coord values, where each Coord key is an ideal location to hit as many of the Points in targets as possible without hitting any Points in requiredExclusions, and each value is the collection of targets that will be hit if the associated key is used. The length of any ArrayList in the returned collection's values will be the number of targets likely to be affected by the AOE when shift() is called with the Coord key as an argument; all of the ArrayLists should have the same length. The second argument may be null, in which case this will initialize it to an empty Set of Coord and disregard it. With complex maps and varied arrangements of obstacles and desirable targets, calculating the best points to evaluate for AI can be computationally difficult. This method provides a way to calculate with good accuracy the best Points to pass to shift(Coord) before calling findArea(). For "blackened thrash industrial death metal" levels of brutality for the AI, the results of this can be used verbatim, but for more reasonable AI levels, you can intentionally alter the best options to simulate imperfect aim or environmental variance on the AOE. Beast-like creatures that do not need devious AI should probably not use this method at all and instead use shift(Coord) with the location of some enemy (probably the closest) as its argument.
      Specified by:
      idealLocations in interface AOE
      Parameters:
      targets - a Set of Points that are desirable targets to include in this AOE
      requiredExclusions - a Set of Points that this tries strongly to avoid including in this AOE
      Returns:
      a OrderedMap of Coord keys and ArrayList of Coord values where keys are ideal locations and values are the target points that will be hit when that key is used.
    • idealLocations

      public OrderedMap<Coord,​ArrayList<Coord>> idealLocations​(Collection<Coord> priorityTargets, Collection<Coord> lesserTargets, Collection<Coord> requiredExclusions)
      Description copied from interface: AOE
      A variant of idealLocations that takes two groups of desirable targets, and will rate locations by how many priorityTargets are in the AOE, then by how many lesserTargets are in the AOE, and will only consider locations that do not affect a Coord in requiredExclusions. Unlike the variant of idealLocations that only takes one group of targets, this variant can return a collection with ArrayList values where the same Coord appears four times in the same ArrayList; this is done only for priorityTargets that are affected by the target Coord at the associated key, and is done so that the length of each similar-quality ArrayList should be identical (since a priorityTarget is worth four times what a lesserTarget is worth in the calculation this uses).
      Specified by:
      idealLocations in interface AOE
      Parameters:
      priorityTargets - A Set of Points that are the most-wanted targets to include in this AOE
      lesserTargets - A Set of Points that are the less-wanted targets to include in this AOE, should not overlap with priorityTargets
      requiredExclusions - a Set of Points that this tries strongly to avoid including in this AOE
      Returns:
      a OrderedMap of Coord keys and ArrayList of Coord values where keys are ideal locations and values are the target points that will be hit when that key is used.
    • setMap

      public void setMap​(char[][] map)
      Description copied from interface: AOE
      This must be called before any other methods, and takes a char[][] with '#' for walls, anything else for floors. It must be bounded with walls, which DungeonGenerator does automatically.
      Specified by:
      setMap in interface AOE
      Parameters:
      map - width first, height second, 2D char array.
    • findArea

      Description copied from interface: AOE
      This is how an AOE interacts with anything that uses it. It expects a map to have already been set with setMap, with '#' for walls, '.' for floors and potentially other chars that implementors can use if they are present in the map. The map must be bounded by walls, which DungeonGenerator does automatically and other generators can easily add with two loops. This returns an OrderedMap of Coord keys to Double values; if a cell is 100% affected by the AOE then the value should be 1.0; if it is 50% affected it should be 0.5, if unaffected should be 0.0, etc. The Coord keys should have the same x and y as the x,y map positions they correspond to.
      Specified by:
      findArea in interface AOE
      Returns:
      an OrderedMap of Coord keys to Double values from 1.0 (fully affected) to 0.0 (unaffected).
    • getOrigin

      public Coord getOrigin()
      Description copied from interface: AOE
      Get the position from which the AOE originates, which may be related to the location of the AOE's effect, as for lines, cones, and other emitted effects, or may be unrelated except for determining which enemies can be seen or targeted from a given origin point (as for distant effects that radiate from a chosen central point, but have a maxRange at which they can deliver that effect).
      Specified by:
      getOrigin in interface AOE
    • setOrigin

      public void setOrigin​(Coord origin)
      Description copied from interface: AOE
      Set the position from which the AOE originates, which may be related to the location of the AOE's effect, as for lines, cones, and other emitted effects, or may be unrelated except for determining which enemies can be seen or targeted from a given origin point (as for distant effects that radiate from a chosen central point, but have a maxRange at which they can deliver that effect).
      Specified by:
      setOrigin in interface AOE
    • getLimitType

      Description copied from interface: AOE
      Gets the AimLimit enum that can be used to restrict points this checks (defaults to null if not set). You can use limitType to restrict any Points that might be processed based on the given origin (which will be used as the geometric origin for any calculations this makes) with AimLimit values having the following meanings:
      • AimLimit.FREE makes no restrictions; it is equivalent here to passing null for limit.
      • AimLimit.EIGHT_WAY will only consider Points to be valid targets if they are along a straight line with an angle that is a multiple of 45 degrees, relative to the positive x axis. Essentially, this limits the points to those a queen could move to in chess.
      • AimLimit.ORTHOGONAL will cause the AOE to only consider Points to be valid targets if they are along a straight line with an angle that is a multiple of 90 degrees, relative to the positive x axis. Essentially, this limits the points to those a rook could move to in chess.
      • AimLimit.DIAGONAL will cause the AOE to only consider Points to be valid targets if they are along a straight line with an angle that is 45 degrees greater than a multiple of 90 degrees, relative to the positive x axis. Essentially, this limits the points to those a bishop could move to in chess.
      • null will cause the AOE to consider all points.
      Specified by:
      getLimitType in interface AOE
    • getMinRange

      public int getMinRange()
      Description copied from interface: AOE
      The minimum inclusive range that the AOE can be shift()-ed to using the distance measurement from radiusType.
      Specified by:
      getMinRange in interface AOE
    • getMaxRange

      public int getMaxRange()
      Description copied from interface: AOE
      The maximum inclusive range that the AOE can be shift()-ed to using the distance measurement from radiusType.
      Specified by:
      getMaxRange in interface AOE
    • getMetric

      public Radius getMetric()
      Description copied from interface: AOE
      Used to determine distance from origin for the purposes of selecting a target location that is within the bounds of minRange and maxRange. Not necessarily used for the implementation of the AOE (randomized-floodfill-based AOE should almost always use Manhattan distance for its spread due to how the algorithm works, but the positioning of where that floodfill should be allowed to start should likely follow the same distance measurement as the rest of the game, like Radius.SQUARE for Chebyshev distance/8-way movement).
      Specified by:
      getMetric in interface AOE
    • getReach

      public Reach getReach()
      Gets the same values returned by getLimitType(), getMinRange(), getMaxRange(), and getMetric() bundled into one Reach object.
      Specified by:
      getReach in interface AOE
      Returns:
      a non-null Reach object.
    • setLimitType

      public void setLimitType​(AimLimit limitType)
      Description copied from interface: AOE
      You can use limitType to restrict any Points that might be processed based on the given origin (which will be used as the geometric origin for any calculations this makes) with AimLimit values having the following meanings:
      • AimLimit.FREE makes no restrictions; it is equivalent here to passing null for limit.
      • AimLimit.EIGHT_WAY will only consider Points to be valid targets if they are along a straight line with an angle that is a multiple of 45 degrees, relative to the positive x axis. Essentially, this limits the points to those a queen could move to in chess.
      • AimLimit.ORTHOGONAL will cause the AOE to only consider Points to be valid targets if they are along a straight line with an angle that is a multiple of 90 degrees, relative to the positive x axis. Essentially, this limits the points to those a rook could move to in chess.
      • AimLimit.DIAGONAL will cause the AOE to only consider Points to be valid targets if they are along a straight line with an angle that is 45 degrees greater than a multiple of 90 degrees, relative to the positive x axis. Essentially, this limits the points to those a bishop could move to in chess.
      Points that are not valid for this limit will simply not be considered.
      Specified by:
      setLimitType in interface AOE
      Parameters:
      limitType - an AimLimit enum
    • setMinRange

      public void setMinRange​(int minRange)
      Description copied from interface: AOE
      The minimum inclusive range that the AOE can be shift()-ed to using the distance measurement from radiusType.
      Specified by:
      setMinRange in interface AOE
    • setMaxRange

      public void setMaxRange​(int maxRange)
      Description copied from interface: AOE
      The maximum inclusive range that the AOE can be shift()-ed to using the distance measurement from radiusType.
      Specified by:
      setMaxRange in interface AOE
    • setMetric

      public void setMetric​(Radius metric)
      Description copied from interface: AOE
      Used to determine distance from origin for the purposes of selecting a target location that is within the bounds of minRange and maxRange. Not necessarily used for the implementation of the AOE (randomized-floodfill-based AOE should almost always use Manhattan distance for its spread due to how the algorithm works, but the positioning of where that floodfill should be allowed to start should likely follow the same distance measurement as the rest of the game, like Radius.SQUARE for Chebyshev distance/8-way movement).
      Specified by:
      setMetric in interface AOE
    • setReach

      public void setReach​(Reach reach)
      Sets the same values as setLimitType(), setMinRange(), setMaxRange(), and setMetric() using one Reach object.
      Specified by:
      setReach in interface AOE
      Parameters:
      reach - a non-null Reach object.