Project

General

Profile

Feature #2377 ยป 0080-daiait.c-Replace-NULL-with-nullptr.patch

Marko Lindqvist, 10/17/2026 10:54 AM

View differences:

ai/default/daiair.c
/******************************************************************//**
Looks for nearest airbase for punit reachable immediately.
Returns NULL if not found. The path is stored in the path
argument if not NULL.
Returns nullptr if not found. The path is stored in the path
argument if not nullptr.
If the unit is damaged, flies to an airbase that can repair
the unit in a minimal number of turns.
FIXME: consider airdrome safety. Can lure enemy bombers
......
struct player *pplayer = unit_owner(punit);
struct pf_parameter parameter;
struct pf_map *pfm;
struct tile *best = NULL;
struct tile *best = nullptr;
int lost_hp = unit_type_get(punit)->hp - punit->hp;
int best_regt = FC_INFINITY;
const struct civ_map *nmap = &(wld.map);
......
#define PROB_MULTIPLIER 100 /* Should unify with those in combat.c */
if (!can_unit_attack_tile(punit, NULL, dst_tile)
|| !(pdefender = get_defender(nmap, punit, dst_tile, NULL))) {
if (!can_unit_attack_tile(punit, nullptr, dst_tile)
|| !(pdefender = get_defender(nmap, punit, dst_tile, nullptr))) {
return 0;
}
......
}
unit_attack = (int) (PROB_MULTIPLIER
* unit_win_chance(nmap, punit, pdefender, NULL));
* unit_win_chance(nmap, punit, pdefender, nullptr));
victim_defense = PROB_MULTIPLIER - unit_attack;
......
Find something to bomb
Air-units specific victim search
Returns the want for the best target. The targets are stored in the
path and pptile arguments if not NULL.
path and pptile arguments if not nullptr.
TODO: take counterattack dangers into account
TODO: make separate handicaps for air units seeing targets
IMO should be more restrictive than general H_MAP, H_FOG
......
struct player *pplayer = unit_owner(punit);
struct pf_parameter parameter;
struct pf_map *pfm;
struct tile *best_tile = NULL;
struct tile *best_tile = nullptr;
adv_want best = 0;
pft_fill_unit_parameter(&parameter, nmap, punit);
......
if (is_enemy_unit_tile(ptile, pplayer)
&& dai_should_we_air_attack_tile(ait, punit, ptile)
&& can_unit_attack_tile(punit, NULL, ptile)) {
&& can_unit_attack_tile(punit, nullptr, ptile)) {
adv_want new_best = dai_evaluate_tile_for_air_attack(nmap, punit,
ptile);
......
*pptile = best_tile;
}
if (path) {
*path = best_tile ? pf_map_path(pfm, best_tile) : NULL;
*path = best_tile ? pf_map_path(pfm, best_tile) : nullptr;
}
pf_map_destroy(pfm);
......
/******************************************************************//**
Iterates through reachable refuel points and appraises them
as a possible base for air operations by (air)unit punit.
Returns NULL if not found (or we just should stay here).
The path is stored in the path argument if not NULL.
Returns nullptr if not found (or we just should stay here).
The path is stored in the path argument if not nullptr.
1. If the unit is damaged, looks for the fastest full regeneration.
(Should we set the unit task to AIUNIT_RECOVER? Currently, no gain)
2. Goes to the nearest city that needs a defender immediately.
......
struct player *pplayer = unit_owner(punit);
struct pf_parameter parameter;
struct pf_map *pfm;
struct tile *best_tile = NULL;
struct tile *best_tile = nullptr;
struct city *pcity;
struct unit *pvirtual = NULL;
struct unit *pvirtual = nullptr;
adv_want best_worth = 0, target_worth;
int lost_hp = unit_type_get(punit)->hp - punit->hp;
int regen_turns_min = FC_INFINITY;
......
log_debug("Repairment of %s is almost finished, stays here",
unit_rule_name(punit));
def_ai_unit_data(punit, ait)->done = TRUE;
return NULL;
return nullptr;
} else {
regen_turns_min = 0;
}
......
if (lost_hp <= 0 || regen_turns_min <= 1) {
log_debug("%s stays defending %s",
unit_rule_name(punit), city_name_get(pcity));
return NULL;
return nullptr;
} else {
/* We may find a city in grave danger that restores faster */
defend = TRUE;
......
unit_tile_set(pvirtual, unit_tile(punit));
start_worth = find_something_to_bomb(ait, nmap, pvirtual,
NULL, NULL);
nullptr, nullptr);
best_worth = MAX(start_worth, 0);
}
}
unit_tile_set(pvirtual, ptile);
target_worth = find_something_to_bomb(ait, nmap, pvirtual, NULL, NULL);
target_worth = find_something_to_bomb(ait, nmap, pvirtual, nullptr, nullptr);
if (target_worth > best_worth) {
/* It's either a first find or it's better than the previous. */
best_worth = target_worth;
......
if (path) {
/* Stores the path. */
*path = best_tile ? pf_map_path(pfm, best_tile) : NULL;
*path = best_tile ? pf_map_path(pfm, best_tile) : nullptr;
}
pf_map_destroy(pfm);
......
/* We are out in the open, what shall we do? */
if (punit->activity == ACTIVITY_GOTO
/* We are on a GOTO. Check if it will get us anywhere */
&& NULL != punit->goto_tile
&& punit->goto_tile != nullptr
&& !same_pos(unit_tile(punit), punit->goto_tile)
&& is_refuel_point(punit->goto_tile, pplayer, punit)) {
pft_fill_unit_parameter(&parameter, nmap, punit);
......
if (find_something_to_bomb(ait, nmap, punit, &path, &dst_tile) > 0) {
/* Found target, coordinates are in punit's goto_dest.
* TODO: separate attacking into a function, check for the best
* TODO: Separate attacking into a function, check for the best
* tile to attack from */
fc_assert_ret(path != NULL && dst_tile != NULL);
fc_assert_ret(path != nullptr && dst_tile != nullptr);
if (!adv_follow_path(punit, path, dst_tile)) {
pf_path_destroy(path);
return; /* The unit died. */
......
}
}
if ((punit = game_unit_by_number(id)) != NULL && punit->moves_left > 0
if ((punit = game_unit_by_number(id)) != nullptr && punit->moves_left > 0
&& punit->moves_left != moves) {
/* We have moved this turn, might have ended up stuck out in the fields
* so, as a safety measure, let's manage again */
......
pplayer, pcity, punittype,
city_production_unit_veteran_level(pcity, punittype));
adv_want profit = find_something_to_bomb(ait, nmap, virtual_unit,
NULL, NULL);
nullptr, nullptr);
if (profit > choice->want) {
/* Update choice */
    (1-1/1)