Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2004:
[Freeciv-Dev] (PR#9637) Ocean numbers
Home

[Freeciv-Dev] (PR#9637) Ocean numbers

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#9637) Ocean numbers
From: "Gregory Berkolaiko" <Gregory.Berkolaiko@xxxxxxxxxxxxx>
Date: Wed, 11 Aug 2004 07:49:49 -0700
Reply-to: rt@xxxxxxxxxxx

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

> [jdorje - Mon Aug 09 16:42:10 2004]:
> 
> Gregory Berkolaiko wrote:
> 
> > Index: server/sanitycheck.c
> > ===================================================================
> > RCS file: /home/freeciv/CVS/freeciv/server/sanitycheck.c,v
> > retrieving revision 1.45
> > diff -u -r1.45 sanitycheck.c
> > --- server/sanitycheck.c    27 Jul 2004 16:43:48 -0000      1.45
> > +++ server/sanitycheck.c    9 Aug 2004 12:51:17 -0000
> > @@ -103,10 +103,15 @@
> >      struct tile *ptile = map_get_tile(x, y);
> >      struct city *pcity = map_get_city(x, y);
> >      int cont = map_get_continent(x, y);
> > +
> > +    assert(cont != 0);
> >      if (is_ocean(map_get_terrain(x, y))) {
> > -      assert(cont == 0);
> > +      adjc_iterate(x, y, x1, y1) {
> > +   if (is_ocean(map_get_terrain(x1, y1))) {
> > +     assert(map_get_continent(x1, y1) == cont);
> > +   }
> > +      } adjc_iterate_end;
> >      } else {
> > -      assert(cont != 0);
> >        adjc_iterate(x, y, x1, y1) {
> >     if (!is_ocean(map_get_terrain(x1, y1))) {
> >       assert(map_get_continent(x1, y1) == cont);
> 
> I changed this part to
> 
>    if (is_ocean(...)) {
>      assert(cont < 0);
>      ...
>    } else {
>      assert(cont > 0);
>      ...
>    }
> 
> but this exposed some problems still in the code.  map_get_continent 
> still returns an unsigned short so the first assertion quickly fails.  I 
> think we should have a "typedef signed short Continent_id;" somewhere 
> and use this in more places.

The attached patch introduces this typedef and uses the type everywhere.
I also added asserts as above.  Testing didn't crash.

I got a problem though, in improvements.h one function takes
Continent_id as an argument, but it doesn't know what it is.  I tried
including map.h but that brought out some other problems.  I guess there
is some C magic to overcome this, but I jus spelled out what is meant by
Continent_id in improvements.h

Hopefully it can be committed as it is, because I really don't want to
spend more time on something that stupid.

G.
Index: ai/advdomestic.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advdomestic.c,v
retrieving revision 1.114
diff -u -r1.114 advdomestic.c
--- ai/advdomestic.c    6 Aug 2004 16:46:24 -0000       1.114
+++ ai/advdomestic.c    11 Aug 2004 14:43:59 -0000
@@ -56,7 +56,7 @@
 static int ai_eval_threat_land(struct player *pplayer, struct city *pcity)
 {
   struct ai_data *ai = ai_data_get(pplayer);
-  int continent;
+  Continent_id continent;
   bool vulnerable;
 
   /* make easy AI dumb */
@@ -95,7 +95,7 @@
 static int ai_eval_threat_air(struct player *pplayer, struct city *pcity)
 {
   struct ai_data *ai = ai_data_get(pplayer);
-  int continent;
+  Continent_id continent;
   bool vulnerable;
 
   /* make easy AI dumber */
@@ -123,7 +123,7 @@
 static int ai_eval_threat_nuclear(struct player *pplayer, struct city *pcity)
 {
   struct ai_data *ai = ai_data_get(pplayer);
-  int continent;
+  Continent_id continent;
   int vulnerable = 1;
 
   /* make easy AI really dumb, like it was before */
@@ -154,7 +154,7 @@
 static int ai_eval_threat_missile(struct player *pplayer, struct city *pcity)
 {
   struct ai_data *ai = ai_data_get(pplayer);
-  int continent = map_get_continent(pcity->x, pcity->y);
+  Continent_id continent = map_get_continent(pcity->x, pcity->y);
   bool vulnerable = is_water_adjacent_to_tile(pcity->x, pcity->y)
                     || ai->threats.continent[continent]
                     || city_got_building(pcity, B_PALACE);
@@ -915,7 +915,7 @@
   struct player *pplayer = city_owner(pcity);
   /* Continent where the city is --- we won't be aiding any wonder 
    * construction on another continent */
-  int continent = map_get_continent(pcity->x, pcity->y);
+  Continent_id continent = map_get_continent(pcity->x, pcity->y);
   /* Total count of caravans available or already being built 
    * on this continent */
   int caravans = 0;
Index: ai/aicity.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aicity.c,v
retrieving revision 1.159
diff -u -r1.159 aicity.c
--- ai/aicity.c 20 Jul 2004 10:05:43 -0000      1.159
+++ ai/aicity.c 11 Aug 2004 14:43:59 -0000
@@ -184,7 +184,8 @@
 static void establish_city_distances(struct player *pplayer, 
                                     struct city *pcity)
 {
-  int distance, wonder_continent;
+  int distance;
+  Continent_id wonder_continent;
   Unit_Type_id freight = best_role_unit(pcity, F_HELP_WONDER);
   int moverate = (freight == U_LAST) ? SINGLE_MOVE
                                      : get_unit_type(freight)->move_rate;
Index: ai/aidata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aidata.c,v
retrieving revision 1.30
diff -u -r1.30 aidata.c
--- ai/aidata.c 30 Jul 2004 20:40:49 -0000      1.30
+++ ai/aidata.c 11 Aug 2004 14:43:59 -0000
@@ -86,7 +86,7 @@
      * enough to warrant city walls. Concentrate instead on 
      * coastal fortresses and hunting down enemy transports. */
     city_list_iterate(aplayer->cities, acity) {
-      int continent = map_get_continent(acity->x, acity->y);
+      Continent_id continent = map_get_continent(acity->x, acity->y);
       ai->threats.continent[continent] = TRUE;
     } city_list_iterate_end;
 
@@ -153,7 +153,7 @@
   ai->explore.continent = fc_calloc(ai->num_continents + 1, sizeof(bool));
   whole_map_iterate(x, y) {
     struct tile *ptile = map_get_tile(x, y);
-    int continent = (int)map_get_continent(x, y);
+    Continent_id continent = map_get_continent(x, y);
 
     if (is_ocean(ptile->terrain)) {
       if (ai->explore.sea_done && ai_handicap(pplayer, H_TARGETS) 
Index: ai/aiexplorer.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiexplorer.c,v
retrieving revision 1.1
diff -u -r1.1 aiexplorer.c
--- ai/aiexplorer.c     6 Aug 2004 16:14:17 -0000       1.1
+++ ai/aiexplorer.c     11 Aug 2004 14:43:59 -0000
@@ -167,7 +167,7 @@
   int range = unit_type(punit)->vision_range;
   int desirable = 0;
   int unknown = 0;
-  int continent;
+  Continent_id continent;
 
   /* Localize the unit */
   
Index: ai/aitools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitools.c,v
retrieving revision 1.117
diff -u -r1.117 aitools.c
--- ai/aitools.c        6 Aug 2004 02:13:34 -0000       1.117
+++ ai/aitools.c        11 Aug 2004 14:44:00 -0000
@@ -577,7 +577,7 @@
 { 
   struct city *pc=NULL;
   int best_dist = -1;
-  int con = map_get_continent(x, y);
+  Continent_id con = map_get_continent(x, y);
 
   players_iterate(pplay) {
     /* If "enemy" is set, only consider cities whose owner we're at
Index: ai/aiunit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v
retrieving revision 1.325
diff -u -r1.325 aiunit.c
--- ai/aiunit.c 7 Aug 2004 17:53:50 -0000       1.325
+++ ai/aiunit.c 11 Aug 2004 14:44:00 -0000
@@ -313,7 +313,8 @@
   Return first city that contains a wonder being built on the given
   continent.
 **************************************************************************/
-static struct city *wonder_on_continent(struct player *pplayer, int cont)
+static struct city *wonder_on_continent(struct player *pplayer, 
+                                       Continent_id cont)
 {
   city_list_iterate(pplayer->cities, pcity) 
     if (!(pcity->is_building_unit) 
@@ -1290,7 +1291,7 @@
   /* Our total attack value with reinforcements */
   int attack;
   int move_time, move_rate;
-  int con = map_get_continent(punit->x, punit->y);
+  Continent_id con = map_get_continent(punit->x, punit->y);
   struct unit *pdef;
   int maxd, needferry;
   /* Do we have access to sea? */
@@ -2233,7 +2234,7 @@
 **************************************************************************/
 static void ai_manage_barbarian_leader(struct player *pplayer, struct unit 
*leader)
 {
-  int con = map_get_continent(leader->x, leader->y);
+  Continent_id con = map_get_continent(leader->x, leader->y);
   int safest = 0, safest_x = leader->x, safest_y = leader->y;
   struct unit *closest_unit = NULL;
   int dist, mindist = 10000;
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.393
diff -u -r1.393 packhand.c
--- client/packhand.c   2 Aug 2004 16:59:14 -0000       1.393
+++ client/packhand.c   11 Aug 2004 14:44:00 -0000
@@ -2012,8 +2012,11 @@
   }
 
   /* update continents */
-  if (ptile->continent != packet->continent && ptile->continent != 0) {
-    /* we're renumbering continents, somebody did a transform. */
+  if (ptile->continent != packet->continent && ptile->continent != 0
+      && packet->continent > 0) {
+    /* We're renumbering continents, somebody did a transform.
+     * But we don't care about renumbering oceans since 
+     * num_oceans is not kept at the client. */
     map.num_continents = 0;
   }
 
Index: common/capstr.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v
retrieving revision 1.175
diff -u -r1.175 capstr.c
--- common/capstr.c     30 Jul 2004 20:40:49 -0000      1.175
+++ common/capstr.c     11 Aug 2004 14:44:00 -0000
@@ -78,7 +78,7 @@
                    "+change_production +tilespec1 +no_earth +trans " \
                    "+want_hack invasions bombard +killstack2 spec +spec2 " \
                    "+city_map startunits +turn_last_built +happyborders " \
-                   "+connid +love"
+                   "+connid +love +ocean_num"
 
 /* "+1.14.delta" is the new delta protocol for 1.14.0-dev.
  *
@@ -136,6 +136,9 @@
  * info sent to clients.
  * 
  * "love" means that we show the AI love for you in the client
+ *
+ * "ocean_num" means that the oceans are numbered by negative numbers
+ * which are stored in ptile->continent and sent to client.
  */
 
 void init_our_capability(void)
Index: common/improvement.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/improvement.c,v
retrieving revision 1.42
diff -u -r1.42 improvement.c
--- common/improvement.c        1 Aug 2004 20:00:33 -0000       1.42
+++ common/improvement.c        11 Aug 2004 14:44:00 -0000
@@ -276,7 +276,7 @@
                                      struct city *pcity,
                                      struct player *pplayer)
 { 
-  int cont = 0;
+  Continent_id cont = 0;
   enum impr_range i;
 
   for (i = IR_NONE; i < IR_LAST; i++) {
@@ -491,7 +491,7 @@
 
     /* Fill the lists with existent improvements with Island equiv_range */
     city_list_iterate(pplayer->cities, pcity) {
-      int cont = map_get_continent(pcity->x, pcity->y);
+      Continent_id cont = map_get_continent(pcity->x, pcity->y);
       Impr_Status *improvs = 
                            &pplayer->island_improv[cont * game.num_impr_types];
 
@@ -561,7 +561,7 @@
   counts.
 **************************************************************************/
 void improvements_update_redundant(struct player *pplayer, struct city *pcity,
-                                   int cont, enum impr_range range)
+                                   signed short cont, enum impr_range range)
 {
 #define CHECK_CITY_IMPR(_pcity)                                              \
 {                                                                            \
Index: common/improvement.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/improvement.h,v
retrieving revision 1.27
diff -u -r1.27 improvement.h
--- common/improvement.h        18 Jul 2004 17:09:39 -0000      1.27
+++ common/improvement.h        11 Aug 2004 14:44:00 -0000
@@ -162,8 +162,9 @@
 void mark_improvement(struct city *pcity,Impr_Type_id id,Impr_Status status);
 void allot_island_improvs(void);
 void improvements_update_obsolete(void);
+/* signed short is Continent_id */
 void improvements_update_redundant(struct player *pplayer, struct city *pcity,
-                                   int cont, enum impr_range range);
+                                   signed short cont, enum impr_range range);
 
 /* Iterates over all improvements. Creates a new variable names m_i
  * with type Impr_Type_id which holds the id of the current improvement. */
Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.186
diff -u -r1.186 map.c
--- common/map.c        5 Aug 2004 10:41:34 -0000       1.186
+++ common/map.c        11 Aug 2004 14:44:00 -0000
@@ -209,6 +209,7 @@
   map.alltemperate          = MAP_DEFAULT_ALLTEMPERATE;
   map.tiles                 = NULL;
   map.num_continents        = 0;
+  map.num_oceans            = 0;
   map.num_start_positions   = 0;
   map.have_specials         = FALSE;
   map.have_rivers_overlay   = FALSE;
@@ -1248,7 +1249,7 @@
 /***************************************************************
 ...
 ***************************************************************/
-unsigned short map_get_continent(int x, int y)
+Continent_id map_get_continent(int x, int y)
 {
   return MAP_TILE(x, y)->continent;
 }
@@ -1256,7 +1257,7 @@
 /***************************************************************
 ...
 ***************************************************************/
-void map_set_continent(int x, int y, int val)
+void map_set_continent(int x, int y, Continent_id val)
 {
   MAP_TILE(x, y)->continent = val;
 }
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.203
diff -u -r1.203 map.h
--- common/map.h        5 Aug 2004 10:41:34 -0000       1.203
+++ common/map.h        11 Aug 2004 14:44:00 -0000
@@ -34,6 +34,8 @@
   HILITE_NONE = 0, HILITE_CITY
 };
 
+typedef signed short Continent_id;
+
 struct tile {
   enum tile_terrain_type terrain;
   enum tile_special_type special;
@@ -44,7 +46,7 @@
                           Player_no is index */
   int assigned; /* these can save a lot of CPU usage -- Syela */
   struct city *worked;      /* city working tile, or NULL if none */
-  unsigned short continent;
+  Continent_id continent;
   signed char move_cost[8]; /* don't know if this helps! */
   struct player *owner;     /* Player owning this tile, or NULL. */
   struct {
@@ -169,6 +171,7 @@
   bool have_huts;
   bool have_rivers_overlay;    /* only applies if !have_specials */
   int num_continents;
+  int num_oceans;               /* not updated at the client */
   struct tile *tiles;
 
   /* Only used by server. */
@@ -212,8 +215,8 @@
                                int end_y, int *dir);
 int get_direction_for_step(int start_x, int start_y, int end_x, int end_y);
 
-void map_set_continent(int x, int y, int val);
-unsigned short map_get_continent(int x, int y);
+void map_set_continent(int x, int y, Continent_id val);
+Continent_id map_get_continent(int x, int y);
 
 void initialize_move_costs(void);
 void reset_move_costs(int x, int y);
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.36
diff -u -r1.36 packets.def
--- common/packets.def  30 Jul 2004 20:40:49 -0000      1.36
+++ common/packets.def  11 Aug 2004 14:44:00 -0000
@@ -188,7 +188,7 @@
 type GOVERNMENT                = UINT8
 type CONNECTION                = UINT8
 type TEAM              = UINT8
-type CONTINENT          = UINT16
+type CONTINENT          = sint16(Continent_id)
 type IMPROVEMENT       = uint8(Impr_Type_id)
 
 # other typedefs
Index: common/packets_gen.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets_gen.c,v
retrieving revision 1.40
diff -u -r1.40 packets_gen.c
--- common/packets_gen.c        30 Jul 2004 20:40:49 -0000      1.40
+++ common/packets_gen.c        11 Aug 2004 14:44:01 -0000
@@ -3076,7 +3076,7 @@
     dio_get_uint8(&din, (int *) &real_packet->owner);
   }
   if (BV_ISSET(fields, 4)) {
-    dio_get_uint16(&din, (int *) &real_packet->continent);
+    dio_get_sint16(&din, (int *) &real_packet->continent);
   }
   if (BV_ISSET(fields, 5)) {
     dio_get_string(&din, real_packet->spec_sprite, 
sizeof(real_packet->spec_sprite));
@@ -3160,7 +3160,7 @@
     dio_put_uint8(&dout, real_packet->owner);
   }
   if (BV_ISSET(fields, 4)) {
-    dio_put_uint16(&dout, real_packet->continent);
+    dio_put_sint16(&dout, real_packet->continent);
   }
   if (BV_ISSET(fields, 5)) {
     dio_put_string(&dout, real_packet->spec_sprite);
Index: common/packets_gen.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets_gen.h,v
retrieving revision 1.32
diff -u -r1.32 packets_gen.h
--- common/packets_gen.h        30 Jul 2004 20:40:49 -0000      1.32
+++ common/packets_gen.h        11 Aug 2004 14:44:01 -0000
@@ -100,7 +100,7 @@
   int known;
   enum tile_special_type special;
   int owner;
-  int continent;
+  Continent_id continent;
   char spec_sprite[MAX_LEN_NAME];
 };
 
Index: server/mapgen.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/mapgen.c,v
retrieving revision 1.142
diff -u -r1.142 mapgen.c
--- server/mapgen.c     5 Aug 2004 10:41:34 -0000       1.142
+++ server/mapgen.c     11 Aug 2004 14:44:01 -0000
@@ -1203,48 +1203,59 @@
 }
 
 /**************************************************************************
- Number this tile and recursive adjacent tiles with specified
- continent number, by flood-fill algorithm.
+  Number this tile and recursive adjacent tiles with specified
+  continent number, by flood-fill algorithm.
+  is_land tells us whether we are assigning continent numbers or ocean 
+  numbers.
 **************************************************************************/
-static void assign_continent_flood(int x, int y, int nr)
+static void assign_continent_flood(int x, int y, bool is_land, int nr)
 {
   if (map_get_continent(x, y) != 0) {
     return;
   }
 
-  if (is_ocean(map_get_terrain(x, y))) {
+  if ((is_land && is_ocean(map_get_terrain(x, y)))
+      || (!is_land && !is_ocean(map_get_terrain(x, y)))) {
     return;
   }
 
   map_set_continent(x, y, nr);
 
   adjc_iterate(x, y, x1, y1) {
-    assign_continent_flood(x1, y1, nr);
+    assign_continent_flood(x1, y1, is_land, nr);
   } adjc_iterate_end;
 }
 
 /**************************************************************************
- Assign continent numbers to all tiles.
- Also sets map.num_continents (note 0 is ocean, and continents
- have numbers 1 to map.num_continents _inclusive_).
- Note this is not used by generators 2,3 or 4 at map creation
- time, as these assign their own continent numbers.
+  Assign continent and ocean numbers to all tiles, set map.num_continents 
+  and map.num_oceans.
+  Continents have numbers 1 to map.num_continents _inclusive_.
+  Oceans have (negative) numbers -1 to -map.num_oceans _inclusive_.
 **************************************************************************/
 void assign_continent_numbers(void)
 {
+  /* Initialize */
   map.num_continents = 0;
+  map.num_oceans = 0;
   whole_map_iterate(x, y) {
     map_set_continent(x, y, 0);
   } whole_map_iterate_end;
 
+  /* Assign new numbers */
   whole_map_iterate(x, y) {
-    if (map_get_continent(x, y) == 0 
-        && !is_ocean(map_get_terrain(x, y))) {
-      assign_continent_flood(x, y, ++map.num_continents);
+    if (map_get_continent(x, y) != 0) {
+      /* Already assigned */
+      continue;
     }
+    if (!is_ocean(map_get_terrain(x, y))) {
+      assign_continent_flood(x, y, TRUE, ++map.num_continents);
+    } else {
+      assign_continent_flood(x, y, FALSE, --map.num_oceans);
+    }      
   } whole_map_iterate_end;
 
-  freelog(LOG_VERBOSE, "Map has %d continents", map.num_continents);
+  freelog(LOG_VERBOSE, "Map has %d continents and %d oceans", 
+         map.num_continents, map.num_oceans);
 }
 
 /****************************************************************************
@@ -1307,7 +1318,7 @@
     /* number of different continents seen from (x,y) */
     int seen_conts = 0;
     /* list of seen continents */
-    int conts[CITY_TILES]; 
+    Continent_id conts[CITY_TILES]; 
     int j;
     
     /* add tile's value to each continent that is within city 
@@ -1315,7 +1326,7 @@
     map_city_radius_iterate(x, y, x1, y1) {
       /* (x1,y1) is possible location of a future city which will
        * be able to get benefit of the tile (x,y) */
-      if (map_get_continent(x1, y1) < 1 
+      if (is_ocean(map_get_terrain(x1, y1)) 
          || map_temperature(x1, y1) <= 2 * ICE_BASE_LEVEL) { 
        /* Not land, or too cold. */
         continue;
@@ -1417,6 +1428,10 @@
   int i;
   enum tile_terrain_type t = map_get_terrain(x, y);
 
+  if (is_ocean(map_get_terrain(x, y))) {
+    return FALSE;
+  }
+
   if (islands[(int)map_get_continent(x, y)].starters == 0) {
     return FALSE;
   }
@@ -1465,7 +1480,7 @@
   data.dist = MIN(40, MIN(map.xsize / 2, map.ysize / 2));
 
   sum = 0;
-  for (k = 0; k <= map.num_continents; k++) {
+  for (k = 1; k <= map.num_continents; k++) {
     sum += islands[k].starters;
     if (islands[k].starters != 0) {
       freelog(LOG_VERBOSE, "starters on isle %i", k);
@@ -2326,7 +2341,9 @@
   } whole_map_iterate_end;
   if (!map.alltemperate) {
     make_polar();
-    assign_continent_numbers(); /* set poles numbers */
+    /* Set poles numbers.  After the map is generated continents will 
+     * be renumbered. */
+    assign_continent_numbers(); 
   }
   make_island(0, 0, pstate, 0);
   islands[2].starters = 0;
Index: server/maphand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/maphand.c,v
retrieving revision 1.137
diff -u -r1.137 maphand.c
--- server/maphand.c    9 Aug 2004 05:24:35 -0000       1.137
+++ server/maphand.c    11 Aug 2004 14:44:01 -0000
@@ -1298,106 +1298,11 @@
 }
 
 /**************************************************************************
-  Recursively renumber the client continent at (x,y) with continent
-  number 'new'.  Ie, renumber (x,y) tile and recursive adjacent
-  land tiles with the same previous continent ('old').
-**************************************************************************/
-static void renumber_continent(int x, int y, int newnum)
-{
-  unsigned short old;
-
-  if(!normalize_map_pos(&x, &y)) {
-    return;
-  }
-  
-  old = map_get_continent(x, y);
-  
-  map_set_continent(x, y, newnum);
-  adjc_iterate(x, y, i, j) {
-    if (!is_ocean(map_get_terrain(i, j))
-        && map_get_continent(i, j) == old) {
-      freelog(LOG_DEBUG,
-              " renumbering continent %d to %d at (%d %d)", old, newnum, i, j);
-      renumber_continent(i, j, newnum);
-    }
-  } adjc_iterate_end;
-}
-
-/**************************************************************************
-  We just transformed (x,y). If we changed it from ocean to land, check to
-  see if we merged a continent. (assign a continent number if we didn't)
-  If we changed it from land to ocean, check to see if we split a continent 
-  in pieces.
-
-  There are two special cases: we raised atlantis and have ourselves a shiny
-  new island. so we set it to map.num_continents + 1 (this btw is impossible
-  under the current transform rules, but it's an easy enough case that we 
-  check for it here anyway), or we sunk a little atoll. In that case, we'll 
-  return FALSE, even though we lost a continent. 
-  It shouldn't make a difference.
-
-  As a bonus, we set the transformed tile's new continent number here.
-**************************************************************************/
-static bool check_for_continent_change(int x, int y)
-{
-  unsigned short con = 0, unused = map.num_continents + 1;
-
-  if (is_ocean(map_get_terrain(x, y))) {
-    map_set_continent(x, y, 0);
-    /* check for land surrounding this tile. */
-    adjc_iterate(x, y, i, j) {
-      if (!is_ocean(map_get_terrain(i, j))) {
-        /* we found a land tile, check for another */
-        adjc_iterate(x, y, l, m) {
-          if (!(l == i && j == m) && !is_ocean(map_get_terrain(l, m))) {
-            /* we found a second adjacent land tile. renumber it */
-            con = map_get_continent(l, m);
-            renumber_continent(l, m, unused);
-
-            /* did the original tile get renumbered? if it did, then we
-             * didn't split the continent. if it's different, then 
-             * we are the proud owner of separate continents */
-            if (map_get_continent(i, j) == unused) {
-              renumber_continent(l, m, con);
-            } else {
-              return TRUE;
-            }
-          }
-        } adjc_iterate_end; 
-      }
-    } adjc_iterate_end;
-  } else {
-    /* check for land surrounding this tile. */
-    adjc_iterate(x, y, i, j) {
-      if (!is_ocean(map_get_terrain(i, j))) {
-        if (con == 0) {
-          con = map_get_continent(i, j);
-        } else if (map_get_continent(i, j) != con) {
-          return TRUE;
-        }
-      }
-    } adjc_iterate_end;
-
-    if (con == 0) {
-      /* we raised atlantis */
-      map_set_continent(x, y, ++map.num_continents);
-
-      allot_island_improvs();
-    } else {
-      /* set the tile to something adjacent to it */
-      map_set_continent(x, y, con);
-    }
-  }
-
-  return FALSE;
-}
-
-/**************************************************************************
   Checks for terrain change between ocean and land.  Handles side-effects.
   (Should be called after any potential ocean/land terrain changes.)
   Also, returns an enum ocean_land_change, describing the change, if any.
 
-  if we did a land change, we do everything in our power to avoid reassigning
+  if we did a land change, we try to avoid reassigning
   continent numbers.
 **************************************************************************/
 enum ocean_land_change check_terrain_ocean_land_change(int x, int y,
@@ -1410,13 +1315,9 @@
     ocean_to_land_fix_rivers(x, y);
     city_landlocked_sell_coastal_improvements(x, y);
 
-    if (check_for_continent_change(x, y)) {
-      assign_continent_numbers();
-
-      allot_island_improvs();
-
-      send_all_known_tiles(NULL);
-    }
+    assign_continent_numbers();
+    allot_island_improvs();
+    send_all_known_tiles(NULL);
     
     map_update_borders_landmass_change(x, y);
 
@@ -1425,13 +1326,9 @@
   } else if (!is_ocean(oldter) && is_ocean(newter)) {
     /* land to ocean ... */
 
-    if (check_for_continent_change(x, y)) {
-      assign_continent_numbers();
-
-      allot_island_improvs();
-
-      send_all_known_tiles(NULL);
-    }
+    assign_continent_numbers();
+    allot_island_improvs();
+    send_all_known_tiles(NULL);
 
     map_update_borders_landmass_change(x, y);
 
@@ -1477,13 +1374,13 @@
   should in the long run perhaps be replaced with more general detection
   of inland seas.
 *************************************************************************/
-static bool is_claimed_ocean(int x, int y, int *contp)
+static bool is_claimed_ocean(int x, int y, Continent_id *contp)
 {
   int cont = -1, numland = 0;
 
   adjc_iterate(x, y, xp, yp) {
     if (!is_ocean(map_get_terrain(xp, yp))) {
-      int thiscont = map_get_continent(xp, yp);
+      Continent_id thiscont = map_get_continent(xp, yp);
       if (cont == -1) {
        cont = thiscont;
       }
@@ -1521,7 +1418,7 @@
     int distsq;                /* Squared distance to city */
     /* integer arithmetic equivalent of (borders+0.5)**2 */
     int cldistsq = game.borders * (game.borders + 1);
-    int cont = map_get_continent(x, y);
+    Continent_id cont = map_get_continent(x, y);
 
     if (!is_ocean(map_get_terrain(x, y)) || is_claimed_ocean(x, y, &cont)) {
       cities_iterate(pcity) {
Index: server/sanitycheck.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/sanitycheck.c,v
retrieving revision 1.45
diff -u -r1.45 sanitycheck.c
--- server/sanitycheck.c        27 Jul 2004 16:43:48 -0000      1.45
+++ server/sanitycheck.c        11 Aug 2004 14:44:01 -0000
@@ -103,10 +103,16 @@
     struct tile *ptile = map_get_tile(x, y);
     struct city *pcity = map_get_city(x, y);
     int cont = map_get_continent(x, y);
+
     if (is_ocean(map_get_terrain(x, y))) {
-      assert(cont == 0);
+      assert(cont < 0);
+      adjc_iterate(x, y, x1, y1) {
+       if (is_ocean(map_get_terrain(x1, y1))) {
+         assert(map_get_continent(x1, y1) == cont);
+       }
+      } adjc_iterate_end;
     } else {
-      assert(cont != 0);
+      assert(cont > 0);
       adjc_iterate(x, y, x1, y1) {
        if (!is_ocean(map_get_terrain(x1, y1))) {
          assert(map_get_continent(x1, y1) == cont);
Index: server/settlers.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/settlers.c,v
retrieving revision 1.194
diff -u -r1.194 settlers.c
--- server/settlers.c   11 Aug 2004 04:33:07 -0000      1.194
+++ server/settlers.c   11 Aug 2004 14:44:01 -0000
@@ -917,7 +917,7 @@
   struct player *pplayer = unit_owner(punit);
   bool in_use;                 /* true if the target square is being used
                                   by one of our cities */
-  int ucont           = map_get_continent(punit->x, punit->y);
+  Continent_id ucont     = map_get_continent(punit->x, punit->y);
   int mv_rate         = unit_type(punit)->move_rate;
   int mv_turns;                        /* estimated turns to move to target 
square */
   int oldv;                    /* current value of consideration tile */
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.179
diff -u -r1.179 srv_main.c
--- server/srv_main.c   5 Aug 2004 11:34:18 -0000       1.179
+++ server/srv_main.c   11 Aug 2004 14:44:01 -0000
@@ -1688,9 +1688,7 @@
     map_fractal_generate();
   }
 
-  if (map.num_continents == 0) {
-    assign_continent_numbers();
-  }
+  assign_continent_numbers();
 
   gamelog_map();
   /* start the game */
Index: server/unittools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v
retrieving revision 1.297
diff -u -r1.297 unittools.c
--- server/unittools.c  6 Aug 2004 14:46:28 -0000       1.297
+++ server/unittools.c  11 Aug 2004 14:44:01 -0000
@@ -42,7 +42,7 @@
 #include "diplhand.h"
 #include "gamelog.h"
 #include "gotohand.h"
-#include "mapgen.h"            /* assign_continent_numbers */
+//#include "mapgen.h"          /* assign_continent_numbers */
 #include "maphand.h"
 #include "plrhand.h"
 #include "sernet.h"

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