diff --git a/include/prototypes.h b/include/prototypes.h index 4950e4a8..5fa5cb37 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -569,6 +569,7 @@ extern int put_plane_on_land(struct plnstr *, struct lndstr *); extern int pln_hitchance(struct plnstr *, int, int); extern int pln_damage(struct plnstr *, coord, coord, char, int *, int); extern int pln_identchance(struct plnstr *, int, int); +extern int pln_is_in_orbit(struct plnstr *); extern void pln_set_tech(struct plnstr *, int); /* pr.c */ extern void pr(char *, ...) ATTRIBUTE((format (printf, 1, 2))); diff --git a/src/lib/commands/laun.c b/src/lib/commands/laun.c index f51e17ba..39131968 100644 --- a/src/lib/commands/laun.c +++ b/src/lib/commands/laun.c @@ -82,7 +82,7 @@ laun(void) prplane(&plane)); continue; } - if ((plane.pln_flags & PLN_LAUNCHED) && (pcp->pl_flags & P_O)) { + if (pln_is_in_orbit(&plane)) { pr("%s already in orbit!\n", prplane(&plane)); continue; } @@ -193,7 +193,7 @@ launch_as(struct plnstr *pp) while (!goodtarget && nxtitem(&ni, &plane)) { if (!plane.pln_own) continue; - if (!(plane.pln_flags & PLN_LAUNCHED)) + if (!pln_is_in_orbit(&plane)) continue; goodtarget = 1; diff --git a/src/lib/commands/pdump.c b/src/lib/commands/pdump.c index 78694204..6c21a65f 100644 --- a/src/lib/commands/pdump.c +++ b/src/lib/commands/pdump.c @@ -258,20 +258,12 @@ pdump(void) pr(" %d", plane.pln_land); break; case 18: - if ((plchr[(int)plane.pln_type].pl_flags & (P_O | P_M)) == - P_O) { - pr(" %c", - (plane.pln_flags & PLN_LAUNCHED) ? 'Y' : 'N'); - } else - pr(" N"); + pr(pln_is_in_orbit(&plane) ? " Y" : " N"); break; case 19: - if ((plchr[(int)plane.pln_type].pl_flags & (P_O | P_M)) == - P_O) { - pr(" %c", - (plane.pln_flags & PLN_SYNCHRONOUS) ? 'Y' : 'N'); - } else - pr(" N"); + pr(pln_is_in_orbit(&plane) + && (plane.pln_flags & PLN_SYNCHRONOUS) + ? " Y" : " N"); break; case 20: if (plane.pln_nuketype != -1) { diff --git a/src/lib/commands/plan.c b/src/lib/commands/plan.c index 3b9b9fa4..136896ec 100644 --- a/src/lib/commands/plan.c +++ b/src/lib/commands/plan.c @@ -74,10 +74,8 @@ plan(void) pr("%5dL", plane.pln_land); else pr(" "); - if (plane.pln_flags & PLN_SYNCHRONOUS) - pr(" geosync"); - else if (plane.pln_flags & PLN_LAUNCHED) - pr(" orbit"); + if (pln_is_in_orbit(&plane)) + pr((plane.pln_flags & PLN_SYNCHRONOUS) ? " geosync" : " orbit"); else if (plane.pln_nuketype >= 0) pr(" %-5.5s %c", nchr[(int)plane.pln_nuketype].n_name, diff --git a/src/lib/commands/sate.c b/src/lib/commands/sate.c index 24b77a22..8c574e5d 100644 --- a/src/lib/commands/sate.c +++ b/src/lib/commands/sate.c @@ -65,7 +65,7 @@ sate(void) return RET_FAIL; } - if (!(plane.pln_flags & PLN_LAUNCHED)) { + if (!pln_is_in_orbit(&plane)) { pr("%s isn't in orbit\n", prplane(&plane)); return RET_FAIL; } diff --git a/src/lib/commands/skyw.c b/src/lib/commands/skyw.c index 6cecd8f0..62f23120 100644 --- a/src/lib/commands/skyw.c +++ b/src/lib/commands/skyw.c @@ -74,7 +74,7 @@ skyw(void) while (nxtitem(&ni, &skyp->s_sat)) { if (!skyp->s_sat.pln_own) continue; - if (!(skyp->s_sat.pln_flags & PLN_LAUNCHED)) + if (!pln_is_in_orbit(&skyp->s_sat)) continue; getsect(skyp->s_sat.pln_x, skyp->s_sat.pln_y, §); n = scthash(skyp->s_sat.pln_x, skyp->s_sat.pln_y, TSIZE); diff --git a/src/lib/commands/trad.c b/src/lib/commands/trad.c index 80fe7230..b6ef02d7 100644 --- a/src/lib/commands/trad.c +++ b/src/lib/commands/trad.c @@ -184,7 +184,7 @@ trad(void) * actually made, except for satellites in orbit. Must be owned * and must be a 60% airfield (except for VTOL planes). */ - if (((trade.trd_type == EF_PLANE) && !(tg.plane.pln_flags & PLN_LAUNCHED)) + if (((trade.trd_type == EF_PLANE) && !pln_is_in_orbit(&tg.plane)) || (trade.trd_type == EF_NUKE)) { while (1) { p = getstring("Destination sector: ", buf); @@ -364,7 +364,7 @@ check_trade(void) tg.nuke.nuk_x, tg.nuke.nuk_y); break; case EF_PLANE: - if ((tg.plane.pln_flags & PLN_LAUNCHED) == 0) { + if (!pln_is_in_orbit(&tg.plane)) { tg.plane.pln_x = trade.trd_x; tg.plane.pln_y = trade.trd_y; } diff --git a/src/lib/commands/tran.c b/src/lib/commands/tran.c index ec737402..b2da0d09 100644 --- a/src/lib/commands/tran.c +++ b/src/lib/commands/tran.c @@ -175,8 +175,7 @@ tran_plane(void) pr("%s has been hardened and can't be transported\n", prplane(&plane)); return RET_FAIL; - } else if ((plane.pln_flags & PLN_LAUNCHED) && - (plchr[type].pl_flags & P_O)) { + } else if (pln_is_in_orbit(&plane)) { pr("%s is in space and can't be transported\n", prplane(&plane)); return RET_FAIL; diff --git a/src/lib/commands/upgr.c b/src/lib/commands/upgr.c index 119fb912..3216f7fc 100644 --- a/src/lib/commands/upgr.c +++ b/src/lib/commands/upgr.c @@ -272,10 +272,12 @@ pupgr(void) plane.pln_uid); continue; } - if (plane.pln_flags & PLN_LAUNCHED) { + if (pln_is_in_orbit(&plane)) { pr("Plane %s is in orbit!\n", prplane(&plane)); continue; } + if (plane.pln_flags & PLN_LAUNCHED) + continue; n++; pp = &plchr[(int)plane.pln_type]; avail = (PLN_BLD_WORK(pp->pl_lcm, pp->pl_hcm) * UPGR_COST + 99) / 100; diff --git a/src/lib/subs/plnsub.c b/src/lib/subs/plnsub.c index 2eddb817..d54643fc 100644 --- a/src/lib/subs/plnsub.c +++ b/src/lib/subs/plnsub.c @@ -1236,6 +1236,13 @@ pln_mobcost(int dist, struct plnstr *pp, int flags) return ldround(cost * dist / pln_range_max(pp) + 5, 1); } +int +pln_is_in_orbit(struct plnstr *pp) +{ + return (plchr[pp->pln_type].pl_flags & (P_M | P_O)) == P_O + && (pp->pln_flags & PLN_LAUNCHED); +} + /* * Set PP's tech to TLEV along with everything else that depends on it. */ diff --git a/src/lib/subs/radmap.c b/src/lib/subs/radmap.c index ea5579ca..0ab3c12b 100644 --- a/src/lib/subs/radmap.c +++ b/src/lib/subs/radmap.c @@ -145,7 +145,7 @@ radmap2(int owner, x = deltx(&ns.range, (int)plane.pln_x); y = delty(&ns.range, (int)plane.pln_y); - if ((plane.pln_flags & PLN_LAUNCHED) && plane.pln_own != owner) { + if (pln_is_in_orbit(&plane) && plane.pln_own != owner) { vis[y][x] = 100; rad[y][x] = '$'; } diff --git a/src/lib/update/plane.c b/src/lib/update/plane.c index 6ac47b4a..a0392298 100644 --- a/src/lib/update/plane.c +++ b/src/lib/update/plane.c @@ -66,7 +66,7 @@ prod_plane(int etus, int natnum, struct bp *bp, int buildem) continue; } - if (pp->pln_flags & PLN_LAUNCHED) { + if (pln_is_in_orbit(pp)) { if (!player->simulation && buildem == 0 && !(pp->pln_flags & PLN_SYNCHRONOUS)) move_sat(pp);