]> git.pond.sub.org Git - empserver/commitdiff
Use relations_with() for US==THEM || getrel(getnatp(US), THEM)
authorMarkus Armbruster <armbru@redhat.com>
Wed, 26 Jan 2011 18:41:28 +0000 (19:41 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Wed, 16 Feb 2011 06:51:39 +0000 (07:51 +0100)
Replacing getrel(getnatp(US), THEM) by relations_with(US, THEM) makes
a difference only when US equals THEM.

Replace patterns like "us == them || getrel(getnatp(us), them)..." by
"relations_with(us, them)...".

13 files changed:
src/lib/commands/drop.c
src/lib/commands/foll.c
src/lib/commands/scut.c
src/lib/commands/shar.c
src/lib/commands/upgr.c
src/lib/subs/list.c
src/lib/subs/lndsub.c
src/lib/subs/plnsub.c
src/lib/subs/retreat.c
src/lib/subs/shpsub.c
src/lib/update/land.c
src/lib/update/plane.c
src/lib/update/ship.c

index fbe78f4516a1e40b1459d6f6411fc656645afe19..1ed7facd74f3916f61c95ed49537991df6cabe96 100644 (file)
@@ -74,8 +74,7 @@ drop(void)
        return RET_SYN;
     getsect(tx, ty, &target);
 
-    if (target.sct_own == player->cnum
-       || getrel(getnatp(target.sct_own), player->cnum) == ALLIED) {
+    if (relations_with(target.sct_own, player->cnum) == ALLIED) {
        /* own or allied sector: cargo drop */
        if (ip->i_uid == I_CIVIL && target.sct_own != target.sct_oldown) {
            pr("Can't drop civilians into occupied sectors.\n");
index 0e95bc23a9a4371301fccfe32d0cd6f2f3320f89..246494771a08044e543e9e8cb5c5f5e5c0dafe2e 100644 (file)
@@ -60,8 +60,7 @@ foll(void)
     if (!good)
        return RET_SYN;
     getship(leader, &ship);
-    if (ship.shp_own != player->cnum &&
-       getrel(getnatp(ship.shp_own), player->cnum) < FRIENDLY) {
+    if (relations_with(ship.shp_own, player->cnum) < FRIENDLY) {
        pr("That ship won't let you follow.\n");
        return RET_FAIL;
     }
index 570cb89aa6427de7d54db94c1482bd285c793efb..ce9c6146b36974cfd1cb43d1b59820ae8648e2cb 100644 (file)
@@ -165,8 +165,7 @@ scuttle_tradeship(struct shpstr *sp, int interactive)
     mp = &mchr[(int)sp->shp_type];
     getsect(sp->shp_x, sp->shp_y, &sect);
     if (sect.sct_own && sect.sct_type == SCT_HARBR && sect.sct_effic >= 2
-       && (sect.sct_own == sp->shp_own
-           || getrel(getnatp(sect.sct_own), sp->shp_own) >= FRIENDLY)) {
+       && relations_with(sect.sct_own, sp->shp_own) >= FRIENDLY) {
        dist = mapdist(sp->shp_x, sp->shp_y,
                       sp->shp_orig_x, sp->shp_orig_y);
        /* Don't disclose distance to to pirates */
index 4f2190181bf545ea6e934d3c0463057054bba999..8d90019d4895bb21c4a8a3fea2d28b41b2f2f786 100644 (file)
@@ -47,7 +47,7 @@ shar(void)
     if (to < 0)
        return RET_SYN;
 
-    if (to != player->cnum && getrel(getnatp(to), player->cnum) < FRIENDLY) {
+    if (relations_with(to, player->cnum) < FRIENDLY) {
        pr("%s does not have friendly relations towards you\n", cname(to));
        return RET_FAIL;
     }
index 33278ff8c87c1efbc227e88046a6e63eddddcc27..960e04131e319bce3b46ac2695aca90983d73d10 100644 (file)
@@ -100,8 +100,7 @@ lupgr(void)
            continue;
        if (sect.sct_type != SCT_HEADQ || sect.sct_effic < 60)
            continue;
-       if (land.lnd_own != sect.sct_own
-           && getrel(getnatp(land.lnd_own), sect.sct_own) < FRIENDLY) {
+       if (relations_with(land.lnd_own, sect.sct_own) < FRIENDLY) {
            pr("You are not on friendly terms with the owner of unit %d!\n",
               land.lnd_uid);
            continue;
@@ -181,8 +180,7 @@ supgr(void)
            continue;
        if (sect.sct_type != SCT_HARBR || sect.sct_effic < 60)
            continue;
-       if (ship.shp_own != sect.sct_own
-           && getrel(getnatp(ship.shp_own), sect.sct_own) < FRIENDLY) {
+       if (relations_with(ship.shp_own, sect.sct_own) < FRIENDLY) {
            pr("You are not on friendly terms with the owner of ship %d!\n",
               ship.shp_uid);
            continue;
@@ -261,8 +259,7 @@ pupgr(void)
            continue;
        if (sect.sct_type != SCT_AIRPT || sect.sct_effic < 60)
            continue;
-       if (plane.pln_own != sect.sct_own
-           && getrel(getnatp(plane.pln_own), sect.sct_own) < FRIENDLY) {
+       if (relations_with(plane.pln_own, sect.sct_own) < FRIENDLY) {
            pr("You are not on friendly terms with the owner of plane %d!\n",
               plane.pln_uid);
            continue;
index 781011e56706258817ab8948113364f25d038b21..d18e61ba4eb1ba5f3f1238a981a18020d2bf37e5 100644 (file)
@@ -102,8 +102,7 @@ carriersatxy(coord x, coord y, natid own)
     while (nxtitem(&ni, &ship)) {
        if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
            continue;
-       if (ship.shp_own != own
-           && getrel(getnatp(ship.shp_own), own) != ALLIED)
+       if (relations_with(ship.shp_own, own) != ALLIED)
            continue;
        if ((carrier_planes(&ship, 0) & (P_L | P_K)) == 0)
            continue;
index d7218c32f66899dce154d27179fee0ba70ca2bf1..c6bc433607feb1551e12df973ae8273a68562f00 100644 (file)
@@ -501,8 +501,7 @@ lnd_mar(struct emp_qelem *list, double *minmobp, double *maxmobp,
            lnd_stays(actor, "has no mil on it to guide it", llp);
            continue;
        }
-       if (sect.sct_own != actor &&
-           getrel(getnatp(sect.sct_own), actor) != ALLIED &&
+       if (relations_with(sect.sct_own, actor) != ALLIED &&
            !(lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY) &&
            sect.sct_own) {
            sprintf(mess, "has been kidnapped by %s", cname(sect.sct_own));
@@ -782,8 +781,7 @@ lnd_fort_interdiction(struct emp_qelem *list,
     while (nxtsct(&ns, &fsect)) {
        if (fsect.sct_own == 0)
            continue;
-       if (fsect.sct_own == victim
-           || getrel(getnatp(fsect.sct_own), victim) >= NEUTRAL)
+       if (relations_with(fsect.sct_own, victim) >= NEUTRAL)
            continue;
        range = roundrange(fortrange(&fsect));
        trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
@@ -1170,7 +1168,7 @@ has_helpful_engineer(coord x, coord y, natid cn)
 
     snxtitem_xy(&ni, EF_LAND, x, y);
     while (nxtitem(&ni, &land)) {
-       if (land.lnd_own != cn && getrel(getnatp(land.lnd_own), cn) != ALLIED)
+       if (relations_with(land.lnd_own, cn) != ALLIED)
            continue;
        if (lchr[(int)land.lnd_type].l_flags & L_ENGINEER)
            return 1;
index 5e7e8023b1e272a33b1d881e87998557a47372e5..ed15058c91f35974ed4c6afe3708fe81425658de 100644 (file)
@@ -102,8 +102,7 @@ get_assembly_point(char *input, struct sctstr *ap_sect, char *buf)
        return NULL;
 
     /* over own or allied sector is fine */
-    if (ap_sect->sct_own == player->cnum
-       || getrel(getnatp(ap_sect->sct_own), player->cnum) == ALLIED)
+    if (relations_with(ap_sect->sct_own, player->cnum) == ALLIED)
        return ap_sect;
 
     /* over own or allied ship is fine */
@@ -111,8 +110,7 @@ get_assembly_point(char *input, struct sctstr *ap_sect, char *buf)
     while (nxtitem(&ni, &ship)) {
        if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
            continue;
-       if (ship.shp_own == player->cnum
-           || getrel(getnatp(ship.shp_own), player->cnum) == ALLIED)
+       if (relations_with(ship.shp_own, player->cnum) == ALLIED)
            return ap_sect;
     }
 
@@ -170,8 +168,7 @@ pln_onewaymission(struct sctstr *target, int *shipno, int *flagp)
     }
 
     /* try to land at sector */
-    if (target->sct_own != player->cnum
-       && getrel(getnatp(target->sct_own), player->cnum) != ALLIED) {
+    if (relations_with(target->sct_own, player->cnum) != ALLIED) {
        pr("Nowhere to land at sector %s!\n",
           xyas(target->sct_x, target->sct_y, player->cnum));
        return -1;
@@ -285,8 +282,7 @@ pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty,
                pr("Your %s vanish without a trace.\n", ip->i_name);
            return;
        }
-       if (sect.sct_own != player->cnum
-           && getrel(getnatp(sect.sct_own), player->cnum) != ALLIED) {
+       if (relations_with(sect.sct_own, player->cnum) != ALLIED) {
            pr("You don't own %s!  Cargo jettisoned...\n",
               xyas(tx, ty, player->cnum));
            return;
@@ -461,8 +457,7 @@ pln_airbase_ok(struct plnstr *pp, int oneway, int noisy)
            CANT_REACH();
            return 0;
        }
-       if (ship.shp_own != pp->pln_own
-           && getrel(getnatp(ship.shp_own), pp->pln_own) != ALLIED) {
+       if (relations_with(ship.shp_own, pp->pln_own) != ALLIED) {
            if (noisy)
                pr("(note) An ally does not own the ship %s is on\n",
                   prplane(pp));
@@ -477,8 +472,7 @@ pln_airbase_ok(struct plnstr *pp, int oneway, int noisy)
            CANT_REACH();
            return 0;
        }
-       if (land.lnd_own != pp->pln_own
-           && getrel(getnatp(land.lnd_own), pp->pln_own) != ALLIED) {
+       if (relations_with(land.lnd_own, pp->pln_own) != ALLIED) {
            if (noisy)
                pr("(note) An ally does not own the unit %s is on\n",
                   prplane(pp));
@@ -496,8 +490,7 @@ pln_airbase_ok(struct plnstr *pp, int oneway, int noisy)
            return 0;
        }
 
-       if (sect.sct_own != pp->pln_own
-           && getrel(getnatp(sect.sct_own), pp->pln_own) != ALLIED) {
+       if (relations_with(sect.sct_own, pp->pln_own) != ALLIED) {
            if (noisy)
                pr("(note) An ally does not own the sector %s is in\n",
                   prplane(pp));
index 75c6d984c4e8aeab146c1381d35e2c81e92fe93c..09b53a0e97ab8df645d8c1fda7c53503c12b3b76 100644 (file)
@@ -249,8 +249,8 @@ retreat_ship1(struct shpstr *sp, char code, int orig)
 
        getsect(newx, newy, &sect);
        if (shp_check_nav(&sect, sp) != CN_NAVIGABLE ||
-           (sect.sct_own && sect.sct_own != sp->shp_own &&
-            getrel(getnatp(sect.sct_own), sp->shp_own) < FRIENDLY)) {
+           (sect.sct_own
+            && relations_with(sect.sct_own, sp->shp_own) < FRIENDLY)) {
            wu(0, sp->shp_own, "%s %s,\nbut could not retreat to %s!\n",
               prship(sp), conditions[findcondition(code)].desc[orig],
               xyas(newx, newy, sp->shp_own));
index 07fe00b297a661b8880efe43ffd94da364065d7f..5883d2ba59e3bac417a50df5a4009983256f61e7 100644 (file)
@@ -750,8 +750,7 @@ shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor,
        navigate = shp_check_nav(&sect, &mlp->unit.ship);
        if (navigate != CN_NAVIGABLE ||
            (sect.sct_own
-            && sect.sct_own != actor
-            && getrel(getnatp(sect.sct_own), actor) < FRIENDLY)) {
+            && relations_with(sect.sct_own, actor) < FRIENDLY)) {
            if (dchr[sect.sct_type].d_nav == NAV_CANAL &&
                !(((struct mchrstr *)mlp->chrp)->m_flags & M_CANAL) &&
                navigate == CN_LANDLOCKED)
index 6fedf64e2d2e28195a16b8c0a2818b1d6b8d7872..90d02e600092fe0fd9a817f5c410b75419538930 100644 (file)
@@ -224,8 +224,7 @@ landrepair(struct lndstr *land, struct natstr *np, struct bp *bp, int etus)
        /* land is ok; no repairs needed */
        return;
     }
-    if ((sp->sct_own != land->lnd_own) &&
-       (getrel(getnatp(sp->sct_own), land->lnd_own) != ALLIED))
+    if (relations_with(sp->sct_own, land->lnd_own) != ALLIED)
        return;
 
     if (!player->simulation)
index 1269447f4e650f9b9550332010812ab14ef786b8..f6a1c7900f335bbbcea3198da702d2b326cef760 100644 (file)
@@ -148,12 +148,10 @@ planerepair(struct plnstr *pp, struct natstr *np, struct bp *bp, int etus)
            return;
        if (carrier->shp_off)
            return;
-       if ((carrier->shp_own != pp->pln_own) &&
-           (getrel(getnatp(carrier->shp_own), pp->pln_own) != ALLIED))
+       if (relations_with(carrier->shp_own, pp->pln_own) != ALLIED)
            return;
     } else {
-       if ((sp->sct_own != pp->pln_own) &&
-           (getrel(getnatp(sp->sct_own), pp->pln_own) != ALLIED))
+       if (relations_with(sp->sct_own, pp->pln_own) != ALLIED)
            return;
     }
 
index 39f22c0e2e115bf1227e79aa42a24c5497eae9ba..2feff43642320806c4bb6a5814c5ba6e85b876d1 100644 (file)
@@ -268,8 +268,7 @@ shiprepair(struct shpstr *ship, struct natstr *np, struct bp *bp, int etus)
     sp = getsectp(ship->shp_x, ship->shp_y);
 
     if (sp->sct_own != 0
-       && sp->sct_own != ship->shp_own
-       && getrel(getnatp(sp->sct_own), ship->shp_own) < FRIENDLY)
+       && relations_with(sp->sct_own, ship->shp_own) < FRIENDLY)
        return;
 
     /* only military can work on a military boat */