-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameForms.cpp
373 lines (335 loc) · 8 KB
/
GameForms.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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
#include "GameForms.h"
#include "GameRTTI.h"
#include "GameObjects.h"
#include "GameExtraData.h"
TESForm * TESForm::TryGetREFRParent(void)
{
TESForm * result = this;
if(result) {
TESObjectREFR * refr = DYNAMIC_CAST(this, TESForm, TESObjectREFR);
if(refr && refr->baseForm)
result = refr->baseForm;
}
return result;
}
UInt8 TESForm::GetModIndex() const
{
return (refID >> 24);
}
TESFullName* TESForm::GetFullName()
{
TESForm* baseForm = this;
TESFullName* fullName = NULL;
if (typeID >= kFormType_Reference && typeID <= kFormType_ACRE) //handle MapMarkers and references
{
TESObjectREFR* refr = DYNAMIC_CAST(this, TESForm, TESObjectREFR);
//if (refr->baseForm->typeID == kFormType_Static)
//{
// ExtraMapMarker* mapMarker = (ExtraMapMarker*)refr->extraDataList.GetByType(kExtraData_MapMarker);
// if (mapMarker && mapMarker->data)
// fullName = &mapMarker->data->fullName;
//}
if (!fullName) //if not a mapmarker, use the base form instead
baseForm = refr->baseForm;
}
else if (typeID == kFormType_Cell) // some exterior cells inherit name of parent worldspace
{
TESObjectCELL* cell = DYNAMIC_CAST(this, TESForm, TESObjectCELL);
if (cell && cell->worldSpace)
if (!cell->fullName.name.m_data || !cell->fullName.name.m_dataLen)
baseForm = cell->worldSpace;
}
if(!fullName)
fullName = DYNAMIC_CAST(baseForm, TESForm, TESFullName);
return fullName;
}
bool TESForm::IsCloned() const
{
return GetModIndex() == 0xff;
}
TESForm* TESForm::CloneForm(bool bPersist) const
{
TESForm* clone = NULL;
clone = (TESForm*)CreateFormInstance(typeID);
if (clone) {
clone->CopyFrom(this);
AddFormToDataHandler(clone);
if (bPersist) {
AddFormToCreatedBaseObjectsList(clone);
}
}
return clone;
}
class ScriptVarFinder
{
public:
const char* m_varName;
ScriptVarFinder(const char* varName) : m_varName(varName)
{ }
bool Accept(Script::VariableInfo* varInfo)
{
//_MESSAGE(" cur var: %s to match: %s", varInfo->name.m_data, m_varName);
if (!_stricmp(m_varName, varInfo->name.m_data))
return true;
else
return false;
}
};
Script::VariableInfo* Script::GetVariableByName(const char* varName)
{
VariableInfo* pVariableInfo = vars.Find(ScriptVarFinder(varName));
return pVariableInfo;
}
Script::RefVariable * Script::GetVariable(UInt32 reqIdx)
{
if (reqIdx > 0) reqIdx--;
RefVariable* pRefVar = refs.GetNthItem(reqIdx);
return pRefVar;
}
EffectItem* EffectItemList::ItemAt(UInt32 whichItem)
{
return list.GetNthItem(whichItem);
}
UInt32 EffectItemList::CountItems() const
{
return list.Count();
}
const char* EffectItemList::GetNthEIName(UInt32 whichEffect) const
{
EffectItem* pEffectItem = list.GetNthItem(whichEffect);
if (pEffectItem) {
if (pEffectItem->scriptEffectInfo) {
return pEffectItem->scriptEffectInfo->effectName.m_data;
} else if (pEffectItem->setting) {
return GetFullName(pEffectItem->setting);
}
}
return "<no name>";
}
class FindByForm {
TESForm* m_pForm;
public:
FindByForm(TESForm* pForm) : m_pForm(pForm) {}
bool Accept(TESForm* pForm) const {
return (pForm->refID == m_pForm->refID) ? true : false;
}
};
SInt32 BGSListForm::GetIndexOf(TESForm* pForm)
{
return list.GetIndexOf(FindByForm(pForm));
}
SInt32 BGSListForm::RemoveForm(TESForm* pForm)
{
SInt32 index = GetIndexOf(pForm);
if (index >= 0) {
RemoveNthForm(index);
}
return index;
}
SInt32 BGSListForm::ReplaceForm(TESForm* pForm, TESForm* pReplaceWith)
{
SInt32 index = GetIndexOf(pForm);
if (index >= 0) {
list.ReplaceNth(index, pReplaceWith);
}
return index;
}
// static
UInt32 TESBipedModelForm::MaskForSlot(UInt32 slot)
{
switch(slot) {
case ePart_Head: return eSlot_Head;
case ePart_Hair: return eSlot_Hair;
case ePart_UpperBody: return eSlot_UpperBody;
case ePart_LeftHand: return eSlot_LeftHand;
case ePart_RightHand: return eSlot_RightHand;
case ePart_Weapon: return eSlot_Weapon;
case ePart_PipBoy: return eSlot_PipBoy;
case ePart_Backpack: return eSlot_Backpack;
case ePart_Necklace: return eSlot_Necklace;
case ePart_Headband: return eSlot_Headband;
case ePart_Hat: return eSlot_Hat;
case ePart_Eyeglasses: return eSlot_Eyeglasses;
case ePart_Nosering: return eSlot_Nosering;
case ePart_Earrings: return eSlot_Earrings;
case ePart_Mask: return eSlot_Mask;
case ePart_Choker: return eSlot_Choker;
case ePart_MouthObject: return eSlot_MouthObject;
case ePart_BodyAddon1: return eSlot_BodyAddon1;
case ePart_BodyAddon2: return eSlot_BodyAddon2;
case ePart_BodyAddon3: return eSlot_BodyAddon3;
default: return -1;
}
}
UInt8 TESObjectWEAP::HandGrip() const
{
switch(handGrip) {
case eHandGrip_1: return 1;
case eHandGrip_2: return 2;
case eHandGrip_3: return 3;
case eHandGrip_Default:
default:
return 0;
}
}
void TESObjectWEAP::SetHandGrip(UInt8 _handGrip)
{
switch(_handGrip) {
case 0: {
handGrip = eHandGrip_Default;
break;
}
case 1: {
handGrip = eHandGrip_1;
break;
}
case 2: {
handGrip = eHandGrip_2;
break;
}
case 3: {
handGrip = eHandGrip_3;
break;
}
default: // not a real value, so don't set it
break;
}
}
UInt8 TESObjectWEAP::AttackAnimation() const
{
switch(attackAnim) {
case eAttackAnim_Default: return 0;
case eAttackAnim_Attack3: return 1;
case eAttackAnim_Attack4: return 2;
case eAttackAnim_Attack5: return 3;
case eAttackAnim_Attack6: return 4;
case eAttackAnim_Attack7: return 5;
case eAttackAnim_Attack8: return 6;
case eAttackAnim_AttackLeft: return 7;
case eAttackAnim_AttackLoop: return 8;
case eAttackAnim_AttackRight: return 9;
case eAttackAnim_AttackSpin: return 10;
case eAttackAnim_AttackSpin2: return 11;
case eAttackAnim_AttackThrow: return 12;
case eAttackAnim_AttackThrow2: return 13;
case eAttackAnim_AttackThrow3: return 14;
case eAttackAnim_AttackThrow4: return 15;
case eAttackAnim_AttackThrow5: return 16;
case eAttackAnim_PlaceMine: return 17;
case eAttackAnim_PlaceMine2: return 18;
default:
return -1;
}
}
void TESObjectWEAP::SetAttackAnimation(UInt8 _attackAnim)
{
switch(_attackAnim) {
case 0: {
attackAnim = eAttackAnim_Default;
break;
}
case 1: {
attackAnim = eAttackAnim_Attack3;
break;
}
case 2: {
attackAnim = eAttackAnim_Attack4;
break;
}
case 3: {
attackAnim = eAttackAnim_Attack5;
break;
}
case 4: {
attackAnim = eAttackAnim_Attack6;
break;
}
case 5: {
attackAnim = eAttackAnim_Attack7;
break;
}
case 6: {
attackAnim = eAttackAnim_Attack8;
break;
}
case 7: {
attackAnim = eAttackAnim_AttackLeft;
break;
}
case 8: {
attackAnim = eAttackAnim_AttackLoop;
break;
}
case 9: {
attackAnim = eAttackAnim_AttackRight;
break;
}
case 10: {
attackAnim = eAttackAnim_AttackSpin;
break;
}
case 11: {
attackAnim = eAttackAnim_AttackSpin2;
break;
}
case 12: {
attackAnim = eAttackAnim_AttackThrow;
break;
}
case 13: {
eAttackAnim_AttackThrow2;
break;
}
case 14: {
attackAnim = eAttackAnim_AttackThrow3;
break;
}
case 15: {
attackAnim = eAttackAnim_AttackThrow4;
break;
}
case 16: {
attackAnim = eAttackAnim_AttackThrow5;
break;
}
case 17: {
attackAnim = eAttackAnim_PlaceMine;
break;
}
case 18: {
attackAnim = eAttackAnim_PlaceMine2;
break;
}
default:
break;
}
}
class FactionMatcher
{
TESFaction* pFaction;
public:
FactionMatcher(TESFaction* faction) : pFaction(faction) {}
bool Accept(TESActorBaseData::FactionListData* data) {
return (data->faction == pFaction) ? true : false;
}
};
SInt8 TESActorBaseData::GetFactionRank(TESFaction* faction)
{
FactionMatcher matcher(faction);
FactionListData* pData = factionList.Find(matcher);
return (pData) ? pData->rank : -1;
}
TESPackage::LocationData* TESPackage::LocationData::Create()
{
LocationData* data = (LocationData*)GameHeapAlloc(sizeof(LocationData));
data->locationType = kPackLocation_EditorLocation;
data->object.form = NULL;
data->radius = 0;
return data;
}
TESPackage::LocationData* TESPackage::GetLocationData()
{
if (!location)
location = LocationData::Create();
return location;
}