summaryrefslogtreecommitdiff
path: root/arm9/src/scrcmd_party.c
blob: 48d558c9f6793ff899865ff312bd41d877db0528 (plain)
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
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
#include "scrcmd.h"
#include "constants/moves.h"
#include "itemtool.h"
#include "map_header.h"
#include "module_05.h"
#include "party.h"
#include "save_block_2.h"
#include "script_pokemon_util.h"
#include "unk_02015CC0.h"
#include "unk_02022504.h"
#include "unk_0204639C.h"
#include "unk_0207FC5C.h"

extern u16 FUN_02054DEC(struct SaveBlock2* sav2);

THUMB_FUNC BOOL ScrCmd_GiveMon(struct ScriptContext* ctx)
{
    u32 mapSec = MapHeader_GetMapSec(*(ctx->unk80->mapId));
    struct UnkSavStruct80 *savePtr = ctx->unk80;
    u16 species = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    u16 level = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    u16 item = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    u16 * varPtr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    struct PlayerParty * party = SavArray_PlayerParty_get(savePtr->saveBlock2);
    *varPtr = (u16)GiveMon(11, savePtr->saveBlock2, species, (u8)level, item, mapSec, 12);
    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_GetPartyMonSpecies(struct ScriptContext* ctx)
{
    u32 species;
    u16* ret_ptr;

    struct UnkSavStruct80* sav_ptr = ctx->unk80;
    u16* mon_slot = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2);
    struct Pokemon* party_mon = GetPartyMonByIndex(party, *mon_slot);

    BOOL party_mon_is_egg = (BOOL)GetMonData(party_mon, MON_DATA_IS_EGG, NULL);
    if (party_mon_is_egg == FALSE)
    {
        species = GetMonData(party_mon, MON_DATA_SPECIES, NULL);
    }
    else
    {
        species = SPECIES_NONE;
    }

    *ret_ptr = (u16)species;
    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_CheckPartyMonOTID(struct ScriptContext* ctx)
{
    struct UnkSavStruct80* sav_ptr = ctx->unk80;
    struct SaveBlock2* sav2 = ScriptEnvironment_GetSav2Ptr(sav_ptr);
    struct PlayerData* player = Sav2_PlayerData_GetProfileAddr(sav2);

    u16* mon_slot = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));

    struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2);
    struct Pokemon* party_mon = GetPartyMonByIndex(party, *mon_slot);

    u16 party_mon_otid = (u16)GetMonData(party_mon, MON_DATA_OTID, NULL);
    u16 player_otid = (u16)PlayerProfile_GetTrainerID(player);
    if (party_mon_otid == player_otid)
    {
        *ret_ptr = 0;
    }
    else
    {
        *ret_ptr = 1;
    }

    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_GiveEgg(struct ScriptContext* ctx)
{
    struct UnkSavStruct80* sav_ptr = ctx->unk80;
    struct PlayerData* player = Sav2_PlayerData_GetProfileAddr(sav_ptr->saveBlock2);
    u16 species = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    u16 unk = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2);
    u8 party_count = (u8)GetPartyCount(party);

    if (party_count < PARTY_SIZE)
    {
        struct Pokemon* egg = AllocMonZeroed(11);
        ZeroMonData(egg);

        s32 met_loc = FUN_02015CF8(1, unk);
        MOD05_SetEggStats(egg, species, 1, player, 3, met_loc);

        AddMonToParty(party, egg);
        FreeToHeap(egg);
    }

    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_SetPartyMonMove(struct ScriptContext* ctx)
{
    u16 mon_slot = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    u16 move_slot = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    u16 move = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    struct PlayerParty* party = SavArray_PlayerParty_get(ctx->unk80->saveBlock2);

    PartyMonSetMoveInSlot(party, mon_slot, move_slot, move);

    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_PartyMonHasMove(struct ScriptContext* ctx)
{
    struct UnkSavStruct80* sav_ptr = ctx->unk80;
    u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    u16 required_move = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    u16 mon_slot = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2);
    struct Pokemon* party_mon = GetPartyMonByIndex(party, mon_slot);

    *ret_ptr = 0;

    BOOL party_mon_is_egg = (BOOL)GetMonData(party_mon, MON_DATA_IS_EGG, NULL);
    if (party_mon_is_egg)
    {
        return FALSE;
    }

    if (required_move == GetMonData(party_mon, MON_DATA_MOVE1, NULL) ||
        required_move == GetMonData(party_mon, MON_DATA_MOVE2, NULL) ||
        required_move == GetMonData(party_mon, MON_DATA_MOVE3, NULL) ||
        required_move == GetMonData(party_mon, MON_DATA_MOVE4, NULL))
    {
        *ret_ptr = 1;
    }

    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_FindPartyMonWithMove(struct ScriptContext* ctx)
{
    struct UnkSavStruct80* sav_ptr = ctx->unk80;
    u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    u16 required_move = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    u8 party_count = (u8)GetPartyCount(SavArray_PlayerParty_get(sav_ptr->saveBlock2));

    u8 i;
    for (i = 0, *ret_ptr = PARTY_SIZE; i < party_count; i++)
    {
        struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2);
        struct Pokemon* party_mon = GetPartyMonByIndex(party, i);

        BOOL party_mon_is_egg = (BOOL)GetMonData(party_mon, MON_DATA_IS_EGG, NULL);
        if (party_mon_is_egg == FALSE)
        {
            if (required_move == GetMonData(party_mon, MON_DATA_MOVE1, NULL) ||
                required_move == GetMonData(party_mon, MON_DATA_MOVE2, NULL) ||
                required_move == GetMonData(party_mon, MON_DATA_MOVE3, NULL) ||
                required_move == GetMonData(party_mon, MON_DATA_MOVE4, NULL))
            {
                *ret_ptr = i;
                break;
            }
        }
    }

    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_SurvivePsn(struct ScriptContext* ctx)
{
    u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    u16 mon_slot = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    struct PlayerParty* party = SavArray_PlayerParty_get(ctx->unk80->saveBlock2);
    struct Pokemon* party_mon = GetPartyMonByIndex(party, mon_slot);

    *ret_ptr = (u16)SurvivePoisoning(party_mon);
    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_CountPartyMonsAtOrBelowLevel(struct ScriptContext* ctx)
{
    u8 party_count;
    u8 i;

    struct UnkSavStruct80* sav_ptr = ctx->unk80;
    u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    u16 highest_level = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    party_count = (u8)GetPartyCount(SavArray_PlayerParty_get(sav_ptr->saveBlock2));

    u8 mons;
    for (i = 0, mons = 0, *ret_ptr = 0; i < party_count; i++)
    {
        struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2);
        struct Pokemon* party_mon = GetPartyMonByIndex(party, i);

        BOOL party_mon_is_egg = (BOOL)GetMonData(party_mon, MON_DATA_IS_EGG, NULL);
        if (party_mon_is_egg == FALSE)
        {
            u32 party_mon_level = GetMonData(party_mon, MON_DATA_LEVEL, NULL);
            if (party_mon_level <= highest_level)
            {
                mons++;
            }
        }
    }

    *ret_ptr = mons;
    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_GetPartyMonLevel(struct ScriptContext* ctx)
{
    struct UnkSavStruct80* sav_ptr = ctx->unk80;
    u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    u16 mon_slot = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2);
    struct Pokemon* party_mon = GetPartyMonByIndex(party, mon_slot);

    *ret_ptr = 0;

    BOOL party_mon_is_egg = (BOOL)GetMonData(party_mon, MON_DATA_IS_EGG, NULL);
    if (party_mon_is_egg == FALSE)
    {
        *ret_ptr = (u16)GetMonData(party_mon, MON_DATA_LEVEL, NULL);
    }

    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_GetPartyMonNature(struct ScriptContext* ctx)
{
    struct UnkSavStruct80* sav_ptr = ctx->unk80;
    u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    u16 mon_slot = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    u8 party_count = (u8)GetPartyCount(SavArray_PlayerParty_get(sav_ptr->saveBlock2));

    if (mon_slot >= party_count)
    {
        *ret_ptr = 0;
        return FALSE;
    }

    struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2);
    struct Pokemon* party_mon = GetPartyMonByIndex(party, mon_slot);

    BOOL party_mon_is_egg = (BOOL)GetMonData(party_mon, MON_DATA_IS_EGG, NULL);
    if (party_mon_is_egg)
    {
        *ret_ptr = 0;
        return FALSE;
    }

    *ret_ptr = GetMonNature(party_mon);
    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_FindPartyMonWithNature(struct ScriptContext* ctx)
{
    struct UnkSavStruct80* sav_ptr = ctx->unk80;
    u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    u16 required_nature = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    u8 party_count = (u8)GetPartyCount(SavArray_PlayerParty_get(sav_ptr->saveBlock2));

    u8 i;
    for (i = 0, *ret_ptr = 0xFF; i < party_count; i++)
    {
        struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2);
        struct Pokemon* party_mon = GetPartyMonByIndex(party, i);

        BOOL party_mon_is_egg = (BOOL)GetMonData(party_mon, MON_DATA_IS_EGG, NULL);
        if (party_mon_is_egg == FALSE)
        {
            u8 party_mon_nature = GetMonNature(party_mon);
            if (required_nature == party_mon_nature)
            {
                *ret_ptr = i;
                break;
            }
        }
    }

    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_GetPartyMonFriendship(struct ScriptContext* ctx)
{
    struct UnkSavStruct80* sav_ptr = ctx->unk80;
    u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    u16 mon_slot = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2);
    struct Pokemon* party_mon = GetPartyMonByIndex(party, mon_slot);

    *ret_ptr = (u16)GetMonData(party_mon, MON_DATA_FRIENDSHIP, NULL);
    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_AddPartyMonFriendship(struct ScriptContext* ctx)
{
    struct UnkSavStruct80* sav_ptr = ctx->unk80;
    u16 friendship_to_add = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    u16 mon_slot = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    u16 map_sec = MapHeader_GetMapSec(*ctx->unk80->mapId);
    struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2);
    struct Pokemon* party_mon = GetPartyMonByIndex(party, mon_slot);

    u16 friendship = (u16)GetMonData(party_mon, MON_DATA_FRIENDSHIP, NULL);

    if (friendship_to_add != 0)
    {
        u16 party_mon_held_item = (u16)GetMonData(party_mon, MON_DATA_HELD_ITEM, NULL);
        u32 held_item_hold_effect = GetItemAttr(party_mon_held_item, ITEMATTR_HOLD_EFFECT, 11);
        if (held_item_hold_effect == HOLD_EFFECT_FRIENDSHIP_UP)
        {
            friendship_to_add = (u16)((friendship_to_add * 150) / 100);
        }

        u32 party_mon_pokeball = GetMonData(party_mon, MON_DATA_POKEBALL, NULL);
        if (party_mon_pokeball == ITEM_LUXURY_BALL)
        {
            friendship_to_add++;
        }

        u32 party_mon_egg_met_location = GetMonData(party_mon, MON_DATA_EGG_MET_LOCATION, NULL);
        if (map_sec == party_mon_egg_met_location)
        {
            friendship_to_add++;
        }
    }

    friendship += friendship_to_add;
    if (friendship > 0xFF)
    {
        friendship = 0xFF;
    }

    SetMonData(party_mon, MON_DATA_FRIENDSHIP, &friendship);

    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_SubtractPartyMonFriendship(struct ScriptContext* ctx)
{
    struct UnkSavStruct80* sav_ptr = ctx->unk80;
    u16 friendship_to_deplete = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    u16 mon_slot = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2);
    struct Pokemon* party_mon = GetPartyMonByIndex(party, mon_slot);

    u16 friendship = (u16)GetMonData(party_mon, MON_DATA_FRIENDSHIP, NULL);
    if (friendship_to_deplete > friendship)
    {
        friendship = 0;
    }
    else
    {
        friendship -= friendship_to_deplete;
    }

    SetMonData(party_mon, MON_DATA_FRIENDSHIP, &friendship);

    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_GetPartyMonContestCondition(struct ScriptContext* ctx)
{
    u16 mon_slot = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    u16 contest_condition_id = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    struct PlayerParty* party = SavArray_PlayerParty_get(ctx->unk80->saveBlock2);
    struct Pokemon* party_mon = GetPartyMonByIndex(party, mon_slot);

    *ret_ptr = (u16)GetMonData(party_mon, MON_DATA_COOL + contest_condition_id, NULL);
    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_GetLeadingPartyMonSlot(struct ScriptContext* ctx)
{
    u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));

    *ret_ptr = FUN_02054DEC(ctx->unk80->saveBlock2);
    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_GetPartyMonTypes(struct ScriptContext* ctx)
{
    struct UnkSavStruct80* sav_ptr = ctx->unk80;
    u16* type1 = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    u16* type2 = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    u16 mon_slot = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2);
    struct Pokemon* party_mon = GetPartyMonByIndex(party, mon_slot);

    *type1 = (u16)GetMonData(party_mon, MON_DATA_TYPE_1, NULL);
    *type2 = (u16)GetMonData(party_mon, MON_DATA_TYPE_2, NULL);
    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_CountPartyMons(struct ScriptContext* ctx)
{
    struct UnkSavStruct80* sav_ptr = ctx->unk80;
    u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2);

    *ret_ptr = (u16)GetPartyCount(party);
    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_CountPartyMons_OmitEggs(struct ScriptContext* ctx)
{
    u32 non_egg_mons;
    s32 i;

    struct UnkSavStruct80* sav_ptr = ctx->unk80;
    u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    s32 party_count = GetPartyCount(SavArray_PlayerParty_get(sav_ptr->saveBlock2));

    for (i = 0, non_egg_mons = 0; i < party_count; i++)
    {
        struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2);
        struct Pokemon* party_mon = GetPartyMonByIndex(party, i);

        BOOL party_mon_is_egg = (BOOL)GetMonData(party_mon, MON_DATA_IS_EGG, NULL);
        if (party_mon_is_egg == FALSE)
        {
            non_egg_mons++;
        }

    }

    *ret_ptr = (u16)non_egg_mons;
    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_CountAvailablePartyMons_IgnoreSlot(struct ScriptContext* ctx)
{
    u16 slot_to_ignore;
    s32 party_count;

    struct UnkSavStruct80* sav_ptr = ctx->unk80;
    u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    slot_to_ignore = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    party_count = GetPartyCount(SavArray_PlayerParty_get(sav_ptr->saveBlock2));

    u32 available_mons;
    s32 i;
    for (i = 0, available_mons = 0; i < party_count; i++)
    {
        if (i != slot_to_ignore)
        {
            struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2);
            struct Pokemon* party_mon = GetPartyMonByIndex(party, i);

            BOOL party_mon_is_egg = (BOOL)GetMonData(party_mon, MON_DATA_IS_EGG, NULL);
            if (party_mon_is_egg == FALSE)
            {
                u32 party_mon_hp = GetMonData(party_mon, MON_DATA_HP, NULL);
                if (party_mon_hp != 0)
                {
                    available_mons++;
                }
            }
        }
    }

    *ret_ptr = (u16)available_mons;
    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_CountAvailablePartyAndPCMons(struct ScriptContext* ctx)
{
    s32 party_count;
    struct PCStorage* pc;

    struct UnkSavStruct80* sav_ptr = ctx->unk80;
    u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    pc = GetStoragePCPointer(sav_ptr->saveBlock2);
    party_count = GetPartyCount(SavArray_PlayerParty_get(sav_ptr->saveBlock2));

    u32 mons;
    s32 i;
    for (i = 0, mons = 0; i < party_count; i++)
    {
        struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2);
        struct Pokemon* party_mon = GetPartyMonByIndex(party, i);

        BOOL party_mon_is_egg = (BOOL)GetMonData(party_mon, MON_DATA_IS_EGG, NULL);
        if (party_mon_is_egg == FALSE)
        {
            u32 party_mon_hp = GetMonData(party_mon, MON_DATA_HP, NULL);
            if (party_mon_hp != 0)
            {
                mons++;
            }
        }
    }

    *ret_ptr = (u16)(mons + PCStorage_CountMonsInAllBoxes(pc));
    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_GetPartyEggCount(struct ScriptContext* ctx)
{
    s32 party_count;
    u32 eggs_in_party;

    struct UnkSavStruct80* sav_ptr = ctx->unk80;
    u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    party_count = GetPartyCount(SavArray_PlayerParty_get(sav_ptr->saveBlock2));

    s32 i;
    for (i = 0, eggs_in_party = 0; i < party_count; i++)
    {
        struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2);
        struct Pokemon* party_mon = GetPartyMonByIndex(party, i);

        BOOL party_mon_is_egg = (BOOL)GetMonData(party_mon, MON_DATA_IS_EGG, NULL);
        if (party_mon_is_egg)
        {
            eggs_in_party++;
        }
    }

    *ret_ptr = (u16)eggs_in_party;
    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_CheckPartyForPokerus(struct ScriptContext* ctx)
{
    u16 party_count;
    u16 i;

    struct UnkSavStruct80* sav_ptr = ctx->unk80;
    u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    party_count = (u16)GetPartyCount(SavArray_PlayerParty_get(sav_ptr->saveBlock2));

    for (i = 0, *ret_ptr = 0; i < party_count; i++)
    {
        struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2);
        struct Pokemon* party_mon = GetPartyMonByIndex(party, i);

        BOOL party_mon_has_pokerus = (BOOL)GetMonData(party_mon, MON_DATA_POKERUS, NULL);
        if (party_mon_has_pokerus)
        {
            *ret_ptr = 1;
            break;
        }
    }

    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_GetPartyMonGender(struct ScriptContext* ctx)
{
    u16 mon_slot = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    struct PlayerParty* party = SavArray_PlayerParty_get(ctx->unk80->saveBlock2);
    struct Pokemon* party_mon = GetPartyMonByIndex(party, mon_slot);

    *ret_ptr = (u16)GetMonData(party_mon, MON_DATA_GENDER, NULL);
    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_CountPartyMonMoves(struct ScriptContext* ctx)
{
    struct Pokemon* party_mon;
    u8 moves;

    struct UnkSavStruct80* sav_ptr = ctx->unk80;
    u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    u16 mon_slot = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2);
    party_mon = GetPartyMonByIndex(party, mon_slot);

    BOOL party_mon_is_egg = (BOOL)GetMonData(party_mon, MON_DATA_IS_EGG, NULL);
    if (party_mon_is_egg)
    {
        *ret_ptr = 0;
        return FALSE;
    }

    moves = 0;

    u32 move1 = GetMonData(party_mon, MON_DATA_MOVE1, NULL);
    if (move1 != MOVE_NONE)
    {
        moves++;
    }

    u32 move2 = GetMonData(party_mon, MON_DATA_MOVE2, NULL);
    if (move2 != MOVE_NONE)
    {
        moves++;
    }

    u32 move3 = GetMonData(party_mon, MON_DATA_MOVE3, NULL);
    if (move3 != MOVE_NONE)
    {
        moves++;
    }

    u32 move4 = GetMonData(party_mon, MON_DATA_MOVE4, NULL);
    if (move4 != MOVE_NONE)
    {
        moves++;
    }

    *ret_ptr = moves;
    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_ForgetPartyMonMove(struct ScriptContext* ctx)
{
    struct UnkSavStruct80* sav_ptr = ctx->unk80;
    u16 mon_slot = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    u16 move_slot = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2);
    struct Pokemon* party_mon = GetPartyMonByIndex(party, mon_slot);

    FUN_020699A4(party_mon, move_slot);

    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_GetPartyMonMove(struct ScriptContext* ctx)
{
    struct UnkSavStruct80* sav_ptr = ctx->unk80;
    u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    u16 mon_slot = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    u16 move_slot = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2);
    struct Pokemon* party_mon = GetPartyMonByIndex(party, mon_slot);

    *ret_ptr = (u16)GetMonData(party_mon, MON_DATA_MOVE1 + move_slot, NULL);
    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_GetPartyMonHeldItem(struct ScriptContext* ctx)
{
    struct UnkSavStruct80* sav_ptr = ctx->unk80;
    u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    u16 mon_slot = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2);
    struct Pokemon* party_mon = GetPartyMonByIndex(party, mon_slot);

    *ret_ptr = (u16)GetMonData(party_mon, MON_DATA_HELD_ITEM, NULL);
    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_ResetPartyMonHeldItem(struct ScriptContext* ctx)
{
    struct UnkSavStruct80* sav_ptr = ctx->unk80;
    u16 mon_slot = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2);
    struct Pokemon* party_mon = GetPartyMonByIndex(party, mon_slot);

    u16 party_mon_held_item = ITEM_NONE;
    SetMonData(party_mon, MON_DATA_HELD_ITEM, &party_mon_held_item);

    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_CheckPartyForSpecies(struct ScriptContext* ctx)
{
    struct UnkSavStruct80* sav_ptr = ctx->unk80;
    u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    u16 species = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    u8 party_count = (u8)GetPartyCount(SavArray_PlayerParty_get(sav_ptr->saveBlock2));

    u8 i;
    for (i = 0, *ret_ptr = 0; i < party_count; i++)
    {
        struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2);
        struct Pokemon* party_mon = GetPartyMonByIndex(party, i);

        BOOL party_mon_is_egg = (BOOL)GetMonData(party_mon, MON_DATA_IS_EGG, NULL);
        if (party_mon_is_egg == FALSE)
        {
            u16 party_mon_species = (u16)GetMonData(party_mon, MON_DATA_SPECIES, NULL);
            if (species == party_mon_species)
            {
                *ret_ptr = 1;
                break;
            }
        }
    }

    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_CountPartyMonRibbons(struct ScriptContext* ctx)
{
    u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    u16 mon_slot = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    struct PlayerParty* party = SavArray_PlayerParty_get(ctx->unk80->saveBlock2);
    struct Pokemon* party_mon = GetPartyMonByIndex(party, mon_slot);

    u16 ribbon_idx;
    u16 ribbons;
    for (ribbon_idx = 0, ribbons = 0; ribbon_idx < 80; ribbon_idx++)
    {
        BOOL party_mon_has_ribbon = (BOOL)GetMonData(party_mon, FUN_0207FC5C((u8)ribbon_idx, 0), NULL);
        if (party_mon_has_ribbon)
        {
            ribbons++;
        }
    }

    *ret_ptr = ribbons;
    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_CountTotalPartyRibbons(struct ScriptContext* ctx)
{
    struct PlayerParty* party;
    u16 ribbon_idx;
    u16 ribbons;

    u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    u16 party_count = (u16)GetPartyCount(SavArray_PlayerParty_get(ctx->unk80->saveBlock2));
    party = SavArray_PlayerParty_get(ctx->unk80->saveBlock2);

    for (ribbon_idx = 0, ribbons = 0; ribbon_idx < 80; ribbon_idx++)
    {
        for (u16 i = 0; i < party_count; i++)
        {
            struct Pokemon* party_mon = GetPartyMonByIndex(party, i);

            BOOL party_mon_is_egg = (BOOL)GetMonData(party_mon, MON_DATA_IS_EGG, NULL);
            if (party_mon_is_egg)
            {
                // BUG: This `break` should be a `continue`, as any party mons after a detected
                //      egg would have their ribbons ignored.
                break;
            }

            BOOL party_mon_has_ribbon = (BOOL)GetMonData(party_mon, FUN_0207FC5C((u8)ribbon_idx, 0), NULL);
            if (party_mon_has_ribbon)
            {
                ribbons++;
                break;
            }
        }
    }

    *ret_ptr = ribbons;
    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_PartyMonHasRibbon(struct ScriptContext* ctx)
{
    u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    u16 mon_slot = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    u16 ribbon_idx = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    struct PlayerParty* party = SavArray_PlayerParty_get(ctx->unk80->saveBlock2);
    struct Pokemon* party_mon = GetPartyMonByIndex(party, mon_slot);

    *ret_ptr = (u16)GetMonData(party_mon, FUN_0207FC5C((u8)ribbon_idx, 0), NULL);
    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_GivePartyMonRibbon(struct ScriptContext* ctx)
{
    u16 mon_slot = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    u16 ribbon_idx = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
    u8 mon_has_ribbon = TRUE;
    struct PlayerParty* party = SavArray_PlayerParty_get(ctx->unk80->saveBlock2);
    struct Pokemon* party_mon = GetPartyMonByIndex(party, mon_slot);

    SetMonData(party_mon, (s32)FUN_0207FC5C((u8)ribbon_idx, 0), &mon_has_ribbon);

    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_CheckPartyForBadEgg(struct ScriptContext* ctx)
{
    u16 ribbon_idx;

    u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
    u16 party_count = (u16)GetPartyCount(SavArray_PlayerParty_get(ctx->unk80->saveBlock2));
    struct PlayerParty* party = SavArray_PlayerParty_get(ctx->unk80->saveBlock2);

    // BUG: Probably a copy-paste fail. Checks if your party has a Bad Egg in it,
    //      80 times.
    for (ribbon_idx = 0; ribbon_idx < 80; ribbon_idx++)
    {
        for (u16 i = 0; i < party_count; i++)
        {
            struct Pokemon* party_mon = GetPartyMonByIndex(party, i);
            BOOL party_mon_is_egg = (BOOL)GetMonData(party_mon, MON_DATA_IS_EGG, NULL);
            if (party_mon_is_egg)
            {
                BOOL party_mon_is_bad_egg = (BOOL)GetMonData(party_mon, MON_DATA_CHECKSUM_FAILED, NULL);
                if (party_mon_is_bad_egg)
                {
                    *ret_ptr = 1;
                    return FALSE;
                }
            }
        }
    }

    *ret_ptr = 0;
    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_Unk00A0(struct ScriptContext* ctx)
{
#pragma unused(ctx)
    return FALSE;
}