[Freeciv-Dev] patch: move CAPABILITY from shared.h
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Currently, CAPABILITY is defined in shared.h, which means almost
everything must be re-compiled if the capability string is changed.
But this is unnecessary, since CAPABILITY is only used in three
places, when it is copied into our_capability[].
This patch moves the compiled in capability string out of shared.h
and into capstr.h and capstr.c. I also made some changes to the
big block of comments about the capability string.
I considered moving the capability string definition into capability.c,
or into shared.c (with an extern in the corresponding .h) but decided
it was cleaner and easy enough to make a new module for it.
I'm not 100% sure though...
Regards,
-- David
diff -N -u -r --exclude-from exclude freeciv-cvs/client/gui-gtk/gui_main.c
fc-adv/client/gui-gtk/gui_main.c
--- freeciv-cvs/client/gui-gtk/gui_main.c Sun Jun 6 16:02:22 1999
+++ fc-adv/client/gui-gtk/gui_main.c Tue Jun 8 11:01:27 1999
@@ -46,6 +46,7 @@
#include <optiondlg.h>
#include <spaceshipdlg.h>
#include <options.h>
+#include <capstr.h>
#define NOTIFY_DIALOG_FONT
"-b&h-lucidatypewriter-bold-r-normal-*-12-*-*-*-*-*-*-*"
#define FIXED_10_BFONT
"-b&h-lucidatypewriter-bold-r-normal-*-10-*-*-*-*-*-*-*"
@@ -758,7 +759,7 @@
single_tile_pixmap = gdk_pixmap_new(root_window,
NORMAL_TILE_WIDTH, NORMAL_TILE_HEIGHT, -1);
- strcpy(our_capability, CAPABILITY);
+ strcpy(our_capability, default_capability_str);
if (getenv("FREECIV_CAPS"))
strcpy(our_capability, getenv("FREECIV_CAPS"));
diff -N -u -r --exclude-from exclude freeciv-cvs/client/gui-xaw/gui_main.c
fc-adv/client/gui-xaw/gui_main.c
--- freeciv-cvs/client/gui-xaw/gui_main.c Sun Jun 6 16:02:22 1999
+++ fc-adv/client/gui-xaw/gui_main.c Tue Jun 8 11:01:27 1999
@@ -60,6 +60,7 @@
#include <spaceshipdlg.h>
#include <repodlgs.h>
#include <options.h>
+#include <capstr.h>
AppResources appResources;
@@ -484,7 +485,7 @@
XSetWMProtocols(display, XtWindow(toplevel), &wm_delete_window, 1);
XtOverrideTranslations(toplevel, XtParseTranslationTable
("<Message>WM_PROTOCOLS: quit-freeciv()"));
- strcpy(our_capability, CAPABILITY);
+ strcpy(our_capability, default_capability_str);
if (getenv("FREECIV_CAPS"))
strcpy(our_capability, getenv("FREECIV_CAPS"));
diff -N -u -r --exclude-from exclude freeciv-cvs/common/Makefile.am
fc-adv/common/Makefile.am
--- freeciv-cvs/common/Makefile.am Mon May 10 18:28:30 1999
+++ fc-adv/common/Makefile.am Tue Jun 8 11:01:28 1999
@@ -8,6 +8,8 @@
attribute.h \
capability.c \
capability.h \
+ capstr.c \
+ capstr.h \
city.c \
city.h \
diptreaty.c \
diff -N -u -r --exclude-from exclude freeciv-cvs/common/Makefile.in
fc-adv/common/Makefile.in
--- freeciv-cvs/common/Makefile.in Mon May 10 18:28:30 1999
+++ fc-adv/common/Makefile.in Tue Jun 8 11:01:53 1999
@@ -88,6 +88,8 @@
attribute.h \
capability.c \
capability.h \
+ capstr.c \
+ capstr.h \
city.c \
city.h \
diptreaty.c \
@@ -134,9 +136,9 @@
X_EXTRA_LIBS = @X_EXTRA_LIBS@
X_PRE_LIBS = @X_PRE_LIBS@
libcivcommon_a_LIBADD =
-libcivcommon_a_OBJECTS = capability.o city.o diptreaty.o game.o \
-genlist.o log.o map.o packets.o player.o mem.o registry.o sbuffer.o \
-shared.o spaceship.o tech.o unit.o
+libcivcommon_a_OBJECTS = capability.o capstr.o city.o diptreaty.o \
+game.o genlist.o log.o map.o packets.o player.o mem.o registry.o \
+sbuffer.o shared.o spaceship.o tech.o unit.o
AR = ar
CFLAGS = @CFLAGS@
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
@@ -148,10 +150,11 @@
TAR = tar
GZIP = --best
-DEP_FILES = .deps/capability.P .deps/city.P .deps/diptreaty.P \
-.deps/game.P .deps/genlist.P .deps/log.P .deps/map.P .deps/mem.P \
-.deps/packets.P .deps/player.P .deps/registry.P .deps/sbuffer.P \
-.deps/shared.P .deps/spaceship.P .deps/tech.P .deps/unit.P
+DEP_FILES = .deps/capability.P .deps/capstr.P .deps/city.P \
+.deps/diptreaty.P .deps/game.P .deps/genlist.P .deps/log.P .deps/map.P \
+.deps/mem.P .deps/packets.P .deps/player.P .deps/registry.P \
+.deps/sbuffer.P .deps/shared.P .deps/spaceship.P .deps/tech.P \
+.deps/unit.P
SOURCES = $(libcivcommon_a_SOURCES)
OBJECTS = $(libcivcommon_a_OBJECTS)
diff -N -u -r --exclude-from exclude freeciv-cvs/common/capstr.c
fc-adv/common/capstr.c
--- freeciv-cvs/common/capstr.c Thu Jan 1 10:00:00 1970
+++ fc-adv/common/capstr.c Tue Jun 8 11:03:55 1999
@@ -0,0 +1,74 @@
+/**********************************************************************
+ Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+***********************************************************************/
+
+/* Capabilities: original author: Mitch Davis (mjd@xxxxxxxxxxxxxxxx)
+ *
+ * The capability string is a string clients and servers trade to find
+ * out if they can talk to each other, and using which protocol version,
+ * and which features and behaviors to expect. The string is a list of
+ * words, separated by whitespace and/or commas, where each word indicates
+ * a capability that this version of Freeciv understands.
+ * If a capability word is mandatory, it should start with a "+".
+ *
+ * eg, #define CAPABILITY "+1.6, MapScroll, +AutoSettlers"
+ *
+ * Client and server functions can test these strings for a particular
+ * capability by calling the functions in capability.c
+ *
+ * The default_capability_str is below, but code should not test this
+ * string directly. Instead, each executable has a string our_capability,
+ * which gives the capabilities of the running executable. You can
+ * override the compiled-in capability string by setting the FREECIV_CAPS
+ * environment variable, though this is probably mainly useful for
+ * testing purposes.
+ *
+ * For checking the connections of other executables, each
+ * "struct connection" has a capability string, which gives the
+ * capability of the executable at the other end of the connection.
+ * So for the client, the capability of the server is in
+ * aconnection.capability, and for the server, the capabilities of
+ * connected clients are in game.players[i]->conn.capability
+ * (The client now also knows the capabilities of other clients,
+ * via game.players[i]->conn.capability.)
+ *
+ * Note the connection struct is a parameter to the functions to send and
+ * receive packets, which may be convenient for adjusting how a packet is
+ * sent or interpreted based on the capabilities of the connection.
+ *
+ * At the time of a major release, the capability string may be
+ * simplified; eg, the example string above could be replaced by "+1.7".
+ * Whoever makes such a change has responsibility to search the Freeciv
+ * code, and look for places where people are using has_capability.
+ * If you're taking a capability out of the string, because now every
+ * client and server supports it, then you should take out the
+ * if(has_capability()) code so that this code is always executed.
+ *
+ * (The savefile and ruleset files have strings which are used similarly,
+ * and checked by the has_capability function, but the strings there
+ * are not directly related to the capability strings discussed here.)
+ */
+
+const char * const default_capability_str = \
+ "+1.8 caravan1 nuke clientcommands";
+
+/* caravan1 means the server automatically establishes a traderoute
+ when a caravan type unit moves into an enemy city. For older
+ servers the client has to explicitly ask for a trade route.
+
+ "nuke" means that it is possible to explode nuclear
+ at a tile without enemy units. Maybe it should be mandatory
+ because it improves player's fighting capabilities.
+
+ "clientcommands" indicates that the server supports server commands
+ sent by clients.
+*/
diff -N -u -r --exclude-from exclude freeciv-cvs/common/capstr.h
fc-adv/common/capstr.h
--- freeciv-cvs/common/capstr.h Thu Jan 1 10:00:00 1970
+++ fc-adv/common/capstr.h Tue Jun 8 11:02:17 1999
@@ -0,0 +1,21 @@
+/**********************************************************************
+ Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+***********************************************************************/
+#ifndef FC__CAPSTR_H
+#define FC__CAPSTR_H
+
+extern const char * const default_capability_str;
+/* Don't use this except to set our_capability[];
+ * use our_capability[] instead; see comments in shared.c
+ */
+
+#endif
diff -N -u -r --exclude-from exclude freeciv-cvs/common/shared.h
fc-adv/common/shared.h
--- freeciv-cvs/common/shared.h Sat Jun 5 22:08:00 1999
+++ fc-adv/common/shared.h Tue Jun 8 11:05:06 1999
@@ -38,53 +38,6 @@
#define WORD_VERSION "version"
#endif
-/* Capabilities: Author: Mitch Davis (mjd@xxxxxxxxxxxxxxxx)
- *
- * Here's the string a client and server trade to find out if they can talk
- * to each other, and using which protocol version. The string is a list
- * of words, separated by whitespace and/or commas, where each word
- * indicates a capability that this version of Freeciv understands.
- * If a capability word is mandatory, it should start with a "+".
- *
- * eg, #define CAPABILITY "+1.6, MapScroll, +AutoSettlers"
- *
- * (Following para replaces previous c_capability and s_capability. --dwp)
- * There is a string our_capability, which gives the capabilities of
- * the running executable, be it client or server.
- * Each "struct connection" also has a capability string, which gives the
- * capability of the executable at the other end of the connection.
- * So for the client, the capability of the server is in
- * aconnection.capability, and for the server, the capabilities of
- * connected clients are in game.players[i]->conn.capability
- *
- * Client and server software can test these strings for a capability by
- * calling the has_capability fn in capability.c.
- *
- * Note the connection struct is a parameter to the functions to send and
- * receive packets, which may be convenient for adjusting how a packet is
- * sent or interpreted based on the capabilities of the connection.
- *
- * A note to whoever increments the capability string for a new release:
- * It is your responsibility to search the Freeciv code, and look for places
- * where people are using has_capability. If you're taking a capability out
- * of the string, because now every client and server supports it, then
- * you should take out the if(has_capability( code so that this code is
- * always executed.
- */
-
-#define CAPABILITY "+1.8 caravan1 nuke clientcommands"
-/* caravan1 means to server automatically established a traderoute
- when a caravan type unit moves into an enemy city. For older
- servers the client has to explicitly ask for a trade route.
-
- "nuke" means that it is possible to explode nuclear
- at a tile without enemy units. Maybe it should be mandatory
- because it improves player's fighting capabilities.
-
- "clientcommands" indicates that the server supports server commands
- sent by clients.
-*/
-
#define CITY_NAMES_FONT "10x20"
#define BROADCAST_EVENT -2
diff -N -u -r --exclude-from exclude freeciv-cvs/server/civserver.c
fc-adv/server/civserver.c
--- freeciv-cvs/server/civserver.c Sun Jun 6 16:03:36 1999
+++ fc-adv/server/civserver.c Tue Jun 8 11:01:28 1999
@@ -64,6 +64,7 @@
#include <autoattack.h>
#include <spacerace.h>
#include <console.h>
+#include <capstr.h>
void show_ending();
void end_game();
@@ -274,7 +275,7 @@
#endif
con_flush();
- strcpy(our_capability, CAPABILITY);
+ strcpy(our_capability, default_capability_str);
if (getenv("FREECIV_CAPS"))
strcpy(our_capability, getenv("FREECIV_CAPS"));
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] patch: move CAPABILITY from shared.h,
David Pfitzner <=
|
|