pokemon_data_i.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #ifndef __POKEMON_DATA_I_H__
  2. #define __POKEMON_DATA_I_H__
  3. #include "pokemon_data.h"
  4. //#include "pokemon_app.h"
  5. //#include "pokemon_char_encode.h"
  6. static void pokemon_stat_ev_calc(PokemonData* pdata, EvIv val);
  7. static void pokemon_stat_iv_calc(PokemonData* pdata, EvIv val);
  8. /* The struct is laid out exactly as the data trasfer that gets sent for trade
  9. * information. It has to be packed in order to not have padding in the Flipper.
  10. * Packing is always potentially filled with pitfalls, however this has worked
  11. * in testing without issue and this code isn't meant to be portable.
  12. */
  13. /* NOTE: These are all opposite endianness on the flipper than they are in the
  14. * GB/Z80. e.g. a uint16_t value of 0x2c01 translates to 0x012c.
  15. * Need to use __builtin_bswap16(val) to switch between Flipper and Pokemon.
  16. */
  17. /* This is 44 bytes in memory */
  18. struct __attribute__((__packed__)) pokemon_party_data_gen_i {
  19. uint8_t index;
  20. uint16_t hp; // Calculated from level
  21. /* Level is normally calculated from exp, however, level is more human
  22. * readable/digestable compared to exp. Therefore, we set legel and then
  23. * from that calculate, (Max)HP, ATK, DEF, SPD, SPC.
  24. */
  25. uint8_t level;
  26. uint8_t status_condition; // Do you really want to trade a Poisoned pokemon?
  27. uint8_t type[2]; // Pokemon with a single type just repeat the type twice
  28. uint8_t catch_held; // Unsure if this has any effect in Gen 1
  29. uint8_t move[4];
  30. uint16_t ot_id;
  31. uint8_t exp[3]; // Calculated from level
  32. uint16_t hp_ev;
  33. uint16_t atk_ev;
  34. uint16_t def_ev;
  35. uint16_t spd_ev;
  36. uint16_t spc_ev;
  37. uint16_t iv;
  38. uint8_t move_pp[4];
  39. uint8_t level_again; // Copy of level
  40. uint16_t max_hp; // Calculated from level
  41. uint16_t atk; // Calculated from level
  42. uint16_t def; // Calculated from level
  43. uint16_t spd; // Calculated from level
  44. uint16_t spc; // Calculated from level
  45. };
  46. struct __attribute__((__packed__)) name {
  47. /* Reused a few times, but in Gen I, all name strings are 11 bytes in memory.
  48. * At most, 10 symbols and a TERM_ byte.
  49. * Note that some strings must be shorter than 11.
  50. */
  51. uint8_t str[LEN_NAME_BUF];
  52. };
  53. typedef struct name Name;
  54. /* This is 415 bytes in memory/transmitted */
  55. struct __attribute__((__packed__)) trade_block_gen_i {
  56. Name trainer_name;
  57. uint8_t party_cnt;
  58. /* Only the first pokemon is ever used even though there are 7 bytes here.
  59. * If the remaining 6 bytes are _not_ 0xff, then the trade window renders
  60. * garbage for the Flipper's party.
  61. */
  62. uint8_t party_members[7];
  63. /* Only the first pokemon is set up, even though there are 6 total party members */
  64. PokemonPartyGenI party[6];
  65. /* Only the first pokemon has an OT name and nickname even though there are 6 members */
  66. /* OT name should not exceed 7 chars! */
  67. Name ot_name[6];
  68. Name nickname[6];
  69. };
  70. /* NOTE: These are all opposite endianness on the flipper than they are in the
  71. * GB/Z80. e.g. a uint16_t value of 0x2c01 translates to 0x012c.
  72. * Need to use __builtin_bswap16(val) to switch between Flipper and Pokemon.
  73. */
  74. /* This is 48 bytes in memory */
  75. struct __attribute__((__packed__)) pokemon_party_data_gen_ii {
  76. uint8_t index;
  77. uint8_t held_item;
  78. uint8_t move[4];
  79. uint16_t ot_id;
  80. uint8_t exp[3];
  81. uint16_t hp_ev;
  82. uint16_t atk_ev;
  83. uint16_t def_ev;
  84. uint16_t spd_ev;
  85. uint16_t spc_ev;
  86. uint16_t iv;
  87. uint8_t move_pp[4];
  88. uint8_t friendship;
  89. uint8_t pokerus;
  90. uint16_t caught_data;
  91. /* Level is normally calculated from exp, however, level is more human
  92. * readable/digestable compared to exp. Therefore, we set level and then
  93. * from that calculate, (Max)HP, ATK, DEF, SPD, SPC.
  94. */
  95. uint8_t level;
  96. uint8_t status_condition;
  97. uint8_t unused;
  98. uint16_t hp;
  99. uint16_t max_hp;
  100. uint16_t atk;
  101. uint16_t def;
  102. uint16_t spd;
  103. uint16_t spc_atk;
  104. uint16_t spc_def;
  105. };
  106. /* NOTE:
  107. * For eggs in gen ii, the handling is a bit clever. The party structure is set
  108. * up as normal for the pokemon that will hatch. The only difference is the
  109. * friendship vairable is used to denote number of egg cycles remaining.
  110. * Then, in the party_members array, that pokemon's index is set to 0xFD which
  111. * is the index for an egg. Once traded, its now an egg.
  112. * Creating an egg is not implemented at this time because I don't really see
  113. * a reason to. But, knowing some of these details makes it really easy to
  114. * implement later on.
  115. */
  116. struct __attribute__((__packed__)) trade_block_gen_ii {
  117. Name trainer_name;
  118. uint8_t party_cnt;
  119. /* Only the first pokemon is ever used even though there are 7 bytes here.
  120. * If the remaining 6 bytes are _not_ 0xff, then the trade window renders
  121. * garbage for the Flipper's party.
  122. */
  123. uint8_t party_members[7];
  124. uint16_t trainer_id;
  125. /* Only the first pokemon is set up, even though there are 6 total party members */
  126. PokemonPartyGenII party[6];
  127. /* Only the first pokemon has an OT name and nickname even though there are 6 members */
  128. /* OT name should not exceed 7 chars! */
  129. Name ot_name[6];
  130. Name nickname[6];
  131. };
  132. #endif // __POKEMON_DATA_I_H__