Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2003:
[Freeciv-Dev] Re: (PR#4200) two bugfixes to intelligence
Home

[Freeciv-Dev] Re: (PR#4200) two bugfixes to intelligence

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] Re: (PR#4200) two bugfixes to intelligence
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Thu, 15 May 2003 07:48:34 -0700
Reply-to: rt@xxxxxxxxxxxxxx

On Thu, 15 May 2003, Raimar Falke wrote:
> See attached patch.

Further patch: Removes duplicate and unused lines of code, and also fixes
a stupid memory overwrite bug.

  - Per

Index: client/civclient.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/civclient.c,v
retrieving revision 1.169
diff -u -r1.169 civclient.c
--- client/civclient.c  3 May 2003 20:20:15 -0000       1.169
+++ client/civclient.c  15 May 2003 14:46:55 -0000
@@ -850,9 +850,7 @@
 **************************************************************************/
 bool can_intel_with_player(struct player *pplayer)
 {
-  return (pplayer->is_alive
-          && pplayer != game.player_ptr
-          && player_has_embassy(game.player_ptr, pplayer));
+  return could_intel_with_player(game.player_ptr, pplayer);
 }
 
 /**************************************************************************
Index: common/diptreaty.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/diptreaty.c,v
retrieving revision 1.15
diff -u -r1.15 diptreaty.c
--- common/diptreaty.c  17 Apr 2003 20:06:36 -0000      1.15
+++ common/diptreaty.c  15 May 2003 14:46:56 -0000
@@ -44,6 +44,19 @@
           && pplayer->is_connected);
 }
 
+/**************************************************************************
+  Returns TRUE iff pplayer could do diplomatic meetings with aplayer.
+**************************************************************************/
+bool could_intel_with_player(struct player *pplayer, struct player *aplayer)
+{
+  return (pplayer->is_alive
+          && aplayer->is_alive
+          && pplayer != aplayer
+          && (pplayer->diplstates[aplayer->player_no].contact_turns_left > 0
+              || aplayer->diplstates[pplayer->player_no].contact_turns_left > 0
+              || player_has_embassy(pplayer, aplayer)));
+}
+
 /****************************************************************
 ...
 *****************************************************************/
Index: common/diptreaty.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/diptreaty.h,v
retrieving revision 1.10
diff -u -r1.10 diptreaty.h
--- common/diptreaty.h  17 Apr 2003 20:06:36 -0000      1.10
+++ common/diptreaty.h  15 May 2003 14:46:56 -0000
@@ -46,6 +46,7 @@
 };
 
 bool could_meet_with_player(struct player *pplayer, struct player *aplayer);
+bool could_intel_with_player(struct player *pplayer, struct player *aplayer);
 
 void init_treaty(struct Treaty *ptreaty, 
                 struct player *plr0, struct player *plr1);
Index: common/tech.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tech.c,v
retrieving revision 1.62
diff -u -r1.62 tech.c
--- common/tech.c       15 May 2003 12:26:53 -0000      1.62
+++ common/tech.c       15 May 2003 14:46:56 -0000
@@ -542,7 +542,9 @@
 {
   static char buffer[200];
 
-  if (!is_future_tech(tech)) {
+  if (tech == A_NOINFO) {
+    my_snprintf(buffer, sizeof(buffer), _("(Unknown)"));
+  } else if (!is_future_tech(tech)) {
     assert(tech_exists(tech));
     my_snprintf(buffer, sizeof(buffer), "%s", advances[tech].name);
   } else {
Index: common/tech.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tech.h,v
retrieving revision 1.38
diff -u -r1.38 tech.h
--- common/tech.h       13 Jan 2003 23:27:12 -0000      1.38
+++ common/tech.h       15 May 2003 14:46:56 -0000
@@ -29,6 +29,7 @@
 #define A_LAST MAX_NUM_ITEMS
 #define A_UNSET (A_LAST-1)
 #define A_FUTURE (A_LAST-2)
+#define A_NOINFO (A_LAST-3)
 
 /*
    A_NONE is the root tech. All players always know this tech. It is
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.271
diff -u -r1.271 plrhand.c
--- server/plrhand.c    10 May 2003 19:20:16 -0000      1.271
+++ server/plrhand.c    15 May 2003 14:46:56 -0000
@@ -1127,7 +1127,10 @@
 }
 
 /**************************************************************************
- Package player info depending on info_level.
+  Package player info depending on info_level. We send everything to
+  plr's connections, we send almost everything to players with embassy
+  to plr, we send a little to players we are in contact with and almost
+  nothing to everyone else.
 
  Note: if reciever is NULL and info < INFO_EMBASSY the info related to the
        receiving player are not set correctly.
@@ -1145,38 +1148,14 @@
     info_level = min_info_level;
   }
 
-  if (info_level >= INFO_MEETING) {
-    packet->gold            = plr->economic.gold;
-    for (i = A_NONE; i < game.num_tech_types; i++) {
+  packet->gold            = plr->economic.gold;
+  packet->government      = plr->government;
+
+  if (info_level >= INFO_EMBASSY) {
+    for (i = A_FIRST; i < game.num_tech_types; i++) {
       packet->inventions[i] = plr->research.inventions[i].state + '0';
     }
     packet->inventions[i]   = '\0';
-    packet->government      = plr->government;
-  } else {
-    packet->gold            = 0;
-    for (i = A_NONE; i < game.num_tech_types; i++) {
-      packet->inventions[i] = '0';
-    }
-
-    /* 
-     * We have to inform the client that the other players also know
-     * A_NONE.
-     */
-    packet->inventions[A_NONE] =
-       plr->research.inventions[A_NONE].state + '0';
-    packet->inventions[i]   = '\0';
-
-    /* Ideally, we should check whether receiver really sees any cities owned
-     * by player before this. */
-    if (server_state == RUN_GAME_STATE) {
-      packet->inventions[city_styles[get_player_city_style(plr)].techreq] = 
'1';
-    }
-
-    /* FIXME: temporary kludge */
-    packet->government      = plr->government; /*G_MAGIC;*/
-  }
-
-  if (info_level >= INFO_EMBASSY) {
     packet->tax             = plr->economic.tax;
     packet->science         = plr->economic.science;
     packet->luxury          = plr->economic.luxury;
@@ -1200,12 +1179,16 @@
       packet->diplstates[i].has_reason_to_cancel = 
plr->diplstates[i].has_reason_to_cancel;
     }
   } else {
+    for (i = A_FIRST; i < game.num_tech_types; i++) {
+      packet->inventions[i] = '0';
+    }
+    packet->inventions[i]   = '\0';
     packet->tax             = 0;
     packet->science         = 0;
     packet->luxury          = 0;
     packet->bulbs_researched= 0;
     packet->techs_researched= 0;
-    packet->researching     = A_UNSET;
+    packet->researching     = A_NOINFO;
     packet->future_tech     = 0;
     packet->revolution      = 0;
 
@@ -1229,15 +1212,20 @@
     /* We always know the players relation to us */
     if (receiver) {
       int p_no = receiver->player_no;
+
       packet->diplstates[p_no].type       = plr->diplstates[p_no].type;
       packet->diplstates[p_no].turns_left = plr->diplstates[p_no].turns_left;
-      packet->diplstates[i].contact_turns_left = 
-         plr->diplstates[i].contact_turns_left;
+      packet->diplstates[p_no].contact_turns_left = 
+         plr->diplstates[p_no].contact_turns_left;
       packet->diplstates[p_no].has_reason_to_cancel =
        plr->diplstates[p_no].has_reason_to_cancel;
     }
   }
 
+  /* We have to inform the client that the other players also know
+   * A_NONE. */
+  packet->inventions[A_NONE] = plr->research.inventions[A_NONE].state + '0';
+
   if (info_level >= INFO_FULL) {
     packet->tech_goal       = plr->ai.tech_goal;
   } else {
@@ -1268,7 +1256,7 @@
   if (receiver && player_has_embassy(receiver, plr)) {
     return INFO_EMBASSY;
   }
-  if (receiver && find_treaty(plr, receiver)) {
+  if (receiver && could_intel_with_player(receiver, plr)) {
     return INFO_MEETING;
   }
   return INFO_MINIMUM;

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