Feature #1535 ยป 0085-unithand.c-Improve-coding-style.patch
server/unithand.c | ||
---|---|---|
struct action *paction = action_by_number(ACTION_UPGRADE_UNIT);
|
||
const struct civ_map *nmap = &(wld.map);
|
||
if (NULL == from_unittype) {
|
||
if (from_unittype == nullptr) {
|
||
/* Probably died or bribed. */
|
||
log_verbose("handle_unit_type_upgrade() invalid unit type %d", uti);
|
||
return;
|
||
... | ... | |
to_unittype = can_upgrade_unittype(pplayer, from_unittype);
|
||
if (!to_unittype) {
|
||
notify_player(pplayer, NULL, E_BAD_COMMAND, ftc_server,
|
||
notify_player(pplayer, nullptr, E_BAD_COMMAND, ftc_server,
|
||
_("Illegal packet, can't upgrade %s (yet)."),
|
||
utype_name_translation(from_unittype));
|
||
return;
|
||
}
|
||
/*
|
||
/*
|
||
* Try to upgrade units. The order we upgrade in is arbitrary (if
|
||
* the player really cared they should have done it manually).
|
||
* the player really cared they should have done it manually).
|
||
*/
|
||
conn_list_do_buffer(pplayer->connections);
|
||
unit_list_iterate(pplayer->units, punit) {
|
||
... | ... | |
/* Alert the player about what happened. */
|
||
if (number_of_upgraded_units > 0) {
|
||
const int cost = unit_upgrade_price(pplayer, from_unittype, to_unittype);
|
||
notify_player(pplayer, NULL, E_UNIT_UPGRADED, ftc_server,
|
||
notify_player(pplayer, nullptr, E_UNIT_UPGRADED, ftc_server,
|
||
/* FIXME: plurality of number_of_upgraded_units ignored!
|
||
* (Plurality of unit names is messed up anyway.) */
|
||
/* TRANS: "2 Musketeers upgraded to Riflemen for 100 gold."
|
||
... | ... | |
cost * number_of_upgraded_units);
|
||
send_player_info_c(pplayer, pplayer->connections);
|
||
} else {
|
||
notify_player(pplayer, NULL, E_UNIT_UPGRADED, ftc_server,
|
||
notify_player(pplayer, nullptr, E_UNIT_UPGRADED, ftc_server,
|
||
_("No units could be upgraded."));
|
||
}
|
||
}
|
||
... | ... | |
struct player *uplayer;
|
||
const char *victim_link;
|
||
const struct unit_type *utype;
|
||
struct tile *ptile = NULL;
|
||
struct tile *ptile = nullptr;
|
||
bool really_lost = FALSE;
|
||
if (!to_capture) {
|
||
... | ... | |
_("%s lost along with control of %s."),
|
||
victim_link, hcity_name);
|
||
/* As in unit_change_owner(), don't say pplayer is killer */
|
||
wipe_unit(to_capture, ULR_CAPTURED, NULL);
|
||
wipe_unit(to_capture, ULR_CAPTURED, nullptr);
|
||
continue;
|
||
}
|
||
if (to_capture != NULL) {
|
||
if (to_capture != nullptr) {
|
||
struct player *new_owner = unit_owner(to_capture);
|
||
if (NULL != pcity /* Keep old behavior */
|
||
if (pcity != nullptr /* Keep old behavior */
|
||
|| is_non_allied_city_tile(ptile, new_owner)
|
||
|| (new_owner == pplayer
|
||
? non_allied_not_listed_at(pplayer, capt + (i + 1),
|
||
... | ... | |
unit_did_action(punit);
|
||
unit_forget_last_activity(punit);
|
||
send_unit_info(NULL, punit);
|
||
send_unit_info(nullptr, punit);
|
||
return TRUE;
|
||
}
|
||
... | ... | |
punit->moves_left = full_moves;
|
||
/* Post attack occupy move. */
|
||
if (NULL != action_auto_perf_unit_do(AAPC_POST_ACTION, punit,
|
||
NULL, NULL, paction,
|
||
def_tile, tile_city(def_tile),
|
||
NULL, NULL)) {
|
||
if (action_auto_perf_unit_do(AAPC_POST_ACTION, punit,
|
||
nullptr, nullptr, paction,
|
||
def_tile, tile_city(def_tile),
|
||
nullptr, nullptr) != nullptr) {
|
||
if (unit_is_alive(id)) {
|
||
int mcost = MAX(0, full_moves - punit->moves_left - SINGLE_MOVE);
|
||
... | ... | |
unit_did_action(punit);
|
||
unit_forget_last_activity(punit);
|
||
send_unit_info(NULL, punit);
|
||
send_unit_info(nullptr, punit);
|
||
}
|
||
return TRUE;
|
||
... | ... | |
/* N.B: unit_link() always returns the same pointer. */
|
||
sz_strlcpy(target_link, unit_link(target));
|
||
if (pcity == NULL) {
|
||
if (pcity == nullptr) {
|
||
/* No where to send the expelled unit. */
|
||
/* The price of failing an expulsion is a single move. */
|
||
actor->moves_left = MAX(0, actor->moves_left - SINGLE_MOVE);
|
||
send_unit_info(NULL, actor);
|
||
send_unit_info(nullptr, actor);
|
||
/* Notify the actor player. */
|
||
notify_player(pplayer, target_tile, E_UNIT_ACTION_FAILED, ftc_server,
|
||
... | ... | |
fc_assert_ret_val(tgt_tile, FALSE);
|
||
unit_move(act_unit, tgt_tile, move_cost,
|
||
NULL, BV_ISSET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK),
|
||
nullptr, BV_ISSET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK),
|
||
FALSE, TRUE,
|
||
BV_ISSET(paction->sub_results, ACT_SUB_RES_HUT_ENTER),
|
||
BV_ISSET(paction->sub_results, ACT_SUB_RES_HUT_FRIGHTEN));
|
||
... | ... | |
/* The max amount of HP that can be added. */
|
||
healing_limit = ((get_target_bonus_effects(
|
||
NULL,
|
||
nullptr,
|
||
&(const struct req_context) {
|
||
.player = unit_owner(act_unit),
|
||
.city = tile_city(unit_tile(act_unit)),
|
||
... | ... | |
/* Heal the target unit. */
|
||
tgt_unit->hp = MIN(tgt_unit->hp + healing_limit, tgt_hp_max);
|
||
send_unit_info(NULL, tgt_unit);
|
||
send_unit_info(nullptr, tgt_unit);
|
||
send_unit_info(NULL, act_unit);
|
||
send_unit_info(nullptr, act_unit);
|
||
/* Every call to unit_link() overwrites the previous. Two units are being
|
||
* linked to. */
|
||
... | ... | |
fc_assert_ret_val(paction, FALSE);
|
||
unit_move(act_unit, tgt_tile, move_cost,
|
||
NULL, BV_ISSET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK),
|
||
nullptr, BV_ISSET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK),
|
||
FALSE, FALSE,
|
||
BV_ISSET(paction->sub_results, ACT_SUB_RES_HUT_ENTER),
|
||
BV_ISSET(paction->sub_results, ACT_SUB_RES_HUT_FRIGHTEN));
|
||
... | ... | |
fc_assert_ret_val(paction, FALSE);
|
||
unit_move(act_unit, tgt_tile, move_cost,
|
||
NULL, BV_ISSET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK),
|
||
nullptr, BV_ISSET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK),
|
||
FALSE, FALSE,
|
||
BV_ISSET(paction->sub_results, ACT_SUB_RES_HUT_ENTER),
|
||
BV_ISSET(paction->sub_results, ACT_SUB_RES_HUT_FRIGHTEN));
|
||
... | ... | |
static bool do_unit_make_homeless(struct unit *punit,
|
||
const struct action *paction)
|
||
{
|
||
unit_change_homecity_handling(punit, NULL, TRUE);
|
||
unit_change_homecity_handling(punit, nullptr, TRUE);
|
||
return punit->homecity == IDENTITY_NUMBER_ZERO;
|
||
}
|
||
... | ... | |
const int,
|
||
const bool))
|
||
{
|
||
if (player2 == NULL) {
|
||
if (player2 == nullptr) {
|
||
/* No one to declare war on */
|
||
return FALSE;
|
||
}
|
||
... | ... | |
const struct city *target_city,
|
||
const struct unit *target_unit)
|
||
{
|
||
struct player *target_player = NULL;
|
||
struct player *target_player = nullptr;
|
||
struct player *actor_player = unit_owner(actor);
|
||
struct action *paction = action_by_number(act);
|
||
fc_assert_ret_val(paction != NULL, NULL);
|
||
fc_assert_ret_val(paction != nullptr, nullptr);
|
||
if (action_id_get_actor_kind(act) != AAK_UNIT) {
|
||
/* No unit can ever do this action so it isn't relevant. */
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
if (!unit_can_do_action(actor, act)) {
|
||
/* The unit can't do the action no matter if there is war or not. */
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
/* Look for hard coded war requirements without support for looking up in
|
||
... | ... | |
fc_assert_action(action_get_target_kind(paction) == ATK_STACK, break);
|
||
if (!unit_has_type_flag(actor, UTYF_FLAGLESS)) {
|
||
if (target_tile != NULL) {
|
||
if (target_tile != nullptr) {
|
||
struct city *tcity;
|
||
if ((tcity = tile_city(target_tile))
|
||
... | ... | |
case ACTRES_PARADROP_CONQUER:
|
||
/* Target is a tile but a city can block it. */
|
||
fc_assert_action(action_get_target_kind(paction) == ATK_TILE, break);
|
||
if (target_tile != NULL
|
||
if (target_tile != nullptr
|
||
&& map_is_known_and_seen(target_tile, actor_player, V_MAIN)) {
|
||
/* Seen tile unit savers */
|
||
... | ... | |
/* Look for war requirements from the action enablers. */
|
||
switch (action_get_target_kind(paction)) {
|
||
case ATK_CITY:
|
||
if (target_city == NULL) {
|
||
if (target_city == nullptr) {
|
||
/* No target city. */
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
target_player = city_owner(target_city);
|
||
break;
|
||
case ATK_UNIT:
|
||
if (target_unit == NULL) {
|
||
if (target_unit == nullptr) {
|
||
/* No target unit. */
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
if (unit_has_type_flag(target_unit, UTYF_FLAGLESS)) {
|
||
/* Target unit is flagless anyway - no war needed */
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
target_player = unit_owner(target_unit);
|
||
break;
|
||
case ATK_STACK:
|
||
if (target_tile == NULL) {
|
||
if (target_tile == nullptr) {
|
||
/* No target units since no target tile. */
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
unit_list_iterate(target_tile->units, tunit) {
|
||
... | ... | |
} unit_list_iterate_end;
|
||
break;
|
||
case ATK_TILE:
|
||
if (target_tile == NULL) {
|
||
if (target_tile == nullptr) {
|
||
/* No target tile. */
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
target_player = tile_owner(target_tile);
|
||
break;
|
||
case ATK_EXTRAS:
|
||
if (target_tile == NULL) {
|
||
if (target_tile == nullptr) {
|
||
/* No target tile. */
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
target_player = target_tile->owner;
|
||
break;
|
||
case ATK_SELF:
|
||
/* Can't declare war on itself. */
|
||
return NULL;
|
||
return nullptr;
|
||
break;
|
||
case ATK_COUNT:
|
||
/* Nothing to check. */
|
||
fc_assert(action_id_get_target_kind(act) != ATK_COUNT);
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
if (target_player == NULL) {
|
||
if (target_player == nullptr) {
|
||
/* Declaring war won't enable the specified action. */
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
/* Look for DiplRelTileOther war requirements from the action enablers. */
|
||
if (target_tile != NULL
|
||
if (target_tile != nullptr
|
||
&& need_war_enabler(unit_type_get(actor), paction,
|
||
actor_player, tile_owner(target_tile),
|
||
utype_can_act_if_tgt_diplrel_tile_other)) {
|
||
... | ... | |
* webperimental's "can't found a city on a tile belonging to a non enemy"
|
||
* rule still is detected. */
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
/**********************************************************************//**
|
||
... | ... | |
target_tile, target_city,
|
||
target_unit);
|
||
if (war_player != NULL) {
|
||
if (war_player != nullptr) {
|
||
/* Declaring war on this player may enable this action. */
|
||
return war_player;
|
||
}
|
||
} action_iterate_end;
|
||
/* No action at all may be enabled by declaring war. */
|
||
return NULL;
|
||
return nullptr;
|
||
} else {
|
||
/* Look for the specified action. */
|
||
return need_war_player_hlp(actor, act_id,
|
||
... | ... | |
const struct action *paction;
|
||
struct action *blocker;
|
||
struct player *act_player = unit_owner(punit);
|
||
struct player *tgt_player = NULL;
|
||
struct player *tgt_player = nullptr;
|
||
struct ane_expl *explnat = fc_malloc(sizeof(struct ane_expl));
|
||
struct civ_map *nmap = &(wld.map);
|
||
bool can_exist = can_unit_exist_at_tile(nmap, punit, unit_tile(punit));
|
||
... | ... | |
/* A specific action should have a suitable target. */
|
||
switch (action_get_target_kind(paction)) {
|
||
case ATK_CITY:
|
||
if (target_city == NULL) {
|
||
if (target_city == nullptr) {
|
||
explnat->kind = ANEK_MISSING_TARGET;
|
||
}
|
||
break;
|
||
case ATK_UNIT:
|
||
if (target_unit == NULL) {
|
||
if (target_unit == nullptr) {
|
||
explnat->kind = ANEK_MISSING_TARGET;
|
||
}
|
||
break;
|
||
case ATK_STACK:
|
||
case ATK_TILE:
|
||
case ATK_EXTRAS:
|
||
if (target_tile == NULL) {
|
||
if (target_tile == nullptr) {
|
||
explnat->kind = ANEK_MISSING_TARGET;
|
||
}
|
||
break;
|
||
... | ... | |
action_custom = unit_upgrade_test(nmap, punit, FALSE);
|
||
break;
|
||
case ACTRES_AIRLIFT:
|
||
action_custom = test_unit_can_airlift_to(nmap, NULL, punit, target_city);
|
||
action_custom = test_unit_can_airlift_to(nmap, nullptr, punit,
|
||
target_city);
|
||
break;
|
||
case ACTRES_NUKE_UNITS:
|
||
action_custom = unit_attack_units_at_tile_result(punit, paction,
|
||
... | ... | |
punit->activity,
|
||
unit_tile(punit),
|
||
city_tile(target_city),
|
||
FALSE, FALSE, NULL, TRUE);
|
||
FALSE, FALSE, nullptr, TRUE);
|
||
} else {
|
||
action_custom = MR_OK;
|
||
}
|
||
... | ... | |
punit->activity,
|
||
unit_tile(punit),
|
||
unit_tile(target_unit),
|
||
FALSE, TRUE, NULL, FALSE);
|
||
FALSE, TRUE, nullptr, FALSE);
|
||
} else {
|
||
action_custom = MR_OK;
|
||
}
|
||
... | ... | |
punit->activity,
|
||
unit_tile(punit),
|
||
target_tile,
|
||
FALSE, FALSE, NULL, FALSE);
|
||
FALSE, FALSE, nullptr, FALSE);
|
||
} else {
|
||
action_custom = MR_OK;
|
||
}
|
||
break;
|
||
case ACTRES_TELEPORT:
|
||
if (target_tile != NULL) {
|
||
if (target_tile != nullptr) {
|
||
action_custom = unit_teleport_to_tile_test(nmap, punit,
|
||
punit->activity,
|
||
unit_tile(punit),
|
||
target_tile,
|
||
FALSE, NULL, FALSE);
|
||
FALSE, nullptr, FALSE);
|
||
} else {
|
||
action_custom = MR_OK;
|
||
}
|
||
... | ... | |
explnat->no_act_terrain = tile_terrain(target_tile);
|
||
} else if ((action_has_result_safe(paction, ACTRES_PARADROP)
|
||
|| action_has_result_safe(paction, ACTRES_PARADROP_CONQUER))
|
||
&& target_tile != NULL
|
||
&& target_tile != nullptr
|
||
&& map_is_known_and_seen(target_tile, act_player,
|
||
V_MAIN)
|
||
&& (!can_unit_exist_at_tile(nmap, punit, target_tile)
|
||
... | ... | |
act_id,
|
||
target_tile,
|
||
target_city,
|
||
target_unit)) != NULL) {
|
||
target_unit)) != nullptr) {
|
||
explnat->kind = ANEK_NO_WAR;
|
||
explnat->no_war_with = must_war_player;
|
||
} else if (action_mp_full_makes_legal(punit, act_id)) {
|
||
explnat->kind = ANEK_LOW_MP;
|
||
} else if (tgt_player != NULL
|
||
} else if (tgt_player != nullptr
|
||
&& act_player != tgt_player
|
||
&& !can_utype_do_act_if_tgt_diplrel(unit_type_get(punit),
|
||
act_id,
|
||
DRO_FOREIGN,
|
||
TRUE)) {
|
||
explnat->kind = ANEK_FOREIGN;
|
||
} else if (tgt_player != NULL
|
||
} else if (tgt_player != nullptr
|
||
&& act_player == tgt_player
|
||
&& !can_utype_do_act_if_tgt_diplrel(unit_type_get(punit),
|
||
act_id,
|
||
DRO_FOREIGN,
|
||
FALSE)) {
|
||
explnat->kind = ANEK_DOMESTIC;
|
||
} else if (punit != NULL
|
||
} else if (punit != nullptr
|
||
&& does_nation_block_action(act_id, FALSE,
|
||
punit, act_player->nation)) {
|
||
explnat->kind = ANEK_NATION_ACT;
|
||
... | ... | |
CITYT_CENTER,
|
||
FALSE)) {
|
||
explnat->kind = ANEK_IS_NOT_CITY_CENTER;
|
||
} else if ((target_tile && tile_owner(target_tile) != NULL)
|
||
} else if ((target_tile && tile_owner(target_tile) != nullptr)
|
||
&& !utype_may_act_tgt_city_tile(unit_type_get(punit),
|
||
act_id,
|
||
CITYT_CLAIMED,
|
||
TRUE)) {
|
||
explnat->kind = ANEK_TGT_IS_CLAIMED;
|
||
} else if ((target_tile && tile_owner(target_tile) == NULL)
|
||
} else if ((target_tile && tile_owner(target_tile) == nullptr)
|
||
&& !utype_may_act_tgt_city_tile(unit_type_get(punit),
|
||
act_id,
|
||
CITYT_CLAIMED,
|
||
... | ... | |
explnat->kind = ANEK_CITY_TOO_CLOSE_TGT;
|
||
} else if ((action_has_result_safe(paction, ACTRES_PARADROP_CONQUER)
|
||
|| action_has_result_safe(paction, ACTRES_PARADROP))
|
||
&& target_tile != NULL
|
||
&& target_tile != nullptr
|
||
&& !map_is_known(target_tile, act_player)) {
|
||
explnat->kind = ANEK_TGT_TILE_UNKNOWN;
|
||
} else if ((action_has_result_safe(paction, ACTRES_CONQUER_CITY)
|
||
... | ... | |
case ATK_UNIT:
|
||
/* The unit should be sent as a target since it is possible to act
|
||
* against it. */
|
||
fc_assert(target_unit != NULL);
|
||
fc_assert(target_unit != nullptr);
|
||
target_unit_id = target_unit->id;
|
||
break;
|
||
case ATK_TILE:
|
||
case ATK_EXTRAS:
|
||
/* The target tile isn't selected here so it hasn't changed. */
|
||
fc_assert(target_tile != NULL);
|
||
fc_assert(target_tile != nullptr);
|
||
if (target_extra && action_id_has_complex_target(act)) {
|
||
/* The target extra may have been set here. */
|
||
... | ... | |
break;
|
||
case ATK_STACK:
|
||
/* The target tile isn't selected here so it hasn't changed. */
|
||
fc_assert(target_tile != NULL);
|
||
fc_assert(target_tile != nullptr);
|
||
break;
|
||
case ATK_SELF:
|
||
/* The target unit is the actor unit. It is already sent. */
|
||
fc_assert(actor_unit != NULL);
|
||
fc_assert(actor_unit != nullptr);
|
||
break;
|
||
case ATK_COUNT:
|
||
fc_assert_msg(action_id_get_target_kind(act) != ATK_COUNT,
|
||
... | ... | |
notify_player(pplayer, unit_tile(actor),
|
||
event, ftc_server,
|
||
/* TRANS: action name.
|
||
* "Your Riflemen can't do Expel Unit to domestic
|
||
* "Your Riflemen can't do Expel Unit to domestic
|
||
* unit stacks." */
|
||
_("Your %s can't do %s to domestic %s."),
|
||
unit_name_translation(actor),
|
||
... | ... | |
/* The mistake may have a cost. */
|
||
/* HP cost */
|
||
punishment_hp = get_target_bonus_effects(NULL, &actor_ctxt, &tgt_ctxt,
|
||
punishment_hp = get_target_bonus_effects(nullptr, &actor_ctxt, &tgt_ctxt,
|
||
EFT_ILLEGAL_ACTION_HP_COST);
|
||
/* Stay in range */
|
||
... | ... | |
" do %s."),
|
||
unit_name_translation(act_unit), punishment_hp,
|
||
action_name_translation(stopped_action));
|
||
send_unit_info(NULL, act_unit);
|
||
send_unit_info(nullptr, act_unit);
|
||
} else {
|
||
/* The unit didn't survive */
|
||
... | ... | |
unit_name_translation(act_unit),
|
||
action_name_translation(stopped_action));
|
||
wipe_unit(act_unit, ULR_KILLED, NULL);
|
||
act_unit = NULL;
|
||
wipe_unit(act_unit, ULR_KILLED, nullptr);
|
||
act_unit = nullptr;
|
||
return TRUE;
|
||
}
|
||
}
|
||
/* MP cost */
|
||
punishment_mp = get_target_bonus_effects(NULL, &actor_ctxt, &tgt_ctxt,
|
||
punishment_mp = get_target_bonus_effects(nullptr, &actor_ctxt, &tgt_ctxt,
|
||
EFT_ILLEGAL_ACTION_MOVE_COST);
|
||
/* Stay in range */
|
||
... | ... | |
/* Punish the unit's move fragments. */
|
||
act_unit->moves_left = MAX(0, act_unit->moves_left - punishment_mp);
|
||
send_unit_info(NULL, act_unit);
|
||
send_unit_info(nullptr, act_unit);
|
||
if (punishment_mp != 0) {
|
||
/* The player probably wants to be disturbed if their unit was punished
|
||
... | ... | |
stopped_action,
|
||
actor,
|
||
target_city, target_unit,
|
||
target_tile, NULL));
|
||
target_tile, nullptr));
|
||
if (request_kind == REQEST_PLAYER_INITIATED) {
|
||
/* This is a foreground request. */
|
||
... | ... | |
struct tile *ptile = index_to_tile(&(wld.map), target_id);
|
||
const struct civ_map *nmap = &(wld.map);
|
||
if (NULL == paction) {
|
||
if (paction == nullptr) {
|
||
/* Non existing action */
|
||
log_error("handle_unit_action_query() the action %d doesn't exist.",
|
||
action_type);
|
||
... | ... | |
return;
|
||
}
|
||
if (NULL == pactor) {
|
||
if (pactor == nullptr) {
|
||
/* Probably died or bribed. */
|
||
log_verbose("handle_unit_action_query() invalid actor %d",
|
||
actor_id);
|
||
... | ... | |
action_type, request_kind);
|
||
} else {
|
||
illegal_action(pplayer, pactor, action_type,
|
||
pcity ? city_owner(pcity) : NULL,
|
||
NULL, pcity, NULL, request_kind, ACT_REQ_PLAYER);
|
||
pcity ? city_owner(pcity) : nullptr,
|
||
nullptr, pcity, nullptr, request_kind, ACT_REQ_PLAYER);
|
||
unit_query_impossible(pc, actor_id, target_id, request_kind);
|
||
return;
|
||
}
|
||
... | ... | |
request_kind);
|
||
} else {
|
||
illegal_action(pplayer, pactor, action_type,
|
||
pcity ? city_owner(pcity) : NULL,
|
||
NULL, pcity, NULL, request_kind, ACT_REQ_PLAYER);
|
||
pcity ? city_owner(pcity) : nullptr,
|
||
nullptr, pcity, nullptr, request_kind, ACT_REQ_PLAYER);
|
||
unit_query_impossible(pc, actor_id, target_id, request_kind);
|
||
return;
|
||
}
|
||
... | ... | |
action_by_number(action_type), request_kind);
|
||
} else {
|
||
illegal_action(pplayer, pactor, action_type,
|
||
pcity ? city_owner(pcity) : NULL,
|
||
NULL, pcity, NULL, request_kind, ACT_REQ_PLAYER);
|
||
pcity ? city_owner(pcity) : nullptr,
|
||
nullptr, pcity, nullptr, request_kind, ACT_REQ_PLAYER);
|
||
unit_query_impossible(pc, actor_id, target_id, request_kind);
|
||
return;
|
||
}
|
||
... | ... | |
struct action *paction;
|
||
int sub_tgt_id;
|
||
struct unit *actor_unit = player_unit_by_number(pplayer, actor_id);
|
||
struct tile *target_tile = NULL;
|
||
struct tile *target_tile = nullptr;
|
||
struct extra_type *target_extra;
|
||
struct impr_type *sub_tgt_impr;
|
||
struct unit *punit = NULL;
|
||
struct city *pcity = NULL;
|
||
struct unit *punit = nullptr;
|
||
struct city *pcity = nullptr;
|
||
const struct civ_map *nmap = &(wld.map);
|
||
if (!action_id_exists(action_type)) {
|
||
... | ... | |
paction = action_by_number(action_type);
|
||
if (NULL == actor_unit) {
|
||
if (actor_unit == nullptr) {
|
||
/* Probably died or bribed. */
|
||
log_verbose("unit_perform_action() invalid actor %d",
|
||
actor_id);
|
||
... | ... | |
switch (action_get_target_kind(paction)) {
|
||
case ATK_CITY:
|
||
pcity = game_city_by_number(target_id);
|
||
if (pcity == NULL) {
|
||
if (pcity == nullptr) {
|
||
log_verbose("unit_perform_action() invalid target city %d",
|
||
target_id);
|
||
return FALSE;
|
||
}
|
||
target_tile = city_tile(pcity);
|
||
fc_assert_ret_val(target_tile != NULL, FALSE);
|
||
fc_assert_ret_val(target_tile != nullptr, FALSE);
|
||
break;
|
||
case ATK_UNIT:
|
||
punit = game_unit_by_number(target_id);
|
||
if (punit == NULL) {
|
||
if (punit == nullptr) {
|
||
log_verbose("unit_perform_action() invalid target unit %d",
|
||
target_id);
|
||
return FALSE;
|
||
}
|
||
target_tile = unit_tile(punit);
|
||
fc_assert_ret_val(target_tile != NULL, FALSE);
|
||
fc_assert_ret_val(target_tile != nullptr, FALSE);
|
||
pcity = tile_city(target_tile);
|
||
break;
|
||
case ATK_STACK:
|
||
case ATK_TILE:
|
||
case ATK_EXTRAS:
|
||
target_tile = index_to_tile(nmap, target_id);
|
||
if (target_tile == NULL) {
|
||
if (target_tile == nullptr) {
|
||
log_verbose("unit_perform_action() invalid target tile %d",
|
||
target_id);
|
||
return FALSE;
|
||
... | ... | |
break;
|
||
case ATK_SELF:
|
||
target_tile = unit_tile(actor_unit);
|
||
fc_assert_ret_val(target_tile != NULL, FALSE);
|
||
fc_assert_ret_val(target_tile != nullptr, FALSE);
|
||
pcity = tile_city(target_tile);
|
||
break;
|
||
case ATK_COUNT:
|
||
... | ... | |
target_extra = extra_by_number(sub_tgt_id);
|
||
fc_assert(!(target_extra->ruledit_disabled));
|
||
} else {
|
||
target_extra = NULL;
|
||
target_extra = nullptr;
|
||
}
|
||
sub_tgt_impr = improvement_by_number(sub_tgt_id);
|
||
... | ... | |
/* No sub target. */
|
||
break;
|
||
case ASTK_BUILDING:
|
||
if (sub_tgt_impr == NULL) {
|
||
if (sub_tgt_impr == nullptr) {
|
||
/* Missing sub target */
|
||
return FALSE;
|
||
}
|
||
... | ... | |
break;
|
||
case ASTK_EXTRA:
|
||
case ASTK_EXTRA_NOT_THERE:
|
||
if (target_extra == NULL) {
|
||
if (target_extra == nullptr) {
|
||
/* Missing sub target */
|
||
return FALSE;
|
||
}
|
||
... | ... | |
if (action_get_activity(paction) != ACTIVITY_LAST
|
||
&& unit_activity_needs_target_from_client(
|
||
action_get_activity(paction))
|
||
&& target_extra == NULL) {
|
||
&& target_extra == nullptr) {
|
||
/* Missing required action extra target. */
|
||
log_verbose("unit_perform_action() action %d requires action "
|
||
"but extra id %d is invalid.",
|
||
... | ... | |
} \
|
||
script_server_signal_emit("action_finished_unit_city", \
|
||
action_by_number(action), success, \
|
||
unit_is_alive(actor_id) ? actor : NULL, \
|
||
city_exist(target_id) ? target : NULL); \
|
||
unit_is_alive(actor_id) ? actor : nullptr, \
|
||
city_exist(target_id) ? target : nullptr); \
|
||
return success; \
|
||
} else { \
|
||
illegal_action(pplayer, actor_unit, action_type, \
|
||
pcity ? city_owner(pcity) : NULL, NULL, pcity, NULL, \
|
||
TRUE, requester); \
|
||
pcity ? city_owner(pcity) : nullptr, nullptr, pcity, \
|
||
nullptr, TRUE, requester); \
|
||
}
|
||
#define ACTION_PERFORM_UNIT_SELF(action, actor, action_performer) \
|
||
... | ... | |
} \
|
||
script_server_signal_emit("action_finished_unit_self", \
|
||
action_by_number(action), success, \
|
||
unit_is_alive(actor_id) ? actor : NULL); \
|
||
unit_is_alive(actor_id) ? actor : nullptr); \
|
||
return success; \
|
||
} else { \
|
||
illegal_action(pplayer, actor_unit, action_type, \
|
||
unit_owner(actor_unit), NULL, NULL, actor_unit, \
|
||
unit_owner(actor_unit), nullptr, nullptr, actor_unit, \
|
||
TRUE, requester); \
|
||
}
|
||
... | ... | |
} \
|
||
script_server_signal_emit("action_finished_unit_unit", \
|
||
action_by_number(action), success, \
|
||
unit_is_alive(actor_id) ? actor : NULL, \
|
||
unit_is_alive(target_id) ? target : NULL); \
|
||
unit_is_alive(actor_id) ? actor : nullptr, \
|
||
unit_is_alive(target_id) ? target \
|
||
: nullptr); \
|
||
return success; \
|
||
} else { \
|
||
illegal_action(pplayer, actor_unit, action_type, \
|
||
punit ? unit_owner(punit) : NULL, NULL, NULL, punit, \
|
||
TRUE, requester); \
|
||
punit ? unit_owner(punit) : nullptr, nullptr, nullptr, \
|
||
punit, TRUE, requester); \
|
||
}
|
||
#define ACTION_PERFORM_UNIT_STACK(action, actor, target, action_performer)\
|
||
... | ... | |
} \
|
||
script_server_signal_emit("action_finished_unit_stack", \
|
||
action_by_number(action), success, \
|
||
unit_is_alive(actor_id) ? actor : NULL, \
|
||
unit_is_alive(actor_id) ? actor : nullptr, \
|
||
target); \
|
||
script_server_signal_emit("action_finished_unit_units", \
|
||
action_by_number(action), success, \
|
||
unit_is_alive(actor_id) ? actor : NULL, \
|
||
unit_is_alive(actor_id) ? actor : nullptr, \
|
||
target); \
|
||
return success; \
|
||
} else { \
|
||
illegal_action(pplayer, actor_unit, action_type, \
|
||
NULL, target_tile, NULL, NULL, \
|
||
nullptr, target_tile, nullptr, nullptr, \
|
||
TRUE, requester); \
|
||
}
|
||
... | ... | |
} \
|
||
script_server_signal_emit("action_finished_unit_tile", \
|
||
action_by_number(action), success, \
|
||
unit_is_alive(actor_id) ? actor : NULL, \
|
||
unit_is_alive(actor_id) ? actor : nullptr, \
|
||
target); \
|
||
return success; \
|
||
} else { \
|
||
illegal_action(pplayer, actor_unit, action_type, \
|
||
target_tile ? tile_owner(target_tile) : NULL, \
|
||
target_tile, NULL, NULL, \
|
||
target_tile ? tile_owner(target_tile) : nullptr, \
|
||
target_tile, nullptr, nullptr, \
|
||
TRUE, requester); \
|
||
}
|
||
... | ... | |
} \
|
||
script_server_signal_emit("action_finished_unit_extras", \
|
||
action_by_number(action), success, \
|
||
unit_is_alive(actor_id) ? actor : NULL, \
|
||
unit_is_alive(actor_id) ? actor : nullptr, \
|
||
target); \
|
||
return success; \
|
||
} else { \
|
||
illegal_action(pplayer, actor_unit, action_type, \
|
||
target_tile ? target_tile->extras_owner : NULL, \
|
||
target_tile, NULL, NULL, \
|
||
target_tile ? target_tile->extras_owner : nullptr, \
|
||
target_tile, nullptr, nullptr, \
|
||
TRUE, requester); \
|
||
}
|
||
... | ... | |
case ACTRES_TELEPORT_CONQUER:
|
||
ACTION_PERFORM_UNIT_TILE(action_type, actor_unit, target_tile,
|
||
unit_move(actor_unit, target_tile, 0,
|
||
NULL, FALSE,
|
||
nullptr, FALSE,
|
||
paction->result == ACTRES_TELEPORT_CONQUER,
|
||
paction->result == ACTRES_TELEPORT_CONQUER,
|
||
FALSE, FALSE));
|
||
... | ... | |
{
|
||
struct city *old_pcity = game_city_by_number(punit->homecity);
|
||
struct player *old_owner = unit_owner(punit);
|
||
struct player *new_owner = (new_pcity == NULL ? old_owner
|
||
: city_owner(new_pcity));
|
||
struct player *new_owner = (new_pcity == nullptr ? old_owner
|
||
: city_owner(new_pcity));
|
||
const struct civ_map *nmap = &(wld.map);
|
||
/* Calling this function when new_pcity is same as old_pcity should
|
||
... | ... | |
vision_clear_sight(punit->server.vision);
|
||
vision_free(punit->server.vision);
|
||
if (pcity != NULL
|
||
if (pcity != nullptr
|
||
&& !can_player_see_units_in_city(old_owner, pcity)) {
|
||
/* Special case when city is being transferred. At this point city
|
||
* itself has changed owner, so it's enemy city now that old owner
|
||
... | ... | |
if (old_pcity) {
|
||
/* Even if unit is dead, we have to unlink unit pointer (punit). */
|
||
unit_list_remove(old_pcity->units_supported, punit);
|
||
/* update unit upkeep */
|
||
/* Update unit upkeep */
|
||
city_units_upkeep(old_pcity);
|
||
}
|
||
if (new_pcity != NULL) {
|
||
if (new_pcity != nullptr) {
|
||
unit_list_prepend(new_pcity->units_supported, punit);
|
||
/* update unit upkeep */
|
||
/* Update unit upkeep */
|
||
city_units_upkeep(new_pcity);
|
||
punit->homecity = new_pcity->id;
|
||
... | ... | |
unit_activities_cancel(punit);
|
||
} else {
|
||
/* Send info to players and observers. */
|
||
send_unit_info(NULL, punit);
|
||
send_unit_info(nullptr, punit);
|
||
}
|
||
if (new_pcity != NULL) {
|
||
if (new_pcity != nullptr) {
|
||
city_refresh(new_pcity);
|
||
send_city_info(new_owner, new_pcity);
|
||
fc_assert(unit_owner(punit) == city_owner(new_pcity));
|
||
... | ... | |
struct city *pcity,
|
||
const struct action *paction)
|
||
{
|
||
const char *giver = NULL;
|
||
const char *giver = nullptr;
|
||
if (unit_owner(punit) != city_owner(pcity)) {
|
||
/* This is a gift. Tell the receiver. */
|
||
... | ... | |
sanity_check_city(pcity);
|
||
send_city_info(NULL, pcity);
|
||
send_city_info(nullptr, pcity);
|
||
script_server_signal_emit("city_size_change", pcity,
|
||
(lua_Integer)amount, "unit_added");
|
||
... | ... | |
if (size > 1) {
|
||
struct city *pcity = tile_city(ptile);
|
||
fc_assert_ret_val(pcity != NULL, FALSE);
|
||
fc_assert_ret_val(pcity != nullptr, FALSE);
|
||
city_change_size(pcity, size, nationality, -1, nullptr);
|
||
}
|
||
... | ... | |
{
|
||
struct unit *punit = player_unit_by_number(pplayer, unit_id);
|
||
if (NULL == punit) {
|
||
if (punit == nullptr) {
|
||
/* Probably died or bribed. */
|
||
log_verbose("handle_unit_change_activity() invalid unit %d", unit_id);
|
||
return;
|
||
... | ... | |
/* Remove city spot reservations for AI settlers on city founding
|
||
* mission, before goto_tile reset. */
|
||
if (punit->server.adv->task != AUT_NONE) {
|
||
adv_unit_new_task(punit, AUT_NONE, NULL);
|
||
adv_unit_new_task(punit, AUT_NONE, nullptr);
|
||
}
|
||
punit->goto_tile = NULL;
|
||
punit->goto_tile = nullptr;
|
||
if (activity == ACTIVITY_GOTO) {
|
||
/* Don't permit a client to set a unit's activity to ACTIVITY_GOTO.
|
||
... | ... | |
struct extra_type *activity_target;
|
||
if (target_id < 0 || target_id >= game.control.num_extra_types) {
|
||
activity_target = NULL;
|
||
activity_target = nullptr;
|
||
} else {
|
||
activity_target = extra_by_number(target_id);
|
||
}
|
||
#ifdef FREECIV_WEB
|
||
/* Web-client is not capable of selecting target, so we do it server side */
|
||
if (activity_target == NULL) {
|
||
if (activity_target == nullptr) {
|
||
struct unit *punit = player_unit_by_number(pplayer, unit_id);
|
||
bool required = TRUE;
|
||
if (punit == NULL) {
|
||
if (punit == nullptr) {
|
||
return;
|
||
}
|
||
... | ... | |
struct base_type *pbase =
|
||
get_base_by_gui_type(BASE_GUI_FORTRESS, punit, ptile);
|
||
if (pbase != NULL) {
|
||
if (pbase != nullptr) {
|
||
activity_target = base_extra_get(pbase);
|
||
}
|
||
... | ... | |
required = FALSE;
|
||
}
|
||
if (activity_target == NULL && required) {
|
||
if (activity_target == nullptr && required) {
|
||
/* Nothing more we can do */
|
||
return;
|
||
}
|
||
... | ... | |
struct packet_unit_short_info unit_att_short_packet, unit_def_short_packet;
|
||
struct packet_unit_info unit_att_packet, unit_def_packet;
|
||
/*
|
||
/*
|
||
* Special case for attacking/defending:
|
||
*
|
||
*
|
||
* Normally the player doesn't get the information about the units inside a
|
||
* city. However for attacking/defending the player has to know the unit of
|
||
* the other side. After the combat a remove_unit packet will be sent
|
||
... | ... | |
conn_list_iterate(game.est_connections, pconn) {
|
||
struct player *pplayer = pconn->playing;
|
||
if (pplayer != NULL) {
|
||
if (pplayer != nullptr) {
|
||
/* NOTE: this means the player can see combat between submarines even
|
||
* if neither sub is visible. See similar comment in send_combat. */
|
||
* if neither sub is visible. See similar comment in send_combat(). */
|
||
if (map_is_known_and_seen(unit_tile(pattacker), pplayer, V_MAIN)
|
||
|| map_is_known_and_seen(unit_tile(pdefender), pplayer,
|
||
V_MAIN)) {
|
||
... | ... | |
} else {
|
||
send_packet_unit_short_info(pconn, &unit_att_short_packet, FALSE);
|
||
}
|
||
|
||
if (pplayer == unit_owner(pdefender)) {
|
||
send_packet_unit_info(pconn, &unit_def_packet);
|
||
} else {
|
||
... | ... | |
/**********************************************************************//**
|
||
Send combat info to players.
|
||
**************************************************************************/
|
||
static void send_combat(struct unit *pattacker, struct unit *pdefender,
|
||
static void send_combat(struct unit *pattacker, struct unit *pdefender,
|
||
int att_veteran, int def_veteran, int bombard)
|
||
{
|
||
struct packet_unit_combat_info combat;
|
||
... | ... | |
V_MAIN)) {
|
||
lsend_packet_unit_combat_info(other_player->connections, &combat);
|
||
/*
|
||
* Remove the client knowledge of the units. This corresponds to the
|
||
* send_packet_unit_short_info calls up above.
|
||
/*
|
||
* Remove the client knowledge of the units. This corresponds to the
|
||
* send_packet_unit_short_info() calls up above.
|
||
*/
|
||
if (!can_player_see_unit(other_player, pattacker)) {
|
||
unit_goes_out_of_sight(other_player, pattacker);
|
||
unit_goes_out_of_sight(other_player, pattacker);
|
||
}
|
||
if (!can_player_see_unit(other_player, pdefender)) {
|
||
unit_goes_out_of_sight(other_player, pdefender);
|
||
unit_goes_out_of_sight(other_player, pdefender);
|
||
}
|
||
}
|
||
} players_iterate_end;
|
||
/* Send combat info to non-player observers as well. They already know
|
||
/* Send combat info to non-player observers as well. They already know
|
||
* about the unit so no unit_info is needed. */
|
||
conn_list_iterate(game.est_connections, pconn) {
|
||
if (NULL == pconn->playing && pconn->observer) {
|
||
if (pconn->playing == nullptr && pconn->observer) {
|
||
send_packet_unit_combat_info(pconn, &combat);
|
||
}
|
||
} conn_list_iterate_end;
|
||
... | ... | |
struct player *pplayer = unit_owner(punit);
|
||
if (pcity
|
||
&& get_target_bonus_effects(NULL,
|
||
&& get_target_bonus_effects(nullptr,
|
||
&(const struct req_context) {
|
||
.player = city_owner(pcity),
|
||
.city = pcity,
|
||
... | ... | |
.unittype = unit_type_get(punit),
|
||
.action = paction,
|
||
},
|
||
NULL, EFT_UNIT_NO_LOSE_POP) <= 0
|
||
nullptr, EFT_UNIT_NO_LOSE_POP) <= 0
|
||
&& (game.info.killcitizen
|
||
&& uclass_has_flag(unit_class_get(punit), UCF_KILLCITIZEN))) {
|
||
struct player *cplayer = city_owner(pcity);
|
||
... | ... | |
if (city_reduce_size(pcity, 1, pplayer, reason)) {
|
||
city_refresh(pcity);
|
||
send_city_info(NULL, pcity);
|
||
send_city_info(nullptr, pcity);
|
||
} else {
|
||
notify_player(pplayer, ctile, E_UNIT_ACTION_ACTOR_SUCCESS, ftc_server,
|
||
/* TRANS: Battleship ... Los Angeles ... Bombard */
|
||
... | ... | |
if (def_hp <= 0) {
|
||
wipe_unit(pdefender, ULR_KILLED, unit_owner(pdefender));
|
||
} else {
|
||
send_unit_info(NULL, pdefender);
|
||
send_unit_info(nullptr, pdefender);
|
||
}
|
||
}
|
||
... | ... | |
unit_did_action(punit);
|
||
unit_forget_last_activity(punit);
|
||
|
||
unit_attack_civilian_casualties(punit, pcity, paction, "bombard");
|
||
send_unit_info(NULL, punit);
|
||
send_unit_info(nullptr, punit);
|
||
return TRUE;
|
||
}
|
||
... | ... | |
/* The nuke must be wiped here so it won't be seen as a victim of its own
|
||
* detonation. */
|
||
if (paction->actor_consuming_always) {
|
||
wipe_unit(punit, ULR_DETONATED, NULL);
|
||
wipe_unit(punit, ULR_DETONATED, nullptr);
|
||
}
|
||
do_nuclear_explosion(paction, act_utype, pplayer, def_tile);
|
||
... | ... | |
char attacker_fp[MAX_LEN_LINK], defender_fp[MAX_LEN_LINK];
|
||
char attacker_tired[MAX_LEN_LINK];
|
||
struct unit *ploser, *pwinner;
|
||
int moves_used, def_moves_used;
|
||
int moves_used, def_moves_used;
|
||
int old_unit_vet, old_defender_vet, vet;
|
||
int winner_id;
|
||
struct player *pplayer = unit_owner(punit);
|
||
... | ... | |
log_debug("Start attack: %s %s against %s %s.",
|
||
nation_rule_name(nation_of_player(pplayer)),
|
||
unit_rule_name(punit),
|
||
unit_rule_name(punit),
|
||
nation_rule_name(nation_of_unit(pdefender)),
|
||
unit_rule_name(pdefender));
|
||
... | ... | |
/* Adjust attackers moves_left _after_ unit_versus_unit() so that
|
||
* the movement attack modifier is correct! --dwp
|
||
*
|
||
* For greater Civ2 compatibility (and game balance issues), we recompute
|
||
* the new total MP based on the HP the unit has left after being damaged,
|
||
* and subtract the MPs that had been used before the combat (plus the
|
||
* For greater Civ2 compatibility (and game balance issues), we recompute
|
||
* the new total MP based on the HP the unit has left after being damaged,
|
||
* and subtract the MPs that had been used before the combat (plus the
|
||
* points used in the attack itself, for the attacker). -GJW, Glip
|
||
*/
|
||
punit->moves_left = unit_move_rate(punit) - moves_used;
|
||
... | ... | |
ploser = (pdefender->hp > 0) ? punit : pdefender;
|
||
vet = (pwinner->veteran == ((punit->hp > 0) ? old_unit_vet :
|
||
old_defender_vet)) ? 0 : 1;
|
||
old_defender_vet)) ? 0 : 1;
|
||
send_combat(punit, pdefender, punit->veteran - old_unit_vet,
|
||
pdefender->veteran - old_defender_vet, 0);
|
||
... | ... | |
def_hp_start);
|
||
}
|
||
punit->moved = TRUE; /* We moved */
|
||
punit->moved = TRUE; /* We moved */
|
||
if (paction->result == ACTRES_COLLECT_RANSOM) {
|
||
collect_ransom(pwinner, ploser,
|
||
... | ... | |
* supported by the city, we may even remove the city
|
||
* (if it shrinks from size 1) */
|
||
pcity = tile_city(def_tile);
|
||
if (pcity != NULL) {
|
||
if (pcity != nullptr) {
|
||
unit_attack_civilian_casualties(punit, pcity, paction, "attack");
|
||
}
|
||
if (unit_is_alive(winner_id)) {
|
||
... | ... | |
}
|
||
/* The attacker may have died for many reasons */
|
||
if (game_unit_by_number(winner_id) != NULL) {
|
||
send_unit_info(NULL, pwinner);
|
||
if (game_unit_by_number(winner_id) != nullptr) {
|
||
send_unit_info(nullptr, pwinner);
|
||
}
|
||
return TRUE;
|
||
... | ... | |
building_lost(tgt_city, tgt_bld, "attacked", act_unit);
|
||
/* Update the player's view of the city. */
|
||
send_city_info(NULL, tgt_city);
|
||
send_city_info(nullptr, tgt_city);
|
||
/* Let the players know. */
|
||
clink = city_link(tgt_city); /* Be careful not to call city_link()
|
||
... | ... | |
/* Sanity check */
|
||
fc_assert_ret_val(tgt_tile, FALSE);
|
||
unit_move(act_unit, tgt_tile, move_cost, NULL, FALSE, TRUE, TRUE,
|
||
unit_move(act_unit, tgt_tile, move_cost, nullptr, FALSE, TRUE, TRUE,
|
||
BV_ISSET(paction->sub_results, ACT_SUB_RES_HUT_ENTER),
|
||
BV_ISSET(paction->sub_results, ACT_SUB_RES_HUT_FRIGHTEN));
|
||
... | ... | |
See also aiunit could_unit_move_to_tile()
|
||
**************************************************************************/
|
||
static bool can_unit_move_to_tile_with_notify(struct unit *punit,
|
||
struct tile *dest_tile,
|
||
bool igzoc,
|
||
struct tile *dest_tile,
|
||
bool igzoc,
|
||
struct unit *embark_to,
|
||
bool enter_enemy_city)
|
||
{
|
||
... | ... | |
int move_cost = map_move_cost_unit(&(wld.map), actor_unit, target_tile);
|
||
unit_move(actor_unit, target_tile, move_cost,
|
||
NULL, BV_ISSET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK),
|
||
nullptr, BV_ISSET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK),
|
||
/* Don't override "Conquer City" */
|
||
FALSE,
|
||
/* Don't override "Conquer Extras" */
|
||
... | ... | |
/* A legal action with an extra sub target is a legal action */
|
||
|| action_tgt_tile_extra(punit, pdesttile, can_not_move)
|
||
/* Tile target actions with extra sub targets are handled above */
|
||
|| action_tgt_tile(punit, pdesttile, NULL, can_not_move);
|
||
|| action_tgt_tile(punit, pdesttile, nullptr, can_not_move);
|
||
if (one_action_may_be_legal || can_not_move) {
|
||
/* There is a target punit, from the player's point of view, may be
|
||
... | ... | |
/*** Phase 2: OK now move the unit ***/
|
||
/* This is a regular move, subject to the rules. */
|
||
if (is_action_enabled_unit_on_tile(nmap, ACTION_UNIT_MOVE,
|
||
punit, pdesttile, NULL)) {
|
||
punit, pdesttile, nullptr)) {
|
||
return unit_perform_action(pplayer, punit->id, tile_index(pdesttile),
|
||
NO_TARGET, "", ACTION_UNIT_MOVE,
|
||
ACT_REQ_PLAYER);
|
||
} else if (is_action_enabled_unit_on_tile(nmap, ACTION_UNIT_MOVE2,
|
||
punit, pdesttile, NULL)) {
|
||
punit, pdesttile, nullptr)) {
|
||
return unit_perform_action(pplayer, punit->id, tile_index(pdesttile),
|
||
NO_TARGET, "", ACTION_UNIT_MOVE2,
|
||
ACT_REQ_PLAYER);
|
||
} else if (is_action_enabled_unit_on_tile(nmap, ACTION_UNIT_MOVE3,
|
||
punit, pdesttile, NULL)) {
|
||
punit, pdesttile, nullptr)) {
|
||
return unit_perform_action(pplayer, punit->id, tile_index(pdesttile),
|
||
NO_TARGET, "", ACTION_UNIT_MOVE3,
|
||
ACT_REQ_PLAYER);
|
||
... | ... | |
NO_TARGET, "", ACTION_TRANSPORT_EMBARK4,
|
||
ACT_REQ_PLAYER);
|
||
} else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK1,
|
||
punit, pdesttile, NULL)) {
|
||
punit, pdesttile, nullptr)) {
|
||
/* "Transport Disembark". */
|
||
return unit_perform_action(pplayer, punit->id, tile_index(pdesttile),
|
||
NO_TARGET, "", ACTION_TRANSPORT_DISEMBARK1,
|
||
ACT_REQ_PLAYER);
|
||
} else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK2,
|
||
punit, pdesttile, NULL)) {
|
||
punit, pdesttile, nullptr)) {
|
||
/* "Transport Disembark 2". */
|
||
return unit_perform_action(pplayer, punit->id, tile_index(pdesttile),
|
||
NO_TARGET, "", ACTION_TRANSPORT_DISEMBARK2,
|
||
ACT_REQ_PLAYER);
|
||
} else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK3,
|
||
punit, pdesttile, NULL)) {
|
||
punit, pdesttile, nullptr)) {
|
||
/* "Transport Disembark 3". */
|
||
return unit_perform_action(pplayer, punit->id, tile_index(pdesttile),
|
||
NO_TARGET, "", ACTION_TRANSPORT_DISEMBARK3,
|
||
ACT_REQ_PLAYER);
|
||
} else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK4,
|
||
punit, pdesttile, NULL)) {
|
||
punit, pdesttile, nullptr)) {
|
||
/* "Transport Disembark 4". */
|
||
return unit_perform_action(pplayer, punit->id, tile_index(pdesttile),
|
||
NO_TARGET, "", ACTION_TRANSPORT_DISEMBARK4,
|
||
ACT_REQ_PLAYER);
|
||
} else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_ENTER,
|
||
punit, pdesttile, NULL)) {
|
||
punit, pdesttile, nullptr)) {
|
||
/* "Enter Hut". */
|
||
return unit_perform_action(pplayer, punit->id, tile_index(pdesttile),
|
||
NO_TARGET, "", ACTION_HUT_ENTER,
|
||
ACT_REQ_PLAYER);
|
||
} else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_ENTER2,
|
||
punit, pdesttile, NULL)) {
|
||
punit, pdesttile, nullptr)) {
|
||
/* "Enter Hut 2". */
|
||
return unit_perform_action(pplayer, punit->id, tile_index(pdesttile),
|
||
NO_TARGET, "", ACTION_HUT_ENTER2,
|
||
ACT_REQ_PLAYER);
|
||
} else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_FRIGHTEN,
|
||
punit, pdesttile, NULL)) {
|
||
punit, pdesttile, nullptr)) {
|
||
/* "Frighten Hut". */
|
||
return unit_perform_action(pplayer, punit->id, tile_index(pdesttile),
|
||
NO_TARGET, "", ACTION_HUT_FRIGHTEN,
|
||
ACT_REQ_PLAYER);
|
||
} else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_FRIGHTEN2,
|
||
punit, pdesttile, NULL)) {
|
||
punit, pdesttile, nullptr)) {
|
||
/* "Frighten Hut 2". */
|
||
return unit_perform_action(pplayer, punit->id, tile_index(pdesttile),
|
||
NO_TARGET, "", ACTION_HUT_FRIGHTEN2,
|
||
... | ... | |
/* TODO: Extend the action not enabled explanation system to cover all
|
||
* existing reasons and switch to using it. See hrm Feature #920229 */
|
||
can_unit_move_to_tile_with_notify(punit, pdesttile, FALSE,
|
||
NULL, FALSE);
|
||
nullptr, FALSE);
|
||
return FALSE;
|
||
}
|
||
}
|
||
... | ... | |
unit_link(punit),
|
||
action_name_translation(paction),
|
||
prod,
|
||
city_link(pcity_dest),
|
||
city_link(pcity_dest),
|
||
abs(build_points_left(pcity_dest)),
|
||
work);
|
||
... | ... | |
}
|
||
/**********************************************************************//**
|
||
Handle request to establish trade route. If pcity_dest is NULL, assumes
|
||
Handle request to establish trade route. If pcity_dest is nullptr, assumes
|
||
that unit is inside target city.
|
||
Returns TRUE iff action could be done, FALSE if it couldn't. Even if
|
||
... | ... | |
goods = unit_current_goods(punit, pcity_homecity);
|
||
if (goods == NULL) {
|
||
if (goods == nullptr) {
|
||
notify_player(pplayer, unit_tile(punit), E_BAD_COMMAND, ftc_server,
|
||
_("Sorry, your %s cannot establish"
|
||
" a trade route because it's not carrying any goods."),
|
||
... | ... | |
homecity_link,
|
||
home_max);
|
||
}
|
||
can_establish = FALSE;
|
||
can_establish = FALSE;
|
||
}
|
||
}
|
||
... | ... | |
destcity_link,
|
||
dest_max);
|
||
}
|
||
can_establish = FALSE;
|
||
can_establish = FALSE;
|
||
}
|
||
}
|
||
}
|
||
... | ... | |
update_bulbs(pplayer, revenue, TRUE, TRUE);
|
||
/* Inform everyone about tech changes */
|
||
send_research_info(research_get(pplayer), NULL);
|
||
send_research_info(research_get(pplayer), nullptr);
|
||
}
|
||
if (can_establish) {
|
||
... | ... | |
partner_player = city_owner(pcity_dest);
|
||
/* Always tell the unit owner */
|
||
notify_player(pplayer, NULL,
|
||
notify_player(pplayer, nullptr,
|
||
E_CARAVAN_ACTION, ftc_server,
|
||
_("New trade route established from %s to %s."),
|
||
homecity_link,
|
||
... | ... | |
struct unit *punit = player_unit_by_number(pplayer, unit_id);
|
||
const struct civ_map *nmap = &(wld.map);
|
||
if (NULL == punit) {
|
||
if (punit == nullptr) {
|
||
/* Being asked to unqueue a "spent" unit because the client haven't
|
||
* been told that it's gone is expected. */
|
||
if (type != USSDT_UNQUEUE) {
|
||
... | ... | |
* perform against the target tile. Action decision state can be set by
|
||
* the server it self too. */
|
||
if (index_to_tile(nmap, value) == NULL) {
|
||
if (index_to_tile(nmap, value) == nullptr) {
|
||
/* Asked to be reminded to ask what actions the unit can do to a non
|
||
* existing target tile. */
|
||
log_verbose("unit_sscs_set() invalid target tile %d for unit %d",
|
||
... | ... | |
* Action decision state can be set by the server it self too. */
|
||
punit->action_decision_want = ACT_DEC_NOTHING;
|
||
punit->action_decision_tile = NULL;
|
||
punit->action_decision_tile = nullptr;
|
||
/* Let the client know that this unit no longer needs the player to
|
||
* decide what to do. */
|
||
... | ... | |
{
|
||
/* Remove city spot reservations for AI settlers on city founding
|
||
* mission. */
|
||
adv_unit_new_task(punit, AUT_NONE, NULL);
|
||
adv_unit_new_task(punit, AUT_NONE, nullptr);
|
||
/* Get rid of old orders. */
|
||
free_unit_orders(punit);
|
||
/* Make sure that no old goto_tile remains. */
|
||
punit->goto_tile = NULL;
|
||
punit->goto_tile = nullptr;
|
||
}
|
||
/**********************************************************************//**
|
||
... | ... | |
{
|
||
struct unit *punit = player_unit_by_number(pplayer, unit_id);
|
||
if (NULL == punit) {
|
||
if (punit == nullptr) {
|
||
/* Probably died or bribed. */
|
||
log_verbose("handle_unit_server_side_agent_set() invalid unit %d",
|
||
unit_id);
|
||
... | ... | |
if (punit->ssa_controller != agent) {
|
||
punit->ssa_controller = agent;
|
||
send_unit_info(NULL, punit);
|
||
send_unit_info(nullptr, punit);
|
||
}
|
||
return TRUE;
|
||
... | ... | |
old activity to new one.
|
||
**************************************************************************/
|
||
static void unit_activity_dependencies(struct unit *punit,
|
||
enum unit_activity old_activity,
|
||
enum unit_activity old_activity,
|
||
struct extra_type *old_target)
|
||
{
|
||
switch (punit->activity) {
|
||
case ACTIVITY_IDLE:
|
||
switch (old_activity) {
|
||
case ACTIVITY_PILLAGE:
|
||
case ACTIVITY_PILLAGE:
|
||
{
|
||
if (old_target != NULL) {
|
||
if (old_target != nullptr) {
|
||
unit_list_iterate_safe(unit_tile(punit)->units, punit2) {
|
||
if (punit2->activity == ACTIVITY_PILLAGE) {
|
||
extra_deps_iterate(&(punit2->activity_target->reqs), pdep) {
|
||
if (pdep == old_target) {
|
||
set_unit_activity(punit2, ACTIVITY_IDLE, ACTION_NONE);
|
||
send_unit_info(NULL, punit2);
|
||
send_unit_info(nullptr, punit2);
|
||
break;
|
||
}
|
||
} extra_deps_iterate_end;
|
||
... | ... | |
/* Restore unit's control status */
|
||
punit->ssa_controller = SSA_NONE;
|
||
break;
|
||
default:
|
||
default:
|
||
; /* Do nothing */
|
||
}
|