blob: 538917f6f411ec4a0adb603ea201417385e81c34 (
plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
#include "stdafx.h"
#include "net.minecraft.world.entity.h"
#include "net.minecraft.world.level.pathfinder.h"
#include "path.h"
Path::~Path()
{
if( nodes.data )
{
for( int i = 0; i < nodes.length; i++ )
delete nodes.data[i];
delete[] nodes.data;
}
}
Path::Path(NodeArray nodes)
{
index = 0;
length = nodes.length;
// 4J - copying these nodes over from a NodeArray (which is an array of Node * references) to just a straight array of Nodes,
// so that this Path is no longer dependent of Nodes allocated elsewhere and can handle its own destruction
// Note: cameFrom pointer will be useless now but that isn't used once this is just a path
this->nodes = NodeArray(length);
for( int i = 0; i < length; i++ )
{
this->nodes.data[i] = new Node();
memcpy(this->nodes.data[i],nodes[i],sizeof(Node));
}
}
void Path::next()
{
index++;
}
bool Path::isDone()
{
return index >= length;
}
Node *Path::last()
{
if (length > 0)
{
return nodes[length - 1];
}
return NULL;
}
Node *Path::get(int i)
{
return nodes[i];
}
int Path::getSize()
{
return length;
}
void Path::setSize(int length)
{
this->length = length;
}
int Path::getIndex()
{
return index;
}
void Path::setIndex(int index)
{
this->index = index;
}
Vec3 *Path::getPos(shared_ptr<Entity> e, int index)
{
double x = nodes[index]->x + (int) (e->bbWidth + 1) * 0.5;
double y = nodes[index]->y;
double z = nodes[index]->z + (int) (e->bbWidth + 1) * 0.5;
return Vec3::newTemp(x, y, z);
}
Vec3 *Path::currentPos(shared_ptr<Entity> e)
{
return getPos(e, index);
}
Vec3 *Path::currentPos()
{
return Vec3::newTemp( nodes[index]->x, nodes[index]->y, nodes[index]->z );
}
bool Path::sameAs(Path *path)
{
if (path == NULL) return false;
if (path->nodes.length != nodes.length) return false;
for (int i = 0; i < nodes.length; ++i)
if (nodes[i]->x != path->nodes[i]->x || nodes[i]->y != path->nodes[i]->y || nodes[i]->z != path->nodes[i]->z) return false;
return true;
}
bool Path::endsIn(Vec3 *pos)
{
Node *lastNode = last();
if (lastNode == NULL) return false;
return lastNode->x == (int) pos->x && lastNode->y == (int) pos->y && lastNode->z == (int) pos->z;
}
bool Path::endsInXZ(Vec3 *pos)
{
Node *lastNode = last();
if (lastNode == NULL) return false;
return lastNode->x == (int) pos->x && lastNode->z == (int) pos->z;
}
|