<URL: http://bugs.freeciv.org/Ticket/Display.html?id=37632 >

 This stores turn unit has been born to unit structure. Main reason
for this is to get rid of the barbarian fuel hack.

 Another possibility is just to remove barbarian fuel hack. Seems like
it has never worked (before this patch), anyway. Barbarian fuel was
never set. This means it was zero from the very beginning (meaning
that barbarians have minimum lifespan of zero turns)


 - ML

diff -Nurd -X.diff_ignore freeciv/ai/aiunit.c freeciv/ai/aiunit.c
--- freeciv/ai/aiunit.c	2007-03-06 05:46:13.000000000 +0200
+++ freeciv/ai/aiunit.c	2007-03-06 07:06:58.000000000 +0200
@@ -2080,14 +2080,14 @@
 }
 
 /**************************************************************************
-  Barbarian units may disband spontaneously if their age is more then 5,
-  they are not in cities, and they are far from any enemy units. It is to 
-  remove barbarians that do not engage into any activity for a long time.
+  Barbarian units may disband spontaneously if their age is more than
+  BARBARIAN_MIN_LIFESPAN, they are not in cities, and they are far from
+  any enemy units. It is to remove barbarians that do not engage into any
+  activity for a long time.
 **************************************************************************/
 static bool unit_can_be_retired(struct unit *punit)
 {
-  if (punit->fuel > 0) {	/* fuel abused for barbarian life span */
-    punit->fuel--;
+  if (punit->born_turn + BARBARIAN_MIN_LIFESPAN > game.info.turn) {
     return FALSE;
   }
 
@@ -2431,7 +2431,8 @@
   } players_iterate_end;
 
   /* Disappearance - 33% chance on coast, when older than barbarian life span */
-  if (is_ocean_near_tile(leader->tile) && leader->fuel == 0) {
+  if (is_ocean_near_tile(leader->tile)
+      && leader->born_turn + BARBARIAN_MIN_LIFESPAN < game.info.turn) {
     if(myrand(3) == 0) {
       UNIT_LOG(LOG_DEBUG, leader, "barbarian leader disappearing...");
       wipe_unit(leader);
diff -Nurd -X.diff_ignore freeciv/common/unit.c freeciv/common/unit.c
--- freeciv/common/unit.c	2007-03-06 03:34:32.000000000 +0200
+++ freeciv/common/unit.c	2007-03-06 06:44:22.000000000 +0200
@@ -1268,6 +1268,7 @@
   punit->foul = FALSE;
   punit->debug = FALSE;
   punit->fuel = unit_type(punit)->fuel;
+  punit->born_turn = game.info.turn;
   punit->hp = unit_type(punit)->hp;
   punit->moves_left = unit_move_rate(punit);
   punit->moved = FALSE;
diff -Nurd -X.diff_ignore freeciv/common/unit.h freeciv/common/unit.h
--- freeciv/common/unit.h	2007-03-05 21:11:49.000000000 +0200
+++ freeciv/common/unit.h	2007-03-06 06:42:46.000000000 +0200
@@ -133,6 +133,7 @@
   int unhappiness;
   int upkeep[O_MAX];
   int fuel;
+  int born_turn;
   int bribe_cost;
   struct unit_ai ai;
   enum unit_activity activity;
diff -Nurd -X.diff_ignore freeciv/server/barbarian.h freeciv/server/barbarian.h
--- freeciv/server/barbarian.h	2007-03-05 21:09:47.000000000 +0200
+++ freeciv/server/barbarian.h	2007-03-06 07:05:14.000000000 +0200
@@ -27,6 +27,8 @@
 
 #define MAP_FACTOR     2000  /* adjust this to get a good uprising frequency */
 
+#define BARBARIAN_MIN_LIFESPAN 5
+
 bool unleash_barbarians(struct tile *ptile);
 void summon_barbarians(void);
 bool is_land_barbarian(struct player *pplayer);
diff -Nurd -X.diff_ignore freeciv/server/diplomats.c freeciv/server/diplomats.c
--- freeciv/server/diplomats.c	2007-03-06 03:34:32.000000000 +0200
+++ freeciv/server/diplomats.c	2007-03-06 06:45:27.000000000 +0200
@@ -461,6 +461,7 @@
   gained_unit->fuel        = pvictim->fuel;
   gained_unit->foul        = pvictim->foul;
   gained_unit->paradropped = pvictim->paradropped;
+  gained_unit->born_turn   = pvictim->born_turn;
 
   /* Inform owner about less than full fuel */
   send_unit_info(pplayer, gained_unit);
diff -Nurd -X.diff_ignore freeciv/server/savegame.c freeciv/server/savegame.c
--- freeciv/server/savegame.c	2007-03-05 21:09:47.000000000 +0200
+++ freeciv/server/savegame.c	2007-03-06 07:01:38.000000000 +0200
@@ -1683,6 +1683,8 @@
     punit->moves_left
       = secfile_lookup_int(file, "player%d.u%d.moves", plrno, i);
     punit->fuel = secfile_lookup_int(file, "player%d.u%d.fuel", plrno, i);
+    punit->born_turn = secfile_lookup_int_default(file, game.info.turn,
+                                                  "player%d.u%d.born", plrno, i);
     activity = secfile_lookup_int(file, "player%d.u%d.activity", plrno, i);
     if (activity == ACTIVITY_PATROL_UNUSED) {
       /* Previously ACTIVITY_PATROL and ACTIVITY_GOTO were used for
@@ -2922,6 +2924,8 @@
 		                plrno, i);
     secfile_insert_int(file, punit->fuel, "player%d.u%d.fuel",
 		                plrno, i);
+    secfile_insert_int(file, punit->born_turn, "player%d.u%d.born",
+                       plrno, i);
     secfile_insert_int(file, punit->battlegroup,
 		       "player%d.u%d.battlegroup", plrno, i);
 
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to