Nav apraksta

custom_structs_malloc.c 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /****************************************************************************
  2. * Copyright (C) 2015-2016 by the SotS Team *
  3. * *
  4. * This file is part of Sovereign of the Skies. *
  5. * *
  6. * Sovereign of the Skies is free software: you can redistribute it *
  7. * and/or modify it *
  8. * under the terms of the GNU Lesser General Public License as published *
  9. * by the Free Software Foundation, either version 3 of the License, or *
  10. * (at your option) any later version provided you include a copy of the *
  11. * licence and this header. *
  12. * *
  13. * Sovereign of the Skies is distributed in the hope that it will be *
  14. * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of *
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  16. * GNU Lesser General Public License for more details. *
  17. * *
  18. * You should have received a copy of the GNU Lesser General Public *
  19. * License along with Sovereign of the Skies. *
  20. * If not, see <http://www.gnu.org/licenses/>. *
  21. ****************************************************************************/
  22. /**
  23. * @file custom_structs_malloc.c
  24. * @author Sturmvogel
  25. * @date 15 dec 2016
  26. * @brief Patch hacks for handling custom battle structures
  27. */
  28. /* === INCLUDE === */
  29. #include <battle_common.h>
  30. #include <battle_custom_structs.h>
  31. #include <battle_locations.h>
  32. #include <config/core.h>
  33. #include <constants/moves.h>
  34. #include <game_engine.h>
  35. #include <memory.h>
  36. /* === PROTOTYPES === */
  37. /**
  38. * @brief allocate the new battle struct memory
  39. */
  40. void malloc_battle_structs();
  41. /**
  42. * @brief free the new battle struct memory
  43. */
  44. void free_battle_structs();
  45. /**
  46. * @brief handle switch in uptates on structures
  47. */
  48. void battle_switch_in();
  49. /* === IMPLEMENTATIONS === */
  50. void malloc_battle_structs() {
  51. custom_battle_elements.ptr = (struct custom_battle_struct *)malloc(sizeof(struct custom_battle_struct));
  52. }
  53. void free_battle_structs() {
  54. free(custom_battle_elements.ptr);
  55. custom_battle_elements.ptr = 0;
  56. flag_clear(FLAG_DEOXYS_AURA);
  57. flag_clear(FLAG_SKIP_BATTLE_MUSIC);
  58. }
  59. // hijack switch in command, clean up battle structs and carry over baton pass
  60. void battle_switch_in() {
  61. struct bank_affecting *current_bank_affecting = &custom_battle_elements.ptr->bank_affecting[battle_active_bank];
  62. // copy of the old structure to carry over baton pass effects
  63. struct bank_affecting prev_bank_affecting = custom_battle_elements.ptr->bank_affecting[battle_active_bank];
  64. memset(current_bank_affecting, 0, sizeof(struct bank_affecting));
  65. // handle type 3 if needed
  66. current_bank_affecting->just_switched_in = 1;
  67. current_bank_affecting->wish_hp = prev_bank_affecting.wish_hp;
  68. if (battle_executed_move == MOVE_BATON_PASS) {
  69. current_bank_affecting->aqua_ring = prev_bank_affecting.aqua_ring;
  70. current_bank_affecting->embargo = prev_bank_affecting.embargo;
  71. current_bank_affecting->powertrick = prev_bank_affecting.powertrick;
  72. current_bank_affecting->gastro_acided = prev_bank_affecting.gastro_acided;
  73. current_bank_affecting->heal_block = prev_bank_affecting.heal_block;
  74. if (prev_bank_affecting.powertrick) {
  75. // carry over switched stats of power trick
  76. u16 *atk = &battle_participants[battle_active_bank].atk;
  77. u16 *def = &battle_participants[battle_active_bank].def;
  78. u16 switch_var = *atk;
  79. *atk = *def;
  80. *def = switch_var;
  81. }
  82. }
  83. struct side_affecting *active_side =
  84. &custom_battle_elements.ptr->side_affecting[get_side_from_bank(battle_active_bank)];
  85. active_side->stealth_rock_done = 0;
  86. active_side->sticky_web_done = 0;
  87. active_side->toxic_spikes_done = 0;
  88. active_side->lunardance_done = 0;
  89. return;
  90. }