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

[Freeciv-Dev] (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] (PR#3745) Diplomacy patch part 2
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Fri, 18 Apr 2003 04:03:15 -0700
Reply-to: rt@xxxxxxxxxxxxxx

This part does some internal generalization and simplification of the
diplomatic network traffic and handling.

What it does:
- PACKET_PLAYER_REMOVE_VISION has been removed
- PACKET_PLAYER_CANCEL_PACT now takes a value that indicates what kind of
treaty is being cancelled, which may be CLAUSE_VISION
- New function establish_embassy(), which wraps embassy making

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.

  - 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     18 Apr 2003 10:48:47 -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;
+    packet.id = player_index;
+    packet.value1 = CLAUSE_CEASEFIRE; /* anything but vision */
     send_packet_generic_integer(&aconnection, PACKET_PLAYER_CANCEL_PACT,
-                               &pa);
+                               &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.21
diff -u -r1.21 plrdlg.c
--- client/gui-gtk-2.0/plrdlg.c 17 Apr 2003 22:41:17 -0000      1.21
+++ client/gui-gtk-2.0/plrdlg.c 18 Apr 2003 10:48:47 -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"
@@ -559,31 +560,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);
 }
 
 /**************************************************************************
@@ -595,14 +591,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; /* anything but vision */
+    send_packet_generic_values(&aconnection, PACKET_PLAYER_CANCEL_PACT,
+                               &packet);
   }
 }
 
@@ -615,14 +612,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: common/capstr.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v
retrieving revision 1.131
diff -u -r1.131 capstr.c
--- common/capstr.c     17 Apr 2003 20:06:36 -0000      1.131
+++ common/capstr.c     18 Apr 2003 10:48:47 -0000
@@ -77,7 +77,7 @@
 #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_nation_selected +diplomacy +diplomacy2"
 /* "+1.14.0" is protocol for 1.14.0 release.
  *
  * "conn_info" is sending the conn_id field. To preserve compatability
@@ -117,6 +117,7 @@
  * players who have no assigned nation (rather than MAX_NUM_NATIONS).
  *
  * "diplomacy": changed requirements for diplomatic meetings
+ * "diplomacy2": unified and simplified handling of diplomatic requests
  */
 
 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    18 Apr 2003 10:48:48 -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    18 Apr 2003 10:48:48 -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   18 Apr 2003 10:48:48 -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   18 Apr 2003 10:48:48 -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  18 Apr 2003 10:48:48 -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.121
diff -u -r1.121 maphand.c
--- server/maphand.c    12 Apr 2003 18:24:42 -0000      1.121
+++ server/maphand.c    18 Apr 2003 10:48:48 -0000
@@ -1259,32 +1259,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    18 Apr 2003 10:48:48 -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    18 Apr 2003 10:48:48 -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   18 Apr 2003 10:48:49 -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]