This repository has been archived by the owner on Mar 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
PapyrusCell.cpp
78 lines (63 loc) · 1.86 KB
/
PapyrusCell.cpp
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
#include "PapyrusCell.h"
#include "GameForms.h"
#include "GameObjects.h"
#include "GameReferences.h"
namespace papyrusCell
{
UInt32 GetNumRefs(TESObjectCELL* thisCell, UInt32 formType)
{
if (!thisCell)
return 0;
if (formType == 0)
return thisCell->objectList.count;
// match the formType instead
UInt32 numMatching = 0;
UInt32 numRefs = thisCell->objectList.count;
for (UInt32 n = 0; n < numRefs; ++n)
{
TESObjectREFR* pRef = NULL;
thisCell->objectList.GetNthItem(n, pRef);
if (pRef && (pRef->formType == formType || pRef->baseForm->formType == formType))
numMatching++;
}
return numMatching;
}
TESObjectREFR * GetNthRef(TESObjectCELL * thisCell, UInt32 index, UInt32 formType)
{
if (!thisCell)
return NULL;
TESObjectREFR* pRef = NULL;
if (formType == 0) {
thisCell->objectList.GetNthItem(index, pRef);
return pRef;
}
UInt32 numMatching = 0;
UInt32 numRefs = thisCell->objectList.count;
for (UInt32 n = 0; n < numRefs; ++n) {
thisCell->objectList.GetNthItem(n, pRef);
if (pRef && (pRef->formType == formType ||pRef->baseForm->formType == formType)) {
if (numMatching++ == index) {
return pRef;
}
}
}
return NULL;
}
float GetWaterLevel(TESObjectCELL * thisCell)
{
if (!thisCell)
return LONG_MIN;
return thisCell->waterLevel;
}
}
#include "PapyrusVM.h"
#include "PapyrusNativeFunctions.h"
void papyrusCell::RegisterFuncs(VMClassRegistry* registry)
{
registry->RegisterFunction(
new NativeFunction1 <TESObjectCELL, UInt32, UInt32>("GetNumRefs", "Cell", papyrusCell::GetNumRefs, registry));
registry->RegisterFunction(
new NativeFunction2 <TESObjectCELL, TESObjectREFR*, UInt32, UInt32>("GetNthRef", "Cell", papyrusCell::GetNthRef, registry));
registry->RegisterFunction(
new NativeFunction0 <TESObjectCELL, float>("GetWaterLevel", "Cell", papyrusCell::GetWaterLevel, registry));
}