Skip to content

Commit

Permalink
pokemon: Reimplement logging
Browse files Browse the repository at this point in the history
  • Loading branch information
kbembedded committed Nov 6, 2023
1 parent 788848a commit de8ef7d
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pokemon_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -1920,6 +1920,7 @@ void pokemon_trade_block_set_default_name(char* dest, PokemonFap* pokemon_fap, s
toupper(pokemon_fap->pokemon_table[pokemon_fap->curr_pokemon].name[i]));
buf[i] = toupper(pokemon_fap->pokemon_table[pokemon_fap->curr_pokemon].name[i]);
}
FURI_LOG_D(TAG, "[app] Set default nickname");

if(dest != NULL) {
strncpy(dest, buf, n);
Expand Down Expand Up @@ -1972,6 +1973,8 @@ void pokemon_trade_block_recalculate_stats_from_level(PokemonFap* pokemon_fap) {

pkmn->level_again = level;
UINT32_TO_EXP(experience, pkmn->exp);
FURI_LOG_D(TAG, "[app] Set pkmn level %d", level);
FURI_LOG_D(TAG, "[app] Set pkmn exp %d", (int)experience);

/* Generate STATEXP */
switch(curr_stats) {
Expand All @@ -1988,6 +1991,7 @@ void pokemon_trade_block_recalculate_stats_from_level(PokemonFap* pokemon_fap) {
break;
}

FURI_LOG_D(TAG, "[app] EVs set to %d", stat);
stat = __builtin_bswap16(stat);

pkmn->hp_ev = stat;
Expand All @@ -2006,33 +2010,50 @@ void pokemon_trade_block_recalculate_stats_from_level(PokemonFap* pokemon_fap) {
((special_iv & 0x0f));
hp_iv = (pkmn->iv & 0xAA) >> 4;
}
FURI_LOG_D(
TAG,
"[app] atk_iv %d, def_iv %d, spd_iv %d, spc_iv %d, hp_iv %d",
atk_iv,
def_iv,
spd_iv,
special_iv,
hp_iv);

/* Calculate HP */
// https://bulbapedia.bulbagarden.net/wiki/Stat#Generations_I_and_II
stat = floor((((2 * (table->base_hp + hp_iv)) + floor(sqrt(pkmn->hp_ev) / 4)) * level) / 100) +
(level + 10);
FURI_LOG_D(TAG, "[app] HP set to %d", stat);
pkmn->hp = __builtin_bswap16(stat);
pkmn->max_hp = pkmn->hp;

/* Calculate ATK, DEF, SPD, SP */
/* TODO: these all use the same calculations, could put the stats in a sub-array and iterate
* through each element in order rather than having to repeat the code. IVs would also need
* to be in a similar array.
**/
// https://bulbapedia.bulbagarden.net/wiki/Stat#Generations_I_and_II
stat =
floor((((2 * (table->base_atk + atk_iv)) + floor(sqrt(pkmn->atk_ev) / 4)) * level) / 100) +
5;
FURI_LOG_D(TAG, "[app] ATK set to %d", stat);
pkmn->atk = __builtin_bswap16(stat);
stat =
floor((((2 * (table->base_def + def_iv)) + floor(sqrt(pkmn->def_ev) / 4)) * level) / 100) +
5;
FURI_LOG_D(TAG, "[app] DEF set to %d", stat);
pkmn->def = __builtin_bswap16(stat);
stat =
floor((((2 * (table->base_spd + spd_iv)) + floor(sqrt(pkmn->spd_ev) / 4)) * level) / 100) +
5;
FURI_LOG_D(TAG, "[app] SPD set to %d", stat);
pkmn->spd = __builtin_bswap16(stat);
stat = floor(
(((2 * (table->base_special + special_iv)) + floor(sqrt(pkmn->special_ev) / 4)) *
level) /
100) +
5;
FURI_LOG_D(TAG, "[app] SPC set to %d", stat);
pkmn->special = __builtin_bswap16(stat);
}

Expand All @@ -2045,15 +2066,24 @@ void pokemon_trade_block_recalculate(PokemonFap* pokemon_fap) {
/* Set current pokemon to the trade structure */
pkmn->index = table->index;
pokemon_fap->trade_block->party_members[0] = table->index;
FURI_LOG_D(TAG, "[app] Set %s in trade block", table->name);

/* Set current pokemon's moves to the trade structure */
for(i = 0; i < 4; i++) {
pkmn->move[i] = table->move[i];
FURI_LOG_D(
TAG,
"[app] Set %s in trade block",
pokemon_named_list_get_name_from_index(pokemon_fap->move_list, pkmn->move[i]));
}

/* Set current pokemon's types to the trade structure */
for(i = 0; i < 2; i++) {
pkmn->type[i] = table->type[i];
FURI_LOG_D(
TAG,
"[app] Set %s in trade block",
pokemon_named_list_get_name_from_index(pokemon_fap->type_list, pkmn->type[i]));
}

pokemon_trade_block_recalculate_stats_from_level(pokemon_fap);
Expand Down
6 changes: 6 additions & 0 deletions scenes/pokemon_move.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ static void select_move_selected_callback(void* context, uint32_t index) {
} else {
pokemon_fap->trade_block->party[0].move[move] = (uint8_t)index;
}
FURI_LOG_D(
TAG,
"[move] Set move %s to %d",
pokemon_named_list_get_name_from_index(
pokemon_fap->move_list, pokemon_fap->trade_block->party[0].move[move]),
(int)move);

/* Move back to move menu */
scene_manager_search_and_switch_to_previous_scene(pokemon_fap->scene_manager, SelectMoveScene);
Expand Down
2 changes: 2 additions & 0 deletions scenes/pokemon_nickname.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ static bool select_nickname_input_validator(const char* text, FuriString* error,
(uint8_t*)pokemon_fap->trade_block->nickname, (char*)text, strlen(text));
}

FURI_LOG_D(TAG, "[nickname] Set nickname to %s", text);

return rc;
}

Expand Down
2 changes: 2 additions & 0 deletions scenes/pokemon_ot_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ static bool select_ot_id_input_validator(const char* text, FuriString* error, vo
pokemon_fap->trade_block->party[0].ot_id = ot_id_16;
}

FURI_LOG_D(TAG, "[ot_id] Set OT ID to %05d", (uint16_t)ot_id);

return rc;
}

Expand Down
2 changes: 2 additions & 0 deletions scenes/pokemon_ot_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ static bool select_ot_name_input_validator(const char* text, FuriString* error,
(uint8_t*)pokemon_fap->trade_block->ot_name, (char*)text, strlen(text));
}

FURI_LOG_D(TAG, "[ot_name] Set OT name to %s", text);

return rc;
}

Expand Down
2 changes: 2 additions & 0 deletions scenes/pokemon_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ static void select_stats_selected_callback(void* context, uint32_t index) {

pokemon_trade_block_recalculate_stats_from_level(pokemon_fap);

FURI_LOG_D(TAG, "[stats] Set stats to %s", stats_text[index]);

scene_manager_previous_scene(pokemon_fap->scene_manager);
}

Expand Down
12 changes: 12 additions & 0 deletions scenes/pokemon_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ static void select_type_1_callback(VariableItem* item) {

variable_item_set_current_value_text(item, pokemon_fap->type_list[index].name);
pokemon_fap->trade_block->party[0].type[0] = pokemon_fap->type_list[index].index;

FURI_LOG_D(
TAG,
"[type] Set type1 to %s",
pokemon_named_list_get_name_from_index(
pokemon_fap->type_list, pokemon_fap->type_list[index].index));
}

static void select_type_2_callback(VariableItem* item) {
Expand All @@ -26,6 +32,12 @@ static void select_type_2_callback(VariableItem* item) {

variable_item_set_current_value_text(item, pokemon_fap->type_list[index].name);
pokemon_fap->trade_block->party[0].type[1] = pokemon_fap->type_list[index].index;

FURI_LOG_D(
TAG,
"[type] Set type2 to %s",
pokemon_named_list_get_name_from_index(
pokemon_fap->type_list, pokemon_fap->type_list[index].index));
}

void select_type_scene_on_exit(void* context) {
Expand Down
1 change: 1 addition & 0 deletions views/select_pokemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ static bool select_pokemon_input_callback(InputEvent* event, void* context) {
/* Advance to next view with the selected pokemon */
case InputKeyOk:
pokemon_fap->curr_pokemon = selected_pokemon;
FURI_LOG_D(TAG, "[Select] Selected %s", pokemon_fap->pokemon_table[selected_pokemon].name);
scene_manager_previous_scene(pokemon_fap->scene_manager);
consumed = true;
break;
Expand Down

0 comments on commit de8ef7d

Please sign in to comment.