No Description

battle_initiative.c 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #include <battle_initiative.h>
  2. #include <battle.h>
  3. #include <battle_help.h>
  4. #include <bpre.h>
  5. struct move_info move_table[1024];
  6. u16 get_speed(u8 bank) {
  7. u32 speed = battle_participants[bank].spd << 16;
  8. switch (get_item_effect(bank, 1)) {
  9. case ITEM_EFFECT_IRONBALL:
  10. speed >>= 1;
  11. break;
  12. case ITEM_EFFECT_CHOICESCARF:
  13. speed = (speed * 150) / 100;
  14. break;
  15. case ITEM_EFFECT_QUICKPOWDER:
  16. if (battle_participants[bank].poke_species == POKE_DITTO && !battle_participants[bank].status2.transformed)
  17. speed <<= 1;
  18. break;
  19. }
  20. if (has_ability_effect(bank, 0, 1)) {
  21. u8 weather_effects = weather_abilities_effect();
  22. switch (battle_participants[bank].ability_id) {
  23. case ABILITY_CHLOROPHYLL:
  24. if (weather_effects && (battle_weather.flags.harsh_sun || battle_weather.flags.permament_sun || battle_weather.flags.sun))
  25. speed *= 2;
  26. break;
  27. case ABILITY_SWIFT_SWIM:
  28. if (weather_effects && (battle_weather.flags.rain || battle_weather.flags.downpour || battle_weather.flags.permament_rain || battle_weather.flags.heavy_rain))
  29. speed *= 2;
  30. break;
  31. case ABILITY_SAND_RUSH:
  32. if (weather_effects && (battle_weather.flags.sandstorm || battle_weather.flags.permament_sandstorm))
  33. speed *= 2;
  34. break;
  35. case ABILITY_QUICK_FEET:
  36. if (battle_participants[bank].status.flags.burn || battle_participants[bank].status.flags.poison || battle_participants[bank].status.flags.toxic_poison)
  37. speed = speed + ((speed * 50) / 100);
  38. else if (battle_participants[bank].status.flags.paralysis) {
  39. //cancel para
  40. speed *= 4;
  41. speed = speed + ((speed * 50) / 100);
  42. }
  43. break;
  44. }
  45. }
  46. if (battle_participants[bank].status.flags.paralysis)
  47. speed >>= 2;
  48. if (custom_battle_elements.ptr->side_affecting[get_side_from_bank(bank)].tailwind)
  49. speed *= 2;
  50. //TODO: unburden
  51. speed = (speed * stat_buffs[battle_participants[bank].spd_buff].dividend) / (stat_buffs[battle_participants[bank].spd_buff].divisor);
  52. return (u16) (speed >> 16);
  53. }
  54. u8 speed_alt_from_item(u8 bank, u8 item_effect) {
  55. switch (item_effect) {
  56. case ITEM_EFFECT_QUICKCLAW:
  57. if (__aeabi_uidivmod(battle_turn_random, 100) > item_get_quality(battle_participants[bank].held_item)) {
  58. return 1;
  59. }
  60. break;
  61. case ITEM_EFFECT_CUSTAPBERRY:
  62. //TODO: implement HP CONDITION
  63. return 1;
  64. break;
  65. case ITEM_EFFECT_LAGGINGTAIL:
  66. return -1;
  67. }
  68. return 0;
  69. }
  70. enum init_enum get_first_to_strike(u8 bank_one, u8 bank_two, u8 ignore_prio) {
  71. enum init_enum result = TIE;
  72. u8 quash_one = custom_battle_elements.ptr->bank_affecting[bank_one].quashed;
  73. u8 quash_two = custom_battle_elements.ptr->bank_affecting[bank_two].quashed;
  74. if (quash_one && !quash_two)
  75. result = TWO;
  76. else if (!quash_one && quash_two)
  77. result = ONE;
  78. else if (!ignore_prio) {
  79. u16 move_one = battle_participants[bank_one].moves[battle_stuff_ptr.ptr->chosen_move_position[bank_one]];
  80. u16 move_two = battle_participants[bank_two].moves[battle_stuff_ptr.ptr->chosen_move_position[bank_two]];
  81. s8 prio_one = 0;
  82. s8 prio_two = 0;
  83. //note priority changing effects and abilities not added as of yet
  84. if (battle_menu_chosen_item[bank_one] == 0)
  85. prio_one = move_table[move_one].priority;
  86. if (battle_menu_chosen_item[bank_two] == 0)
  87. prio_two = move_table[move_two].priority;
  88. if (prio_one > prio_two)
  89. result = ONE;
  90. else if (prio_two > prio_one)
  91. result = TWO;
  92. }
  93. if (result == TIE) {
  94. s8 brack_one = speed_alt_from_item(bank_one, get_item_effect(bank_one, true));
  95. s8 brack_two = speed_alt_from_item(bank_two, get_item_effect(bank_two, true));
  96. if (brack_one > brack_two)
  97. result = ONE;
  98. else if (brack_two > brack_one)
  99. result = TWO;
  100. else {
  101. u8 stall_one = has_ability(bank_one, ABILITY_STALL);
  102. u8 stall_two = has_ability(bank_two, ABILITY_STALL);
  103. if (stall_one && !stall_two)
  104. result = TWO;
  105. else if (stall_two && !stall_one)
  106. result = ONE;
  107. else {
  108. u16 speed_one = get_speed(bank_one);
  109. u16 speed_two = get_speed(bank_two);
  110. if (custom_battle_elements.ptr->field_affecting.trick_room || (stall_one && stall_two)) {
  111. u16 swap_speed = speed_one;
  112. speed_one = speed_two;
  113. speed_two = swap_speed;
  114. }
  115. if (speed_one > speed_two)
  116. result = ONE;
  117. else if (speed_two > speed_one)
  118. result = TWO;
  119. else if (random() & 1)
  120. result = ONE;
  121. }
  122. }
  123. }
  124. return result;
  125. }