]> git.pond.sub.org Git - empserver/commitdiff
(nxtitem): Skipped unowned sectors (could not occur), ships, planes,
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 29 May 2005 13:15:56 +0000 (13:15 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 29 May 2005 13:15:56 +0000 (13:15 +0000)
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
src/lib/commands/load.c
src/lib/commands/lten.c
src/lib/commands/pboa.c
src/lib/commands/tend.c
src/lib/commands/upgr.c
src/lib/subs/nxtitem.c

index d32bcf661a8358b4923757c3d33865d30dab7e0e..d3febff171bcdf79ee591a3f841d1731a5bba84a 100644 (file)
@@ -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) {
index 7c5fb81041ca7e80ef3c37ae056c083e1c77b23b..fc09e5627891c094ebb525dfb988508ef3a093a7 100644 (file)
@@ -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)
index 87f114f070494762220d705ce74791f4a824cc9d..bbce046120c587cd7da5393200eb4d004479633f 100644 (file)
@@ -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;
 
index 1957a91373b6347516f6545247d050272d48d8fe..b95a9de2f79245b907cb64b9f1e654b6a65142d5 100644 (file)
@@ -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, &sect);
        if (sect.sct_own != player->cnum)
index 6300dd36c5c0fba48353ad565c4a35a6bc9d0e65..5223a30a6a049af4a759e16f161c6bc8d546e309 100644 (file)
@@ -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;
index e3543bf64633c5231fa113359424ed426f6c6163..c1ddd72ae46bc3fc359d7c6fb14f0312a952a198 100644 (file)
@@ -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];
index 30c2f5d331e9c4783bddcb91e85df7c8d991d849..9297c573ae88941c8dfe02d5f3883d89da6dfb29 100644 (file)
@@ -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)) {