(nxtitem): Skipped unowned sectors (could not occur), ships, planes,

land units and nukes for selection type NS_LIST.  Thus, unowned items
explicitly selected by item number are skipped, while the same items
selected implicitely by group, area or whatever are not.  This makes
no sense.  Some callers break the nstr_item abstraction to prevent the
skipping, so they get all items regardless of how they were selected.
All other callers filter out unowned items.  This skipping misfeature
dates back to the very oldest known versions of Empire.  Remove it.
Also remove skipping prevention hacks from callers.

(tend_nxtitem): Now identical to nxtitem(), except it lacks some extra
normalization of item coordinates, which should have no effect.
Replace by nxtitem().
This commit is contained in:
Markus Armbruster 2005-05-29 13:15:56 +00:00
parent 15448392f3
commit b111abc2c5
7 changed files with 3 additions and 94 deletions

View file

@ -102,8 +102,6 @@ fuel(void)
return RET_FAIL; return RET_FAIL;
} }
ni.flags &= ~(EFF_OWNER);
while (nxtitem(&ni, (s_char *)&item)) { while (nxtitem(&ni, (s_char *)&item)) {
fueled = 0; fueled = 0;
if (type == EF_SHIP) { if (type == EF_SHIP) {

View file

@ -109,8 +109,6 @@ load(void)
if (!snxtitem(&nbst, EF_SHIP, p)) if (!snxtitem(&nbst, EF_SHIP, p))
return RET_SYN; return RET_SYN;
nbst.flags &= ~(EFF_OWNER);
load_unload = **player->argp == 'l' ? LOAD : UNLOAD; load_unload = **player->argp == 'l' ? LOAD : UNLOAD;
nships = 0; nships = 0;
@ -251,8 +249,6 @@ lload(void)
load_unload = *(*player->argp + 1) == 'l' ? LOAD : UNLOAD; load_unload = *(*player->argp + 1) == 'l' ? LOAD : UNLOAD;
nbst.flags &= ~(EFF_OWNER);
nunits = 0; nunits = 0;
while (nxtitem(&nbst, (s_char *)&land)) { while (nxtitem(&nbst, (s_char *)&land)) {
if (land.lnd_own == 0) if (land.lnd_own == 0)

View file

@ -103,7 +103,7 @@ ltend(void)
if (!check_ship_ok(&tender)) if (!check_ship_ok(&tender))
return RET_FAIL; return RET_FAIL;
total = 0; total = 0;
while (tend_nxtitem(&targets, (s_char *)&target)) { while (nxtitem(&targets, (s_char *)&target)) {
if (!player->owner) if (!player->owner)
continue; continue;

View file

@ -46,7 +46,6 @@ pboa(void)
if (!snxtitem(&np, EF_PLANE, player->argp[1])) if (!snxtitem(&np, EF_PLANE, player->argp[1]))
return RET_SYN; return RET_SYN;
np.flags = 0;
while (nxtitem(&np, (s_char *)&plane)) { while (nxtitem(&np, (s_char *)&plane)) {
getsect(plane.pln_x, plane.pln_y, &sect); getsect(plane.pln_x, plane.pln_y, &sect);
if (sect.sct_own != player->cnum) if (sect.sct_own != player->cnum)

View file

@ -133,7 +133,7 @@ tend(void)
if (!check_ship_ok(&tender)) if (!check_ship_ok(&tender))
return RET_SYN; return RET_SYN;
total = 0; total = 0;
while (tend_nxtitem(&targets, (s_char *)&target)) { while (nxtitem(&targets, &target)) {
if (!player->owner && if (!player->owner &&
(getrel(getnatp(target.shp_own), player->cnum) < FRIENDLY)) (getrel(getnatp(target.shp_own), player->cnum) < FRIENDLY))
continue; continue;
@ -197,81 +197,6 @@ expose_ship(struct shpstr *s1, struct shpstr *s2)
s1->shp_pstage = PLG_EXPOSED; s1->shp_pstage = PLG_EXPOSED;
} }
/*
* tend_nxtitem.c
*
* get next item from list. Stolen from nxtitem to make 1 itsy-bitsy change
*
* Dave Pare, 1989
*/
int
tend_nxtitem(struct nstr_item *np, void *ptr)
{
struct genitem *gp;
int selected;
if (np->sel == NS_UNDEF)
return 0;
gp = (struct genitem *)ptr;
do {
if (np->sel == NS_LIST) {
np->index++;
if (np->index >= np->size)
return 0;
np->cur = np->list[np->index];
} else {
np->cur++;
}
if (!np->read(np->type, np->cur, ptr)) {
/* if read fails, fatal */
return 0;
}
selected = 1;
switch (np->sel) {
case NS_LIST:
/* The change is to take the player->owner check out here */
break;
case NS_ALL:
/* XXX maybe combine NS_LIST and NS_ALL later */
break;
case NS_DIST:
if (!xyinrange(gp->x, gp->y, &np->range)) {
selected = 0;
break;
}
np->curdist = mapdist((int)gp->x, (int)gp->y,
(int)np->cx, (int)np->cy);
if (np->curdist > np->dist)
selected = 0;
break;
case NS_AREA:
if (!xyinrange(gp->x, gp->y, &np->range))
selected = 0;
if (gp->x == np->range.hx || gp->y == np->range.hy)
selected = 0;
break;
case NS_XY:
if (gp->x != np->cx || gp->y != np->cy)
selected = 0;
break;
case NS_GROUP:
if (np->group != gp->group)
selected = 0;
break;
default:
CANT_HAPPEN("bad np->sel");
return 0;
}
if (selected && np->ncond) {
/* nstr_exec is expensive, so we do it last */
if (!nstr_exec(np->cond, np->ncond, ptr))
selected = 0;
}
} while (!selected);
return 1;
}
static int static int
tend_land(struct shpstr *tenderp, s_char *units) tend_land(struct shpstr *tenderp, s_char *units)
{ {
@ -303,7 +228,7 @@ tend_land(struct shpstr *tenderp, s_char *units)
break; break;
if (!check_land_ok(&land)) if (!check_land_ok(&land))
return RET_SYN; return RET_SYN;
while (tend_nxtitem(&targets, (s_char *)&target)) { while (nxtitem(&targets, &target)) {
if (!player->owner && if (!player->owner &&
(getrel(getnatp(target.shp_own), player->cnum) < FRIENDLY)) (getrel(getnatp(target.shp_own), player->cnum) < FRIENDLY))
continue; continue;

View file

@ -94,7 +94,6 @@ lupgr(void)
if (!snxtitem(&ni, EF_LAND, player->argp[2])) if (!snxtitem(&ni, EF_LAND, player->argp[2]))
return RET_SYN; return RET_SYN;
ni.flags &= ~(EFF_OWNER);
natp = getnatp(player->cnum); natp = getnatp(player->cnum);
cash = natp->nat_money; cash = natp->nat_money;
tlev = (int)natp->nat_level[NAT_TLEV]; tlev = (int)natp->nat_level[NAT_TLEV];
@ -178,7 +177,6 @@ supgr(void)
if (!snxtitem(&ni, EF_SHIP, player->argp[2])) if (!snxtitem(&ni, EF_SHIP, player->argp[2]))
return RET_SYN; return RET_SYN;
ni.flags &= ~(EFF_OWNER);
natp = getnatp(player->cnum); natp = getnatp(player->cnum);
cash = natp->nat_money; cash = natp->nat_money;
tlev = (int)natp->nat_level[NAT_TLEV]; tlev = (int)natp->nat_level[NAT_TLEV];
@ -261,7 +259,6 @@ pupgr(void)
if (!snxtitem(&ni, EF_PLANE, player->argp[2])) if (!snxtitem(&ni, EF_PLANE, player->argp[2]))
return RET_SYN; return RET_SYN;
ni.flags &= ~(EFF_OWNER);
natp = getnatp(player->cnum); natp = getnatp(player->cnum);
cash = natp->nat_money; cash = natp->nat_money;
tlev = (int)natp->nat_level[NAT_TLEV]; tlev = (int)natp->nat_level[NAT_TLEV];

View file

@ -65,15 +65,9 @@ nxtitem(struct nstr_item *np, void *ptr)
} }
selected = 1; selected = 1;
switch (np->sel) { switch (np->sel) {
/*
* This one won't work unless you're running in emp_player
*/
case NS_LIST: case NS_LIST:
if ((np->flags & EFF_OWNER) && !player->owner)
selected = 0;
break; break;
case NS_ALL: case NS_ALL:
/* XXX maybe combine NS_LIST and NS_ALL later */
break; break;
case NS_DIST: case NS_DIST:
if (!xyinrange(gp->x, gp->y, &np->range)) { if (!xyinrange(gp->x, gp->y, &np->range)) {