暂无描述

battle_initiative.c 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 battle_initiative.c
  24. * @author Sturmvogel
  25. * @date 15 dec 2016
  26. * @brief Methods calculating speed based stats in-battle
  27. */
  28. /* === INCLUDE === */
  29. #include <battle_initiative.h>
  30. #include <pkmn_item_effects.h>
  31. #include <pokemon.h>
  32. #include <battle_help.h>
  33. #include <pkmn_abilities.h>
  34. #include <math.h>
  35. #include <battle_common.h>
  36. #include <battle_abilities.h>
  37. #include <battle_structs.h>
  38. #include <battle_locations.h>
  39. #include <battle_custom_structs.h>
  40. #include <battle_fractions.h>
  41. /* === EXTERN STRUCTS === */
  42. struct move_info move_table[1024];
  43. /* === IMPLEMENTATIONS === */
  44. u16 get_speed(u8 bank) {
  45. u32 speed = battle_participants[bank].spd << 16;
  46. switch (battle_item_get_effect(bank, 1)) {
  47. case ITEM_EFFECT_IRONBALL:
  48. speed >>= 1;
  49. break;
  50. case ITEM_EFFECT_CHOICESCARF:
  51. speed = (speed * 150) / 100;
  52. break;
  53. case ITEM_EFFECT_QUICKPOWDER:
  54. if (battle_participants[bank].poke_species == POKE_DITTO && !battle_participants[bank].status2.transformed)
  55. speed <<= 1;
  56. break;
  57. }
  58. if (ability_has_effect(bank, 0, 1)) {
  59. u8 weather_effects = ability_weather_effects();
  60. switch (battle_participants[bank].ability_id) {
  61. case ABILITY_CHLOROPHYLL:
  62. if (weather_effects && (battle_weather.flags.harsh_sun || battle_weather.flags.permament_sun || battle_weather.flags.sun))
  63. speed *= 2;
  64. break;
  65. case ABILITY_SWIFT_SWIM:
  66. if (weather_effects && (battle_weather.flags.rain || battle_weather.flags.downpour || battle_weather.flags.permament_rain || battle_weather.flags.heavy_rain))
  67. speed *= 2;
  68. break;
  69. case ABILITY_SAND_RUSH:
  70. if (weather_effects && (battle_weather.flags.sandstorm || battle_weather.flags.permament_sandstorm))
  71. speed *= 2;
  72. break;
  73. case ABILITY_QUICK_FEET:
  74. if (battle_participants[bank].status.flags.burn || battle_participants[bank].status.flags.poison || battle_participants[bank].status.flags.toxic_poison)
  75. speed = speed + ((speed * 50) / 100);
  76. else if (battle_participants[bank].status.flags.paralysis) {
  77. /* cancel para */
  78. speed *= 4;
  79. speed = speed + ((speed * 50) / 100);
  80. }
  81. break;
  82. }
  83. }
  84. if (battle_participants[bank].status.flags.paralysis)
  85. speed >>= 2;
  86. if (custom_battle_elements.ptr->side_affecting[get_side_from_bank(bank)].tailwind)
  87. speed *= 2;
  88. if (battle_status_3[bank].unburden)
  89. speed *= 2;
  90. //TODO: /* SWAMP EFFECT */
  91. speed = (speed * stat_buffs[battle_participants[bank].spd_buff].dividend) / (stat_buffs[battle_participants[bank].spd_buff].divisor);
  92. return (u16) (speed >> 16);
  93. }
  94. u8 speed_alt_from_item(u8 bank, u8 item_effect) {
  95. switch (item_effect) {
  96. case ITEM_EFFECT_QUICKCLAW:
  97. if ((battle_turn_random % 100) > item_get_quality(battle_participants[bank].held_item)) {
  98. return 1;
  99. }
  100. break;
  101. case ITEM_EFFECT_CUSTAPBERRY:
  102. //TODO: implement HP CONDITION
  103. return 1;
  104. break;
  105. case ITEM_EFFECT_LAGGINGTAIL:
  106. return -1;
  107. }
  108. return 0;
  109. }
  110. enum init_enum get_first_to_strike(u8 bank_one, u8 bank_two, u8 ignore_prio) {
  111. enum init_enum result = TIE;
  112. u8 quash_one = custom_battle_elements.ptr->bank_affecting[bank_one].quashed;
  113. u8 quash_two = custom_battle_elements.ptr->bank_affecting[bank_two].quashed;
  114. if (quash_one && !quash_two)
  115. result = TWO;
  116. else if (!quash_one && quash_two)
  117. result = ONE;
  118. else if (!ignore_prio) {
  119. u16 move_one = battle_participants[bank_one].moves[battle_stuff_ptr.ptr->chosen_move_position[bank_one]];
  120. u16 move_two = battle_participants[bank_two].moves[battle_stuff_ptr.ptr->chosen_move_position[bank_two]];
  121. s8 prio_one = 0;
  122. s8 prio_two = 0;
  123. /* note priority changing effects and abilities not added as of yet */
  124. /* NOTE: !HANDLE PRIORITY LIKE A PROPERTY! */
  125. if (battle_menu_chosen_item[bank_one] == 0)
  126. prio_one = move_table[move_one].priority;
  127. if (battle_menu_chosen_item[bank_two] == 0)
  128. prio_two = move_table[move_two].priority;
  129. if (prio_one > prio_two)
  130. result = ONE;
  131. else if (prio_two > prio_one)
  132. result = TWO;
  133. }
  134. if (result == TIE) {
  135. s8 brack_one = speed_alt_from_item(bank_one, battle_item_get_effect(bank_one, true));
  136. s8 brack_two = speed_alt_from_item(bank_two, battle_item_get_effect(bank_two, true));
  137. if (brack_one > brack_two)
  138. result = ONE;
  139. else if (brack_two > brack_one)
  140. result = TWO;
  141. else {
  142. u8 stall_one = ability_has_ability(bank_one, ABILITY_STALL);
  143. u8 stall_two = ability_has_ability(bank_two, ABILITY_STALL);
  144. if (stall_one && !stall_two)
  145. result = TWO;
  146. else if (stall_two && !stall_one)
  147. result = ONE;
  148. else {
  149. u16 speed_one = get_speed(bank_one);
  150. u16 speed_two = get_speed(bank_two);
  151. if (custom_battle_elements.ptr->field_affecting.trick_room || (stall_one && stall_two)) {
  152. u16 swap_speed = speed_one;
  153. speed_one = speed_two;
  154. speed_two = swap_speed;
  155. }
  156. if (speed_one > speed_two)
  157. result = ONE;
  158. else if (speed_two > speed_one)
  159. result = TWO;
  160. else if (random() & 1)
  161. result = ONE;
  162. }
  163. }
  164. }
  165. return result;
  166. }