Author: cazfi
Date: Thu May  7 02:40:22 2015
New Revision: 29014

URL: http://svn.gna.org/viewcvs/freeciv?rev=29014&view=rev
Log:
Autosettlers iterate through all tasks in the city worker task list.

See patch #6048

Modified:
    trunk/ai/classic/classicai.c
    trunk/ai/default/aisettler.c
    trunk/server/advisors/autosettlers.c
    trunk/server/advisors/autosettlers.h
    trunk/server/citytools.c
    trunk/server/citytools.h

Modified: trunk/ai/classic/classicai.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/classic/classicai.c?rev=29014&r1=29013&r2=29014&view=diff
==============================================================================
--- trunk/ai/classic/classicai.c        (original)
+++ trunk/ai/classic/classicai.c        Thu May  7 02:40:22 2015
@@ -123,7 +123,7 @@
 
   /* Clear worker tasks, classic AI does not use those */
   city_list_iterate(pplayer->cities, pcity) {
-    clear_worker_task(pcity);
+    clear_worker_tasks(pcity);
   } city_list_iterate_end;
 
   dai_gained_control(deftype, pplayer);

Modified: trunk/ai/default/aisettler.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/aisettler.c?rev=29014&r1=29013&r2=29014&view=diff
==============================================================================
--- trunk/ai/default/aisettler.c        (original)
+++ trunk/ai/default/aisettler.c        Thu May  7 02:40:22 2015
@@ -1070,16 +1070,20 @@
   /*** Try find some work ***/
 
   if (unit_has_type_flag(punit, UTYF_SETTLERS)) {
+    struct worker_task *best_task;
+
     TIMING_LOG(AIT_WORKERS, TIMER_START);
 
     /* Have nearby cities requests? */
-    pcity = settler_evaluate_city_requests(punit, &best_act, &best_target,
-                                           &best_tile, &path, state);
+    pcity = settler_evaluate_city_requests(punit, &best_task, &path, state);
 
     if (pcity != NULL) {
       if (path != NULL) {
         completion_time = pf_path_last_position(path)->turn;
         best_impr = 1;
+        best_act = best_task->act;
+        best_target = best_task->tgt;
+        best_tile = best_task->ptile;
       } else {
         pcity = NULL;
       }
@@ -1155,7 +1159,7 @@
                               best_tile, best_act, &best_target,
                               completion_time)) {
     if (pcity != NULL) {
-      clear_worker_task(pcity);
+      clear_worker_tasks(pcity);
     }
   }
 

Modified: trunk/server/advisors/autosettlers.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/advisors/autosettlers.c?rev=29014&r1=29013&r2=29014&view=diff
==============================================================================
--- trunk/server/advisors/autosettlers.c        (original)
+++ trunk/server/advisors/autosettlers.c        Thu May  7 02:40:22 2015
@@ -740,9 +740,7 @@
   Return best city request to fulfill.
 ****************************************************************************/
 struct city *settler_evaluate_city_requests(struct unit *punit,
-                                            enum unit_activity *best_act,
-                                            struct extra_type **best_target,
-                                            struct tile **best_tile,
+                                            struct worker_task **best_task,
                                             struct pf_path **path,
                                             struct settlermap *state)
 {
@@ -762,9 +760,7 @@
 
   /* Have nearby cities requests? */
   city_list_iterate(pplayer->cities, pcity) {
-    struct worker_task *ptask = worker_task_list_get(pcity->task_reqs, 0);
-
-    if (ptask != NULL) {
+    worker_task_list_iterate(pcity->task_reqs, ptask) {
       bool consider = TRUE;
 
       /* Do not go to tiles that already have workers there. */
@@ -814,14 +810,10 @@
           }
         }
       }
-    }
+    } worker_task_list_iterate_end;
   } city_list_iterate_end;
 
-  if (best != NULL) {
-    *best_act = best->act;
-    *best_target = best->tgt;
-    *best_tile = best->ptile;
-  }
+  *best_task = best;
 
   if (path != NULL) {
     *path = best ? pf_map_path(pfm, best->ptile) : NULL;
@@ -841,6 +833,7 @@
                            struct settlermap *state,
                            int recursion)
 {
+  struct worker_task *best_task;
   enum unit_activity best_act;
   struct tile *best_tile = NULL;
   struct extra_type *best_target;
@@ -866,8 +859,7 @@
 
   /* Have nearby cities requests? */
 
-  taskcity = settler_evaluate_city_requests(punit, &best_act, &best_target,
-                                            &best_tile, &path, state);
+  taskcity = settler_evaluate_city_requests(punit, &best_task, &path, state);
 
   if (taskcity != NULL) {
     if (path != NULL) {
@@ -876,10 +868,12 @@
 
     adv_unit_new_task(punit, AUT_AUTO_SETTLER, best_tile);
 
+    best_target = best_task->tgt;
+
     if (auto_settler_setup_work(pplayer, punit, state, recursion,
-                                path, best_tile, best_act,
+                                path, best_task->ptile, best_task->act,
                                 &best_target, completion_time)) {
-      clear_worker_task(taskcity);
+      clear_worker_task(taskcity, best_task);
     }
 
     if (path != NULL) {

Modified: trunk/server/advisors/autosettlers.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/advisors/autosettlers.h?rev=29014&r1=29013&r2=29014&view=diff
==============================================================================
--- trunk/server/advisors/autosettlers.h        (original)
+++ trunk/server/advisors/autosettlers.h        Thu May  7 02:40:22 2015
@@ -47,9 +47,7 @@
                                   struct settlermap *state);
 
 struct city *settler_evaluate_city_requests(struct unit *punit,
-                                            enum unit_activity *best_act,
-                                            struct extra_type **best_target,
-                                            struct tile **best_tile,
+                                            struct worker_task **best_task,
                                             struct pf_path **path,
                                             struct settlermap *state);
 

Modified: trunk/server/citytools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/citytools.c?rev=29014&r1=29013&r2=29014&view=diff
==============================================================================
--- trunk/server/citytools.c    (original)
+++ trunk/server/citytools.c    Thu May  7 02:40:22 2015
@@ -1009,7 +1009,7 @@
   CALL_PLR_AI_FUNC(city_lost, pcity->owner, pcity->owner, pcity);
 
   /* Forget old tasks */
-  clear_worker_task(pcity);
+  clear_worker_tasks(pcity);
 
   /* Activate AI control of the new owner. */
   CALL_PLR_AI_FUNC(city_got, ptaker, ptaker, pcity);
@@ -3060,10 +3060,9 @@
 /**************************************************************************
   Clear worker task from the city and inform owner
 **************************************************************************/
-void clear_worker_task(struct city *pcity)
+void clear_worker_task(struct city *pcity, struct worker_task *ptask)
 {
   struct packet_worker_task packet;
-  struct worker_task *ptask = worker_task_list_get(pcity->task_reqs, 0);
 
   if (ptask != NULL) {
     worker_task_list_remove(pcity->task_reqs, ptask);
@@ -3078,6 +3077,14 @@
 
   lsend_packet_worker_task(city_owner(pcity)->connections, &packet);
   lsend_packet_worker_task(game.glob_observers, &packet);
+}
+
+/**************************************************************************
+  Clear all worker tasks from the city and inform owner
+**************************************************************************/
+void clear_worker_tasks(struct city *pcity)
+{
+  clear_worker_task(pcity, worker_task_list_get(pcity->task_reqs, 0));
 }
 
 /**************************************************************************

Modified: trunk/server/citytools.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/citytools.h?rev=29014&r1=29013&r2=29014&view=diff
==============================================================================
--- trunk/server/citytools.h    (original)
+++ trunk/server/citytools.h    Thu May  7 02:40:22 2015
@@ -99,7 +99,8 @@
 
 void sync_cities(void);
 
-void clear_worker_task(struct city *pcity);
+void clear_worker_task(struct city *pcity, struct worker_task *ptask);
+void clear_worker_tasks(struct city *pcity);
 void package_and_send_worker_task(struct city *pcity);
 
 #endif  /* FC__CITYTOOLS_H */


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to