From f7faeb6470f6a0a41344915cc6158ed9f127902e Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 28 Jan 2004 09:31:22 +0000 Subject: [PATCH] (lnd_fortify): New, factored out of fort(). (fort): Use it; no functional changes. (is_engineer): Move to logical place, external linkage. --- include/land.h | 2 +- include/prototypes.h | 1 + src/lib/commands/fort.c | 53 ++--------------------------------------- src/lib/common/land.c | 15 ++++++++++++ src/lib/subs/lndsub.c | 48 +++++++++++++++++++++++++++++++++++++ 5 files changed, 67 insertions(+), 52 deletions(-) diff --git a/include/land.h b/include/land.h index 0dbff0831..cf393a93b 100644 --- a/include/land.h +++ b/include/land.h @@ -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_fortify (struct lndstr *lp, int hard_amt); void landdamage(); void lnd_nav(); diff --git a/include/prototypes.h b/include/prototypes.h index efe557f0e..ade09bd08 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -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 is_engineer(int x, int y); /* log.c */ extern void loginit(void); extern void logerror(s_char *, ...); diff --git a/src/lib/commands/fort.c b/src/lib/commands/fort.c index 0c5835efd..90a18b462 100644 --- a/src/lib/commands/fort.c +++ b/src/lib/commands/fort.c @@ -44,16 +44,13 @@ #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_amt, hard_amt, mob_used; - int eng; + int fort_amt, hard_amt; s_char *p; extern int land_mob_max; s_char buf[1024]; @@ -95,38 +92,7 @@ fort(void) 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); @@ -142,18 +108,3 @@ fort(void) 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; -} diff --git a/src/lib/common/land.c b/src/lib/common/land.c index a7e415b82..627f7e6f1 100644 --- a/src/lib/common/land.c +++ b/src/lib/common/land.c @@ -96,3 +96,18 @@ has_units_with_mob(coord x, coord y, natid cn) 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; +} diff --git a/src/lib/subs/lndsub.c b/src/lib/subs/lndsub.c index a4362181e..80f9230a4 100644 --- a/src/lib/subs/lndsub.c +++ b/src/lib/subs/lndsub.c @@ -1349,3 +1349,51 @@ lnd_can_attack(struct lndstr *lp) 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; +} -- 2.43.0