No Description

battle_help.c 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #include <battle_help.h>
  2. //from kds emerald battle engine upgrade
  3. u8 type_effectiveness_table[TYPE_FAIRY - 0x4][TYPE_FAIRY - 0x4] = {
  4. {10, 10, 10, 10, 10, 05, 10, 00, 05, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10}, //normal
  5. {20, 10, 05, 05, 10, 20, 05, 00, 20, 10, 10, 10, 10, 10, 05, 20, 10, 20, 05}, //fight
  6. {10, 20, 10, 10, 10, 05, 20, 10, 05, 10, 10, 10, 20, 05, 10, 10, 10, 10, 10}, //flying
  7. {10, 10, 10, 05, 05, 05, 10, 05, 00, 10, 10, 10, 20, 10, 10, 10, 10, 10, 20}, //poison
  8. {10, 10, 00, 20, 10, 20, 05, 10, 20, 10, 20, 10, 05, 20, 10, 10, 10, 10, 10}, //ground
  9. {10, 05, 20, 10, 05, 10, 20, 10, 05, 10, 20, 10, 10, 10, 10, 20, 10, 10, 10}, //rock
  10. {10, 05, 05, 05, 10, 10, 10, 05, 05, 10, 05, 10, 20, 10, 20, 10, 10, 20, 05}, //bug
  11. {00, 10, 10, 10, 10, 10, 10, 20, 10, 10, 10, 10, 10, 10, 20, 10, 10, 05, 10}, //ghost
  12. {10, 10, 10, 10, 10, 20, 10, 10, 05, 10, 05, 05, 10, 05, 10, 20, 10, 10, 20}, //steel
  13. {10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10}, //egg
  14. {10, 10, 10, 10, 10, 05, 20, 10, 20, 10, 05, 05, 20, 10, 10, 20, 05, 10, 10}, //fire
  15. {10, 10, 10, 10, 20, 20, 10, 10, 10, 10, 20, 05, 05, 10, 10, 10, 05, 10, 10}, //water
  16. {10, 10, 05, 05, 20, 20, 05, 10, 05, 10, 05, 20, 05, 10, 10, 10, 05, 10, 10}, //grass
  17. {10, 10, 20, 10, 00, 10, 10, 10, 10, 10, 10, 20, 05, 05, 10, 10, 05, 10, 10}, //electric
  18. {10, 20, 10, 20, 10, 10, 10, 10, 05, 10, 10, 10, 10, 10, 05, 10, 10, 00, 10}, //psychic
  19. {10, 10, 20, 10, 20, 10, 10, 10, 05, 10, 05, 05, 20, 10, 10, 05, 20, 10, 10}, //ice
  20. {10, 10, 10, 10, 10, 10, 10, 10, 05, 10, 10, 10, 10, 10, 10, 10, 20, 10, 00}, //dragon
  21. {10, 05, 10, 10, 10, 10, 10, 20, 10, 10, 10, 10, 10, 10, 20, 10, 10, 05, 05}, //dark
  22. {10, 20, 10, 05, 10, 10, 10, 10, 05, 10, 05, 10, 10, 10, 10, 10, 20, 20, 10} //fairy
  23. };
  24. u16 damage_type_effectiveness_update(u8 attacking_type, u8 defending_type, u8 atk_bank, u8 def_bank, u16 chained_effect, u8 airstatus) {
  25. u8 effect, atype = attacking_type, dtype = defending_type;
  26. if (!chained_effect || atype == TYPE_EGG || dtype == TYPE_EGG)
  27. return chained_effect;
  28. if (atype >= TYPE_FAIRY)
  29. atype = atype - 5;
  30. if (dtype >= TYPE_FAIRY)
  31. dtype = dtype - 5;
  32. effect = type_effectiveness_table[atype][dtype];
  33. if (custom_battle_elements.ptr->various.inverse_battle) {
  34. if (effect == 20) {
  35. effect = 5;
  36. } else if (effect == 5 || effect == 0) {
  37. effect = 20;
  38. }
  39. }
  40. //handle normal / fighting on ghost
  41. if ((((attacking_type == TYPE_NORMAL || attacking_type == TYPE_FIGHTING) && defending_type == TYPE_GHOST && ((battle_participants[def_bank].status2.foresight))) || battle_participants[atk_bank].ability_id == ABILITY_SCRAPPY) && effect == 0) {
  42. effect = 10;
  43. }
  44. //handle other effectiveness changers here
  45. switch (effect) {
  46. case 0:
  47. chained_effect = 0;
  48. break;
  49. case 5:
  50. chained_effect = chained_effect >> 1;
  51. break;
  52. case 20:
  53. chained_effect = chained_effect << 1;
  54. break;
  55. }
  56. return chained_effect;
  57. }
  58. u16 apply_type_effectiveness(u16 chained_effect, u8 move_type, u8 target_bank, u8 atk_bank, u8 airstatus) {
  59. u8 defender_type1 = battle_participants[target_bank].type1;
  60. u8 defender_type2 = battle_participants[target_bank].type2;
  61. //set different types
  62. if (defender_type2 == defender_type1)
  63. defender_type2 = TYPE_EGG;
  64. chained_effect = damage_type_effectiveness_update(move_type, defender_type1, atk_bank, target_bank, chained_effect, airstatus);
  65. chained_effect = damage_type_effectiveness_update(move_type, defender_type2, atk_bank, target_bank, chained_effect, airstatus);
  66. return chained_effect;
  67. }
  68. u16 type_effectiveness_calc(u16 move, u8 move_type, u8 atk_bank, u8 def_bank, u8 effects_handling_and_recording) {
  69. u16 chained_effect = 64;
  70. //TODO: double_type moves
  71. //TODO: get air status
  72. chained_effect = apply_type_effectiveness(chained_effect, move_type, def_bank, atk_bank, 2);
  73. //TODO: save into structs
  74. //TODO: effect_handling_and_recoring
  75. return chained_effect;
  76. }
  77. u8 has_type(u8 bank, u8 type) {
  78. return battle_participants[bank].type1 == type || battle_participants[bank].type2 == type;
  79. }
  80. u8 get_item_effect(u8 bank, u8 check_negating_effects) {
  81. if (check_negating_effects) {
  82. if (battle_participants[bank].ability_id == ABILITY_KLUTZ || custom_battle_elements.ptr->bank_affecting[bank].embargo)
  83. return ITEM_EFFECT_NOEFFECT;
  84. }
  85. if (battle_participants[bank].held_item == ITEM_ENIGMABERRY) {
  86. return battle_enigma_berry[bank].battle_effect_x12;
  87. } else {
  88. return item_get_x12(battle_participants[bank].held_item);
  89. }
  90. }
  91. u8 cant_poison(u8 bank, u8 self_inflicted) { //0 == can poison
  92. //1 == is already poisoned
  93. //2 == has other major condition
  94. //3 == type doesn't allow it
  95. //4 == ability doesn't allow it
  96. //5 == safeguard protection
  97. //8 == misty terrain doesn't allow it !TODO!
  98. if (battle_participants[bank].status.flags.poison || battle_participants[bank].status.flags.toxic_poison)
  99. return 1;
  100. if (battle_participants[bank].status.int_status)
  101. return 2;
  102. if (has_type(bank, TYPE_POISON) || has_type(bank, TYPE_STEEL))
  103. return 3;
  104. if (((battle_participants[bank].ability_id == ABILITY_IMMUNITY || (battle_participants[bank].ability_id == ABILITY_LEAF_GUARD && (battle_weather.flags.sun || battle_weather.flags.permament_sun || battle_weather.flags.harsh_sun)))))
  105. return 4;
  106. if (side_affecting_halfword[get_side_from_bank(bank)].safeguard_on && !self_inflicted)
  107. return 5;
  108. return 0;
  109. }
  110. u8 count_party_pokemon(u8 bank)
  111. {
  112. struct pokemon* poke;
  113. if (get_side_from_bank(bank))
  114. poke = &party_opponent[0];
  115. else
  116. poke = &party_player[0];
  117. u8 usable_pokes = 0;
  118. for (u8 i = 0; i < 6; i ++)
  119. {
  120. if (pokemon_get_attribute(&poke[i], ATTR_CURRENT_HP, 0) != 0 && pokemon_get_attribute(&poke[i], ATTR_IS_EGG, 0) != 1 && pokemon_get_attribute(&poke[i], ATTR_SPECIES, 0) != 0)
  121. usable_pokes++;
  122. }
  123. return usable_pokes;
  124. }