Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2003:
[Freeciv-Dev] Re: (PR#3745) Diplomacy patch part 2
Home

[Freeciv-Dev] Re: (PR#3745) Diplomacy patch part 2

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] Re: (PR#3745) Diplomacy patch part 2
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Thu, 24 Apr 2003 08:14:08 -0700
Reply-to: rt@xxxxxxxxxxxxxx

On Sun, 20 Apr 2003, Gregory Berkolaiko wrote:
> > These are necessary changes for the next installment of this series of
> > patches, since it creates a more general framework to handle various
> > types of treaties and their cancellation.
>
> The patch looks sane to me.Should it be ported to other clients first?  It
> will break them as it is now.

Here it is, ported to all clients.

  - Per

Index: client/gui-gtk/plrdlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/plrdlg.c,v
retrieving revision 1.46
diff -u -r1.46 plrdlg.c
--- client/gui-gtk/plrdlg.c     17 Apr 2003 20:06:35 -0000      1.46
+++ client/gui-gtk/plrdlg.c     24 Apr 2003 15:13:00 -0000
@@ -23,6 +23,7 @@
 #include <gdk/gdkkeysyms.h>
 #include <gtk/gtk.h>
 
+#include "diptreaty.h"
 #include "fcintl.h"
 #include "game.h"
 #include "log.h"
@@ -562,19 +563,20 @@
   if (!selection)
     return;
   else {
-    struct packet_generic_integer pa;    
+    struct packet_generic_values packet;
 
     row = GPOINTER_TO_INT(selection->data);
     player_index = LI_2_PI(row);
 
-    pa.value = player_index;
-    send_packet_generic_integer(&aconnection, PACKET_PLAYER_CANCEL_PACT,
-                               &pa);
+    packet.id = player_index;
+    packet.value1 = CLAUSE_CEASEFIRE; /* can be any pact clause */
+    send_packet_generic_values(&aconnection, PACKET_PLAYER_CANCEL_PACT,
+                               &packet);
   }
 }
 
 /**************************************************************************
-...
+  ...
 **************************************************************************/
 void players_vision_callback(GtkWidget *w, gpointer data)
 {
@@ -585,14 +587,15 @@
   if (!selection)
     return;
   else {
-    struct packet_generic_integer pa;    
+    struct packet_generic_values packet;
 
     row = GPOINTER_TO_INT(selection->data);
     player_index = LI_2_PI(row);
 
-    pa.value = player_index;
-    send_packet_generic_integer(&aconnection, PACKET_PLAYER_REMOVE_VISION,
-                               &pa);
+    packet.id = player_index;
+    packet.value1 = CLAUSE_VISION;
+    send_packet_generic_values(&aconnection, PACKET_PLAYER_CANCEL_PACT,
+                              &pa);
   }
 }
 
Index: client/gui-gtk-2.0/plrdlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/plrdlg.c,v
retrieving revision 1.23
diff -u -r1.23 plrdlg.c
--- client/gui-gtk-2.0/plrdlg.c 19 Apr 2003 04:21:20 -0000      1.23
+++ client/gui-gtk-2.0/plrdlg.c 24 Apr 2003 15:13:00 -0000
@@ -23,6 +23,7 @@
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
 
+#include "diptreaty.h"
 #include "fcintl.h"
 #include "game.h"
 #include "packets.h"
@@ -533,31 +534,26 @@
 }
 
 /**************************************************************************
-...
+  Callback for diplomatic meetings button. This button is enabled iff
+  we can meet with the other player.
 **************************************************************************/
 void players_meet_callback(GtkMenuItem *item, gpointer data)
 {
   GtkTreeModel *model;
   GtkTreeIter it;
   gint plrno;
+  struct packet_diplomacy_info packet;
 
-  if (!gtk_tree_selection_get_selected(players_selection, &model, &it))
+  if (!gtk_tree_selection_get_selected(players_selection, &model, &it)) {
     return;
+  }
   gtk_tree_model_get(model, &it, PLRNO_COLUMN, &plrno, -1);
 
-  if (can_meet_with_player(&game.players[plrno])) {
-    struct packet_diplomacy_info pa;
-  
-    pa.plrno0=game.player_idx;
-    pa.plrno1=plrno;
-    pa.plrno_from=pa.plrno0;
-    send_packet_diplomacy_info(&aconnection, PACKET_DIPLOMACY_INIT_MEETING,
-                              &pa);
-  }
-  else {
-    append_output_window(_("Game: You need an embassy to "
-                          "establish a diplomatic meeting."));
-  }
+  packet.plrno0 = game.player_idx;
+  packet.plrno1 = plrno;
+  packet.plrno_from = packet.plrno0;
+  send_packet_diplomacy_info(&aconnection, PACKET_DIPLOMACY_INIT_MEETING,
+                             &packet);
 }
 
 /**************************************************************************
@@ -569,14 +565,15 @@
   GtkTreeIter it;
 
   if (gtk_tree_selection_get_selected(players_selection, &model, &it)) {
-    struct packet_generic_integer pa;    
+    struct packet_generic_values packet;
     gint plrno;
 
     gtk_tree_model_get(model, &it, PLRNO_COLUMN, &plrno, -1);
 
-    pa.value = plrno;
-    send_packet_generic_integer(&aconnection, PACKET_PLAYER_CANCEL_PACT,
-                               &pa);
+    packet.id = plrno;
+    packet.value1 = CLAUSE_CEASEFIRE; /* can be any pact clause */
+    send_packet_generic_values(&aconnection, PACKET_PLAYER_CANCEL_PACT,
+                               &packet);
   }
 }
 
@@ -589,14 +586,15 @@
   GtkTreeIter it;
 
   if (gtk_tree_selection_get_selected(players_selection, &model, &it)) {
-    struct packet_generic_integer pa;    
+    struct packet_generic_values packet;
     gint plrno;
 
     gtk_tree_model_get(model, &it, PLRNO_COLUMN, &plrno, -1);
 
-    pa.value = plrno;
-    send_packet_generic_integer(&aconnection, PACKET_PLAYER_REMOVE_VISION,
-                               &pa);
+    packet.id = plrno;
+    packet.value1 = CLAUSE_VISION;
+    send_packet_generic_values(&aconnection, PACKET_PLAYER_CANCEL_PACT,
+                              &packet);
   }
 }
 
Index: client/gui-mui/plrdlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/plrdlg.c,v
retrieving revision 1.28
diff -u -r1.28 plrdlg.c
--- client/gui-mui/plrdlg.c     17 Apr 2003 20:06:36 -0000      1.28
+++ client/gui-mui/plrdlg.c     24 Apr 2003 15:13:00 -0000
@@ -268,9 +268,12 @@
 
   if(playerno)
   {
-    struct packet_generic_integer pa;
-    pa.value = playerno - 100;
-    send_packet_generic_integer(&aconnection, PACKET_PLAYER_CANCEL_PACT, &pa);
+    struct packet_generic_values packet;
+
+    packet.id = playerno - 100;
+    packet.value1 = CLAUSE_CEASEFIRE;
+    send_packet_generic_values(&aconnection, PACKET_PLAYER_CANCEL_PACT,
+                               &packet);
   }
 }
 
@@ -284,9 +287,12 @@
 
   if(playerno)
   {
-    struct packet_generic_integer pa;
-    pa.value = playerno - 100;
-    send_packet_generic_integer(&aconnection, PACKET_PLAYER_REMOVE_VISION, 
&pa);
+    struct packet_generic_values packet;
+
+    packet.id = playerno - 100;
+    packet.value1 = CLAUSE_VISION;
+    send_packet_generic_values(&aconnection,
+                               PACKET_PLAYER_CANCEL_PACT, &packet);
   }
 }
 
Index: client/gui-win32/plrdlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/plrdlg.c,v
retrieving revision 1.14
diff -u -r1.14 plrdlg.c
--- client/gui-win32/plrdlg.c   17 Apr 2003 20:06:36 -0000      1.14
+++ client/gui-win32/plrdlg.c   24 Apr 2003 15:13:00 -0000
@@ -84,10 +84,12 @@
 *******************************************************************/
 static void players_war(int player_index)
 {
-  struct packet_generic_integer pa;  
-  pa.value = player_index;
+  struct packet_generic_values packet;
+
+  packet.value1 = CLAUSE_CEASEFIRE; /* can be any pact clause */
+  packet.id = player_index;
   send_packet_generic_integer(&aconnection, PACKET_PLAYER_CANCEL_PACT,
-                             &pa);
+                             &packet);
 }
 
 /******************************************************************
@@ -95,10 +97,12 @@
 *******************************************************************/
 static void players_vision(int player_index)
 {
-  struct packet_generic_integer pa;  
-  pa.value = player_index;
-  send_packet_generic_integer(&aconnection, PACKET_PLAYER_REMOVE_VISION,
-                             &pa);
+  struct packet_generic_values packet;
+
+  packet.value1 = CLAUSE_VISION;
+  packet.id = player_index;
+  send_packet_generic_values(&aconnection, PACKET_PLAYER_CANCEL_PACT,
+                            &packet);
 }
 
 /******************************************************************
Index: client/gui-xaw/plrdlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/plrdlg.c,v
retrieving revision 1.36
diff -u -r1.36 plrdlg.c
--- client/gui-xaw/plrdlg.c     17 Apr 2003 20:06:36 -0000      1.36
+++ client/gui-xaw/plrdlg.c     24 Apr 2003 15:13:00 -0000
@@ -393,10 +393,12 @@
   
   ret=XawListShowCurrent(players_list);
   if(ret->list_index!=XAW_LIST_NONE) {
-    struct packet_generic_integer pa;    
-    pa.value=ret->list_index;
-    send_packet_generic_integer(&aconnection, PACKET_PLAYER_CANCEL_PACT,
-                               &pa);
+    struct packet_generic_values packet;
+
+    packet.id = ret->list_index;
+    packet.value1 = CLAUSE_CEASEFIRE /* can be any pact clause */
+    send_packet_generic_values(&aconnection, PACKET_PLAYER_CANCEL_PACT,
+                               &packet);
   }
 }
 
@@ -410,10 +412,12 @@
   
   ret=XawListShowCurrent(players_list);
   if(ret->list_index!=XAW_LIST_NONE) {
-    struct packet_generic_integer pa;    
-    pa.value=ret->list_index;
-    send_packet_generic_integer(&aconnection, PACKET_PLAYER_REMOVE_VISION,
-                               &pa);
+    struct packet_generic_values packet;
+
+    packet.id = ret->list_index;
+    packet.value1 = CLAUSE_VISION;
+    send_packet_generic_values(&aconnection, 
+                               PACKET_PLAYER_REMOVE_VISION, &packet);
   }
 }
 
Index: common/capstr.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v
retrieving revision 1.132
diff -u -r1.132 capstr.c
--- common/capstr.c     22 Apr 2003 20:50:56 -0000      1.132
+++ common/capstr.c     24 Apr 2003 15:13:00 -0000
@@ -77,7 +77,8 @@
 #define CAPABILITY "+1.14.0 conn_info +occupied team tech_impr_gfx " \
                    "city_struct_minor_cleanup obsolete_last class_legend " \
                    "+impr_req +waste +fastfocus +continent +small_dipl " \
-                   "+no_nation_selected +diplomacy +no_extra_tiles"
+                   "+no_nation_selected +diplomacy +no_extra_tiles" \
+                   "+diplomacy2"
 /* "+1.14.0" is protocol for 1.14.0 release.
  *
  * "conn_info" is sending the conn_id field. To preserve compatability
@@ -120,6 +121,8 @@
  *
  * "no_extra_tiles" means that the extra, unknown (NODRAW) tiles will not be
  * sent to clients (previously used to help with drawing the terrain).
+ *
+ * "diplomacy2": unified and simplified handling of diplomatic request
  */
 
 void init_our_capability(void)
Index: common/packets.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.c,v
retrieving revision 1.245
diff -u -r1.245 packets.c
--- common/packets.c    17 Apr 2003 20:06:36 -0000      1.245
+++ common/packets.c    24 Apr 2003 15:13:01 -0000
@@ -323,10 +323,11 @@
   case PACKET_CITY_REFRESH:
   case PACKET_INCITE_INQ:
   case PACKET_CITY_NAME_SUGGEST_REQ:
-  case PACKET_PLAYER_CANCEL_PACT:
-  case PACKET_PLAYER_REMOVE_VISION:
     return receive_packet_generic_integer(pc);
-    
+
+  case PACKET_PLAYER_CANCEL_PACT:
+    return receive_packet_generic_values(pc);
+
   case PACKET_ALLOC_NATION:
     return receive_packet_alloc_nation(pc);
 
Index: common/packets.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.h,v
retrieving revision 1.144
diff -u -r1.144 packets.h
--- common/packets.h    12 Apr 2003 18:24:42 -0000      1.144
+++ common/packets.h    24 Apr 2003 15:13:01 -0000
@@ -115,7 +115,6 @@
   PACKET_RULESET_GAME,
   PACKET_CONN_INFO,
   PACKET_SHORT_CITY,
-  PACKET_PLAYER_REMOVE_VISION,
   PACKET_GOTO_ROUTE,
   PACKET_PATROL_ROUTE,
   PACKET_CONN_PING,
Index: server/diplhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/diplhand.c,v
retrieving revision 1.68
diff -u -r1.68 diplhand.c
--- server/diplhand.c   17 Apr 2003 20:06:36 -0000      1.68
+++ server/diplhand.c   24 Apr 2003 15:13:01 -0000
@@ -387,7 +387,7 @@
                         pgiver->name);
        check_city_workers(plr0);
        check_city_workers(plr1);
-       break;          
+       break;
       case CLAUSE_VISION:
        give_shared_vision(pgiver, pdest);
        notify_player_ex(pgiver, -1, -1, E_TREATY_SHARED_VISION,
@@ -408,6 +408,17 @@
   }
 }
 
+/****************************************************************************
+  Create an embassy. pplayer gets an embassy with aplayer.
+****************************************************************************/
+void establish_embassy(struct player *pplayer, struct player *aplayer)
+{
+  /* Establish the embassy. */
+  pplayer->embassy |= (1 << aplayer->player_no);
+  send_player_info(pplayer, pplayer);
+  send_player_info(pplayer, aplayer);  /* update player dialog with embassy */
+  send_player_info(aplayer, pplayer);  /* INFO_EMBASSY level info */
+}
 
 /**************************************************************************
 ...
Index: server/diplhand.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/diplhand.h,v
retrieving revision 1.5
diff -u -r1.5 diplhand.h
--- server/diplhand.h   14 Apr 2001 10:03:14 -0000      1.5
+++ server/diplhand.h   24 Apr 2003 15:13:01 -0000
@@ -18,6 +18,8 @@
 struct packet_diplomacy_info;
 struct connection;
 
+void establish_embassy(struct player *pplayer, struct player *aplayer);
+
 struct Treaty *find_treaty(struct player *plr0, struct player *plr1);
 
 void handle_diplomacy_cancel_meeting(struct player *pplayer, 
Index: server/diplomats.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/diplomats.c,v
retrieving revision 1.36
diff -u -r1.36 diplomats.c
--- server/diplomats.c  5 Mar 2003 08:56:08 -0000       1.36
+++ server/diplomats.c  24 Apr 2003 15:13:01 -0000
@@ -26,6 +26,7 @@
 
 #include "citytools.h"
 #include "cityturn.h"
+#include "diplhand.h"
 #include "gamelog.h"
 #include "gotohand.h"
 #include "plrhand.h"
@@ -46,7 +47,6 @@
 static void maybe_cause_incident(enum diplomat_actions action, struct player 
*offender,
                                 struct unit *victim_unit, struct city 
*victim_city);
 
-
 /******************************************************************************
   Poison a city's water supply.
 
@@ -276,11 +276,7 @@
 
   freelog (LOG_DEBUG, "embassy: succeeded");
 
-  /* Establish the embassy. */
-  pplayer->embassy |= (1 << pcity->owner);
-  send_player_info(pplayer, pplayer);
-  send_player_info(pplayer, cplayer);    /* update player dialog with embassy 
*/
-  send_player_info(cplayer, pplayer);    /* INFO_EMBASSY level info */
+  establish_embassy(pplayer, cplayer);
 
   /* Notify everybody involved. */
   notify_player_ex(pplayer, pcity->x, pcity->y, E_MY_DIPLOMAT_EMBASSY,
Index: server/maphand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/maphand.c,v
retrieving revision 1.122
diff -u -r1.122 maphand.c
--- server/maphand.c    22 Apr 2003 20:50:56 -0000      1.122
+++ server/maphand.c    24 Apr 2003 15:13:01 -0000
@@ -1191,32 +1191,6 @@
   }
 }
 
-/***************************************************************
-...
-***************************************************************/
-void handle_player_remove_vision(struct player *pplayer,
-                                struct packet_generic_integer *packet)
-{
-  struct player *pplayer2;
-
-  if (packet->value < 0 || packet->value >= game.nplayers) {
-    return;
-  }
-  pplayer2 = get_player(packet->value);
-  if (pplayer == pplayer2 || !gives_shared_vision(pplayer, pplayer2)) {
-    return;
-  }
-
-  /* Do not allow team mates to backstab */
-  if (pplayer->team != TEAM_NONE && pplayer->team == pplayer2->team) {
-    return;
-  }
-
-  remove_shared_vision(pplayer, pplayer2);
-  notify_player(pplayer2, _("%s no longer gives us shared vision!"),
-               pplayer->name);
-}
-
 /*************************************************************************
 ...
 *************************************************************************/
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.267
diff -u -r1.267 plrhand.c
--- server/plrhand.c    17 Apr 2003 20:06:36 -0000      1.267
+++ server/plrhand.c    24 Apr 2003 15:13:01 -0000
@@ -18,6 +18,7 @@
 #include <assert.h>
 #include <stdarg.h>
 
+#include "diptreaty.h"
 #include "events.h"
 #include "fcintl.h"
 #include "government.h"
@@ -802,16 +803,19 @@
 }
 
 /**************************************************************************
-Handles a player cancelling a "pact" with another player.
+  Handles a player cancelling a "pact" with another player.
 **************************************************************************/
-void handle_player_cancel_pact(struct player *pplayer, int other_player)
+void handle_player_cancel_pact(struct player *pplayer,
+                               struct packet_generic_values *packet)
 {
   enum diplstate_type old_type;
   enum diplstate_type new_type;
   struct player *pplayer2;
   int reppenalty = 0;
   bool has_senate;
-    
+  int other_player = packet->id;
+  int clause = packet->value1;
+
   if (other_player < 0 || other_player >= game.nplayers) {
     return;
   }
@@ -821,13 +825,26 @@
   has_senate = government_has_flag(get_gov_pplayer(pplayer), G_HAS_SENATE);
 
   /* can't break a pact with yourself */
-  if (pplayer == pplayer2)
+  if (pplayer == pplayer2) {
     return;
+  }
 
   /* can't break a pact with a team member */
   if (pplayer->team != TEAM_NONE && pplayer->team == pplayer2->team) {
     return;
   }
+
+  if (clause == CLAUSE_VISION) {
+    if (!gives_shared_vision(pplayer, pplayer2)) {
+      return;
+    }
+    remove_shared_vision(pplayer, pplayer2);
+    notify_player(pplayer2, _("%s no longer gives us shared vision!"),
+                pplayer->name);
+    return;
+  }
+
+  /* else, breaking a treaty */
 
   /* check what the new status will be, and what will happen to our
      reputation */
Index: server/plrhand.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.h,v
retrieving revision 1.53
diff -u -r1.53 plrhand.h
--- server/plrhand.h    17 Apr 2003 20:06:36 -0000      1.53
+++ server/plrhand.h    24 Apr 2003 15:13:01 -0000
@@ -34,7 +34,8 @@
 void handle_player_rates(struct player *pplayer, 
                         struct packet_player_request *preq);
 void check_player_government_rates(struct player *pplayer);
-void handle_player_cancel_pact(struct player *pplayer, int other_player);
+void handle_player_cancel_pact(struct player *pplayer,
+                               struct packet_generic_values *packet);
 void make_contact(struct player *pplayer1, struct player *pplayer2, int x,
                  int y);
 void maybe_make_contact(int x, int y, struct player *pplayer);
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.123
diff -u -r1.123 srv_main.c
--- server/srv_main.c   17 Apr 2003 20:06:37 -0000      1.123
+++ server/srv_main.c   24 Apr 2003 15:13:01 -0000
@@ -922,14 +922,10 @@
     handle_unit_paradrop_to(pplayer, (struct packet_unit_request *)packet);
     break;
   case PACKET_PLAYER_CANCEL_PACT:
-    handle_player_cancel_pact(pplayer,
-                             ((struct packet_generic_integer *)packet)->value);
+    handle_player_cancel_pact(pplayer, (struct packet_generic_values *)packet);
     break;
   case PACKET_UNIT_CONNECT:
     handle_unit_connect(pplayer, (struct packet_unit_connect *)packet);
-    break;
-  case PACKET_PLAYER_REMOVE_VISION:
-    handle_player_remove_vision(pplayer, (struct packet_generic_integer 
*)packet);
     break;
   case PACKET_GOTO_ROUTE:
     handle_goto_route(pplayer, (struct packet_goto_route *)packet);

[Prev in Thread] Current Thread [Next in Thread]