Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2004:
[Freeciv-Dev] (PR#9882) Continent and Ocean numbers
Home

[Freeciv-Dev] (PR#9882) Continent and Ocean numbers

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#9882) Continent and Ocean numbers
From: "Mateusz Stefek" <mstefek@xxxxxxxxx>
Date: Thu, 2 Sep 2004 03:24:11 -0700
Reply-to: rt@xxxxxxxxxxx

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

Sync with CVS.

Any comments?
--
mateusz
Index: ai/advdomestic.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advdomestic.c,v
retrieving revision 1.118
diff -u -r1.118 advdomestic.c
--- ai/advdomestic.c    31 Aug 2004 15:52:46 -0000      1.118
+++ ai/advdomestic.c    2 Sep 2004 10:17:15 -0000
@@ -63,7 +63,7 @@
     return 40;
   }
 
-  continent = map_get_continent(pcity->x, pcity->y);
+  continent = map_get_continent_number(pcity->x, pcity->y);
   vulnerable = ai->threats.continent[continent]
                || city_got_building(pcity, B_PALACE)
                || (ai->threats.invasions
@@ -86,12 +86,12 @@
 
   /* trump coinage, and wall, and sam */
   if (is_ocean(map_get_terrain(pcity->x, pcity->y))) {
-    return ai->threats.ocean[-map_get_continent(pcity->x, pcity->y)]
+    return ai->threats.ocean[map_get_ocean_number(pcity->x, pcity->y)]
            ? TRADE_WEIGHTING + 3 : 1;
   } else {
     adjc_iterate(pcity->x, pcity->y, x2, y2) {
       if (is_ocean(map_get_terrain(x2, y2))) {
-        Continent_id ocean_number = map_get_continent(x2, y2);
+        Continent_id ocean_number = map_get_ocean_number(x2, y2);
 
         if (ai->threats.ocean[-ocean_number]) {
           return TRADE_WEIGHTING + 3;
@@ -116,7 +116,7 @@
     return 50;
   }
 
-  continent = map_get_continent(pcity->x, pcity->y);
+  continent = map_get_continent_number(pcity->x, pcity->y);
   vulnerable = ai->threats.air
                && (ai->threats.continent[continent]
                    || is_water_adjacent_to_tile(pcity->x, pcity->y) 
@@ -147,7 +147,7 @@
   /* No non-allied player has nuclear capability yet. */
   if (ai->threats.nuclear == 0) { return 0; }
 
-  continent = map_get_continent(pcity->x, pcity->y);
+  continent = map_get_continent_number(pcity->x, pcity->y);
   if (ai->threats.continent[continent]
       || is_water_adjacent_to_tile(pcity->x, pcity->y)
       || city_got_building(pcity, B_PALACE)) {
@@ -167,7 +167,7 @@
 static int ai_eval_threat_missile(struct player *pplayer, struct city *pcity)
 {
   struct ai_data *ai = ai_data_get(pplayer);
-  Continent_id continent = map_get_continent(pcity->x, pcity->y);
+  Continent_id continent = map_get_continent_number(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);
@@ -926,9 +926,7 @@
                                  struct ai_choice *choice)
 {
   struct player *pplayer = city_owner(pcity);
-  /* Continent where the city is --- we won't be aiding any wonder 
-   * construction on another continent */
-  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;
@@ -943,7 +941,7 @@
   /* Count existing caravans */
   unit_list_iterate(pplayer->units, punit) {
     if (unit_flag(punit, F_HELP_WONDER)
-        && map_get_continent(punit->x, punit->y) == continent)
+        && map_is_same_continent(punit->x, punit->y, pcity->x, pcity->y))
       caravans++;
   } unit_list_iterate_end;
 
@@ -953,7 +951,7 @@
         && unit_type_flag(acity->currently_building, F_HELP_WONDER)
         && (acity->shield_stock
            >= unit_build_shield_cost(acity->currently_building))
-        && map_get_continent(acity->x, acity->y) == continent) {
+        && map_is_same_continent(acity->x, acity->y, pcity->x, pcity->y)) {
       caravans++;
     }
   } city_list_iterate_end;
@@ -975,7 +973,7 @@
      * to finish the wonder. */
     if (!acity->is_building_unit
         && is_wonder(acity->currently_building)
-        && map_get_continent(acity->x, acity->y) == continent
+        && map_is_same_continent(acity->x, acity->y, pcity->x, pcity->y)
         && acity != pcity
         && (build_points_left(acity)
            > unit_build_shield_cost(unit_type) * caravans)) {
Index: ai/aicity.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aicity.c,v
retrieving revision 1.160
diff -u -r1.160 aicity.c
--- ai/aicity.c 13 Aug 2004 15:59:11 -0000      1.160
+++ ai/aicity.c 2 Sep 2004 10:17:17 -0000
@@ -191,7 +191,7 @@
                                      : get_unit_type(freight)->move_rate;
 
   if (!pcity->is_building_unit && is_wonder(pcity->currently_building)) {
-    wonder_continent = map_get_continent(pcity->x, pcity->y);
+    wonder_continent = map_get_continent_number(pcity->x, pcity->y);
   } else {
     wonder_continent = 0;
   }
@@ -200,7 +200,8 @@
   city_list_iterate(pplayer->cities, othercity) {
     distance = WARMAP_COST(othercity->x, othercity->y);
     if (wonder_continent != 0
-        && map_get_continent(othercity->x, othercity->y) == wonder_continent) {
+        && map_get_continent_number(othercity->x, othercity->y) == 
+          wonder_continent) {
       othercity->ai.distance_to_wonder_city = distance;
     }
 
Index: ai/aidata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aidata.c,v
retrieving revision 1.36
diff -u -r1.36 aidata.c
--- ai/aidata.c 30 Aug 2004 21:20:33 -0000      1.36
+++ ai/aidata.c 2 Sep 2004 10:17:20 -0000
@@ -82,7 +82,7 @@
      * enough to warrant city walls. Concentrate instead on 
      * coastal fortresses and hunting down enemy transports. */
     city_list_iterate(aplayer->cities, acity) {
-      Continent_id continent = map_get_continent(acity->x, acity->y);
+      Continent_id continent = map_get_continent_number(acity->x, acity->y);
       ai->threats.continent[continent] = TRUE;
     } city_list_iterate_end;
 
@@ -98,13 +98,14 @@
          * seaborne units, we don't have to worry. Go on the offensive! */
         if (unit_type(punit)->attack_strength > 1) {
          if (is_ocean(map_get_terrain(punit->x, punit->y))) {
-           Continent_id continent = map_get_continent(punit->x, punit->y);
-           ai->threats.ocean[-continent] = TRUE;
+           Continent_id ocean_number = 
+             map_get_ocean_number(punit->x, punit->y);
+           ai->threats.ocean[ocean_number] = TRUE;
          } else {
            adjc_iterate(punit->x, punit->y, x2, y2) {
              if (is_ocean(map_get_terrain(x2, y2))) {
-               Continent_id continent = map_get_continent(x2, y2);
-               ai->threats.ocean[-continent] = TRUE;
+               Continent_id ocean_number = map_get_ocean_number(x2, y2);
+               ai->threats.ocean[ocean_number] = TRUE;
              }
            } adjc_iterate_end;
          }
@@ -151,19 +152,23 @@
   ai->explore.ocean = fc_calloc(ai->num_oceans + 1, sizeof(bool));
   whole_map_iterate(x, y) {
     struct tile *ptile = map_get_tile(x, y);
-    Continent_id continent = map_get_continent(x, y);
+    Continent_id continent;
 
     if (is_ocean(ptile->terrain)) {
+      Continent_id ocean_number = map_get_ocean_number(x, y);
       if (ai->explore.sea_done && ai_handicap(pplayer, H_TARGETS) 
           && !map_is_known(x, y, pplayer)) {
        /* We're not done there. */
         ai->explore.sea_done = FALSE;
-        ai->explore.ocean[-continent] = TRUE;
+        ai->explore.ocean[ocean_number] = TRUE;
       }
       /* skip rest, which is land only */
       continue;
     }
-    if (ai->explore.continent[ptile->continent]) {
+    
+    continent = map_get_continent_number(x, y);
+    
+    if (ai->explore.continent[continent]) {
       /* we don't need more explaining, we got the point */
       continue;
     }
@@ -187,7 +192,7 @@
   ai->stats.cities = fc_calloc(ai->num_continents + 1, sizeof(int));
   ai->stats.average_production = 0;
   city_list_iterate(pplayer->cities, pcity) {
-    ai->stats.cities[(int)map_get_continent(pcity->x, pcity->y)]++;
+    ai->stats.cities[(int)map_get_continent_number(pcity->x, pcity->y)]++;
     ai->stats.average_production += pcity->shield_surplus;
   } city_list_iterate_end;
   ai->stats.average_production /= MAX(1, city_list_size(&pplayer->cities));
@@ -196,7 +201,7 @@
     struct tile *ptile = map_get_tile(punit->x, punit->y);
 
     if (!is_ocean(ptile->terrain) && unit_flag(punit, F_SETTLERS)) {
-      ai->stats.workers[(int)map_get_continent(punit->x, punit->y)]++;
+      ai->stats.workers[(int)map_get_continent_number(punit->x, punit->y)]++;
     }
     if (unit_flag(punit, F_DIPLOMAT) && punit->ai.ai_role == AIUNIT_ATTACK) {
       /* Heading somewhere on a mission, reserve target. */
Index: ai/aitools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitools.c,v
retrieving revision 1.121
diff -u -r1.121 aitools.c
--- ai/aitools.c        31 Aug 2004 15:35:31 -0000      1.121
+++ ai/aitools.c        2 Sep 2004 10:17:23 -0000
@@ -579,7 +579,8 @@
 { 
   struct city *pc=NULL;
   int best_dist = -1;
-  Continent_id con = map_get_continent(x, y);
+  
+  int is_ocean = is_ocean(map_get_terrain(x, y));
 
   players_iterate(pplay) {
     /* If "enemy" is set, only consider cities whose owner we're at
@@ -594,8 +595,9 @@
       /* Find the closest city known to the player with a matching
        * continent. */
       if ((best_dist == -1 || city_dist < best_dist)
-         && (everywhere || con == 0
-             || con == map_get_continent(pcity->x, pcity->y))
+         && (everywhere ||
+             is_ocean ||
+             map_is_same_continent(pcity->x, pcity->y, x, y))
          && (!pplayer || map_is_known(pcity->x, pcity->y, pplayer))) {
        best_dist = city_dist;
         pc = pcity;
@@ -712,8 +714,7 @@
     if (pcity != acity
        && !acity->is_building_unit
        && is_wonder(acity->currently_building)
-       && (map_get_continent(acity->x, acity->y)
-           == map_get_continent(pcity->x, pcity->y))) {
+       && (map_is_same_continent(acity->x, acity->y, pcity->x, pcity->y))) {
       return TRUE;
     }
   } city_list_iterate_end;
Index: ai/aiunit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v
retrieving revision 1.334
diff -u -r1.334 aiunit.c
--- ai/aiunit.c 1 Sep 2004 11:47:25 -0000       1.334
+++ ai/aiunit.c 2 Sep 2004 10:17:35 -0000
@@ -319,7 +319,7 @@
   city_list_iterate(pplayer->cities, pcity) 
     if (!(pcity->is_building_unit) 
         && is_wonder(pcity->currently_building)
-        && map_get_continent(pcity->x, pcity->y) == cont) {
+        && map_get_continent_number(pcity->x, pcity->y) == cont) {
       return pcity;
   }
   city_list_iterate_end;
@@ -889,7 +889,7 @@
   CHECK_UNIT(punit);
   
   square_iterate(punit->x, punit->y, search_dist, xx, yy) {
-    if (map_get_continent(xx, yy) == map_get_continent(pc->x, pc->y)
+    if (map_is_same_continent(xx, yy, pc->x, pc->y)
         && real_map_distance(punit->x, punit->y, xx, yy) < dist) {
 
       dist = real_map_distance(punit->x, punit->y, xx, yy);
@@ -1338,7 +1338,7 @@
   /* Our total attack value with reinforcements */
   int attack;
   int move_time, move_rate;
-  Continent_id con = map_get_continent(punit->x, punit->y);
+
   struct unit *pdef;
   int maxd, needferry;
   /* Do we have access to sea? */
@@ -1613,7 +1613,7 @@
         /* Yes, we like this target */
         if (punit->id != 0 && is_ground_unit(punit) 
             && !unit_flag(punit, F_MARINES)
-            && map_get_continent(acity->x, acity->y) != con) {
+            && !map_is_same_continent(acity->x, acity->y, punit->x, punit->y)) 
{
           /* a non-virtual ground unit is trying to attack something on 
            * another continent.  Need a beachhead which is adjacent 
            * to the city and an available ocean tile */
@@ -1666,7 +1666,7 @@
       }
 
       if (is_ground_unit(punit) 
-          && (map_get_continent(aunit->x, aunit->y) != con 
+          && (!map_is_same_continent(aunit->x, aunit->y, punit->x, punit->y)
               || WARMAP_COST(aunit->x, aunit->y) >= maxd)) {
         /* Impossible or too far to walk */
         continue;
@@ -1900,7 +1900,8 @@
 
   if (punit->ai.ai_role == AIUNIT_NONE) {
     if ((pcity = wonder_on_continent(pplayer, 
-                                     map_get_continent(punit->x, punit->y))) 
+                                     map_get_continent_number(punit->x,
+                                                             punit->y))) 
         && unit_flag(punit, F_HELP_WONDER)
         && build_points_left(pcity) > (pcity->shield_surplus * 2)) {
       if (!same_pos(pcity->x, pcity->y, punit->x, punit->y)) {
@@ -1927,8 +1928,8 @@
            if (pcity
               && can_cities_trade(pcity, pdest)
               && can_establish_trade_route(pcity, pdest)
-               && map_get_continent(pcity->x, pcity->y) 
-                                == map_get_continent(pdest->x, pdest->y)) {
+               && map_is_same_continent(pcity->x, pcity->y, 
+                                       pdest->x, pdest->y)) {
              tradeval=trade_between_cities(pcity, pdest);
              if (tradeval != 0) {
                if (best < tradeval) {
@@ -2281,7 +2282,6 @@
 **************************************************************************/
 static void ai_manage_barbarian_leader(struct player *pplayer, struct unit 
*leader)
 {
-  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;
@@ -2301,7 +2301,7 @@
   unit_list_iterate(pplayer->units, aunit) {
     if (unit_has_role(aunit->type, L_BARBARIAN_LEADER)
        || !is_ground_unit(aunit)
-       || map_get_continent(aunit->x, aunit->y) != con)
+       || !map_is_same_continent(aunit->x, aunit->y, leader->x, leader->y))
       continue;
 
     if (WARMAP_COST(aunit->x, aunit->y) < mindist) {
@@ -2312,8 +2312,8 @@
 
   if (closest_unit
       && !same_pos(closest_unit->x, closest_unit->y, leader->x, leader->y)
-      && (map_get_continent(leader->x, leader->y)
-          == map_get_continent(closest_unit->x, closest_unit->y))) {
+      && (map_is_same_continent(leader->x, leader->y,
+                                closest_unit->x, closest_unit->y))) {
     (void) ai_unit_goto(leader, closest_unit->x, closest_unit->y);
     return; /* sticks better to own units with this -- jk */
   }
@@ -2326,7 +2326,7 @@
     unit_list_iterate(other_player->units, aunit) {
       if (is_military_unit(aunit)
          && is_ground_unit(aunit)
-         && map_get_continent(aunit->x, aunit->y) == con) {
+         && map_is_same_continent(aunit->x, aunit->y, leader->x, leader->y)) {
        /* questionable assumption: aunit needs as many moves to reach us as we
           need to reach it */
        dist = WARMAP_COST(aunit->x, aunit->y) - unit_move_rate(aunit);
Index: client/gui-gtk/cityrep.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/cityrep.c,v
retrieving revision 1.85
diff -u -r1.85 cityrep.c
--- client/gui-gtk/cityrep.c    1 May 2004 03:34:57 -0000       1.85
+++ client/gui-gtk/cityrep.c    2 Sep 2004 10:17:35 -0000
@@ -795,8 +795,8 @@
       for(; current; current = g_list_next(current))
        {
          struct city* selectedcity = current->data;
-          if (map_get_continent(pcity->x, pcity->y)
-              == map_get_continent(selectedcity->x, selectedcity->y))
+          if (map_is_same_continent(pcity->x, pcity->y,
+                                   selectedcity->x, selectedcity->y))
            {
              gtk_clist_select_row(GTK_CLIST(city_list),i,0);
              break;
Index: client/gui-gtk-2.0/cityrep.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/cityrep.c,v
retrieving revision 1.58
diff -u -r1.58 cityrep.c
--- client/gui-gtk-2.0/cityrep.c        1 May 2004 17:28:47 -0000       1.58
+++ client/gui-gtk-2.0/cityrep.c        2 Sep 2004 10:17:36 -0000
@@ -959,8 +959,8 @@
     itree_get(&it, 0, &res, -1);
     pcity = res;
 
-    if (map_get_continent(pcity->x, pcity->y)
-           == map_get_continent(selectedcity->x, selectedcity->y)) {
+    if (map_is_same_continent(pcity->x, pcity->y, 
+                              selectedcity->x, selectedcity->y)) {
       itree_select(city_selection, &it);
     }
   }
Index: client/gui-win32/cityrep.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/cityrep.c,v
retrieving revision 1.30
diff -u -r1.30 cityrep.c
--- client/gui-win32/cityrep.c  15 May 2004 21:30:34 -0000      1.30
+++ client/gui-win32/cityrep.c  2 Sep 2004 10:17:39 -0000
@@ -580,8 +580,8 @@
        {
          struct city *selectedcity;
          selectedcity=(struct city *)ListBox_GetItemData(hLst,cityids[j]);
-          if (map_get_continent(pcity->x, pcity->y)
-              == map_get_continent(selectedcity->x, selectedcity->y))
+          if (map_is_same_continent(pcity->x, pcity->y,
+                                   selectedcity->x, selectedcity->y))
            {    
              ListBox_SetSel(hLst,TRUE,i);
              break;
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.240
diff -u -r1.240 city.c
--- common/city.c       1 Sep 2004 19:45:19 -0000       1.240
+++ common/city.c       2 Sep 2004 10:17:45 -0000
@@ -1019,8 +1019,7 @@
     bonus = (pc1->tile_trade + pc2->tile_trade + 4) / 8;
 
     /* Double if on different continents. */
-    if (map_get_continent(pc1->x, pc1->y) !=
-       map_get_continent(pc2->x, pc2->y)) {
+    if (!map_is_same_continent(pc1->x, pc1->y, pc2->x, pc2->y)) {
       bonus *= 2;
     }
 
@@ -1199,8 +1198,7 @@
   case B_HOOVER:
   case B_BACH:
     if (improvement_variant(id)==1) {
-      return (map_get_continent(tmp->x, tmp->y) ==
-             map_get_continent(pcity->x, pcity->y));
+      return (map_is_same_continent(tmp->x, tmp->y, pcity->x, pcity->y));
     } else {
       return TRUE;
     }
@@ -2522,7 +2520,7 @@
   }
 
   improvements_update_redundant(pplayer, pcity, 
-                                map_get_continent(pcity->x, pcity->y),
+                                map_get_continent_number(pcity->x, pcity->y),
                                 improvement_types[impr].equiv_range);
 }
 
@@ -2541,7 +2539,7 @@
   mark_improvement(pcity, impr, I_NONE);
 
   improvements_update_redundant(pplayer, pcity,
-                                map_get_continent(pcity->x, pcity->y),
+                                map_get_continent_number(pcity->x, pcity->y),
                                 improvement_types[impr].equiv_range);
 }
 
Index: common/improvement.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/improvement.c,v
retrieving revision 1.44
diff -u -r1.44 improvement.c
--- common/improvement.c        1 Sep 2004 03:16:47 -0000       1.44
+++ common/improvement.c        2 Sep 2004 10:17:49 -0000
@@ -285,7 +285,7 @@
 
   if (pcity) {
     equiv_list[IR_CITY] = pcity->improvements;
-    cont = map_get_continent(pcity->x, pcity->y);
+    cont = map_get_continent_number(pcity->x, pcity->y);
     assert(cont > 0);
   }
 
@@ -492,7 +492,7 @@
 
     /* Fill the lists with existent improvements with Island equiv_range */
     city_list_iterate(pplayer->cities, pcity) {
-      Continent_id cont = map_get_continent(pcity->x, pcity->y);
+      Continent_id cont = map_get_continent_number(pcity->x, pcity->y);
       Impr_Status *improvs = 
                            &pplayer->island_improv[cont * game.num_impr_types];
 
@@ -606,7 +606,7 @@
   case IR_ISLAND:
     assert(cont > 0);
     city_list_iterate(pplayer->cities, pcity2) {
-      if (map_get_continent(pcity2->x, pcity2->y) == cont) {
+      if (map_get_continent_number(pcity2->x, pcity2->y) == cont) {
         CHECK_CITY_IMPR(pcity2);
       }
     } city_list_iterate_end;
Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.190
diff -u -r1.190 map.c
--- common/map.c        31 Aug 2004 05:43:51 -0000      1.190
+++ common/map.c        2 Sep 2004 10:18:13 -0000
@@ -1253,20 +1253,44 @@
 /***************************************************************
 ...
 ***************************************************************/
-Continent_id map_get_continent(int x, int y)
+Continent_id map_get_continent_number(int x, int y)
 {
+  assert(!is_ocean(map_get_terrain(x, y)));
   return MAP_TILE(x, y)->continent;
 }
 
 /***************************************************************
 ...
 ***************************************************************/
+Continent_id map_get_ocean_number(int x, int y)
+{
+  assert(is_ocean(map_get_terrain(x, y)));
+  /* continent number is stored as negative value */
+  return -(MAP_TILE(x, y)->continent);
+}
+
+/***************************************************************
+...
+***************************************************************/
 void map_set_continent(int x, int y, Continent_id val)
 {
   MAP_TILE(x, y)->continent = val;
 }
 
 /***************************************************************
+  Check if given tiles are on different continents/oceans
+  If one tile is on a ocean and the other on a land return FALSE
+***************************************************************/
+bool map_is_same_continent(int x, int y, int x2, int y2) 
+{
+  if (is_ocean(map_get_terrain(x, y)) != 
+      is_ocean(map_get_terrain(x2, y2))) {
+    return FALSE;
+  }
+  return (MAP_TILE(x, y)->continent == MAP_TILE(x2, y2)->continent);
+}
+
+/***************************************************************
 ...
 ***************************************************************/
 Terrain_type_id map_get_terrain(int x, int y)
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.210
diff -u -r1.210 map.h
--- common/map.h        26 Aug 2004 18:37:52 -0000      1.210
+++ common/map.h        2 Sep 2004 10:18:14 -0000
@@ -223,7 +223,9 @@
 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, Continent_id val);
-Continent_id map_get_continent(int x, int y);
+Continent_id map_get_continent_number(int x, int y);
+Continent_id map_get_ocean_number(int x, int y);
+bool map_is_same_continent(int x, int y, int x2, int y2);
 
 void initialize_move_costs(void);
 void reset_move_costs(int x, int y);
Index: server/gamehand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/gamehand.c,v
retrieving revision 1.138
diff -u -r1.138 gamehand.c
--- server/gamehand.c   29 Aug 2004 19:03:32 -0000      1.138
+++ server/gamehand.c   2 Sep 2004 10:18:46 -0000
@@ -208,7 +208,7 @@
        x = p.x + myrand(2 * game.dispersion + 1) - game.dispersion;
        y = p.y + myrand(2 * game.dispersion + 1) - game.dispersion;
       } while (!(normalize_map_pos(&x, &y)
-                && map_get_continent(p.x, p.y) == map_get_continent(x, y)
+                && map_is_same_continent(p.x, p.y, x, y)
                 && !is_ocean(map_get_terrain(x, y))
                 && !is_non_allied_unit_tile(map_get_tile(x, y),
                                             pplayer)));
Index: server/gotohand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/gotohand.c,v
retrieving revision 1.183
diff -u -r1.183 gotohand.c
--- server/gotohand.c   1 Sep 2004 19:54:18 -0000       1.183
+++ server/gotohand.c   2 Sep 2004 10:18:51 -0000
@@ -1248,21 +1248,20 @@
        * and with a boat */
       if (ground_unit_transporter_capacity(x, y, pplayer) > 0) {
         adjc_iterate(x, y, tmp_x, tmp_y) {
-          if (map_get_continent(tmp_x, tmp_y) == 
-              map_get_continent(punit->x, punit->y))
+          if (map_is_same_continent(tmp_x, tmp_y, punit->x, punit->y))
             /* The target is adjacent to our continent! */
             return TRUE;
         } adjc_iterate_end;
       }
     } else {
       /* Going to a land tile: better be our continent */
-      if (map_get_continent(punit->x, punit->y) == map_get_continent(x, y)) {
+      if (map_is_same_continent(punit->x, punit->y, x, y)) {
         return TRUE;
       } else {
         /* Well, it's not our continent, but maybe we are on a boat
          * adjacent to the target continent? */
        adjc_iterate(punit->x, punit->y, tmp_x, tmp_y) {
-         if (map_get_continent(tmp_x, tmp_y) == map_get_continent(x, y)) {
+         if (map_is_same_continent(tmp_x, tmp_y, x, y)) {
            return TRUE;
           }
        } adjc_iterate_end;
Index: server/mapgen.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/mapgen.c,v
retrieving revision 1.150
diff -u -r1.150 mapgen.c
--- server/mapgen.c     1 Sep 2004 22:41:39 -0000       1.150
+++ server/mapgen.c     2 Sep 2004 10:18:58 -0000
@@ -1290,7 +1290,7 @@
         continue;
       }
       for (j = 0; j < seen_conts; j++) {
-       if (map_get_continent(x1, y1) == conts[j]) {
+       if (map_get_continent_number(x1, y1) == conts[j]) {
           /* Continent of (x1,y1) is already in the list */
          break;
         }
@@ -1298,7 +1298,7 @@
       if (j >= seen_conts) { 
        /* we have not seen this continent yet */
        assert(seen_conts < CITY_TILES);
-       conts[seen_conts] = map_get_continent(x1, y1);
+       conts[seen_conts] = map_get_continent_number(x1, y1);
        seen_conts++;
       }
     } map_city_radius_iterate_end;
@@ -1390,7 +1390,7 @@
     return FALSE;
   }
 
-  if (islands[(int)map_get_continent(x, y)].starters == 0) {
+  if (islands[(int)map_get_continent_number(x, y)].starters == 0) {
     return FALSE;
   }
 
@@ -1411,7 +1411,7 @@
     int x1 = map.start_positions[i].x;
     int y1 = map.start_positions[i].y;
 
-    if (map_get_continent(x, y) == map_get_continent(x1, y1)
+    if (map_is_same_continent(x, y, x1, y1)
        && real_map_distance(x, y, x1, y1) < data->dist) {
       return FALSE;
     }
@@ -1451,7 +1451,7 @@
                                   * sizeof(*map.start_positions));
   while (data.count < game.nplayers) {
     if (rand_map_pos_filtered(&x, &y, &data, is_valid_start_pos)) {
-      islands[(int)map_get_continent(x, y)].starters--;
+      islands[(int)map_get_continent_number(x, y)].starters--;
       map.start_positions[data.count].x = x;
       map.start_positions[data.count].y = y;
       map.start_positions[data.count].nation = NO_NATION_SELECTED;
@@ -1915,7 +1915,8 @@
   while (i > 0 && (failsafe--) > 0) {
     get_random_map_position_from_state(&x, &y, pstate);
 
-    if (map_get_continent(x, y) == pstate->isleindex &&
+    if (!is_ocean(map_get_terrain(x, y)) &&
+        map_get_continent_number(x, y) == pstate->isleindex &&
        not_placed(x, y)) {
 
       /* the first condition helps make terrain more contiguous,
@@ -1968,7 +1969,8 @@
 
   while (i > 0 && (failsafe--) > 0) {
     get_random_map_position_from_state(&x, &y, pstate);
-    if (map_get_continent(x, y) == pstate->isleindex
+    if (is_ocean(map_get_terrain(x, y)) && 
+        map_get_continent_number(x, y) == pstate->isleindex
        && not_placed(x, y)) {
 
       /* the first condition helps make terrain more contiguous,
Index: server/maphand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/maphand.c,v
retrieving revision 1.146
diff -u -r1.146 maphand.c
--- server/maphand.c    31 Aug 2004 08:17:50 -0000      1.146
+++ server/maphand.c    2 Sep 2004 10:19:00 -0000
@@ -59,7 +59,7 @@
 **************************************************************************/
 static void assign_continent_flood(int x, int y, bool is_land, int nr)
 {
-  if (map_get_continent(x, y) != 0) {
+  if (map_get_tile(x, y)->continent != 0) {
     return;
   }
 
@@ -93,15 +93,15 @@
   }
   
   whole_map_iterate(x, y) {
-    Continent_id cont = map_get_continent(x, y);
     if (!is_ocean(map_get_terrain(x, y))) {
+      Continent_id cont = map_get_continent_number(x, y);
       adjc_iterate(x, y, x2, y2) {
-        Continent_id cont2 = map_get_continent(x2, y2);
        if (is_ocean(map_get_terrain(x2, y2))) {
-         if (lake_surrounders[-cont2] == 0) {
-           lake_surrounders[-cont2] = cont;
-         } else if (lake_surrounders[-cont2] != cont) {
-           lake_surrounders[-cont2] = -1;
+          Continent_id ocean = map_get_ocean_number(x2, y2);
+         if (lake_surrounders[ocean] == 0) {
+           lake_surrounders[ocean] = cont;
+         } else if (lake_surrounders[ocean] != cont) {
+           lake_surrounders[ocean] = -1;
          }
        }
       } adjc_iterate_end;
@@ -140,7 +140,7 @@
 
   /* Assign new numbers */
   whole_map_iterate(x, y) {
-    if (map_get_continent(x, y) != 0) {
+    if (map_get_tile(x, y)->continent != 0) {
       /* Already assigned. */
       continue;
     }
@@ -1480,23 +1480,23 @@
 *************************************************************************/
 static bool is_claimed_ocean(int x, int y, Continent_id *contp)
 {
-  Continent_id cont = map_get_continent(x, y);
+  Continent_id ocean = map_get_ocean_number(x, y);
   Continent_id cont2, other;
   int ocean_tiles;
   
-  if (get_ocean_size(-cont) <= MAXIMUM_CLAIMED_OCEAN_SIZE &&
-      lake_surrounders[-cont] > 0) {
-    *contp = lake_surrounders[-cont];
+  if (get_ocean_size(ocean) <= MAXIMUM_CLAIMED_OCEAN_SIZE &&
+      lake_surrounders[ocean] > 0) {
+    *contp = lake_surrounders[ocean];
     return TRUE;
   }
   
   other = 0;
   ocean_tiles = 0;
   adjc_iterate(x, y, x2, y2) {
-    cont2 = map_get_continent(x2, y2);
-    if (cont2 == cont) {
+    if (is_ocean(map_get_terrain(x2, y2))) {
       ocean_tiles++;
     } else {
+      cont2 = map_get_continent_number(x2, y2);
       if (other == 0) {
         other = cont2;
       } else if (other != cont2) {
@@ -1534,11 +1534,27 @@
     int distsq;                /* Squared distance to city */
     /* integer arithmetic equivalent of (borders+0.5)**2 */
     int cldistsq = game.borders * (game.borders + 1);
-    Continent_id cont = map_get_continent(x, y);
+    
+    if (!is_ocean(map_get_terrain(x, y))) {
+      cities_iterate(pcity) {
+        if (map_is_same_continent(pcity->x, pcity->y, x, y)) {
+          distsq = sq_map_distance(pcity->x, pcity->y, x, y);    
+          if (distsq < cldistsq ||
+               (distsq == cldistsq &&
+                (!closest || closest->turn_founded > pcity->turn_founded))) {
+            closest = pcity;
+            cldistsq = distsq;
+          } 
+       }
+      } cities_iterate_end;
+    } else {
+      /* (x,y) is ocean */
+      Continent_id cont;
 
-    if (!is_ocean(map_get_terrain(x, y)) || is_claimed_ocean(x, y, &cont)) {
+      is_claimed_ocean(x, y, &cont);
       cities_iterate(pcity) {
-       if (map_get_continent(pcity->x, pcity->y) == cont) {
+        if (!is_ocean(map_get_terrain(pcity->x, pcity->y)) &&
+           map_get_continent_number(pcity->x, pcity->y) == cont) {
           distsq = sq_map_distance(pcity->x, pcity->y, x, y);
           if (distsq < cldistsq ||
                (distsq == cldistsq &&
@@ -1546,11 +1562,10 @@
             closest = pcity;
             cldistsq = distsq;
           } 
-        }
+        }        
       } cities_iterate_end;
     }
   }
-
   return closest;
 }
 
Index: server/sanitycheck.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/sanitycheck.c,v
retrieving revision 1.50
diff -u -r1.50 sanitycheck.c
--- server/sanitycheck.c        29 Aug 2004 19:38:07 -0000      1.50
+++ server/sanitycheck.c        2 Sep 2004 10:19:00 -0000
@@ -102,20 +102,17 @@
   whole_map_iterate(x, y) {
     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);
       adjc_iterate(x, y, x1, y1) {
        if (is_ocean(map_get_terrain(x1, y1))) {
-         assert(map_get_continent(x1, y1) == cont);
+         assert(map_is_same_continent(x1, y1, x, y));
        }
       } 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);
+         assert(map_is_same_continent(x1, y1, x, y));
        }
       } adjc_iterate_end;
     }
Index: server/settlers.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/settlers.c,v
retrieving revision 1.199
diff -u -r1.199 settlers.c
--- server/settlers.c   31 Aug 2004 04:40:51 -0000      1.199
+++ server/settlers.c   2 Sep 2004 10:19:06 -0000
@@ -921,7 +921,6 @@
   struct player *pplayer = unit_owner(punit);
   bool in_use;                 /* true if the target square is being used
                                   by one of our cities */
-  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 */
@@ -946,7 +945,7 @@
       if (get_worker_city(pcity, i, j) == C_TILE_UNAVAILABLE)
        continue;
       in_use = (get_worker_city(pcity, i, j) == C_TILE_WORKER);
-      if (map_get_continent(x, y) == ucont
+      if (map_is_same_continent(x, y, punit->x, punit->y)
          && WARMAP_COST(x, y) <= THRESHOLD * mv_rate
          && !BV_CHECK_MASK(TERRITORY(x, y), my_enemies)
          /* pretty good, hope it's enough! -- Syela */
Index: server/unittools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v
retrieving revision 1.300
diff -u -r1.300 unittools.c
--- server/unittools.c  26 Aug 2004 18:37:53 -0000      1.300
+++ server/unittools.c  2 Sep 2004 10:19:10 -0000
@@ -1080,7 +1080,7 @@
     value = get_virtual_defense_power(U_LAST, u_type, x1, y1, FALSE, 0);
     value *= 10;
 
-    if (ptile->continent != map_get_continent(pcity->x, pcity->y)) {
+    if (!map_is_same_continent(x1, y1, pcity->x, pcity->y)) {
       value /= 2;
     }
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#9882) Continent and Ocean numbers, Mateusz Stefek <=