(lnd_fortify): New, factored out of fort().
(fort): Use it; no functional changes. (is_engineer): Move to logical place, external linkage.
This commit is contained in:
parent
ab01edbe46
commit
f7faeb6470
5 changed files with 67 additions and 52 deletions
|
@ -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_mar_one_sector(struct emp_qelem *, int, natid, int);
|
||||||
extern int lnd_support(natid, natid, coord, coord);
|
extern int lnd_support(natid, natid, coord, coord);
|
||||||
extern int lnd_can_attack(struct lndstr *);
|
extern int lnd_can_attack(struct lndstr *);
|
||||||
|
extern int lnd_fortify (struct lndstr *lp, int hard_amt);
|
||||||
|
|
||||||
void landdamage();
|
void landdamage();
|
||||||
void lnd_nav();
|
void lnd_nav();
|
||||||
|
|
|
@ -330,6 +330,7 @@ extern int gamehours(time_t, int *);
|
||||||
extern int has_units(coord, coord, natid, struct lndstr *);
|
extern int has_units(coord, coord, natid, struct lndstr *);
|
||||||
extern int has_units_with_mob(coord, coord, natid);
|
extern int has_units_with_mob(coord, coord, natid);
|
||||||
extern int adj_units(coord, coord, natid);
|
extern int adj_units(coord, coord, natid);
|
||||||
|
extern int is_engineer(int x, int y);
|
||||||
/* log.c */
|
/* log.c */
|
||||||
extern void loginit(void);
|
extern void loginit(void);
|
||||||
extern void logerror(s_char *, ...);
|
extern void logerror(s_char *, ...);
|
||||||
|
|
|
@ -44,16 +44,13 @@
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
|
|
||||||
static int is_engineer(int, int);
|
|
||||||
|
|
||||||
int
|
int
|
||||||
fort(void)
|
fort(void)
|
||||||
{
|
{
|
||||||
int nunits;
|
int nunits;
|
||||||
struct nstr_item ni;
|
struct nstr_item ni;
|
||||||
struct lndstr land;
|
struct lndstr land;
|
||||||
int fort_amt, hard_amt, mob_used;
|
int fort_amt, hard_amt;
|
||||||
int eng;
|
|
||||||
s_char *p;
|
s_char *p;
|
||||||
extern int land_mob_max;
|
extern int land_mob_max;
|
||||||
s_char buf[1024];
|
s_char buf[1024];
|
||||||
|
@ -95,38 +92,7 @@ fort(void)
|
||||||
|
|
||||||
nunits++;
|
nunits++;
|
||||||
|
|
||||||
hard_amt = min(land.lnd_mobil, hard_amt);
|
lnd_fortify (&land, 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);
|
|
||||||
|
|
||||||
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));
|
pr("%d unit%s\n", nunits, splur(nunits));
|
||||||
return RET_OK;
|
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;
|
|
||||||
}
|
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue