<URL: http://bugs.freeciv.org/Ticket/Display.html?id=37534 >

 Get base gfx tags from ruleset.

 For this first version only default ruleset and amplio tileset have
been updated.


 - ML

diff -Nurd -X.diff_ignore freeciv/client/packhand.c freeciv/client/packhand.c
--- freeciv/client/packhand.c	2007-03-04 18:03:59.000000000 +0200
+++ freeciv/client/packhand.c	2007-03-05 04:30:19.000000000 +0200
@@ -2473,6 +2473,8 @@
 
   sz_strlcpy(pbase->name_orig, p->name);
   pbase->name = Q_(pbase->name_orig);
+  sz_strlcpy(pbase->graphic_str, p->graphic_str);
+  sz_strlcpy(pbase->graphic_alt, p->graphic_alt);
 
   for (i = 0; i < p->reqs_count; i++) {
     requirement_vector_append(&pbase->reqs, &p->reqs[i]);
@@ -2480,6 +2482,8 @@
   assert(pbase->reqs.size == p->reqs_count);
 
   pbase->flags = p->flags;
+
+  tileset_setup_base(tileset, pbase);
 }
 
 /**************************************************************************
diff -Nurd -X.diff_ignore freeciv/client/tilespec.c freeciv/client/tilespec.c
--- freeciv/client/tilespec.c	2007-02-28 23:02:38.000000000 +0200
+++ freeciv/client/tilespec.c	2007-03-05 04:42:55.000000000 +0200
@@ -27,6 +27,7 @@
 #include <string.h>
 
 #include "astring.h"
+#include "base.h"
 #include "capability.h"
 #include "fcintl.h"
 #include "game.h" /* for fill_xxx */
@@ -241,9 +242,6 @@
       *irrigation[MAX_INDEX_CARDINAL],
       *pollution,
       *village,
-      *fortress,
-      *fortress_back,
-      *airbase,
       *fallout,
       *fog,
       **fullfog,
@@ -253,6 +251,12 @@
   } tx;				/* terrain extra */
   struct {
     struct sprite
+      *background,
+      *middleground,
+      *foreground;
+  } bases[BASE_LAST];
+  struct {
+    struct sprite
       *main[EDGE_COUNT],
       *city[EDGE_COUNT],
       *worked[EDGE_COUNT],
@@ -947,6 +951,9 @@
   government_iterate(gov) {
     tileset_setup_government(tileset, gov->index);
   } government_iterate_end;
+  base_type_iterate(pbase) {
+    tileset_setup_base(tileset, pbase);
+  } base_type_iterate_end;
   for (id = 0; id < game.control.nation_count; id++) {
     tileset_setup_nation_flag(tileset, id);
   }
@@ -2259,9 +2266,6 @@
   SET_SPRITE(tx.fallout,    "tx.fallout");
   SET_SPRITE(tx.pollution,  "tx.pollution");
   SET_SPRITE(tx.village,    "tx.village");
-  SET_SPRITE(tx.fortress,   "tx.fortress");
-  SET_SPRITE_ALT(tx.fortress_back, "tx.fortress_back", "tx.fortress");
-  SET_SPRITE(tx.airbase,    "tx.airbase");
   SET_SPRITE(tx.fog,        "tx.fog");
 
   /* Load color sprites. */
@@ -2591,6 +2595,57 @@
 			    presource->name);
 }
 
+/****************************************************************************
+  Set base sprite values; should only happen after
+  tilespec_load_tiles().
+****************************************************************************/
+void tileset_setup_base(struct tileset *t,
+                        const struct base_type *pbase)
+{
+  char full_tag_name_pri[MAX_LEN_NAME + strlen("_fg")];
+  char full_tag_name_alt[MAX_LEN_NAME + strlen("_fg")];
+  const int id = pbase->id;
+
+  assert(id >= 0 && id < game.control.num_base_types);
+
+  sz_strlcpy(full_tag_name_pri, pbase->graphic_str);
+  strcat(full_tag_name_pri, "_bg");
+  sz_strlcpy(full_tag_name_alt, pbase->graphic_str);
+  strcat(full_tag_name_alt, "_bg");
+
+  t->sprites.bases[id].background
+    = lookup_sprite_tag_alt(t, full_tag_name_pri,
+			    full_tag_name_alt,
+			    FALSE, "base_type",
+			    pbase->name);
+
+  sz_strlcpy(full_tag_name_pri, pbase->graphic_str);
+  strcat(full_tag_name_pri, "_mg");
+  sz_strlcpy(full_tag_name_alt, pbase->graphic_str);
+  strcat(full_tag_name_alt, "_mg");
+  t->sprites.bases[id].middleground
+    = lookup_sprite_tag_alt(t, full_tag_name_pri,
+			    full_tag_name_alt,
+			    FALSE, "base_type",
+			    pbase->name);
+
+  sz_strlcpy(full_tag_name_pri, pbase->graphic_str);
+  strcat(full_tag_name_pri, "_fg");
+  sz_strlcpy(full_tag_name_alt, pbase->graphic_str);
+  strcat(full_tag_name_alt, "_fg");
+  t->sprites.bases[id].foreground
+    = lookup_sprite_tag_alt(t, full_tag_name_pri,
+			    full_tag_name_alt,
+			    FALSE, "base_type",
+			    pbase->name);
+
+  if (t->sprites.bases[id].background == NULL
+      && t->sprites.bases[id].middleground == NULL
+      && t->sprites.bases[id].foreground == NULL) {
+    freelog(LOG_ERROR, _("No graphics for base %s at all!"), pbase->name);
+    exit(EXIT_FAILURE);
+  }
+}
 
 
 /**********************************************************************
@@ -4072,10 +4127,9 @@
 	}
       }
 
-      if (draw_fortress_airbase
-          && pbase != NULL && pbase->id == BASE_FORTRESS
-	  && t->sprites.tx.fortress_back) {
-	ADD_SPRITE_FULL(t->sprites.tx.fortress_back);
+      if (draw_fortress_airbase && pbase != NULL
+          && t->sprites.bases[pbase->id].background) {
+        ADD_SPRITE_FULL(t->sprites.bases[pbase->id].background);
       }
 
       if (draw_mines && contains_special(tspecial, S_MINE)
@@ -4127,9 +4181,9 @@
 
   case LAYER_SPECIAL2:
     if (ptile && client_tile_get_known(ptile) != TILE_UNKNOWN) {
-      if (draw_fortress_airbase
-          && pbase != NULL && pbase->id == BASE_AIRBASE) {
-	ADD_SPRITE_FULL(t->sprites.tx.airbase);
+      if (draw_fortress_airbase && pbase != NULL
+          && t->sprites.bases[pbase->id].middleground) {
+        ADD_SPRITE_FULL(t->sprites.bases[pbase->id].middleground);
       }
 
       if (draw_pollution && contains_special(tspecial, S_POLLUTION)) {
@@ -4176,11 +4230,11 @@
 
   case LAYER_SPECIAL3:
     if (ptile && client_tile_get_known(ptile) != TILE_UNKNOWN) {
-      if (t->is_isometric && draw_fortress_airbase
-          && pbase != NULL && pbase->id == BASE_FORTRESS) {
+      if (draw_fortress_airbase && pbase != NULL
+          && t->sprites.bases[pbase->id].foreground) {
 	/* Draw fortress front in iso-view (non-iso view only has a fortress
 	 * back). */
-	ADD_SPRITE_FULL(t->sprites.tx.fortress);
+	ADD_SPRITE_FULL(t->sprites.bases[pbase->id].foreground);
       }
     }
     break;
diff -Nurd -X.diff_ignore freeciv/client/tilespec.h freeciv/client/tilespec.h
--- freeciv/client/tilespec.h	2007-02-26 14:16:19.000000000 +0200
+++ freeciv/client/tilespec.h	2007-03-05 04:32:56.000000000 +0200
@@ -25,6 +25,8 @@
 
 struct sprite;			/* opaque; gui-dep */
 
+struct base_type;
+
 /* Create the sprite_vector type. */
 #define SPECVEC_TAG sprite
 #define SPECVEC_TYPE struct sprite *
@@ -130,6 +132,8 @@
 			     const struct terrain *pterrain);
 void tileset_setup_resource(struct tileset *t,
 			    const struct resource *presource);
+void tileset_setup_base(struct tileset *t,
+                        const struct base_type *pbase);
 void tileset_setup_government(struct tileset *t, int id);
 void tileset_setup_nation_flag(struct tileset *t, int id);
 void tileset_setup_city_tiles(struct tileset *t, int style);
diff -Nurd -X.diff_ignore freeciv/common/base.h freeciv/common/base.h
--- freeciv/common/base.h	2007-03-05 00:51:27.000000000 +0200
+++ freeciv/common/base.h	2007-03-05 03:48:23.000000000 +0200
@@ -39,9 +39,11 @@
 BV_DEFINE(bv_base_flags, BF_LAST);
 
 struct base_type {
+  int id;
   const char *name;
   char name_orig[MAX_LEN_NAME];
-  int id;
+  char graphic_str[MAX_LEN_NAME];
+  char graphic_alt[MAX_LEN_NAME];
   struct requirement_vector reqs;
   bv_base_flags flags;
 };
diff -Nurd -X.diff_ignore freeciv/common/packets.def freeciv/common/packets.def
--- freeciv/common/packets.def	2007-03-03 23:02:08.000000000 +0200
+++ freeciv/common/packets.def	2007-03-05 03:51:34.000000000 +0200
@@ -1270,6 +1270,8 @@
 PACKET_RULESET_BASE=120;sc,lsend
   UINT8 id;
   STRING name[MAX_LEN_NAME];
+  STRING graphic_str[MAX_LEN_NAME];
+  STRING graphic_alt[MAX_LEN_NAME];
   UINT8 reqs_count;
   REQUIREMENT reqs[MAX_NUM_REQS:reqs_count];
   BV_BASE_FLAGS flags;
diff -Nurd -X.diff_ignore freeciv/data/amplio/moderncities.spec freeciv/data/amplio/moderncities.spec
--- freeciv/data/amplio/moderncities.spec	2007-02-26 14:15:32.000000000 +0200
+++ freeciv/data/amplio/moderncities.spec	2007-03-05 04:38:52.000000000 +0200
@@ -46,10 +46,10 @@
 ; used by all city styles
 
  0,  0, "city.disorder"
- 0,  1, "tx.airbase"
+ 0,  1, "base.airbase_mg"
  0,  2, "tx.airbase_full"
- 0,  4, "tx.fortress"
- 0,  5, "tx.fortress_back"
+ 0,  4, "base.fortress_fg"
+ 0,  5, "base.fortress_bg"
  0,  6, "city.electricage_occupied_0"
  0,  6, "city.modern_occupied_0"
  0,  6, "city.postmodern_occupied_0"
diff -Nurd -X.diff_ignore freeciv/data/default/terrain.ruleset freeciv/data/default/terrain.ruleset
--- freeciv/data/default/terrain.ruleset	2007-03-04 22:55:02.000000000 +0200
+++ freeciv/data/default/terrain.ruleset	2007-03-05 04:46:33.000000000 +0200
@@ -756,6 +756,9 @@
 ; fortress and airbase.
 ;
 ; name                    = Name of the base type.
+; graphic                 = tag specifing preferred graphic
+; graphic_alt	          = tag for alternate garphic if preferred graphic is not 
+;                           present. Can use eg "-" for no alternate graphic.
 ; reqs 	                  = requirements to build the base (see effects.ruleset
 ;                           and README.effects for help on requirements)
 ; flags
@@ -772,6 +775,8 @@
 
 [fortress]
 name        = _("Fortress")
+graphic     = "base.fortress"
+graphic_alt = "-"
 reqs        =
     { "type", "name", "range"
       "Tech", "Construction", "Player"
@@ -782,6 +787,8 @@
 
 [airbase]
 name        = _("Airbase")
+graphic     = "base.airbase"
+graphic_alt = "-"
 reqs        =
     { "type", "name", "range"
       "Tech", "Radio", "Player"
diff -Nurd -X.diff_ignore freeciv/server/ruleset.c freeciv/server/ruleset.c
--- freeciv/server/ruleset.c	2007-03-04 16:55:04.000000000 +0200
+++ freeciv/server/ruleset.c	2007-03-05 03:50:58.000000000 +0200
@@ -1801,6 +1801,13 @@
       freelog(LOG_ERROR, "Unhandled base type in load_ruleset_terrain()");
       exit(EXIT_FAILURE);
     }
+
+    sz_strlcpy(pbase->graphic_str,
+               secfile_lookup_str_default(file, "-", "%s.graphic", section));
+    sz_strlcpy(pbase->graphic_alt,
+               secfile_lookup_str_default(file, "-",
+                                          "%s.graphic_alt", section));
+
     reqs = lookup_req_list(file, section, "reqs");
     requirement_vector_copy(&pbase->reqs, reqs);
 
@@ -3061,6 +3068,8 @@
 
     packet.id = b->id;
     sz_strlcpy(packet.name, b->name);
+    sz_strlcpy(packet.graphic_str, b->graphic_str);
+    sz_strlcpy(packet.graphic_alt, b->graphic_alt);
 
     j = 0;
     requirement_vector_iterate(&b->reqs, preq) {
diff -Nurd -X.diff_ignore freeciv/version.in freeciv/version.in
--- freeciv/version.in	2007-03-03 23:02:09.000000000 +0200
+++ freeciv/version.in	2007-03-05 03:51:42.000000000 +0200
@@ -24,4 +24,4 @@
 #   - Avoid adding a new manditory capbility to the development branch for
 #     as long as possible.  We want to maintain network compatibility with
 #     the stable branch for as long as possible.
-FREECIV_NETWORK_CAPSTRING("+Freeciv.Devel.2007.Mar.03")
+FREECIV_NETWORK_CAPSTRING("+Freeciv.Devel.2007.Mar.05")
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to