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
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
//! Various enums used by the game.
use crate::ffi;
use crate::ffi::type_matchup::Type;

#[repr(i32)]
#[derive(PartialEq, Eq, Clone, Copy)]
/// Move index of a monster, used by some functions.
pub enum TargetTypeIndex {
    FirstType = 0,
    SecondType = 1,
}

#[repr(u32)]
#[derive(PartialEq, Eq, Clone, Copy)]
/// Describes the effectiveness of a move's type against type(s).
pub enum DungeonTypeMatchup {
    Immune = ffi::type_matchup::MATCHUP_IMMUNE,
    NotVeryEffective = ffi::type_matchup::MATCHUP_NOT_VERY_EFFECTIVE,
    Neutral = ffi::type_matchup::MATCHUP_NEUTRAL,
    SuperEffective = ffi::type_matchup::MATCHUP_SUPER_EFFECTIVE,
}

impl TryFrom<ffi::type_matchup::Type> for DungeonTypeMatchup {
    type Error = ();

    fn try_from(value: Type) -> Result<Self, Self::Error> {
        match value {
            ffi::type_matchup::MATCHUP_IMMUNE => Ok(DungeonTypeMatchup::Immune),
            ffi::type_matchup::MATCHUP_NOT_VERY_EFFECTIVE => {
                Ok(DungeonTypeMatchup::NotVeryEffective)
            }
            ffi::type_matchup::MATCHUP_NEUTRAL => Ok(DungeonTypeMatchup::Neutral),
            ffi::type_matchup::MATCHUP_SUPER_EFFECTIVE => Ok(DungeonTypeMatchup::SuperEffective),
            _ => Err(()),
        }
    }
}

#[repr(u32)]
#[derive(PartialEq, Eq, Clone, Copy)]
/// The type of an entity in a dungeon.
pub enum DungeonEntityType {
    Nothing = ffi::entity_type::ENTITY_NOTHING,
    Monster = ffi::entity_type::ENTITY_MONSTER,
    Trap = ffi::entity_type::ENTITY_TRAP,
    Item = ffi::entity_type::ENTITY_ITEM,
    HiddenStairs = ffi::entity_type::ENTITY_HIDDEN_STAIRS,
}

impl TryFrom<ffi::entity_type::Type> for DungeonEntityType {
    type Error = ();

    fn try_from(value: ffi::entity_type::Type) -> Result<Self, Self::Error> {
        match value {
            ffi::entity_type::ENTITY_NOTHING => Ok(DungeonEntityType::Nothing),
            ffi::entity_type::ENTITY_MONSTER => Ok(DungeonEntityType::Monster),
            ffi::entity_type::ENTITY_TRAP => Ok(DungeonEntityType::Trap),
            ffi::entity_type::ENTITY_ITEM => Ok(DungeonEntityType::Item),
            ffi::entity_type::ENTITY_HIDDEN_STAIRS => Ok(DungeonEntityType::HiddenStairs),
            _ => Err(()),
        }
    }
}

#[repr(u32)]
#[derive(PartialEq, Eq, Clone, Copy)]
/// The gender of a monster.
pub enum MonsterGender {
    Invalid = ffi::monster_gender::GENDER_INVALID,
    Male = ffi::monster_gender::GENDER_MALE,
    Female = ffi::monster_gender::GENDER_FEMALE,
    Genderless = ffi::monster_gender::GENDER_GENDERLESS,
}

/// Invalid values for the enum are converted into [`Self::Invalid`]
impl From<ffi::monster_gender::Type> for MonsterGender {
    fn from(value: ffi::entity_type::Type) -> Self {
        match value {
            ffi::monster_gender::GENDER_INVALID => MonsterGender::Invalid,
            ffi::monster_gender::GENDER_MALE => MonsterGender::Male,
            ffi::monster_gender::GENDER_FEMALE => MonsterGender::Female,
            ffi::monster_gender::GENDER_GENDERLESS => MonsterGender::Genderless,
            _ => MonsterGender::Invalid,
        }
    }
}

#[repr(u32)]
#[derive(PartialEq, Eq, Clone, Copy)]
/// The category of a move.
pub enum MoveCategory {
    None = ffi::move_category::CATEGORY_NONE,
    Physical = ffi::move_category::CATEGORY_PHYSICAL,
    Special = ffi::move_category::CATEGORY_SPECIAL,
    Status = ffi::move_category::CATEGORY_STATUS,
}

impl TryFrom<ffi::move_category::Type> for MoveCategory {
    type Error = ();

    fn try_from(value: ffi::move_category::Type) -> Result<Self, Self::Error> {
        match value {
            ffi::move_category::CATEGORY_NONE => Ok(MoveCategory::None),
            ffi::move_category::CATEGORY_PHYSICAL => Ok(MoveCategory::Physical),
            ffi::move_category::CATEGORY_SPECIAL => Ok(MoveCategory::Special),
            ffi::move_category::CATEGORY_STATUS => Ok(MoveCategory::Status),
            _ => Err(()),
        }
    }
}

#[repr(u32)]
#[derive(PartialEq, Eq, Clone, Copy)]
/// The type of a floor.
pub enum FloorType {
    /// The floor is neither a fixed floor nor does it contain a rescue point.
    Normal = ffi::floor_type::FLOOR_TYPE_NORMAL,
    /// The floor is a fixed floor.
    Fixed = ffi::floor_type::FLOOR_TYPE_FIXED,
    /// The floor has a rescue point.
    Rescue = ffi::floor_type::FLOOR_TYPE_RESCUE,
}

impl TryFrom<ffi::floor_type::Type> for FloorType {
    type Error = ();

    fn try_from(value: ffi::floor_type::Type) -> Result<Self, Self::Error> {
        match value {
            ffi::floor_type::FLOOR_TYPE_NORMAL => Ok(FloorType::Normal),
            ffi::floor_type::FLOOR_TYPE_FIXED => Ok(FloorType::Fixed),
            ffi::floor_type::FLOOR_TYPE_RESCUE => Ok(FloorType::Rescue),
            _ => Err(()),
        }
    }
}

#[repr(u32)]
#[derive(PartialEq, Eq, Clone, Copy)]
/// The type of terrain of a tile.
pub enum TerrainType {
    Wall = ffi::terrain_type::TERRAIN_WALL,
    Normal = ffi::terrain_type::TERRAIN_NORMAL,
    Secondary = ffi::terrain_type::TERRAIN_SECONDARY,
    Chasm = ffi::terrain_type::TERRAIN_CHASM,
}

impl TryFrom<ffi::terrain_type::Type> for TerrainType {
    type Error = ();

    fn try_from(value: ffi::terrain_type::Type) -> Result<Self, Self::Error> {
        match value {
            ffi::terrain_type::TERRAIN_WALL => Ok(TerrainType::Wall),
            ffi::terrain_type::TERRAIN_NORMAL => Ok(TerrainType::Normal),
            ffi::terrain_type::TERRAIN_SECONDARY => Ok(TerrainType::Secondary),
            ffi::terrain_type::TERRAIN_CHASM => Ok(TerrainType::Chasm),
            _ => Err(()),
        }
    }
}

#[repr(u32)]
#[derive(PartialEq, Eq, Clone, Copy)]
/// The type of secondary terrain of a tile.
pub enum SecondaryTerrainType {
    Water = ffi::secondary_terrain_type::SECONDARY_TERRAIN_WATER,
    Lava = ffi::secondary_terrain_type::SECONDARY_TERRAIN_LAVA,
    Chasm = ffi::secondary_terrain_type::SECONDARY_TERRAIN_CHASM,
}

impl TryFrom<ffi::secondary_terrain_type::Type> for SecondaryTerrainType {
    type Error = ();

    fn try_from(value: ffi::secondary_terrain_type::Type) -> Result<Self, Self::Error> {
        match value {
            ffi::secondary_terrain_type::SECONDARY_TERRAIN_WATER => Ok(SecondaryTerrainType::Water),
            ffi::secondary_terrain_type::SECONDARY_TERRAIN_LAVA => Ok(SecondaryTerrainType::Lava),
            ffi::secondary_terrain_type::SECONDARY_TERRAIN_CHASM => Ok(SecondaryTerrainType::Chasm),
            _ => Err(()),
        }
    }
}

#[repr(u32)]
#[derive(PartialEq, Eq, Clone, Copy)]
/// Types of weather.
pub enum Weather {
    Clear = ffi::weather_id::WEATHER_CLEAR,
    Sunny = ffi::weather_id::WEATHER_SUNNY,
    Sandstorm = ffi::weather_id::WEATHER_SANDSTORM,
    Cloudy = ffi::weather_id::WEATHER_CLOUDY,
    Rain = ffi::weather_id::WEATHER_RAIN,
    Hail = ffi::weather_id::WEATHER_HAIL,
    Fog = ffi::weather_id::WEATHER_FOG,
    Snow = ffi::weather_id::WEATHER_SNOW,
    Random = ffi::weather_id::WEATHER_RANDOM,
}

impl TryFrom<ffi::weather_id::Type> for Weather {
    type Error = ();

    fn try_from(value: ffi::weather_id::Type) -> Result<Self, Self::Error> {
        match value {
            ffi::weather_id::WEATHER_CLEAR => Ok(Weather::Clear),
            ffi::weather_id::WEATHER_SUNNY => Ok(Weather::Sunny),
            ffi::weather_id::WEATHER_SANDSTORM => Ok(Weather::Sandstorm),
            ffi::weather_id::WEATHER_CLOUDY => Ok(Weather::Cloudy),
            ffi::weather_id::WEATHER_RAIN => Ok(Weather::Rain),
            ffi::weather_id::WEATHER_HAIL => Ok(Weather::Hail),
            ffi::weather_id::WEATHER_FOG => Ok(Weather::Fog),
            ffi::weather_id::WEATHER_SNOW => Ok(Weather::Snow),
            ffi::weather_id::WEATHER_RANDOM => Ok(Weather::Random),
            _ => Err(()),
        }
    }
}

#[repr(u32)]
#[derive(PartialEq, Eq, Clone, Copy)]
/// Types of weather.
pub enum DungeonObjective {
    Story = ffi::dungeon_objective::OBJECTIVE_STORY,
    Rescue = ffi::dungeon_objective::OBJECTIVE_RESCUE,
    Normal = ffi::dungeon_objective::OBJECTIVE_NORMAL,
}

impl TryFrom<ffi::dungeon_objective::Type> for DungeonObjective {
    type Error = ();

    fn try_from(value: ffi::dungeon_objective::Type) -> Result<Self, Self::Error> {
        match value {
            ffi::dungeon_objective::OBJECTIVE_STORY => Ok(DungeonObjective::Story),
            ffi::dungeon_objective::OBJECTIVE_RESCUE => Ok(DungeonObjective::Rescue),
            ffi::dungeon_objective::OBJECTIVE_NORMAL => Ok(DungeonObjective::Normal),
            _ => Err(()),
        }
    }
}

#[repr(i32)]
#[derive(PartialEq, Eq, Clone, Copy)]
/// Direction on the dungeon grid
pub enum Direction {
    Down = ffi::direction_id::DIR_DOWN,
    DownRight = ffi::direction_id::DIR_DOWN_RIGHT,
    Right = ffi::direction_id::DIR_RIGHT,
    UpRight = ffi::direction_id::DIR_UP_RIGHT,
    Up = ffi::direction_id::DIR_UP,
    UpLeft = ffi::direction_id::DIR_UP_LEFT,
    Left = ffi::direction_id::DIR_LEFT,
    DownLeft = ffi::direction_id::DIR_DOWN_LEFT,
    Current = ffi::direction_id::DIR_CURRENT,
}

impl TryFrom<ffi::direction_id::Type> for Direction {
    type Error = ();

    fn try_from(value: ffi::direction_id::Type) -> Result<Self, Self::Error> {
        match value {
            ffi::direction_id::DIR_DOWN => Ok(Direction::Down),
            ffi::direction_id::DIR_DOWN_RIGHT => Ok(Direction::DownRight),
            ffi::direction_id::DIR_RIGHT => Ok(Direction::Right),
            ffi::direction_id::DIR_UP_RIGHT => Ok(Direction::UpRight),
            ffi::direction_id::DIR_UP => Ok(Direction::Up),
            ffi::direction_id::DIR_UP_LEFT => Ok(Direction::UpLeft),
            ffi::direction_id::DIR_LEFT => Ok(Direction::Left),
            ffi::direction_id::DIR_DOWN_LEFT => Ok(Direction::DownLeft),
            ffi::direction_id::DIR_CURRENT => Ok(Direction::Current),
            _ => Err(()),
        }
    }
}

#[repr(u32)]
#[derive(PartialEq, Eq, Clone, Copy)]
/// Different types of warp effects
pub enum WarpType {
    /// Warp to a random position
    Random = ffi::warp_type::WARP_RANDOM,
    /// Warp within 2 tiles of the stairs
    Stairs2 = ffi::warp_type::WARP_STAIRS_2,
    /// Warp within 2 tiles of a specified position
    PositionFuzzy = ffi::warp_type::WARP_POSITION_FUZZY,
    /// Warp to an exact position
    PositionExact = ffi::warp_type::WARP_POSITION_EXACT,
    /// Warp within 3 tiles of the stairs
    Stairs3 = ffi::warp_type::WARP_STAIRS_3,
    /// Warp within 2 tiles of the leader
    Leader = ffi::warp_type::WARP_LEADER,
}

impl TryFrom<ffi::warp_type::Type> for WarpType {
    type Error = ();

    fn try_from(value: ffi::warp_type::Type) -> Result<Self, Self::Error> {
        match value {
            ffi::warp_type::WARP_RANDOM => Ok(WarpType::Random),
            ffi::warp_type::WARP_STAIRS_2 => Ok(WarpType::Stairs2),
            ffi::warp_type::WARP_POSITION_FUZZY => Ok(WarpType::PositionFuzzy),
            ffi::warp_type::WARP_POSITION_EXACT => Ok(WarpType::PositionExact),
            ffi::warp_type::WARP_STAIRS_3 => Ok(WarpType::Stairs3),
            ffi::warp_type::WARP_LEADER => Ok(WarpType::Leader),
            _ => Err(()),
        }
    }
}

#[repr(i32)]
#[derive(PartialEq, Eq, Clone, Copy)]
/// The status of a monster's Conversion 2 state.
pub enum Conversion2Status {
    /// The monster is not under the effect of Conversion 2.
    None = 0,
    /// The monster is under the effect of Conversion 2 from a status.
    FromStatus = 1,
    /// The monster is under the effect of Conversion 2 from an exclusive item.
    FromExclusiveItem = 2,
}

impl TryFrom<i32> for Conversion2Status {
    type Error = ();

    fn try_from(value: i32) -> Result<Self, Self::Error> {
        match value {
            0 => Ok(Conversion2Status::None),
            1 => Ok(Conversion2Status::FromStatus),
            2 => Ok(Conversion2Status::FromExclusiveItem),
            _ => Err(()),
        }
    }
}

#[repr(i32)]
#[derive(PartialEq, Eq, Clone, Copy)]
/// Controls whether the loop that runs until the current floor ends should continue
/// iterating or not and why
pub enum FloorLoopStatus {
    /// The floor loop keeps executing as normal
    Continue = 0,
    /// The floor loop exits because the leader fainted
    LeaderFainted = 1,
    /// The floor loop exits because the floor is over
    NextFloor = 2,
}

impl TryFrom<ffi::floor_loop_status::Type> for FloorLoopStatus {
    type Error = ();

    fn try_from(value: ffi::floor_loop_status::Type) -> Result<Self, Self::Error> {
        match value {
            ffi::floor_loop_status::FLOOR_LOOP_CONTINUE => Ok(FloorLoopStatus::Continue),
            ffi::floor_loop_status::FLOOR_LOOP_LEADER_FAINTED => Ok(FloorLoopStatus::LeaderFainted),
            ffi::floor_loop_status::FLOOR_LOOP_NEXT_FLOOR => Ok(FloorLoopStatus::NextFloor),
            _ => Err(()),
        }
    }
}

#[repr(u32)]
#[derive(PartialEq, Eq, Clone, Copy)]
/// Indicates whether or not the attempt of generating a mission was successful or not.
pub enum MissionGenerationResult {
    /// Mission was successfully generated
    Success = ffi::mission_generation_result::MISSION_GENERATION_SUCCESS,
    /// Mission generation failed.
    Failure = ffi::mission_generation_result::MISSION_GENERATION_FAILURE,
    /// Mission generation failed, the game should not try to generate more.
    GlobalFailure = ffi::mission_generation_result::MISSION_GENERATION_GLOBAL_FAILURE,
}

impl TryFrom<ffi::mission_generation_result::Type> for MissionGenerationResult {
    type Error = ();

    fn try_from(value: Type) -> Result<Self, Self::Error> {
        match value {
            ffi::mission_generation_result::MISSION_GENERATION_SUCCESS => {
                Ok(MissionGenerationResult::Success)
            }
            ffi::mission_generation_result::MISSION_GENERATION_FAILURE => {
                Ok(MissionGenerationResult::Failure)
            }
            ffi::mission_generation_result::MISSION_GENERATION_GLOBAL_FAILURE => {
                Ok(MissionGenerationResult::GlobalFailure)
            }
            _ => Err(()),
        }
    }
}

#[repr(u32)]
#[derive(PartialEq, Eq, Clone, Copy)]
/// Group of mission type on a dungeon floor.
pub enum MissionTypeGroup {
    RescueClient = ffi::mission_type::MISSION_RESCUE_CLIENT,
    RescueTarget = ffi::mission_type::MISSION_RESCUE_TARGET,
    EscortToTarget = ffi::mission_type::MISSION_ESCORT_TO_TARGET,
    ExploreWithClient = ffi::mission_type::MISSION_EXPLORE_WITH_CLIENT,
    ProspectWithClient = ffi::mission_type::MISSION_PROSPECT_WITH_CLIENT,
    GuideClient = ffi::mission_type::MISSION_GUIDE_CLIENT,
    FindItem = ffi::mission_type::MISSION_FIND_ITEM,
    DeliverItem = ffi::mission_type::MISSION_DELIVER_ITEM,
    SearchForTarget = ffi::mission_type::MISSION_SEARCH_FOR_TARGET,
    TakeItemFromOutlaw = ffi::mission_type::MISSION_TAKE_ITEM_FROM_OUTLAW,
    ArrestOutlaw = ffi::mission_type::MISSION_ARREST_OUTLAW,
    ChallengeRequest = ffi::mission_type::MISSION_CHALLENGE_REQUEST,
    TreasureMemo = ffi::mission_type::MISSION_TREASURE_MEMO,
}

impl TryFrom<ffi::mission_type::Type> for MissionTypeGroup {
    type Error = ();

    fn try_from(value: Type) -> Result<Self, Self::Error> {
        match value {
            ffi::mission_type::MISSION_RESCUE_CLIENT => Ok(MissionTypeGroup::RescueClient),
            ffi::mission_type::MISSION_RESCUE_TARGET => Ok(MissionTypeGroup::RescueTarget),
            ffi::mission_type::MISSION_ESCORT_TO_TARGET => Ok(MissionTypeGroup::EscortToTarget),
            ffi::mission_type::MISSION_EXPLORE_WITH_CLIENT => {
                Ok(MissionTypeGroup::ExploreWithClient)
            }
            ffi::mission_type::MISSION_PROSPECT_WITH_CLIENT => {
                Ok(MissionTypeGroup::ProspectWithClient)
            }
            ffi::mission_type::MISSION_GUIDE_CLIENT => Ok(MissionTypeGroup::GuideClient),
            ffi::mission_type::MISSION_FIND_ITEM => Ok(MissionTypeGroup::FindItem),
            ffi::mission_type::MISSION_DELIVER_ITEM => Ok(MissionTypeGroup::DeliverItem),
            ffi::mission_type::MISSION_SEARCH_FOR_TARGET => Ok(MissionTypeGroup::SearchForTarget),
            ffi::mission_type::MISSION_TAKE_ITEM_FROM_OUTLAW => {
                Ok(MissionTypeGroup::TakeItemFromOutlaw)
            }
            ffi::mission_type::MISSION_ARREST_OUTLAW => Ok(MissionTypeGroup::ArrestOutlaw),
            ffi::mission_type::MISSION_CHALLENGE_REQUEST => Ok(MissionTypeGroup::ChallengeRequest),
            ffi::mission_type::MISSION_TREASURE_MEMO => Ok(MissionTypeGroup::TreasureMemo),
            _ => Err(()),
        }
    }
}

#[derive(PartialEq, Eq, Clone, Copy)]
/// Specific mission type on a dungeon floor.
pub enum MissionType {
    RescueClient,
    RescueTarget,
    EscortToTarget,
    ExploreWithClient(MissionSubtypeExplore),
    ProspectWithClient,
    GuideClient,
    FindItem,
    DeliverItem,
    SearchForTarget,
    TakeItemFromOutlaw(MissionSubtypeTakeItem),
    ArrestOutlaw(MissionSubtypeOutlaw),
    ChallengeRequest(MissionSubtypeChallenge),
    TreasureMemo,
}

impl MissionType {
    /// Group for this mission type.
    pub fn group(&self) -> MissionTypeGroup {
        match self {
            MissionType::RescueClient => MissionTypeGroup::RescueClient,
            MissionType::RescueTarget => MissionTypeGroup::RescueTarget,
            MissionType::EscortToTarget => MissionTypeGroup::EscortToTarget,
            MissionType::ExploreWithClient(_) => MissionTypeGroup::ExploreWithClient,
            MissionType::ProspectWithClient => MissionTypeGroup::ProspectWithClient,
            MissionType::GuideClient => MissionTypeGroup::GuideClient,
            MissionType::FindItem => MissionTypeGroup::FindItem,
            MissionType::DeliverItem => MissionTypeGroup::DeliverItem,
            MissionType::SearchForTarget => MissionTypeGroup::SearchForTarget,
            MissionType::TakeItemFromOutlaw(_) => MissionTypeGroup::TakeItemFromOutlaw,
            MissionType::ArrestOutlaw(_) => MissionTypeGroup::ArrestOutlaw,
            MissionType::ChallengeRequest(_) => MissionTypeGroup::ChallengeRequest,
            MissionType::TreasureMemo => MissionTypeGroup::TreasureMemo,
        }
    }

    /// Subtype for this mission type as a c-union, if any.
    pub fn c_subtype(&self) -> ffi::mission_subtype {
        let mut mission_subtype: ffi::mission_subtype;
        unsafe {
            let mut s = ::core::mem::MaybeUninit::uninit();
            ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
            mission_subtype = s.assume_init();
            match self {
                MissionType::ExploreWithClient(v) => {
                    *mission_subtype.explore = ffi::mission_subtype_explore_8 {
                        _bitfield_align_1: [],
                        _bitfield_1: ffi::mission_subtype_explore_8::new_bitfield_1(
                            (*v) as ffi::mission_subtype_explore::Type,
                        ),
                    };
                }
                MissionType::TakeItemFromOutlaw(v) => {
                    *mission_subtype.take_item = ffi::mission_subtype_take_item_8 {
                        _bitfield_align_1: [],
                        _bitfield_1: ffi::mission_subtype_take_item_8::new_bitfield_1(
                            (*v) as ffi::mission_subtype_take_item::Type,
                        ),
                    };
                }
                MissionType::ArrestOutlaw(v) => {
                    *mission_subtype.outlaw = ffi::mission_subtype_outlaw_8 {
                        _bitfield_align_1: [],
                        _bitfield_1: ffi::mission_subtype_outlaw_8::new_bitfield_1(
                            (*v) as ffi::mission_subtype_outlaw::Type,
                        ),
                    };
                }
                MissionType::ChallengeRequest(v) => {
                    *mission_subtype.challenge = ffi::mission_subtype_challenge_8 {
                        _bitfield_align_1: [],
                        _bitfield_1: ffi::mission_subtype_challenge_8::new_bitfield_1(
                            (*v) as ffi::mission_subtype_challenge::Type,
                        ),
                    };
                }
                _ => *mission_subtype.none = 0,
            }
        }
        mission_subtype
    }
}

#[repr(u32)]
#[derive(PartialEq, Eq, Clone, Copy)]
/// Mission subtype for [`MissionType::ExploreWithClient`].
pub enum MissionSubtypeExplore {
    Normal = ffi::mission_subtype_explore::MISSION_EXPLORE_NORMAL,
    SealedChamber = ffi::mission_subtype_explore::MISSION_EXPLORE_SEALED_CHAMBER,
    GoldenChamber = ffi::mission_subtype_explore::MISSION_EXPLORE_GOLDEN_CHAMBER,
}

impl TryFrom<ffi::mission_subtype_explore::Type> for MissionSubtypeExplore {
    type Error = ();

    fn try_from(value: ffi::mission_subtype_explore::Type) -> Result<Self, Self::Error> {
        match value {
            ffi::mission_subtype_explore::MISSION_EXPLORE_NORMAL => {
                Ok(MissionSubtypeExplore::Normal)
            }
            ffi::mission_subtype_explore::MISSION_EXPLORE_SEALED_CHAMBER => {
                Ok(MissionSubtypeExplore::SealedChamber)
            }
            ffi::mission_subtype_explore::MISSION_EXPLORE_GOLDEN_CHAMBER => {
                Ok(MissionSubtypeExplore::GoldenChamber)
            }
            _ => Err(()),
        }
    }
}

impl TryFrom<ffi::mission_subtype> for MissionSubtypeExplore {
    type Error = ();

    fn try_from(value: ffi::mission_subtype) -> Result<Self, Self::Error> {
        // SAFETY: We just copy the value and we check if it's a valid enum value.
        Self::try_from(unsafe { value.explore.val() })
    }
}

#[repr(u32)]
#[derive(PartialEq, Eq, Clone, Copy)]
/// Mission subtype for [`MissionType::TakeItemFromOutlaw`].
pub enum MissionSubtypeTakeItem {
    NormalOutlaw = ffi::mission_subtype_take_item::MISSION_TAKE_ITEM_NORMAL_OUTLAW,
    HiddenOutlaw = ffi::mission_subtype_take_item::MISSION_TAKE_ITEM_HIDDEN_OUTLAW,
    FleeingOutlaw = ffi::mission_subtype_take_item::MISSION_TAKE_ITEM_FLEEING_OUTLAW,
}

impl TryFrom<ffi::mission_subtype_take_item::Type> for MissionSubtypeTakeItem {
    type Error = ();

    fn try_from(value: ffi::mission_subtype_take_item::Type) -> Result<Self, Self::Error> {
        match value {
            ffi::mission_subtype_take_item::MISSION_TAKE_ITEM_NORMAL_OUTLAW => {
                Ok(MissionSubtypeTakeItem::NormalOutlaw)
            }
            ffi::mission_subtype_take_item::MISSION_TAKE_ITEM_HIDDEN_OUTLAW => {
                Ok(MissionSubtypeTakeItem::HiddenOutlaw)
            }
            ffi::mission_subtype_take_item::MISSION_TAKE_ITEM_FLEEING_OUTLAW => {
                Ok(MissionSubtypeTakeItem::FleeingOutlaw)
            }
            _ => Err(()),
        }
    }
}

impl TryFrom<ffi::mission_subtype> for MissionSubtypeTakeItem {
    type Error = ();

    fn try_from(value: ffi::mission_subtype) -> Result<Self, Self::Error> {
        // SAFETY: We just copy the value and we check if it's a valid enum value.
        Self::try_from(unsafe { value.take_item.val() })
    }
}

#[repr(u32)]
#[derive(PartialEq, Eq, Clone, Copy)]
/// Mission subtype for [`MissionType::ArrestOutlaw`].
pub enum MissionSubtypeOutlaw {
    Normal0 = ffi::mission_subtype_outlaw::MISSION_OUTLAW_NORMAL_0,
    Normal1 = ffi::mission_subtype_outlaw::MISSION_OUTLAW_NORMAL_1,
    Normal2 = ffi::mission_subtype_outlaw::MISSION_OUTLAW_NORMAL_2,
    Normal3 = ffi::mission_subtype_outlaw::MISSION_OUTLAW_NORMAL_3,
    Escort = ffi::mission_subtype_outlaw::MISSION_OUTLAW_ESCORT,
    Fleeing = ffi::mission_subtype_outlaw::MISSION_OUTLAW_FLEEING,
    Hideout = ffi::mission_subtype_outlaw::MISSION_OUTLAW_HIDEOUT,
    MonsterHouse = ffi::mission_subtype_outlaw::MISSION_OUTLAW_MONSTER_HOUSE,
}

impl TryFrom<ffi::mission_subtype_take_item::Type> for MissionSubtypeOutlaw {
    type Error = ();

    fn try_from(value: ffi::mission_subtype_outlaw::Type) -> Result<Self, Self::Error> {
        match value {
            ffi::mission_subtype_outlaw::MISSION_OUTLAW_NORMAL_0 => {
                Ok(MissionSubtypeOutlaw::Normal0)
            }
            ffi::mission_subtype_outlaw::MISSION_OUTLAW_NORMAL_1 => {
                Ok(MissionSubtypeOutlaw::Normal1)
            }
            ffi::mission_subtype_outlaw::MISSION_OUTLAW_NORMAL_2 => {
                Ok(MissionSubtypeOutlaw::Normal2)
            }
            ffi::mission_subtype_outlaw::MISSION_OUTLAW_NORMAL_3 => {
                Ok(MissionSubtypeOutlaw::Normal3)
            }
            ffi::mission_subtype_outlaw::MISSION_OUTLAW_ESCORT => Ok(MissionSubtypeOutlaw::Escort),
            ffi::mission_subtype_outlaw::MISSION_OUTLAW_FLEEING => {
                Ok(MissionSubtypeOutlaw::Fleeing)
            }
            ffi::mission_subtype_outlaw::MISSION_OUTLAW_HIDEOUT => {
                Ok(MissionSubtypeOutlaw::Hideout)
            }
            ffi::mission_subtype_outlaw::MISSION_OUTLAW_MONSTER_HOUSE => {
                Ok(MissionSubtypeOutlaw::MonsterHouse)
            }
            _ => Err(()),
        }
    }
}

impl TryFrom<ffi::mission_subtype> for MissionSubtypeOutlaw {
    type Error = ();

    fn try_from(value: ffi::mission_subtype) -> Result<Self, Self::Error> {
        // SAFETY: We just copy the value and we check if it's a valid enum value.
        Self::try_from(unsafe { value.outlaw.val() })
    }
}

#[repr(u32)]
#[derive(PartialEq, Eq, Clone, Copy)]
/// Mission subtype for [`MissionType::ChallengeRequest`].
pub enum MissionSubtypeChallenge {
    Normal = ffi::mission_subtype_challenge::MISSION_CHALLENGE_NORMAL,
    Mewtwo = ffi::mission_subtype_challenge::MISSION_CHALLENGE_MEWTWO,
    Entei = ffi::mission_subtype_challenge::MISSION_CHALLENGE_ENTEI,
    Raikou = ffi::mission_subtype_challenge::MISSION_CHALLENGE_RAIKOU,
    Suicune = ffi::mission_subtype_challenge::MISSION_CHALLENGE_SUICUNE,
    Jirachi = ffi::mission_subtype_challenge::MISSION_CHALLENGE_JIRACHI,
}

impl TryFrom<ffi::mission_subtype_take_item::Type> for MissionSubtypeChallenge {
    type Error = ();

    fn try_from(value: ffi::mission_subtype_challenge::Type) -> Result<Self, Self::Error> {
        match value {
            ffi::mission_subtype_challenge::MISSION_CHALLENGE_NORMAL => {
                Ok(MissionSubtypeChallenge::Normal)
            }
            ffi::mission_subtype_challenge::MISSION_CHALLENGE_MEWTWO => {
                Ok(MissionSubtypeChallenge::Mewtwo)
            }
            ffi::mission_subtype_challenge::MISSION_CHALLENGE_ENTEI => {
                Ok(MissionSubtypeChallenge::Entei)
            }
            ffi::mission_subtype_challenge::MISSION_CHALLENGE_RAIKOU => {
                Ok(MissionSubtypeChallenge::Raikou)
            }
            ffi::mission_subtype_challenge::MISSION_CHALLENGE_SUICUNE => {
                Ok(MissionSubtypeChallenge::Suicune)
            }
            ffi::mission_subtype_challenge::MISSION_CHALLENGE_JIRACHI => {
                Ok(MissionSubtypeChallenge::Jirachi)
            }
            _ => Err(()),
        }
    }
}

impl TryFrom<ffi::mission_subtype> for MissionSubtypeChallenge {
    type Error = ();

    fn try_from(value: ffi::mission_subtype) -> Result<Self, Self::Error> {
        // SAFETY: We just copy the value and we check if it's a valid enum value.
        Self::try_from(unsafe { value.challenge.val() })
    }
}

#[repr(i32)]
#[derive(PartialEq, Eq, Clone, Copy)]
/// List of reasons why you can get forcefully kicked out of a dungeon.
pub enum ForcedLossReason {
    /// You don't have to get kicked out of the dungeon.
    None = 0,
    /// Your partner fainted (before postgame).
    PartnerFainted = 1,
    /// Your client fainted.
    ClientFainted = 2,
    /// The client you had to escort fainted.
    EscortFainted = 3,
    /// "Your client \[name:0\] couldn't join you. Let's return to Treasure Town."
    ClientCantJoin = 4,
}

impl TryFrom<ffi::forced_loss_reason::Type> for ForcedLossReason {
    type Error = ();

    fn try_from(value: ffi::forced_loss_reason::Type) -> Result<Self, Self::Error> {
        match value {
            ffi::forced_loss_reason::FORCED_LOSS_NONE => Ok(ForcedLossReason::None),
            ffi::forced_loss_reason::FORCED_LOSS_PARTNER_FAINTED => {
                Ok(ForcedLossReason::PartnerFainted)
            }
            ffi::forced_loss_reason::FORCED_LOSS_CLIENT_FAINTED => {
                Ok(ForcedLossReason::ClientFainted)
            }
            ffi::forced_loss_reason::FORCED_LOSS_ESCORT_FAINTED => {
                Ok(ForcedLossReason::EscortFainted)
            }
            ffi::forced_loss_reason::FORCED_LOSS_CLIENT_CANT_JOIN => {
                Ok(ForcedLossReason::ClientCantJoin)
            }
            _ => Err(()),
        }
    }
}

#[repr(u32)]
#[derive(PartialEq, Eq, Clone, Copy)]
/// Type of hidden stairs.
pub enum HiddenStairsType {
    /// No hidden stairs.
    None = ffi::hidden_stairs_type::HIDDEN_STAIRS_NONE,
    /// Stairs lead to the secret bazar.
    SecretBazar = ffi::hidden_stairs_type::HIDDEN_STAIRS_SECRET_BAZAAR,
    /// Stairs lead to the secret room.
    SecretRoom = ffi::hidden_stairs_type::HIDDEN_STAIRS_SECRET_ROOM,
    /// Stairs lead to a random location.
    Random = ffi::hidden_stairs_type::HIDDEN_STAIRS_RANDOM_SECRET_BAZAAR_OR_SECRET_ROOM,
}

impl TryFrom<ffi::hidden_stairs_type::Type> for HiddenStairsType {
    type Error = ();

    fn try_from(value: Type) -> Result<Self, Self::Error> {
        match value {
            ffi::hidden_stairs_type::HIDDEN_STAIRS_NONE => Ok(HiddenStairsType::None),
            ffi::hidden_stairs_type::HIDDEN_STAIRS_SECRET_BAZAAR => {
                Ok(HiddenStairsType::SecretBazar)
            }
            ffi::hidden_stairs_type::HIDDEN_STAIRS_SECRET_ROOM => Ok(HiddenStairsType::SecretRoom),
            ffi::hidden_stairs_type::HIDDEN_STAIRS_RANDOM_SECRET_BAZAAR_OR_SECRET_ROOM => {
                Ok(HiddenStairsType::Random)
            }
            _ => Err(()),
        }
    }
}