Get rid of src/lib/common/land.c
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.
This commit is contained in:
parent
312e6d4c5b
commit
3d2518a724
5 changed files with 79 additions and 122 deletions
|
@ -39,9 +39,11 @@
|
|||
#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], §);
|
||||
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?
|
||||
*/
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue