This repository has been archived by the owner on Nov 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpath.nut
79 lines (72 loc) · 1.79 KB
/
path.nut
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* modified path from the AyStar algorithm library
* The last entry has a GetParent() of null.
*/
class Path
{
_prev = null;
_next = null;
_tile = null;
_direction = null;
_cost = null;
_length = null;
_real_length = null;
constructor(old_path, new_tile, new_direction)
{
this._prev = old_path;
this._tile = new_tile;
this._direction = new_direction;
if (old_path == null) {
this._length = 0;
this._real_length = 0.0;
} else {
old_path._next = this;
this._length = old_path.GetLength() + AIMap.DistanceManhattan(old_path.GetTile(), new_tile);
if (old_path.GetParent() != null)
{
local old_tile = old_path.GetTile();
local very_old_tile = old_path.GetParent().GetTile();
if (new_tile - old_tile != old_tile - very_old_tile) {
this._real_length = old_path._real_length + 0.5;
}
else{
this._real_length = old_path._real_length + 1.0;
}
}
else
{
this._real_length = 0.0;
}
}
//local mode = AIExecMode();
//AISign.BuildSign(new_tile, this._real_length);
};
/**
* Return the tile where this (partial-)path ends.
*/
function GetTile() { return this._tile; }
/**
* Return the direction from which we entered the tile in this (partial-)path.
*/
function GetDirection() { return this._direction; }
/**
* Return an instance of this class leading to the previous node.
*/
function GetParent() { return this._prev; }
/**
* Return an instance of this class leading to the next node.
*/
function GetChildren() { return this._next; }
/**
* Return the length (in tiles) of this path.
*/
function GetLength() { return this._length; }
/**
* Return the length (in tiles) of this path.
*/
function GetRealLength()
{
if (this.GetParent() == null) return 0;
return this.GetParent()._real_length;
}
};