Empeld
Empeld plugin documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events
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)
 
virtual int GetHeuristic (Vector3i src, Vector3i dst)
 

Detailed Description

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

Constructor & Destructor Documentation

essentials.action.Pathing.DefaultWorldCostEngine.DefaultWorldCostEngine ( IWorldReadonly  world)
15  {
16  _world = world;
17  }

Member Function Documentation

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

Implements essentials.action.Pathing.IPathCostEngine.

20  {
21  var block = _world.GetIBlock(dst.X, dst.Y, dst.Z);
22  if (block.Solid)
23  return -1; //Impassible
24 
25  var onBlock = _world.GetIBlock(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)
30  return 32;
31  if (onBlock.Climbable)
32  return 1;
33  if (onBlock.IsLiquid)
34  return 4;
35  if (src.Z != dst.Z)
36  return 2;
37  return 1;
38  }
IBlock GetIBlock(int x, int y, int z)
Get the block properties at a position
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
virtual int essentials.action.Pathing.DefaultWorldCostEngine.GetHeuristic ( Vector3i  src,
Vector3i  dst 
)
virtual

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

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