From b111abc2c5a99f30ba39a58b29112e70e980d8f0 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sun, 29 May 2005 13:15:56 +0000 Subject: [PATCH] (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(). --- src/lib/commands/fuel.c | 2 -- src/lib/commands/load.c | 4 --- src/lib/commands/lten.c | 2 +- src/lib/commands/pboa.c | 1 - src/lib/commands/tend.c | 79 ++--------------------------------------- src/lib/commands/upgr.c | 3 -- src/lib/subs/nxtitem.c | 6 ---- 7 files changed, 3 insertions(+), 94 deletions(-) diff --git a/src/lib/commands/fuel.c b/src/lib/commands/fuel.c index d32bcf66..d3febff1 100644 --- a/src/lib/commands/fuel.c +++ b/src/lib/commands/fuel.c @@ -102,8 +102,6 @@ fuel(void) return RET_FAIL; } - ni.flags &= ~(EFF_OWNER); - while (nxtitem(&ni, (s_char *)&item)) { fueled = 0; if (type == EF_SHIP) { diff --git a/src/lib/commands/load.c b/src/lib/commands/load.c index 7c5fb810..fc09e562 100644 --- a/src/lib/commands/load.c +++ b/src/lib/commands/load.c @@ -109,8 +109,6 @@ load(void) if (!snxtitem(&nbst, EF_SHIP, p)) return RET_SYN; - nbst.flags &= ~(EFF_OWNER); - load_unload = **player->argp == 'l' ? LOAD : UNLOAD; nships = 0; @@ -251,8 +249,6 @@ lload(void) load_unload = *(*player->argp + 1) == 'l' ? LOAD : UNLOAD; - nbst.flags &= ~(EFF_OWNER); - nunits = 0; while (nxtitem(&nbst, (s_char *)&land)) { if (land.lnd_own == 0) diff --git a/src/lib/commands/lten.c b/src/lib/commands/lten.c index 87f114f0..bbce0461 100644 --- a/src/lib/commands/lten.c +++ b/src/lib/commands/lten.c @@ -103,7 +103,7 @@ ltend(void) if (!check_ship_ok(&tender)) return RET_FAIL; total = 0; - while (tend_nxtitem(&targets, (s_char *)&target)) { + while (nxtitem(&targets, (s_char *)&target)) { if (!player->owner) continue; diff --git a/src/lib/commands/pboa.c b/src/lib/commands/pboa.c index 1957a913..b95a9de2 100644 --- a/src/lib/commands/pboa.c +++ b/src/lib/commands/pboa.c @@ -46,7 +46,6 @@ pboa(void) if (!snxtitem(&np, EF_PLANE, player->argp[1])) return RET_SYN; - np.flags = 0; while (nxtitem(&np, (s_char *)&plane)) { getsect(plane.pln_x, plane.pln_y, §); if (sect.sct_own != player->cnum) diff --git a/src/lib/commands/tend.c b/src/lib/commands/tend.c index 6300dd36..5223a30a 100644 --- a/src/lib/commands/tend.c +++ b/src/lib/commands/tend.c @@ -133,7 +133,7 @@ tend(void) if (!check_ship_ok(&tender)) return RET_SYN; total = 0; - while (tend_nxtitem(&targets, (s_char *)&target)) { + while (nxtitem(&targets, &target)) { if (!player->owner && (getrel(getnatp(target.shp_own), player->cnum) < FRIENDLY)) continue; @@ -197,81 +197,6 @@ expose_ship(struct shpstr *s1, struct shpstr *s2) 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 tend_land(struct shpstr *tenderp, s_char *units) { @@ -303,7 +228,7 @@ tend_land(struct shpstr *tenderp, s_char *units) break; if (!check_land_ok(&land)) return RET_SYN; - while (tend_nxtitem(&targets, (s_char *)&target)) { + while (nxtitem(&targets, &target)) { if (!player->owner && (getrel(getnatp(target.shp_own), player->cnum) < FRIENDLY)) continue; diff --git a/src/lib/commands/upgr.c b/src/lib/commands/upgr.c index e3543bf6..c1ddd72a 100644 --- a/src/lib/commands/upgr.c +++ b/src/lib/commands/upgr.c @@ -94,7 +94,6 @@ lupgr(void) if (!snxtitem(&ni, EF_LAND, player->argp[2])) return RET_SYN; - ni.flags &= ~(EFF_OWNER); natp = getnatp(player->cnum); cash = natp->nat_money; tlev = (int)natp->nat_level[NAT_TLEV]; @@ -178,7 +177,6 @@ supgr(void) if (!snxtitem(&ni, EF_SHIP, player->argp[2])) return RET_SYN; - ni.flags &= ~(EFF_OWNER); natp = getnatp(player->cnum); cash = natp->nat_money; tlev = (int)natp->nat_level[NAT_TLEV]; @@ -261,7 +259,6 @@ pupgr(void) if (!snxtitem(&ni, EF_PLANE, player->argp[2])) return RET_SYN; - ni.flags &= ~(EFF_OWNER); natp = getnatp(player->cnum); cash = natp->nat_money; tlev = (int)natp->nat_level[NAT_TLEV]; diff --git a/src/lib/subs/nxtitem.c b/src/lib/subs/nxtitem.c index 30c2f5d3..9297c573 100644 --- a/src/lib/subs/nxtitem.c +++ b/src/lib/subs/nxtitem.c @@ -65,15 +65,9 @@ nxtitem(struct nstr_item *np, void *ptr) } selected = 1; switch (np->sel) { - /* - * This one won't work unless you're running in emp_player - */ case NS_LIST: - if ((np->flags & EFF_OWNER) && !player->owner) - selected = 0; 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)) {