109 if ((ptreaty->plr0 ==
plr0 && ptreaty->plr1 ==
plr1)
110 || (ptreaty->plr0 ==
plr1 && ptreaty->plr1 ==
plr0)) {
122 static enum diplstate_type
dst_closest(
enum diplstate_type a,
123 enum diplstate_type b)
125 static int how_close[DS_LAST];
126 how_close[DS_NO_CONTACT] = 0;
127 how_close[DS_WAR] = 1;
128 how_close[DS_CEASEFIRE] = 2;
129 how_close[DS_ARMISTICE] = 3;
130 how_close[DS_PEACE] = 4;
131 how_close[DS_ALLIANCE] = 5;
132 how_close[DS_TEAM] = 6;
134 if (how_close[a] < how_close[b]) {
150 bool *player_accept, *other_accept;
152 bool worker_refresh_required =
false;
155 if (
nullptr == pother || pplayer == pother) {
165 if (ptreaty->
plr0 == pplayer) {
166 player_accept = &ptreaty->
accept0;
167 other_accept = &ptreaty->
accept1;
169 player_accept = &ptreaty->
accept1;
170 other_accept = &ptreaty->
accept0;
173 if (!*player_accept) {
179 struct city *pcity =
nullptr;
181 if (pclause->from == pplayer) {
185 nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
188 nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
191 "Requirements of a clause between %s and %s not fullfilled",
198 switch (pclause->type) {
201 qCritical(
"%s tried to give embassy to %s, who already "
210 game.
info.tech_trade_allow_holes)) {
213 qCritical(
"Treaty: %s can't have tech %s",
218 _(
"The %s can't accept %s."),
225 qCritical(
"Nation %s try to give unknown tech %s to nation %s.",
231 _(
"You don't have tech %s, you can't accept treaty."),
240 _(
"City you are trying to give no longer exists, "
241 "you can't accept treaty."));
247 _(
"You are not owner of %s, you can't accept treaty."),
253 _(
"Your capital (%s) is requested, "
254 "you can't accept treaty."),
259 case CLAUSE_CEASEFIRE:
271 case CLAUSE_ALLIANCE:
275 _(
"You cannot form an alliance because you are "
276 "at war with an ally of %s."),
280 _(
"You cannot form an alliance because %s is "
281 "at war with an ally of yours."),
291 _(
"You don't have enough gold, "
292 "you can't accept treaty."));
303 *player_accept = !*player_accept;
305 dlsend_packet_diplomacy_accept_treaty(pplayer->
connections,
307 *player_accept, *other_accept);
308 dlsend_packet_diplomacy_accept_treaty(pother->
connections,
310 *other_accept, *player_accept);
313 int nclauses = clause_list_size(ptreaty->
clauses);
315 dlsend_packet_diplomacy_cancel_meeting(
317 dlsend_packet_diplomacy_cancel_meeting(
321 PL_(
"A treaty containing %d clause was agreed upon.",
322 "A treaty containing %d clauses was agreed upon.",
326 PL_(
"A treaty containing %d clause was agreed upon.",
327 "A treaty containing %d clauses was agreed upon.",
338 if (pclause->from == pother) {
342 nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
345 nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
348 _(
"Clause requirements are no longer fulfilled. "
349 "Treaty with %s canceled!"),
352 _(
"Clause requirements are no longer fulfilled. "
353 "Treaty with %s canceled!"),
359 if (pclause->from == pother) {
360 switch (pclause->type) {
365 _(
"One of the cities the %s are giving away"
366 " is destroyed! Treaty canceled!"),
369 _(
"One of the cities the %s are giving away"
370 " is destroyed! Treaty canceled!"),
376 _(
"The %s no longer control %s! "
381 _(
"The %s no longer control %s! "
389 _(
"Your capital (%s) is requested, "
390 "you can't accept treaty."),
396 case CLAUSE_ALLIANCE:
410 case CLAUSE_CEASEFIRE:
419 _(
"The %s don't have the promised amount "
420 "of gold! Treaty canceled!"),
423 _(
"The %s don't have the promised amount "
424 "of gold! Treaty canceled!"),
440 struct player *pgiver = pclause->from;
441 struct player *pdest = (pplayer == pgiver) ? pother : pplayer;
446 enum diplstate_type old_diplstate = ds_giverdest->
type;
450 switch (pclause->type) {
456 _(
"%s allowed you to create an embassy!"),
459 case CLAUSE_ADVANCE: {
464 const char *advance_name;
468 qDebug(
"Nation %s already know tech %s, "
469 "that %s want to give them.",
478 _(
"You are taught the knowledge of %s."),
485 sizeof(research_name));
487 _(
"You have acquired %s thanks to the %s "
488 "treaty with the %s."),
492 presearch, pgiver, E_TECH_EMBASSY,
ftc_server,
494 Q_(
"?fromplr:The %s have acquired %s from the %s."),
506 pclause->value * (100 -
game.
server.diplgoldcost) / 100;
510 PL_(
"You get %d gold.",
"You get %d gold.", received),
517 _(
"You receive the %s worldmap."),
520 worker_refresh_required =
true;
526 _(
"You receive the %s seamap."),
529 worker_refresh_required =
true;
535 qCritical(
"Treaty city id %d not found - skipping clause.",
541 _(
"You receive the city of %s from %s."),
545 _(
"You give the city of %s to %s."),
city_link(pcity),
555 case CLAUSE_CEASEFIRE:
556 if (old_diplstate == DS_ALLIANCE) {
560 ds_giverdest->
type = DS_CEASEFIRE;
562 ds_destgiver->
type = DS_CEASEFIRE;
565 _(
"You agree on a cease-fire with %s."),
568 _(
"You agree on a cease-fire with %s."),
570 if (old_diplstate == DS_ALLIANCE) {
572 pgiver, pdest, pgiver_seen_units, pdest_seen_units);
573 unit_list_destroy(pgiver_seen_units);
574 unit_list_destroy(pdest_seen_units);
577 worker_refresh_required =
true;
580 if (old_diplstate == DS_ALLIANCE) {
584 ds_giverdest->
type = DS_ARMISTICE;
585 ds_destgiver->
type = DS_ARMISTICE;
595 PL_(
"You agree on an armistice with the %s. In %d turn, "
596 "it will become a peace treaty. Move your "
597 "military units out of %s territory to avoid them "
599 "You agree on an armistice with the %s. In %d turns, "
600 "it will become a peace treaty. Move any "
601 "military units out of %s territory to avoid them "
609 PL_(
"You agree on an armistice with the %s. In %d turn, "
610 "it will become a peace treaty. Move your "
611 "military units out of %s territory to avoid them "
613 "You agree on an armistice with the %s. In %d turns, "
614 "it will become a peace treaty. Move any "
615 "military units out of %s territory to avoid them "
620 if (old_diplstate == DS_ALLIANCE) {
622 pgiver, pdest, pgiver_seen_units, pdest_seen_units);
623 unit_list_destroy(pgiver_seen_units);
624 unit_list_destroy(pdest_seen_units);
627 worker_refresh_required =
true;
629 case CLAUSE_ALLIANCE:
630 ds_giverdest->
type = DS_ALLIANCE;
631 ds_destgiver->
type = DS_ALLIANCE;
637 _(
"You agree on an alliance with %s."),
640 _(
"You agree on an alliance with %s."),
645 worker_refresh_required =
true;
650 _(
"You give shared vision to %s."),
657 worker_refresh_required =
true;
660 fc_assert(pclause->type != CLAUSE_COUNT);
671 if (worker_refresh_required) {
678 treaty_list_remove(
treaties, ptreaty);
706 int counterpart,
int giver,
707 enum clause_type type,
int value)
713 if (
nullptr == pother || pplayer == pother ||
nullptr == pgiver) {
717 if (pgiver != pplayer && pgiver != pother) {
723 if (ptreaty &&
remove_clause(ptreaty, pgiver, type, value)) {
724 dlsend_packet_diplomacy_remove_clause(
726 dlsend_packet_diplomacy_remove_clause(
737 int counterpart,
int giver,
738 enum clause_type type,
int value)
744 if (
nullptr == pother || pplayer == pother ||
nullptr == pgiver) {
748 if (pgiver != pplayer && pgiver != pother) {
754 if (ptreaty &&
add_clause(ptreaty, pgiver, type, value)) {
763 if (type == CLAUSE_CITY) {
771 dlsend_packet_diplomacy_create_clause(
773 dlsend_packet_diplomacy_create_clause(
790 dlsend_packet_diplomacy_cancel_meeting(
795 dlsend_packet_diplomacy_cancel_meeting(
799 treaty_list_remove(
treaties, ptreaty);
813 if (
nullptr == pother || pplayer == pother) {
828 if (
nullptr == pother || pplayer == pother) {
839 _(
"Your diplomatic envoy was decapitated!"));
844 auto *ptreaty =
new Treaty;
846 treaty_list_prepend(
treaties, ptreaty);
848 dlsend_packet_diplomacy_init_meeting(
850 dlsend_packet_diplomacy_init_meeting(
872 dsend_packet_diplomacy_init_meeting(dest,
player_number(other),
876 dsend_packet_diplomacy_create_clause(dest,
player_number(other),
878 pclause->type, pclause->value);
882 if (ptreaty->
plr0 == pplayer) {
883 dsend_packet_diplomacy_accept_treaty(
886 dsend_packet_diplomacy_accept_treaty(
922 dlsend_packet_diplomacy_accept_treaty(
924 dlsend_packet_diplomacy_accept_treaty(
925 pplayer2->connections,
player_number(pplayer),
false,
false);
#define CALL_PLR_AI_FUNC(_func, _player,...)
struct player * city_owner(const struct city *pcity)
Return the owner of the city.
bool is_capital(const struct city *pcity)
Return TRUE iff this city is its nation's capital.
struct tile * city_tile(const struct city *pcity)
Return the tile location of the city.
static struct treaty_list * treaties
void establish_embassy(struct player *pplayer, struct player *aplayer)
Create an embassy.
void diplhand_init()
Initialize diplhand module.
void send_diplomatic_meetings(struct connection *dest)
Send information on any on-going diplomatic meetings for connection's player.
struct Treaty * find_treaty(struct player *plr0, struct player *plr1)
Find currently active treaty between two players.
void free_treaties()
Free all the treaties currently in treaty list.
void handle_diplomacy_remove_clause_req(struct player *pplayer, int counterpart, int giver, enum clause_type type, int value)
Handle request to remove clause from treaty.
void handle_diplomacy_create_clause_req(struct player *pplayer, int counterpart, int giver, enum clause_type type, int value)
Handle request to add clause to treaty between two players.
void diplhand_free()
Free all the resources allocated by diplhand.
static void call_treaty_accepted(struct player *pplayer, struct player *aplayer, struct Treaty *ptreaty)
Calls treaty_accepted function if such is set for AI player.
struct treaty_list * get_all_treaties()
Get treaty list.
void reject_all_treaties(struct player *pplayer)
Reject all treaties currently being negotiated.
void handle_diplomacy_init_meeting_req(struct player *pplayer, int counterpart)
Handle meeting opening request.
void cancel_all_meetings(struct player *pplayer)
Cancels all meetings of player.
void handle_diplomacy_cancel_meeting_req(struct player *pplayer, int counterpart)
Handle meeting cancelling request.
static void call_treaty_evaluate(struct player *pplayer, struct player *aplayer, struct Treaty *ptreaty)
Calls treaty_evaluate function if such is set for AI player.
static enum diplstate_type dst_closest(enum diplstate_type a, enum diplstate_type b)
Return the closest of the two diplstate types.
static void really_diplomacy_cancel_meeting(struct player *pplayer, struct player *pother)
Cancel meeting.
void handle_diplomacy_accept_treaty_req(struct player *pplayer, int counterpart)
pplayer clicked the accept button.
#define treaty_list_iterate(list, p)
#define treaty_list_iterate_end
bool add_clause(struct Treaty *ptreaty, struct player *pfrom, enum clause_type type, int val)
Add clause to treaty.
struct clause_info * clause_info_get(enum clause_type type)
Free memory associated with clause infos.
void clear_treaty(struct Treaty *ptreaty)
Free the clauses of a treaty.
void init_treaty(struct Treaty *ptreaty, struct player *plr0, struct player *plr1)
Initialize treaty structure between two players.
bool remove_clause(struct Treaty *ptreaty, struct player *pfrom, enum clause_type type, int val)
Remove clause from treaty.
bool could_meet_with_player(const struct player *pplayer, const struct player *aplayer)
Returns TRUE iff pplayer could do diplomatic meetings with aplayer.
#define clause_list_iterate_end
#define clause_list_iterate(clauselist, pclause)
#define is_pact_clause(x)
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Returns the effect bonus for a player.
#define PL_(String1, String2, n)
const struct ft_color ftc_server
const char * city_link(const struct city *pcity)
Get a text link to a city.
struct city * game_city_by_number(int id)
Often used function to get a city pointer from a city ID.
#define fc_assert(condition)
#define fc_assert_action(condition, action)
void give_map_from_player_to_player(struct player *pfrom, struct player *pdest)
Give information about whole map (all tiles) from player to player.
void give_seamap_from_player_to_player(struct player *pfrom, struct player *pdest)
Give information about all oceanic tiles from player to player.
void give_citymap_from_player_to_player(struct city *pcity, struct player *pfrom, struct player *pdest)
Give information about tiles within city radius from player to player.
bool map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Returns whether the layer 'vlayer' of the tile 'ptile' is known and seen by the player 'pplayer'.
void give_shared_vision(struct player *pfrom, struct player *pto)
Starts shared vision between two players.
const char * nation_rule_name(const struct nation_type *pnation)
Return the (untranslated) rule name of the nation (adjective form).
const char * nation_plural_for_player(const struct player *pplayer)
Return the (translated) plural noun of the given nation of a player.
const char * nation_adjective_for_player(const struct player *pplayer)
Return the (translated) adjective for the given nation of a player.
struct nation_type * nation_of_player(const struct player *pplayer)
Return the nation of a player.
void notify_research(const struct research *presearch, const struct player *exclude, enum event_type event, const struct ft_color color, const char *format,...)
Sends a message to all players that share research.
void notify_player(const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Similar to notify_conn_packet (see also), but takes player as "destination".
void notify_research_embassies(const struct research *presearch, const struct player *exclude, enum event_type event, const struct ft_color color, const char *format,...)
Sends a message to all players that have embassies with someone who shares research.
struct player * player_by_number(const int player_id)
Return struct player pointer for the given player index.
int player_number(const struct player *pplayer)
Return the player index/number/id.
enum dipl_reason pplayer_can_make_treaty(const struct player *p1, const struct player *p2, enum diplstate_type treaty)
Returns true iff p1 can make given treaty with p2.
bool player_has_real_embassy(const struct player *pplayer, const struct player *pplayer2)
Returns whether pplayer has a real embassy with pplayer2, established from a diplomat,...
int player_index(const struct player *pplayer)
Return the player index.
const char * player_name(const struct player *pplayer)
Return the leader name of the player.
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Returns diplomatic state type between two players.
#define players_iterate_end
@ DIPL_ALLIANCE_PROBLEM_THEM
@ DIPL_ALLIANCE_PROBLEM_US
#define players_iterate(_pplayer)
static bool is_barbarian(const struct player *pplayer)
void send_player_all_c(struct player *src, struct conn_list *dest)
Send all information about a player (player_info and all player_diplstates) to the given connections.
void update_players_after_alliance_breakup(struct player *pplayer, struct player *pplayer2, const struct unit_list *pplayer_seen_units, const struct unit_list *pplayer2_seen_units)
After the alliance is breaken, we need to do two things:
bool are_reqs_active(const struct player *target_player, const struct player *other_player, const struct city *target_city, const struct impr_type *target_building, const struct tile *target_tile, const struct unit *target_unit, const struct unit_type *target_unittype, const struct output_type *target_output, const struct specialist *target_specialist, const struct action *target_action, const struct requirement_vector *reqs, const enum req_problem_type prob_type, const enum vision_layer vision_layer, const enum national_intelligence nintel)
Checks the requirement(s) to see if they are active on the given target.
struct research * research_get(const struct player *pplayer)
Returns the research structure associated with the player.
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Returns state of the tech for current research.
bool research_invention_gettable(const struct research *presearch, const Tech_type_id tech, bool allow_holes)
Returns TRUE iff the given tech can be given to the players sharing the research immediately.
int research_pretty_name(const struct research *presearch, char *buf, size_t buf_len)
Set in 'buf' the name of the research owner.
void script_server_signal_emit(const char *signal_name,...)
Invoke all the callback functions attached to a given signal.
#define BAD_HEURISTIC_INIT(_ini_val_)
struct clause_list * clauses
struct civ_game::@28::@32 server
struct packet_game_info info
struct requirement_vector receiver_reqs
struct requirement_vector giver_reqs
enum diplstate_type max_state
struct conn_list * connections
struct player_economic economic
const char * advance_rule_name(const struct advance *padvance)
Return the (untranslated) rule name of the advance/technology.
struct advance * advance_by_number(const Tech_type_id atype)
Return the advance for the given advance index.
const char * advance_name_translation(const struct advance *padvance)
Return the (translated) name of the given advance/technology.