<URL: http://bugs.freeciv.org/Ticket/Display.html?id=39730 >

Committed S2_1 revision 13744.
Committed S2_2 revision 13745.

Here's the slightly different S2_2 patch for posterity.

trunk looks problematic....

Index: server/cityhand.c
===================================================================
--- server/cityhand.c   (revision 13744)
+++ server/cityhand.c   (working copy)
@@ -397,19 +397,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 = game_find_city_by_number(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 13744)
+++ server/diplomats.c  (working copy)
@@ -209,8 +209,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;
 
@@ -225,10 +225,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);
 }
 
 /******************************************************************************
@@ -391,8 +388,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;
   
@@ -406,13 +404,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,
@@ -421,8 +412,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"
@@ -480,7 +474,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);
@@ -693,7 +687,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. */
@@ -1306,7 +1300,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 13744)
+++ 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 13744)
+++ server/unithand.c   (working copy)
@@ -168,28 +168,68 @@
   }
 }
 
-/***************************************************************
-  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 = game_find_unit_by_number(unit_id);
+  struct unit *pdiplomat = player_find_unit_by_id(pplayer, diplomat_id);
+  struct unit *punit = game_find_unit_by_number(target_id);
+  struct city *pcity = game_find_city_by_number(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)
+     && unit_has_type_flag(pdiplomat, F_SPY)) {
+      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 = game_find_unit_by_number(target_id);
@@ -258,12 +298,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;
@@ -1092,8 +1126,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)) {
         if (can_unit_exist_at_tile(punit, punit->tile)) {
Index: common/unit.c
===================================================================
--- common/unit.c       (revision 13744)
+++ common/unit.c       (working copy)
@@ -109,8 +109,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
@@ -1339,7 +1337,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 13744)
+++ common/unit.h       (working copy)
@@ -24,9 +24,14 @@
 
 /* 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
 };
@@ -35,12 +40,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 */
 };
 
@@ -125,7 +135,6 @@
   int veteran;
   int fuel;
   int birth_turn;
-  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 13744)
+++ common/packets.def  (working copy)
@@ -613,15 +613,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
@@ -866,14 +859,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;
@@ -881,14 +874,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 13744)
+++ common/city.h       (working copy)
@@ -268,8 +268,6 @@
   int food_stock;
   int shield_stock;
   int pollution;
-  /* city can't be incited if INCITE_IMPOSSIBLE_COST */
-  int incite_revolt_cost;      
 
   struct universal production;
 
Index: common/fc_types.h
===================================================================
--- common/fc_types.h   (revision 13744)
+++ common/fc_types.h   (working copy)
@@ -86,13 +86,25 @@
 
 /* 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_BASE,          /* Build base */
+  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_BASE = 18,                  /* building base */
   ACTIVITY_LAST   /* leave this one last */
 };
 
Index: ai/aidiplomat.c
===================================================================
--- ai/aidiplomat.c     (revision 13744)
+++ ai/aidiplomat.c     (working copy)
@@ -284,8 +284,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;                                                         \
   }
 
@@ -499,7 +499,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);
@@ -525,8 +525,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 (game_find_unit_by_number(sanity) && punit->moves_left > 0) {
         return TRUE;
Index: client/control.c
===================================================================
--- client/control.c    (revision 13744)
+++ client/control.c    (working copy)
@@ -1195,9 +1195,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 13744)
+++ client/gui-gtk-2.0/diplomat_dialog.c        (working copy)
@@ -66,8 +66,10 @@
 *****************************************************************/
 static void diplomat_bribe_callback(GtkWidget *w, gpointer data)
 {
-  if (game_find_unit_by_number(diplomat_id) && 
game_find_unit_by_number(diplomat_target_id)) {
-    dsend_packet_unit_bribe_inq(&aconnection, diplomat_target_id);
+  if (game_find_unit_by_number(diplomat_id)
+   && game_find_unit_by_number(diplomat_target_id)) {
+    request_diplomat_answer(DIPLOMAT_BRIBE, diplomat_id,
+                           diplomat_target_id, 0);
   }
   gtk_widget_destroy(diplomat_dialog);
 }
@@ -75,7 +77,7 @@
 /****************************************************************
 ...
 *****************************************************************/
-void popup_bribe_dialog(struct unit *punit)
+void popup_bribe_dialog(struct unit *punit, int cost)
 {
   GtkWidget *shell;
 
@@ -85,11 +87,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 +99,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,9 +485,9 @@
 *****************************************************************/
 static void spy_request_sabotage_list(GtkWidget *w, gpointer data)
 {
-  if(game_find_unit_by_number(diplomat_id) &&
-     (game_find_city_by_number(diplomat_target_id))) {
-    request_diplomat_action(SPY_GET_SABOTAGE_LIST, diplomat_id,
+  if (game_find_unit_by_number(diplomat_id)
+   && game_find_city_by_number(diplomat_target_id)) {
+    request_diplomat_answer(DIPLOMAT_SABOTAGE, diplomat_id,
                            diplomat_target_id, 0);
   }
   gtk_widget_destroy(diplomat_dialog);
@@ -508,8 +510,10 @@
 *****************************************************************/
 static void diplomat_incite_callback(GtkWidget *w, gpointer data)
 {
-  if (game_find_unit_by_number(diplomat_id) && 
game_find_city_by_number(diplomat_target_id)) {
-    dsend_packet_city_incite_inq(&aconnection, diplomat_target_id);
+  if (game_find_unit_by_number(diplomat_id)
+   && game_find_city_by_number(diplomat_target_id)) {
+    request_diplomat_answer(DIPLOMAT_INCITE, diplomat_id,
+                           diplomat_target_id, 0);
   }
   gtk_widget_destroy(diplomat_dialog);
 }
@@ -529,11 +533,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,
@@ -541,12 +545,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 {
@@ -554,7 +558,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 13744)
+++ client/control.h    (working copy)
@@ -93,6 +93,8 @@
 void request_unit_select_same_type_tile(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 13744)
+++ client/gui-xaw/diplomat_dialog.c    (working copy)
@@ -92,15 +92,17 @@
 {
   destroy_message_dialog(w);
 
-  if (game_find_unit_by_number(diplomat_id) && 
game_find_unit_by_number(diplomat_target_id)) {
-    dsend_packet_unit_bribe_inq(&aconnection, diplomat_target_id);
+  if (game_find_unit_by_number(diplomat_id)
+   && game_find_unit_by_number(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 +110,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 +123,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);
@@ -556,9 +558,9 @@
   destroy_message_dialog(w);
   diplomat_dialog = NULL;
 
-  if(game_find_unit_by_number(diplomat_id) &&
-     (game_find_city_by_number(diplomat_target_id))) {
-    request_diplomat_action(SPY_GET_SABOTAGE_LIST, diplomat_id,
+  if (game_find_unit_by_number(diplomat_id)
+   && game_find_city_by_number(diplomat_target_id)) {
+    request_diplomat_answer(DIPLOMAT_SABOTAGE, diplomat_id,
                            diplomat_target_id, 0);
   }
 }
@@ -621,28 +623,30 @@
   destroy_message_dialog(w);
   diplomat_dialog = NULL;
 
-  if (game_find_unit_by_number(diplomat_id) && 
game_find_city_by_number(diplomat_target_id)) {
-    dsend_packet_city_incite_inq(&aconnection, diplomat_target_id);
+  if (game_find_unit_by_number(diplomat_id)
+   && game_find_city_by_number(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 +656,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 13744)
+++ 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,
                           struct base_type *pbase);
Index: client/gui-win32/dialogs.c
===================================================================
--- client/gui-win32/dialogs.c  (revision 13744)
+++ client/gui-win32/dialogs.c  (working copy)
@@ -1305,9 +1305,9 @@
   destroy_message_dialog(w);
   diplomat_dialog=0;
 
-  if(game_find_unit_by_number(diplomat_id) &&
-     (game_find_city_by_number(diplomat_target_id))) {
-    request_diplomat_action(SPY_GET_SABOTAGE_LIST, diplomat_id,
+  if (game_find_unit_by_number(diplomat_id)
+   && game_find_city_by_number(diplomat_target_id)) {
+    request_diplomat_answer(DIPLOMAT_SABOTAGE, diplomat_id,
                            diplomat_target_id, 0);
   }
 }
@@ -1343,8 +1343,9 @@
   destroy_message_dialog(w);
   
   if (game_find_unit_by_number(diplomat_id)
-      && game_find_unit_by_number(diplomat_target_id)) { 
-    dsend_packet_unit_bribe_inq(&aconnection, diplomat_target_id);
+   && game_find_unit_by_number(diplomat_target_id)) { 
+    request_diplomat_answer(DIPLOMAT_BRIBE, diplomat_id,
+                           diplomat_target_id, 0);
    }
 
 }
@@ -1352,17 +1353,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,
@@ -1371,7 +1372,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);
@@ -1526,27 +1527,29 @@
   destroy_message_dialog(w);
   diplomat_dialog = 0;
 
-  if (game_find_unit_by_number(diplomat_id) && 
game_find_city_by_number(diplomat_target_id)) {
-    dsend_packet_city_incite_inq(&aconnection, diplomat_target_id);
+  if (game_find_unit_by_number(diplomat_id)
+   && game_find_city_by_number(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,
@@ -1555,7 +1558,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 13744)
+++ client/packhand.c   (working copy)
@@ -1276,7 +1276,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;
@@ -2778,36 +2777,6 @@
 }
 
 /**************************************************************************
-  ...
-**************************************************************************/
-void handle_unit_bribe_info(int unit_id, int cost)
-{
-  struct unit *punit = game_find_unit_by_number(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 = game_find_city_by_number(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)
@@ -2830,14 +2799,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 = game_find_city_by_number(target_id);
+  struct unit *punit = game_find_unit_by_number(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 13744)
+++ client/gui-sdl/diplomat_dialog.c    (working copy)
@@ -133,7 +133,7 @@
 {
   if (game_find_unit_by_number(pDiplomat_Dlg->diplomat_id)
      && game_find_city_by_number(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 (game_find_unit_by_number(pDiplomat_Dlg->diplomat_id)
        && game_find_city_by_number(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 (game_find_unit_by_number(pDiplomat_Dlg->diplomat_id)
        && game_find_unit_by_number(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 13744)
+++ 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-stub/dialogs.c
===================================================================
--- client/gui-stub/dialogs.c   (revision 13744)
+++ 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
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to