Project

General

Profile

Feature #2392 ยป 0086-diplhand.c-Replace-NULL-with-nullptr.patch

Marko Lindqvist, 10/19/2026 10:15 PM

View differences:

server/diplhand.c
const struct req_context player_ctxt = { .player = pplayer };
const struct req_context other_ctxt = { .player = pother };
if (NULL == pother || pplayer == pother) {
if (pother == nullptr || pplayer == pother) {
return;
}
......
other_accept = &ptreaty->accept0;
}
if (!*player_accept) { /* Tries to accept. */
if (!*player_accept) { /* Tries to accept. */
/* Check that player who accepts can keep what they promise. */
clause_list_iterate(ptreaty->clauses, pclause) {
struct city *pcity = NULL;
struct city *pcity = nullptr;
if (pclause->from == pplayer) {
struct clause_info *info = clause_info_get(pclause->type);
......
}
if (pclause->from == pplayer || is_pact_clause(pclause->type)) {
switch (pclause->type) {
case CLAUSE_EMBASSY:
switch (pclause->type) {
case CLAUSE_EMBASSY:
if (player_has_real_embassy(pother, pplayer)) {
log_error("%s tried to give embassy to %s, who already "
"has an embassy",
......
return;
}
break;
case CLAUSE_ADVANCE:
case CLAUSE_ADVANCE:
if (!research_invention_gettable(research_get(pother),
pclause->value, game.info.tech_trade_allow_holes)) {
/* It is impossible to give a technology to a civilization that
* can not possess it (the client should enforce this). */
/* It is impossible to give a technology to a civilization that
* can not possess it (the client should enforce this). */
log_error("Treaty: %s can't have tech %s",
nation_rule_name(nation_of_player(pother)),
advance_rule_name(advance_by_number(pclause->value)));
notify_player(pplayer, NULL, E_DIPLOMACY, ftc_server,
notify_player(pplayer, nullptr, E_DIPLOMACY, ftc_server,
_("The %s can't accept %s."),
nation_plural_for_player(pother),
advance_name_translation(advance_by_number
(pclause->value)));
return;
return;
}
if (research_invention_state(research_get(pplayer), pclause->value)
!= TECH_KNOWN) {
......
nation_rule_name(nation_of_player(pplayer)),
advance_rule_name(advance_by_number(pclause->value)),
nation_rule_name(nation_of_player(pother)));
notify_player(pplayer, NULL, E_DIPLOMACY, ftc_server,
_("You don't have tech %s, you can't accept treaty."),
notify_player(pplayer, nullptr, E_DIPLOMACY, ftc_server,
_("You don't have tech %s, you can't accept treaty."),
advance_name_translation(advance_by_number
(pclause->value)));
return;
}
break;
case CLAUSE_CITY:
pcity = game_city_by_number(pclause->value);
if (!pcity) { /* Can't find out cityname any more. */
notify_player(pplayer, NULL, E_DIPLOMACY, ftc_server,
_("City you are trying to give no longer exists, "
"you can't accept treaty."));
return;
}
if (city_owner(pcity) != pplayer) {
notify_player(pplayer, NULL, E_DIPLOMACY, ftc_server,
_("You are not owner of %s, you can't accept treaty."),
city_link(pcity));
return;
}
if (is_capital(pcity)) {
notify_player(pplayer, NULL, E_DIPLOMACY, ftc_server,
_("Your capital (%s) is requested, "
"you can't accept treaty."),
city_link(pcity));
return;
}
break;
case CLAUSE_CEASEFIRE:
return;
}
break;
case CLAUSE_CITY:
pcity = game_city_by_number(pclause->value);
if (!pcity) { /* Can't find out cityname any more. */
notify_player(pplayer, nullptr, E_DIPLOMACY, ftc_server,
_("City you are trying to give no longer exists, "
"you can't accept treaty."));
return;
}
if (city_owner(pcity) != pplayer) {
notify_player(pplayer, nullptr, E_DIPLOMACY, ftc_server,
_("You are not owner of %s, you can't accept treaty."),
city_link(pcity));
return;
}
if (is_capital(pcity)) {
notify_player(pplayer, nullptr, E_DIPLOMACY, ftc_server,
_("Your capital (%s) is requested, "
"you can't accept treaty."),
city_link(pcity));
return;
}
break;
case CLAUSE_CEASEFIRE:
diplcheck = pplayer_can_make_treaty(pplayer, pother, DS_CEASEFIRE);
if (diplcheck != DIPL_OK) {
return;
}
break;
case CLAUSE_PEACE:
case CLAUSE_PEACE:
diplcheck = pplayer_can_make_treaty(pplayer, pother, DS_PEACE);
if (diplcheck != DIPL_OK) {
return;
}
break;
case CLAUSE_ALLIANCE:
case CLAUSE_ALLIANCE:
diplcheck = pplayer_can_make_treaty(pplayer, pother, DS_ALLIANCE);
if (diplcheck == DIPL_ALLIANCE_PROBLEM_US) {
notify_player(pplayer, NULL, E_DIPLOMACY, ftc_server,
notify_player(pplayer, nullptr, E_DIPLOMACY, ftc_server,
_("You cannot form an alliance because you are "
"at war with an ally of %s."),
player_name(pother));
} else if (diplcheck == DIPL_ALLIANCE_PROBLEM_THEM) {
notify_player(pplayer, NULL, E_DIPLOMACY, ftc_server,
notify_player(pplayer, nullptr, E_DIPLOMACY, ftc_server,
_("You cannot form an alliance because %s is "
"at war with an ally of yours."),
player_name(pother));
......
return;
}
break;
case CLAUSE_GOLD:
if (pplayer->economic.gold < pclause->value) {
notify_player(pplayer, NULL, E_DIPLOMACY, ftc_server,
_("You don't have enough gold, "
"you can't accept treaty."));
return;
}
break;
case CLAUSE_GOLD:
if (pplayer->economic.gold < pclause->value) {
notify_player(pplayer, nullptr, E_DIPLOMACY, ftc_server,
_("You don't have enough gold, "
"you can't accept treaty."));
return;
}
break;
case CLAUSE_MAP:
case CLAUSE_SEAMAP:
case CLAUSE_VISION:
......
*player_accept = ! *player_accept;
dlsend_packet_diplomacy_accept_treaty(pplayer->connections,
player_number(pother), *player_accept,
*other_accept);
player_number(pother), *player_accept,
*other_accept);
dlsend_packet_diplomacy_accept_treaty(pother->connections,
player_number(pplayer), *other_accept,
*player_accept);
player_number(pplayer), *other_accept,
*player_accept);
if (ptreaty->accept0 && ptreaty->accept1) {
int nclauses = clause_list_size(ptreaty->clauses);
dlsend_packet_diplomacy_cancel_meeting(pplayer->connections,
player_number(pother),
player_number(pplayer));
player_number(pother),
player_number(pplayer));
dlsend_packet_diplomacy_cancel_meeting(pother->connections,
player_number(pplayer),
player_number(pplayer));
player_number(pplayer),
player_number(pplayer));
notify_player(pplayer, NULL, E_DIPLOMACY, ftc_server,
notify_player(pplayer, nullptr, E_DIPLOMACY, ftc_server,
PL_("A treaty containing %d clause was agreed upon.",
"A treaty containing %d clauses was agreed upon.",
nclauses),
nclauses);
notify_player(pother, NULL, E_DIPLOMACY, ftc_server,
notify_player(pother, nullptr, E_DIPLOMACY, ftc_server,
PL_("A treaty containing %d clause was agreed upon.",
"A treaty containing %d clauses was agreed upon.",
nclauses),
......
&(info->giver_reqs), RPT_POSSIBLE)
|| !are_reqs_active(&player_ctxt, &other_ctxt,
&(info->receiver_reqs), RPT_POSSIBLE)) {
notify_player(pplayer, NULL, E_DIPLOMACY, ftc_server,
notify_player(pplayer, nullptr, E_DIPLOMACY, ftc_server,
_("Clause requirements are no longer fulfilled. "
"Treaty with %s canceled!"),
nation_plural_for_player(pother));
notify_player(pother, NULL, E_DIPLOMACY, ftc_server,
notify_player(pother, nullptr, E_DIPLOMACY, ftc_server,
_("Clause requirements are no longer fulfilled. "
"Treaty with %s canceled!"),
nation_plural_for_player(pplayer));
......
}
if (pclause->from == pother) {
switch (pclause->type) {
case CLAUSE_CITY:
switch (pclause->type) {
case CLAUSE_CITY:
pcity = game_city_by_number(pclause->value);
if (!pcity) { /* Can't find out cityname any more. */
notify_player(pplayer, NULL, E_DIPLOMACY, ftc_server,
if (!pcity) { /* Can't find out cityname any more. */
notify_player(pplayer, nullptr, E_DIPLOMACY, ftc_server,
_("One of the cities the %s are giving away"
" is destroyed! Treaty canceled!"),
nation_plural_for_player(pother));
notify_player(pother, NULL, E_DIPLOMACY, ftc_server,
notify_player(pother, nullptr, E_DIPLOMACY, ftc_server,
_("One of the cities the %s are giving away"
" is destroyed! Treaty canceled!"),
nation_plural_for_player(pother));
goto cleanup;
}
if (city_owner(pcity) != pother) {
notify_player(pplayer, NULL, E_DIPLOMACY, ftc_server,
goto cleanup;
}
if (city_owner(pcity) != pother) {
notify_player(pplayer, nullptr, E_DIPLOMACY, ftc_server,
_("The %s no longer control %s! "
"Treaty canceled!"),
nation_plural_for_player(pother),
city_link(pcity));
notify_player(pother, NULL, E_DIPLOMACY, ftc_server,
notify_player(pother, nullptr, E_DIPLOMACY, ftc_server,
_("The %s no longer control %s! "
"Treaty canceled!"),
nation_plural_for_player(pother),
city_link(pcity));
goto cleanup;
}
if (is_capital(pcity)) {
notify_player(pother, NULL, E_DIPLOMACY, ftc_server,
goto cleanup;
}
if (is_capital(pcity)) {
notify_player(pother, nullptr, E_DIPLOMACY, ftc_server,
_("Your capital (%s) is requested, "
"you can't accept treaty."),
city_link(pcity));
goto cleanup;
}
goto cleanup;
}
break;
case CLAUSE_ALLIANCE:
break;
case CLAUSE_ALLIANCE:
/* We need to recheck this way since things might have
* changed. */
diplcheck = pplayer_can_make_treaty(pplayer, pother, DS_ALLIANCE);
......
goto cleanup;
}
break;
case CLAUSE_GOLD:
if (pother->economic.gold < pclause->value) {
notify_player(pplayer, NULL, E_DIPLOMACY, ftc_server,
case CLAUSE_GOLD:
if (pother->economic.gold < pclause->value) {
notify_player(pplayer, nullptr, E_DIPLOMACY, ftc_server,
_("The %s don't have the promised amount "
"of gold! Treaty canceled!"),
nation_plural_for_player(pother));
notify_player(pother, NULL, E_DIPLOMACY, ftc_server,
notify_player(pother, nullptr, E_DIPLOMACY, ftc_server,
_("The %s don't have the promised amount "
"of gold! Treaty canceled!"),
nation_plural_for_player(pother));
goto cleanup;
}
break;
default:
; /* nothing */
}
goto cleanup;
}
break;
default:
; /* Nothing */
}
}
} clause_list_iterate_end;
......
struct player_diplstate *ds_destgiver
= player_diplstate_get(pdest, pgiver);
enum diplstate_type old_diplstate = ds_giverdest->type;
struct unit_list *pgiver_seen_units BAD_HEURISTIC_INIT(NULL);
struct unit_list *pdest_seen_units BAD_HEURISTIC_INIT(NULL);
struct unit_list *pgiver_seen_units BAD_HEURISTIC_INIT(nullptr);
struct unit_list *pdest_seen_units BAD_HEURISTIC_INIT(nullptr);
int armistice_length, arm_1, arm_2;
int ceasefire_length, cf_1, cf_2;
switch (pclause->type) {
case CLAUSE_EMBASSY:
establish_embassy(pdest, pgiver); /* sic */
notify_player(pgiver, NULL, E_TREATY_EMBASSY, ftc_server,
notify_player(pgiver, nullptr, E_TREATY_EMBASSY, ftc_server,
_("You gave an embassy to %s."),
player_name(pdest));
notify_player(pdest, NULL, E_TREATY_EMBASSY, ftc_server,
notify_player(pdest, nullptr, E_TREATY_EMBASSY, ftc_server,
_("%s allowed you to create an embassy!"),
player_name(pgiver));
break;
......
}
advance_name = advance_name_translation(advance_by_number
(pclause->value));
notify_player(pdest, NULL, E_TECH_GAIN, ftc_server,
notify_player(pdest, nullptr, E_TECH_GAIN, ftc_server,
_("You are taught the knowledge of %s."),
advance_name);
......
* (100 - game.server.diplgoldcost) / 100;
pgiver->economic.gold -= pclause->value;
pdest->economic.gold += received;
notify_player(pdest, NULL, E_DIPLOMACY, ftc_server,
notify_player(pdest, nullptr, E_DIPLOMACY, ftc_server,
PL_("You get %d gold.",
"You get %d gold.", received), received);
}
break;
break;
case CLAUSE_MAP:
give_map_from_player_to_player(pgiver, pdest);
notify_player(pdest, NULL, E_DIPLOMACY, ftc_server,
give_map_from_player_to_player(pgiver, pdest);
notify_player(pdest, nullptr, E_DIPLOMACY, ftc_server,
/* TRANS: ... Polish worldmap. */
_("You receive the %s worldmap."),
nation_adjective_for_player(pgiver));
worker_refresh_required = TRUE; /* See CLAUSE_VISION */
break;
break;
case CLAUSE_SEAMAP:
give_seamap_from_player_to_player(pgiver, pdest);
notify_player(pdest, NULL, E_DIPLOMACY, ftc_server,
give_seamap_from_player_to_player(pgiver, pdest);
notify_player(pdest, nullptr, E_DIPLOMACY, ftc_server,
/* TRANS: ... Polish seamap. */
_("You receive the %s seamap."),
nation_adjective_for_player(pgiver));
worker_refresh_required = TRUE; /* See CLAUSE_VISION */
break;
break;
case CLAUSE_CITY:
{
{
struct city *pcity = game_city_by_number(pclause->value);
if (!pcity) {
if (!pcity) {
log_error("Treaty city id %d not found - skipping clause.",
pclause->value);
break;
}
break;
}
notify_player(pdest, city_tile(pcity), E_CITY_TRANSFER, ftc_server,
_("You receive the city of %s from %s."),
......
script_server_signal_emit("city_transferred", pcity, pgiver,
pdest, "trade");
}
break;
}
break;
}
case CLAUSE_CEASEFIRE:
if (old_diplstate == DS_ALLIANCE) {
pgiver_seen_units = get_units_seen_via_ally(pgiver, pdest);
......
ceasefire_length = MAX(1, ceasefire_length);
ds_giverdest->turns_left = ceasefire_length;
ds_destgiver->turns_left = ceasefire_length;
notify_player(pgiver, NULL, E_TREATY_CEASEFIRE, ftc_server,
notify_player(pgiver, nullptr, E_TREATY_CEASEFIRE, ftc_server,
_("You agree on a cease-fire with %s."),
player_name(pdest));
notify_player(pdest, NULL, E_TREATY_CEASEFIRE, ftc_server,
notify_player(pdest, nullptr, E_TREATY_CEASEFIRE, ftc_server,
_("You agree on a cease-fire with %s."),
player_name(pgiver));
if (old_diplstate == DS_ALLIANCE) {
......
}
worker_refresh_required = TRUE;
break;
break;
case CLAUSE_PEACE:
if (old_diplstate == DS_ALLIANCE) {
pgiver_seen_units = get_units_seen_via_ally(pgiver, pdest);
......
armistice_length = MAX(1, armistice_length);
ds_giverdest->turns_left = armistice_length;
ds_destgiver->turns_left = armistice_length;
notify_player(pgiver, NULL, E_TREATY_PEACE, ftc_server,
notify_player(pgiver, nullptr, E_TREATY_PEACE, ftc_server,
/* TRANS: ... the Poles ... Polish territory */
PL_("You agree on an armistice with the %s. In %d turn, "
"it will become a peace treaty. Move your "
......
nation_plural_for_player(pdest),
armistice_length,
nation_adjective_for_player(pdest));
notify_player(pdest, NULL, E_TREATY_PEACE, ftc_server,
notify_player(pdest, nullptr, E_TREATY_PEACE, ftc_server,
/* TRANS: ... the Poles ... Polish territory */
PL_("You agree on an armistice with the %s. In %d turn, "
"it will become a peace treaty. Move your "
......
}
worker_refresh_required = TRUE;
break;
break;
case CLAUSE_ALLIANCE:
set_diplstate_type(ds_giverdest, ds_destgiver, DS_ALLIANCE);
notify_player(pgiver, NULL, E_TREATY_ALLIANCE, ftc_server,
notify_player(pgiver, nullptr, E_TREATY_ALLIANCE, ftc_server,
_("You agree on an alliance with %s."),
player_name(pdest));
notify_player(pdest, NULL, E_TREATY_ALLIANCE, ftc_server,
notify_player(pdest, nullptr, E_TREATY_ALLIANCE, ftc_server,
_("You agree on an alliance with %s."),
player_name(pgiver));
give_allied_visibility(pgiver, pdest);
give_allied_visibility(pdest, pgiver);
worker_refresh_required = TRUE;
break;
break;
case CLAUSE_VISION:
give_shared_vision(pgiver, pdest);
notify_player(pgiver, NULL, E_TREATY_SHARED_VISION, ftc_server,
give_shared_vision(pgiver, pdest);
notify_player(pgiver, nullptr, E_TREATY_SHARED_VISION, ftc_server,
_("You give shared vision to %s."),
player_name(pdest));
notify_player(pdest, NULL, E_TREATY_SHARED_VISION, ftc_server,
notify_player(pdest, nullptr, E_TREATY_SHARED_VISION, ftc_server,
_("%s gives you shared vision."),
player_name(pgiver));
/* Yes, shared vision may let us to _know_ tiles
* within radius of our own city. */
worker_refresh_required = TRUE;
break;
break;
case CLAUSE_SHARED_TILES:
BV_SET(pgiver->gives_shared_tiles, player_index(pdest));
notify_player(pgiver, NULL, E_TREATY_SHARED_TILES, ftc_server,
notify_player(pgiver, nullptr, E_TREATY_SHARED_TILES, ftc_server,
_("You share your tiles with %s."),
player_name(pdest));
notify_player(pdest, NULL, E_TREATY_SHARED_TILES, ftc_server,
notify_player(pdest, nullptr, E_TREATY_SHARED_TILES, ftc_server,
_("%s shares their tiles with you."),
player_name(pgiver));
worker_refresh_required = TRUE;
......
cleanup:
treaty_remove(ptreaty);
send_player_all_c(pplayer, NULL);
send_player_all_c(pother, NULL);
send_player_all_c(pplayer, nullptr);
send_player_all_c(pother, nullptr);
}
}
......
struct player *pgiver = player_by_number(giver);
struct player *pother = player_by_number(counterpart);
if (NULL == pother || pplayer == pother || NULL == pgiver) {
if (pother == nullptr || pplayer == pother || pgiver == nullptr) {
return;
}
......
if (ptreaty && remove_clause(ptreaty, pgiver, type, value)) {
dlsend_packet_diplomacy_remove_clause(pplayer->connections,
player_number(pother), giver, type,
value);
player_number(pother), giver, type,
value);
dlsend_packet_diplomacy_remove_clause(pother->connections,
player_number(pplayer), giver, type,
value);
player_number(pplayer), giver, type,
value);
call_treaty_evaluate(pplayer, pother, ptreaty);
call_treaty_evaluate(pother, pplayer, ptreaty);
}
......
struct player *pgiver = player_by_number(giver);
struct player *pother = player_by_number(counterpart);
if (NULL == pother || pplayer == pother || NULL == pgiver) {
if (pother == nullptr || pplayer == pother || pgiver == nullptr) {
return;
}
......
ptreaty = find_treaty(pplayer, pother);
if (ptreaty != NULL
&& add_clause(ptreaty, pgiver, type, value, NULL)) {
if (ptreaty != nullptr
&& add_clause(ptreaty, pgiver, type, value, nullptr)) {
/*
* If we are trading cities, then it is possible that
* the dest is unaware of it's existence. We have 2 choices,
......
struct city *pcity = game_city_by_number(value);
if (pcity && !map_is_known_and_seen(pcity->tile, pother, V_MAIN)) {
give_citymap_from_player_to_player(pcity, pplayer, pother);
give_citymap_from_player_to_player(pcity, pplayer, pother);
}
}
dlsend_packet_diplomacy_create_clause(pplayer->connections,
player_number(pother), giver, type,
value);
player_number(pother), giver, type,
value);
dlsend_packet_diplomacy_create_clause(pother->connections,
player_number(pplayer), giver, type,
value);
player_number(pplayer), giver, type,
value);
call_treaty_evaluate(pplayer, pother, ptreaty);
call_treaty_evaluate(pother, pplayer, ptreaty);
}
......
if (ptreaty) {
dlsend_packet_diplomacy_cancel_meeting(pother->connections,
player_number(pplayer),
player_number(pplayer));
notify_player(pother, NULL, E_DIPLOMACY, ftc_server,
player_number(pplayer),
player_number(pplayer));
notify_player(pother, nullptr, E_DIPLOMACY, ftc_server,
_("%s canceled the meeting!"),
player_name(pplayer));
/* Need to send to pplayer too, for multi-connects: */
dlsend_packet_diplomacy_cancel_meeting(pplayer->connections,
player_number(pother),
player_number(pplayer));
notify_player(pplayer, NULL, E_DIPLOMACY, ftc_server,
player_number(pother),
player_number(pplayer));
notify_player(pplayer, nullptr, E_DIPLOMACY, ftc_server,
_("Meeting with %s canceled."),
player_name(pother));
treaty_remove(ptreaty);
......
Handle meeting cancelling request.
**************************************************************************/
void handle_diplomacy_cancel_meeting_req(struct player *pplayer,
int counterpart)
int counterpart)
{
struct player *pother = player_by_number(counterpart);
if (NULL == pother || pplayer == pother) {
if (pother == nullptr || pplayer == pother) {
return;
}
......
{
struct player *pother = player_by_number(counterpart);
if (NULL == pother || pplayer == pother) {
if (pother == nullptr || pplayer == pother) {
return;
}
......
if (get_player_bonus(pplayer, EFT_NO_DIPLOMACY) > 0
|| get_player_bonus(pother, EFT_NO_DIPLOMACY) > 0) {
notify_player(pplayer, NULL, E_DIPLOMACY, ftc_server,
notify_player(pplayer, nullptr, E_DIPLOMACY, ftc_server,
_("Your diplomatic envoy was decapitated!"));
return;
}
......
treaty_add(ptreaty);
dlsend_packet_diplomacy_init_meeting(pplayer->connections,
player_number(pother),
player_number(pplayer));
player_number(pother),
player_number(pplayer));
dlsend_packet_diplomacy_init_meeting(pother->connections,
player_number(pplayer),
player_number(pplayer));
player_number(pplayer),
player_number(pplayer));
}
}
......
treaty->accept0 = FALSE;
treaty->accept1 = FALSE;
dlsend_packet_diplomacy_accept_treaty(pplayer->connections,
player_number(pplayer2),
FALSE,
FALSE);
player_number(pplayer2),
FALSE,
FALSE);
dlsend_packet_diplomacy_accept_treaty(pplayer2->connections,
player_number(pplayer),
FALSE,
FALSE);
FALSE,
FALSE);
} players_iterate_end;
}
    (1-1/1)