blob: 2f23afc07fbe176da9ac725ce8926a374e8abb3d (
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
|
#include "worldmap.h"
dWMPathData_c::dWMPathData_c() {
}
dWMPathData_c::~dWMPathData_c() {
}
bool dWMPathData_c::load(void *data) {
MapReport("dWMPathData_c initialised with %p\n", data);
WMPathHeader *header = (WMPathHeader*)data;
this->data = header;
u32 ptr = (u32)data; // for easy addition! probably bad practice, but whatever..
// first off, fix the list pointers
header->pathList = (WMPathDef**)((u32)header->pathList + ptr);
header->pointList = (WMPathPoint**)((u32)header->pointList + ptr);
header->segmentList = (WMPathSegment**)((u32)header->segmentList + ptr);
header->actionList = (WMPathAction**)((u32)header->actionList + ptr);
// now, fix every pointer in the lists
MapReport("Fixing up list pointers\n");
for (int i = 0; i < header->pathCount; i++)
header->pathList[i] = (WMPathDef*)((u32)header->pathList[i] + ptr);
for (int i = 0; i < header->pointCount; i++)
header->pointList[i] = (WMPathPoint*)((u32)header->pointList[i] + ptr);
for (int i = 0; i < header->segmentCount; i++)
header->segmentList[i] = (WMPathSegment*)((u32)header->segmentList[i] + ptr);
for (int i = 0; i < header->actionCount; i++)
header->actionList[i] = (WMPathAction*)((u32)header->actionList[i] + ptr);
// next up, fix every pointer in these structs
MapReport("Fixing up path pointers [%d]\n", header->pathCount);
for (int i = 0; i < header->pathCount; i++) {
WMPathDef *thisPath = header->pathList[i];
//MapReport("Path @ %p - Index: %d - Segments: %d\n", thisPath, i, thisPath->segCount);
thisPath->startPoint = header->pointList[(u32)thisPath->startPoint];
thisPath->endPoint = header->pointList[(u32)thisPath->endPoint];
for (int j = 0; j < thisPath->segCount; j++) {
thisPath->segments[j] = header->segmentList[(u32)thisPath->segments[j]];
}
}
MapReport("Fixing up point pointers [%d]\n", header->pointCount);
for (int i = 0; i < header->pointCount; i++) {
WMPathPoint *thisPoint = header->pointList[i];
for (int j = 0; j < 4; j++) {
if ((u32)thisPoint->exits.asArray[j].path == -1) {
thisPoint->exits.asArray[j].path = 0;
} else {
thisPoint->exits.asArray[j].path = header->pathList[(u32)thisPoint->exits.asArray[j].path];
}
}
}
MapReport("Fixing up segment pointers [%d]\n", header->segmentCount);
for (int i = 0; i < header->segmentCount; i++) {
WMPathSegment *thisSegment = header->segmentList[i];
if ((u32)thisSegment->action == -1) {
thisSegment->action = 0;
} else {
thisSegment->action = header->actionList[(u32)thisSegment->action];
}
}
MapReport("Load complete\n");
return true;
}
int dWMPathData_c::getPointID(WMPathPoint *point) {
for (int i = 0; i < data->pointCount; i++) {
if (data->pointList[i] == point)
return i;
}
return -1;
}
|