Ingen beskrivning

battle_initiative.c 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. {
  40. //cancel para
  41. speed *= 4;
  42. speed = speed + ((speed * 50) / 100);
  43. }
  44. break;
  45. }
  46. }
  47. if (battle_participants[bank].status.flags.paralysis)
  48. speed >>= 2;
  49. if (custom_battle_elements.ptr->side_affecting[get_side_from_bank(bank)].tailwind)
  50. speed *= 2;
  51. //TODO: unburden
  52. speed = (speed * stat_buffs[battle_participants[bank].spd_buff].dividend) / (stat_buffs[battle_participants[bank].spd_buff].divisor);
  53. return (u16)(speed >> 16);
  54. }
  55. enum init_enum get_first_to_strike(u8 bank_one, u8 bank_two, u8 ignore_prio) {
  56. enum init_enum result = TIE;
  57. //TODO: implement quash
  58. if (!ignore_prio) {
  59. u16 move_one = battle_participants[bank_one].moves[battle_stuff_ptr.ptr->chosen_move_position[bank_one]];
  60. u16 move_two = battle_participants[bank_two].moves[battle_stuff_ptr.ptr->chosen_move_position[bank_two]];
  61. s8 prio_one = 0;
  62. s8 prio_two = 0;
  63. //note priority changing effects and abilities not added as of yet
  64. if (battle_menu_chosen_item[bank_one] == 0)
  65. prio_one = move_table[move_one].priority;
  66. if (battle_menu_chosen_item[bank_two] == 0)
  67. prio_two = move_table[move_two].priority;
  68. if (prio_one > prio_two)
  69. result = ONE;
  70. else if (prio_two > prio_one)
  71. result = TWO;
  72. }
  73. if (result == TIE) {
  74. //TODO: calculate item bracket effects
  75. //TODO: calculate speed
  76. u8 stall_one = has_ability(bank_one, ABILITY_STALL);
  77. u8 stall_two = has_ability(bank_two, ABILITY_STALL);
  78. if (stall_one && !stall_two)
  79. result = TWO;
  80. else if (stall_two && !stall_one)
  81. result = ONE;
  82. else {
  83. u16 speed_one = get_speed(bank_one);
  84. u16 speed_two = get_speed(bank_two);
  85. if (custom_battle_elements.ptr->field_affecting.trick_room || (stall_one && stall_two)) {
  86. u16 swap_speed = speed_one;
  87. speed_one = speed_two;
  88. speed_two = swap_speed;
  89. }
  90. if (speed_one > speed_two)
  91. result = ONE;
  92. else if (speed_two > speed_one)
  93. result = TWO;
  94. else if (random() & 1)
  95. result = ONE;
  96. }
  97. }
  98. return result;
  99. }