[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]
On Mon, Sep 08, 2003 at 09:15:54AM -0700, Per I. Mathisen wrote:
>
> On Mon, 8 Sep 2003, jjc@xxxxxxxxxxxxxxxxxx wrote:
> > 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.
>
> Very nice. Can you have a go at disabling the Meet menu items, too?
game.diplomacy was not being sent to the client. New patch adds an optional
capability, dip_ability and will send the value of game.diplomacy to the
client.
--
Josh Cogliati
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.327
diff -U9 -r1.327 packhand.c
--- client/packhand.c 2003/08/19 16:44:19 1.327
+++ client/packhand.c 2003/09/08 22:30:04
@@ -1160,18 +1160,19 @@
{
int i;
bool boot_help, need_effect_update = FALSE;
game.gold=pinfo->gold;
game.tech=pinfo->tech;
game.researchcost=pinfo->researchcost;
game.skill_level=pinfo->skill_level;
game.timeout=pinfo->timeout;
+ game.diplomacy = pinfo->diplomacy;
game.end_year=pinfo->end_year;
game.year=pinfo->year;
game.turn=pinfo->turn;
game.min_players=pinfo->min_players;
game.max_players=pinfo->max_players;
game.nplayers=pinfo->nplayers;
game.globalwarming=pinfo->globalwarming;
game.heating=pinfo->heating;
Index: common/capstr.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v
retrieving revision 1.141
diff -U9 -r1.141 capstr.c
--- common/capstr.c 2003/08/04 14:57:42 1.141
+++ common/capstr.c 2003/09/08 22:30:24
@@ -73,19 +73,19 @@
* and checked by the same has_capability function, but the strings there
* are not directly related to the capability strings discussed here.)
*/
#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 " \
"+diplomacy2 +citizens_style +root_tech auth " \
- "+nat_ulimit +retake +goto_pack borders"
+ "+nat_ulimit +retake +goto_pack borders dip_ability"
/* "+1.14.0" is protocol for 1.14.0 release.
*
* "conn_info" is sending the conn_id field. To preserve compatability
* with old clients trying to connect this should persist across releases.
*
* "occupied": don't send info about units which are inside enemy
* cities but instead use the occupied flag of short_city_info.
*
@@ -136,18 +136,21 @@
* "nat_ulimit" means that the MAX_NUM_NATIONS limit has been removed,
* allowing easy adding of arbitrarily many nations.
*
* "retake" means that a client can switch players during a running game.
*
* "goto_pack" changes the goto route packet to send (255,255) instead of
* map.xsize/map.ysize to mark the end of the goto chunk.
*
* "borders" is support for national borders.
+ *
+ * "dip_ability" is support for reporting the state of ability to do
+ * diplomacy restrictions (see game.diplomacy)
*/
void init_our_capability(void)
{
const char *s;
s = getenv("FREECIV_CAPS");
if (!s) {
s = CAPABILITY;
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 22:30:25
@@ -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 22:30:25
@@ -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 22:30:27
@@ -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,18 +314,22 @@
#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: common/packets.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.c,v
retrieving revision 1.253
diff -U9 -r1.253 packets.c
--- common/packets.c 2003/08/07 21:24:50 1.253
+++ common/packets.c 2003/09/08 22:30:38
@@ -1056,18 +1056,21 @@
dio_put_uint8(&dout, pinfo->conquercost);
dio_put_uint8(&dout, pinfo->unhappysize);
dio_put_bool8(&dout, pinfo->angrycitizen);
for (i = 0; i < A_LAST /*game.num_tech_types */ ; i++)
dio_put_uint8(&dout, pinfo->global_advances[i]);
for (i = 0; i < B_LAST /*game.num_impr_types */ ; i++)
dio_put_uint16(&dout, pinfo->global_wonders[i]);
+ if (has_capability("dip_ability", pc->capability)) {
+ dio_put_uint8(&dout, pinfo->diplomacy);
+ }
dio_put_uint8(&dout, pinfo->techpenalty);
dio_put_uint8(&dout, pinfo->foodbox);
dio_put_uint8(&dout, pinfo->civstyle);
dio_put_bool8(&dout, pinfo->spacerace);
/* computed values */
dio_put_uint32(&dout, pinfo->seconds_to_turndone);
dio_put_uint32(&dout, pinfo->turn);
@@ -1104,18 +1107,21 @@
dio_get_uint8(&din, &pinfo->conquercost);
dio_get_uint8(&din, &pinfo->unhappysize);
dio_get_bool8(&din, &pinfo->angrycitizen);
for (i = 0; i < A_LAST /*game.num_tech_types */ ; i++)
dio_get_uint8(&din, &pinfo->global_advances[i]);
for (i = 0; i < B_LAST /*game.num_impr_types */ ; i++)
dio_get_uint16(&din, &pinfo->global_wonders[i]);
+ if (has_capability("dip_ability", pc->capability)) {
+ dio_get_uint8(&din, &pinfo->diplomacy);
+ }
dio_get_uint8(&din, &pinfo->techpenalty);
dio_get_uint8(&din, &pinfo->foodbox);
dio_get_uint8(&din, &pinfo->civstyle);
dio_get_bool8(&din, &pinfo->spacerace);
/* computed values */
dio_get_uint32(&din, &pinfo->seconds_to_turndone);
dio_get_uint32(&din, &pinfo->turn);
Index: common/packets.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.h,v
retrieving revision 1.150
diff -U9 -r1.150 packets.h
--- common/packets.h 2003/08/01 19:58:47 1.150
+++ common/packets.h 2003/09/08 22:30:43
@@ -877,18 +877,19 @@
int cooling;
int cityfactor;
int unhappysize;
bool angrycitizen;
int diplcost,freecost,conquercost;
int global_advances[A_LAST];
int global_wonders[B_LAST];
int foodbox;
int techpenalty;
+ int diplomacy;
bool spacerace;
/* the following values are computed each time packet_game_info is sent */
int seconds_to_turndone;
};
/*********************************************************
...
*********************************************************/
struct packet_map_info {
Index: server/gamehand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/gamehand.c,v
retrieving revision 1.126
diff -U9 -r1.126 gamehand.c
--- server/gamehand.c 2003/04/08 20:36:10 1.126
+++ server/gamehand.c 2003/09/08 22:31:02
@@ -222,18 +222,19 @@
ginfo.year = game.year;
ginfo.turn = game.turn;
ginfo.min_players = game.min_players;
ginfo.max_players = game.max_players;
ginfo.nplayers = game.nplayers;
ginfo.globalwarming = game.globalwarming;
ginfo.heating = game.heating;
ginfo.nuclearwinter = game.nuclearwinter;
ginfo.cooling = game.cooling;
+ ginfo.diplomacy = game.diplomacy;
ginfo.techpenalty = game.techpenalty;
ginfo.foodbox = game.foodbox;
ginfo.civstyle = game.civstyle;
ginfo.spacerace = game.spacerace;
ginfo.unhappysize = game.unhappysize;
ginfo.angrycitizen = game.angrycitizen;
ginfo.diplcost = game.diplcost;
ginfo.freecost = game.freecost;
ginfo.conquercost = game.conquercost;
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 22:31:12
@@ -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 22:31:29
@@ -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 22:31:55
@@ -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 "
|
|