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

 ferry.ai.passenger is initialized as 0 in create_unit_virtual(), not
as FERRY_AVAILABLE (-1). This means that new ferries are considered
unavailable until ai.passenger is overwritten.
 Attached patch takes care of initialization with FERRY_AVAILABLE.


 - ML

diff -Nurd -X.diff_ignore freeciv/ai/aiferry.c freeciv/ai/aiferry.c
--- freeciv/ai/aiferry.c	2006-07-17 23:56:47.000000000 +0300
+++ freeciv/ai/aiferry.c	2007-01-25 20:41:05.000000000 +0200
@@ -128,6 +128,29 @@
 #endif /* DEBUG_FERRY_STATS */
 
 /**************************************************************************
+  Initialize new ferry when player gets it
+**************************************************************************/
+void aiferry_init_ferry(struct unit *ferry)
+{
+  if (is_sailing_unit(ferry)) {
+    unit_class_iterate(punitclass) {
+      if (punitclass->move_type == LAND_MOVING
+          && can_unit_type_transport(ferry->type, punitclass)) {
+        /* Can transport some land units, so is consider ferry */
+        struct ai_data *ai = ai_data_get(unit_owner(ferry));
+
+        ferry->ai.passenger = FERRY_AVAILABLE;
+        ai->stats.boats++;
+        ai->stats.available_boats++;
+
+        break;
+      }
+    } unit_class_iterate_end;
+  }
+}
+
+
+/**************************************************************************
   Use on a unit which no longer needs a boat. 
 **************************************************************************/
 void aiferry_clear_boat(struct unit *punit)
diff -Nurd -X.diff_ignore freeciv/ai/aiferry.h freeciv/ai/aiferry.h
--- freeciv/ai/aiferry.h	2006-07-17 23:56:47.000000000 +0300
+++ freeciv/ai/aiferry.h	2007-01-25 20:40:07.000000000 +0200
@@ -30,6 +30,11 @@
  */
 int aiferry_find_boat(struct unit *punit, int cap, struct pf_path **path);
 
+/* 
+ * Initializes aiferry stats for a new unit
+ */
+void aiferry_init_ferry(struct unit *ferry);
+
 /*
  * Release the boat reserved in punit's ai.ferryboat field.
  */
diff -Nurd -X.diff_ignore freeciv/server/unittools.c freeciv/server/unittools.c
--- freeciv/server/unittools.c	2007-01-25 17:59:51.000000000 +0200
+++ freeciv/server/unittools.c	2007-01-25 20:43:00.000000000 +0200
@@ -62,6 +62,7 @@
 
 #include "advdiplomacy.h"
 #include "aiexplorer.h"
+#include "aiferry.h"
 #include "aitools.h"
 #include "aiunit.h"
 
@@ -1400,6 +1401,9 @@
 
   sync_cities();
 
+  /* Initialize aiferry stuff for new unit */
+  aiferry_init_ferry(punit);
+
   return punit;
 }
 
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to