Use relations_with() for getrel(getnatp(US), THEM) where US!=THEM
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 29 Jan 2011 13:34:40 +0000 (14:34 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Wed, 16 Feb 2011 06:52:25 +0000 (07:52 +0100)
Replacing getrel(getnatp(US), THEM) by relations_with(US, THEM) makes
a difference only when US equals THEM.  Replace in places where it's
obvious that they're not equal.

Note: getsect() sets player->owner to "player is god or owns this
sector".  Thus, after getsect(..., &sect), sect.sct_own ==
player->cnum implies player->owner.  Conversely, !player->owner
implies sect.sct_own != player->cnum.  Similarly for getship(),
getplane() and nxtitem().

src/lib/commands/arm.c
src/lib/commands/assa.c
src/lib/commands/atta.c
src/lib/commands/load.c
src/lib/commands/scra.c
src/lib/commands/sona.c
src/lib/commands/spy.c
src/lib/commands/tend.c
src/lib/subs/fortdef.c
src/lib/subs/plnsub.c

index b3d37594a0fd7ba29fd2161b942e816c21f89e4f..19d879a17eb867b88c4fa0446940132c39fb3593 100644 (file)
@@ -59,7 +59,7 @@ arm(void)
        return RET_SYN;
     while (nxtitem(&ni, &pl)) {
        if (!player->owner
-           && getrel(getnatp(pl.pln_own), player->cnum) != ALLIED)
+           && relations_with(pl.pln_own, player->cnum) != ALLIED)
            continue;
        plc = &plchr[(int)pl.pln_type];
        if ((plc->pl_flags & (P_O | P_N | P_MAR))
@@ -150,7 +150,7 @@ disarm(void)
        }
        getsect(nuke.nuk_x, nuke.nuk_y, &sect);
        if (!player->owner
-           && getrel(getnatp(sect.sct_own), player->cnum) != ALLIED) {
+           && relations_with(sect.sct_own, player->cnum) != ALLIED) {
            pr("Disarming %s in sector %s requires an alliance!\n",
               prplane(&pl), xyas(sect.sct_x, sect.sct_y, player->cnum));
            continue;
index 9fbd30e2f8ab43600379ec193e9cab797220f7f7..e40a187af290d2e57b0d98772d6c707323d5c36c 100644 (file)
@@ -164,7 +164,7 @@ assa(void)
        for (qp = olist.q_forw; qp != &olist; qp = next) {
            next = qp->q_forw;
            llp = (struct ulist *)qp;
-           rel = getrel(getnatp(def->own), player->cnum);
+           rel = relations_with(def->own, player->cnum);
            if (chance(0.10) || rel == ALLIED || !def->own) {
                pr("%s made it on shore safely.\n", prland(&llp->unit.land));
                llp->unit.land.lnd_x = def->x;
index c993fd636c5951d14a7fe2d2a50de3c23dbea4a9..f7faa96e28860964d7ddef379cbcd3e29ffbe45c 100644 (file)
@@ -95,7 +95,7 @@ atta(void)
        newy = def->y + diroff[n + 1][1];
        getsect(newx, newy, &sect);     /* incase cross world boundary */
        if (!player->owner
-           && getrel(getnatp(sect.sct_own), player->cnum) != ALLIED)
+           && relations_with(sect.sct_own, player->cnum) != ALLIED)
            continue;
        att_combat_init(&off[++last], EF_SECTOR);
        off[last].x = sect.sct_x;
index 4e46212a98cca224b17edd63bc483b05a4f041be..0e8bea59816cc92f5b93d6191e5101c3189c5d8e 100644 (file)
@@ -117,7 +117,7 @@ load(void)
        if (!player->owner) {
            if (load_unload == UNLOAD || !noisy)
                continue;
-           if (getrel(getnatp(ship.shp_own), player->cnum) < FRIENDLY)
+           if (relations_with(ship.shp_own, player->cnum) < FRIENDLY)
                continue;
        }
 
@@ -145,7 +145,7 @@ load(void)
        }
        if (load_unload == UNLOAD
            && !player->owner
-           && getrel(getnatp(sect.sct_own), player->cnum) < FRIENDLY) {
+           && relations_with(sect.sct_own, player->cnum) < FRIENDLY) {
            if (noisy)
                pr("You can't unload into an unfriendly %s\n",
                   dchr[sect.sct_type].d_name);
@@ -251,7 +251,7 @@ lload(void)
        if (!player->owner) {
            if (load_unload == UNLOAD || !noisy)
                continue;
-           if (getrel(getnatp(land.lnd_own), player->cnum) != ALLIED)
+           if (relations_with(land.lnd_own, player->cnum) != ALLIED)
                continue;
        }
 
@@ -266,7 +266,7 @@ lload(void)
                       xyas(sect.sct_x, sect.sct_y, player->cnum));
                continue;
            }
-           if (getrel(getnatp(sect.sct_own), player->cnum) != ALLIED) {
+           if (relations_with(sect.sct_own, player->cnum) != ALLIED) {
                pr("Sector %s is not yours.\n",
                   xyas(sect.sct_x, sect.sct_y, player->cnum));
                continue;
index 1528873aa07987a4ef8eb951df3209f21bf27e30..5bad10aff960101e4f0633fe32704bc638ce5ea0 100644 (file)
@@ -135,7 +135,7 @@ scra(void)
        getsect(item.gen.x, item.gen.y, &sect);
        if (type == EF_SHIP) {
            if (!player->owner
-               && getrel(getnatp(sect.sct_own), player->cnum) < FRIENDLY) {
+               && relations_with(sect.sct_own, player->cnum) < FRIENDLY) {
                pr("%s is not in a friendly harbor!\n",
                   prship(&item.ship));
                continue;
@@ -158,7 +158,7 @@ scra(void)
            }
        } else {
            if (!player->owner
-               && getrel(getnatp(sect.sct_own), player->cnum) != ALLIED) {
+               && relations_with(sect.sct_own, player->cnum) != ALLIED) {
                pr("%s is not in an allied sector!\n",
                   obj_nameof(&item.gen));
                continue;
index f38e8a6c13439ac273ce745eb69be104629da261..7e7e6d2f014dd7cf2abce18eb13c7885e1a355a4 100644 (file)
@@ -173,7 +173,7 @@ sona(void)
            if (rad[y][x] != dchr[SCT_WATER].d_mnem && rad[y][x] != 'X')
                continue;
            if (tmcp->m_flags & M_SUB &&
-               getrel(getnatp(targ.shp_own), player->cnum) < FRIENDLY) {
+               relations_with(targ.shp_own, player->cnum) < FRIENDLY) {
                if (mcp->m_vrnge + visib < 8)
                    pr("Sonar detects sub #%d @ %s\n",
                       targ.shp_uid,
@@ -275,7 +275,7 @@ plane_sona(struct emp_qelem *plane_list, int x, int y,
                pr("Sonar contact in %s\n", xyas(x, y, player->cnum));
                found = 1;
            }
-           if (getrel(getnatp(targ->shp_own), pp->pln_own) < FRIENDLY &&
+           if (relations_with(targ->shp_own, pp->pln_own) < FRIENDLY &&
                roll(100) > pln_identchance(pp, shp_hardtarget(targ),
                                            EF_SHIP))
                if (roll(100) > pln_identchance(pp, shp_hardtarget(targ),
index 721de2ddd9c1d31b46a9353b09380f22a1df694e..2a7ec53bd4de1220e01bdc244e08a1b51b460c0a 100644 (file)
@@ -129,7 +129,7 @@ spy(void)
                continue;
 
            own = dsect.sct_own;
-           relat = getrel(getnatp(own), player->cnum);
+           relat = relations_with(own, player->cnum);
            if (relat <= NEUTRAL
                && chance(dsect.sct_item[I_MILIT] / 200.0)) {
                /* spy caught */
index 13856384d1503638584b39563a9ebca449e16fa3..1bd33e7b5e1cdee4c6ddfdc5441cab056500618a 100644 (file)
@@ -134,8 +134,8 @@ tend(void)
            return RET_SYN;
        total = 0;
        while (nxtitem(&targets, &target)) {
-           if (!player->owner &&
-               (getrel(getnatp(target.shp_own), player->cnum) < FRIENDLY))
+           if (!player->owner
+               && relations_with(target.shp_own, player->cnum) < FRIENDLY)
                continue;
            if (target.shp_uid == tender.shp_uid)
                continue;
@@ -232,8 +232,8 @@ tend_land(struct shpstr *tenderp, char *units)
        if (!check_ship_ok(tenderp) || !check_land_ok(&land))
            return RET_SYN;
        while (nxtitem(&targets, &target)) {
-           if (!player->owner &&
-               (getrel(getnatp(target.shp_own), player->cnum) < FRIENDLY))
+           if (!player->owner
+               && relations_with(target.shp_own, player->cnum) < FRIENDLY)
                continue;
            if (target.shp_uid == tenderp->shp_uid)
                continue;
index c67173a91c4e12c99a4ee45d01f1ddbeba710710..26062734b863aece108c1b64abf3aefe583c36ec 100644 (file)
@@ -159,8 +159,8 @@ feels_like_helping(natid cn, natid friend, natid foe)
     if (cn == friend)
        return 1;               /* help self against anybody else */
     /* third party helps ally if at war with foe: */
-    return getrel(getnatp(cn), friend) == ALLIED
-       && getrel(getnatp(cn), foe) == AT_WAR;
+    return relations_with(cn, friend) == ALLIED
+       && relations_with(cn, foe) == AT_WAR;
 }
 
 /* Shoot back
index ed15058c91f35974ed4c6afe3708fe81425658de..c4c1a13e5536bbc6b071c43b9ce10f328b1edf6f 100644 (file)
@@ -143,7 +143,7 @@ pln_onewaymission(struct sctstr *target, int *shipno, int *flagp)
            if (cno < 0
                || !getship(cno, &ship)
                || (!player->owner
-                   && (getrel(getnatp(ship.shp_own), player->cnum)
+                   && (relations_with(ship.shp_own, player->cnum)
                        != ALLIED))) {
                pr("Not yours\n");
                continue;