]> git.pond.sub.org Git - empserver/commitdiff
(lnd_fortify): New, factored out of fort().
authorMarkus Armbruster <armbru@pond.sub.org>
Wed, 28 Jan 2004 09:31:22 +0000 (09:31 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Wed, 28 Jan 2004 09:31:22 +0000 (09:31 +0000)
(fort): Use it; no functional changes.
(is_engineer): Move to logical place, external linkage.

include/land.h
include/prototypes.h
src/lib/commands/fort.c
src/lib/common/land.c
src/lib/subs/lndsub.c

index 0dbff08315268de76b5ae0175275f5e8f47ff474..cf393a93b6161e0399b9d96259e6651f893c81ee 100644 (file)
@@ -226,7 +226,7 @@ extern int lnd_hardtarget(struct lndstr *);
 extern int lnd_mar_one_sector(struct emp_qelem *, int, natid, int);
 extern int lnd_support(natid, natid, coord, coord);
 extern int lnd_can_attack(struct lndstr *);
 extern int lnd_mar_one_sector(struct emp_qelem *, int, natid, int);
 extern int lnd_support(natid, natid, coord, coord);
 extern int lnd_can_attack(struct lndstr *);
-
+extern int lnd_fortify (struct lndstr *lp, int hard_amt);
 
 void landdamage();
 void lnd_nav();
 
 void landdamage();
 void lnd_nav();
index efe557f0eb029efaa095ed728cdf3cb11f0a99b3..ade09bd08ebfe2754cf68cdb521965d2f07af140 100644 (file)
@@ -330,6 +330,7 @@ extern int gamehours(time_t, int *);
 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_units(coord, coord, natid, struct lndstr *);
 extern int has_units_with_mob(coord, coord, natid);
 extern int adj_units(coord, coord, natid);
+extern int is_engineer(int x, int y);
 /* log.c */
 extern void loginit(void);
 extern void logerror(s_char *, ...);
 /* log.c */
 extern void loginit(void);
 extern void logerror(s_char *, ...);
index 0c5835efd205230126e825b4b46522f9409d1374..90a18b462b045cdb22f78c9b65216bff5e808511 100644 (file)
 #include "file.h"
 #include "commands.h"
 
 #include "file.h"
 #include "commands.h"
 
-static int is_engineer(int, int);
-
 int
 fort(void)
 {
     int nunits;
     struct nstr_item ni;
     struct lndstr land;
 int
 fort(void)
 {
     int nunits;
     struct nstr_item ni;
     struct lndstr land;
-    int fort_amt, hard_amt, mob_used;
-    int eng;
+    int fort_amt, hard_amt;
     s_char *p;
     extern int land_mob_max;
     s_char buf[1024];
     s_char *p;
     extern int land_mob_max;
     s_char buf[1024];
@@ -95,38 +92,7 @@ fort(void)
 
        nunits++;
 
 
        nunits++;
 
-       hard_amt = min(land.lnd_mobil, hard_amt);
-
-       if ((land.lnd_harden + hard_amt) > land_mob_max)
-           hard_amt = land_mob_max - land.lnd_harden;
-
-       eng = is_engineer(land.lnd_x, land.lnd_y);
-
-       if (eng)
-           hard_amt = ((float)hard_amt * 1.5);
-
-       if ((land.lnd_harden + hard_amt) > land_mob_max)
-           hard_amt = land_mob_max - land.lnd_harden;
-
-       /* Ok, set the mobility used */
-       mob_used = hard_amt;
-
-       /* Now, if an engineer helped, it's really only 2/3rds of
-          that */
-       if (eng)
-           mob_used = (int)((float)mob_used / 1.5);
-
-       /* If we increased it, but not much, we gotta take at least 1
-          mob point. */
-       if (mob_used <= 0 && hard_amt > 0)
-           mob_used = 1;
-
-       land.lnd_mobil -= mob_used;
-       if (land.lnd_mobil < 0)
-           land.lnd_mobil = 0;
-
-       land.lnd_harden += hard_amt;
-       land.lnd_harden = min(land.lnd_harden, land_mob_max);
+       lnd_fortify (&land, hard_amt);
 
        pr("%s hardened to %d\n", prland(&land), land.lnd_harden);
 
 
        pr("%s hardened to %d\n", prland(&land), land.lnd_harden);
 
@@ -142,18 +108,3 @@ fort(void)
        pr("%d unit%s\n", nunits, splur(nunits));
     return RET_OK;
 }
        pr("%d unit%s\n", nunits, splur(nunits));
     return RET_OK;
 }
-
-static int
-is_engineer(int x, int y)
-{
-    struct nstr_item ni;
-    struct lndstr land;
-
-    snxtitem_xy(&ni, EF_LAND, x, y);
-    while (nxtitem(&ni, (s_char *)&land)) {
-       if (lchr[(int)land.lnd_type].l_flags & L_ENGINEER)
-           return 1;
-    }
-
-    return 0;
-}
index a7e415b82050fe567733e59777520e5b49fdce80..627f7e6f16b47be832d05a0bbbf83cb009864aa5 100644 (file)
@@ -96,3 +96,18 @@ has_units_with_mob(coord x, coord y, natid cn)
 
     return 0;
 }
 
     return 0;
 }
+
+int
+is_engineer(int x, int y)
+{
+    struct nstr_item ni;
+    struct lndstr land;
+
+    snxtitem_xy(&ni, EF_LAND, x, y);
+    while (nxtitem(&ni, (s_char *)&land)) {
+       if (lchr[(int)land.lnd_type].l_flags & L_ENGINEER)
+           return 1;
+    }
+
+    return 0;
+}
index a4362181ea69b50cb920a4728cd2b330c05f1e2d..80f9230a4158d3cf522cdf821cd27136aec16c2a 100644 (file)
@@ -1349,3 +1349,51 @@ lnd_can_attack(struct lndstr *lp)
 
     return 1;
 }
 
     return 1;
 }
+
+/*
+ * Increase fortification value of LP.
+ * Fortification costs mobility.  Use up to HARD_AMT mobility.
+ * Return actual fortification increase.
+ */
+int
+lnd_fortify (struct lndstr *lp, int hard_amt)
+{
+    extern int land_mob_max;
+    int mob_used;
+    int eng;
+
+    hard_amt = min(lp->lnd_mobil, hard_amt);
+
+    if ((lp->lnd_harden + hard_amt) > land_mob_max)
+       hard_amt = land_mob_max - lp->lnd_harden;
+
+    eng = is_engineer(lp->lnd_x, lp->lnd_y);
+
+    if (eng)
+       hard_amt = ((float)hard_amt * 1.5);
+
+    if ((lp->lnd_harden + hard_amt) > land_mob_max)
+       hard_amt = land_mob_max - lp->lnd_harden;
+
+    /* Ok, set the mobility used */
+    mob_used = hard_amt;
+
+    /* Now, if an engineer helped, it's really only 2/3rds of
+       that */
+    if (eng)
+       mob_used = (int)((float)mob_used / 1.5);
+
+    /* If we increased it, but not much, we gotta take at least 1
+       mob point. */
+    if (mob_used <= 0 && hard_amt > 0)
+       mob_used = 1;
+
+    lp->lnd_mobil -= mob_used;
+    if (lp->lnd_mobil < 0)
+       lp->lnd_mobil = 0;
+
+    lp->lnd_harden += hard_amt;
+    lp->lnd_harden = min(lp->lnd_harden, land_mob_max);
+
+    return hard_amt;
+}