Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2003:
[Freeciv-Dev] Re: (PR#5135) Re: Re: Free for all Games
Home

[Freeciv-Dev] Re: (PR#5135) Re: Re: Free for all Games

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: per@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#5135) Re: Re: Free for all Games
From: "jjc@xxxxxxxxxxxxxxxxxx" <jjc@xxxxxxxxxxxxxxxxxx>
Date: Mon, 8 Sep 2003 09:09:56 -0700
Reply-to: rt@xxxxxxxxxxxxxx

On Mon, Sep 08, 2003 at 06:34:33AM -0700, Per I. Mathisen wrote:
> 
> > help diplom
> Option: diplomacy  -  The ability to do diplomacy with other players
> Description:
>   If set to 0 (default), diplomacy is enabled for all.
>   If set to 1, diplomacy is only allowed between human players.
>   If set to 2, diplomacy is only allowed between AI players.
>   If set to 3, diplomacy is disabled for all.
>   You can always do diplomacy with players on your team.
> Status: changeable
> Value: 0, Minimum: 0, Default: 0, Maximum: 3
> 
> CHANGES:
>  - prettier help (see above)
>  - saved to savegame
>  - war set on contact as appropriate
>  - team mates can always do diplomacy
> 
> Please test/comment.
> 
>   - Per
> 

Tested with both 0 and 2.  When diplomacy is disabled, I think that 
the Meet menu item in gui-gtk-2.0 should be grayed out.  Currently it 
is black, but selecting it does not do anything when diplomacy is disabled.

Comment on the code.  I think there should be a diplomacy_possible 
function so the check does not have to be replicated in multiple 
places.  I don't like the name diplomacy_possible, but I can't think of 
a better one.  See attached patch.

-- 
Josh Cogliati


Index: common/diptreaty.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/diptreaty.c,v
retrieving revision 1.17
diff -U9 -r1.17 diptreaty.c
--- common/diptreaty.c  2003/08/08 22:11:41     1.17
+++ common/diptreaty.c  2003/09/08 15:39:12
@@ -12,36 +12,54 @@
 ***********************************************************************/
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "game.h"
 #include "log.h"
 #include "mem.h"
 #include "player.h"
 
 #include "diptreaty.h"
 
 #define SPECLIST_TAG clause
 #define SPECLIST_TYPE struct Clause
 #include "speclist_c.h"
 
 /**************************************************************************
+  Returns TRUE iff pplayer could do diplomancy in the game at all.
+**************************************************************************/
+bool diplomacy_possible(struct player *pplayer, struct player *aplayer)
+{
+  return  (game.diplomacy == 0
+          || (game.diplomacy == 1 
+              && !pplayer->ai.control 
+              && !aplayer->ai.control)
+          || (game.diplomacy == 2
+              && pplayer->ai.control
+              && aplayer->ai.control)
+          || (pplayer->team != TEAM_NONE
+              && pplayer->team == aplayer->team));
+}
+
+/**************************************************************************
   Returns TRUE iff pplayer could do diplomatic meetings with aplayer.
 **************************************************************************/
 bool could_meet_with_player(struct player *pplayer, struct player *aplayer)
 {
   return (pplayer->is_alive
           && aplayer->is_alive
           && pplayer != aplayer
+          && diplomacy_possible(pplayer,aplayer)
           && (player_has_embassy(aplayer, pplayer) 
               || player_has_embassy(pplayer, aplayer)
               || pplayer->diplstates[aplayer->player_no].contact_turns_left > 0
               || aplayer->diplstates[pplayer->player_no].contact_turns_left > 
0)
           && (aplayer->is_connected || aplayer->ai.control)
           && (pplayer->is_connected || pplayer->ai.control));
 }
 
 /**************************************************************************
Index: common/diptreaty.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/diptreaty.h,v
retrieving revision 1.12
diff -U9 -r1.12 diptreaty.h
--- common/diptreaty.h  2003/05/31 16:22:15     1.12
+++ common/diptreaty.h  2003/09/08 15:39:12
@@ -39,18 +39,19 @@
   int value;
 };
 
 struct Treaty {
   struct player *plr0, *plr1;
   bool accept0, accept1;
   struct clause_list clauses;
 };
 
+bool diplomacy_possible(struct player *pplayer, struct player *aplayer);
 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);
 bool add_clause(struct Treaty *ptreaty, struct player *pfrom, 
               enum clause_type type, int val);
 bool remove_clause(struct Treaty *ptreaty, struct player *pfrom, 
                  enum clause_type type, int val);
Index: common/game.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.h,v
retrieving revision 1.124
diff -U9 -r1.124 game.h
--- common/game.h       2003/08/10 14:44:14     1.124
+++ common/game.h       2003/09/08 15:39:15
@@ -155,18 +155,19 @@
   int nation_count;
   int playable_nation_count;
   int styles_count;
 
   int watchtower_extra_vision;
   int watchtower_vision;
   int allowed_city_names;
 
   int borders;         /* distance of border from city; 0=disabled. */
+  int diplomacy;        /* who can do it */
 
   char rulesetdir[MAX_LEN_NAME];
   int firepower_factor;                /* See README.rulesets */
   struct {
     int cathedral_plus;                /* eg Theology */
     int cathedral_minus;       /* eg Communism */
     int colosseum_plus;                /* eg Electricity */
     int temple_plus;           /* eg Mysticism */
     int nav;                   /* AI convenience: tech_req for first
@@ -313,19 +314,58 @@
 #define GAME_MAX_DIPLCOST            100
 
 #define GAME_DEFAULT_FOGOFWAR        TRUE
 
 /* 0 means no national borders.  Performance dropps quickly as the border
  * distance increases (o(n^2) or worse). */
 #define GAME_DEFAULT_BORDERS         7
 #define GAME_MIN_BORDERS             0
 #define GAME_MAX_BORDERS             24
+
+#define GAME_DEFAULT_DIPLOMACY       0
+#define GAME_MIN_DIPLOMACY           0
+#define GAME_MAX_DIPLOMACY           3
 
 #define GAME_DEFAULT_DIPLCHANCE      80
 #define GAME_MIN_DIPLCHANCE          1
 #define GAME_MAX_DIPLCHANCE          99
 
 #define GAME_DEFAULT_FREECOST        0
 #define GAME_MIN_FREECOST            0
 #define GAME_MAX_FREECOST            100
 
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.290
diff -U9 -r1.290 plrhand.c
--- server/plrhand.c    2003/09/03 21:33:58     1.290
+++ server/plrhand.c    2003/09/08 15:39:44
@@ -1436,21 +1436,26 @@
       || !pplayer1->is_alive || !pplayer2->is_alive
       || is_barbarian(pplayer1) || is_barbarian(pplayer2)) {
     return;
   }
 
   pplayer1->diplstates[player2].contact_turns_left = game.contactturns;
   pplayer2->diplstates[player1].contact_turns_left = game.contactturns;
 
   if (pplayer_get_diplstate(pplayer1, pplayer2)->type == DS_NO_CONTACT) {
+    /* Set default new diplomatic state depending on game.diplomacy
+     * server setting. Default is zero, which gives DS_NEUTRAL. */
+    enum diplstate_type dipstate = diplomacy_possible(pplayer1,pplayer2)
+                                    ? DS_NEUTRAL : DS_WAR;
+
     pplayer1->diplstates[player2].type
       = pplayer2->diplstates[player1].type
-      = DS_NEUTRAL;
+      = dipstate;
     notify_player_ex(pplayer1, x, y,
                     E_FIRST_CONTACT,
                     _("Game: You have made contact with the %s, ruled by %s."),
                     get_nation_name_plural(pplayer2->nation), pplayer2->name);
     notify_player_ex(pplayer2, x, y,
                     E_FIRST_CONTACT,
                     _("Game: You have made contact with the %s, ruled by %s."),
                     get_nation_name_plural(pplayer1->nation), pplayer1->name);
     send_player_info(pplayer1, pplayer2);
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.134
diff -U9 -r1.134 savegame.c
--- server/savegame.c   2003/08/19 19:46:25     1.134
+++ server/savegame.c   2003/09/08 15:39:58
@@ -1899,18 +1899,22 @@
     game.citymindist  = secfile_lookup_int_default(file,
       GAME_DEFAULT_CITYMINDIST, "game.citymindist");
 
     game.rapturedelay  = secfile_lookup_int_default(file,
       GAME_DEFAULT_RAPTUREDELAY, "game.rapturedelay");
 
     /* National borders setting. */
     game.borders = secfile_lookup_int_default(file, 0, "game.borders");
 
+    /* Diplomacy. */
+    game.diplomacy = secfile_lookup_int_default(file, GAME_DEFAULT_DIPLOMACY, 
+                                                "game.diplomacy");
+
     if (has_capability("watchtower", savefile_options)) {
       game.watchtower_extra_vision =
          secfile_lookup_int(file, "game.watchtower_extra_vision");
       game.watchtower_vision =
          secfile_lookup_int(file, "game.watchtower_vision");
     } else {
       game.watchtower_extra_vision = 0;
       game.watchtower_vision = 1;
     }
@@ -2300,18 +2304,19 @@
   secfile_insert_int(file, game.killcitizen, "game.killcitizen");
   secfile_insert_bool(file, game.turnblock, "game.turnblock");
   secfile_insert_bool(file, game.savepalace, "game.savepalace");
   secfile_insert_bool(file, game.fixedlength, "game.fixedlength");
   secfile_insert_int(file, game.barbarianrate, "game.barbarians");
   secfile_insert_int(file, game.onsetbarbarian, "game.onsetbarbs");
   secfile_insert_int(file, game.occupychance, "game.occupychance");
   secfile_insert_str(file, game.demography, "game.demography");
   secfile_insert_int(file, game.borders, "game.borders");
+  secfile_insert_int(file, game.diplomacy, "game.diplomacy");
   secfile_insert_int(file, game.watchtower_vision, "game.watchtower_vision");
   secfile_insert_int(file, game.watchtower_extra_vision, 
"game.watchtower_extra_vision");
   secfile_insert_int(file, game.allowed_city_names, "game.allowed_city_names");
 
   if (TRUE) {
     /* Now always save these, so the server options reflect the
      * actual values used at the start of the game.
      * The first two used to be saved as "map.xsize" and "map.ysize"
      * when PRE_GAME_STATE, but I'm standardizing on width,height --dwp
Index: server/stdinhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v
retrieving revision 1.291
diff -U9 -r1.291 stdinhand.c
--- server/stdinhand.c  2003/09/02 04:52:06     1.291
+++ server/stdinhand.c  2003/09/08 15:40:27
@@ -558,18 +558,27 @@
          GAME_DEFAULT_WATCHTOWER_EXTRA_VISION)
 
   GEN_INT("borders", game.borders, SSET_RULES, SSET_TO_CLIENT,
          N_("National border's radius"),
          N_("If this is set to greater than 0, nations will have territory "
             "delineated by borders placed on the loci between cities, with "
             "the maximum distance from any city specified."), NULL,
          GAME_MIN_BORDERS, GAME_MAX_BORDERS, GAME_DEFAULT_BORDERS)
 
+  GEN_INT("diplomacy", game.diplomacy, SSET_RULES, SSET_TO_CLIENT,
+         N_("The ability to do diplomacy with other players"),
+         N_("If set to 0 (default), diplomacy is enabled for all.\n"
+            "If set to 1, diplomacy is only allowed between human players.\n"
+            "If set to 2, diplomacy is only allowed between AI players.\n"
+             "If set to 3, diplomacy is disabled for all.\n"
+             "You can always do diplomacy with players on your team."), NULL,
+         GAME_MIN_DIPLOMACY, GAME_MAX_DIPLOMACY, GAME_DEFAULT_DIPLOMACY)
+
   GEN_INT("citynames", game.allowed_city_names, SSET_RULES, SSET_TO_CLIENT,
          N_("Allowed city names"),
          N_("If set to 0, there are no restrictions: players can have "
             "multiple cities with the same names. "
             "If set to 1, city names have to be unique to a player: "
             "one player can't have multiple cities with the same name. "
             "If set to 2 or 3, city names have to be globally unique: "
             "all cities in a game have to have different names. "
             "If set to 3, a player isn't allowed to use a default city name "

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