From 8cb7b755574f67e43d752fb46cf090ee6d23177a Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 29 Jan 2011 14:34:40 +0100 Subject: [PATCH] Use relations_with() for getrel(getnatp(US), THEM) where US!=THEM 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.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 | 4 ++-- src/lib/commands/assa.c | 2 +- src/lib/commands/atta.c | 2 +- src/lib/commands/load.c | 8 ++++---- src/lib/commands/scra.c | 4 ++-- src/lib/commands/sona.c | 4 ++-- src/lib/commands/spy.c | 2 +- src/lib/commands/tend.c | 8 ++++---- src/lib/subs/fortdef.c | 4 ++-- src/lib/subs/plnsub.c | 2 +- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/lib/commands/arm.c b/src/lib/commands/arm.c index b3d37594a..19d879a17 100644 --- a/src/lib/commands/arm.c +++ b/src/lib/commands/arm.c @@ -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, §); 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; diff --git a/src/lib/commands/assa.c b/src/lib/commands/assa.c index 9fbd30e2f..e40a187af 100644 --- a/src/lib/commands/assa.c +++ b/src/lib/commands/assa.c @@ -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; diff --git a/src/lib/commands/atta.c b/src/lib/commands/atta.c index c993fd636..f7faa96e2 100644 --- a/src/lib/commands/atta.c +++ b/src/lib/commands/atta.c @@ -95,7 +95,7 @@ atta(void) newy = def->y + diroff[n + 1][1]; getsect(newx, newy, §); /* 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; diff --git a/src/lib/commands/load.c b/src/lib/commands/load.c index 4e46212a9..0e8bea598 100644 --- a/src/lib/commands/load.c +++ b/src/lib/commands/load.c @@ -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; diff --git a/src/lib/commands/scra.c b/src/lib/commands/scra.c index 1528873aa..5bad10aff 100644 --- a/src/lib/commands/scra.c +++ b/src/lib/commands/scra.c @@ -135,7 +135,7 @@ scra(void) getsect(item.gen.x, item.gen.y, §); 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; diff --git a/src/lib/commands/sona.c b/src/lib/commands/sona.c index f38e8a6c1..7e7e6d2f0 100644 --- a/src/lib/commands/sona.c +++ b/src/lib/commands/sona.c @@ -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), diff --git a/src/lib/commands/spy.c b/src/lib/commands/spy.c index 721de2ddd..2a7ec53bd 100644 --- a/src/lib/commands/spy.c +++ b/src/lib/commands/spy.c @@ -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 */ diff --git a/src/lib/commands/tend.c b/src/lib/commands/tend.c index 13856384d..1bd33e7b5 100644 --- a/src/lib/commands/tend.c +++ b/src/lib/commands/tend.c @@ -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; diff --git a/src/lib/subs/fortdef.c b/src/lib/subs/fortdef.c index c67173a91..26062734b 100644 --- a/src/lib/subs/fortdef.c +++ b/src/lib/subs/fortdef.c @@ -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 diff --git a/src/lib/subs/plnsub.c b/src/lib/subs/plnsub.c index ed15058c9..c4c1a13e5 100644 --- a/src/lib/subs/plnsub.c +++ b/src/lib/subs/plnsub.c @@ -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; -- 2.43.0