No Description

entry_hazards.c 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #include <battle_help.h>
  2. #include <bpre.h>
  3. extern void* bs_stealth_rock;
  4. extern void* bs_toxic_spikes;
  5. extern void* bs_toxic_spikes_bad;
  6. extern void* bs_sticky_web;
  7. extern void* bs_toxic_resolve;
  8. extern void* bs_spikes_lain;
  9. extern void* bs_rocks_lain;
  10. extern void* bs_toxic_lain;
  11. extern void* bs_sticky_lain;
  12. u8 execute_entry_hazards() {
  13. u8 active_side = get_side_from_bank(battle_active_bank);
  14. u8 has_effect = 0;
  15. struct side_affecting* active_side_affecting = &custom_battle_elements.ptr->side_affecting[active_side];
  16. if (side_affecting_halfword[active_side].spikes_on && !(side_affecting_halfword[active_side].spikes_damage_done)) {
  17. //spikes lay down, deal spiky damage
  18. u32 damage = (battle_participants[battle_active_bank].max_hp) / ((5 - battle_side_timers[active_side].spikes_amount) * 2);
  19. if (damage == 0)
  20. damage = 1;
  21. battle_damage_store = damage;
  22. side_affecting_halfword[active_side].spikes_damage_done = 1;
  23. battle_script_push();
  24. battlescript_cursor = (void*) (0x081D8CBE);
  25. has_effect = 1;
  26. } else if (active_side_affecting->stealth_rock && !(active_side_affecting->stealth_rock_done)) {
  27. active_side_affecting->stealth_rock_done = 1;
  28. //check for magic guard here
  29. u32 damage = battle_participants[battle_active_bank].max_hp;
  30. switch (type_effectiveness_calc(MOVE_STEALTH_ROCK, TYPE_ROCK, battle_active_bank^1, battle_active_bank, 0) >> 4) {
  31. case 1:
  32. damage = damage >> 5;
  33. break;
  34. case 2:
  35. damage = damage >> 4;
  36. break;
  37. case 4:
  38. damage = damage >> 3;
  39. break;
  40. case 8:
  41. damage = damage >> 2;
  42. break;
  43. case 16:
  44. damage = damage >> 1;
  45. break;
  46. }
  47. if (damage == 0)
  48. damage = 1;
  49. battle_damage_store = damage;
  50. battle_script_push();
  51. battlescript_cursor = bs_stealth_rock;
  52. has_effect = 1;
  53. } else if (active_side_affecting->toxic_spikes_psn && !(active_side_affecting->toxic_spikes_done)) {
  54. active_side_affecting->toxic_spikes_done = 1;
  55. if (has_type(battle_active_bank, TYPE_POISON)) {
  56. has_effect = 1;
  57. active_side_affecting->toxic_spikes_psn = 0;
  58. active_side_affecting->toxic_spikes_badpsn = 0;
  59. battle_script_push();
  60. battlescript_cursor = bs_toxic_resolve;
  61. } else if (!cant_poison(battle_active_bank, 0)) {
  62. if (active_side_affecting->toxic_spikes_badpsn) {
  63. battle_participants[battle_active_bank].status.flags.toxic_poison = 1;
  64. battle_script_push();
  65. battlescript_cursor = bs_toxic_spikes_bad;
  66. }
  67. else {
  68. battle_participants[battle_active_bank].status.flags.poison = 1;
  69. battle_script_push();
  70. battlescript_cursor = bs_toxic_spikes;
  71. }
  72. prepare_setattributes_in_battle(0, REQUEST_STATUS_BATTLE, 0, 4, &battle_participants[battle_active_bank].status.flags);
  73. mark_buffer_bank_for_execution(battle_active_bank);
  74. has_effect = 1;
  75. }
  76. } else if (active_side_affecting->sticky_web && !(active_side_affecting->sticky_web_done) && battle_participants[battle_active_bank].spd_buff != 0) {
  77. active_side_affecting->sticky_web_done = 1;
  78. battle_script_push();
  79. battlescript_cursor = bs_sticky_web;
  80. battle_stat_changer = 0x93;
  81. has_effect = 1;
  82. }
  83. if (has_effect) {
  84. custom_battle_elements.ptr->various.var1 = battle_active_bank;
  85. battle_participants[battle_active_bank].status2.destinny_bond = 0;
  86. battle_hitmarker &= 0xFFFFFFBF;
  87. }
  88. return has_effect;
  89. }
  90. u8 lay_entry_hazards() {
  91. u8 target_side = get_side_from_bank(battle_defender_bank);
  92. u8 fail = 0;
  93. struct side_affecting* target_side_struct = &custom_battle_elements.ptr->side_affecting[target_side];
  94. switch (battle_executed_move) {
  95. case MOVE_SPIKES:
  96. if (battle_side_timers[target_side].spikes_amount < 3) {
  97. battle_side_timers[target_side].spikes_amount++;
  98. side_affecting_halfword[target_side].spikes_on = 1;
  99. battlescript_cursor = bs_spikes_lain;
  100. } else {
  101. fail = 1;
  102. }
  103. break;
  104. case MOVE_STEALTH_ROCK:
  105. if (target_side_struct->stealth_rock == 0) {
  106. target_side_struct->stealth_rock = 1;
  107. battlescript_cursor = bs_rocks_lain;
  108. } else
  109. fail = 1;
  110. break;
  111. case MOVE_TOXIC_SPIKES:
  112. if (target_side_struct->toxic_spikes_psn == 0) {
  113. target_side_struct->toxic_spikes_psn = 1;
  114. battlescript_cursor = bs_toxic_lain;
  115. } else if (target_side_struct->toxic_spikes_badpsn == 0) {
  116. target_side_struct->toxic_spikes_badpsn = 1;
  117. battlescript_cursor = bs_toxic_lain;
  118. } else
  119. fail = 1;
  120. break;
  121. case MOVE_STICKY_WEB:
  122. if (target_side_struct->sticky_web == 0) {
  123. target_side_struct->sticky_web = 1;
  124. battlescript_cursor = bs_sticky_lain;
  125. } else
  126. fail = 1;
  127. break;
  128. default:
  129. fail = 1;
  130. break;
  131. }
  132. if (fail) {
  133. //failed execution
  134. battlescript_cursor = (void*) (0x081D7DF0);
  135. }
  136. return 1;
  137. }