-
Notifications
You must be signed in to change notification settings - Fork 324
/
DFLocation.cs
686 lines (558 loc) · 21.4 KB
/
DFLocation.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
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
// Project: Daggerfall Unity
// Copyright: Copyright (C) 2009-2022 Daggerfall Workshop
// Web Site: http://www.dfworkshop.net
// License: MIT License (http://www.opensource.org/licenses/mit-license.php)
// Source Code: https://github.com/Interkarma/daggerfall-unity
// Original Author: Gavin Clayton (interkarma@dfworkshop.net)
// Contributors:
//
// Notes:
//
#region Using Statements
using System;
using DaggerfallConnect.Arena2;
#endregion
namespace DaggerfallConnect
{
/// <summary>
/// Stores information about locations, such as cities and dungeons.
/// </summary>
public struct DFLocation
{
#region Structure Variables
/// <summary>
/// Set to true if loaded.
/// </summary>
public bool Loaded;
/// <summary>
/// Name of this location.
/// </summary>
public string Name;
/// <summary>
/// Name of the parent region.
/// IMPORTANT: This RegionName is used in many places as a string key and must always be the non-localized version as found in MAPS.BSA.
/// Anywhere using this for display to player should use TextProvider.GetLocalizedRegionName() instead.
/// </summary>
public string RegionName;
/// <summary>
/// True if location has a dungeon, otherwise false.
/// </summary>
public bool HasDungeon;
/// <summary>
/// RegionMapTable data for this location.
/// </summary>
public DFRegion.RegionMapTable MapTableData;
/// <summary>
/// Exterior location.
/// </summary>
public LocationExterior Exterior;
/// <summary>
/// Dungeon attached to location (if HasDungeon = true).
/// </summary>
public LocationDungeon Dungeon;
/// <summary>
/// Climate settings for this location.
/// </summary>
public ClimateSettings Climate;
/// <summary>
/// Political alignment of this location (equal to region index + 128).
/// </summary>
public int Politic;
/// <summary>
/// Region index.
/// </summary>
public int RegionIndex;
/// <summary>
/// Location index.
/// </summary>
public int LocationIndex;
#endregion
#region Methods
/// <summary>Some 1x1 locations (e.g. Privateer's Hold exterior) are positioned differently
/// Seems to be 1x1 blocks using CUST prefix, but possibly more research needed</summary>
public bool HasCustomLocationPosition()
{
const string custBlockPrefix = "CUST";
if (Exterior.ExteriorData.Width == 1 && Exterior.ExteriorData.Height == 1)
{
return Exterior.ExteriorData.BlockNames[0].StartsWith(custBlockPrefix);
}
return false;
}
#endregion
#region Building Enumerations
/// <summary>
/// Building types within cities.
/// </summary>
public enum BuildingTypes
{
None = -1,
Alchemist,
HouseForSale,
Armorer,
Bank,
Town4,
Bookseller,
ClothingStore,
FurnitureStore,
GemStore,
GeneralStore,
Library,
GuildHall,
PawnShop,
WeaponSmith,
Temple,
Tavern,
Palace,
House1, // Always has locked entry doors
House2, // Has unlocked doors from 0600-1800
House3,
House4,
House5,
House6,
Town23,
Ship, // Never displayed on automap
Special1 = 0x74, // Special1-4 never displayed on automap
Special2 = 0xdf,
Special3 = 0xf9,
Special4 = 0xfa,
AnyShop = 0xfffd, // DaggerfallUnity: all valid shop types
AnyHouse = 0xfffe, // DaggerfallUnity: all valid house types
AllValid = 0xffff, // DaggerfallUnity: all valid types
}
#endregion
#region Climate Enumerations
/// <summary>
/// Climate base type enumeration for climate-swapping textures.
/// </summary>
public enum ClimateBaseType
{
None = -1,
Desert = 0,
Mountain = 100,
Temperate = 300,
Swamp = 400,
}
/// <summary>
/// Climate texture groups for identifying how texture is used.
/// </summary>
public enum ClimateTextureGroup
{
None,
Nature,
Terrain,
Exterior,
Interior,
}
/// <summary>
/// Climate texture sets that can be cast to texture index for any climate.
/// Includes enumerations for detail/misc textures with no climate swap.
/// </summary>
public enum ClimateTextureSet
{
// General sets
None = -1,
Misc = 46,
// Terrain sets
Exterior_Terrain = 2,
// Exterior sets
Exterior_Ruins = 7,
Exterior_Ruins_2 = 8,
Exterior_Castle = 9,
Exterior_Castle_Snow = 10,
Exterior_CityA = 12,
Exterior_CityA_Snow = 13,
Exterior_CityB = 14,
Exterior_CityB_Snow = 15,
Exterior_CityWalls = 17,
Exterior_CityWalls_Snow = 18,
Exterior_Farm = 26,
Exterior_Farm_Snow = 27,
Exterior_Fences = 29,
Exterior_Fences_Snow = 30,
Exterior_MagesGuild = 35,
Exterior_MagesGuild_Snow = 36,
Exterior_Manor = 38,
Exterior_Manor_Snow = 39,
Exterior_MerchantHomes = 42,
Exterior_MerchantHomes_Snow = 43,
Exterior_TavernExteriors = 58,
Exterior_TavernExteriors_Snow = 59,
Exterior_TempleExteriors = 61,
Exterior_TempleExteriors_Snow = 62,
Exterior_Village = 64,
Exterior_Village_Snow = 65,
Exterior_Roofs = 69,
Exterior_Roofs_Snow = 70,
Exterior_CitySpec = 79,
Exterior_CitySpec_Snow = 80,
Exterior_CitySpecB = 82,
Exterior_CitySpecB_Snow = 83,
// Exterior misc (no climate variant)
Exterior_Hedges = 33,
Exterior_MiscWoodPlanks = 67,
Exterior_Doors = 74,
Exterior_BaseTextures = 85,
Exterior_Wagon = 88,
Exterior_BarnInterior = 171, // Used on underside of city roofs
Exterior_Barn = 171,
Exterior_Barn_Snow = 172,
// Interior sets
Interior_CastleInt = 11,
Interior_CityInt = 16,
Interior_CryptA = 19,
Interior_CryptB = 20,
Interior_DungeonsA = 22,
Interior_DungeonsB = 23,
Interior_DungeonsC = 24,
Interior_DungeonsNEWCs = 25,
Interior_FarmInt = 28,
Interior_MagesGuildInt = 37,
Interior_ManorInt = 40,
Interior_MarbleFloors = 41,
Interior_MerchantHomesInt = 44,
Interior_Mines = 45,
Interior_Caves = 47,
Interior_Paintings = 48,
Interior_TavernInt = 60,
Interior_TempleInt = 63,
Interior_VillageInt = 66,
Interior_Sewer = 68,
Interior_MiscFurniture = 90,
// Nature sets
Nature_RainForest = 500,
Nature_SubTropical = 501,
Nature_Swamp = 502,
Nature_Desert = 503,
Nature_TemperateWoodland = 504,
Nature_TemperateWoodland_Snow = 505,
Nature_WoodlandHills = 506,
Nature_WoodlandHills_Snow = 507,
Nature_HauntedWoodlands = 508,
Nature_HauntedWoodlands_Snow = 509,
Nature_Mountains = 510,
Nature_Mountains_Snow = 511,
}
/// <summary>
/// Weather variations of climate sets.
/// </summary>
public enum ClimateWeather
{
/// <summary>Dry summer weather. Use with any climate set.</summary>
Normal = 0,
/// <summary>Buildings and ground in winter (only valid with exterior climate sets).</summary>
Winter = 1,
/// <summary>Ground wet from rain (only valid with ClimateSet.Terrain).</summary>
Rain = 2,
}
#endregion
#region Holiday Enumerations
/// <summary>
/// Holiday ID numbers.
/// </summary>
public enum Holidays
{
None,
New_Life,
Scour_Day,
Ovanka,
South_Winds_Prayer,
Day_of_Lights,
Waking_Day,
Mad_Pelagius,
Othroktide,
Day_of_Release,
Hearts_Day,
Perserverance_Day,
Aduros_Nau,
First_Harvest,
Day_of_Waiting,
Flower_Day,
Festival_of_Blades,
Gardtide,
Day_of_the_Dead,
Day_of_Shame,
Jesters_Day,
Second_Harvest,
Marukhs_Day,
Fire_Festival,
Fishing_Day,
Drigh_RZimb,
Mid_Year,
Dancing_Day,
Tibedetha,
Merchants_Festival,
Divad_Etept,
Suns_Rest,
Fiery_Night,
Maiden_Katrica,
Koomu_Alazeri,
Feast_of_the_Tiger,
Appreciation_Day,
Harvest_End,
Tales_and_Tallow,
Khurat,
Riglametha,
Childrens_Day,
Dirij_Tereur,
Witches_Festival,
Broken_Diamonds,
Emperors_Birthday,
Serpents_Dance,
Moon_Festival,
Hel_Anseilak,
Warriors_Festival,
North_Winds_Festival,
Baranth_Do,
Chila,
Saturalia,
Old_Life_Festival, // Not used
}
#endregion
#region Climate Structures
/// <summary>
/// Contains settings for various climate data.
/// </summary>
public struct ClimateSettings
{
/// <summary>World climate value from CLIMATE.PAK. Ranges from 223-232.</summary>
public int WorldClimate;
/// <summary>Base climate type.</summary>
public ClimateBaseType ClimateType;
/// <summary>Texture set for nature textures.</summary>
public ClimateTextureSet NatureSet;
/// <summary>Texture archive index for ground plane.</summary>
public int GroundArchive;
/// <summary>Texture archive index for ground scenery (rocks, trees, etc.).</summary>
public int NatureArchive;
/// <summary>Texture archive index for base sky set.</summary>
public int SkyBase;
/// <summary>The race of wandering NPCs in this subclimate.</summary>
public FactionFile.FactionRaces People;
/// <summary>The name bank of NPCs in this subclimate.</summary>
public FactionFile.FactionRaces Names;
}
#endregion
#region Shared Child Structures
/// <summary>
/// Initial data common to both dungeons and exterior locations.
/// </summary>
public struct LocationRecordElement
{
/// <summary>Number of doors in this location.</summary>
internal UInt32 DoorCount;
/// <summary>Door data array with DoorCount members.</summary>
internal LocationDoorElement[] Doors;
/// <summary>Header for location data.</summary>
public LocationRecordElementHeader Header;
}
/// <summary>
/// Describes a door element.
/// </summary>
public struct LocationDoorElement
{
/// <summary>Index to element within LocationExterior.BuildingData array.
/// Or 0xffff when door is not associated with BuildingData array.</summary>
public UInt16 BuildingDataIndex;
/// <summary>Always 0.</summary>
public Byte NullValue;
/// <summary>Unknown mask;</summary>
public Byte Mask;
/// <summary>Unknown.</summary>
public Byte Unknown1;
/// <summary>Unknown.</summary>
public Byte Unknown2;
}
/// <summary>
/// Header used for each location record element.
/// </summary>
public struct LocationRecordElementHeader
{
/// <summary>Always 1.</summary>
internal UInt32 AlwaysOne1;
/// <summary>Always 0.</summary>
internal UInt16 NullValue1;
/// <summary>Always 0.</summary>
internal Byte NullValue2;
/// <summary>X coordinate for location in world units.</summary>
public Int32 X;
/// <summary>Always 0.</summary>
internal UInt32 NullValue3;
/// <summary>X coordinate for location in world units.</summary>
public Int32 Y;
/// <summary>Set to 0x0000 for dungeon interior data, or 0x8000 for location exterior data.</summary>
public UInt16 IsExterior;
/// <summary>Always 0.</summary>
internal UInt16 NullValue4;
/// <summary>Unknown.</summary>
internal UInt32 Unknown1;
/// <summary>
/// Unknown value for LocationDungeon structure, used by SongManager to select songs.
/// Location index for Exterior structure. (should match top level index)
/// </summary>
public UInt32 Unknown2;
/// <summary>Always 1.</summary>
internal UInt16 AlwaysOne2;
/// <summary>LocationID used by the quest subsystem.</summary>
public UInt16 LocationId;
/// <summary>Always 0.</summary>
internal UInt32 NullValue5;
/// <summary>Set to 0x0000 for exterior data, or 0x0001 for interior data.</summary>
public UInt16 IsInterior;
/// <summary>Set to 0x0000 when no exterior data present, or ID of exterior location</summary>
public UInt32 ExteriorLocationId;
/// <summary>Array of 26 0-value bytes.</summary>
internal Byte[] NullValue6;
/// <summary>Name of location used when entering it.</summary>
public String LocationName;
/// <summary>Array of 9 unknown bytes.</summary>
internal Byte[] Unknown3;
}
#endregion
#region Exterior Child Structures
/// <summary>
/// Describes exterior location.
/// </summary>
public struct LocationExterior
{
/// <summary>Each location is described by a LocationRecordElement.</summary>
public LocationRecordElement RecordElement;
/// <summary>The number of building structures present.</summary>
public UInt16 BuildingCount;
/// <summary>Unknown.</summary>
internal Byte[] Unknown1;
/// <summary>Data associated with each building.</summary>
public BuildingData[] Buildings;
/// <summary>Exterior map data including layout information.</summary>
public ExteriorData ExteriorData;
}
/// <summary>
/// Data relating to a building.
/// </summary>
public struct BuildingData
{
/// <summary>Used to generate building name.</summary>
public UInt16 NameSeed;
/// <summary>For taverns this is the time in game minutes when room rental will end.</summary>
internal UInt32 ServiceTimeLimit;
/// <summary>Unknown. Set to 1 after renting a tavern room</summary>
internal UInt16 Unknown;
/// <summary>Unknown.</summary>
internal UInt16 Unknown2;
/// <summary>Unknown.</summary>
internal UInt32 Unknown3;
/// <summary>Unknown.</summary>
internal UInt32 Unknown4;
/// <summary>FactionId associated with building, or 0 if no faction.</summary>
public UInt16 FactionId;
/// <summary>Generally increases with each building.
/// Known use by classic is in identifying whether inside the player's house when trying to rest.</summary>
public Int16 Sector;
/// <summary>Should always be the same as LocationRecordElementHeader.LocationId.</summary>
public UInt16 LocationId;
/// <summary>Type of building.</summary>
public BuildingTypes BuildingType;
/// <summary>Specifies quality of building from 1-20.</summary>
public Byte Quality;
}
/// <summary>
/// Layout data for exterior location.
/// </summary>
public struct ExteriorData
{
/// <summary>Another name for this location. Changing seems to have no effect in game.</summary>
public String AnotherName;
/// <summary>This (value and 0x000fffff) matches (MapTable.MapId and 0x000fffff).</summary>
public Int32 MapId;
/// <summary>Location ID.</summary>
public UInt32 LocationId;
/// <summary>Width of exterior map grid from 1-8.</summary>
public Byte Width;
/// <summary>Height of exterior map grid from 1-8.</summary>
public Byte Height;
/// <summary>Unknown.</summary>
internal Byte[] Unknown2;
/// <summary>Unknown.</summary>
internal Byte Unknown3;
/// <summary>ASCII value for first letter in .RMB file name.</summary>
internal Byte Letter1ForRMBName;
/// <summary>If non-zero, ships can be purchased at banks here. Also has an unknown use.</summary>
public Byte PortTownAndUnknown;
/// <summary>Only first Width*Height elements will have any meaning.</summary>
internal Byte[] BlockIndex;
/// <summary>Only first Width*Height elements will have any meaning.</summary>
internal Byte[] BlockNumber;
/// <summary>Only first Width*Height elements will have any meaning.</summary>
internal Byte[] BlockCharacter;
/// <summary>Resolved block names.</summary>
public string[] BlockNames;
/// <summary>Unknown.</summary>
internal Byte[] Unknown4;
/// <summary>Always 0.</summary>
internal UInt64 NullValue1;
/// <summary>Always 0.</summary>
internal Byte NullValue2;
/// <summary>Unknown.</summary>
internal UInt32[] Unknown5;
/// <summary>Always 0.</summary>
internal Byte[] NullValue3;
/// <summary>Unknown.</summary>
internal UInt32 Unknown6;
}
#endregion
#region Dungeon Child Structures
/// <summary>
/// Describes a dungeon map.
/// </summary>
public struct LocationDungeon
{
/// <summary>Each dungeon is described by a LocationRecordElement.</summary>
public LocationRecordElement RecordElement;
/// <summary>Header for dungeon layout.</summary>
public DungeonHeader Header;
/// <summary>Layout of dungeon.</summary>
public DungeonBlock[] Blocks;
}
/// <summary>
/// Header preceding dungeon layout elements.
/// </summary>
public struct DungeonHeader
{
/// <summary>Always 0.</summary>
internal UInt16 NullValue1;
/// <summary>Unknown.</summary>
internal UInt32 Unknown1;
/// <summary>Unknown.</summary>
internal UInt32 Unknown2;
/// <summary>Count of DungeonBlock elements.</summary>
public UInt16 BlockCount;
/// <summary>Unknown.</summary>
internal Byte[] Unknown3;
}
/// <summary>
/// Describes a dungeon block element in a dungeon map layout.
/// </summary>
public struct DungeonBlock
{
/// <summary>X position of block.</summary>
public SByte X;
/// <summary>Y position of block.</summary>
public SByte Z;
/// <summary>Bitfield containing BlockNumber, start bit, and BlockIndex.</summary>
internal UInt16 BlockNumberStartIndexBitfield;
/// <summary>BlockNumber read from bitfield.</summary>
internal UInt16 BlockNumber;
/// <summary>IsStartingBlock read from bitfield.</summary>
public Boolean IsStartingBlock;
/// <summary>BlockIndex read from bitfield.</summary>
internal Byte BlockIndex;
/// <summary>Name of RDB block.</summary>
public String BlockName;
/// <summary>Height level of dungeon water. 10000 means no water.</summary>
public Int16 WaterLevel;
/// <summary>Whether this block is a main story castle area.</summary>
public Boolean CastleBlock;
}
#endregion
}
}