No Description

entry_hazards.c 4.8KB

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