Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2004:
[Freeciv-Dev] Re: (PR#7416) RFC: death to earth
Home

[Freeciv-Dev] Re: (PR#7416) RFC: death to earth

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: (PR#7416) RFC: death to earth
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 17 Feb 2004 00:52:08 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=7416 >

Jason Short wrote:

> My proposal is this: a scenario may give, for each tile, the name of a 
> sprite to use for that tile.  If this sprite name is given and if the 
> tileset contains that sprite, it is used instead of the normal terrain 
> drawing provided by the tileset.  It is easy to make this mimic the 
> current behavior.  But it could also be used to do some really cool 
> things: you could take a map of all earth, split it up into tiles, and 
> play an entire game on this "accurate" map (with an appropriate scenario).

Here's a patch that does exactly this.

The behavior is identical for current scenarios, but is easily extensible.

jason

? client/gui-beos
? server/.new.hand_gen.
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.350
diff -u -r1.350 packhand.c
--- client/packhand.c   2004/02/07 11:16:49     1.350
+++ client/packhand.c   2004/02/17 08:50:18
@@ -1276,12 +1276,11 @@
 /**************************************************************************
 ...
 **************************************************************************/
-void handle_map_info(int xsize, int ysize, bool is_earth, int topology_id)
+void handle_map_info(int xsize, int ysize, int topology_id)
 {
   map.xsize = xsize;
   map.ysize = ysize;
   map.topology_id = topology_id;
-  map.is_earth = is_earth;
 
   map_allocate();
   init_client_goto();
@@ -1923,6 +1922,24 @@
     }
   }
   ptile->known = packet->known;
+
+  /* Don't upate tile_changed for this. */
+  if (packet->spec_sprite[0] != '\0') {
+    if (!ptile->spec_sprite
+       || strcmp(ptile->spec_sprite, packet->spec_sprite) != 0) {
+      if (ptile->spec_sprite) {
+       free(ptile->spec_sprite);
+      }
+      ptile->spec_sprite = mystrdup(packet->spec_sprite);
+      tile_changed = TRUE;
+    }
+  } else {
+    if (ptile->spec_sprite) {
+      free(ptile->spec_sprite);
+      ptile->spec_sprite = NULL;
+      tile_changed = TRUE;
+    }
+  }
 
   reset_move_costs(packet->x, packet->y);
 
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.138
diff -u -r1.138 tilespec.c
--- client/tilespec.c   2004/02/17 04:52:59     1.138
+++ client/tilespec.c   2004/02/17 08:50:19
@@ -1051,13 +1051,6 @@
       my_snprintf(buffer, sizeof(buffer), "tx.coast_cape_%s", nsew_str(i));
       SET_SPRITE(tx.coast_cape[i], buffer);
     }
-
-    for(i=0; i<2; i++) {
-      for(j=0; j<3; j++) {
-       my_snprintf(buffer, sizeof(buffer), "tx.denmark_%d%d", i, j);
-       SET_SPRITE(tx.denmark[i][j], buffer);
-      }
-    }
   }
 
   for(i=0; i<4; i++) {
@@ -2091,7 +2084,6 @@
   struct city *pcity;
   struct unit *pfocus;
   struct unit *punit;
-  int den_y=map.ysize*.24;
   struct drawn_sprite *save_sprs = sprs;
   *solid_bg = FALSE;
   *pplayer = NULL;
@@ -2128,9 +2120,9 @@
   build_tile_data(abs_x0, abs_y0, 
                  &ttype, &tspecial, ttype_near, tspecial_near);
 
-  if(map.is_earth &&
-     abs_x0>=34 && abs_x0<=36 && abs_y0>=den_y && abs_y0<=den_y+1) {
-    mysprite = sprites.tx.denmark[abs_y0-den_y][abs_x0-34];
+  if (ptile->spec_sprite && (mysprite = load_sprite(ptile->spec_sprite))) {
+    freelog(LOG_DEBUG, "Using spec_sprite %s for %d,%d",
+           ptile->spec_sprite, abs_x0, abs_y0);
   } else {
     /* FIXME: doesn't support is_layered. */
     if (sprites.terrain[ttype]->match_type == 0) {
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.50
diff -u -r1.50 tilespec.h
--- client/tilespec.h   2004/02/17 04:52:59     1.50
+++ client/tilespec.h   2004/02/17 08:50:19
@@ -216,8 +216,7 @@
       *river_outlet[4],                /* indexed by enum direction4 */
       *coast_cape_iso[8][4], /* 4 = up down left right */
       /* for non-isometric */
-      *coast_cape[NUM_DIRECTION_NSEW],       /* first unused */
-      *denmark[2][3];          /* row, column */
+      *coast_cape[NUM_DIRECTION_NSEW];       /* first unused */
   } tx;                                /* terrain extra */
 
   struct terrain_drawing_data *terrain[MAX_NUM_TERRAINS];
Index: common/capstr.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v
retrieving revision 1.158
diff -u -r1.158 capstr.c
--- common/capstr.c     2004/02/17 04:52:59     1.158
+++ common/capstr.c     2004/02/17 08:50:19
@@ -76,7 +76,7 @@
 
 #define CAPABILITY "+1.14.delta +last_turns_shield_surplus veteran +orders " \
                    "+starter +union +iso_maps +orders2client " \
-                   "+change_production +tilespec1"
+                   "+change_production +tilespec1 +no_earth"
 
 /* "+1.14.delta" is the new delta protocol for 1.14.0-dev.
  *
@@ -99,6 +99,9 @@
  * "change_production" is the E_CITY_PRODUCTION_CHANGED event.
  *
  * "tilespec1" means changed graphic strings in terrain.ruleset.
+ *
+ * "no_earth" means that the map.is_earth value is gone; replaced by
+ * ptile->spec_sprite
  */
 
 void init_our_capability(void)
Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.160
diff -u -r1.160 map.c
--- common/map.c        2004/02/02 01:48:48     1.160
+++ common/map.c        2004/02/17 08:50:19
@@ -181,7 +181,6 @@
   map.ysize                 = MAP_DEFAULT_HEIGHT;
   map.seed                  = MAP_DEFAULT_SEED;
   map.riches                = MAP_DEFAULT_RICHES;
-  map.is_earth              = FALSE;
   map.huts                  = MAP_DEFAULT_HUTS;
   map.landpercent           = MAP_DEFAULT_LANDMASS;
   map.grasssize             = MAP_DEFAULT_GRASS;
@@ -219,6 +218,7 @@
   if (!is_server) {
     ptile->client.hilite = HILITE_NONE; /* Area Selection in client. */
   }
+  ptile->spec_sprite = NULL;
 }
 
 /**************************************************************************
@@ -243,6 +243,10 @@
 static void tile_free(struct tile *ptile)
 {
   unit_list_unlink_all(&ptile->units);
+  if (ptile->spec_sprite) {
+    free(ptile->spec_sprite);
+    ptile->spec_sprite = NULL;
+  }
 }
 
 /**************************************************************************
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.175
diff -u -r1.175 map.h
--- common/map.h        2004/02/17 04:52:59     1.175
+++ common/map.h        2004/02/17 08:50:19
@@ -54,6 +54,7 @@
     /* Area Selection in client. */
     enum tile_hilite hilite;
   } client;
+  char *spec_sprite;
 };
 
 
@@ -122,7 +123,6 @@
   int xsize, ysize; /* native dimensions */
   int seed;
   int riches;
-  bool is_earth;
   int huts;
   int landpercent;
   int grasssize;
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.9
diff -u -r1.9 packets.def
--- common/packets.def  2004/02/07 11:16:50     1.9
+++ common/packets.def  2004/02/17 08:50:20
@@ -314,6 +314,7 @@
   SPECIAL special;
   PLAYER owner;
   CONTINENT continent;
+  STRING spec_sprite[MAX_LEN_NAME];
 end
 
 PACKET_GAME_INFO=15; is-info,sc
@@ -349,7 +350,6 @@
 PACKET_MAP_INFO=16; is-info,sc
   COORD xsize;
   COORD ysize;
-  BOOL is_earth;
   UINT8 topology_id;
 end
 
Index: data/scenario/earth-160x90-v2.sav
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/scenario/earth-160x90-v2.sav,v
retrieving revision 1.2
diff -u -r1.2 earth-160x90-v2.sav
--- data/scenario/earth-160x90-v2.sav   2002/11/22 23:19:47     1.2
+++ data/scenario/earth-160x90-v2.sav   2004/02/17 08:50:22
@@ -267,3 +267,9 @@
 
n087="0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
 
n088="0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
 
n089="0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
+spec_sprite_34_21="tx.denmark_00"
+spec_sprite_35_21="tx.denmark_01"
+spec_sprite_36_21="tx.denmark_02"
+spec_sprite_34_22="tx.denmark_10"
+spec_sprite_35_22="tx.denmark_11"
+spec_sprite_36_22="tx.denmark_12"
Index: data/scenario/earth-80x50-v2.sav
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/scenario/earth-80x50-v2.sav,v
retrieving revision 1.2
diff -u -r1.2 earth-80x50-v2.sav
--- data/scenario/earth-80x50-v2.sav    2000/08/09 13:24:21     1.2
+++ data/scenario/earth-80x50-v2.sav    2004/02/17 08:50:22
@@ -202,3 +202,9 @@
 
n047="00000000000000000000000000000000000000000000000000000000000000000000000000000000"
 
n048="00000000000000000000000000000000000000000000000000000000000000000000000000000000"
 
n049="00000000000000000000000000000000000000000000000000000000000000000000000000000000"
+spec_sprite_34_11="tx.denmark_00"
+spec_sprite_35_11="tx.denmark_01"
+spec_sprite_36_11="tx.denmark_02"
+spec_sprite_34_12="tx.denmark_10"
+spec_sprite_35_12="tx.denmark_11"
+spec_sprite_36_12="tx.denmark_12"
Index: server/maphand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/maphand.c,v
retrieving revision 1.132
diff -u -r1.132 maphand.c
--- server/maphand.c    2004/02/05 08:05:05     1.132
+++ server/maphand.c    2004/02/17 08:50:22
@@ -337,6 +337,11 @@
   info.x = x;
   info.y = y;
   info.owner = ptile->owner ? ptile->owner->player_no : MAP_TILE_OWNER_NULL;
+  if (ptile->spec_sprite) {
+    sz_strlcpy(info.spec_sprite, ptile->spec_sprite);
+  } else {
+    info.spec_sprite[0] = '\0';
+  }
 
   conn_list_iterate(*dest, pconn) {
     struct player *pplayer = pconn->player;
@@ -386,6 +391,11 @@
   info.x = x;
   info.y = y;
   info.owner = ptile->owner ? ptile->owner->player_no : MAP_TILE_OWNER_NULL;
+  if (ptile->spec_sprite) {
+    sz_strlcpy(info.spec_sprite, ptile->spec_sprite);
+  } else {
+    info.spec_sprite[0] = '\0';
+  }
 
   if (!pplayer) {
     /* Observer sees all. */
@@ -615,7 +625,6 @@
   minfo.xsize=map.xsize;
   minfo.ysize=map.ysize;
   minfo.topology_id = map.topology_id;
-  minfo.is_earth=map.is_earth;
  
   lsend_packet_map_info(dest, &minfo);
 }
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.146
diff -u -r1.146 savegame.c
--- server/savegame.c   2004/02/13 22:09:18     1.146
+++ server/savegame.c   2004/02/17 08:50:29
@@ -325,8 +325,6 @@
   map.topology_id = secfile_lookup_int_default(file, MAP_ORIGINAL_TOPO,
                                               "map.topology_id");
 
-  map.is_earth=secfile_lookup_bool(file, "map.is_earth");
-
   /* In some cases we read these before, but not always, and
    * its safe to read them again:
    */
@@ -341,6 +339,19 @@
                map_get_tile(x, y)->terrain = char2terrain(ch));
 
   assign_continent_numbers();
+
+  whole_map_iterate(mx, my) {
+    struct tile *ptile = map_get_tile(mx, my);
+    int nx, ny;
+
+    map_to_native_pos(&nx, &ny, mx, my);
+
+    ptile->spec_sprite = secfile_lookup_str_default(file, NULL,
+                               "map.spec_sprite_%d_%d", nx, ny);
+    if (ptile->spec_sprite) {
+      ptile->spec_sprite = mystrdup(ptile->spec_sprite);
+    }
+  } whole_map_iterate_end;
 }
 
 /***************************************************************
@@ -446,7 +457,9 @@
   /* map.xsize and map.ysize (saved as map.width and map.height)
    * are now always saved in game_save()
    */
-  secfile_insert_bool(file, map.is_earth, "map.is_earth");
+
+  /* Old freecivs expect map.is_earth to be present in the savegame. */
+  secfile_insert_bool(file, FALSE, "map.is_earth");
 
   secfile_insert_bool(file, game.save_options.save_starts, "game.save_starts");
   if (game.save_options.save_starts) {
@@ -508,6 +521,18 @@
     SAVE_NORMAL_MAP_DATA(x, y, file, "map.i%03d",
                         bin2ascii_hex(map_get_tile(x, y)->known, 7));
   }
+
+  whole_map_iterate(mx, my) {
+    struct tile *ptile = map_get_tile(mx, my);
+
+    if (ptile->spec_sprite) {
+      int nx, ny;
+
+      map_to_native_pos(&nx, &ny, mx, my);
+      secfile_insert_str(file, ptile->spec_sprite, 
+                        "map.spec_sprite_%d_%d", nx, ny);
+    }
+  } whole_map_iterate_end;
 }
 
 /***************************************************************

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] Re: (PR#7416) RFC: death to earth, Jason Short <=