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

Here's a simple 2.1b6 replacement, untested.  It simply checks whether
the diplomat can actually execute the desired command.

Please check against your favorite clients.

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)
@@ -1297,6 +1297,8 @@
       break;
     case DIPLOMAT_MOVE:
     case DIPLOMAT_EMBASSY:
+    case DIPLOMAT_BRIBE_QUERY:
+    case DIPLOMAT_INCITE_QUERY:
     case DIPLOMAT_INVESTIGATE:
     case SPY_GET_SABOTAGE_LIST:
       return; /* These are not considered offences */
Index: server/unithand.c
===================================================================
--- server/unithand.c   (revision 13743)
+++ server/unithand.c   (working copy)
@@ -167,27 +167,13 @@
 }
 
 /***************************************************************
-  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_unit_bribe_inq(struct connection *pc, int unit_id)
-{
-  struct player *pplayer = pc->player;
-  struct unit *punit = find_unit_by_id(unit_id);
-
-  if (pplayer && punit) {
-    punit->bribe_cost = unit_bribe_cost(punit);
-    dsend_packet_unit_bribe_info(pc, unit_id, punit->bribe_cost);
-  }
-}
-
-/***************************************************************
 ...
 ***************************************************************/
-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);
@@ -205,6 +191,35 @@
        diplomat_bribe(pplayer, pdiplomat, pvictim);
       }
       break;
+    case DIPLOMAT_BRIBE_QUERY:
+      if(pvictim && diplomat_can_do_action(pdiplomat, DIPLOMAT_BRIBE,
+                                          pvictim->tile)) {
+       pvictim->bribe_cost = unit_bribe_cost(pvictim);
+       /* Only send result back to the requesting connection,
+          not all connections for that player. */
+       dlsend_packet_unit_diplomat_popup_dialog(player_reply_dest(pplayer),
+                                                diplomat_id, target_id,
+                                                pvictim->bribe_cost,
+                                                action_type);
+      }
+      break;
+    case DIPLOMAT_INCITE:
+      if(pcity && diplomat_can_do_action(pdiplomat, DIPLOMAT_INCITE,
+                                        pcity->tile)) {
+       diplomat_incite(pplayer, pdiplomat, pcity);
+      }
+      break;
+    case DIPLOMAT_INCITE_QUERY:
+      if(pcity && diplomat_can_do_action(pdiplomat, DIPLOMAT_INCITE,
+                                        pcity->tile)) {
+       /* Only send result back to the requesting connection,
+          not all connections for that player. */
+       dlsend_packet_unit_diplomat_popup_dialog(player_reply_dest(pplayer),
+                                                diplomat_id, target_id,
+                                                city_incite_cost(pplayer, 
pcity),
+                                                action_type);
+      }
+      break;
     case SPY_SABOTAGE_UNIT:
       if(pvictim && diplomat_can_do_action(pdiplomat, SPY_SABOTAGE_UNIT,
                                           pvictim->tile)) {
@@ -236,12 +251,6 @@
        diplomat_embassy(pplayer, pdiplomat, pcity);
       }
       break;
-    case DIPLOMAT_INCITE:
-      if(pcity && diplomat_can_do_action(pdiplomat, DIPLOMAT_INCITE,
-                                        pcity->tile)) {
-       diplomat_incite(pplayer, pdiplomat, pcity);
-      }
-      break;
     case DIPLOMAT_MOVE:
       if(pcity && diplomat_can_do_action(pdiplomat, DIPLOMAT_MOVE,
                                         pcity->tile)) {
@@ -1066,7 +1075,9 @@
           die("Bug in unithand.c: no diplomat target.");
         }
        dlsend_packet_unit_diplomat_popup_dialog(player_reply_dest(pplayer),
-                                                punit->id, target_id);
+                                                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.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,20 @@
   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_BRIBE_QUERY = 3,
+  DIPLOMAT_INCITE = 4,
+  DIPLOMAT_INCITE_QUERY = 5,
+  DIPLOMAT_INVESTIGATE = 6,
+  DIPLOMAT_SABOTAGE = 7,
+  DIPLOMAT_STEAL = 8,
+  SPY_POISON = 9, 
+  SPY_SABOTAGE_UNIT = 10,
+  SPY_GET_SABOTAGE_LIST = 11,
   DIPLOMAT_ANY_ACTION   /* leave this one last */
 };
 
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,29 +844,24 @@
   CITY city_id;
 end
 
-PACKET_UNIT_BRIBE_INQ=67;cs,handle-per-conn,dsend
-  UNIT unit_id;
-end
+# 67-68 removed in 2.1
 
-PACKET_UNIT_BRIBE_INFO=68;sc,dsend
-  UNIT unit_id;
-  GOLD cost;
-end
-
 PACKET_UNIT_TYPE_UPGRADE=69;cs,dsend
   UNIT_TYPE type;
 end
 
 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
   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: 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;                                                         \
   }
 
@@ -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,7 +1149,7 @@
 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);
 }
 
 void wakeup_sentried_units(struct tile *ptile)
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_action(DIPLOMAT_BRIBE_QUERY, 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_action(DIPLOMAT_INCITE_QUERY, diplomat_id,
+                           diplomat_target_id, 0);
   }
   gtk_widget_destroy(diplomat_dialog);
 }
Index: client/gui-xaw/diplomat_dialog.c
===================================================================
--- client/gui-xaw/diplomat_dialog.c    (revision 13743)
+++ client/gui-xaw/diplomat_dialog.c    (working copy)
@@ -93,7 +93,8 @@
   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_action(DIPLOMAT_BRIBE_QUERY, diplomat_id,
+                           diplomat_target_id, 0);
   }
 }
 
@@ -622,7 +623,8 @@
   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_action(DIPLOMAT_INCITE_QUERY, diplomat_id,
+                           diplomat_target_id, 0);
   }
 }
 
Index: client/gui-win32/dialogs.c
===================================================================
--- client/gui-win32/dialogs.c  (revision 13743)
+++ client/gui-win32/dialogs.c  (working copy)
@@ -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_action(DIPLOMAT_BRIBE_QUERY, diplomat_id,
+                           diplomat_target_id, 0);
    }
 
 }
@@ -1532,7 +1533,8 @@
   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_action(DIPLOMAT_INCITE_QUERY, diplomat_id,
+                           diplomat_target_id, 0);
   }
 }
 
Index: client/packhand.c
===================================================================
--- client/packhand.c   (revision 13743)
+++ client/packhand.c   (working copy)
@@ -2659,36 +2659,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 +2681,41 @@
 /**************************************************************************
 ...
 **************************************************************************/
-void handle_unit_diplomat_popup_dialog(int diplomat_id, int target_id)
+void handle_unit_diplomat_popup_dialog(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
+   || !can_client_issue_orders()) {
+    return;
   }
+
+  switch (action_type) {
+  case DIPLOMAT_BRIBE_QUERY:
+    if (punit) {
+      punit->bribe_cost = cost;
+      if (!game.player_ptr->ai.control) {
+        popup_bribe_dialog(punit);
+      }
+    }
+    break;
+  case DIPLOMAT_INCITE_QUERY:
+    if (pcity) {
+      pcity->incite_revolt_cost = cost;
+      if (!game.player_ptr->ai.control) {
+        popup_incite_dialog(pcity);
+      }
+    }
+    break;
+  default:
+    process_diplomat_arrival(pdiplomat, target_id);
+    break;
+  };
 }
 
 /**************************************************************************
Index: client/gui-sdl/diplomat_dialog.c
===================================================================
--- client/gui-sdl/diplomat_dialog.c    (revision 13743)
+++ client/gui-sdl/diplomat_dialog.c    (working copy)
@@ -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_action(DIPLOMAT_INCITE_QUERY,
+                             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_action(DIPLOMAT_BRIBE_QUERY,
+                             pDiplomat_Dlg->diplomat_id,
+                             pDiplomat_Dlg->diplomat_target_id, 0);
     }
     
     popdown_diplomat_dialog();
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to