public class Technique
extends java.lang.Object
implements java.io.Serializable
setMap(char[][])
before considering the Technique if it has not been called yet, if the physical
map (including doors and obstacles) has changed since setMap() was last called, or simply on every Technique every
time the map changes if there are few enemies with few Techniques. PERFORMING ANY SUBSEQUENT STEPS WITHOUT SETTING
THE MAP TO THE CURRENT ACTUAL PHYSICAL MAP WILL HAVE BAD CONSEQUENCES FOR LOGIC AND MAY CAUSE CRASHING BUGS DUE TO
ARRAY BOUNDS VIOLATIONS IF YOU HAVEN'T SET THE MAP ARRAY IN THE FIRST PLACE. The map should be bounded by wall chars
('#'), which is done automatically by DungeonGenerator
and similar classes, and
can be done with DungeonUtility.wallWrap(char[][])
as well.idealLocations(Coord, Set, Set, Set)
with the
values of targets, lesserTargets, and/or priorityTargets set to beings that the AI can see (likely using FOV) and
wants to affect with this Technique (enemies for offensive Techniques, allies for supporting ones), and
requiredExclusions typically set to allies for offensive Techniques that can cause friendly-fire damage, or to null
for supporting ones or Techniques that don't affect allies.possibleTargets(Coord)
or its other overload, or can validate choices without telling the player beforehand
using canTarget(Coord, Coord)
(this may be useful for cases where the player is activating an unknown magic
item like a scroll, and the actual range hasn't been revealed).apply(Coord, Coord)
with the user position as a Coord and the
chosen Coord, and proceed to process the effects of the Technique as fitting for your game on the returned Map of
Coord keys to Double values denoting how affected (from 0.0 for unaffected to 1.0 for full power) that Coord is.
An AI might decide which Technique to use by an aggression ("aggro" or "hatred") level tracked per-enemy, by weights
on Techniques for different situations, by choosing at random, or some combination of factors.Modifier and Type | Field and Description |
---|---|
AOE |
aoe |
protected char[][] |
dungeon |
java.lang.String |
id |
java.lang.String |
name |
Constructor and Description |
---|
Technique()
Creates a Technique that can target any adjacent single Coord, using
Chebyshev (8-way square) distance.
|
Technique(java.lang.String name)
Creates a Technique that can target any adjacent single Coord,
using Chebyshev (8-way square) distance.
|
Technique(java.lang.String name,
AOE aoe)
Creates a Technique that can target a Coord at a range specified by the given AOE's minRange and maxRange,
using a distance metric from the AOE, and use that target Coord for the given AOE.
|
Technique(java.lang.String name,
java.lang.String id,
AOE aoe)
Creates a Technique that can target a Coord at a range specified by the given AOE's minRange and maxRange,
using a distance metric from the AOE, and use that target Coord for the given AOE.
|
Modifier and Type | Method and Description |
---|---|
OrderedMap<Coord,java.lang.Double> |
apply(Coord user,
Coord aimAt)
This does one last validation of the location aimAt (checking that it is within the valid range for this
Technique) before getting the area affected by the AOE targeting that cell.
|
boolean |
canTarget(Coord user,
Coord possibleTarget)
A quick yes-or-no check for whether a
user at a given Coord can use this Technique to target the given
Coord of a possibleTarget . |
OrderedMap<Coord,java.util.ArrayList<Coord>> |
idealLocations(Coord user,
java.util.Collection<Coord> targets,
java.util.Collection<Coord> requiredExclusions)
Get a mapping of Coord keys representing locations to apply this Technique to, to ArrayList of Coord values
representing which targets (by their location) are affected by choosing that Coord.
|
OrderedMap<Coord,java.util.ArrayList<Coord>> |
idealLocations(Coord user,
java.util.Set<Coord> priorityTargets,
java.util.Set<Coord> lesserTargets,
java.util.Set<Coord> requiredExclusions)
Get a mapping of Coord keys representing locations to apply this Technique to, to ArrayList of Coord values
representing which targets (by their location) are effected by choosing that Coord.
|
GreasedRegion |
possibleTargets(Coord user)
Gets all possible target-able Coords when using this technique from the given Coord
user , returning them
in a GreasedRegion. |
GreasedRegion |
possibleTargets(Coord user,
double[][] resistanceMap)
Gets all possible target-able Coords when using this technique from the given Coord
user , returning them
in a GreasedRegion. |
void |
setMap(char[][] map)
VITAL: Call this method before any calls to idealLocations() or apply(), and call it again if the map changes.
|
public java.lang.String name
public java.lang.String id
public AOE aoe
protected char[][] dungeon
public Technique()
public Technique(java.lang.String name)
name
- An identifier that may be displayed to the user. Also used for id.public Technique(java.lang.String name, AOE aoe)
name
- An identifier that may be displayed to the user. Also used for id.aoe
- An implementation of the AOE interface; typically needs construction beforehand.public Technique(java.lang.String name, java.lang.String id, AOE aoe)
name
- An identifier that may be displayed to the user.id
- An identifier that should always be internal, and will probably never be shown to the user.aoe
- An implementation of the AOE interface; typically needs construction beforehand.public void setMap(char[][] map)
map
- A char 2D array like one generated by squidpony.squidgrid.mapping.DungeonGenerator, with '#' for walls and bounded edges.public OrderedMap<Coord,java.util.ArrayList<Coord>> idealLocations(Coord user, java.util.Collection<Coord> targets, java.util.Collection<Coord> requiredExclusions)
user
- The location of the user of this Techniquetargets
- Set of Coord of desirable targets to include in the area of this Technique, as many as possible.requiredExclusions
- Set of Coord where each value is something this Technique will really try to avoid.public OrderedMap<Coord,java.util.ArrayList<Coord>> idealLocations(Coord user, java.util.Set<Coord> priorityTargets, java.util.Set<Coord> lesserTargets, java.util.Set<Coord> requiredExclusions)
user
- The location of the user of this TechniquepriorityTargets
- Set of Coord of important targets to include in the area of this Technique, preferring to target a single priorityTarget over four lesserTargets.lesserTargets
- Set of Coord of desirable targets to include in the area of this Technique, as many as possible without excluding priorityTargets.requiredExclusions
- Set of Coord where each value is something this Technique will really try to avoid.public OrderedMap<Coord,java.lang.Double> apply(Coord user, Coord aimAt)
user
- The position of the Technique's user, x first, y second.aimAt
- A target Coord typically obtained from idealLocations that determines how to position the AOE.public boolean canTarget(Coord user, Coord possibleTarget)
user
at a given Coord can use this Technique to target the given
Coord of a possibleTarget
. There doesn't need to be a creature in the possibleTarget cell, since area of
effect Techniques could still affect nearby creatures. Returns true if possibleTarget is a viable target cell for
the given user Coord with this Technique, or false otherwise.user
- the Coord of the starting cell of this Technique, usually the position of the Technique's userpossibleTarget
- a Coord that could maybe be a viable targetpossibleTarget
from the position user
, or false otherwisepublic GreasedRegion possibleTargets(Coord user)
user
, returning them
in a GreasedRegion. Note that a GreasedRegion can be used as a Collection of Coord with a fairly fast
GreasedRegion.contains(Coord)
method, or at least faster than an ArrayList of Coord. GreasedRegion values
are mutable, like arrays, so if you want to edit the returned value you can do so without constructing additional
objects. This works by getting a FOV map (using shadowcasting and the same metric/radius type as the aoe
field on this Technique) to figure out what cells are visible, then eliminating cells that don't match the
minimum range on the AOE or aren't legal targets because of its AimLimit.
DungeonUtility.generateSimpleResistances(char[][])
every time; if you want other resistances, you should
use possibleTargets(Coord, double[][])
instead.user
- the position of the user of this Techniquepublic GreasedRegion possibleTargets(Coord user, double[][] resistanceMap)
user
, returning them
in a GreasedRegion. This takes a 2D double array as a resistance map, the same kind used by FOV
, which
can be obtained with DungeonUtility.generateResistances(char[][])
or
DungeonUtility.generateSimpleResistances(char[][])
. Note that a GreasedRegion can be used as a Collection
of Coord with a fairly fast GreasedRegion.contains(Coord)
method, or at least faster than an ArrayList of
Coord. GreasedRegion values are mutable, like arrays, so if you want to edit the returned value you can do so
without constructing additional objects. This works by getting a FOV map (using shadowcasting and the same
metric/radius type as the aoe
field on this Technique) to figure out what cells are visible, then
eliminating cells that don't match the minimum range on the AOE or aren't legal targets because of its AimLimit.
possibleTargets(Coord)
, which needs to construct an additional temporary 2D
array. You may also want to reuse an existing resistance map, and you can with this method.user
- the position of the user of this TechniqueresistanceMap
- a 2D double array where walls are 1.0 and other values are less; often produced by DungeonUtility.generateSimpleResistances(char[][])
Copyright © Eben Howard 2012–2022. All rights reserved.