summaryrefslogtreecommitdiff
path: root/src/fldeff_softboiled.c
blob: 4a96ef872201b3c9ecc15afb35dcf3b851c9218c (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
#include "global.h"
#include "fldeff_softboiled.h"
#include "menu.h"
#include "party_menu.h"
#include "pokemon.h"
#include "pokemon_menu.h"
#include "constants/songs.h"
#include "sound.h"
#include "sprite.h"
#include "strings.h"
#include "task.h"
#include "ewram.h"

#if ENGLISH
#define WINDOW_LEFT 3
#define WINDOW_RIGHT 26
#elif GERMAN
#define WINDOW_LEFT 0
#define WINDOW_RIGHT 29
#endif

// extern
extern u8 gPartyMenuMessage_IsPrinting;
extern u8 gLastFieldPokeMenuOpened;
extern u8 gUnknown_0202E8F4;

// Static
static void sub_8133D50(u8 taskId);
static void Task_ChooseNewMonForSoftboiled(u8 taskId);
static void CantUseSoftboiled(u8 taskId);
static void sub_8133EF8(u8 taskId);

bool8 SetUpFieldMove_SoftBoiled(void) {
    u16 maxHp;
    u16 hp;
    u16 minHp;

    maxHp = GetMonData(&gPlayerParty[gLastFieldPokeMenuOpened], MON_DATA_MAX_HP);
    hp = GetMonData(&gPlayerParty[gLastFieldPokeMenuOpened], MON_DATA_HP);

    minHp = (maxHp / 5);
    if (hp >= minHp)
    {
        return TRUE;
    }

    return FALSE;
}

void sub_8133D28(u8 taskid) {
    ePartyMenu.unkC = sub_8133D50;
    ePartyMenu2.pmUnk272 = 3;
    DoPokemonMenu_Switch(taskid);
}

static void sub_8133D50(u8 taskId) {
    u8 userPartyId, recipientPartyId;
    u16 hp;
    struct Pokemon *pokemon;
    //struct Task *task;

    struct Sprite *sprites = gSprites;

    userPartyId = sprites[ePartyMenu.slotId].data[0];
    recipientPartyId = sprites[ePartyMenu.slotId2].data[0];

    if (userPartyId > 5 || recipientPartyId > 5)
    {
        sub_806CD44(taskId);
        return;
    }

    gPartyMenu.pokemon = &gPlayerParty[sprites[ePartyMenu.slotId2].data[0]];
    hp = GetMonData(gPartyMenu.pokemon, MON_DATA_HP);

    if (hp == 0 || userPartyId == recipientPartyId || GetMonData(gPartyMenu.pokemon, MON_DATA_MAX_HP) == hp)
    {
        CantUseSoftboiled(taskId);
        return;
    }

    PlaySE(SE_USE_ITEM);

    gPartyMenu.primarySelectedMonIndex = gSprites[ePartyMenu.slotId].data[0];

    pokemon = &gPlayerParty[gPartyMenu.primarySelectedMonIndex];
    gPartyMenu.pokemon = pokemon;
    gPartyMenu.secondarySelectedIndex = 0;
    gPartyMenu.unkC = -0x8000;
    gPartyMenu.unk10 = sub_8133EF8;


    gTasks[taskId].data[10] = GetMonData(gPartyMenu.pokemon, MON_DATA_MAX_HP);
    gTasks[taskId].data[11] = GetMonData(gPartyMenu.pokemon, MON_DATA_HP);
    gTasks[taskId].data[12] = gTasks[taskId].data[10] / 5;

    PartyMenuEraseMsgBoxAndFrame();
    gTasks[taskId].func = sub_806FA18;
    ePartyMenu2.pmUnk282 = gTasks[taskId].data[11];
}

static void Task_ChooseNewMonForSoftboiled(u8 taskId) {
    if (gPartyMenuMessage_IsPrinting)
    {
        return;
    }

    Menu_EraseWindowRect(WINDOW_LEFT, 14, WINDOW_RIGHT, 19);
    PrintPartyMenuPromptText(3, 0);
    gTasks[taskId].func = HandlePartyMenuSwitchPokemonInput;
}

static void CantUseSoftboiled(u8 taskId) {
    gUnknown_0202E8F4 = 0;
    PartyMenuEraseMsgBoxAndFrame();
    DisplayPartyMenuMessage(gOtherText_CantUseOnPoke, 1);
    gTasks[taskId].func = Task_ChooseNewMonForSoftboiled;
}

static void sub_8133EF8(u8 taskId)
{
    sub_806CCE4();
    ePartyMenu2.unk261 = 2;
    DestroySprite(&gSprites[ePartyMenu.slotId]);
    Menu_EraseWindowRect(WINDOW_LEFT, 14, WINDOW_RIGHT, 19);
    PrintPartyMenuPromptText(0, 0);
    SwitchTaskToFollowupFunc(ePartyMenu.unk0);
}