Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2005:
[Freeciv-Dev] (PR#14992) I: common/unitlist.[ch]
Home

[Freeciv-Dev] (PR#14992) I: common/unitlist.[ch]

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#14992) I: common/unitlist.[ch]
From: "Egor Vyscrebentsov" <evyscr@xxxxxxxxx>
Date: Mon, 26 Dec 2005 04:48:41 -0800
Reply-to: bugs@xxxxxxxxxxx

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

Good daytime!

Jason Short wrote:
> Egor Vyscrebentsov wrote:
> > Functions from gui-gtk-2.0/menu.c:
> >   units_can_*
> >   units_have_flag
> >   units_are_occupied
> > added by battlegroups patch should (IMHO) be moved into some of
> > common client files. They have nothing gui-specific to my look.
> 
> Quite.  But what file?  Or should a new file be created?  There's
> also a static function added to (IIRC) control.c, can_units_attack_at
> or some such.

After some IRC talking Jason suggested a new file: common/unitlist.[ch]

First variant of patch (unitlist-1-var1.diff) only moves functions from
client/gui-gtk-2.0/menu.c into common/unitlist

Second variant (unitlist-1-var2.diff) also moves unit_list declarations
and specific functions from common/unit.c

Since I don't know how to compel svn to make diffs with new local files,
2 versions of unitlist.[ch] attached: unitlist.[ch].v1 are for first
variant of patch.

gui-gtk-2.0 is working, gui-xaw has separate patch (with recent fixes).

-- 
Thanks, evyscr

Attachment: unitlist.c.v1
Description: Binary data

Index: common/Makefile.am
===================================================================
--- common/Makefile.am  (revision 11385)
+++ common/Makefile.am  (working copy)
@@ -64,6 +64,8 @@
                tile.h          \
                unit.c          \
                unit.h          \
+               unitlist.c      \
+               unitlist.h      \
                unittype.c      \
                unittype.h      \
                worklist.c      \
Index: client/gui-gtk-2.0/menu.c
===================================================================
--- client/gui-gtk-2.0/menu.c   (revision 11385)
+++ client/gui-gtk-2.0/menu.c   (working copy)
@@ -30,6 +30,7 @@
 #include "movement.h"
 #include "support.h"
 #include "unit.h"
+#include "unitlist.h"
 
 #include "chatline.h"
 #include "cityrep.h"
@@ -1182,131 +1183,6 @@
   return tile_get_info_text(&newtile);
 }
 
-/****************************************************************************
-  Return TRUE if the function returns true for any of the units.
-****************************************************************************/
-static bool can_units_do(struct unit_list *punits,
-                        bool (can_fn)(const struct unit *punit))
-{
-  unit_list_iterate(punits, punit) {
-    if (can_fn(punit)) {
-      return TRUE;
-    }
-  } unit_list_iterate_end;
-
-  return FALSE;
-}
-
-/****************************************************************************
-  Returns TRUE if any of the units can do the activity.
-****************************************************************************/
-static bool can_units_do_activity(struct unit_list *punits,
-                                 enum unit_activity activity)
-{
-  unit_list_iterate(punits, punit) {
-    if (can_unit_do_activity(punit, activity)) {
-      return TRUE;
-    }
-  } unit_list_iterate_end;
-
-  return FALSE;
-}
-
-/****************************************************************************
-  Returns TRUE if any of the units can do the activity.
-****************************************************************************/
-static bool can_units_do_diplomat_action(struct unit_list *punits,
-                                        enum diplomat_actions action)
-{
-  unit_list_iterate(punits, punit) {
-    if (is_diplomat_unit(punit)
-       && diplomat_can_do_action(punit, action, punit->tile)) {
-      return TRUE;
-    }
-  } unit_list_iterate_end;
-
-  return FALSE;
-}
-
-/****************************************************************************
-  If has_flag is true, returns true iff any of the units have the flag.
-
-  If has_flag is false, returns true iff any of the units don't have the
-  flag.
-****************************************************************************/
-static bool units_have_flag(struct unit_list *punits,
-                           enum unit_flag_id flag,
-                           bool has_flag)
-{
-  unit_list_iterate(punits, punit) {
-    if (EQ(has_flag, unit_flag(punit, flag))) {
-      return TRUE;
-    }
-  } unit_list_iterate_end;
-
-  return FALSE;
-}
-
-/****************************************************************************
-
-****************************************************************************/
-static bool units_are_occupied(struct unit_list *punits)
-{
-  unit_list_iterate(punits, punit) {
-    if (get_transporter_occupancy(punit) > 0) {
-      return TRUE;
-    }
-  } unit_list_iterate_end;
-
-  return FALSE;
-}
-
-/****************************************************************************
-  Return TRUE iff any of these units can load.
-****************************************************************************/
-static bool units_can_load(struct unit_list *punits)
-{
-  unit_list_iterate(punits, punit) {
-    if (can_unit_load(punit,
-                     find_transporter_for_unit(punit, punit->tile))) {
-      return TRUE;
-    }
-  } unit_list_iterate_end;
-
-  return FALSE;
-}
-
-/****************************************************************************
-  Return TRUE iff any of these units can unload.
-****************************************************************************/
-static bool units_can_unload(struct unit_list *punits)
-{
-  unit_list_iterate(punits, punit) {
-    if (can_unit_unload(punit, find_unit_by_id(punit->transported_by))
-       && can_unit_exist_at_tile(punit, punit->tile)) {
-      return TRUE;
-    }
-  } unit_list_iterate_end;
-
-  return FALSE;
-}
-
-/****************************************************************************
-  Return TRUE iff any of the units' tiles have the activity running
-  on them.
-****************************************************************************/
-static bool units_have_activity_on_tile(struct unit_list *punits,
-                                       enum unit_activity activity)
-{
-  unit_list_iterate(punits, punit) {
-    if (is_unit_activity_on_tile(activity, punit->tile)) {
-      return TRUE;
-    }
-  } unit_list_iterate_end;
-
-  return FALSE;
-}
-
 /****************************************************************
 Note: the menu strings should contain underscores as in the
 menu_items struct. The underscores will be removed elsewhere if

Attachment: unitlist.h
Description: Binary data

Attachment: unitlist.h.v1
Description: Binary data

Index: server/gotohand.c
===================================================================
--- server/gotohand.c   (revision 11385)
+++ server/gotohand.c   (working copy)
@@ -27,6 +27,7 @@
 #include "mem.h"
 #include "movement.h"
 #include "rand.h"
+#include "unitlist.h"
 
 #include "airgoto.h"
 #include "maphand.h"
Index: server/score.c
===================================================================
--- server/score.c      (revision 11385)
+++ server/score.c      (working copy)
@@ -26,9 +26,11 @@
 #include "player.h"
 #include "srv_main.h"
 #include "shared.h"
-#include "score.h"
 #include "unit.h"
+#include "unitlist.h"
 
+#include "score.h"
+
 static int get_civ_score(const struct player *pplayer);
 
 /**************************************************************************
Index: server/srv_main.c
===================================================================
--- server/srv_main.c   (revision 11385)
+++ server/srv_main.c   (working copy)
@@ -67,6 +67,7 @@
 #include "support.h"
 #include "tech.h"
 #include "timing.h"
+#include "unitlist.h"
 #include "version.h"
 
 #include "auth.h"
Index: server/scripting/api_methods.c
===================================================================
--- server/scripting/api_methods.c      (revision 11385)
+++ server/scripting/api_methods.c      (working copy)
@@ -15,6 +15,8 @@
 #include <config.h>
 #endif
 
+#include "unitlist.h"
+
 #include "api_methods.h"
 #include "script.h"
 
Index: server/citytools.c
===================================================================
--- server/citytools.c  (revision 11385)
+++ server/citytools.c  (working copy)
@@ -35,6 +35,7 @@
 #include "support.h"
 #include "tech.h"
 #include "unit.h"
+#include "unitlist.h"
 
 #include "script.h"
 
Index: server/settlers.c
===================================================================
--- server/settlers.c   (revision 11385)
+++ server/settlers.c   (working copy)
@@ -30,6 +30,7 @@
 #include "packets.h"
 #include "support.h"
 #include "timing.h"
+#include "unitlist.h"
 
 #include "citytools.h"
 #include "gotohand.h"
Index: server/report.c
===================================================================
--- server/report.c     (revision 11385)
+++ server/report.c     (working copy)
@@ -31,6 +31,7 @@
 #include "rand.h"
 #include "support.h"
 #include "version.h"
+#include "unitlist.h"
 
 #include "citytools.h"
 #include "report.h"
Index: server/barbarian.c
===================================================================
--- server/barbarian.c  (revision 11385)
+++ server/barbarian.c  (working copy)
@@ -38,6 +38,7 @@
 #include "support.h"
 #include "tech.h"
 #include "terrain.h"
+#include "unitlist.h"
 
 #include "gamehand.h"
 #include "gamelog.h"
Index: server/cityturn.c
===================================================================
--- server/cityturn.c   (revision 11385)
+++ server/cityturn.c   (working copy)
@@ -34,6 +34,7 @@
 #include "support.h"
 #include "tech.h"
 #include "unit.h"
+#include "unitlist.h"
 
 #include "script.h"
 
Index: server/maphand.c
===================================================================
--- server/maphand.c    (revision 11385)
+++ server/maphand.c    (working copy)
@@ -30,6 +30,7 @@
 #include "nation.h"
 #include "packets.h"
 #include "unit.h"
+#include "unitlist.h"
 
 #include "citytools.h"
 #include "cityturn.h"
Index: server/gamelog.c
===================================================================
--- server/gamelog.c    (revision 11385)
+++ server/gamelog.c    (working copy)
@@ -28,6 +28,7 @@
 #include "score.h"
 #include "srv_main.h"
 #include "support.h"
+#include "unitlist.h"
 
 #include "gamelog.h"
 #include "stdinhand.h"
Index: server/diplomats.c
===================================================================
--- server/diplomats.c  (revision 11385)
+++ server/diplomats.c  (working copy)
@@ -24,6 +24,7 @@
 #include "log.h"
 #include "player.h"
 #include "rand.h"
+#include "unitlist.h"
 
 #include "citytools.h"
 #include "cityturn.h"
Index: server/unittools.c
===================================================================
--- server/unittools.c  (revision 11385)
+++ server/unittools.c  (working copy)
@@ -37,6 +37,7 @@
 #include "shared.h"
 #include "support.h"
 #include "unit.h"
+#include "unitlist.h"
 
 #include "barbarian.h"
 #include "citytools.h"
Index: server/sanitycheck.c
===================================================================
--- server/sanitycheck.c        (revision 11385)
+++ server/sanitycheck.c        (working copy)
@@ -27,6 +27,7 @@
 #include "player.h"
 #include "terrain.h"
 #include "unit.h"
+#include "unitlist.h"
 
 #include "citytools.h"
 #include "maphand.h"
Index: server/unithand.c
===================================================================
--- server/unithand.c   (revision 11385)
+++ server/unithand.c   (working copy)
@@ -34,6 +34,7 @@
 #include "rand.h"
 #include "shared.h"
 #include "unit.h"
+#include "unitlist.h"
 
 #include "barbarian.h"
 #include "citytools.h"
Index: server/stdinhand.c
===================================================================
--- server/stdinhand.c  (revision 11385)
+++ server/stdinhand.c  (working copy)
@@ -45,6 +45,7 @@
 #include "shared.h"            /* fc__attribute, bool type, etc. */
 #include "support.h"
 #include "timing.h"
+#include "unitlist.h"
 #include "version.h"
 
 #include "citytools.h"
Index: server/savegame.c
===================================================================
--- server/savegame.c   (revision 11385)
+++ server/savegame.c   (working copy)
@@ -37,6 +37,7 @@
 #include "idex.h"
 #include "map.h"
 #include "unit.h"
+#include "unitlist.h"
 #include "version.h"
 
 #include "aicity.h"
Index: server/plrhand.c
===================================================================
--- server/plrhand.c    (revision 11385)
+++ server/plrhand.c    (working copy)
@@ -31,6 +31,7 @@
 #include "shared.h"
 #include "support.h"
 #include "tech.h"
+#include "unitlist.h"
 
 #include "script.h"
 
Index: common/unit.c
===================================================================
--- common/unit.c       (revision 11385)
+++ common/unit.c       (working copy)
@@ -28,6 +28,7 @@
 #include "shared.h"
 #include "support.h"
 #include "tech.h"
+#include "unitlist.h"
 
 #include "city.h"
 #include "unit.h"
@@ -1071,67 +1072,6 @@
 }
 
 /**************************************************************************
-  Look for a unit with the given ID in the unit list.
-**************************************************************************/
-struct unit *unit_list_find(const struct unit_list *This, int id)
-{
-  unit_list_iterate(This, punit) {
-    if (punit->id == id) {
-      return punit;
-    }
-  } unit_list_iterate_end;
-
-  return NULL;
-}
-
-/**************************************************************************
- Comparison function for genlist_sort, sorting by ord_map:
- The indirection is a bit gory:
- Read from the right:
-   1. cast arg "a" to "ptr to void*"   (we're sorting a list of "void*"'s)
-   2. dereference to get the "void*"
-   3. cast that "void*" to a "struct unit*"
-**************************************************************************/
-static int compar_unit_ord_map(const void *a, const void *b)
-{
-  const struct unit *ua, *ub;
-  ua = (const struct unit*) *(const void**)a;
-  ub = (const struct unit*) *(const void**)b;
-  return ua->ord_map - ub->ord_map;
-}
-
-/**************************************************************************
- Comparison function for genlist_sort, sorting by ord_city: see above.
-**************************************************************************/
-static int compar_unit_ord_city(const void *a, const void *b)
-{
-  const struct unit *ua, *ub;
-  ua = (const struct unit*) *(const void**)a;
-  ub = (const struct unit*) *(const void**)b;
-  return ua->ord_city - ub->ord_city;
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-void unit_list_sort_ord_map(struct unit_list *This)
-{
-  if (unit_list_size(This) > 1) {
-    unit_list_sort(This, compar_unit_ord_map);
-  }
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-void unit_list_sort_ord_city(struct unit_list *This)
-{
-  if (unit_list_size(This) > 1) {
-    unit_list_sort(This, compar_unit_ord_city);
-  }
-}
-
-/**************************************************************************
   Return the unit's owner.
 **************************************************************************/
 struct player *unit_owner(const struct unit *punit)
Index: common/unittype.c
===================================================================
--- common/unittype.c   (revision 11385)
+++ common/unittype.c   (working copy)
@@ -28,6 +28,7 @@
 #include "shared.h"
 #include "support.h"
 #include "tech.h"
+#include "unitlist.h"
 
 #include "unittype.h"
 
Index: common/unit.h
===================================================================
--- common/unit.h       (revision 11385)
+++ common/unit.h       (working copy)
@@ -13,8 +13,6 @@
 #ifndef FC__UNIT_H
 #define FC__UNIT_H
 
-#include "mem.h"               /* unit_list_iterate_safe */
-
 #include "fc_types.h"
 #include "terrain.h"           /* enum tile_special_type */
 #include "unittype.h"
@@ -188,38 +186,11 @@
   } orders;
 };
 
-/* get 'struct unit_list' and related functions: */
-#define SPECLIST_TAG unit
-#define SPECLIST_TYPE struct unit
-#include "speclist.h"
-
-#define unit_list_iterate(unitlist, punit) \
-    TYPED_LIST_ITERATE(struct unit, unitlist, punit)
-#define unit_list_iterate_end  LIST_ITERATE_END
 #define SINGLE_MOVE 3
 #define MOVE_COST_RIVER 1
 #define MOVE_COST_RAIL 0
 #define MOVE_COST_ROAD 1
 
-#define unit_list_iterate_safe(unitlist, punit) \
-{ \
-  int _size = unit_list_size(unitlist); \
-  if (_size > 0) { \
-    int _ids[_size]; \
-    int _i = 0; \
-    unit_list_iterate(unitlist, punit) { \
-      _ids[_i++] = punit->id; \
-    } unit_list_iterate_end; \
-    for (_i=0; _i<_size; _i++) { \
-      struct unit *punit = find_unit_by_id(_ids[_i]); \
-      if (punit) { \
-
-#define unit_list_iterate_safe_end \
-      } \
-    } \
-  } \
-}
-
 /* Iterates over the types of unit activity. */
 #define activity_type_iterate(act)                                         \
 {                                                                          \
@@ -231,11 +202,6 @@
   }                                                                        \
 }
 
-struct unit *unit_list_find(const struct unit_list *This, int id);
-
-void unit_list_sort_ord_map(struct unit_list *This);
-void unit_list_sort_ord_city(struct unit_list *This);
-
 bool diplomat_can_do_action(const struct unit *pdiplomat,
                            enum diplomat_actions action,
                            const struct tile *ptile);
Index: common/combat.c
===================================================================
--- common/combat.c     (revision 11385)
+++ common/combat.c     (working copy)
@@ -26,6 +26,7 @@
 #include "movement.h"
 #include "packets.h"
 #include "unit.h"
+#include "unitlist.h"
 
 #include "combat.h"
 
Index: common/city.c
===================================================================
--- common/city.c       (revision 11385)
+++ common/city.c       (working copy)
@@ -30,6 +30,7 @@
 #include "mem.h"
 #include "movement.h"
 #include "packets.h"
+#include "unitlist.h"
 
 #include "cm.h"
 
Index: common/aicore/aisupport.c
===================================================================
--- common/aicore/aisupport.c   (revision 11385)
+++ common/aicore/aisupport.c   (working copy)
@@ -23,6 +23,7 @@
 #include "spaceship.h"
 #include "support.h"
 #include "tech.h"
+#include "unitlist.h"
 
 #include "aisupport.h"
 
Index: common/aicore/citymap.c
===================================================================
--- common/aicore/citymap.c     (revision 11385)
+++ common/aicore/citymap.c     (working copy)
@@ -28,6 +28,7 @@
 #include "mem.h"
 #include "support.h"
 #include "unit.h"
+#include "unitlist.h"
 #include "unittype.h"
 
 #include "citymap.h"
Index: common/aicore/path_finding.c
===================================================================
--- common/aicore/path_finding.c        (revision 11385)
+++ common/aicore/path_finding.c        (working copy)
@@ -22,6 +22,7 @@
 #include "map.h"
 #include "mem.h"
 #include "pqueue.h"
+#include "unitlist.h"
 
 #include "path_finding.h"
 
Index: common/player.c
===================================================================
--- common/player.c     (revision 11385)
+++ common/player.c     (working copy)
@@ -30,6 +30,7 @@
 #include "support.h"
 #include "tech.h"
 #include "unit.h"
+#include "unitlist.h"
 
 #include "player.h"
 
Index: common/game.c
===================================================================
--- common/game.c       (revision 11385)
+++ common/game.c       (working copy)
@@ -35,6 +35,7 @@
 #include "support.h"
 #include "tech.h"
 #include "unit.h"
+#include "unitlist.h"
 
 #include "game.h"
 
Index: common/map.c
===================================================================
--- common/map.c        (revision 11385)
+++ common/map.c        (working copy)
@@ -28,6 +28,7 @@
 #include "shared.h"
 #include "support.h"
 #include "unit.h"
+#include "unitlist.h"
 
 #include "map.h"
 
Index: common/Makefile.am
===================================================================
--- common/Makefile.am  (revision 11385)
+++ common/Makefile.am  (working copy)
@@ -64,6 +64,8 @@
                tile.h          \
                unit.c          \
                unit.h          \
+               unitlist.c      \
+               unitlist.h      \
                unittype.c      \
                unittype.h      \
                worklist.c      \
Index: ai/aiferry.c
===================================================================
--- ai/aiferry.c        (revision 11385)
+++ ai/aiferry.c        (working copy)
@@ -19,6 +19,7 @@
 #include "log.h"
 #include "movement.h"
 #include "unit.h"
+#include "unitlist.h"
 
 #include "path_finding.h"
 #include "pf_tools.h"
Index: ai/advdomestic.c
===================================================================
--- ai/advdomestic.c    (revision 11385)
+++ ai/advdomestic.c    (working copy)
@@ -24,6 +24,7 @@
 #include "map.h"
 #include "mem.h"
 #include "unit.h"
+#include "unitlist.h"
 #include "unittype.h"
 
 #include "citytools.h"
Index: ai/aitools.c
===================================================================
--- ai/aitools.c        (revision 11385)
+++ ai/aitools.c        (working copy)
@@ -29,6 +29,7 @@
 #include "player.h"
 #include "shared.h"
 #include "unit.h"
+#include "unitlist.h"
 
 #include "citymap.h"
 #include "path_finding.h"
Index: ai/advdiplomacy.c
===================================================================
--- ai/advdiplomacy.c   (revision 11385)
+++ ai/advdiplomacy.c   (working copy)
@@ -34,6 +34,7 @@
 #include "spaceship.h"
 #include "support.h"
 #include "tech.h"
+#include "unitlist.h"
 
 #include "citytools.h"
 #include "diplhand.h"
Index: ai/aicity.c
===================================================================
--- ai/aicity.c (revision 11385)
+++ ai/aicity.c (working copy)
@@ -34,6 +34,7 @@
 #include "shared.h"
 #include "support.h"
 #include "unit.h"
+#include "unitlist.h"
 
 #include "path_finding.h"
 #include "pf_tools.h"
Index: ai/aidata.c
===================================================================
--- ai/aidata.c (revision 11385)
+++ ai/aidata.c (working copy)
@@ -25,6 +25,7 @@
 #include "mem.h"
 #include "movement.h"
 #include "unit.h"
+#include "unitlist.h"
 
 #include "citytools.h"
 #include "diplhand.h"
Index: ai/aidiplomat.c
===================================================================
--- ai/aidiplomat.c     (revision 11385)
+++ ai/aidiplomat.c     (working copy)
@@ -32,6 +32,7 @@
 #include "shared.h"
 #include "timing.h"
 #include "unit.h"
+#include "unitlist.h"
 
 #include "barbarian.h"
 #include "citytools.h"
Index: ai/advmilitary.c
===================================================================
--- ai/advmilitary.c    (revision 11385)
+++ ai/advmilitary.c    (working copy)
@@ -24,6 +24,7 @@
 #include "log.h"
 #include "map.h"
 #include "movement.h"
+#include "unitlist.h"
 
 #include "citytools.h"
 #include "cityturn.h"
Index: ai/aiparatrooper.c
===================================================================
--- ai/aiparatrooper.c  (revision 11385)
+++ ai/aiparatrooper.c  (working copy)
@@ -25,6 +25,7 @@
 #include "pf_tools.h"
 #include "player.h"
 #include "unit.h"
+#include "unitlist.h"
 #include "unittools.h"
 
 #include "aidata.h"
Index: ai/aihunt.c
===================================================================
--- ai/aihunt.c (revision 11385)
+++ ai/aihunt.c (working copy)
@@ -26,6 +26,7 @@
 #include "pf_tools.h"
 #include "player.h"
 #include "unit.h"
+#include "unitlist.h"
 
 #include "citytools.h"
 #include "settlers.h"
Index: ai/aiunit.c
===================================================================
--- ai/aiunit.c (revision 11385)
+++ ai/aiunit.c (working copy)
@@ -33,6 +33,7 @@
 #include "shared.h"
 #include "timing.h"
 #include "unit.h"
+#include "unitlist.h"
 
 #include "barbarian.h"
 #include "caravan.h"
Index: client/agents/sha.c
===================================================================
--- client/agents/sha.c (revision 11385)
+++ client/agents/sha.c (working copy)
@@ -15,11 +15,13 @@
 #include <config.h>
 #endif
 
-#include "game.h"
 #include "log.h"
-#include "map.h"
 #include "support.h"
 
+#include "game.h"
+#include "map.h"
+#include "unitlist.h"
+
 #include "agents.h"
 
 #include "sha.h"
Index: client/citydlg_common.c
===================================================================
--- client/citydlg_common.c     (revision 11385)
+++ client/citydlg_common.c     (working copy)
@@ -17,11 +17,13 @@
 
 #include <assert.h>
 
-#include "city.h"
 #include "fcintl.h"
 #include "log.h"
 #include "support.h"
 
+#include "city.h"
+#include "unitlist.h"
+
 #include "citydlg_g.h"
 #include "mapview_g.h"
 
Index: client/cityrepdata.c
===================================================================
--- client/cityrepdata.c        (revision 11385)
+++ client/cityrepdata.c        (working copy)
@@ -19,11 +19,13 @@
 #include <stdio.h>
 #include <string.h>
 
+#include "fcintl.h"
+#include "support.h"
+
 #include "city.h"
-#include "fcintl.h"
 #include "game.h"
 #include "map.h"
-#include "support.h"
+#include "unitlist.h"
 
 #include "cma_fec.h"
 #include "options.h"
Index: client/control.c
===================================================================
--- client/control.c    (revision 11385)
+++ client/control.c    (working copy)
@@ -19,11 +19,13 @@
 
 #include "fcintl.h"
 #include "log.h"
-#include "map.h"
 #include "mem.h"
-#include "movement.h"
 #include "timing.h"
 
+#include "map.h"
+#include "movement.h"
+#include "unitlist.h"
+
 #include "audio.h"
 #include "chatline_g.h"
 #include "citydlg_g.h"
Index: client/gui-gtk-2.0/citydlg.c
===================================================================
--- client/gui-gtk-2.0/citydlg.c        (revision 11385)
+++ client/gui-gtk-2.0/citydlg.c        (working copy)
@@ -33,6 +33,7 @@
 #include "player.h"
 #include "shared.h"
 #include "support.h"
+#include "unitlist.h"
 
 #include "cityrep.h"
 #include "civclient.h"
Index: client/gui-gtk-2.0/gotodlg.c
===================================================================
--- client/gui-gtk-2.0/gotodlg.c        (revision 11385)
+++ client/gui-gtk-2.0/gotodlg.c        (working copy)
@@ -29,6 +29,7 @@
 #include "player.h"
 #include "support.h"
 #include "unit.h"
+#include "unitlist.h"
 
 #include "clinet.h"
 #include "civclient.h"
Index: client/gui-gtk-2.0/repodlgs.c
===================================================================
--- client/gui-gtk-2.0/repodlgs.c       (revision 11385)
+++ client/gui-gtk-2.0/repodlgs.c       (working copy)
@@ -30,6 +30,7 @@
 #include "packets.h"
 #include "shared.h"
 #include "support.h"
+#include "unitlist.h"
 
 #include "chatline_common.h"
 #include "cityrep.h"
Index: client/gui-gtk-2.0/gui_main.c
===================================================================
--- client/gui-gtk-2.0/gui_main.c       (revision 11385)
+++ client/gui-gtk-2.0/gui_main.c       (working copy)
@@ -42,6 +42,7 @@
 #include "mem.h"
 #include "shared.h"
 #include "support.h"
+#include "unitlist.h"
 #include "version.h"
 
 #include "chatline.h"
Index: client/gui-gtk-2.0/menu.c
===================================================================
--- client/gui-gtk-2.0/menu.c   (revision 11385)
+++ client/gui-gtk-2.0/menu.c   (working copy)
@@ -30,6 +30,7 @@
 #include "movement.h"
 #include "support.h"
 #include "unit.h"
+#include "unitlist.h"
 
 #include "chatline.h"
 #include "cityrep.h"
@@ -1182,131 +1183,6 @@
   return tile_get_info_text(&newtile);
 }
 
-/****************************************************************************
-  Return TRUE if the function returns true for any of the units.
-****************************************************************************/
-static bool can_units_do(struct unit_list *punits,
-                        bool (can_fn)(const struct unit *punit))
-{
-  unit_list_iterate(punits, punit) {
-    if (can_fn(punit)) {
-      return TRUE;
-    }
-  } unit_list_iterate_end;
-
-  return FALSE;
-}
-
-/****************************************************************************
-  Returns TRUE if any of the units can do the activity.
-****************************************************************************/
-static bool can_units_do_activity(struct unit_list *punits,
-                                 enum unit_activity activity)
-{
-  unit_list_iterate(punits, punit) {
-    if (can_unit_do_activity(punit, activity)) {
-      return TRUE;
-    }
-  } unit_list_iterate_end;
-
-  return FALSE;
-}
-
-/****************************************************************************
-  Returns TRUE if any of the units can do the activity.
-****************************************************************************/
-static bool can_units_do_diplomat_action(struct unit_list *punits,
-                                        enum diplomat_actions action)
-{
-  unit_list_iterate(punits, punit) {
-    if (is_diplomat_unit(punit)
-       && diplomat_can_do_action(punit, action, punit->tile)) {
-      return TRUE;
-    }
-  } unit_list_iterate_end;
-
-  return FALSE;
-}
-
-/****************************************************************************
-  If has_flag is true, returns true iff any of the units have the flag.
-
-  If has_flag is false, returns true iff any of the units don't have the
-  flag.
-****************************************************************************/
-static bool units_have_flag(struct unit_list *punits,
-                           enum unit_flag_id flag,
-                           bool has_flag)
-{
-  unit_list_iterate(punits, punit) {
-    if (EQ(has_flag, unit_flag(punit, flag))) {
-      return TRUE;
-    }
-  } unit_list_iterate_end;
-
-  return FALSE;
-}
-
-/****************************************************************************
-
-****************************************************************************/
-static bool units_are_occupied(struct unit_list *punits)
-{
-  unit_list_iterate(punits, punit) {
-    if (get_transporter_occupancy(punit) > 0) {
-      return TRUE;
-    }
-  } unit_list_iterate_end;
-
-  return FALSE;
-}
-
-/****************************************************************************
-  Return TRUE iff any of these units can load.
-****************************************************************************/
-static bool units_can_load(struct unit_list *punits)
-{
-  unit_list_iterate(punits, punit) {
-    if (can_unit_load(punit,
-                     find_transporter_for_unit(punit, punit->tile))) {
-      return TRUE;
-    }
-  } unit_list_iterate_end;
-
-  return FALSE;
-}
-
-/****************************************************************************
-  Return TRUE iff any of these units can unload.
-****************************************************************************/
-static bool units_can_unload(struct unit_list *punits)
-{
-  unit_list_iterate(punits, punit) {
-    if (can_unit_unload(punit, find_unit_by_id(punit->transported_by))
-       && can_unit_exist_at_tile(punit, punit->tile)) {
-      return TRUE;
-    }
-  } unit_list_iterate_end;
-
-  return FALSE;
-}
-
-/****************************************************************************
-  Return TRUE iff any of the units' tiles have the activity running
-  on them.
-****************************************************************************/
-static bool units_have_activity_on_tile(struct unit_list *punits,
-                                       enum unit_activity activity)
-{
-  unit_list_iterate(punits, punit) {
-    if (is_unit_activity_on_tile(activity, punit->tile)) {
-      return TRUE;
-    }
-  } unit_list_iterate_end;
-
-  return FALSE;
-}
-
 /****************************************************************
 Note: the menu strings should contain underscores as in the
 menu_items struct. The underscores will be removed elsewhere if
Index: client/gui-gtk-2.0/dialogs.c
===================================================================
--- client/gui-gtk-2.0/dialogs.c        (revision 11385)
+++ client/gui-gtk-2.0/dialogs.c        (working copy)
@@ -34,6 +34,7 @@
 #include "player.h"
 #include "rand.h"
 #include "support.h"
+#include "unitlist.h"
 
 #include "chatline.h"
 #include "choice_dialog.h"
Index: client/gui-gtk-2.0/diplomat_dialog.c
===================================================================
--- client/gui-gtk-2.0/diplomat_dialog.c        (revision 11385)
+++ client/gui-gtk-2.0/diplomat_dialog.c        (working copy)
@@ -21,6 +21,7 @@
 
 #include "game.h"
 #include "unit.h"
+#include "unitlist.h"
 
 #include "dialogs_g.h"
 #include "chatline.h"
Index: client/text.c
===================================================================
--- client/text.c       (revision 11385)
+++ client/text.c       (working copy)
@@ -20,13 +20,16 @@
 #include <string.h>
 
 #include "astring.h"
-#include "map.h"
-#include "combat.h"
 #include "fcintl.h"
 #include "log.h"
 #include "support.h"
+
+#include "combat.h"
+#include "government.h"
+#include "map.h"
+#include "unitlist.h"
+
 #include "climisc.h"
-#include "government.h"
 #include "civclient.h"
 
 #include "control.h"
Index: client/repodlgs_common.c
===================================================================
--- client/repodlgs_common.c    (revision 11385)
+++ client/repodlgs_common.c    (working copy)
@@ -18,11 +18,13 @@
 #include <assert.h>
 
 #include "fcintl.h"
-#include "game.h"
-#include "government.h"
 #include "mem.h"               /* free */
 #include "support.h"           /* my_snprintf */
 
+#include "game.h"
+#include "government.h"
+#include "unitlist.h"
+
 #include "repodlgs_g.h"
 
 #include "civclient.h"         /* can_client_issue_orders */
Index: client/goto.c
===================================================================
--- client/goto.c       (revision 11385)
+++ client/goto.c       (working copy)
@@ -19,11 +19,13 @@
 #include <string.h>
 
 #include "log.h"
+#include "mem.h"
+
 #include "map.h"
-#include "mem.h"
 #include "packets.h"
 #include "pf_tools.h"
 #include "unit.h"
+#include "unitlist.h"
 
 #include "civclient.h"
 #include "clinet.h"
Index: client/packhand.c
===================================================================
--- client/packhand.c   (revision 11385)
+++ client/packhand.c   (working copy)
@@ -34,6 +34,7 @@
 #include "spaceship.h"
 #include "support.h"
 #include "unit.h"
+#include "unitlist.h"
 #include "worklist.h"
 
 #include "agents.h"
Index: client/tilespec.c
===================================================================
--- client/tilespec.c   (revision 11385)
+++ client/tilespec.c   (working copy)
@@ -41,6 +41,7 @@
 #include "shared.h"
 #include "support.h"
 #include "unit.h"
+#include "unitlist.h"
 
 #include "dialogs_g.h"
 #include "graphics_g.h"
Index: client/mapctrl_common.c
===================================================================
--- client/mapctrl_common.c     (revision 11385)
+++ client/mapctrl_common.c     (working copy)
@@ -18,11 +18,13 @@
 #include <assert.h>
 #include <stdlib.h>            /* qsort */
 
-#include "combat.h"
 #include "fcintl.h"
 #include "log.h"
 #include "support.h"
 
+#include "combat.h"
+#include "unitlist.h"
+
 #include "agents.h"
 #include "chatline_common.h"
 #include "cityrep_g.h"
Index: client/mapview_common.c
===================================================================
--- client/mapview_common.c     (revision 11385)
+++ client/mapview_common.c     (working copy)
@@ -19,11 +19,13 @@
 
 #include "fcintl.h"
 #include "log.h"
-#include "map.h"
 #include "rand.h"
 #include "support.h"
 #include "timing.h"
 
+#include "map.h"
+#include "unitlist.h"
+
 #include "graphics_g.h"
 #include "gui_main_g.h"
 #include "mapctrl_g.h"
Index: client/climisc.c
===================================================================
--- client/climisc.c    (revision 11388)
+++ client/climisc.c    (working copy)
@@ -26,16 +26,18 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "fcintl.h"
+#include "log.h"
+#include "support.h"
+
 #include "city.h"
 #include "diptreaty.h"
-#include "fcintl.h"
 #include "game.h"
 #include "government.h"
-#include "log.h"
 #include "map.h"
 #include "packets.h"
 #include "spaceship.h"
-#include "support.h"
+#include "unitlist.h"
 
 #include "chatline_g.h"
 #include "citydlg_g.h"

Attachment: unitlist.c
Description: Binary data


[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#14992) I: common/unitlist.[ch], Egor Vyscrebentsov <=