|
@@ -29,44 +29,45 @@
|
29
|
29
|
|
30
|
30
|
/* === INCLUDE === */
|
31
|
31
|
|
|
32
|
+#include <battle_common.h>
|
|
33
|
+#include <battle_custom_structs.h>
|
32
|
34
|
#include <battle_help.h>
|
33
|
35
|
#include <battle_locations.h>
|
34
|
|
-#include <battle_custom_structs.h>
|
35
|
36
|
#include <game_engine.h>
|
36
|
|
-#include <pkmn_types.h>
|
37
|
37
|
#include <pkmn_abilities.h>
|
|
38
|
+#include <pkmn_attributes.h>
|
38
|
39
|
#include <pkmn_item_effects.h>
|
39
|
40
|
#include <pkmn_items.h>
|
40
|
|
-#include <pkmn_attributes.h>
|
41
|
|
-#include <battle_common.h>
|
|
41
|
+#include <pkmn_types.h>
|
42
|
42
|
|
43
|
43
|
/* === STATICS === */
|
44
|
44
|
|
45
|
45
|
/* from kds emerald battle engine upgrade */
|
46
|
46
|
u8 type_effectiveness_table[TYPE_FAIRY - 0x4][TYPE_FAIRY - 0x4] = {
|
47
|
|
- {10, 10, 10, 10, 10, 05, 10, 00, 05, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10}, //normal
|
48
|
|
- {20, 10, 05, 05, 10, 20, 05, 00, 20, 10, 10, 10, 10, 10, 05, 20, 10, 20, 05}, //fight
|
49
|
|
- {10, 20, 10, 10, 10, 05, 20, 10, 05, 10, 10, 10, 20, 05, 10, 10, 10, 10, 10}, //flying
|
50
|
|
- {10, 10, 10, 05, 05, 05, 10, 05, 00, 10, 10, 10, 20, 10, 10, 10, 10, 10, 20}, //poison
|
51
|
|
- {10, 10, 00, 20, 10, 20, 05, 10, 20, 10, 20, 10, 05, 20, 10, 10, 10, 10, 10}, //ground
|
52
|
|
- {10, 05, 20, 10, 05, 10, 20, 10, 05, 10, 20, 10, 10, 10, 10, 20, 10, 10, 10}, //rock
|
53
|
|
- {10, 05, 05, 05, 10, 10, 10, 05, 05, 10, 05, 10, 20, 10, 20, 10, 10, 20, 05}, //bug
|
54
|
|
- {00, 10, 10, 10, 10, 10, 10, 20, 10, 10, 10, 10, 10, 10, 20, 10, 10, 05, 10}, //ghost
|
55
|
|
- {10, 10, 10, 10, 10, 20, 10, 10, 05, 10, 05, 05, 10, 05, 10, 20, 10, 10, 20}, //steel
|
56
|
|
- {10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10}, //egg
|
57
|
|
- {10, 10, 10, 10, 10, 05, 20, 10, 20, 10, 05, 05, 20, 10, 10, 20, 05, 10, 10}, //fire
|
58
|
|
- {10, 10, 10, 10, 20, 20, 10, 10, 10, 10, 20, 05, 05, 10, 10, 10, 05, 10, 10}, //water
|
59
|
|
- {10, 10, 05, 05, 20, 20, 05, 10, 05, 10, 05, 20, 05, 10, 10, 10, 05, 10, 10}, //grass
|
60
|
|
- {10, 10, 20, 10, 00, 10, 10, 10, 10, 10, 10, 20, 05, 05, 10, 10, 05, 10, 10}, //electric
|
61
|
|
- {10, 20, 10, 20, 10, 10, 10, 10, 05, 10, 10, 10, 10, 10, 05, 10, 10, 00, 10}, //psychic
|
62
|
|
- {10, 10, 20, 10, 20, 10, 10, 10, 05, 10, 05, 05, 20, 10, 10, 05, 20, 10, 10}, //ice
|
63
|
|
- {10, 10, 10, 10, 10, 10, 10, 10, 05, 10, 10, 10, 10, 10, 10, 10, 20, 10, 00}, //dragon
|
64
|
|
- {10, 05, 10, 10, 10, 10, 10, 20, 10, 10, 10, 10, 10, 10, 20, 10, 10, 05, 05}, //dark
|
65
|
|
- {10, 20, 10, 05, 10, 10, 10, 10, 05, 10, 05, 10, 10, 10, 10, 10, 20, 20, 10} //fairy
|
|
47
|
+ {10, 10, 10, 10, 10, 05, 10, 00, 05, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10}, // normal
|
|
48
|
+ {20, 10, 05, 05, 10, 20, 05, 00, 20, 10, 10, 10, 10, 10, 05, 20, 10, 20, 05}, // fight
|
|
49
|
+ {10, 20, 10, 10, 10, 05, 20, 10, 05, 10, 10, 10, 20, 05, 10, 10, 10, 10, 10}, // flying
|
|
50
|
+ {10, 10, 10, 05, 05, 05, 10, 05, 00, 10, 10, 10, 20, 10, 10, 10, 10, 10, 20}, // poison
|
|
51
|
+ {10, 10, 00, 20, 10, 20, 05, 10, 20, 10, 20, 10, 05, 20, 10, 10, 10, 10, 10}, // ground
|
|
52
|
+ {10, 05, 20, 10, 05, 10, 20, 10, 05, 10, 20, 10, 10, 10, 10, 20, 10, 10, 10}, // rock
|
|
53
|
+ {10, 05, 05, 05, 10, 10, 10, 05, 05, 10, 05, 10, 20, 10, 20, 10, 10, 20, 05}, // bug
|
|
54
|
+ {00, 10, 10, 10, 10, 10, 10, 20, 10, 10, 10, 10, 10, 10, 20, 10, 10, 05, 10}, // ghost
|
|
55
|
+ {10, 10, 10, 10, 10, 20, 10, 10, 05, 10, 05, 05, 10, 05, 10, 20, 10, 10, 20}, // steel
|
|
56
|
+ {10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10}, // egg
|
|
57
|
+ {10, 10, 10, 10, 10, 05, 20, 10, 20, 10, 05, 05, 20, 10, 10, 20, 05, 10, 10}, // fire
|
|
58
|
+ {10, 10, 10, 10, 20, 20, 10, 10, 10, 10, 20, 05, 05, 10, 10, 10, 05, 10, 10}, // water
|
|
59
|
+ {10, 10, 05, 05, 20, 20, 05, 10, 05, 10, 05, 20, 05, 10, 10, 10, 05, 10, 10}, // grass
|
|
60
|
+ {10, 10, 20, 10, 00, 10, 10, 10, 10, 10, 10, 20, 05, 05, 10, 10, 05, 10, 10}, // electric
|
|
61
|
+ {10, 20, 10, 20, 10, 10, 10, 10, 05, 10, 10, 10, 10, 10, 05, 10, 10, 00, 10}, // psychic
|
|
62
|
+ {10, 10, 20, 10, 20, 10, 10, 10, 05, 10, 05, 05, 20, 10, 10, 05, 20, 10, 10}, // ice
|
|
63
|
+ {10, 10, 10, 10, 10, 10, 10, 10, 05, 10, 10, 10, 10, 10, 10, 10, 20, 10, 00}, // dragon
|
|
64
|
+ {10, 05, 10, 10, 10, 10, 10, 20, 10, 10, 10, 10, 10, 10, 20, 10, 10, 05, 05}, // dark
|
|
65
|
+ {10, 20, 10, 05, 10, 10, 10, 10, 05, 10, 05, 10, 10, 10, 10, 10, 20, 20, 10} // fairy
|
66
|
66
|
};
|
67
|
67
|
|
68
|
68
|
/* === IMPLEMENTATIONS === */
|
69
|
|
-u16 battle_damage_type_effectiveness_update(u8 attacking_type, u8 defending_type, u8 atk_bank, u8 def_bank, u16 chained_effect, u8 airstatus) {
|
|
69
|
+u16 battle_damage_type_effectiveness_update(u8 attacking_type, u8 defending_type, u8 atk_bank, u8 def_bank,
|
|
70
|
+ u16 chained_effect, u8 airstatus) {
|
70
|
71
|
u8 effect, atype = attacking_type, dtype = defending_type;
|
71
|
72
|
if (!chained_effect || atype == TYPE_EGG || dtype == TYPE_EGG)
|
72
|
73
|
return chained_effect;
|
|
@@ -86,24 +87,26 @@ u16 battle_damage_type_effectiveness_update(u8 attacking_type, u8 defending_type
|
86
|
87
|
}
|
87
|
88
|
}
|
88
|
89
|
/* handle normal / fighting on ghost */
|
89
|
|
- if ((((attacking_type == TYPE_NORMAL || attacking_type == TYPE_FIGHTING) && defending_type == TYPE_GHOST && ((battle_participants[def_bank].status2.foresight))) || battle_participants[atk_bank].ability_id == ABILITY_SCRAPPY) && effect == 0) {
|
|
90
|
+ if ((((attacking_type == TYPE_NORMAL || attacking_type == TYPE_FIGHTING) && defending_type == TYPE_GHOST &&
|
|
91
|
+ ((battle_participants[def_bank].status2.foresight))) ||
|
|
92
|
+ battle_participants[atk_bank].ability_id == ABILITY_SCRAPPY) &&
|
|
93
|
+ effect == 0) {
|
90
|
94
|
effect = 10;
|
91
|
95
|
}
|
92
|
96
|
/* handle other effectiveness changers here */
|
93
|
97
|
|
94
|
98
|
switch (effect) {
|
95
|
|
- case 0:
|
96
|
|
- chained_effect = 0;
|
97
|
|
- break;
|
98
|
|
- case 5:
|
99
|
|
- chained_effect = chained_effect >> 1;
|
100
|
|
- break;
|
101
|
|
- case 20:
|
102
|
|
- chained_effect = chained_effect << 1;
|
103
|
|
- break;
|
|
99
|
+ case 0:
|
|
100
|
+ chained_effect = 0;
|
|
101
|
+ break;
|
|
102
|
+ case 5:
|
|
103
|
+ chained_effect = chained_effect >> 1;
|
|
104
|
+ break;
|
|
105
|
+ case 20:
|
|
106
|
+ chained_effect = chained_effect << 1;
|
|
107
|
+ break;
|
104
|
108
|
}
|
105
|
109
|
return chained_effect;
|
106
|
|
-
|
107
|
110
|
}
|
108
|
111
|
|
109
|
112
|
u16 battle_apply_type_effectiveness(u16 chained_effect, u8 move_type, u8 target_bank, u8 atk_bank, u8 airstatus) {
|
|
@@ -112,18 +115,21 @@ u16 battle_apply_type_effectiveness(u16 chained_effect, u8 move_type, u8 target_
|
112
|
115
|
/* set different types */
|
113
|
116
|
if (defender_type2 == defender_type1)
|
114
|
117
|
defender_type2 = TYPE_EGG;
|
115
|
|
- chained_effect = battle_damage_type_effectiveness_update(move_type, defender_type1, atk_bank, target_bank, chained_effect, airstatus);
|
116
|
|
- chained_effect = battle_damage_type_effectiveness_update(move_type, defender_type2, atk_bank, target_bank, chained_effect, airstatus);
|
|
118
|
+ chained_effect = battle_damage_type_effectiveness_update(move_type, defender_type1, atk_bank, target_bank,
|
|
119
|
+ chained_effect, airstatus);
|
|
120
|
+ chained_effect = battle_damage_type_effectiveness_update(move_type, defender_type2, atk_bank, target_bank,
|
|
121
|
+ chained_effect, airstatus);
|
117
|
122
|
return chained_effect;
|
118
|
123
|
}
|
119
|
124
|
|
120
|
|
-u16 battle_type_effectiveness_calc(u16 move, u8 move_type, u8 atk_bank, u8 def_bank, u8 effects_handling_and_recording) {
|
|
125
|
+u16 battle_type_effectiveness_calc(u16 move, u8 move_type, u8 atk_bank, u8 def_bank,
|
|
126
|
+ u8 effects_handling_and_recording) {
|
121
|
127
|
u16 chained_effect = 64;
|
122
|
|
- //TODO: double_type moves
|
123
|
|
- //TODO: get air status
|
|
128
|
+ // TODO: double_type moves
|
|
129
|
+ // TODO: get air status
|
124
|
130
|
chained_effect = battle_apply_type_effectiveness(chained_effect, move_type, def_bank, atk_bank, 2);
|
125
|
|
- //TODO: save into structs
|
126
|
|
- //TODO: effect_handling_and_recording
|
|
131
|
+ // TODO: save into structs
|
|
132
|
+ // TODO: effect_handling_and_recording
|
127
|
133
|
return chained_effect;
|
128
|
134
|
}
|
129
|
135
|
|
|
@@ -133,7 +139,8 @@ u8 battle_bank_has_type(u8 bank, u8 type) {
|
133
|
139
|
|
134
|
140
|
u8 battle_item_get_effect(u8 bank, u8 check_negating_effects) {
|
135
|
141
|
if (check_negating_effects) {
|
136
|
|
- if (battle_participants[bank].ability_id == ABILITY_KLUTZ || custom_battle_elements.ptr->bank_affecting[bank].embargo)
|
|
142
|
+ if (battle_participants[bank].ability_id == ABILITY_KLUTZ ||
|
|
143
|
+ custom_battle_elements.ptr->bank_affecting[bank].embargo)
|
137
|
144
|
return ITEM_EFFECT_NOEFFECT;
|
138
|
145
|
}
|
139
|
146
|
if (battle_participants[bank].held_item == ITEM_ENIGMABERRY) {
|
|
@@ -143,37 +150,39 @@ u8 battle_item_get_effect(u8 bank, u8 check_negating_effects) {
|
143
|
150
|
}
|
144
|
151
|
}
|
145
|
152
|
|
146
|
|
-u8 battle_bank_is_poison_resistant(u8 bank, u8 self_inflicted) { //0 == can poison
|
147
|
|
- //1 == is already poisoned
|
148
|
|
- //2 == has other major condition
|
149
|
|
- //3 == type doesn't allow it
|
150
|
|
- //4 == ability doesn't allow it
|
151
|
|
- //5 == safeguard protection
|
152
|
|
- //8 == misty terrain doesn't allow it !TODO!
|
|
153
|
+u8 battle_bank_is_poison_resistant(u8 bank, u8 self_inflicted) { // 0 == can poison
|
|
154
|
+ // 1 == is already poisoned
|
|
155
|
+ // 2 == has other major condition
|
|
156
|
+ // 3 == type doesn't allow it
|
|
157
|
+ // 4 == ability doesn't allow it
|
|
158
|
+ // 5 == safeguard protection
|
|
159
|
+ // 8 == misty terrain doesn't allow it !TODO!
|
153
|
160
|
if (battle_participants[bank].status.flags.poison || battle_participants[bank].status.flags.toxic_poison)
|
154
|
161
|
return 1;
|
155
|
162
|
if (battle_participants[bank].status.int_status)
|
156
|
163
|
return 2;
|
157
|
164
|
if (battle_bank_has_type(bank, TYPE_POISON) || battle_bank_has_type(bank, TYPE_STEEL))
|
158
|
165
|
return 3;
|
159
|
|
- if (((battle_participants[bank].ability_id == ABILITY_IMMUNITY || (battle_participants[bank].ability_id == ABILITY_LEAF_GUARD && (battle_weather.flags.sun || battle_weather.flags.permament_sun || battle_weather.flags.harsh_sun)))))
|
|
166
|
+ if (((battle_participants[bank].ability_id == ABILITY_IMMUNITY ||
|
|
167
|
+ (battle_participants[bank].ability_id == ABILITY_LEAF_GUARD &&
|
|
168
|
+ (battle_weather.flags.sun || battle_weather.flags.permament_sun || battle_weather.flags.harsh_sun)))))
|
160
|
169
|
return 4;
|
161
|
170
|
if (side_affecting_halfword[get_side_from_bank(bank)].safeguard_on && !self_inflicted)
|
162
|
171
|
return 5;
|
163
|
172
|
return 0;
|
164
|
173
|
}
|
165
|
174
|
|
166
|
|
-u8 battle_count_party_pokemon(u8 bank)
|
167
|
|
-{
|
168
|
|
- struct pokemon* poke;
|
|
175
|
+u8 battle_count_party_pokemon(u8 bank) {
|
|
176
|
+ struct pokemon *poke;
|
169
|
177
|
if (get_side_from_bank(bank))
|
170
|
178
|
poke = &party_opponent[0];
|
171
|
179
|
else
|
172
|
180
|
poke = &party_player[0];
|
173
|
181
|
u8 usable_pokes = 0;
|
174
|
|
- for (u8 i = 0; i < 6; i ++)
|
175
|
|
- {
|
176
|
|
- if (pokemon_get_attribute(&poke[i], ATTR_CURRENT_HP, 0) != 0 && pokemon_get_attribute(&poke[i], ATTR_IS_EGG, 0) != 1 && pokemon_get_attribute(&poke[i], ATTR_SPECIES, 0) != 0)
|
|
182
|
+ for (u8 i = 0; i < 6; i++) {
|
|
183
|
+ if (pokemon_get_attribute(&poke[i], ATTR_CURRENT_HP, 0) != 0 &&
|
|
184
|
+ pokemon_get_attribute(&poke[i], ATTR_IS_EGG, 0) != 1 &&
|
|
185
|
+ pokemon_get_attribute(&poke[i], ATTR_SPECIES, 0) != 0)
|
177
|
186
|
usable_pokes++;
|
178
|
187
|
}
|
179
|
188
|
return usable_pokes;
|