Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2003:
[Freeciv-Dev] (PR#4606) FreecivAC: Oceanic cities
Home

[Freeciv-Dev] (PR#4606) FreecivAC: Oceanic cities

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#4606) FreecivAC: Oceanic cities
From: "Ben Webb" <ben@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 18 Jul 2003 06:53:14 -0700
Reply-to: rt@xxxxxxxxxxxxxx

The attached patch generalises the city_can_be_built_here() function
such that it takes the move_type of the city-building unit into account.
This allows naval units with the Cities flag to build cities on ocean
tiles, while air units can build cities anywhere. (Since the default
rulesets include no such units, there is no visible gameplay change, but
it increases ruleset flexibility and allows for SMAC compatibility.)
A redundant is_ocean check in settlers.c is also removed by this patch,
and the cities-and-units-in-oceans sanity checks relaxed slightly.

        Ben
-- 
ben@xxxxxxxxxxxxxxxxxxxxxx         http://bellatrix.pcl.ox.ac.uk/~ben/
"It is quite a three-pipe problem."
        - 'The Red-Headed League', Sir Arthur Conan Doyle

diff -Nur -Xfreecivdiff.ignore freeciv-cvs/common/city.c 
freeciv-patched/common/city.c
--- freeciv-cvs/common/city.c   2003-07-18 13:40:03.000000000 +0100
+++ freeciv-patched/common/city.c       2003-07-18 14:39:48.000000000 +0100
@@ -817,11 +817,15 @@
 }
 
 /**************************************************************************
-...
+  Returns TRUE if the given unit can build a city at the given map
+  coordinates.
 **************************************************************************/
-bool city_can_be_built_here(int x, int y)
+bool city_can_be_built_here(int x, int y, struct unit *punit)
 {
-  if (is_ocean(map_get_terrain(x, y))) {
+  enum unit_move_type move_type = unit_type(punit)->move_type;
+
+  if ((move_type == LAND_MOVING && is_ocean(map_get_terrain(x, y)))
+      || (move_type == SEA_MOVING && !is_ocean(map_get_terrain(x, y)))) {
     return FALSE;
   }
 
diff -Nur -Xfreecivdiff.ignore freeciv-cvs/common/city.h 
freeciv-patched/common/city.h
--- freeciv-cvs/common/city.h   2003-07-10 11:53:40.000000000 +0100
+++ freeciv-patched/common/city.h       2003-07-18 14:39:48.000000000 +0100
@@ -393,7 +393,7 @@
                                struct city **result_pcity);
 bool is_worker_here(struct city *pcity, int city_x, int city_y);
 
-bool city_can_be_built_here(int x, int y);
+bool city_can_be_built_here(int x, int y, struct unit *punit);
 
 /* trade functions */
 bool can_establish_trade_route(struct city *pc1, struct city *pc2);
diff -Nur -Xfreecivdiff.ignore freeciv-cvs/common/unit.c 
freeciv-patched/common/unit.c
--- freeciv-cvs/common/unit.c   2003-07-18 13:40:03.000000000 +0100
+++ freeciv-patched/common/unit.c       2003-07-18 14:39:48.000000000 +0100
@@ -457,7 +457,7 @@
       return AB_NOT_BUILD_UNIT;
     if (punit->moves_left == 0)
       return AB_NO_MOVES_BUILD;
-    if (!city_can_be_built_here(punit->x, punit->y))
+    if (!city_can_be_built_here(punit->x, punit->y, punit))
       return AB_NOT_BUILD_LOC;
     return AB_BUILD_OK;
   }
diff -Nur -Xfreecivdiff.ignore freeciv-cvs/server/sanitycheck.c 
freeciv-patched/server/sanitycheck.c
--- freeciv-cvs/server/sanitycheck.c    2003-07-07 18:24:02.000000000 +0100
+++ freeciv-patched/server/sanitycheck.c        2003-07-18 14:41:27.000000000 
+0100
@@ -137,7 +137,9 @@
       } unit_list_iterate_end;
 
       assert(is_normal_map_pos(pcity->x, pcity->y));
-      assert(!is_ocean(map_get_terrain(pcity->x, pcity->y)));
+
+      /* Disabled, as we can build water bases now */
+      /*assert(!is_ocean(map_get_terrain(pcity->x, pcity->y)));*/
 
       city_map_iterate(x, y) {
        int map_x,map_y;
@@ -238,9 +240,7 @@
       pcity = map_get_city(x, y);
       if (pcity) {
        assert(pplayers_allied(city_owner(pcity), pplayer));
-      }
-
-      if (is_ocean(map_get_terrain(x, y))) {
+      } else if (is_ocean(map_get_terrain(x, y))) {
        assert(ground_unit_transporter_capacity(x, y, pplayer) >= 0);
       }
 
diff -Nur -Xfreecivdiff.ignore freeciv-cvs/server/settlers.c 
freeciv-patched/server/settlers.c
--- freeciv-cvs/server/settlers.c       2003-07-18 13:40:05.000000000 +0100
+++ freeciv-patched/server/settlers.c   2003-07-18 14:39:48.000000000 +0100
@@ -932,11 +932,10 @@
     int b, mv_cost, newv, moves = 0;
 
     if (!is_already_assigned(punit, pplayer, x, y)
-       && !is_ocean(map_get_terrain(x, y))
+       && city_can_be_built_here(x, y, punit)
        && !BV_CHECK_MASK(territory[x][y], my_enemies)
        /* pretty good, hope it's enough! -- Syela */
        && (near < 8 || map_get_continent(x, y) != ucont)
-       && city_can_be_built_here(x,y)
        && !city_exists_within_city_radius(x, y, FALSE)) {
 
       /* potential target, calculate mv_cost: */
diff -Nur -Xfreecivdiff.ignore freeciv-cvs/server/unittools.c 
freeciv-patched/server/unittools.c
--- freeciv-cvs/server/unittools.c      2003-07-18 13:40:05.000000000 +0100
+++ freeciv-patched/server/unittools.c  2003-07-18 14:39:48.000000000 +0100
@@ -2247,7 +2247,7 @@
 {
   struct player *pplayer = unit_owner(punit);
   
-  if (city_can_be_built_here(punit->x, punit->y)) {
+  if (city_can_be_built_here(punit->x, punit->y, punit)) {
     notify_player_ex(pplayer, punit->x, punit->y, E_HUT_CITY,
                     _("Game: You found a friendly city."));
     create_city(pplayer, punit->x, punit->y,

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#4606) FreecivAC: Oceanic cities, Ben Webb <=