|
@@ -30,6 +30,7 @@
|
30
|
30
|
#include <game_engine.h>
|
31
|
31
|
#include <pkmn_attributes.h>
|
32
|
32
|
#include <agb_debug.h>
|
|
33
|
+#include <math.h>
|
33
|
34
|
|
34
|
35
|
enum evo_source
|
35
|
36
|
{
|
|
@@ -56,13 +57,30 @@ struct evo_result
|
56
|
57
|
};
|
57
|
58
|
|
58
|
59
|
#define EVO_NULL {0,0,0,0,0}
|
|
60
|
+#define MAX_EVOLUTIONS 5
|
|
61
|
+#define EVO_NO_EVO (struct evo_result){false,false,0}
|
|
62
|
+
|
|
63
|
+#define HAPPY_BOUND 219
|
|
64
|
+#define BEAUTY_BOUND 170
|
|
65
|
+
|
|
66
|
+#define EVO_HAPPINESS 1
|
59
|
67
|
#define EVO_LEVEL_UP 4
|
60
|
|
-#define MAX_EVOLUTIONS 3
|
|
68
|
+#define EVO_TRADE 5
|
|
69
|
+#define EVO_TRADE_ITEM 6
|
|
70
|
+#define EVO_STONE 7
|
|
71
|
+#define EVO_ATK 8
|
|
72
|
+#define EVO_DEF 9
|
|
73
|
+#define EVO_ADEQU 10
|
|
74
|
+#define EVO_PERSO_HIGH 11
|
|
75
|
+#define EVO_PERSO_LOW 12
|
|
76
|
+#define EVO_SPAWN 13
|
|
77
|
+#define EVO_SPAWNED 14
|
|
78
|
+#define EVO_BEAUTY 15
|
61
|
79
|
|
62
|
80
|
struct evo_information evolutions[][MAX_EVOLUTIONS] = {
|
63
|
|
- {EVO_NULL,EVO_NULL,EVO_NULL},
|
64
|
|
- {{EVO_LEVEL_UP,16,2,0,0},EVO_NULL,EVO_NULL},
|
65
|
|
- {{EVO_LEVEL_UP,32,3,0,0},EVO_NULL,EVO_NULL},
|
|
81
|
+ {EVO_NULL,EVO_NULL,EVO_NULL,EVO_NULL,EVO_NULL}, //Nothing
|
|
82
|
+ {{EVO_BEAUTY,7,2,0,0},{EVO_SPAWNED,7,150,0,0},EVO_NULL,EVO_NULL,EVO_NULL}, //BISASAM
|
|
83
|
+ {{EVO_LEVEL_UP,32,3,0,0},EVO_NULL,EVO_NULL,EVO_NULL,EVO_NULL},//BISAKNOSP
|
66
|
84
|
};
|
67
|
85
|
|
68
|
86
|
struct evo_call_arguments
|
|
@@ -79,24 +97,169 @@ typedef struct evo_result (*evolution_callback)(struct evo_call_arguments);
|
79
|
97
|
|
80
|
98
|
struct evo_result evolve_by_level(struct evo_call_arguments arguments)
|
81
|
99
|
{
|
82
|
|
- if(arguments.source != LEVEL_UP)
|
|
100
|
+ if(arguments.evolution.argument <= arguments.level && arguments.source == LEVEL_UP)
|
|
101
|
+ {
|
|
102
|
+ return (struct evo_result){true, false, arguments.evolution.evolve_to};
|
|
103
|
+ }
|
|
104
|
+ else
|
|
105
|
+ {
|
|
106
|
+ return (struct evo_result){false, false, 0};
|
|
107
|
+ }
|
|
108
|
+}
|
|
109
|
+
|
|
110
|
+struct evo_result evolve_by_trade_group(struct evo_call_arguments arguments)
|
|
111
|
+{
|
|
112
|
+ if(arguments.source != TRADE)
|
83
|
113
|
{
|
84
|
114
|
return (struct evo_result){false, false, 0};
|
85
|
115
|
}
|
86
|
|
- if(arguments.evolution.argument <= arguments.level)
|
|
116
|
+ if(arguments.evolution.method == EVO_TRADE_ITEM)
|
|
117
|
+ {
|
|
118
|
+ if(arguments.item != arguments.evolution.argument)
|
|
119
|
+ return (struct evo_result){false, false, 0};
|
|
120
|
+ else
|
|
121
|
+ return (struct evo_result){true,true, arguments.evolution.evolve_to};
|
|
122
|
+ }
|
|
123
|
+ else if(arguments.evolution.method == EVO_TRADE)
|
|
124
|
+ {
|
|
125
|
+ return (struct evo_result){true, false, arguments.evolution.evolve_to};
|
|
126
|
+ }
|
|
127
|
+ else
|
|
128
|
+ {
|
|
129
|
+ dprintf("An invalid trade group method was reached in \"evolve_by_trade_group\"\nmethod: %d", arguments.evolution.method);
|
|
130
|
+ return (struct evo_result){false,false,0};
|
|
131
|
+ }
|
|
132
|
+}
|
|
133
|
+
|
|
134
|
+struct evo_result evolve_random(struct evo_call_arguments arguments)
|
|
135
|
+{
|
|
136
|
+ if(arguments.source != LEVEL_UP)
|
|
137
|
+ {
|
|
138
|
+ return EVO_NO_EVO;
|
|
139
|
+ }
|
|
140
|
+ u32 pid = pokemon_get_attribute(arguments.poke, ATTR_PID, NULL);
|
|
141
|
+ pid = pid & 0xFFFF;
|
|
142
|
+ u8 mod = __aeabi_uidivmod(pid, 10);
|
|
143
|
+ dprintf("A pokemon tries to evolve at random: pid: %d, low: %d, mod: %d\n", pid, pid, mod);
|
|
144
|
+ if(mod >= 5)
|
|
145
|
+ {
|
|
146
|
+ if(arguments.evolution.method == EVO_PERSO_HIGH)
|
|
147
|
+ return (struct evo_result){true, false, arguments.evolution.evolve_to};
|
|
148
|
+ else
|
|
149
|
+ return EVO_NO_EVO;
|
|
150
|
+ }
|
|
151
|
+ else
|
|
152
|
+ {
|
|
153
|
+ if(arguments.evolution.method == EVO_PERSO_LOW)
|
|
154
|
+ return (struct evo_result){true, false, arguments.evolution.evolve_to};
|
|
155
|
+ else
|
|
156
|
+ return EVO_NO_EVO;
|
|
157
|
+ }
|
|
158
|
+}
|
|
159
|
+
|
|
160
|
+struct evo_result evolve_by_stone(struct evo_call_arguments arguments)
|
|
161
|
+{
|
|
162
|
+ if(arguments.source != STONE_EVOLUTION && arguments.source != STONE_REQUEST)
|
|
163
|
+ {
|
|
164
|
+ return (struct evo_result){false,false, 0};
|
|
165
|
+ }
|
|
166
|
+ if(arguments.stoneId == arguments.evolution.argument)
|
87
|
167
|
{
|
88
|
168
|
return (struct evo_result){true, false, arguments.evolution.evolve_to};
|
89
|
169
|
}
|
|
170
|
+ else
|
|
171
|
+ {
|
|
172
|
+ return (struct evo_result){false,false,0};
|
|
173
|
+ }
|
|
174
|
+}
|
|
175
|
+
|
|
176
|
+struct evo_result evolve_by_atk_def(struct evo_call_arguments arguments)
|
|
177
|
+{
|
|
178
|
+ u32 atk = pokemon_get_attribute(arguments.poke, ATTR_ATTACK, NULL);
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+ u32 def = pokemon_get_attribute(arguments.poke, ATTR_DEFENCE, NULL);
|
|
182
|
+ dprintf("A pokemon wants to evolve by atk and def.\n");
|
|
183
|
+ dprintf("Level required: %d, pkmn level: %d, pkmn atk: %d, pkmn def: %d\n", arguments.evolution.argument, arguments.level, atk, def);
|
|
184
|
+ if(arguments.evolution.method == EVO_ATK)
|
|
185
|
+ {
|
|
186
|
+ if(atk > def)
|
|
187
|
+ return evolve_by_level(arguments);
|
|
188
|
+ else
|
|
189
|
+ return EVO_NO_EVO;
|
|
190
|
+ }
|
|
191
|
+ if(arguments.evolution.method == EVO_DEF)
|
|
192
|
+ {
|
|
193
|
+ if(def > atk)
|
|
194
|
+ return evolve_by_level(arguments);
|
|
195
|
+ else
|
|
196
|
+ return EVO_NO_EVO;
|
|
197
|
+ }
|
|
198
|
+ if(arguments.evolution.method == EVO_ADEQU)
|
|
199
|
+ {
|
|
200
|
+ if(atk == def)
|
|
201
|
+ return evolve_by_level(arguments);
|
|
202
|
+ else
|
|
203
|
+ return EVO_NO_EVO;
|
|
204
|
+ }
|
|
205
|
+ dprintf("invalid atk and def evo code reached.\n");
|
|
206
|
+ return EVO_NO_EVO;
|
|
207
|
+}
|
|
208
|
+
|
|
209
|
+struct evo_result evolve_by_happiness(struct evo_call_arguments arguments)
|
|
210
|
+{
|
|
211
|
+ u32 happiness = pokemon_get_attribute(arguments.poke, ATTR_HAPPINESS, NULL);
|
|
212
|
+ dprintf("A pokemon wants to evolve by happiness.\n");
|
|
213
|
+ dprintf("Happiness value: %d; needed: %d\n", happiness, HAPPY_BOUND);
|
|
214
|
+ if((happiness > HAPPY_BOUND) && (arguments.source == LEVEL_UP))
|
|
215
|
+ {
|
|
216
|
+ return (struct evo_result){true,false,arguments.evolution.evolve_to};
|
|
217
|
+ }
|
|
218
|
+ else
|
|
219
|
+ {
|
|
220
|
+ return (struct evo_result){false,false,0};
|
|
221
|
+ }
|
|
222
|
+}
|
|
223
|
+
|
|
224
|
+struct evo_result evolve_by_beauty(struct evo_call_arguments arguments)
|
|
225
|
+{
|
|
226
|
+ u32 beauty = pokemon_get_attribute(arguments.poke, ATTR_BEAUTY, NULL);
|
|
227
|
+ dprintf("A pokemon tires to evolve by beauty: value: %d; required: %d.\n", beauty, BEAUTY_BOUND);
|
|
228
|
+ if(beauty > BEAUTY_BOUND && arguments.source == LEVEL_UP)
|
|
229
|
+ return evolve_by_level(arguments);
|
|
230
|
+ return EVO_NO_EVO;
|
|
231
|
+}
|
|
232
|
+
|
|
233
|
+struct evo_result evolve_no_method(struct evo_call_arguments arguments)
|
|
234
|
+{
|
|
235
|
+ //For shedninja
|
|
236
|
+ return EVO_NO_EVO;
|
|
237
|
+}
|
|
238
|
+
|
|
239
|
+struct evo_result evolve_invalid_method(struct evo_call_arguments arguments)
|
|
240
|
+{
|
|
241
|
+ dprintf("A pokemon tried to execute an evolution method that is not yet implemented.\n");
|
90
|
242
|
return (struct evo_result){false, false, 0};
|
91
|
243
|
}
|
92
|
244
|
|
93
|
245
|
static evolution_callback evolution_methods[] =
|
94
|
246
|
{
|
95
|
|
- NULL,
|
96
|
|
- NULL, //TODO: Happiness
|
97
|
|
- NULL, //TODO: Happiness DAY
|
98
|
|
- NULL, //TODO: Happiness NIGHT
|
99
|
|
- evolve_by_level
|
|
247
|
+ evolve_invalid_method,
|
|
248
|
+ evolve_by_happiness,
|
|
249
|
+ evolve_invalid_method, //TODO: Happiness DAY
|
|
250
|
+ evolve_invalid_method, //TODO: Happiness NIGHT
|
|
251
|
+ evolve_by_level,
|
|
252
|
+ evolve_by_trade_group,
|
|
253
|
+ evolve_by_trade_group,
|
|
254
|
+ evolve_by_stone,
|
|
255
|
+ evolve_by_atk_def,
|
|
256
|
+ evolve_by_atk_def,
|
|
257
|
+ evolve_by_atk_def,
|
|
258
|
+ evolve_random,
|
|
259
|
+ evolve_random,
|
|
260
|
+ evolve_by_level, //Shedninja SPAWN
|
|
261
|
+ evolve_no_method, //Shedninja SPAWNED
|
|
262
|
+ evolve_by_beauty
|
100
|
263
|
};
|
101
|
264
|
|
102
|
265
|
u16 evolution_try_evolve(struct pokemon* pokemon, enum evo_source source, u16 stoneId)
|
|
@@ -104,16 +267,20 @@ u16 evolution_try_evolve(struct pokemon* pokemon, enum evo_source source, u16 st
|
104
|
267
|
u16 held_item = pokemon_get_attribute(pokemon, ATTR_HELD_ITEM, NULL);
|
105
|
268
|
u16 species = pokemon_get_attribute(pokemon, ATTR_SPECIES, NULL);
|
106
|
269
|
u16 level = pokemon_get_attribute(pokemon, ATTR_LEVEL, NULL);
|
107
|
|
- //TODO PID
|
108
|
270
|
dprintf("Species %d tried to evolve.\n", species);
|
109
|
271
|
dprintf("Cause: %d\n", source);
|
|
272
|
+ if(species > 2)
|
|
273
|
+ {
|
|
274
|
+ dprintf("Currently no evolution possible due to short table!\n");
|
|
275
|
+ return 0;
|
|
276
|
+ }
|
110
|
277
|
struct evo_information* current_evolution_structure = evolutions[species];
|
111
|
278
|
struct evo_result result;
|
112
|
279
|
for(int i = 0; i < MAX_EVOLUTIONS; ++i)
|
113
|
280
|
{
|
114
|
281
|
if(current_evolution_structure[i].method != 0)
|
115
|
282
|
{
|
116
|
|
- dprintf("found valid evolution with method %d for species %d", current_evolution_structure[i].method, species);
|
|
283
|
+ dprintf("found valid evolution with method %d for species %d\n", current_evolution_structure[i].method, species);
|
117
|
284
|
struct evo_call_arguments args = {held_item, level, source, stoneId, pokemon, current_evolution_structure[i]};
|
118
|
285
|
result = evolution_methods[current_evolution_structure[i].method](args);
|
119
|
286
|
if(result.can_evolve)
|
|
@@ -124,12 +291,11 @@ u16 evolution_try_evolve(struct pokemon* pokemon, enum evo_source source, u16 st
|
124
|
291
|
{
|
125
|
292
|
if(result.consume_item)
|
126
|
293
|
{
|
127
|
|
- //TODO: Consume
|
|
294
|
+ u16 zero = 0;
|
|
295
|
+ pokemon_set_attribute(pokemon, ATTR_HELD_ITEM, &zero);
|
128
|
296
|
}
|
129
|
297
|
return result.evolve_to;
|
130
|
298
|
}
|
131
|
299
|
else
|
132
|
300
|
return 0;
|
133
|
|
- /*evolve everything to mewtu for jiggs & giggles*/
|
134
|
|
- return 150;
|
135
|
301
|
}
|