Incidencia #46024

pf_tools.c::pf_attack_possible bug

Abrir Fecha: 2022-11-01 23:09 Última actualización: 2022-11-05 09:40

Informador:
Propietario:
Tipo:
Estado:
Cerrado
Componente:
Prioridad:
5 - Medium
Gravedad:
5 - Medium
Resolución:
Fixed
Fichero:
1

Details

1. Did not incorporate server changes such as UTYF_NEVER_PROTECTS, which results in AI thinking unprotected tiles can't be attacked, and bugs the goto-pathing of dumb clients who must use server side goto. 2. Did not enact the rule that unreachable units inside cities are reachable.

FIXED VERSION is below:

/************************************************************************//**
  Can we attack 'ptile'? At this point, it assumes there are non-allied
  units on the tile.
****************************************************************************/
static inline bool pf_attack_possible(const struct tile *ptile,
                                      enum known_type known,
                                      const struct pf_parameter *param)
{
  bool non_allied_city;
  bool attack_any;

  if (!can_attack_non_native(param->utype)
      && !is_native_tile(param->utype, ptile)) {
    return FALSE;
  }

  if (TILE_KNOWN_SEEN != known) {
    /* We cannot see units, let's assume we can attack. */
    return TRUE;
  }

  non_allied_city = is_non_allied_city_tile(ptile, param->owner);
  attack_any = FALSE;

  unit_list_iterate(ptile->units, punit) {
    /* Any non-hostile unit will fail the whole stack*/
    if (!pplayers_at_war(unit_owner(punit), param->owner)) {
      return FALSE;
    }

    /* Hostile unit reachability test. */
    if (BV_ISSET(param->utype->targets, uclass_index(unit_class_get(punit)))
        || tile_has_native_base(ptile, unit_type_get(punit))
        || non_allied_city) {
      attack_any = TRUE;
    } else if (game.info.unreachable_protects) {
      /* We get here if punit is unreachable to utype */
      if (!utype_has_flag(unit_type_get(punit), UTYF_NEVER_PROTECTS)) {
        return FALSE;
      }
      /* NB: if there are UTYF_NEVER_PROTECTS units on the tile, 'attack_any'
         has to get set TRUE at least once to enable an attack to the tile,
         which is exactly correct behaviour. */
    }
  } unit_list_iterate_end;

  return attack_any;
}

Ticket History (3/4 Histories)

2022-11-01 23:09 Updated by: lexxie9952
  • New Ticket "pf_tools.c::pf_attack_possible bug" created
2022-11-02 10:31 Updated by: cazfi
  • Propietario Update from (Ninguno) to cazfi
  • Resolución Update from Ninguno to Accepted
  • Hito Update from (Ninguno) to 3.1.0 (cerrado)
  • Componente Update from (Ninguno) to General
Comentario

Attached as a patch, so one can see what are the changes made here.

2022-11-05 09:40 Updated by: cazfi
  • Estado Update from Open to Cerrado
  • Resolución Update from Accepted to Fixed

Editar

Please login to add comment to this ticket » Entrar