summaryrefslogtreecommitdiff
path: root/Update-Sitrus-Berry's-effect-to-Gen-4-standard.md
blob: f39f8b79fbee987bff15a8a69d9292c2b8c4bf34 (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
In Generation III the Sitrus Berry healed only 30 HP, an effect inherited from the Gold Berry in Generation II. In Generation IV it was improved to heal one quarter of the user's max HP.

## Contents

1. [Define a constant](#1-define-a-constant)
2. [Use the constant](#2-use-the-constant)
3. [Teach the game what to do with it](#3-teach-the-game-what-to-do-with-it)
4. [Edit the held item effect](#4-edit-the-held-item-effect)
5. [Add hold effect define and usage for non-battle engine users](#5-add-hold-effect-define-and-usage)

## 1. Define a new constant

Edit `include/constants/item_effects.h`:

```diff
 // Special HP recovery amounts for ITEM4_HEAL_HP
 #define ITEM6_HEAL_FULL    ((u8) -1)
 #define ITEM6_HEAL_HALF    ((u8) -2)
-#define ITEM6_HEAL_LVL_UP  ((u8) -3)
+#define ITEM6_HEAL_QUARTER ((u8) -3)
+#define ITEM6_HEAL_LVL_UP  ((u8) -4)
```

## 2. Use the constant

Edit `src/data/pokemon/item_effects.h`:

```diff
 const u8 gItemEffect_SitrusBerry[7] = {
     [4] = ITEM4_HEAL_HP,
-    [6] = 30,
+    [6] = ITEM6_HEAL_QUARTER,
 };
```

## 3. Teach the game what to do with it

Edit `src\pokemon.c` (inside the intimidatingly large function `PokemonUseItemEffects`):

```diff
 // Get amount of HP to restore
 dataUnsigned = itemEffect[var_3C++];
 switch (dataUnsigned)
 {
 case ITEM6_HEAL_FULL:
     dataUnsigned = GetMonData(mon, MON_DATA_MAX_HP, NULL) - GetMonData(mon, MON_DATA_HP, NULL);
     break;
 case ITEM6_HEAL_HALF:
     dataUnsigned = GetMonData(mon, MON_DATA_MAX_HP, NULL) / 2;
     if (dataUnsigned == 0)
         dataUnsigned = 1;
     break;
+case ITEM6_HEAL_QUARTER:
+    dataUnsigned = GetMonData(mon, MON_DATA_MAX_HP, NULL) / 4;
+    if (dataUnsigned == 0)
+        dataUnsigned = 1;
+    break;
 case ITEM6_HEAL_LVL_UP:
     dataUnsigned = gBattleScripting.levelUpHP;
     break;
 }
```

## 4. Edit the held item effect

So far, we've only edited the outside of battle effects of the Sitrus Berry. Go to `src\data\items.h` and look for the Sitrus Berry. There are two important lines here:
```diff
        .holdEffect = HOLD_EFFECT_RESTORE_HP,
        .holdEffectParam = 30,
```
We'll want to change these to:
```diff
        .holdEffect = HOLD_EFFECT_RESTORE_PCT_HP,
        .holdEffectParam = 25, //restores 25% of the max HP
```

If you're using the battle engine by Dizzyegg/rhh, you're all done! Otherwise, you'll need to do step 5.

## 5. Add hold effect define and usage

Go to `include\constants\hold_effects.h` and define a new hold effect:
```diff
        #define HOLD_EFFECT_RESTORE_PCT_HP 67
```

Now go to `src/battle_util.c` and look for this section in the function `ItemBattleEffects`
```diff
            case HOLD_EFFECT_RESTORE_HP:
                if (gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / 2 && !moveTurn)
                {
                    gBattleMoveDamage = battlerHoldEffectParam;
                    if (gBattleMons[battlerId].hp + battlerHoldEffectParam > gBattleMons[battlerId].maxHP)
                        gBattleMoveDamage = gBattleMons[battlerId].maxHP - gBattleMons[battlerId].hp;
                    gBattleMoveDamage *= -1;
                    BattleScriptExecute(BattleScript_ItemHealHP_RemoveItem);
                    effect = 4;
                }
                break;
```
You're going to want to add another case directly below this case. Copy paste this in:
```diff
            case HOLD_EFFECT_RESTORE_PCT_HP:
                if (gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / 2 && !moveTurn)
                {
                    gBattleMoveDamage = (gBattleMons[battlerId].maxHP * battlerHoldEffectParam) / 100;
                    if (gBattleMons[battlerId].hp + battlerHoldEffectParam > gBattleMons[battlerId].maxHP)
                        gBattleMoveDamage = gBattleMons[battlerId].maxHP - gBattleMons[battlerId].hp;
                    gBattleMoveDamage *= -1;
                    BattleScriptExecute(BattleScript_ItemHealHP_RemoveItem);
                    effect = ITEM_HP_CHANGE;
                }
                break;
```

That's all!