Class WeightedGoalMap
Implementation of the second half of the goal map system described in this article -- the ability to combine multiple goal maps with different weights.
Inherited Members
Namespace: GoRogue.Pathing
Assembly: GoRogue.dll
Syntax
public sealed class WeightedGoalMap : GridViewBase<double?>, IGridView<double?>
Remarks
This class encapsulates the work of building one overall goal map out of multiple existing maps. It holds references to one or more maps, each with its own "weight". The higher the weight value, the more strongly an AI will attempt to pursue this goal. A negative weight inverts the map, turning its goal into something to avoid. Inverting the weight does not create a "safety map" as described in the article, as the resulting goal map will show no concept of global vs. local avoidance. For that functionality, see FleeMap.
Note that all the grid views held by this class must have the same width and height. If their width and height change after they are added such that this is not the case, unexpected behavior will occur.
Constructors
View SourceWeightedGoalMap(IGridView<double?>)
Constructor. Takes a single goal map and assigns it a weight of 1.0.
Declaration
public WeightedGoalMap(IGridView<double?> map)
Parameters
Type | Name | Description |
---|---|---|
IGridView<double?> | map | The goal map. |
WeightedGoalMap(IEnumerable<GoalMapWeightPair>)
Constructor. Takes an existing goal map dictionary and copies it.
Declaration
public WeightedGoalMap(IEnumerable<GoalMapWeightPair> maps)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<GoalMapWeightPair> | maps | The goal maps. Each one must be of the same size, and all weights should have a nonzero value. |
WeightedGoalMap(IEnumerable<IGridView<double?>>)
Constructor. Takes a sequence of goal maps and assigns each one a weight of 1.0.
Declaration
public WeightedGoalMap(IEnumerable<IGridView<double?>> maps)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IGridView<double?>> | maps | The goal maps. Each one must be of the same size. |
Fields
View SourceWeights
The list of weighted goal maps. Can be used to add or remove goal maps, or change their weights.
Declaration
public readonly List<GoalMapWeightPair> Weights
Field Value
Type | Description |
---|---|
List<GoalMapWeightPair> |
Remarks
When adding a new goal map, its Width and Height should be identical to the WeightedGoalMap's Width and Height.
Properties
View SourceHeight
The height of the goal map, and the goal maps that compose it.
Declaration
public override int Height { get; }
Property Value
Type | Description |
---|---|
int |
Overrides
this[Point]
Returns the value of the combined goal maps at any given point.
Declaration
public override double? this[Point point] { get; }
Parameters
Type | Name | Description |
---|---|---|
Point | point |
Property Value
Type | Description |
---|---|
double? |
Overrides
Width
The width of the goal map, and the goal maps that compose it.
Declaration
public override int Width { get; }
Property Value
Type | Description |
---|---|
int |
Overrides
Methods
View SourceCombine()
Computes the entire aggregate goal map and returns it, effectively caching the result. This may be useful in situations where the goals are shared between many characters and do not change frequently.
Declaration
public ArrayView<double?> Combine()
Returns
Type | Description |
---|---|
ArrayView<double?> |