Empeld
Empeld plugin documentation.
essentials.action.Pathing.DefaultWorldCostEngine Class Reference

Default world cost engine. Avoids hills and water. Should work for most default blocks More...

Inheritance diagram for essentials.action.Pathing.DefaultWorldCostEngine:
essentials.action.Pathing.IPathCostEngine

Public Member Functions

 DefaultWorldCostEngine (IWorldReadonly world)
 
virtual int GetActualCost (Vector3i src, Vector3i dst)
 Gets the actual cost traversing between two points If less than 0, treated as impassible. Otherwise cost is relative More...
 
virtual int GetHeuristic (Vector3i src, Vector3i dst)
 Gets the heuristic cost between two points (to better predict which way to search) More...
 

Protected Attributes

readonly IWorldReadonly World
 

Detailed Description

Default world cost engine. Avoids hills and water. Should work for most default blocks

Constructor & Destructor Documentation

◆ DefaultWorldCostEngine()

essentials.action.Pathing.DefaultWorldCostEngine.DefaultWorldCostEngine ( IWorldReadonly  world)
15  {
16  World = world;
17  }
readonly IWorldReadonly World
Definition: DefaultWorldCostEngine.cs:12

Member Function Documentation

◆ GetActualCost()

virtual int essentials.action.Pathing.DefaultWorldCostEngine.GetActualCost ( Vector3i  src,
Vector3i  dst 
)
virtual

Gets the actual cost traversing between two points If less than 0, treated as impassible. Otherwise cost is relative

These points should always be on the "surface" of blocks (aka, empty themselves, but over something solid).

Returns
The actual cost.
Parameters
srcSource.
dstDst.

Attribute: dst

;

Attribute: dst.X, dst.Y, dst.Z-1

;

Implements essentials.action.Pathing.IPathCostEngine.

20  {
21  var inBlock = World[dst];
22  if (inBlock.Solid)
23  return -1; //Impassible
24 
25  var onBlock = World[dst.X, dst.Y, dst.Z-1];
26  if (!onBlock.Solid && !onBlock.Climbable)
27  return -1; //Can't hover
28 
29  if (onBlock.DamageInfliction > 0 || inBlock.DamageInfliction > 0)
30  return 16;
31  if (onBlock.Climbable || inBlock.Climbable)
32  return 1;
33  if (onBlock.IsLiquid || inBlock.IsLiquid)
34  return 4;
35  if (src.Z != dst.Z)
36  return 2;
37  return 1;
38  }
readonly IWorldReadonly World
Definition: DefaultWorldCostEngine.cs:12
int Y
The Y coordinate
Definition: Vector3i.cs:23
int X
The X coordinate
Definition: Vector3i.cs:18
int Z
The Z coordinate
Definition: Vector3i.cs:28

◆ GetHeuristic()

virtual int essentials.action.Pathing.DefaultWorldCostEngine.GetHeuristic ( Vector3i  src,
Vector3i  dst 
)
virtual

Gets the heuristic cost between two points (to better predict which way to search)

Returns
The heuristic.
Parameters
srcSource.
dstDst.

Implements essentials.action.Pathing.IPathCostEngine.

41  {
42  int dx = src.X - dst.X;
43  int dy = src.Y - dst.Y;
44  return (int)Math.Sqrt(dx*dx + dy*dy) + Math.Abs(dst.Z - src.Z)*2;
45  }
int Y
The Y coordinate
Definition: Vector3i.cs:23
int X
The X coordinate
Definition: Vector3i.cs:18
int Z
The Z coordinate
Definition: Vector3i.cs:28

Member Data Documentation

◆ World

readonly IWorldReadonly essentials.action.Pathing.DefaultWorldCostEngine.World
protected

The documentation for this class was generated from the following file: