-
Notifications
You must be signed in to change notification settings - Fork 0
/
he_InfoVersion.cs
595 lines (540 loc) · 17 KB
/
he_InfoVersion.cs
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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
using System;
using System.Drawing;
namespace nwn2_ai_2da_editor
{
// Contains functions for changing the InfoVersion of spells/races/classes.
partial class he
{
const int HENCH_SPELL_INFO_VERSION_SHIFT = 24;
/// <summary>
/// This funct is used only for
/// <c><see cref="Click_clearCoreAiVersion()">Click_clearCoreAiVersion()</see></c>.
/// </summary>
/// <param name="str"></param>
/// <param name="all"></param>
/// <remarks>Used to be a helper for <c>Click_setCoreAiVersion()</c>.</remarks>
void SetInfoVersion_spells(string str, bool all)
{
Spell spell;
SpellChanged spellchanged;
int spellinfo0, spellinfo, differ;
bool dirty;
int ver = Int32.Parse(str) << HENCH_SPELL_INFO_VERSION_SHIFT; // the return from the dialog.
int total = Spells.Count;
for (int id = 0; id != total; ++id)
{
spell = Spells[id];
if (dirty = ((spell.differ & control_Spells.bit_spellinfo) != 0))
{
spellinfo0 = SpellsChanged[id].spellinfo;
}
else if (all || spell.isChanged)
{
spellinfo0 = spell.spellinfo;
}
else
continue; // ignore clean spell-structs if !all
if (spellinfo0 == 0)
{
continue; // if spellinfo is blank leave it blank
}
if ((spellinfo0 & ~hc.HENCH_SPELL_INFO_VERSION_MASK) == 0) // force-clear the version if the rest of spellinfo is blank
{
spellinfo = 0;
}
else
spellinfo = ((spellinfo0 & ~hc.HENCH_SPELL_INFO_VERSION_MASK) | ver);
if (spellinfo != spellinfo0)
{
if (id == Id)
{
HenchControl.SetMasterText(spellinfo.ToString()); // firing the TextChanged event takes care of it.
}
else
{
if (dirty)
{
spellchanged = SpellsChanged[id];
}
else
{
spellchanged = new SpellChanged();
spellchanged.targetinfo = spell.targetinfo;
spellchanged.effectweight = spell.effectweight;
spellchanged.effecttypes = spell.effecttypes;
spellchanged.damageinfo = spell.damageinfo;
spellchanged.savetype = spell.savetype;
spellchanged.savedctype = spell.savedctype;
}
spellchanged.spellinfo = spellinfo;
// check it
differ = control_Spells.SpellDiffer(spell, spellchanged);
spell.differ = differ;
Spells[id] = spell;
Color color;
if (differ != control_Spells.bit_clean)
{
SpellsChanged[id] = spellchanged;
color = Color.Crimson;
}
else
{
SpellsChanged.Remove(id);
if (spell.isChanged) color = Color.Blue;
else color = DefaultForeColor;
}
Tree.Nodes[id].ForeColor = color;
}
}
}
}
/// <summary>
/// This funct is used only for
/// <c><see cref="Click_clearCoreAiVersion()">Click_clearCoreAiVersion()</see></c>.
/// </summary>
/// <param name="str"></param>
/// <param name="all"></param>
/// <remarks>Used to be a helper for <c>Click_setCoreAiVersion()</c>.</remarks>
void SetInfoVersion_racial(string str, bool all)
{
// NOTE: This will iterate through all changed races even
// if an invalid version # is input via the dialog since it
// inserts the default version even if there is no other
// data in the racialflags-int.
Race race;
RaceChanged racechanged;
int racialflags0, racialflags, differ;
bool dirty;
int ver = (Int32.Parse(str) << HENCH_SPELL_INFO_VERSION_SHIFT); // the return from the dialog.
int total = Races.Count;
for (int id = 0; id != total; ++id)
{
race = Races[id];
if (dirty = ((race.differ & control_Racial.bit_flags) != 0))
{
racialflags0 = RacesChanged[id].flags;
}
else if (all || race.isChanged)
{
racialflags0 = race.flags;
}
else
continue; // ignore clean racial-structs if !all
if ((racialflags0 & hc.HENCH_SPELL_INFO_VERSION_MASK) != ver)
{
if (!BypassInfoVersion)
{
racialflags = ((racialflags0 & ~hc.HENCH_SPELL_INFO_VERSION_MASK) | ver);
}
else
racialflags = (racialflags0 & ~hc.HENCH_SPELL_INFO_VERSION_MASK); // wipe version info for TonyAI 2.3+
if (id == Id)
{
HenchControl.SetMasterText(racialflags.ToString()); // firing the TextChanged event takes care of it.
}
else
{
if (dirty)
{
racechanged = RacesChanged[id];
}
else
{
racechanged = new RaceChanged();
racechanged.feat1 = race.feat1;
racechanged.feat2 = race.feat2;
racechanged.feat3 = race.feat3;
racechanged.feat4 = race.feat4;
racechanged.feat5 = race.feat5;
}
racechanged.flags = racialflags;
// check it
differ = control_Racial.RaceDiffer(race, racechanged);
race.differ = differ;
Races[id] = race;
Color color;
if (differ != control_Racial.bit_clean)
{
RacesChanged[id] = racechanged;
color = Color.Crimson;
}
else
{
RacesChanged.Remove(id);
if (race.isChanged) color = Color.Blue;
else color = DefaultForeColor;
}
Tree.Nodes[id].ForeColor = color;
}
}
}
}
/// <summary>
/// This funct is used only for
/// <c><see cref="Click_clearCoreAiVersion()">Click_clearCoreAiVersion()</see></c>.
/// </summary>
/// <param name="str"></param>
/// <param name="all"><c>true</c> to apply version to all classes else
/// apply to changed classes only</param>
/// <remarks>Used to be a helper for <c>Click_setCoreAiVersion()</c>.</remarks>
void SetInfoVersion_classes(string str, bool all)
{
Class @class;
ClassChanged classchanged;
int classflags0, classflags, differ;
bool dirty;
int ver = (Int32.Parse(str) << HENCH_SPELL_INFO_VERSION_SHIFT); // the return from the dialog.
int total = Classes.Count;
for (int id = 0; id != total; ++id)
{
@class = Classes[id];
if (dirty = ((@class.differ & control_Classes.bit_flags) != 0))
{
classflags0 = ClassesChanged[id].flags;
}
else if (all || @class.isChanged)
{
classflags0 = @class.flags;
}
else
continue; // ignore clean class-structs if !all
if ((classflags0 & hc.HENCH_SPELL_INFO_VERSION_MASK) != ver)
{
if (!BypassInfoVersion)
{
classflags = ((classflags0 & ~hc.HENCH_SPELL_INFO_VERSION_MASK) | ver);
}
else
classflags = (classflags0 & ~hc.HENCH_SPELL_INFO_VERSION_MASK); // wipe version info for TonyAI 2.3+
if (id == Id)
{
HenchControl.SetMasterText(classflags.ToString()); // firing the TextChanged event takes care of it.
}
else
{
if (dirty)
{
classchanged = ClassesChanged[id];
}
else
{
classchanged = new ClassChanged();
classchanged.feat1 = @class.feat1;
classchanged.feat2 = @class.feat2;
classchanged.feat3 = @class.feat3;
classchanged.feat4 = @class.feat4;
classchanged.feat5 = @class.feat5;
classchanged.feat6 = @class.feat6;
classchanged.feat7 = @class.feat7;
classchanged.feat8 = @class.feat8;
classchanged.feat9 = @class.feat9;
classchanged.feat10 = @class.feat10;
classchanged.feat11 = @class.feat11;
}
classchanged.flags = classflags;
// check it
differ = control_Classes.ClassDiffer(@class, classchanged);
@class.differ = differ;
Classes[id] = @class;
Color color;
if (differ != control_Classes.bit_clean)
{
ClassesChanged[id] = classchanged;
color = Color.Crimson;
}
else
{
ClassesChanged.Remove(id);
if (@class.isChanged) color = Color.Blue;
else color = DefaultForeColor;
}
Tree.Nodes[id].ForeColor = color;
}
}
}
}
// /// <summary>
// /// An inputbox with which to set CoreAI version information.
// /// </summary>
// /// <param name="type"></param>
// /// <param name="str"></param>
// /// <returns></returns>
// static DialogResult InfoVersion(Type2da type, ref string str)
// {
// string title, text_1, text_2, text_3;
// switch (type)
// {
// default:
// case Type2da.Spells:
// title = " Spell Info version";
// text_1 = "current spell only";
// text_2 = "any changed spells";
// text_3 = "all spells in 2da";
// break;
//
// case Type2da.Racial:
// title = " Racial Info version";
// text_1 = "current race only";
// text_2 = "any changed race";
// text_3 = "all races in 2da";
// break;
//
// case Type2da.Classes:
// title = " Class Info version";
// text_1 = "current class only";
// text_2 = "any changed class";
// text_3 = "all classes in 2da";
// break;
// }
//
// DialogResult dr = DialogResult.Cancel;
//
// using (var ib = new Form())
// {
// var size = new Size(350, 125);
//
// ib.FormBorderStyle = FormBorderStyle.FixedToolWindow;
// ib.StartPosition = FormStartPosition.CenterParent;
// ib.ClientSize = size;
// ib.Text = title;
// ib.Font = new Font("Courier New", 8.25f, FontStyle.Regular, GraphicsUnit.Point, (byte)0);
//
//
// const int pad = 5;
//
// var infoText = new Label();
// infoText.Size = new Size(size.Width - pad * 2, 20);
// infoText.Location = new Point(pad, pad + 2);
// infoText.Font = new Font("Courier New", 8.25f, FontStyle.Bold, GraphicsUnit.Point, (byte)0);
// infoText.ForeColor = Color.Crimson;
// infoText.TextAlign = ContentAlignment.TopCenter;
// infoText.Text = "Do NOT change this!";
// ib.Controls.Add(infoText);
//
// var textBox = new TextBox();
// textBox.Size = new Size(size.Width - pad * 10, 20);
// textBox.Location = new Point(pad * 5, 30);
// textBox.Text = str;
// textBox.TextChanged += TextChanged_ver;
// ib.Controls.Add(textBox);
//
// const int wBtn = 80;
// const int hBtn = 55;
// int yBtn = size.Height - hBtn - pad;
//
//
// var cancelButton = new Button();
// cancelButton.DialogResult = DialogResult.Cancel;
// cancelButton.Name = "cancelButton";
// cancelButton.Size = new Size(wBtn, hBtn);
// cancelButton.Text = "&Cancel";
// cancelButton.Location = new Point((size.Width - pad) * 4 / 4 - wBtn, yBtn);
// ib.Controls.Add(cancelButton);
//
// var okButton = new Button();
// okButton.DialogResult = DialogResult.OK;
// okButton.Name = "okButton";
// okButton.Size = new Size(wBtn, hBtn);
// okButton.Text = text_1;
// okButton.Location = new Point((size.Width - pad) * 3 / 4 - wBtn, yBtn);
// ib.Controls.Add(okButton);
//
// var anyButton = new Button();
// anyButton.DialogResult = DialogResult.Yes;
// anyButton.Name = "anyButton";
// anyButton.Size = new Size(wBtn, hBtn);
// anyButton.Text = text_2;
// anyButton.Location = new Point((size.Width - pad) * 2 / 4 - wBtn, yBtn);
// ib.Controls.Add(anyButton);
//
// var allButton = new Button();
// allButton.DialogResult = DialogResult.Retry;
// allButton.Name = "allButton";
// allButton.Size = new Size(wBtn, hBtn);
// allButton.Text = text_3;
// allButton.Location = new Point((size.Width - pad) * 1 / 4 - wBtn, yBtn);
// ib.Controls.Add(allButton);
//
//
// ib.AcceptButton = okButton; // [Enter]
// ib.CancelButton = cancelButton; // [Esc]
//
// dr = ib.ShowDialog();
//
// str = textBox.Text;
// }
// return dr;
// }
// /// <summary>
// /// Handles the text-changed of the inputbox to ensure a valid version #.
// /// NOTE: version is held in only 8 bits of the master-int (do not allow 0)
// /// </summary>
// /// <param name="sender"></param>
// /// <param name="e"></param>
// static void TextChanged_ver(object sender, EventArgs e)
// {
// var tb = sender as TextBox;
//
// int ver;
// if (!Int32.TryParse(tb.Text, out ver)
// || ver < 1 || ver > 255)
// {
// tb.Text = (hc.HENCH_SPELL_INFO_VERSION >> HENCH_SPELL_INFO_VERSION_SHIFT).ToString();
// tb.SelectionStart = tb.Text.Length;
//
// MessageBox.Show("Integer must be in range 1 to 255",
// " are you sure you know what you're doing",
// MessageBoxButtons.OK,
// MessageBoxIcon.Error,
// MessageBoxDefaultButton.Button1);
// }
// }
// /// <summary>
// /// Sets the InfoVersion of spell IDs.
// /// </summary>
// void SetInfoVersion_spells()
// {
// Spell spell = Spells[Id]; // use the current spell's ver as a basis
//
// int spellinfo;
// if ((spell.differ & control_Spells.bit_spellinfo) != 0)
// {
// spellinfo = SpellsChanged[Id].spellinfo;
// }
// else
// spellinfo = spell.spellinfo;
//
// int ver0 = (spellinfo & hc.HENCH_SPELL_INFO_VERSION_MASK);
// if (ver0 == 0)
// {
// ver0 = hc.HENCH_SPELL_INFO_VERSION;
// }
// ver0 >>= HENCH_SPELL_INFO_VERSION_SHIFT;
//
//
// string str = ver0.ToString();
// switch (InfoVersion(Type2da.Spells, ref str)) // get user-input w/ InfoVersion dialog
// {
// case DialogResult.OK: // change the current spell's version only
// if ((spellinfo & ~hc.HENCH_SPELL_INFO_VERSION_MASK) == 0) // force-clear the version if the rest of spellinfo is blank
// {
// if (spellinfo != 0)
// {
// spellinfo = 0;
// HenchControl.SetMasterText(spellinfo.ToString()); // firing the TextChanged event takes care of it.
// }
// }
// else
// {
// int ver = Int32.Parse(str); // the return from the dialog.
// if (ver != ver0) // check that user actually changed the value
// {
// spellinfo &= ~hc.HENCH_SPELL_INFO_VERSION_MASK;
// spellinfo |= (ver << HENCH_SPELL_INFO_VERSION_SHIFT);
// HenchControl.SetMasterText(spellinfo.ToString()); // firing the TextChanged event takes care of it.
// }
// }
// break;
//
// case DialogResult.Yes: // change the version of any currently changed spell
// SetInfoVersion_spells(str, false);
// break;
//
// case DialogResult.Retry: // change the version of all spells currently loaded
// SetInfoVersion_spells(str, true);
// break;
//
// case DialogResult.Cancel: // do a jig.
// break;
// }
// }
// /// <summary>
// /// Sets the InfoVersion of race IDs.
// /// </summary>
// void SetInfoVersion_racial()
// {
// Race race = Races[Id]; // use the current race's ver as a basis
//
// int racialflags;
// if ((race.differ & control_Racial.bit_flags) != 0)
// {
// racialflags = RacesChanged[Id].flags;
// }
// else
// racialflags = race.flags;
//
// int ver0 = (racialflags & hc.HENCH_SPELL_INFO_VERSION_MASK) >> HENCH_SPELL_INFO_VERSION_SHIFT;
//
// string str = ver0.ToString();
// switch (InfoVersion(Type2da.Racial, ref str)) // get user-input w/ InfoVersion dialog
// {
// case DialogResult.OK: // change the current race's version only
// {
// int ver = Int32.Parse(str); // the return from the dialog.
// if (ver != ver0) // check that user actually changed the value
// {
// racialflags &= ~hc.HENCH_SPELL_INFO_VERSION_MASK;
// racialflags |= (ver << HENCH_SPELL_INFO_VERSION_SHIFT);
// HenchControl.SetMasterText(racialflags.ToString()); // firing the TextChanged event takes care of it.
// }
// break;
// }
//
// case DialogResult.Yes: // change the version of any currently changed race
// SetInfoVersion_racial(str, false);
// break;
//
// case DialogResult.Retry: // change the version of all races currently loaded
// SetInfoVersion_racial(str, true);
// break;
//
// case DialogResult.Cancel: // do a jig.
// break;
// }
// }
// /// <summary>
// /// Sets the InfoVersion of class IDs.
// /// </summary>
// void SetInfoVersion_classes()
// {
// Class @class = Classes[Id]; // use the current class' ver as a basis
//
// int classflags;
// if ((@class.differ & control_Classes.bit_flags) != 0)
// {
// classflags = ClassesChanged[Id].flags;
// }
// else
// classflags = @class.flags;
//
// int ver0 = (classflags & hc.HENCH_SPELL_INFO_VERSION_MASK) >> HENCH_SPELL_INFO_VERSION_SHIFT;
//
// string str = ver0.ToString();
// switch (InfoVersion(Type2da.Classes, ref str)) // get user-input w/ InfoVersion dialog
// {
// case DialogResult.OK: // change the current class' version only
// {
// int ver = Int32.Parse(str); // the return from the dialog.
// if (ver != ver0) // check that user actually changed the value
// {
// classflags &= ~hc.HENCH_SPELL_INFO_VERSION_MASK;
// classflags |= (ver << HENCH_SPELL_INFO_VERSION_SHIFT);
// HenchControl.SetMasterText(classflags.ToString()); // firing the TextChanged event takes care of it.
// }
// break;
// }
//
// case DialogResult.Yes: // change the version of any currently changed class
// SetInfoVersion_classes(str, false);
// break;
//
// case DialogResult.Retry: // change the version of all classes currently loaded
// SetInfoVersion_classes(str, true);
// break;
//
// case DialogResult.Cancel: // do a jig.
// break;
// }
// }
}
}