Praytic/youtd2

Range check for tower attacks is off by 8

Closed this issue · 1 comments

Observations:

  • a lot of range checks (one per creep I assume) when creeps out of range - would the same apply for every tower * every creep?

range_checks2

  • when in range - checks are much more rare (when attack is ready). I get that it is known and optimized specifically for bonus round when towers almost always have attacks on cooldowns
  • however, we get one check with 772 range - most likely missing +8 from RANGE_CHECK_BONUS_FOR_OTHER_UNITS

Zrzut ekranu 2024-10-11 225219

  • same for this boss

Zrzut ekranu 2024-10-11 225354

  • we get some checks that would allow the boss to be attacked (distance 777) range: 780 from code (tower.gd):
    var creeps_in_range: Array = Utils.get_units_in_range(self, _attack_target_type, get_position_wc3_2d(), attack_range)
  • and other one that does not (distance 772) in tower.gd too:
    'var target_is_valid: bool = _target_is_valid(new_target)'

Zrzut ekranu 2024-10-11 225449

  • and then checks get less frequent but still 780 and 772:

Zrzut ekranu 2024-10-11 225548

My initial idea would be to fix _target_is_valid in tower.gd by adding:
attack_range = Utils.apply_unit_range_extension(attack_range, _attack_target_type)

From these notes, I mainly see that Tower._update_target_list() has a bug about RANGE_CHECK_BONUS_FOR_OTHER_UNITS.

  1. It calls Utils.get_units_in_range() which adds RANGE_CHECK_BONUS_FOR_OTHER_UNITS
  2. It also calls _target_is_valid() which does NOT add RANGE_CHECK_BONUS_FOR_OTHER_UNITS

I can confirm, current behavior is incorrect.

This fix is fine:

My initial idea would be to fix _target_is_valid in tower.gd by adding:
attack_range = Utils.apply_unit_range_extension(attack_range, _attack_target_type)