Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2002:
[Freeciv-Dev] (PR#2350) Remove dependencies
Home

[Freeciv-Dev] (PR#2350) Remove dependencies

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] (PR#2350) Remove dependencies
From: "Raimar Falke via RT" <rt@xxxxxxxxxxxxxx>
Date: Fri, 15 Nov 2002 14:39:33 -0800
Reply-to: rt@xxxxxxxxxxxxxx


The attached patch moves code to {city,conn,unit}_list.[ch]. Since
most of the time we aren't interrested in the layout of struct city
and co but are interrested in the lists (to embed them). Moving them
out makes it possible to cut down the dependencies (meaning than fewer
files are recompiled if connection.h is changed for example).

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 checking for the vaidity of the Maxwell laws on this machine... ok
 checking if e=mc^2... ok
 checking if we can safely swap on /dev/fd0... yes
    -- kvirc 2.0.0's configure 

diff -Nurd -X clean/diff_ignore clean/ai/aiair.c work/ai/aiair.c
--- clean/ai/aiair.c    Thu Nov 14 09:48:52 2002
+++ work/ai/aiair.c     Fri Nov 15 22:48:40 2002
@@ -16,6 +16,7 @@
 #endif
 
 #include "combat.h"
+#include "game.h"
 #include "log.h"
 #include "map.h"
 #include "player.h"
diff -Nurd -X clean/diff_ignore clean/ai/ailog.c work/ai/ailog.c
--- clean/ai/ailog.c    Thu Nov 14 09:48:52 2002
+++ work/ai/ailog.c     Fri Nov 15 22:49:42 2002
@@ -19,6 +19,8 @@
 
 #include "city.h"
 #include "log.h"
+#include "game.h"
+#include "player.h"
 #include "shared.h"
 #include "support.h"
 #include "unit.h"
diff -Nurd -X clean/diff_ignore clean/client/citydlg_common.c 
work/client/citydlg_common.c
--- clean/client/citydlg_common.c       Thu Nov 14 09:48:52 2002
+++ work/client/citydlg_common.c        Fri Nov 15 23:24:11 2002
@@ -16,6 +16,7 @@
 #endif
 
 #include "city.h"
+#include "game.h"
 #include "fcintl.h"
 #include "log.h"
 #include "support.h"
diff -Nurd -X clean/diff_ignore clean/client/goto.c work/client/goto.c
--- clean/client/goto.c Thu Nov 14 18:34:53 2002
+++ work/client/goto.c  Fri Nov 15 23:24:51 2002
@@ -18,6 +18,7 @@
 #include <assert.h>
 #include <string.h>
 
+#include "game.h"
 #include "log.h"
 #include "map.h"
 #include "mem.h"
diff -Nurd -X clean/diff_ignore clean/client/gui-gtk/finddlg.c 
work/client/gui-gtk/finddlg.c
--- clean/client/gui-gtk/finddlg.c      Thu Nov 14 09:48:52 2002
+++ work/client/gui-gtk/finddlg.c       Fri Nov 15 22:58:56 2002
@@ -22,6 +22,7 @@
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
 
+#include "city.h"
 #include "fcintl.h"
 #include "game.h"
 #include "player.h"
diff -Nurd -X clean/diff_ignore clean/client/mapview_common.c 
work/client/mapview_common.c
--- clean/client/mapview_common.c       Fri Nov 15 10:20:47 2002
+++ work/client/mapview_common.c        Fri Nov 15 23:25:33 2002
@@ -17,6 +17,8 @@
 
 #include <assert.h>
 
+#include "city.h"
+#include "game.h"
 #include "log.h"
 #include "map.h"
 #include "support.h"
diff -Nurd -X clean/diff_ignore clean/client/messagewin_common.c 
work/client/messagewin_common.c
--- clean/client/messagewin_common.c    Thu Nov 14 09:48:52 2002
+++ work/client/messagewin_common.c     Fri Nov 15 23:25:52 2002
@@ -18,6 +18,7 @@
 #include <assert.h>
 #include <string.h>
 
+#include "game.h"
 #include "mem.h"
 #include "messagewin_g.h"
 #include "options.h"
diff -Nurd -X clean/diff_ignore clean/client/repodlgs_common.c 
work/client/repodlgs_common.c
--- clean/client/repodlgs_common.c      Thu Nov 14 09:48:52 2002
+++ work/client/repodlgs_common.c       Fri Nov 15 23:26:19 2002
@@ -17,6 +17,7 @@
 
 #include <assert.h>
 
+#include "city.h"
 #include "game.h"
 #include "repodlgs_g.h"
 
diff -Nurd -X clean/diff_ignore clean/common/Makefile.am work/common/Makefile.am
--- clean/common/Makefile.am    Thu Nov 14 09:35:36 2002
+++ work/common/Makefile.am     Fri Nov 15 22:42:54 2002
@@ -15,10 +15,14 @@
                capstr.h        \
                city.c          \
                city.h          \
+               city_list.c     \
+               city_list.h     \
                combat.c        \
                combat.h        \
                connection.c    \
                connection.h    \
+               conn_list.c     \
+               conn_list.h     \
                create_lsend.pl \
                dataio.c        \
                dataio.h        \
@@ -82,6 +86,8 @@
                timing.h        \
                unit.c          \
                unit.h          \
+               unit_list.c     \
+               unit_list.h     \
                unittype.c      \
                unittype.h      \
                worklist.c      \
diff -Nurd -X clean/diff_ignore clean/common/city.c work/common/city.c
--- clean/common/city.c Fri Nov 15 20:07:00 2002
+++ work/common/city.c  Fri Nov 15 22:42:05 2002
@@ -25,14 +25,10 @@
 #include "map.h"
 #include "mem.h"
 #include "support.h"
+#include "unit.h"
 
 #include "city.h"
 
-/* get 'struct city_list' functions: */
-#define SPECLIST_TAG city
-#define SPECLIST_TYPE struct city
-#include "speclist_c.h"
-
 /* start helper functions for generic_city_refresh */
 static int content_citizens(struct player *pplayer);
 static void set_tax_income(struct city *pcity);
@@ -1038,36 +1034,6 @@
   return (pcity->rapture > 0 && pcity->food_surplus > 0
          && (pcity->rapture % game.rapturedelay) == 0
          && government_has_flag(g, G_RAPTURE_CITY_GROWTH));
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-struct city *city_list_find_id(struct city_list *This, int id)
-{
-  if (id != 0) {
-    city_list_iterate(*This, pcity) {
-      if (pcity->id == id) {
-       return pcity;
-      }
-    } city_list_iterate_end;
-  }
-
-  return NULL;
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-struct city *city_list_find_name(struct city_list *This, const char *name)
-{
-  city_list_iterate(*This, pcity) {
-    if (mystrcasecmp(name, pcity->name) == 0) {
-      return pcity;
-    }
-  } city_list_iterate_end;
-
-  return NULL;
 }
 
 /**************************************************************************
diff -Nurd -X clean/diff_ignore clean/common/city.h work/common/city.h
--- clean/common/city.h Fri Nov 15 20:07:00 2002
+++ work/common/city.h  Fri Nov 15 22:30:29 2002
@@ -14,7 +14,7 @@
 #define FC__CITY_H
 
 #include "improvement.h"
-#include "unit.h"              /* struct unit_list */
+#include "unit_list.h"
 #include "worklist.h"
 
 struct player;
@@ -319,15 +319,6 @@
 
 extern struct citystyle *city_styles;
 
-/* get 'struct city_list' and related functions: */
-#define SPECLIST_TAG city
-#define SPECLIST_TYPE struct city
-#include "speclist.h"
-
-#define city_list_iterate(citylist, pcity) \
-    TYPED_LIST_ITERATE(struct city, citylist, pcity)
-#define city_list_iterate_end  LIST_ITERATE_END
-
 /* properties */
 
 struct player *city_owner(struct city *pcity);
@@ -414,10 +405,6 @@
 bool can_establish_trade_route(struct city *pc1, struct city *pc2);
 int trade_between_cities(struct city *pc1, struct city *pc2);
 int city_num_trade_routes(struct city *pcity);
-
-/* list functions */
-struct city *city_list_find_id(struct city_list *This, int id);
-struct city *city_list_find_name(struct city_list *This, const char *name);
 
 int city_name_compare(const void *p1, const void *p2);
 
diff -Nurd -X clean/diff_ignore clean/common/city_list.c work/common/city_list.c
--- clean/common/city_list.c    Thu Jan  1 01:00:00 1970
+++ work/common/city_list.c     Fri Nov 15 22:45:36 2002
@@ -0,0 +1,55 @@
+/********************************************************************** 
+ 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
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "city.h"
+#include "support.h"
+
+#include "city_list.h"
+
+#define SPECLIST_TAG city
+#define SPECLIST_TYPE struct city
+#include "speclist_c.h"
+
+/**************************************************************************
+...
+**************************************************************************/
+struct city *city_list_find_id(struct city_list *This, int id)
+{
+  if (id != 0) {
+    city_list_iterate(*This, pcity) {
+      if (pcity->id == id) {
+       return pcity;
+      }
+    } city_list_iterate_end;
+  }
+
+  return NULL;
+}
+
+/**************************************************************************
+...
+**************************************************************************/
+struct city *city_list_find_name(struct city_list *This, const char *name)
+{
+  city_list_iterate(*This, pcity) {
+    if (mystrcasecmp(name, pcity->name) == 0) {
+      return pcity;
+    }
+  } city_list_iterate_end;
+
+  return NULL;
+}
diff -Nurd -X clean/diff_ignore clean/common/city_list.h work/common/city_list.h
--- clean/common/city_list.h    Thu Jan  1 01:00:00 1970
+++ work/common/city_list.h     Fri Nov 15 19:37:28 2002
@@ -0,0 +1,30 @@
+/********************************************************************** 
+ 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
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+#ifndef FC__CITY_LIST_H
+#define FC__CITY_LIST_H
+
+struct city;
+
+#define SPECLIST_TAG city
+#define SPECLIST_TYPE struct city
+#include "speclist.h"
+
+#define city_list_iterate(citylist, pcity) \
+    TYPED_LIST_ITERATE(struct city, citylist, pcity)
+#define city_list_iterate_end  LIST_ITERATE_END
+
+/* list functions */
+struct city *city_list_find_id(struct city_list *This, int id);
+struct city *city_list_find_name(struct city_list *This, const char *name);
+
+#endif  /* FC__CITY_LIST_H */
diff -Nurd -X clean/diff_ignore clean/common/combat.c work/common/combat.c
--- clean/common/combat.c       Thu Nov 14 17:03:27 2002
+++ work/common/combat.c        Fri Nov 15 19:45:33 2002
@@ -19,8 +19,10 @@
 #include <math.h>
 #include <stdio.h>
 
+#include "city.h"
 #include "log.h"
 #include "map.h"
+#include "player.h"
 #include "unit.h"
 
 #include "combat.h"
diff -Nurd -X clean/diff_ignore clean/common/conn_list.c work/common/conn_list.c
--- clean/common/conn_list.c    Thu Jan  1 01:00:00 1970
+++ work/common/conn_list.c     Fri Nov 15 19:31:16 2002
@@ -0,0 +1,22 @@
+/********************************************************************** 
+ 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
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "conn_list.h"
+
+#define SPECLIST_TAG conn
+#define SPECLIST_TYPE struct connection
+#include "speclist_c.h"
diff -Nurd -X clean/diff_ignore clean/common/conn_list.h work/common/conn_list.h
--- clean/common/conn_list.h    Thu Jan  1 01:00:00 1970
+++ work/common/conn_list.h     Fri Nov 15 19:30:19 2002
@@ -0,0 +1,25 @@
+/********************************************************************** 
+ 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
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+#ifndef FC__CONN_LIST_H
+#define FC__CONN_LIST_H
+
+struct connection;
+#define SPECLIST_TAG conn
+#define SPECLIST_TYPE struct connection
+#include "speclist.h"
+
+#define conn_list_iterate(connlist, pconn) \
+    TYPED_LIST_ITERATE(struct connection, connlist, pconn)
+#define conn_list_iterate_end  LIST_ITERATE_END
+
+#endif  /* FC__CONN_LIST_H */
diff -Nurd -X clean/diff_ignore clean/common/connection.c 
work/common/connection.c
--- clean/common/connection.c   Thu Nov 14 17:03:27 2002
+++ work/common/connection.c    Fri Nov 15 19:32:07 2002
@@ -46,11 +46,6 @@
 
 #include "connection.h"
 
-/* get 'struct conn_list' functions: */
-#define SPECLIST_TAG conn
-#define SPECLIST_TYPE struct connection
-#include "speclist_c.h"
-
 /* String used for connection.addr and related cases to indicate
  * blank/unknown/not-applicable address:
  */
diff -Nurd -X clean/diff_ignore clean/common/connection.h 
work/common/connection.h
--- clean/common/connection.h   Thu Nov 14 17:03:27 2002
+++ work/common/connection.h    Fri Nov 15 19:31:51 2002
@@ -24,6 +24,7 @@
 ***************************************************************************/
 
 #include "shared.h"            /* MAX_LEN_ADDR, bool type */
+#include "conn_list.h"
 
 struct player;
 struct timer_list;
@@ -53,18 +54,6 @@
   On the distinction between nations(formerly races), players, and users,
   see doc/HACKING
 ***************************************************************************/
-
-/* get 'struct conn_list' and related functions: */
-/* do this with forward definition of struct connection, so that
- * connection struct can contain a struct conn_list */
-struct connection;
-#define SPECLIST_TAG conn
-#define SPECLIST_TYPE struct connection
-#include "speclist.h"
-
-#define conn_list_iterate(connlist, pconn) \
-    TYPED_LIST_ITERATE(struct connection, connlist, pconn)
-#define conn_list_iterate_end  LIST_ITERATE_END
 
 /***********************************************************
   This is a buffer where the data is first collected,
diff -Nurd -X clean/diff_ignore clean/common/game.h work/common/game.h
--- clean/common/game.h Thu Nov 14 17:03:28 2002
+++ work/common/game.h  Fri Nov 15 19:32:35 2002
@@ -18,7 +18,7 @@
 #include <sys/time.h>
 #endif
 
-#include "connection.h"                /* struct conn_list */
+#include "conn_list.h"
 #include "improvement.h"       /* Impr_Status */
 #include "shared.h"
 #include "player.h"
diff -Nurd -X clean/diff_ignore clean/common/government.c 
work/common/government.c
--- clean/common/government.c   Thu Nov 14 17:03:28 2002
+++ work/common/government.c    Fri Nov 15 19:41:52 2002
@@ -19,6 +19,7 @@
 #include <string.h>
 #include <assert.h>
 
+#include "city.h"
 #include "game.h"
 #include "log.h"
 #include "mem.h"
diff -Nurd -X clean/diff_ignore clean/common/improvement.c 
work/common/improvement.c
--- clean/common/improvement.c  Thu Nov 14 17:03:28 2002
+++ work/common/improvement.c   Fri Nov 15 19:42:36 2002
@@ -18,6 +18,7 @@
 #include <assert.h>
 #include <string.h>
 
+#include "city.h"
 #include "game.h"
 #include "map.h"
 #include "support.h"
diff -Nurd -X clean/diff_ignore clean/common/map.c work/common/map.c
--- clean/common/map.c  Thu Nov 14 17:03:28 2002
+++ work/common/map.c   Fri Nov 15 19:44:15 2002
@@ -23,6 +23,7 @@
 #include "city.h"
 #include "fcintl.h"
 #include "log.h"
+#include "game.h"              /* is_server */
 #include "mem.h"
 #include "rand.h"
 #include "shared.h"
diff -Nurd -X clean/diff_ignore clean/common/map.h work/common/map.h
--- clean/common/map.h  Thu Nov  7 15:45:22 2002
+++ work/common/map.h   Fri Nov 15 19:45:12 2002
@@ -16,10 +16,10 @@
 #include <assert.h>
 #include <math.h>
 
-#include "player.h"
 #include "terrain.h"
-#include "unit.h"
-#include "game.h"
+#include "unit_list.h"
+#include "nation.h"            /* MAX_NUM_NATIONS */
+#include "unit.h"              /* enum unit_activity */
 
 struct Sprite;                 /* opaque; client-gui specific */
 
diff -Nurd -X clean/diff_ignore clean/common/packets.c work/common/packets.c
--- clean/common/packets.c      Fri Nov 15 18:10:46 2002
+++ work/common/packets.c       Fri Nov 15 19:46:34 2002
@@ -38,6 +38,7 @@
 #include "dataio.h"
 #include "events.h"
 #include "fcintl.h"
+#include "game.h"              /* is_server */
 #include "log.h"
 #include "mem.h"
 #include "support.h"
diff -Nurd -X clean/diff_ignore clean/common/packets.h work/common/packets.h
--- clean/common/packets.h      Thu Nov 14 10:19:54 2002
+++ work/common/packets.h       Fri Nov 15 19:46:09 2002
@@ -14,6 +14,7 @@
 #define FC__PACKETS_H
 
 #include "connection.h"                /* struct connection, MAX_LEN_* */
+#include "city.h"              /* NUM_TRADEROUTES, CITY_MAP_SIZE */
 #include "map.h"
 #include "player.h"
 #include "shared.h"            /* MAX_LEN_NAME, MAX_LEN_ADDR */
diff -Nurd -X clean/diff_ignore clean/common/player.c work/common/player.c
--- clean/common/player.c       Thu Nov 14 18:34:54 2002
+++ work/common/player.c        Fri Nov 15 19:34:18 2002
@@ -20,6 +20,7 @@
 #include <string.h>
 
 #include "city.h"
+#include "connection.h"
 #include "fcintl.h"
 #include "game.h"
 #include "government.h"
diff -Nurd -X clean/diff_ignore clean/common/player.h work/common/player.h
--- clean/common/player.h       Thu Nov 14 09:35:36 2002
+++ work/common/player.h        Fri Nov 15 19:42:13 2002
@@ -13,14 +13,14 @@
 #ifndef FC__PLAYER_H
 #define FC__PLAYER_H
 
-#include "city.h"
-#include "connection.h"                /* struct conn_list */
+#include "city_list.h"
+#include "conn_list.h"
 #include "improvement.h"       /* Impr_Status */
-#include "nation.h"
+#include "nation.h"            /* Nation_Type_id */
 #include "shared.h"
 #include "spaceship.h"
-#include "tech.h"
-#include "unit.h"
+#include "unit_list.h"
+#include "worklist.h"
 
 struct tile;
 
diff -Nurd -X clean/diff_ignore clean/common/tech.c work/common/tech.c
--- clean/common/tech.c Thu Nov 14 18:34:54 2002
+++ work/common/tech.c  Fri Nov 15 19:46:59 2002
@@ -20,6 +20,7 @@
 #include <string.h>
 #include <assert.h>
 
+#include "city.h"
 #include "fcintl.h"
 #include "game.h"
 #include "log.h"
diff -Nurd -X clean/diff_ignore clean/common/unit.c work/common/unit.c
--- clean/common/unit.c Fri Nov 15 20:07:00 2002
+++ work/common/unit.c  Fri Nov 15 22:41:33 2002
@@ -17,6 +17,7 @@
 
 #include <assert.h>
 
+#include "city.h"
 #include "fcintl.h"
 #include "game.h"
 #include "log.h"
@@ -28,11 +29,6 @@
 
 #include "unit.h"
 
-/* get 'struct unit_list' functions: */
-#define SPECLIST_TAG unit
-#define SPECLIST_TYPE struct unit
-#include "speclist_c.h"
-
 /***************************************************************
 This function calculates the move rate of the unit taking into 
 account the penalty for reduced hitpoints (affects sea and land 
@@ -939,67 +935,6 @@
     freelog(LOG_FATAL, "Unknown unit activity %d in unit_activity_text()",
            punit->activity);
     exit(EXIT_FAILURE);
-  }
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-struct unit *unit_list_find(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) {
-    genlist_sort(&This->list, compar_unit_ord_map);
-  }
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-void unit_list_sort_ord_city(struct unit_list *This)
-{
-  if(unit_list_size(This) > 1) {
-    genlist_sort(&This->list, compar_unit_ord_city);
   }
 }
 
diff -Nurd -X clean/diff_ignore clean/common/unit.h work/common/unit.h
--- clean/common/unit.h Fri Nov 15 20:07:00 2002
+++ work/common/unit.h  Fri Nov 15 22:30:30 2002
@@ -135,15 +135,6 @@
   struct goto_route *pgr;
 };
 
-
-/* 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
@@ -169,11 +160,6 @@
     free(_ids); \
   } \
 }
-
-struct unit *unit_list_find(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(struct unit *pdiplomat,
                           enum diplomat_actions action, 
diff -Nurd -X clean/diff_ignore clean/common/unit_list.c work/common/unit_list.c
--- clean/common/unit_list.c    Thu Jan  1 01:00:00 1970
+++ work/common/unit_list.c     Fri Nov 15 22:56:16 2002
@@ -0,0 +1,85 @@
+/********************************************************************** 
+ 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
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "unit.h"
+
+#include "unit_list.h"
+
+#define SPECLIST_TAG unit
+#define SPECLIST_TYPE struct unit
+#include "speclist_c.h"
+
+/**************************************************************************
+...
+**************************************************************************/
+struct unit *unit_list_find(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) {
+    genlist_sort(&This->list, compar_unit_ord_map);
+  }
+}
+
+/**************************************************************************
+...
+**************************************************************************/
+void unit_list_sort_ord_city(struct unit_list *This)
+{
+  if(unit_list_size(This) > 1) {
+    genlist_sort(&This->list, compar_unit_ord_city);
+  }
+}
diff -Nurd -X clean/diff_ignore clean/common/unit_list.h work/common/unit_list.h
--- clean/common/unit_list.h    Thu Jan  1 01:00:00 1970
+++ work/common/unit_list.h     Fri Nov 15 19:39:42 2002
@@ -0,0 +1,30 @@
+/********************************************************************** 
+ 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
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+#ifndef FC__UNIT_LIST_H
+#define FC__UNIT_LIST_H
+
+struct unit;
+#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
+
+struct unit *unit_list_find(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);
+
+#endif  /* FC__UNIT_LIST_H */
diff -Nurd -X clean/diff_ignore clean/common/unittype.c work/common/unittype.c
--- clean/common/unittype.c     Thu Nov 14 09:48:55 2002
+++ work/common/unittype.c      Fri Nov 15 19:48:18 2002
@@ -19,6 +19,7 @@
 #include <string.h>
 
 #include "astring.h"
+#include "city.h"
 #include "fcintl.h"
 #include "game.h"
 #include "government.h"
@@ -27,6 +28,7 @@
 #include "support.h"
 #include "tech.h"
 #include "shared.h"
+#include "unit.h"
 
 #include "unittype.h"
 
diff -Nurd -X clean/diff_ignore clean/server/airgoto.c work/server/airgoto.c
--- clean/server/airgoto.c      Thu Nov 14 09:48:55 2002
+++ work/server/airgoto.c       Fri Nov 15 22:52:39 2002
@@ -15,6 +15,7 @@
 #include <config.h>
 #endif
 
+#include "city.h"
 #include "log.h"
 #include "map.h"
 #include "mem.h"
diff -Nurd -X clean/diff_ignore clean/server/cityhand.c work/server/cityhand.c
--- clean/server/cityhand.c     Thu Nov 14 17:03:28 2002
+++ work/server/cityhand.c      Fri Nov 15 22:53:06 2002
@@ -24,6 +24,7 @@
 #include "events.h"
 #include "fcintl.h"
 #include "idex.h"
+#include "game.h"
 #include "log.h"
 #include "map.h"
 #include "player.h"
diff -Nurd -X clean/diff_ignore clean/server/diplomats.c work/server/diplomats.c
--- clean/server/diplomats.c    Thu Nov 14 18:34:54 2002
+++ work/server/diplomats.c     Fri Nov 15 22:53:33 2002
@@ -19,6 +19,7 @@
 
 #include "events.h"
 #include "fcintl.h"
+#include "game.h"
 #include "government.h"
 #include "log.h"
 #include "player.h"
diff -Nurd -X clean/diff_ignore clean/server/gamehand.c work/server/gamehand.c
--- clean/server/gamehand.c     Thu Nov 14 09:48:55 2002
+++ work/server/gamehand.c      Fri Nov 15 22:54:13 2002
@@ -18,6 +18,7 @@
 #include <assert.h>
 
 #include "fcintl.h"
+#include "game.h"
 #include "improvement.h"
 #include "log.h"
 #include "mem.h"

[Prev in Thread] Current Thread [Next in Thread]