<URL: http://bugs.freeciv.org/Ticket/Display.html?id=39730 >
Forgot to attach the proposed patch:
Index: server/cityhand.c
===================================================================
--- server/cityhand.c (revision 13743)
+++ server/cityhand.c (working copy)
@@ -411,19 +411,3 @@
send_city_info(pplayer, pcity);
}
-
-/***************************************************************
- Tell the client the cost of inciting a revolt or bribing a unit.
- Only send result back to the requesting connection, not all
- connections for that player.
-***************************************************************/
-void handle_city_incite_inq(struct connection *pc, int city_id)
-{
- struct player *pplayer = pc->player;
- struct city *pcity = find_city_by_id(city_id);
-
- if (pplayer && pcity) {
- dsend_packet_city_incite_info(pc, city_id,
- city_incite_cost(pplayer, pcity));
- }
-}
Index: server/diplomats.c
===================================================================
--- server/diplomats.c (revision 13743)
+++ server/diplomats.c (working copy)
@@ -208,8 +208,8 @@
Only send back to the originating connection, if there is one. (?)
****************************************************************************/
-void spy_get_sabotage_list(struct player *pplayer, struct unit *pdiplomat,
- struct city *pcity)
+void spy_send_sabotage_list(struct connection *pc, struct unit *pdiplomat,
+ struct city *pcity)
{
struct packet_city_sabotage_list packet;
@@ -224,10 +224,7 @@
packet.diplomat_id = pdiplomat->id;
packet.city_id = pcity->id;
- lsend_packet_city_sabotage_list(player_reply_dest(pplayer), &packet);
-
- /* this may cause a diplomatic incident */
- maybe_cause_incident(SPY_GET_SABOTAGE_LIST, pplayer, NULL, pcity);
+ send_packet_city_sabotage_list(pc, &packet);
}
/******************************************************************************
@@ -390,8 +387,9 @@
struct unit *pvictim)
{
struct player *uplayer;
- int diplomat_id;
struct tile *victim_tile;
+ int bribe_cost;
+ int diplomat_id;
bool vet = FALSE;
struct unit *gained_unit = NULL;
@@ -405,13 +403,6 @@
freelog (LOG_DEBUG, "bribe-unit: unit: %d", pdiplomat->id);
- /* Update bribe cost. */
- if (pvictim->bribe_cost == -1) {
- freelog (LOG_ERROR, "Bribe cost -1 in diplomat_bribe by %s",
- pplayer->name);
- pvictim->bribe_cost = unit_bribe_cost (pvictim);
- }
-
/* Check for unit from a bribable government. */
if (get_player_bonus(uplayer, EFT_UNBRIBABLE_UNITS)) {
notify_player(pplayer, pdiplomat->tile,
@@ -420,8 +411,11 @@
return;
}
+ /* Get bribe cost, ignoring any previously saved value. */
+ bribe_cost = unit_bribe_cost(pvictim);
+
/* If player doesn't have enough gold, can't bribe. */
- if (pplayer->economic.gold < pvictim->bribe_cost) {
+ if (pplayer->economic.gold < bribe_cost) {
notify_player(pplayer, pdiplomat->tile,
E_MY_DIPLOMAT_FAILED,
_("You don't have enough gold to"
@@ -478,7 +472,7 @@
pplayer->name);
/* This costs! */
- pplayer->economic.gold -= pvictim->bribe_cost;
+ pplayer->economic.gold -= bribe_cost;
/* This may cause a diplomatic incident */
maybe_cause_incident(DIPLOMAT_BRIBE, pplayer, pvictim, NULL);
@@ -691,7 +685,7 @@
return;
}
- /* Get incite cost. */
+ /* Get incite cost, ignoring any previously saved value. */
revolt_cost = city_incite_cost(pplayer, pcity);
/* If player doesn't have enough gold, can't incite a revolt. */
@@ -1298,7 +1292,6 @@
case DIPLOMAT_MOVE:
case DIPLOMAT_EMBASSY:
case DIPLOMAT_INVESTIGATE:
- case SPY_GET_SABOTAGE_LIST:
return; /* These are not considered offences */
case DIPLOMAT_ANY_ACTION:
case SPY_POISON:
Index: server/diplomats.h
===================================================================
--- server/diplomats.h (revision 13743)
+++ server/diplomats.h (working copy)
@@ -21,8 +21,8 @@
struct city *pcity);
void diplomat_investigate(struct player *pplayer, struct unit *pdiplomat,
struct city *pcity);
-void spy_get_sabotage_list(struct player *pplayer, struct unit *pdiplomat,
- struct city *pcity);
+void spy_send_sabotage_list(struct connection *pc, struct unit *pdiplomat,
+ struct city *pcity);
void spy_poison(struct player *pplayer, struct unit *pdiplomat,
struct city *pcity);
void spy_sabotage_unit(struct player *pplayer, struct unit *pdiplomat,
Index: server/unithand.c
===================================================================
--- server/unithand.c (revision 13743)
+++ server/unithand.c (working copy)
@@ -166,28 +166,67 @@
}
}
-/***************************************************************
- Tell the client the cost of inciting a revolt or bribing a unit.
+/**************************************************************************
+ Tell the client the cost of bribing a unit, inciting a revolt, or
+ any other parameters needed for action.
+
Only send result back to the requesting connection, not all
connections for that player.
-***************************************************************/
-void handle_unit_bribe_inq(struct connection *pc, int unit_id)
+**************************************************************************/
+void handle_unit_diplomat_query(struct connection *pc,
+ int diplomat_id,
+ int target_id,
+ int value,
+ enum diplomat_actions action_type)
{
struct player *pplayer = pc->player;
- struct unit *punit = find_unit_by_id(unit_id);
+ struct unit *pdiplomat = player_find_unit_by_id(pplayer, diplomat_id);
+ struct unit *punit = find_unit_by_id(target_id);
+ struct city *pcity = find_city_by_id(target_id);
- if (pplayer && punit) {
- punit->bribe_cost = unit_bribe_cost(punit);
- dsend_packet_unit_bribe_info(pc, unit_id, punit->bribe_cost);
+ if (!pdiplomat || !unit_has_type_flag(pdiplomat, F_DIPLOMAT)) {
+ return;
}
+
+ switch (action_type) {
+ case DIPLOMAT_BRIBE:
+ if (punit && diplomat_can_do_action(pdiplomat, DIPLOMAT_BRIBE,
+ punit->tile)) {
+ dsend_packet_unit_diplomat_answer(pc,
+ diplomat_id, target_id,
+ unit_bribe_cost(punit),
+ action_type);
+ }
+ break;
+ case DIPLOMAT_INCITE:
+ if (pcity && diplomat_can_do_action(pdiplomat, DIPLOMAT_INCITE,
+ pcity->tile)) {
+ dsend_packet_unit_diplomat_answer(pc,
+ diplomat_id, target_id,
+ city_incite_cost(pplayer, pcity),
+ action_type);
+ }
+ break;
+ case DIPLOMAT_SABOTAGE:
+ if (pcity && diplomat_can_do_action(pdiplomat, DIPLOMAT_SABOTAGE,
+ pcity->tile)) {
+ spy_send_sabotage_list(pc, pdiplomat, pcity);
+ }
+ break;
+ default:
+ /* Nothing */
+ break;
+ };
}
-/***************************************************************
+/**************************************************************************
...
-***************************************************************/
-void handle_unit_diplomat_action(struct player *pplayer, int diplomat_id,
- enum diplomat_actions action_type,
- int target_id, int value)
+**************************************************************************/
+void handle_unit_diplomat_action(struct player *pplayer,
+ int diplomat_id,
+ int target_id,
+ int value,
+ enum diplomat_actions action_type)
{
struct unit *pdiplomat = player_find_unit_by_id(pplayer, diplomat_id);
struct unit *pvictim = find_unit_by_id(target_id);
@@ -256,12 +295,6 @@
diplomat_get_tech(pplayer, pdiplomat, pcity, value);
}
break;
- case SPY_GET_SABOTAGE_LIST:
- if(pcity && diplomat_can_do_action(pdiplomat, SPY_GET_SABOTAGE_LIST,
- pcity->tile)) {
- spy_get_sabotage_list(pplayer, pdiplomat, pcity);
- }
- break;
case DIPLOMAT_ANY_ACTION:
/* Nothing */
break;
@@ -1065,8 +1098,9 @@
} else {
die("Bug in unithand.c: no diplomat target.");
}
- dlsend_packet_unit_diplomat_popup_dialog(player_reply_dest(pplayer),
- punit->id, target_id);
+ dlsend_packet_unit_diplomat_answer(player_reply_dest(pplayer),
+ punit->id, target_id,
+ 0, DIPLOMAT_MOVE);
return FALSE;
} else if (!can_unit_move_to_tile(punit, pdesttile, igzoc)) {
notify_player(pplayer, punit->tile, E_BAD_COMMAND,
Index: common/unit.c
===================================================================
--- common/unit.c (revision 13743)
+++ common/unit.c (working copy)
@@ -108,8 +108,6 @@
return !pplayers_allied(city_owner(pcity), unit_owner(pdiplomat));
if(action==DIPLOMAT_ANY_ACTION)
return TRUE;
- if (action==SPY_GET_SABOTAGE_LIST && unit_has_type_flag(pdiplomat,
F_SPY))
- return pplayers_at_war(unit_owner(pdiplomat), city_owner(pcity));
}
} else { /* Action against a unit at a tile */
/* If it is made possible to do action against allied units
@@ -1435,7 +1433,6 @@
punit->ai.passenger = 0;
punit->ai.bodyguard = 0;
punit->ai.charge = 0;
- punit->bribe_cost = -1; /* flag value */
punit->transported_by = -1;
punit->focus_status = FOCUS_AVAIL;
punit->ord_map = 0;
Index: common/unit.h
===================================================================
--- common/unit.h (revision 13743)
+++ common/unit.h (working copy)
@@ -23,20 +23,37 @@
/* Changing this enum will break savegame and network compatability. */
enum unit_activity {
- ACTIVITY_IDLE, ACTIVITY_POLLUTION, ACTIVITY_ROAD, ACTIVITY_MINE,
- ACTIVITY_IRRIGATE, ACTIVITY_FORTIFIED, ACTIVITY_FORTRESS, ACTIVITY_SENTRY,
- ACTIVITY_RAILROAD, ACTIVITY_PILLAGE, ACTIVITY_GOTO, ACTIVITY_EXPLORE,
- ACTIVITY_TRANSFORM, ACTIVITY_UNKNOWN, ACTIVITY_AIRBASE, ACTIVITY_FORTIFYING,
- ACTIVITY_FALLOUT,
- ACTIVITY_PATROL_UNUSED, /* Needed for savegame compatability. */
+ ACTIVITY_IDLE = 0,
+ ACTIVITY_POLLUTION = 1,
+ ACTIVITY_ROAD = 2,
+ ACTIVITY_MINE = 3,
+ ACTIVITY_IRRIGATE = 4,
+ ACTIVITY_FORTIFIED = 5,
+ ACTIVITY_FORTRESS = 6,
+ ACTIVITY_SENTRY = 7,
+ ACTIVITY_RAILROAD = 8,
+ ACTIVITY_PILLAGE = 9,
+ ACTIVITY_GOTO = 10,
+ ACTIVITY_EXPLORE = 11,
+ ACTIVITY_TRANSFORM = 12,
+ ACTIVITY_UNKNOWN = 13, /* savegame compatability. */
+ ACTIVITY_AIRBASE = 14,
+ ACTIVITY_FORTIFYING = 15,
+ ACTIVITY_FALLOUT = 16,
+ ACTIVITY_PATROL_UNUSED = 17, /* savegame compatability. */
ACTIVITY_LAST /* leave this one last */
};
/* Changing this enum will break network compatability. */
enum unit_orders {
- ORDER_MOVE, ORDER_ACTIVITY,
- ORDER_FULL_MP, ORDER_BUILD_CITY, ORDER_DISBAND, ORDER_BUILD_WONDER,
- ORDER_TRADEROUTE, ORDER_HOMECITY,
+ ORDER_MOVE = 0,
+ ORDER_ACTIVITY = 1,
+ ORDER_FULL_MP = 2,
+ ORDER_BUILD_CITY = 3,
+ ORDER_DISBAND = 4,
+ ORDER_BUILD_WONDER = 5,
+ ORDER_TRADEROUTE = 6,
+ ORDER_HOMECITY = 7,
/* and plenty more for later... */
ORDER_LAST
};
@@ -45,12 +62,17 @@
FOCUS_AVAIL, FOCUS_WAIT, FOCUS_DONE
};
+/* Changing this enum will break network compatability. */
enum diplomat_actions {
- DIPLOMAT_BRIBE, DIPLOMAT_EMBASSY, DIPLOMAT_SABOTAGE,
- DIPLOMAT_STEAL, DIPLOMAT_INCITE, SPY_POISON,
- DIPLOMAT_INVESTIGATE, SPY_SABOTAGE_UNIT,
- SPY_GET_SABOTAGE_LIST,
- DIPLOMAT_MOVE, /* move onto city square - only for allied cities */
+ DIPLOMAT_MOVE = 0, /* move onto city square - only for allied cities */
+ DIPLOMAT_EMBASSY = 1,
+ DIPLOMAT_BRIBE = 2,
+ DIPLOMAT_INCITE = 3,
+ DIPLOMAT_INVESTIGATE = 4,
+ DIPLOMAT_SABOTAGE = 5,
+ DIPLOMAT_STEAL = 6,
+ SPY_POISON = 7,
+ SPY_SABOTAGE_UNIT = 8,
DIPLOMAT_ANY_ACTION /* leave this one last */
};
@@ -136,7 +158,6 @@
int unhappiness;
int upkeep[O_MAX];
int fuel;
- int bribe_cost;
struct unit_ai ai;
enum unit_activity activity;
struct tile *goto_tile; /* May be NULL. */
Index: common/packets.def
===================================================================
--- common/packets.def (revision 13743)
+++ common/packets.def (working copy)
@@ -603,15 +603,8 @@
CITY city_id;
end
-PACKET_CITY_INCITE_INQ=33;cs,handle-per-conn,dsend
- CITY city_id;
-end
+# 33-34 removed in 2.1
-PACKET_CITY_INCITE_INFO=34;sc,dsend
- CITY city_id;
- GOLD cost;
-end
-
# For city name suggestions, client sends unit id of unit building the
# city. The server does not use the id, but sends it back to the
# client so that the client knows what to do with the suggestion when
@@ -851,14 +844,14 @@
CITY city_id;
end
-PACKET_UNIT_BRIBE_INQ=67;cs,handle-per-conn,dsend
- UNIT unit_id;
+PACKET_UNIT_DIPLOMAT_QUERY=66;cs,handle-per-conn,dsend
+ UNIT diplomat_id;
+ UNIT target_id; # city_id or unit_id target_id;
+ SINT16 value;
+ DIPLOMAT_ACTION action_type;
end
-PACKET_UNIT_BRIBE_INFO=68;sc,dsend
- UNIT unit_id;
- GOLD cost;
-end
+# 67-68 removed in 2.1
PACKET_UNIT_TYPE_UPGRADE=69;cs,dsend
UNIT_TYPE type;
@@ -866,14 +859,16 @@
PACKET_UNIT_DIPLOMAT_ACTION=70;cs,dsend
UNIT diplomat_id;
- DIPLOMAT_ACTION action_type;
UNIT target_id; # city_id or unit_id target_id;
SINT16 value;
+ DIPLOMAT_ACTION action_type;
end
-PACKET_UNIT_DIPLOMAT_POPUP_DIALOG=71;sc,dsend,lsend
+PACKET_UNIT_DIPLOMAT_ANSWER=71;sc,dsend,lsend
UNIT diplomat_id;
- UINT32 target_id;
+ UNIT target_id; # city_id or unit_id target_id;
+ GOLD cost;
+ DIPLOMAT_ACTION action_type;
end
PACKET_UNIT_CHANGE_ACTIVITY=72; cs,dsend
Index: common/city.h
===================================================================
--- common/city.h (revision 13743)
+++ common/city.h (working copy)
@@ -242,8 +242,6 @@
int food_stock;
int shield_stock;
int pollution;
- /* city can't be incited if INCITE_IMPOSSIBLE_COST */
- int incite_revolt_cost;
struct city_production production;
Index: ai/aidiplomat.c
===================================================================
--- ai/aidiplomat.c (revision 13743)
+++ ai/aidiplomat.c (working copy)
@@ -283,8 +283,8 @@
if (diplomat_can_do_action(punit, my_act, ctarget->tile)) { \
freelog(LOG_DIPLOMAT, "Player %s's diplomat %d does " #my_act \
" on %s", pplayer->name, punit->id, ctarget->name); \
- handle_unit_diplomat_action(pplayer, punit->id, my_act, \
- ctarget->id, my_val); \
+ handle_unit_diplomat_action(pplayer, punit->id, \
+ ctarget->id, my_val, my_act); \
return; \
}
@@ -498,7 +498,7 @@
continue;
}
/* Should we make the expense? */
- cost = pvictim->bribe_cost = unit_bribe_cost(pvictim);
+ cost = unit_bribe_cost(pvictim);
if (!threat) {
/* Don't empty our treasure without good reason! */
gold_avail = pplayer->economic.gold - ai_gold_reserve(pplayer);
@@ -524,8 +524,9 @@
}
if (diplomat_can_do_action(punit, DIPLOMAT_BRIBE, pos.tile)) {
- handle_unit_diplomat_action(pplayer, punit->id, DIPLOMAT_BRIBE,
- unit_list_get(ptile->units, 0)->id, -1);
+ handle_unit_diplomat_action(pplayer, punit->id,
+ unit_list_get(ptile->units, 0)->id, -1,
+ DIPLOMAT_BRIBE);
/* autoattack might kill us as we move in */
if (find_unit_by_id(sanity) && punit->moves_left > 0) {
return TRUE;
Index: client/control.c
===================================================================
--- client/control.c (revision 13743)
+++ client/control.c (working copy)
@@ -1149,9 +1149,26 @@
void request_diplomat_action(enum diplomat_actions action, int dipl_id,
int target_id, int value)
{
- dsend_packet_unit_diplomat_action(&aconnection,
dipl_id,action,target_id,value);
+ dsend_packet_unit_diplomat_action(&aconnection,
dipl_id,target_id,value,action);
}
+/**************************************************************************
+ Query a diplomat about costs and infrastructure.
+ - action : The action to be requested.
+ - dipl_id : The unit ID of the diplomatic unit.
+ - target_id : The ID of the target unit or city.
+ - value : For DIPLOMAT_STEAL or DIPLOMAT_SABOTAGE, the technology
+ or building to aim for (spies only).
+**************************************************************************/
+void request_diplomat_answer(enum diplomat_actions action, int dipl_id,
+ int target_id, int value)
+{
+ dsend_packet_unit_diplomat_query(&aconnection,
dipl_id,target_id,value,action);
+}
+
+/**************************************************************************
+ ...
+**************************************************************************/
void wakeup_sentried_units(struct tile *ptile)
{
if (!can_client_issue_orders()) {
Index: client/gui-gtk-2.0/diplomat_dialog.c
===================================================================
--- client/gui-gtk-2.0/diplomat_dialog.c (revision 13743)
+++ client/gui-gtk-2.0/diplomat_dialog.c (working copy)
@@ -67,7 +67,8 @@
static void diplomat_bribe_callback(GtkWidget *w, gpointer data)
{
if (find_unit_by_id(diplomat_id) && find_unit_by_id(diplomat_target_id)) {
- dsend_packet_unit_bribe_inq(&aconnection, diplomat_target_id);
+ request_diplomat_answer(DIPLOMAT_BRIBE, diplomat_id,
+ diplomat_target_id, 0);
}
gtk_widget_destroy(diplomat_dialog);
}
@@ -75,7 +76,7 @@
/****************************************************************
...
*****************************************************************/
-void popup_bribe_dialog(struct unit *punit)
+void popup_bribe_dialog(struct unit *punit, int cost)
{
GtkWidget *shell;
@@ -85,11 +86,11 @@
GTK_STOCK_OK, NULL, NULL, NULL);
gtk_window_present(GTK_WINDOW(shell));
return;
- } else if (game.player_ptr->economic.gold >= punit->bribe_cost) {
+ } else if (game.player_ptr->economic.gold >= cost) {
shell = gtk_message_dialog_new(NULL, 0,
GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
_("Bribe unit for %d gold?\nTreasury contains %d gold."),
- punit->bribe_cost, game.player_ptr->economic.gold);
+ cost, game.player_ptr->economic.gold);
gtk_window_set_title(GTK_WINDOW(shell), _("Bribe Enemy Unit"));
setup_dialog(shell, toplevel);
} else {
@@ -97,7 +98,7 @@
0,
GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,
_("Bribing the unit costs %d gold.\nTreasury contains %d gold."),
- punit->bribe_cost, game.player_ptr->economic.gold);
+ cost, game.player_ptr->economic.gold);
gtk_window_set_title(GTK_WINDOW(shell), _("Traitors Demand Too Much!"));
setup_dialog(shell, toplevel);
}
@@ -483,7 +484,7 @@
{
if(find_unit_by_id(diplomat_id) &&
(find_city_by_id(diplomat_target_id))) {
- request_diplomat_action(SPY_GET_SABOTAGE_LIST, diplomat_id,
+ request_diplomat_answer(DIPLOMAT_SABOTAGE, diplomat_id,
diplomat_target_id, 0);
}
gtk_widget_destroy(diplomat_dialog);
@@ -507,7 +508,8 @@
static void diplomat_incite_callback(GtkWidget *w, gpointer data)
{
if (find_unit_by_id(diplomat_id) && find_city_by_id(diplomat_target_id)) {
- dsend_packet_city_incite_inq(&aconnection, diplomat_target_id);
+ request_diplomat_answer(DIPLOMAT_INCITE, diplomat_id,
+ diplomat_target_id, 0);
}
gtk_widget_destroy(diplomat_dialog);
}
@@ -527,11 +529,11 @@
/****************************************************************
Popup the yes/no dialog for inciting, since we know the cost now
*****************************************************************/
-void popup_incite_dialog(struct city *pcity)
+void popup_incite_dialog(struct city *pcity, int cost)
{
GtkWidget *shell;
- if (pcity->incite_revolt_cost == INCITE_IMPOSSIBLE_COST) {
+ if (INCITE_IMPOSSIBLE_COST == cost) {
shell = gtk_message_dialog_new(NULL,
0,
GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,
@@ -539,12 +541,12 @@
pcity->name);
gtk_window_set_title(GTK_WINDOW(shell), _("City can't be incited!"));
setup_dialog(shell, toplevel);
- } else if (game.player_ptr->economic.gold >= pcity->incite_revolt_cost) {
+ } else if (game.player_ptr->economic.gold >= cost) {
shell = gtk_message_dialog_new(NULL,
0,
GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
_("Incite a revolt for %d gold?\nTreasury contains %d gold."),
- pcity->incite_revolt_cost, game.player_ptr->economic.gold);
+ cost, game.player_ptr->economic.gold);
gtk_window_set_title(GTK_WINDOW(shell), _("Incite a Revolt!"));
setup_dialog(shell, toplevel);
} else {
@@ -552,7 +554,7 @@
0,
GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,
_("Inciting a revolt costs %d gold.\nTreasury contains %d gold."),
- pcity->incite_revolt_cost, game.player_ptr->economic.gold);
+ cost, game.player_ptr->economic.gold);
gtk_window_set_title(GTK_WINDOW(shell), _("Traitors Demand Too Much!"));
setup_dialog(shell, toplevel);
}
Index: client/control.h
===================================================================
--- client/control.h (revision 13743)
+++ client/control.h (working copy)
@@ -101,6 +101,8 @@
void request_unit_select_same_type(struct unit_list *punits);
void request_diplomat_action(enum diplomat_actions action, int dipl_id,
int target_id, int value);
+void request_diplomat_answer(enum diplomat_actions action, int dipl_id,
+ int target_id, int value);
void request_toggle_city_outlines(void);
void request_toggle_map_grid(void);
void request_toggle_map_borders(void);
Index: client/gui-xaw/diplomat_dialog.c
===================================================================
--- client/gui-xaw/diplomat_dialog.c (revision 13743)
+++ client/gui-xaw/diplomat_dialog.c (working copy)
@@ -93,14 +93,15 @@
destroy_message_dialog(w);
if (find_unit_by_id(diplomat_id) && find_unit_by_id(diplomat_target_id)) {
- dsend_packet_unit_bribe_inq(&aconnection, diplomat_target_id);
+ request_diplomat_answer(DIPLOMAT_BRIBE, diplomat_id,
+ diplomat_target_id, 0);
}
}
/**************************************************************************
Creates and popups the bribe dialog
**************************************************************************/
-void popup_bribe_dialog(struct unit *punit)
+void popup_bribe_dialog(struct unit *punit, int cost)
{
char buf[128];
@@ -108,11 +109,11 @@
popup_message_dialog(toplevel, "diplomatbribedialog",
_("This unit cannot be bribed!"),
diplomat_bribe_no_callback, 0, 0, NULL);
- } else if(game.player_ptr->economic.gold>=punit->bribe_cost) {
+ } else if (game.player_ptr->economic.gold >= cost) {
my_snprintf(buf, sizeof(buf),
_("Bribe unit for %d gold?\n"
"Treasury contains %d gold."),
- punit->bribe_cost, game.player_ptr->economic.gold);
+ cost, game.player_ptr->economic.gold);
popup_message_dialog(toplevel, "diplomatbribedialog", buf,
diplomat_bribe_yes_callback, 0, 0,
diplomat_bribe_no_callback, 0, 0,
@@ -121,7 +122,7 @@
my_snprintf(buf, sizeof(buf),
_("Bribing the unit costs %d gold.\n"
"Treasury contains %d gold."),
- punit->bribe_cost, game.player_ptr->economic.gold);
+ cost, game.player_ptr->economic.gold);
popup_message_dialog(toplevel, "diplomatnogolddialog", buf,
diplomat_bribe_no_callback, 0, 0,
NULL);
@@ -558,7 +559,7 @@
if(find_unit_by_id(diplomat_id) &&
(find_city_by_id(diplomat_target_id))) {
- request_diplomat_action(SPY_GET_SABOTAGE_LIST, diplomat_id,
+ request_diplomat_answer(DIPLOMAT_SABOTAGE, diplomat_id,
diplomat_target_id, 0);
}
}
@@ -622,27 +623,28 @@
diplomat_dialog = NULL;
if (find_unit_by_id(diplomat_id) && find_city_by_id(diplomat_target_id)) {
- dsend_packet_city_incite_inq(&aconnection, diplomat_target_id);
+ request_diplomat_answer(DIPLOMAT_INCITE, diplomat_id,
+ diplomat_target_id, 0);
}
}
/**************************************************************************
Popup the yes/no dialog for inciting, since we know the cost now
**************************************************************************/
-void popup_incite_dialog(struct city *pcity)
+void popup_incite_dialog(struct city *pcity, int cost)
{
char buf[128];
- if (pcity->incite_revolt_cost == INCITE_IMPOSSIBLE_COST) {
+ if (INCITE_IMPOSSIBLE_COST == cost) {
my_snprintf(buf, sizeof(buf), _("You can't incite a revolt in %s."),
pcity->name);
popup_message_dialog(toplevel, "diplomatnogolddialog", buf,
diplomat_incite_no_callback, 0, 0, NULL);
- } else if (game.player_ptr->economic.gold >= pcity->incite_revolt_cost) {
+ } else if (game.player_ptr->economic.gold >= cost) {
my_snprintf(buf, sizeof(buf),
_("Incite a revolt for %d gold?\n"
"Treasury contains %d gold."),
- pcity->incite_revolt_cost, game.player_ptr->economic.gold);
+ cost, game.player_ptr->economic.gold);
diplomat_target_id = pcity->id;
popup_message_dialog(toplevel, "diplomatrevoltdialog", buf,
diplomat_incite_yes_callback, 0, 0,
@@ -652,7 +654,7 @@
my_snprintf(buf, sizeof(buf),
_("Inciting a revolt costs %d gold.\n"
"Treasury contains %d gold."),
- pcity->incite_revolt_cost, game.player_ptr->economic.gold);
+ cost, game.player_ptr->economic.gold);
popup_message_dialog(toplevel, "diplomatnogolddialog", buf,
diplomat_incite_no_callback, 0, 0,
NULL);
Index: client/include/dialogs_g.h
===================================================================
--- client/include/dialogs_g.h (revision 13743)
+++ client/include/dialogs_g.h (working copy)
@@ -42,8 +42,8 @@
void popup_diplomat_dialog(struct unit *punit, struct tile *ptile);
int diplomat_handled_in_diplomat_dialog(void);
void close_diplomat_dialog(void);
-void popup_incite_dialog(struct city *pcity);
-void popup_bribe_dialog(struct unit *punit);
+void popup_incite_dialog(struct city *pcity, int cost);
+void popup_bribe_dialog(struct unit *punit, int cost);
void popup_sabotage_dialog(struct city *pcity);
void popup_pillage_dialog(struct unit *punit, bv_special may_pillage);
void popup_upgrade_dialog(struct unit_list *punits);
Index: client/gui-win32/dialogs.c
===================================================================
--- client/gui-win32/dialogs.c (revision 13743)
+++ client/gui-win32/dialogs.c (working copy)
@@ -1312,7 +1312,7 @@
if(find_unit_by_id(diplomat_id) &&
(find_city_by_id(diplomat_target_id))) {
- request_diplomat_action(SPY_GET_SABOTAGE_LIST, diplomat_id,
+ request_diplomat_answer(DIPLOMAT_SABOTAGE, diplomat_id,
diplomat_target_id, 0);
}
}
@@ -1349,7 +1349,8 @@
if (find_unit_by_id(diplomat_id)
&& find_unit_by_id(diplomat_target_id)) {
- dsend_packet_unit_bribe_inq(&aconnection, diplomat_target_id);
+ request_diplomat_answer(DIPLOMAT_BRIBE, diplomat_id,
+ diplomat_target_id, 0);
}
}
@@ -1357,17 +1358,17 @@
/****************************************************************
...
*****************************************************************/
-void popup_bribe_dialog(struct unit *punit)
+void popup_bribe_dialog(struct unit *punit, int cost)
{
char buf[128];
if (unit_has_type_flag(punit, F_UNBRIBABLE)) {
popup_message_dialog(root_window, _("Ooops..."),
_("This unit cannot be bribed!"),
diplomat_bribe_no_callback, 0, 0);
- } else if(game.player_ptr->economic.gold>=punit->bribe_cost) {
+ } else if (game.player_ptr->economic.gold >= cost) {
my_snprintf(buf, sizeof(buf),
_("Bribe unit for %d gold?\nTreasury contains %d gold."),
- punit->bribe_cost, game.player_ptr->economic.gold);
+ cost, game.player_ptr->economic.gold);
popup_message_dialog(root_window, /*"diplomatbribedialog"*/_("Bribe Enemy
Unit"
), buf,
_("_Yes"), diplomat_bribe_yes_callback, 0,
@@ -1376,7 +1377,7 @@
my_snprintf(buf, sizeof(buf),
_("Bribing the unit costs %d gold.\n"
"Treasury contains %d gold."),
- punit->bribe_cost, game.player_ptr->economic.gold);
+ cost, game.player_ptr->economic.gold);
popup_message_dialog(root_window, /*"diplomatnogolddialog"*/
_("Traitors Demand Too Much!"), buf, _("Darn"),
diplomat_bribe_no_callback, 0, 0);
@@ -1532,26 +1533,27 @@
diplomat_dialog = 0;
if (find_unit_by_id(diplomat_id) && find_city_by_id(diplomat_target_id)) {
- dsend_packet_city_incite_inq(&aconnection, diplomat_target_id);
+ request_diplomat_answer(DIPLOMAT_INCITE, diplomat_id,
+ diplomat_target_id, 0);
}
}
/****************************************************************
Popup the yes/no dialog for inciting, since we know the cost now
*****************************************************************/
-void popup_incite_dialog(struct city *pcity)
+void popup_incite_dialog(struct city *pcity, int cost)
{
char buf[128];
- if (pcity->incite_revolt_cost == INCITE_IMPOSSIBLE_COST) {
+ if (INCITE_IMPOSSIBLE_COST == cost) {
my_snprintf(buf, sizeof(buf), _("You can't incite a revolt in %s."),
pcity->name);
popup_message_dialog(root_window, _("City can't be incited!"), buf,
_("Darn"), diplomat_incite_no_callback, 0, 0);
- } else if (game.player_ptr->economic.gold >= pcity->incite_revolt_cost) {
+ } else if (game.player_ptr->economic.gold >= cost) {
my_snprintf(buf, sizeof(buf),
_("Incite a revolt for %d gold?\nTreasury contains %d gold."),
- pcity->incite_revolt_cost, game.player_ptr->economic.gold);
+ cost, game.player_ptr->economic.gold);
diplomat_target_id = pcity->id;
popup_message_dialog(root_window, /*"diplomatrevoltdialog"*/_("Incite a
Revolt!"), buf,
_("_Yes"), diplomat_incite_yes_callback, 0,
@@ -1560,7 +1562,7 @@
my_snprintf(buf, sizeof(buf),
_("Inciting a revolt costs %d gold.\n"
"Treasury contains %d gold."),
- pcity->incite_revolt_cost, game.player_ptr->economic.gold);
+ cost, game.player_ptr->economic.gold);
popup_message_dialog(root_window, /*"diplomatnogolddialog"*/_("Traitors
Demand Too Much!"), buf,
_("Darn"), diplomat_incite_no_callback, 0,
0);
Index: client/packhand.c
===================================================================
--- client/packhand.c (revision 13743)
+++ client/packhand.c (working copy)
@@ -1263,7 +1263,6 @@
punit->veteran = packet_unit->veteran;
punit->moves_left = packet_unit->moves_left;
- punit->bribe_cost = 0;
punit->fuel = packet_unit->fuel;
punit->goto_tile = packet_unit->goto_tile;
punit->paradropped = packet_unit->paradropped;
@@ -2659,36 +2658,6 @@
}
/**************************************************************************
- ...
-**************************************************************************/
-void handle_unit_bribe_info(int unit_id, int cost)
-{
- struct unit *punit = find_unit_by_id(unit_id);
-
- if (punit) {
- punit->bribe_cost = cost;
- if (game.player_ptr && !game.player_ptr->ai.control) {
- popup_bribe_dialog(punit);
- }
- }
-}
-
-/**************************************************************************
- ...
-**************************************************************************/
-void handle_city_incite_info(int city_id, int cost)
-{
- struct city *pcity = find_city_by_id(city_id);
-
- if (pcity) {
- pcity->incite_revolt_cost = cost;
- if (game.player_ptr && !game.player_ptr->ai.control) {
- popup_incite_dialog(pcity);
- }
- }
-}
-
-/**************************************************************************
...
**************************************************************************/
void handle_city_name_suggestion_info(int unit_id, char *name)
@@ -2711,14 +2680,45 @@
/**************************************************************************
...
**************************************************************************/
-void handle_unit_diplomat_popup_dialog(int diplomat_id, int target_id)
+void handle_unit_diplomat_answer(int diplomat_id, int target_id, int cost,
+ enum diplomat_actions action_type)
{
+ struct city *pcity = find_city_by_id(target_id);
+ struct unit *punit = find_unit_by_id(target_id);
struct unit *pdiplomat =
player_find_unit_by_id(game.player_ptr, diplomat_id);
- if (pdiplomat && can_client_issue_orders()) {
- process_diplomat_arrival(pdiplomat, target_id);
+ if (NULL == pdiplomat) {
+ return;
}
+
+ switch (action_type) {
+ case DIPLOMAT_BRIBE:
+ if (punit) {
+ if (game.player_ptr && !game.player_ptr->ai.control) {
+ popup_bribe_dialog(punit, cost);
+ }
+ }
+ break;
+ case DIPLOMAT_INCITE:
+ if (pcity) {
+ if (game.player_ptr && !game.player_ptr->ai.control) {
+ popup_incite_dialog(pcity, cost);
+ }
+ }
+ break;
+ case DIPLOMAT_MOVE:
+ if (can_client_issue_orders()) {
+ process_diplomat_arrival(pdiplomat, target_id);
+ }
+ break;
+ default:
+ freelog(LOG_ERROR,
+ "handle_unit_diplomat_answer()"
+ " invalid action_type (%d).",
+ action_type);
+ break;
+ };
}
/**************************************************************************
Index: client/gui-sdl/diplomat_dialog.c
===================================================================
--- client/gui-sdl/diplomat_dialog.c (revision 13743)
+++ client/gui-sdl/diplomat_dialog.c (working copy)
@@ -133,7 +133,7 @@
{
if (find_unit_by_id(pDiplomat_Dlg->diplomat_id)
&& find_city_by_id(pDiplomat_Dlg->diplomat_target_id)) {
- request_diplomat_action(SPY_GET_SABOTAGE_LIST, pDiplomat_Dlg->diplomat_id,
+ request_diplomat_answer(DIPLOMAT_SABOTAGE, pDiplomat_Dlg->diplomat_id,
pDiplomat_Dlg->diplomat_target_id, 0);
}
@@ -426,7 +426,9 @@
if (Main.event.button.button == SDL_BUTTON_LEFT) {
if (find_unit_by_id(pDiplomat_Dlg->diplomat_id)
&& find_city_by_id(pDiplomat_Dlg->diplomat_target_id)) {
- dsend_packet_city_incite_inq(&aconnection,
pDiplomat_Dlg->diplomat_target_id);
+ request_diplomat_answer(DIPLOMAT_INCITE,
+ pDiplomat_Dlg->diplomat_id,
+ pDiplomat_Dlg->diplomat_target_id, 0);
}
popdown_diplomat_dialog();
@@ -465,7 +467,9 @@
if (find_unit_by_id(pDiplomat_Dlg->diplomat_id)
&& find_unit_by_id(pDiplomat_Dlg->diplomat_target_id)) {
- dsend_packet_unit_bribe_inq(&aconnection,
pDiplomat_Dlg->diplomat_target_id);
+ request_diplomat_answer(DIPLOMAT_BRIBE,
+ pDiplomat_Dlg->diplomat_id,
+ pDiplomat_Dlg->diplomat_target_id, 0);
}
popdown_diplomat_dialog();
@@ -1102,7 +1106,7 @@
Popup a window asking a diplomatic unit if it wishes to incite the
given enemy city.
**************************************************************************/
-void popup_incite_dialog(struct city *pCity)
+void popup_incite_dialog(struct city *pCity, int cost)
{
struct widget *pWindow = NULL, *pBuf = NULL;
SDL_String16 *pStr;
@@ -1146,7 +1150,7 @@
area.w =MAX(area.w, adj_size(8));
area.h = MAX(area.h, adj_size(2));
- if (pCity->incite_revolt_cost == INCITE_IMPOSSIBLE_COST) {
+ if (INCITE_IMPOSSIBLE_COST == cost) {
/* exit button */
pBuf = create_themeicon(pTheme->Small_CANCEL_Icon, pWindow->dst,
@@ -1179,10 +1183,10 @@
area.w = MAX(area.w , pBuf->size.w);
area.h += pBuf->size.h;
- } else if (game.player_ptr->economic.gold >= pCity->incite_revolt_cost) {
+ } else if (game.player_ptr->economic.gold >= cost) {
my_snprintf(cBuf, sizeof(cBuf),
_("Incite a revolt for %d gold?\nTreasury contains %d gold."),
- pCity->incite_revolt_cost, game.player_ptr->economic.gold);
+ cost, game.player_ptr->economic.gold);
create_active_iconlabel(pBuf, pWindow->dst, pStr, cBuf, NULL);
@@ -1232,7 +1236,7 @@
my_snprintf(cBuf, sizeof(cBuf),
_("Inciting a revolt costs %d gold.\n"
"Treasury contains %d gold."),
- pCity->incite_revolt_cost, game.player_ptr->economic.gold);
+ cost, game.player_ptr->economic.gold);
create_active_iconlabel(pBuf, pWindow->dst, pStr, cBuf, NULL);
@@ -1344,7 +1348,7 @@
Popup a dialog asking a diplomatic unit if it wishes to bribe the
given enemy unit.
**************************************************************************/
-void popup_bribe_dialog(struct unit *pUnit)
+void popup_bribe_dialog(struct unit *pUnit, int cost)
{
struct widget *pWindow = NULL, *pBuf = NULL;
SDL_String16 *pStr;
@@ -1388,10 +1392,10 @@
area.w = MAX(area.w, adj_size(8));
area.h = MAX(area.h, adj_size(2));
- if(game.player_ptr->economic.gold >= pUnit->bribe_cost) {
+ if (game.player_ptr->economic.gold >= cost) {
my_snprintf(cBuf, sizeof(cBuf),
_("Bribe unit for %d gold?\nTreasury contains %d gold."),
- pUnit->bribe_cost, game.player_ptr->economic.gold);
+ cost, game.player_ptr->economic.gold);
create_active_iconlabel(pBuf, pWindow->dst, pStr, cBuf, NULL);
@@ -1439,7 +1443,7 @@
my_snprintf(cBuf, sizeof(cBuf),
_("Bribing the unit costs %d gold.\n"
"Treasury contains %d gold."),
- pUnit->bribe_cost, game.player_ptr->economic.gold);
+ cost, game.player_ptr->economic.gold);
create_active_iconlabel(pBuf, pWindow->dst, pStr, cBuf, NULL);
Index: client/gui-ftwl/dialogs.c
===================================================================
--- client/gui-ftwl/dialogs.c (revision 13743)
+++ client/gui-ftwl/dialogs.c (working copy)
@@ -326,7 +326,7 @@
Popup a window asking a diplomatic unit if it wishes to incite the
given enemy city.
**************************************************************************/
-void popup_incite_dialog(struct city *pcity)
+void popup_incite_dialog(struct city *pcity, int cost)
{
/* PORTME */
}
@@ -335,7 +335,7 @@
Popup a dialog asking a diplomatic unit if it wishes to bribe the
given enemy unit.
**************************************************************************/
-void popup_bribe_dialog(struct unit *punit)
+void popup_bribe_dialog(struct unit *punit, int cost)
{
/* PORTME */
}
Index: client/gui-mui/dialogs.c
===================================================================
--- client/gui-mui/dialogs.c (revision 13743)
+++ client/gui-mui/dialogs.c (working copy)
@@ -212,14 +212,15 @@
/****************************************************************
Popup the bribe confirmation window
*****************************************************************/
-void popup_bribe_dialog(struct unit *punit)
+void popup_bribe_dialog(struct unit *punit, int cost)
{
char buf[128];
- if(game.player_ptr->economic.gold>=punit->bribe_cost)
+ if (game.player_ptr->economic.gold >= cost)
{
- my_snprintf(buf, sizeof(buf),_("Bribe unit for %d gold?\nTreasury contains
%d gold."),
- punit->bribe_cost, game.player_ptr->economic.gold);
+ my_snprintf(buf, sizeof(buf),
+ _("Bribe unit for %d gold?\nTreasury contains %d gold."),
+ cost, game.player_ptr->economic.gold);
popup_message_dialog(main_wnd, _("Bribe Enemy Unit"), buf,
_("Yes"), diplomat_bribe_yes, 0,
@@ -227,8 +228,9 @@
0);
} else
{
- my_snprintf(buf, sizeof(buf), _("Bribing the unit costs %d gold.\nTreasury
contains %d gold."),
- punit->bribe_cost, game.player_ptr->economic.gold);
+ my_snprintf(buf, sizeof(buf),
+ _("Bribing the unit costs %d gold.\nTreasury contains %d
gold."),
+ cost, game.player_ptr->economic.gold);
popup_message_dialog(main_wnd, _("Traitors Demand Too Much!"), buf,
_("Darn"), message_close,0,
@@ -475,18 +477,19 @@
/****************************************************************
Popup the yes/no dialog for inciting, since we know the cost now
*****************************************************************/
-void popup_incite_dialog(struct city *pcity)
+void popup_incite_dialog(struct city *pcity, int cost)
{
char buf[128];
- if (pcity->incite_revolt_cost == INCITE_IMPOSSIBLE_COST) {
+ if (INCITE_IMPOSSIBLE_COST == cost) {
my_snprintf(buf, sizeof(buf), _("You can't incite a revolt in %s."),
pcity->name);
popup_message_dialog(main_wnd, _("City can't be incited!"), buf,
_("Darn"), diplomat_incite_no, 0, 0);
- } else if (game.player_ptr->economic.gold >= pcity->incite_revolt_cost) {
- my_snprintf(buf, sizeof(buf),_("Incite a revolt for %d gold?\nTreasury
contains %d gold."),
- pcity->incite_revolt_cost, game.player_ptr->economic.gold);
+ } else if (game.player_ptr->economic.gold >= cost) {
+ my_snprintf(buf, sizeof(buf),
+ _("Incite a revolt for %d gold?\nTreasury contains %d gold."),
+ cost, game.player_ptr->economic.gold);
diplomat_target_id = pcity->id;
popup_message_dialog(main_wnd, _("Incite a Revolt!"), buf,
@@ -496,8 +499,9 @@
} else
{
- my_snprintf(buf, sizeof(buf), _("Inciting a revolt costs %d
gold.\nTreasury contains %d gold."),
- pcity->incite_revolt_cost, game.player_ptr->economic.gold);
+ my_snprintf(buf, sizeof(buf),
+ _("Inciting a revolt costs %d gold.\nTreasury contains %d
gold."),
+ cost, game.player_ptr->economic.gold);
popup_message_dialog(main_wnd, _("Traitors Demand Too Much!"), buf,
_("Darn"), diplomat_incite_no,0,
0);
@@ -661,7 +665,7 @@
if(find_unit_by_id(diplomat_id) &&
(find_city_by_id(diplomat_target_id))) {
- request_diplomat_action(SPY_GET_SABOTAGE_LIST, diplomat_id,
+ request_diplomat_answer(DIPLOMAT_SABOTAGE, diplomat_id,
diplomat_target_id, 0);
}
}
Index: client/gui-stub/dialogs.c
===================================================================
--- client/gui-stub/dialogs.c (revision 13743)
+++ client/gui-stub/dialogs.c (working copy)
@@ -118,7 +118,7 @@
Popup a window asking a diplomatic unit if it wishes to incite the
given enemy city.
**************************************************************************/
-void popup_incite_dialog(struct city *pcity)
+void popup_incite_dialog(struct city *pcity, int cost)
{
/* PORTME */
}
@@ -127,7 +127,7 @@
Popup a dialog asking a diplomatic unit if it wishes to bribe the
given enemy unit.
**************************************************************************/
-void popup_bribe_dialog(struct unit *punit)
+void popup_bribe_dialog(struct unit *punit, int cost)
{
/* PORTME */
}
_______________________________________________
Freeciv-dev mailing list
[email protected]
https://mail.gna.org/listinfo/freeciv-dev