Author: cazfi
Date: Thu Apr 21 14:42:08 2016
New Revision: 32455

URL: http://svn.gna.org/viewcvs/freeciv?rev=32455&view=rev
Log:
Added gtk3- and gtk3x-client support for multiple worker tasks for each city,
nne for each tile on range.

See patch #6031

Modified:
    branches/S2_6/ai/threaded/taicity.c
    branches/S2_6/client/gui-gtk-3.0/citydlg.c
    branches/S2_6/client/packhand.c
    branches/S2_6/client/tilespec.c
    branches/S2_6/fc_version
    branches/S2_6/server/citytools.c
    branches/S2_6/server/citytools.h
    branches/S2_6/server/srv_main.c
    branches/S2_6/server/unithand.c

Modified: branches/S2_6/ai/threaded/taicity.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/ai/threaded/taicity.c?rev=32455&r1=32454&r2=32455&view=diff
==============================================================================
--- branches/S2_6/ai/threaded/taicity.c (original)
+++ branches/S2_6/ai/threaded/taicity.c Thu Apr 21 14:42:08 2016
@@ -394,7 +394,7 @@
     ptask->want  = data->task.want;
 
     /* Send info to observers */
-    package_and_send_worker_task(pcity);
+    package_and_send_worker_tasks(pcity);
   }
 
   free(data);

Modified: branches/S2_6/client/gui-gtk-3.0/citydlg.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-3.0/citydlg.c?rev=32455&r1=32454&r2=32455&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-3.0/citydlg.c  (original)
+++ branches/S2_6/client/gui-gtk-3.0/citydlg.c  Thu Apr 21 14:42:08 2016
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/***********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -2799,9 +2799,7 @@
 
   task.city_id = pcity->id;
 
-  if (act == ACTIVITY_IDLE) {
-    task.tile_id = -1;
-    task.activity = ACTIVITY_IDLE;
+  if (act == ACTIVITY_LAST) {
     task.tgt = -1;
     task.want = 0;
   } else {
@@ -2834,10 +2832,11 @@
       task.tgt = extra_index(tgt);
     }
 
-    task.tile_id = ptile->index;
-    task.activity = act;
     task.want = 100;
   }
+
+  task.tile_id = ptile->index;
+  task.activity = act;
 
   send_packet_worker_task(&client.conn, &task);
 }
@@ -2874,7 +2873,7 @@
     if (ptask != NULL) {
       choice_dialog_add(shl, _("Clear request"),
                         G_CALLBACK(set_city_workertask),
-                        GINT_TO_POINTER(ACTIVITY_IDLE), FALSE, NULL);
+                        GINT_TO_POINTER(ACTIVITY_LAST), FALSE, NULL);
     }
 
     if ((pterr->mining_result == pterr

Modified: branches/S2_6/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/packhand.c?rev=32455&r1=32454&r2=32455&view=diff
==============================================================================
--- branches/S2_6/client/packhand.c     (original)
+++ branches/S2_6/client/packhand.c     Thu Apr 21 14:42:08 2016
@@ -1121,22 +1121,33 @@
 void handle_worker_task(const struct packet_worker_task *packet)
 {
   struct city *pcity = game_city_by_number(packet->city_id);
-  struct worker_task *ptask;
+  struct worker_task *ptask = NULL;
 
   if (pcity == NULL
       || (pcity->owner != client.conn.playing && 
!client_is_global_observer())) {
     return;
   }
 
-  ptask = worker_task_list_get(pcity->task_reqs, 0);
-
-  if (ptask == NULL && packet->tile_id >= 0) {
-    ptask = fc_malloc(sizeof(struct worker_task));
-    worker_task_list_append(pcity->task_reqs, ptask);
-  } else if (ptask != NULL && packet->tile_id < 0) {
-    worker_task_list_remove(pcity->task_reqs, ptask);
-    free(ptask);
-    ptask = NULL;
+  worker_task_list_iterate(pcity->task_reqs, ptask_old) {
+    if (tile_index(ptask_old->ptile) == packet->tile_id) {
+      ptask = ptask_old;
+      break;
+    }
+  } worker_task_list_iterate_end;
+
+  if (ptask == NULL) {
+    if (packet->activity == ACTIVITY_LAST) {
+      return;
+    } else {
+      ptask = fc_malloc(sizeof(struct worker_task));
+      worker_task_list_append(pcity->task_reqs, ptask);
+    }
+  } else {
+    if (packet->activity == ACTIVITY_LAST) {
+      worker_task_list_remove(pcity->task_reqs, ptask);
+      free(ptask);
+      ptask = NULL;
+    }
   }
 
   if (ptask != NULL) {

Modified: branches/S2_6/client/tilespec.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/tilespec.c?rev=32455&r1=32454&r2=32455&view=diff
==============================================================================
--- branches/S2_6/client/tilespec.c     (original)
+++ branches/S2_6/client/tilespec.c     Thu Apr 21 14:42:08 2016
@@ -1,4 +1,4 @@
-/**********************************************************************
+/***********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -11,7 +11,7 @@
    GNU General Public License for more details.
 ***********************************************************************/
 
-/**********************************************************************
+/***********************************************************************
   Functions for handling the tilespec files which describe
   the files and contents of tilesets.
   original author: David Pfitzner <d...@mso.anu.edu.au>
@@ -5663,34 +5663,34 @@
 
   case LAYER_WORKERTASK:
     if (citymode != NULL && ptile != NULL) {
-      struct worker_task *ptask = worker_task_list_get(citymode->task_reqs, 0);
-
-      if (ptask != NULL && ptask->ptile == ptile) {
-        switch (ptask->act) {
-        case ACTIVITY_MINE:
-          if (ptask->tgt == NULL) {
-            ADD_SPRITE_SIMPLE(t->sprites.unit.plant);
-          } else {
+      worker_task_list_iterate(citymode->task_reqs, ptask) {
+        if (ptask->ptile == ptile) {
+          switch (ptask->act) {
+          case ACTIVITY_MINE:
+            if (ptask->tgt == NULL) {
+              ADD_SPRITE_SIMPLE(t->sprites.unit.plant);
+            } else {
+              
ADD_SPRITE_SIMPLE(t->sprites.extras[extra_index(ptask->tgt)].activity);
+            }
+            break;
+          case ACTIVITY_IRRIGATE:
+            if (ptask->tgt == NULL) {
+              ADD_SPRITE_SIMPLE(t->sprites.unit.irrigate);
+            } else {
+              
ADD_SPRITE_SIMPLE(t->sprites.extras[extra_index(ptask->tgt)].activity);
+            }
+            break;
+          case ACTIVITY_GEN_ROAD:
             
ADD_SPRITE_SIMPLE(t->sprites.extras[extra_index(ptask->tgt)].activity);
+            break;
+          case ACTIVITY_TRANSFORM:
+            ADD_SPRITE_SIMPLE(t->sprites.unit.transform);
+            break;
+          default:
+            break;
           }
-          break;
-        case ACTIVITY_IRRIGATE:
-          if (ptask->tgt == NULL) {
-            ADD_SPRITE_SIMPLE(t->sprites.unit.irrigate);
-          } else {
-            
ADD_SPRITE_SIMPLE(t->sprites.extras[extra_index(ptask->tgt)].activity);
-          }
-          break;
-        case ACTIVITY_GEN_ROAD:
-          
ADD_SPRITE_SIMPLE(t->sprites.extras[extra_index(ptask->tgt)].activity);
-          break;
-        case ACTIVITY_TRANSFORM:
-          ADD_SPRITE_SIMPLE(t->sprites.unit.transform);
-          break;
-        default:
-          break;
         }
-      }
+      } worker_task_list_iterate_end;
     }
     break;
 

Modified: branches/S2_6/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/fc_version?rev=32455&r1=32454&r2=32455&view=diff
==============================================================================
--- branches/S2_6/fc_version    (original)
+++ branches/S2_6/fc_version    Thu Apr 21 14:42:08 2016
@@ -55,7 +55,7 @@
 #   - Avoid adding a new mandatory capability to the development branch for
 #     as long as possible.  We want to maintain network compatibility with
 #     the stable branch for as long as possible.
-NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-2.6-2016.Apr.19"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-2.6-2016.Apr.21"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: branches/S2_6/server/citytools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/citytools.c?rev=32455&r1=32454&r2=32455&view=diff
==============================================================================
--- branches/S2_6/server/citytools.c    (original)
+++ branches/S2_6/server/citytools.c    Thu Apr 21 14:42:08 2016
@@ -3139,17 +3139,20 @@
 {
   struct packet_worker_task packet;
 
-  if (ptask != NULL) {
-    worker_task_list_remove(pcity->task_reqs, ptask);
-    free(ptask);
-  }
+  if (ptask == NULL) {
+    return;
+  }
+
+  worker_task_list_remove(pcity->task_reqs, ptask);
 
   packet.city_id = pcity->id;
-  packet.tile_id = -1;
-  packet.activity = ACTIVITY_IDLE;
+  packet.tile_id = tile_index(ptask->ptile);
+  packet.activity = ACTIVITY_LAST;
   packet.tgt = 0;
   packet.want = 0;
 
+  free(ptask);
+
   lsend_packet_worker_task(city_owner(pcity)->connections, &packet);
   lsend_packet_worker_task(game.glob_observers, &packet);
 }
@@ -3159,19 +3162,21 @@
 **************************************************************************/
 void clear_worker_tasks(struct city *pcity)
 {
-  clear_worker_task(pcity, worker_task_list_get(pcity->task_reqs, 0));
+  while (worker_task_list_size(pcity->task_reqs) > 0) {
+    clear_worker_task(pcity, worker_task_list_get(pcity->task_reqs, 0));
+  }
 }
 
 /**************************************************************************
   Send city worker task to owner
 **************************************************************************/
-void package_and_send_worker_task(struct city *pcity)
+void package_and_send_worker_tasks(struct city *pcity)
 {
   struct packet_worker_task packet;
-  struct worker_task *ptask = worker_task_list_get(pcity->task_reqs, 0);
 
   packet.city_id = pcity->id;
-  if (ptask != NULL) {
+
+  worker_task_list_iterate(pcity->task_reqs, ptask) {
     packet.tile_id = tile_index(ptask->ptile);
     packet.activity = ptask->act;
     if (ptask->tgt == NULL) {
@@ -3180,13 +3185,8 @@
       packet.tgt = extra_number(ptask->tgt);
     }
     packet.want = ptask->want;
-  } else {
-    packet.tile_id = -1;
-    packet.activity = ACTIVITY_IDLE;
-    packet.tgt = 0;
-    packet.want = 0;
-  }
-
-  lsend_packet_worker_task(city_owner(pcity)->connections, &packet);
-  lsend_packet_worker_task(game.glob_observers, &packet);
-}
+
+    lsend_packet_worker_task(city_owner(pcity)->connections, &packet);
+    lsend_packet_worker_task(game.glob_observers, &packet);
+  } worker_task_list_iterate_end;
+}

Modified: branches/S2_6/server/citytools.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/citytools.h?rev=32455&r1=32454&r2=32455&view=diff
==============================================================================
--- branches/S2_6/server/citytools.h    (original)
+++ branches/S2_6/server/citytools.h    Thu Apr 21 14:42:08 2016
@@ -101,6 +101,6 @@
 
 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);
+void package_and_send_worker_tasks(struct city *pcity);
 
 #endif  /* FC__CITYTOOLS_H */

Modified: branches/S2_6/server/srv_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/srv_main.c?rev=32455&r1=32454&r2=32455&view=diff
==============================================================================
--- branches/S2_6/server/srv_main.c     (original)
+++ branches/S2_6/server/srv_main.c     Thu Apr 21 14:42:08 2016
@@ -629,7 +629,7 @@
   send_spaceship_info(NULL, dest);
 
   cities_iterate(pcity) {
-    package_and_send_worker_task(pcity);
+    package_and_send_worker_tasks(pcity);
   } cities_iterate_end;
 }
 

Modified: branches/S2_6/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/unithand.c?rev=32455&r1=32454&r2=32455&view=diff
==============================================================================
--- branches/S2_6/server/unithand.c     (original)
+++ branches/S2_6/server/unithand.c     Thu Apr 21 14:42:08 2016
@@ -3466,26 +3466,37 @@
                         const struct packet_worker_task *packet)
 {
   struct city *pcity = game_city_by_number(packet->city_id);
-  struct worker_task *ptask;
-
-  if (pcity == NULL || pcity->owner != pplayer) {
-    return;
-  }
-
-  ptask = worker_task_list_get(pcity->task_reqs, 0);
-
-  if (ptask == NULL && packet->tile_id >= 0) {
+  struct worker_task *ptask = NULL;
+  struct tile *ptile = index_to_tile(packet->tile_id);
+
+  if (pcity == NULL || pcity->owner != pplayer || ptile == NULL) {
+    return;
+  }
+
+  worker_task_list_iterate(pcity->task_reqs, ptask_old) {
+    if (tile_index(ptask_old->ptile) == packet->tile_id) {
+      ptask = ptask_old;
+    }
+  } worker_task_list_iterate_end;
+
+  if (ptask == NULL) {
+    if (packet->activity == ACTIVITY_LAST) {
+      return;
+    }
+
     ptask = fc_malloc(sizeof(struct worker_task));
     worker_task_init(ptask);
     worker_task_list_append(pcity->task_reqs, ptask);
-  } else if (ptask != NULL && packet->tile_id < 0) {
-    worker_task_list_remove(pcity->task_reqs, ptask);
-    free(ptask);
-    ptask = NULL;
+  } else {
+    if (packet->activity == ACTIVITY_LAST) {
+      worker_task_list_remove(pcity->task_reqs, ptask);
+      free(ptask);
+      ptask = NULL;
+    }
   }
 
   if (ptask != NULL) {
-    ptask->ptile = index_to_tile(packet->tile_id);
+    ptask->ptile = ptile;
     ptask->act = packet->activity;
     if (packet->tgt >= 0) {
       ptask->tgt = extra_by_number(packet->tgt);


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

Reply via email to