Package squidpony.squidai
Class AreaUtils
java.lang.Object
squidpony.squidai.AreaUtils
public class AreaUtils extends Object
Static utilities for use in AOE and anything else that might need HashMaps of Coord keys to Double values.
Created by Tommy Ettinger on 7/13/2015.
-
Constructor Summary
Constructors Constructor Description AreaUtils()
-
Method Summary
Modifier and Type Method Description static OrderedMap<Coord,Double>
arrayToHashMap(boolean[][] map)
This takes a 2D boolean array and returns a HashMap of Coord keys to Double values, but will only use the value 1.0, and only for positions in map that have as their boolean element true.static OrderedMap<Coord,Double>
arrayToHashMap(double[][] map)
This takes a 2D double array called map and returns a HashMap of Coord keys to Double values, and will have a key for every position in map that is greater than 0.0, with values equal to those in map.static OrderedMap<Coord,Double>
arrayToHashMap(double[][] map, double cutoff)
This takes a 2D double array and returns a HashMap of Coord keys to Double values, but will only use the value 1.0, and only does this if the passed double[][] has a value at that position that is greater than cutoff.static OrderedMap<Coord,Double>
dijkstraToHashMap(double[][] map)
This takes a DijkstraMap that has already completed a scan() and returns a HashMap of Coord keys to Double values, and will have a key for every position that was reached in the DijkstraMap, with 1.0 as the only value.static boolean
verifyLimit(AimLimit limit, Coord origin, Coord end)
Checks that the given end Coord can be targeted from the given origin Coord given the directional targeting rules specified by limit.static boolean
verifyReach(Reach reach, Coord origin, Coord end)
Checks that the given end Coord can be targeted from the given origin Coord given the complete targeting rules specified by reach.
-
Constructor Details
-
Method Details
-
arrayToHashMap
This takes a 2D boolean array and returns a HashMap of Coord keys to Double values, but will only use the value 1.0, and only for positions in map that have as their boolean element true.- Parameters:
map
- width by height, commonly generated by FOV methods- Returns:
- a HashMap of Coord keys to Double values, but the only value used is 1.0
-
arrayToHashMap
This takes a 2D double array called map and returns a HashMap of Coord keys to Double values, and will have a key for every position in map that is greater than 0.0, with values equal to those in map.- Parameters:
map
- width by height, commonly generated by FOV methods- Returns:
- a HashMap of Coord keys to Double values, with values all greater than 0.0
-
arrayToHashMap
This takes a 2D double array and returns a HashMap of Coord keys to Double values, but will only use the value 1.0, and only does this if the passed double[][] has a value at that position that is greater than cutoff. For example, a cutoff of 0.3 will make all elements in the 2D array that are 0.3 or less be ignored and not put into the HashMap, but all elements that are greater than 0.3 will be placed in as 1.0.- Parameters:
map
- width by height, commonly generated by FOV methodscutoff
- any elements greater than this will be 1.0 in the return, anything else will be ignored- Returns:
- a HashMap of Coord keys to Double values, but the only value used is 1.0
-
dijkstraToHashMap
This takes a DijkstraMap that has already completed a scan() and returns a HashMap of Coord keys to Double values, and will have a key for every position that was reached in the DijkstraMap, with 1.0 as the only value.- Parameters:
map
- a double[][] returned by a DijkstraMap running its scan()- Returns:
- a HashMap of Coord keys to Double values, with values of 1.0 only
-
verifyLimit
Checks that the given end Coord can be targeted from the given origin Coord given the directional targeting rules specified by limit. If any of the arguments are null, returns true (it assumes that any limits are not valid and don't restrict anything). The following AimLimit enum values for limit have 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.
- Parameters:
limit
- an AimLimit enum that restricts valid points unless it is AimLimit.FREE or nullorigin
- where the user isend
- where the point we want to verify is- Returns:
- true if the point is a valid target or if the limits are invalid (non-restricting), false otherwise
-
verifyReach
Checks that the given end Coord can be targeted from the given origin Coord given the complete targeting rules specified by reach. If any of the arguments are null, returns true (it assumes that any limits are not valid and don't restrict anything). If reach.limit is null, it treats it as equivalent toAimLimit.FREE
. Otherwise, it uses the metric, minDistance, and maxDistance from reach to calculate if end is target-able from origin assuming an unobstructed playing field.- Parameters:
reach
- a Reach object that, if non-null, gives limits for how targeting can proceed.origin
- where the user isend
- where the point we want to verify is- Returns:
- true if the point is a valid target or if the limits are invalid (non-restricting), false otherwise
-