-
Notifications
You must be signed in to change notification settings - Fork 0
/
MwRandItemGen.h
315 lines (244 loc) · 10.8 KB
/
MwRandItemGen.h
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
/*===========================================================================
*
* File: Mwranditemgen.H
* Author: Dave Humphrey ([email protected])
* Created On: May 23, 2003
*
* Description
*
*=========================================================================*/
#ifndef __MWRANDITEMGEN_H
#define __MWRANDITEMGEN_H
/*===========================================================================
*
* Begin Required Includes
*
*=========================================================================*/
#include "MWRandItems.h"
#include "MWRandEffects.h"
#include "MWRandUniques.h"
#include "MWRandLList.h"
#include "MWRandItemGroup.h"
#include "EsmFile.h"
/*===========================================================================
* End of Required Includes
*=========================================================================*/
/*===========================================================================
*
* Begin Definitions
*
*=========================================================================*/
/* Script filename format */
#define MWRIG_SCRIPTFILE_FORMAT _T("script%04d.txt")
#define MWRIG_SCRIPTFILE_WILDCARD _T("script????.txt")
/* Size of the script data buffers */
#define MWRIG_SCRIPTDATA_SIZE 32000
/* Maximum number of items allowed in a level list */
#define MWRID_MAXITEMS_LEVELLIST 9900
/* Number of extra PH lists to create */
#define MWRID_EXTRA_PHLISTS 5
/*===========================================================================
* End of Definitions
*=========================================================================*/
/*===========================================================================
*
* Begin Type Definitions
*
*=========================================================================*/
/* Creation options */
class mwrig_options_t : public mwri_group_t {
public:
int CurrentItemLevel;
long CurrentEffectMask;
float CurrentRatio;
mwri_item_t* pCurrentItem;
mwrand_effect_t* pCurrentPrefix;
mwrand_effect_t* pCurrentSuffix;
mwru_unique_t* pCurrentUnique;
};
/*===========================================================================
* End of Type Definitions
*=========================================================================*/
/*===========================================================================
*
* Begin Class CMwRandItemGen Definition
*
* Description
*
*=========================================================================*/
class CMwRandItemGen {
/*---------- Begin Private Class Members ----------------------*/
private:
CMwRandItems m_RandItems; /* Data table classes */
CMwRandEffects m_RandEffects;
CMwRandUniques m_RandUniques;
CMwRandLList m_RandLLists;
CMwRandItemGroup m_GroupData;
CMwRandItemArray m_ValidItems;
CMwRandEffectArray m_ValidPrefixes;
CMwRandEffectArray m_ValidSuffixes;
CMwRandUniqueArray m_ValidUniques;
TCHAR m_InitialPath[_MAX_PATH + 1];
long m_NumNewItems;
long m_NumEnchantments;
long m_NumScripts;
long m_NumLevelLists;
long m_NumPHLists;
bool m_HasEnchantment;
long m_ExportCount;
mwrig_options_t m_Options;
CEsmRecArray m_NewRecords; /* Newly created records */
CEsmRecArray m_ListRecords;
CEsmRecArray m_LevelLists;
CEsmRecArray m_PHLists;
CEsmRecArray m_AllRecords;
CEsmFile m_EsmFile;
CEsmLevelItem* m_pLevelItems;
CEsmScript* m_pScript1;
CEsmScript* m_pScript2;
CSString m_ScriptBuffer1;
CSString m_ScriptBuffer2;
byte m_ScriptData1[MWRIG_SCRIPTDATA_SIZE];
byte m_ScriptData2[MWRIG_SCRIPTDATA_SIZE];
int m_ScriptSize1;
int m_ScriptSize2;
CGenFile m_ScriptFile;
/*---------- Begin Protected Class Methods --------------------*/
protected:
/* Adds a single enchantment effect to the given record */
void AddEnchantEffect (CEsmRecord* pEnchant, mwrand_encheff_t& EnchantEffect);
/* Add the sorted leveled items to the leveled list */
void AddLevelListItem (CEsmRecord* pRecord);
void AddSortLevelItems (void);
/* Add data to the compiled script buffers */
bool AddScriptData1 (const char* pData, const int Size);
bool AddScriptData2 (const char* pData, const int Size);
/* Allocates a new record according to the current settings */
CEsmRecord* AllocateNewRecord (void);
void AllocateLevelList (void);
/* Returns true if the input item level is currently valid */
bool CheckItemLevel (const int Level);
bool CheckEffectLevel (const int Level);
bool CheckCursedLevel (const int Level);
/* Removes any suffixes that don't match the current prefix */
void CheckValidSuffixes (void);
/* Check and correct weapon damage */
void CheckWeaponDamage (CEsmWeapon* pWeapon);
/* Check and remove item duplicates as required */
bool CheckDuplicates (CEsmRecord* pRecord);
/* Clear all the currently valid item arrays */
void ClearValidItems (void);
/* Attempt to close the script file */
bool CloseScriptFile (void);
bool CloseScriptRecord (void);
/* Compute any magical effects for the current item */
void ComputeCurrentEffects (void);
/* Computes a new current item level */
void ComputeItemLevel (void);
void ComputeQualityLevel (void);
int ComputeItemLevel (CEsmItem2* pItem);
/* Create the given enchant for the record */
void CreateEffect (CEsmRecord* pRecord, mwrand_effect_t* pEffect, CEsmEnchant** ppEnchant, CEsmSpell** ppSpell);
/* Allocate and initialize the place-holder lists */
void CreatePHLists (void);
/* Create/add specific effect types */
void CreateEnchantment (CEsmRecord* pRecord, mwrand_effect_t* pEffect, CEsmEnchant** ppEnchant);
void CreateSpell (CEsmRecord* pRecord, mwrand_effect_t* pEffect, CEsmSpell** ppSpell);
void CreateArmor (CEsmRecord* pRecord, mwrand_effect_t* pEffect);
void CreateDamage (CEsmRecord* pRecord, mwrand_effect_t* pEffect);
void CreateEnchantPts (CEsmRecord* pRecord, mwrand_effect_t* pEffect);
void CreateMaxDamage (CEsmRecord* pRecord, mwrand_effect_t* pEffect);
void CreateMinDamage (CEsmRecord* pRecord, mwrand_effect_t* pEffect);
void CreateWeight (CEsmRecord* pRecord, mwrand_effect_t* pEffect);
void CreateReach (CEsmRecord* pRecord, mwrand_effect_t* pEffect);
void CreateSpeed (CEsmRecord* pRecord, mwrand_effect_t* pEffect);
void CreateCondition (CEsmRecord* pRecord, mwrand_effect_t* pEffect);
/* Main item creation function */
void CreateItem (void);
/* Export record data from an ESP/ESM file */
bool ExportArmor (CGenFile& OutputFile, CEsmArmor* pArmor);
bool ExportClothing (CGenFile& OutputFile, CEsmClothing* pClothing);
bool ExportMisc (CGenFile& OutputFile, CEsmMisc* pMisc);
bool ExportWeapon (CGenFile& OutputFile, CEsmWeapon* pWeapon);
bool ExportBodyParts (CGenFile& OutputFile, CEsmRecord* pRecord);
/* See if the record is a duplicate item */
bool IsDuplicate (CEsmRecord* pRecord);
/* Checks if the effect/item pair is valid */
bool IsValidEffect (mwrand_effect_t* pEffect, mwri_item_t* pItem);
/* Makes a random item and stores it in the new array */
bool MakeRandomItem (void);
/* Make a new enchantment/spell object */
void MakeEnchantment (CEsmRecord* pRecord, CEsmEnchant** ppEnchant);
void MakeSpell (CEsmRecord* pRecord, CEsmSpell** ppSpell);
/* Create base item strings */
const TCHAR* MakeItemID (void);
const TCHAR* MakeLevelListID (void);
const TCHAR* MakePHListID (void);
const TCHAR* MakeItemName (void);
/* Attempt to open a new script file */
bool OpenNewScriptFile (void);
bool OpenNewScriptRecord (void);
/* Create the levelled list scripts */
bool OutputLListScripts (void);
bool OutputPHListScripts (void);
/* Select a base item to use */
void SelectBaseItem (void);
/* Select all valid items/effects/uniques based on the current settings */
void SelectValidItems (void);
void SelectValidSuffixes (void);
void SelectValidPrefixes (void);
void SelectValidUniques (void);
/* Sets the new record parameters according to the current settings */
void SetRecordItemParams (CEsmRecord* pRecord);
void SetRecordEffects (CEsmRecord* pRecord);
void SetWeaponParams (CEsmWeapon* pWeapon);
void SetArmorParams (CEsmArmor* pArmor);
void SetClothingParams (CEsmClothing* pClothing);
void SetMiscParams (CEsmMisc* pMisc);
void SetBodyParts (CEsmRecord* pRecord);
/* Outputs a single script entry to the script file */
bool WriteScriptEntry (const TCHAR* pID, const int Level);
bool WriteScriptRecord (const TCHAR* pID, const int Level);
/*---------- Begin Public Class Methods -----------------------*/
public:
/* Class Constructors/Destructors */
CMwRandItemGen();
virtual ~CMwRandItemGen() { Destroy(); }
virtual void Destroy (void);
/* Creates all items accorinding to the current settings */
bool CreateItems (void);
/* Delete all records in the new array */
void DestroyNewRecords (void);
void ClearAllRecords (void) { m_AllRecords.RemoveAll(); }
/* Export base item data from an ESP/ESM file */
bool ExportItemData (const TCHAR* pEsmFile, const TCHAR* pOutputFile);
/* Get class members */
mwrig_options_t* GetOptions (void) { return (&m_Options); }
CEsmRecArray* GetNewRecords (void) { return (&m_NewRecords); }
CEsmFile* GetEsmFile (void) { return (&m_EsmFile); }
long GetNumNewItems (void) { return (m_NumNewItems); }
long GetNumEnchantments (void) { return (m_NumEnchantments); }
/* Attempt to load the data files */
bool LoadDataFiles (void);
bool LoadGroupFile (const TCHAR* pFilename);
bool SaveGroupFile (const TCHAR* pFilename);
/* Attempt to merge an existing ESP into the current records */
bool MergeEsp (const TCHAR* pFilename, const bool Add = true);
};
/*===========================================================================
* End of Class CMwRandItemGen Definition
*=========================================================================*/
/*===========================================================================
*
* Begin Function Prototypes
*
*=========================================================================*/
/* Set default options */
void DefaultMWRandItemGenOptions (mwrig_options_t& Options);
/*===========================================================================
* End of Function Prototypes
*=========================================================================*/
#endif
/*===========================================================================
* End of File Mwranditemgen.H
*=========================================================================*/