commonlibsse_ng\re\b/
BGSEncounterZone.rs

1use crate::re::BGSLoadFormBuffer::BGSLoadFormBuffer;
2use crate::re::BGSSaveFormBuffer::BGSSaveFormBuffer;
3use crate::re::FormTypes::FormType;
4use crate::re::TESFile::TESFile;
5use crate::re::TESForm::{DerivedTESForm, TESForm};
6use crate::re::offsets_rtti::RTTI_BGSEncounterZone;
7use crate::re::offsets_vtable::VTABLE_BGSEncounterZone;
8use crate::re::{BGSLocation, TESFaction};
9use crate::rel::id::VariantID;
10use std::ptr;
11
12/// Represents the `ENCOUNTER_ZONE_DATA` structure.
13#[repr(C)]
14pub struct ENCOUNTER_ZONE_DATA {
15    /// Pointer to `TESFaction`.
16    pub zone_owner: *mut TESFaction, // 00
17
18    /// Pointer to `BGSLocation`.
19    pub location: *mut BGSLocation, // 08
20
21    /// Owner rank.
22    pub owner_rank: i8, // 10
23
24    /// Minimum level.
25    pub min_level: i8, // 11
26
27    /// Encounter zone flags.
28    pub flags: Flags, // 12
29
30    /// Maximum level.
31    pub max_level: i8, // 13
32
33    /// Padding to align the structure with C++ layout.
34    pub pad14: u32, // 14
35}
36
37const _: () = {
38    assert!(core::mem::size_of::<ENCOUNTER_ZONE_DATA>() == 0x18);
39};
40
41impl Default for ENCOUNTER_ZONE_DATA {
42    #[inline]
43    fn default() -> Self {
44        Self {
45            zone_owner: ptr::null_mut(),
46            location: ptr::null_mut(),
47            owner_rank: 0,
48            min_level: 0,
49            flags: Flags::empty(),
50            max_level: 0,
51            pad14: 0,
52        }
53    }
54}
55
56bitflags::bitflags! {
57    #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
58    pub struct Flags: u8 {
59        const None = 0;
60        const NEVER_RESETS = 1 << 0;
61        const MATCH_PC_BELOW_MINIMUM_LEVEL = 1 << 1;
62        const DISABLE_COMBAT_BOUNDARY = 1 << 2;
63    }
64}
65
66/// Represents the `ENCOUNTER_ZONE_GAME_DATA` structure.
67#[repr(C)]
68pub struct ENCOUNTER_ZONE_GAME_DATA {
69    /// Detach time.
70    pub detach_time: u32, // 00
71
72    /// Attach time.
73    pub attach_time: u32, // 04
74
75    /// Reset time.
76    pub reset_time: u32, // 08
77
78    /// Zone level.
79    pub zone_level: u16, // 0C
80
81    /// Padding.
82    pub pad0d: u16, // 0E
83}
84
85const _: () = {
86    assert!(core::mem::size_of::<ENCOUNTER_ZONE_GAME_DATA>() == 0x10);
87};
88
89impl Default for ENCOUNTER_ZONE_GAME_DATA {
90    #[inline]
91    fn default() -> Self {
92        Self { detach_time: 0, attach_time: 0, reset_time: 0, zone_level: 0, pad0d: 0 }
93    }
94}
95
96/// Represents the `BGSEncounterZone` class.
97#[repr(C)]
98pub struct BGSEncounterZone {
99    /// Base class `TESForm`.
100    pub __base: TESForm,
101
102    /// Encounter zone data.
103    pub data: ENCOUNTER_ZONE_DATA, // 20
104
105    /// Encounter zone game data.
106    pub game_data: ENCOUNTER_ZONE_GAME_DATA, // 38
107}
108
109const _: () = {
110    assert!(core::mem::offset_of!(BGSEncounterZone, __base) == 0x0);
111    assert!(core::mem::offset_of!(BGSEncounterZone, data) == 0x20);
112    assert!(core::mem::offset_of!(BGSEncounterZone, game_data) == 0x38);
113    assert!(core::mem::size_of::<BGSEncounterZone>() == 0x48);
114};
115
116bitflags::bitflags! {
117    /// - Maybe unused
118    #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
119    pub struct ChangeFlags: u32 {
120        const ZONE_FLAGS = 1 << 1;
121        const GAME_DATA = 1 << 31;
122    }
123
124    /// - Maybe unused
125    #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
126    pub struct RecordFlags: u32 {
127        const DELETED = 1 << 5;
128        const IGNORED = 1 << 12;
129    }
130}
131
132impl DerivedTESForm for BGSEncounterZone {
133    const FORM_TYPE: FormType = Self::FORM_TYPE;
134
135    #[inline]
136    fn get_form(&self) -> &TESForm {
137        &self.__base
138    }
139}
140
141impl BGSEncounterZone {
142    /// Address & offset of the runtime type information (RTTI) identifier.
143    pub const RTTI: VariantID = RTTI_BGSEncounterZone;
144
145    /// Address & offset of the virtual function table.
146    pub const VTABLE: [VariantID; 1] = VTABLE_BGSEncounterZone;
147
148    /// The `FormType` value for encounter zones.
149    pub const FORM_TYPE: FormType = FormType::EncounterZone;
150}
151
152/// The virtual function table for `BGSEncounterZone`.
153#[repr(C)]
154pub struct BGSEncounterZoneVtbl {
155    /// Destructor function pointer.
156    pub CxxDrop: fn(this: &mut BGSEncounterZone),
157
158    /// Function pointer for `InitializeData`.
159    pub InitializeData: fn(this: &mut BGSEncounterZone),
160
161    /// Function pointer for `Load`.
162    pub Load: fn(this: &mut BGSEncounterZone, mod_file: *mut TESFile) -> bool,
163
164    /// Function pointer for `SaveGame`.
165    pub SaveGame: fn(this: &BGSEncounterZone, buf: *mut BGSSaveFormBuffer),
166
167    /// Function pointer for `LoadGame`.
168    pub LoadGame: fn(this: &mut BGSEncounterZone, buf: *mut BGSLoadFormBuffer),
169
170    /// Function pointer for `Revert`.
171    pub Revert: fn(this: &mut BGSEncounterZone, buf: *mut BGSLoadFormBuffer),
172
173    /// Function pointer for `InitItemImpl`.
174    pub InitItemImpl: fn(this: &mut BGSEncounterZone),
175}