No Description

custom_structs_malloc.c 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include <bpre.h>
  2. #include <battle.h>
  3. #include "custom_structs.h"
  4. #include "custom_structs_malloc.h"
  5. #include <debug.h>
  6. #include <items.h>
  7. void malloc_battle_structs()
  8. {
  9. custom_battle_elements.ptr=(struct custom_battle_struct*)malloc(sizeof(struct custom_battle_struct));
  10. }
  11. void free_battle_structs()
  12. {
  13. free(custom_battle_elements.ptr);
  14. custom_battle_elements.ptr=0;
  15. }
  16. //hijack switch in command, clean up battle structs and carry over baton pass
  17. void battle_switch_in()
  18. {
  19. struct bank_affecting* current_bank_affecting = &custom_battle_elements.ptr->bank_affecting[battle_active_bank];
  20. //copy of the old structure to carry over baton pass effects
  21. struct bank_affecting prev_bank_affecting = custom_battle_elements.ptr->bank_affecting[battle_active_bank];
  22. memset(current_bank_affecting, 0, sizeof(struct bank_affecting));
  23. //handle type 3 if needed
  24. current_bank_affecting->just_switched_in = 1;
  25. current_bank_affecting->wish_hp = prev_bank_affecting.wish_hp;
  26. if(battle_executed_move == MOVE_BATON_PASS)
  27. {
  28. current_bank_affecting->aqua_ring = prev_bank_affecting.aqua_ring;
  29. current_bank_affecting->embargo = prev_bank_affecting.embargo;
  30. current_bank_affecting->powertrick = prev_bank_affecting.powertrick;
  31. current_bank_affecting->gastro_acided = prev_bank_affecting.gastro_acided;
  32. current_bank_affecting->heal_block = prev_bank_affecting.heal_block;
  33. if(prev_bank_affecting.powertrick)
  34. {
  35. //carry over switched stats of power trick
  36. u16 *atk = &battle_participants[battle_active_bank].atk;
  37. u16 *def = &battle_participants[battle_active_bank].def;
  38. u16 switch_var = *atk;
  39. *atk = *def;
  40. *def = switch_var;
  41. }
  42. }
  43. struct side_affecting* active_side = &custom_battle_elements.ptr->side_affecting[get_side_from_bank(battle_active_bank)];
  44. active_side->stealth_rock_done = 0;
  45. active_side->sticky_web_done = 0;
  46. active_side->toxic_spikes_done = 0;
  47. active_side->lunardance_done = 0;
  48. return;
  49. }