pokemon_data.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #ifndef POKEMON_DATA_H
  2. #define POKEMON_DATA_H
  3. #pragma once
  4. /* The struct is laid out exactly as the data trasfer that gets sent for trade
  5. * information. It has to be packed in order to not have padding in the Flipper.
  6. * Packing is always potentially filled with pitfalls, however this has worked
  7. * in testing without issue and this code isn't meant to be portable.
  8. */
  9. /* NOTE: These are all opposite endianness on the flipper than they are in the
  10. * GB/Z80. e.g. a uint16_t value of 0x2c01 translates to 0x012c.
  11. * Need to use __builtin_bswap16(val) to switch between Flipper and Pokemon.
  12. */
  13. /* This is 44 bytes in memory */
  14. struct __attribute__((__packed__)) pokemon_structure {
  15. uint8_t index;
  16. uint16_t hp; // Calculated from level
  17. /* Level is normally calculated from exp, however, level is more human
  18. * readable/digestable compared to exp. Therefore, we set legel and then
  19. * from that calculate, (Max)HP, ATK, DEF, SPD, SPC.
  20. */
  21. uint8_t level;
  22. uint8_t status_condition; // Do you really want to trade a Poisoned pokemon?
  23. uint8_t type[2]; // Pokemon with a single type just repeat the type twice
  24. uint8_t catch_held; // Unsure if this has any effect in Gen 1
  25. uint8_t move[4];
  26. uint16_t ot_id;
  27. uint8_t exp[3]; // Calculated from level
  28. uint16_t hp_ev;
  29. uint16_t atk_ev;
  30. uint16_t def_ev;
  31. uint16_t spd_ev;
  32. uint16_t special_ev;
  33. uint16_t iv;
  34. uint8_t move_pp[4];
  35. uint8_t level_again; // Copy of level
  36. uint16_t max_hp; // Calculated from level
  37. uint16_t atk; // Calculated from level
  38. uint16_t def; // Calculated from level
  39. uint16_t spd; // Calculated from level
  40. uint16_t special; // Calculated from level
  41. };
  42. struct __attribute__((__packed__)) name {
  43. /* Reused a few times, but in Gen I, all name strings are 11 bytes in memory.
  44. * At most, 10 symbols and a TERM_ byte.
  45. * Note that some strings must be shorter than 11.
  46. */
  47. unsigned char str[11];
  48. };
  49. /* This is 415 bytes in memory/transmitted */
  50. struct __attribute__((__packed__)) trade_data_block {
  51. /* TODO: Change this to use struct name above */
  52. unsigned char trainer_name[11];
  53. uint8_t party_cnt;
  54. /* Only the first pokemon is ever used even though there are 7 bytes here.
  55. * If the remaining 6 bytes are _not_ 0xff, then the trade window renders
  56. * garbage for the Flipper's party.
  57. */
  58. uint8_t party_members[7];
  59. /* Only the first pokemon is set up, even though there are 6 total party members */
  60. struct pokemon_structure party[6];
  61. /* Only the first pokemon has an OT name and nickname even though there are 6 members */
  62. /* OT name should not exceed 7 chars! */
  63. struct name ot_name[6];
  64. struct name nickname[6];
  65. };
  66. typedef struct trade_data_block TradeBlock;
  67. #endif /* POKEMON_DATA_H */