No Description

custom_structs_malloc.c 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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_custom_structs.h>
  30. #include <game_engine.h>
  31. #include <memory.h>
  32. #include <moves.h>
  33. #include <battle_common.h>
  34. #include <battle_locations.h>
  35. /* === PROTOTYPES === */
  36. /**
  37. * @brief allocate the new battle struct memory
  38. */
  39. void malloc_battle_structs();
  40. /**
  41. * @brief free the new battle struct memory
  42. */
  43. void free_battle_structs();
  44. /**
  45. * @brief handle switch in uptates on structures
  46. */
  47. void battle_switch_in();
  48. /* === IMPLEMENTATIONS === */
  49. void malloc_battle_structs()
  50. {
  51. custom_battle_elements.ptr=(struct custom_battle_struct*)malloc(sizeof(struct custom_battle_struct));
  52. }
  53. void free_battle_structs()
  54. {
  55. free(custom_battle_elements.ptr);
  56. custom_battle_elements.ptr=0;
  57. }
  58. //hijack switch in command, clean up battle structs and carry over baton pass
  59. void battle_switch_in()
  60. {
  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. {
  70. current_bank_affecting->aqua_ring = prev_bank_affecting.aqua_ring;
  71. current_bank_affecting->embargo = prev_bank_affecting.embargo;
  72. current_bank_affecting->powertrick = prev_bank_affecting.powertrick;
  73. current_bank_affecting->gastro_acided = prev_bank_affecting.gastro_acided;
  74. current_bank_affecting->heal_block = prev_bank_affecting.heal_block;
  75. if(prev_bank_affecting.powertrick)
  76. {
  77. //carry over switched stats of power trick
  78. u16 *atk = &battle_participants[battle_active_bank].atk;
  79. u16 *def = &battle_participants[battle_active_bank].def;
  80. u16 switch_var = *atk;
  81. *atk = *def;
  82. *def = switch_var;
  83. }
  84. }
  85. struct side_affecting* active_side = &custom_battle_elements.ptr->side_affecting[get_side_from_bank(battle_active_bank)];
  86. active_side->stealth_rock_done = 0;
  87. active_side->sticky_web_done = 0;
  88. active_side->toxic_spikes_done = 0;
  89. active_side->lunardance_done = 0;
  90. return;
  91. }