Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2004:
[Freeciv-Dev] Re: (PR#6970) tririemes lost near arctic and units on arct
Home

[Freeciv-Dev] Re: (PR#6970) tririemes lost near arctic and units on arct

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: (PR#6970) tririemes lost near arctic and units on arctics
From: "Marcelo Burda" <mburda@xxxxxxxxx>
Date: Thu, 8 Jan 2004 09:20:27 -0800
Reply-to: rt@xxxxxxxxxxx

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

Ok, i am make a new patch for it (including the 6972)
 (plobably best if we joint the 2 ticket, no more "Wishlist")

this one is full civ1 and civ2 compilant if your choice this ruleset. no
options needed.

this change a litle the generator, i add spetial 2 tiles from coast, not
only one, if you like i can make it only one tile but coast cities need
spetials 2 tiles.


this implementing in not the best, probably we can make a best work if
we extend the concept of tiles flags to enviromentals flags initialisez
by server from the map, ( somes by generator) and some others After
generated or when loading its, this avoid the need to test nearest tiles
ich time. and can alow to determine cimatics zones.

but this is a nother idea.

Marcelo 


diff -ruN -Xdiff_ignore freeciv-cvs-Jan-04-ET1.22/common/aicore/pf_tools.c 
freeciv/common/aicore/pf_tools.c
--- freeciv-cvs-Jan-04-ET1.22/common/aicore/pf_tools.c  2003-11-20 
07:02:22.000000000 +0100
+++ freeciv/common/aicore/pf_tools.c    2004-01-07 12:11:28.000000000 +0100
@@ -376,9 +376,22 @@
 static bool trireme_is_pos_dangerous(int x, int y, enum known_type known,
                                     struct pf_parameter *param)
 {
-  return map_get_terrain(x, y) == T_OCEAN && !is_coastline(x, y);
+  return terrain_has_flag(map_get_terrain(x, y),TER_UNSAFE_COAST) 
+      && !is_safecoastline(x, y);
 }
 
+/**********************************************************************
+  An example of position-dangerous callback.  For all units.
+  FIXME: it cheats.
+***********************************************************************/
+static bool is_pos_dangerous(int x, int y, enum known_type known,
+                                    struct pf_parameter *param)
+{
+  return terrain_has_flag(map_get_terrain(x, y),TER_UNSAFE) 
+      && !is_safecoastline(x, y);
+}
+
+
 
 /* =====================  Tools for filling parameters =============== */
 
@@ -426,8 +439,9 @@
       && base_trireme_loss_pct(unit_owner(punit)) > 0) {
     parameter->turn_mode = TM_WORST_TIME;
     parameter->is_pos_dangerous = trireme_is_pos_dangerous;
-  } else {
-    parameter->is_pos_dangerous = NULL;
+  } else {  
+    parameter->turn_mode = TM_WORST_TIME;
+    parameter->is_pos_dangerous = is_pos_dangerous;
   }
 }
 
diff -ruN -Xdiff_ignore freeciv-cvs-Jan-04-ET1.22/common/map.c 
freeciv/common/map.c
--- freeciv-cvs-Jan-04-ET1.22/common/map.c      2004-01-06 18:31:50.000000000 
+0100
+++ freeciv/common/map.c        2004-01-07 18:27:12.000000000 +0100
@@ -519,7 +519,9 @@
   enum terrain_flag_id flag;
   const char *flag_names[] = {
     /* Must match terrain flags in terrain.h. */
-    "NoBarbs"
+    "NoBarbs",
+    "UnsafeCoast",
+    "UnsafeTerrain"
   };
 
   assert(ARRAY_SIZE(flag_names) == TER_COUNT);
@@ -578,11 +580,11 @@
 /***************************************************************
 ...
 ***************************************************************/
-bool is_coastline(int x, int y)
+bool is_safecoastline(int x, int y)
 {
   adjc_iterate(x, y, x1, y1) {
     enum tile_terrain_type ter = map_get_terrain(x1, y1);
-    if (!is_ocean(ter) && ter != T_UNKNOWN) {
+    if (!terrain_has_flag(ter, TER_UNSAFE_COAST) && ter != T_UNKNOWN) {
       return TRUE;
     }
   } adjc_iterate_end;
diff -ruN -Xdiff_ignore freeciv-cvs-Jan-04-ET1.22/common/map.h 
freeciv/common/map.h
--- freeciv-cvs-Jan-04-ET1.22/common/map.h      2004-01-06 18:31:00.000000000 
+0100
+++ freeciv/common/map.h        2004-01-07 11:47:30.000000000 +0100
@@ -412,7 +412,7 @@
 enum terrain_flag_id terrain_flag_from_str(const char *s);
 bool is_special_near_tile(int x, int y, enum tile_special_type spe);
 int count_special_near_tile(int x, int y, enum tile_special_type spe);
-bool is_coastline(int x,int y);
+bool is_safecoastline(int x,int y);
 bool terrain_is_clean(int x, int y);
 bool is_at_coast(int x, int y);
 bool is_hut_close(int x, int y);
diff -ruN -Xdiff_ignore freeciv-cvs-Jan-04-ET1.22/common/terrain.h 
freeciv/common/terrain.h
--- freeciv-cvs-Jan-04-ET1.22/common/terrain.h  2003-11-20 07:02:21.000000000 
+0100
+++ freeciv/common/terrain.h    2004-01-07 11:41:10.000000000 +0100
@@ -73,6 +73,8 @@
 
 enum terrain_flag_id {
   TER_NO_BARBS, /* No barbarians summoned on this terrain. */
+  TER_UNSAFE_COAST,/*this tile is not safe as coast, all_ocean! */ 
+  TER_UNSAFE,  /*unsafe for all units if no safe_coast tile near */ 
   TER_LAST
 };
 #define TER_FIRST (TER_NO_BARBS)
diff -ruN -Xdiff_ignore freeciv-cvs-Jan-04-ET1.22/common/unit.c 
freeciv/common/unit.c
--- freeciv-cvs-Jan-04-ET1.22/common/unit.c     2003-11-29 07:05:27.000000000 
+0100
+++ freeciv/common/unit.c       2004-01-08 14:33:07.000000000 +0100
@@ -1356,8 +1356,34 @@
 }
 
 /**************************************************************************
-  Like base_trireme_loss_pct but take the position into account.
+ No air unit on unsafe terrain loss pct
+**********+*****************************************************************/
+int unsafe_terrain_loss_pct(struct player *pplayer, int x, int y)
+{
+  /*
+   * If we are next to land, we have no chance of losing
+   * the unit.  To make this really useful for ai planning purposes,
+   * we'd need to confirm that we can exist/move at the (x, y)
+   * location we are given.
+   */
+  if (terrain_has_flag(map_get_terrain(x, y), TER_UNSAFE) 
+      && !is_safecoastline(x, y)) {
+    return base_unsafe_terrain_loss_pct( pplayer) ;
+  } else {
+    return 0;
+  }
+}
+
+/**************************************************************************
+ all no air unit have a 15% loss percentage in unsafe terrains
 **************************************************************************/
+base_unsafe_terrain_loss_pct(struct player *pplayer)
+{
+    return 15;
+}
+/****************************************************************************
+ Like base_trireme_loss_pct but take the position into account.
+*****************************************************************************/
 int trireme_loss_pct(struct player *pplayer, int x, int y)
 {
   /*
@@ -1366,10 +1392,11 @@
    * we'd need to confirm that we can exist/move at the (x, y)
    * location we are given.
    */
-  if (map_get_terrain(x, y) != T_OCEAN || is_coastline(x, y)) {
-    return 0;
-  } else {
+  if ( terrain_has_flag(map_get_terrain(x, y), TER_UNSAFE_COAST)
+      && !is_safecoastline(x, y)) {
     return base_trireme_loss_pct(pplayer);
+  } else {
+    return 0;
   }
 }
 
diff -ruN -Xdiff_ignore freeciv-cvs-Jan-04-ET1.22/common/unit.h 
freeciv/common/unit.h
--- freeciv-cvs-Jan-04-ET1.22/common/unit.h     2003-12-02 07:12:22.000000000 
+0100
+++ freeciv/common/unit.h       2004-01-08 14:33:47.000000000 +0100
@@ -268,6 +268,9 @@
 struct unit *is_non_attack_unit_tile(struct tile *ptile,
                                     struct player *pplayer);
 
+int unsafe_terrain_loss_pct(struct player *pplayer, int x, int y);
+int base_unsafe_terrain_loss_pct(struct player *pplayer);
+
 int trireme_loss_pct(struct player *pplayer, int x, int y);
 int base_trireme_loss_pct(struct player *pplayer);
 
diff -ruN -Xdiff_ignore freeciv-cvs-Jan-04-ET1.22/data/civ1/terrain.ruleset 
freeciv/data/civ1/terrain.ruleset
--- freeciv-cvs-Jan-04-ET1.22/data/civ1/terrain.ruleset 2003-10-03 
06:58:49.000000000 +0200
+++ freeciv/data/civ1/terrain.ruleset   2004-01-08 17:51:51.000000000 +0100
@@ -424,6 +424,7 @@
 mining_time          = 0
 transform_result     = "no"
 transform_time       = 0
+flags                = "UnsafeCoast"
 helptext            = _("\
 Oceans cover much of the world, and only sea units (Triremes and\
  other boats) can travel on them.\
diff -ruN -Xdiff_ignore freeciv-cvs-Jan-04-ET1.22/data/civ2/terrain.ruleset 
freeciv/data/civ2/terrain.ruleset
--- freeciv-cvs-Jan-04-ET1.22/data/civ2/terrain.ruleset 2003-10-03 
06:58:49.000000000 +0200
+++ freeciv/data/civ2/terrain.ruleset   2004-01-08 17:52:33.000000000 +0100
@@ -432,6 +432,7 @@
 mining_time          = 0
 transform_result     = "no"
 transform_time       = 0
+flags                = "UnsafeCoast"
 helptext            = _("\
 Oceans cover much of the world, and only sea units (Triremes and\
  other boats) can travel on them.\
diff -ruN -Xdiff_ignore freeciv-cvs-Jan-04-ET1.22/data/default/terrain.ruleset 
freeciv/data/default/terrain.ruleset
--- freeciv-cvs-Jan-04-ET1.22/data/default/terrain.ruleset      2003-10-03 
06:58:49.000000000 +0200
+++ freeciv/data/default/terrain.ruleset        2004-01-07 11:12:38.000000000 
+0100
@@ -179,7 +179,7 @@
 mining_time          = 10
 transform_result     = "Tundra"
 transform_time       = 24
-flags                = "NoBarbs"
+flags                = "NoBarbs", "UnsafeTerrain", "UnsafeCoast"
 helptext            = _("\
 Glaciers are found only in the most northerly or southerly\
  reaches of the world.  They are very cold, and hence difficult to\
@@ -432,6 +432,7 @@
 mining_time          = 0
 transform_result     = "Swamp"
 transform_time       = 36
+flags                = "UnsafeCoast"
 helptext            = _("\
 Oceans cover much of the world, and only sea units (Triremes and\
  other boats) can travel on them.\
Les fichiers binaires freeciv-cvs-Jan-04-ET1.22/gmon.out et freeciv/gmon.out 
sont différents.
diff -ruN -Xdiff_ignore freeciv-cvs-Jan-04-ET1.22/server/gotohand.c 
freeciv/server/gotohand.c
--- freeciv-cvs-Jan-04-ET1.22/server/gotohand.c 2004-01-06 18:31:21.000000000 
+0100
+++ freeciv/server/gotohand.c   2004-01-07 11:52:58.000000000 +0100
@@ -689,7 +689,9 @@
              /* Allow players to target anything */
              continue;
            } else {
-             move_cost = SINGLE_MOVE;
+             move_cost = (unsafe_terrain_loss_pct>0)
+                 ?(2*SINGLE_MOVE+1)
+                 :SINGLE_MOVE;
            }
          }
        } else if (!goto_zoc_ok(punit, x, y, x1, y1, LOCAL_VECTOR(x, y))) {
@@ -1154,7 +1156,7 @@
   } adjc_dir_iterate_end;
 
   if (best_fitness == DONT_SELECT_ME_FITNESS && afraid_of_sinking
-      && !is_coastline(punit->x, punit->y)) {
+      && !is_safecoastline(punit->x, punit->y)) {
     /* 
      * We've got a trireme in the middle of the sea. With
      * best_fitness==DONT_SELECT_ME_FITNESS, it'll end its turn right
diff -ruN -Xdiff_ignore freeciv-cvs-Jan-04-ET1.22/server/mapgen.c 
freeciv/server/mapgen.c
--- freeciv-cvs-Jan-04-ET1.22/server/mapgen.c   2004-01-06 18:31:51.000000000 
+0100
+++ freeciv/server/mapgen.c     2004-01-07 12:50:45.000000000 +0100
@@ -1518,6 +1518,22 @@
   free(new_hmap);
 }
 
+/* ************************************************************
+ * retourn TRUE if a ok ground tile for city is in a city radius 
+ * ************************************************************/
+static bool near_ok_city_places(int map_x, int map_y)
+{
+  square_dxy_iterate(map_x, map_y, 2, x_itr, y_itr, dx_itr, dy_itr) {
+    if (abs(dx_itr) + abs(dy_itr) == 4) {
+      continue;
+    }
+    if ( map_get_terrain(x_itr, y_itr) != T_ARCTIC 
+        &&  map_get_terrain(x_itr, y_itr) != T_OCEAN ) {
+      return TRUE;
+    }  
+  } square_dxy_iterate_end;
+  return FALSE;
+}
 /**************************************************************************
   this function spreads out huts on the map, a position can be used for a
   hut if there isn't another hut close and if it's not on the ocean.
@@ -1550,7 +1566,7 @@
   for (y=1;y<map.ysize-1;y++) {
     for (x=0;x<map.xsize; x++) {
       ttype = map_get_terrain(x, y);
-      if ((is_ocean(ttype) && is_coastline(x,y)) || !is_ocean(ttype)) {
+      if (near_ok_city_places(x,y)) {
        if (myrand(1000)<prob) {
          if (!is_special_close(x,y)) {
            if (tile_types[ttype].special_1_name[0] != '\0' &&
@@ -1712,10 +1728,20 @@
   }
 }
 
-/*************************************************************************/
+/*************************************************************************
+*************************************************************************/
+static bool is_near_land(center_x, center_y)
+{
+  adjc_iterate(center_x, center_y, x_itr, y_itr) {
+    if (!is_ocean(map_get_terrain(x_itr, y_itr))) {
+      return TRUE;
+    }
+  }
+  adjc_iterate_end;
+  return FALSE;
+}
 
 static long int checkmass;
-
 /**************************************************************************
   finds a place and drop the island created when called with islemass != 0
 **************************************************************************/
@@ -1732,7 +1758,7 @@
 
     if (!normalize_map_pos(&map_x, &map_y))
       return FALSE;
-    if (hmap(x, y) != 0 && is_coastline(map_x, map_y))
+    if (hmap(x, y) != 0 && is_near_land(map_x, map_y))
       return FALSE;
   }
                       
@@ -1743,7 +1769,7 @@
 
       if (!normalize_map_pos(&map_x, &map_y))
        return FALSE;
-      if (hmap(x, y) != 0 && is_coastline(map_x, map_y))
+      if (hmap(x, y) != 0 && is_near_land(map_x, map_y))
        return FALSE;
     }
   }
diff -ruN -Xdiff_ignore freeciv-cvs-Jan-04-ET1.22/server/unittools.c 
freeciv/server/unittools.c
--- freeciv-cvs-Jan-04-ET1.22/server/unittools.c        2003-12-05 
07:07:46.000000000 +0100
+++ freeciv/server/unittools.c  2004-01-08 17:57:50.000000000 +0100
@@ -422,30 +422,43 @@
     unit_restore_hitpoints(pplayer, punit);
 
     /* 3) Check that unit has hitpoints */
-    if (punit->hp<=0) {
+    if (punit->hp <= 0) {
       /* This should usually only happen for heli units,
-        but if any other units get 0 hp somehow, catch
-        them too.  --dwp  */
-      notify_player_ex(pplayer, punit->x, punit->y, E_UNIT_LOST, 
-          _("Game: Your %s has run out of hit points."), 
-          unit_name(punit->type));
+         but if any other units get 0 hp somehow, catch
+         them too.  --dwp  */
+      notify_player_ex(pplayer, punit->x, punit->y, E_UNIT_LOST,
+                      _("Game: Your %s has run out of hit points."),
+                      unit_name(punit->type));
       gamelog(GAMELOG_UNITF, _("%s lose a %s (out of hp)"),
              get_nation_name_plural(pplayer->nation),
              unit_name(punit->type));
       wipe_unit(punit);
-      continue; /* Continue iterating... */
+      continue;                        /* Continue iterating... */
     }
 
     /* 4) Check that triremes are near coastline, otherwise... */
+
     if (unit_flag(punit, F_TRIREME)
-       && myrand(100) < trireme_loss_pct(pplayer, punit->x, punit->y)) {
-      notify_player_ex(pplayer, punit->x, punit->y, E_UNIT_LOST, 
+       && (myrand(100) < trireme_loss_pct(pplayer, punit->x, punit->y))) {
+      notify_player_ex(pplayer, punit->x, punit->y, E_UNIT_LOST,
                       _("Game: Your %s has been lost on the high seas."),
                       unit_name(punit->type));
       gamelog(GAMELOG_UNITTRI, _("%s Trireme lost at sea"),
              get_nation_name_plural(pplayer->nation));
       wipe_unit(punit);
-      continue; /* Continue iterating... */
+      continue;                        /* Continue iterating... */
+    } 
+
+    if (!is_air_unit(punit) 
+       && myrand(100) < unsafe_terrain_loss_pct(pplayer, punit->x,
+                                                  punit->y)) {
+      notify_player_ex(pplayer, punit->x, punit->y, E_UNIT_LOST,
+                      _("Game: Your %s has been lost on unsafe terrain."),
+                      unit_name(punit->type));
+      gamelog(GAMELOG_UNITTRI, _("%s unit lost on unsafe terrain"),
+             get_nation_name_plural(pplayer->nation));
+      wipe_unit(punit);
+      continue;                        /* Continue iterating... */
     }
 
     /* 5) Resque planes if needed */

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