]> git.pond.sub.org Git - empserver/commitdiff
Get rid of src/lib/common/land.c
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 2 Feb 2008 20:36:37 +0000 (21:36 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 3 Feb 2008 06:37:16 +0000 (07:37 +0100)
There are several files with land unit subroutines.  This one is in an
awkward place: it depends on stuff from ../subs, which contributes to
libcommon.a's ugly dependencies.  Move its contents to logical places
(use internal linkage where possible), and remove it.

include/prototypes.h
src/lib/commands/cede.c
src/lib/common/land.c [deleted file]
src/lib/subs/list.c
src/lib/subs/lndsub.c

index a2ba04f58801240bb190ad42863fa83687629bc0..3ed8becfc0c5fe0fa64fa76c73263ad7715369f6 100644 (file)
@@ -298,11 +298,6 @@ extern double hap_req(struct natstr *np);
 extern int is_wday_allowed(int, char *);
 extern int is_daytime_allowed(int, char *);
 extern int gamehours(time_t);
-/* land.c */
-extern int has_units(coord, coord, natid, struct lndstr *);
-extern int has_units_with_mob(coord, coord, natid);
-extern int adj_units(coord, coord, natid);
-extern int has_helpful_engineer(coord x, coord y, natid cn);
 /* log.c */
 extern int loginit(char *);
 extern int logreopen(void);
@@ -488,6 +483,8 @@ extern int planesatxy(coord, coord, int, int, struct emp_qelem *);
 extern int asw_shipsatxy(coord, coord, int, int, struct plnstr *,
                         struct shiplist **);
 extern int num_shipsatxy(coord, coord, int, int);
+extern int has_units(coord, coord, natid, struct lndstr *);
+extern int adj_units(coord, coord, natid);
 extern int islist(char *);
 /* src/lib/subs/mission.c */
 extern char *mission_name(short);
index 636bc5b7894191de3e70c948d5c00db3fc32847c..bbdecc17e60518ec6dc55e7865fbb7c9bbc528bd 100644 (file)
@@ -42,6 +42,7 @@
 #include "plane.h"
 #include "ship.h"
 
+static int has_units_with_mob(coord, coord, natid);
 static void cede_hdr(void);
 static int cede_sect(struct nstr_sect *, natid);
 static int cede_ship(struct nstr_item *, natid);
@@ -169,6 +170,23 @@ cede_sect(struct nstr_sect *ns, natid to)
     return RET_OK;
 }
 
+static int
+has_units_with_mob(coord x, coord y, natid cn)
+{
+    struct nstr_item ni;
+    struct lndstr land;
+
+    snxtitem_xy(&ni, EF_LAND, x, y);
+    while (nxtitem(&ni, &land)) {
+       if (land.lnd_own != cn)
+           continue;
+       if (land.lnd_mobil > 0)
+           return 1;
+    }
+
+    return 0;
+}
+
 static void
 cede_hdr(void)
 {
diff --git a/src/lib/common/land.c b/src/lib/common/land.c
deleted file mode 100644 (file)
index 4f239d4..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
- *
- *  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 of the License, 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.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- *  ---
- *
- *  See files README, COPYING and CREDITS in the root of the source
- *  tree for related information and legal notices.  It is expected
- *  that future projects/authors will amend these files as needed.
- *
- *  ---
- *
- *  land.c: Misc. land unit routines
- * 
- *  Known contributors to this file:
- *     
- */
-
-#include <config.h>
-
-#include "file.h"
-#include "land.h"
-#include "misc.h"
-#include "nat.h"
-#include "nsc.h"
-#include "path.h"
-#include "prototypes.h"
-#include "sect.h"
-#include "xy.h"
-
-int
-adj_units(coord x, coord y, natid own)
-{
-    int i;
-    struct sctstr sect;
-
-    for (i = DIR_FIRST; i <= DIR_LAST; i++) {
-       getsect(x + diroff[i][0], y + diroff[i][1], &sect);
-       if (has_units(sect.sct_x, sect.sct_y, own, 0))
-           return 1;
-    }
-    return 0;
-}
-
-int
-has_units(coord x, coord y, natid cn, struct lndstr *lp)
-{
-    int n;
-    struct lndstr land;
-
-    for (n = 0; ef_read(EF_LAND, n, &land); n++) {
-       if (land.lnd_x != x || land.lnd_y != y)
-           continue;
-       if (lp) {
-           /* Check this unit.  If it is this one, we don't want
-              it included in the count. */
-           if (lp->lnd_uid == land.lnd_uid)
-               continue;
-       }
-       if (land.lnd_own == cn)
-           return 1;
-    }
-
-    return 0;
-}
-
-int
-has_units_with_mob(coord x, coord y, natid cn)
-{
-    struct nstr_item ni;
-    struct lndstr land;
-
-    snxtitem_xy(&ni, EF_LAND, x, y);
-    while (nxtitem(&ni, &land)) {
-       if (land.lnd_own != cn)
-           continue;
-       if (land.lnd_mobil > 0)
-           return 1;
-    }
-
-    return 0;
-}
-
-/*
- * Is there a engineer unit at X,Y that can help nation CN?
- */
-int
-has_helpful_engineer(coord x, coord y, natid cn)
-{
-    struct nstr_item ni;
-    struct lndstr land;
-
-    snxtitem_xy(&ni, EF_LAND, x, y);
-    while (nxtitem(&ni, &land)) {
-       if (land.lnd_own != cn && getrel(getnatp(land.lnd_own), cn) != ALLIED)
-           continue;
-       if (lchr[(int)land.lnd_type].l_flags & L_ENGINEER)
-           return 1;
-    }
-
-    return 0;
-}
index 0aa111ddd0453afeafc2e8a528b6d3e57cfd3e7f..96ce5d2da91e2f9f33a80e5c60d715ae6fb5f3ff 100644 (file)
 #include "misc.h"
 #include "nat.h"
 #include "nsc.h"
+#include "path.h"
 #include "plane.h"
 #include "player.h"
 #include "prototypes.h"
+#include "sect.h"
 #include "ship.h"
 #include "xy.h"
 
@@ -271,6 +273,42 @@ num_shipsatxy(coord x, coord y, int wantflags, int nowantflags)
     return ships;
 }
 
+int
+adj_units(coord x, coord y, natid own)
+{
+    int i;
+    struct sctstr sect;
+
+    for (i = DIR_FIRST; i <= DIR_LAST; i++) {
+       getsect(x + diroff[i][0], y + diroff[i][1], &sect);
+       if (has_units(sect.sct_x, sect.sct_y, own, 0))
+           return 1;
+    }
+    return 0;
+}
+
+int
+has_units(coord x, coord y, natid cn, struct lndstr *lp)
+{
+    int n;
+    struct lndstr land;
+
+    for (n = 0; ef_read(EF_LAND, n, &land); n++) {
+       if (land.lnd_x != x || land.lnd_y != y)
+           continue;
+       if (lp) {
+           /* Check this unit.  If it is this one, we don't want
+              it included in the count. */
+           if (lp->lnd_uid == land.lnd_uid)
+               continue;
+       }
+       if (land.lnd_own == cn)
+           return 1;
+    }
+
+    return 0;
+}
+
 /*
  * is p a list of ships/planes/units?
  */
index 224c7e1cbe937ef67a06e8c0411fb85b5f504eac..259aefcae41ecf9c9a7674b3e790baa084d136e4 100644 (file)
@@ -53,6 +53,7 @@
 
 static void lnd_mess(char *, struct ulist *);
 static int lnd_hit_mine(struct lndstr *, struct lchrstr *);
+static int has_helpful_engineer(coord, coord, natid);
 
 double
 attack_val(int combat_mode, struct lndstr *lp)
@@ -1248,6 +1249,26 @@ lnd_fortify(struct lndstr *lp, int mob)
     return hard_amt;
 }
 
+/*
+ * Is there a engineer unit at X,Y that can help nation CN?
+ */
+static int
+has_helpful_engineer(coord x, coord y, natid cn)
+{
+    struct nstr_item ni;
+    struct lndstr land;
+
+    snxtitem_xy(&ni, EF_LAND, x, y);
+    while (nxtitem(&ni, &land)) {
+       if (land.lnd_own != cn && getrel(getnatp(land.lnd_own), cn) != ALLIED)
+           continue;
+       if (lchr[(int)land.lnd_type].l_flags & L_ENGINEER)
+           return 1;
+    }
+
+    return 0;
+}
+
 /*
  * Set LP's tech to TLEV along with everything else that depends on it.
  */