/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
* ---
*
* plnsub.c: Plane subroutine stuff
- *
+ *
* Known contributors to this file:
* Dave Pare, 1986
* Ken Stevens, 1995
* Steve McClure, 1998-2000
- * Markus Armbruster, 2004-2005
+ * Markus Armbruster, 2004-2009
*/
#include <config.h>
static int pln_equip(struct plist *, struct ichrstr *, int, char);
static int fit_plane_on_ship(struct plnstr *, struct shpstr *);
+/*
+ * Get planes and escorts argument.
+ * Read planes into *NI_BOMB, and (optional) escorts into *NI_ESC.
+ * If INPUT_BOMB is not empty, use it, else prompt for more input.
+ * Same for INPUT_ESC.
+ * If we got a plane argument, initialize *NI_BOMB and *NI_ESC, and
+ * return 0.
+ * Else return -1 (*NI_BOMB and *NI_ESC may be modified).
+ */
+int
+get_planes(struct nstr_item *ni_bomb, struct nstr_item *ni_esc,
+ char *input_bomb, char *input_esc)
+{
+ if (!snxtitem(ni_bomb, EF_PLANE, input_bomb, NULL))
+ return -1;
+ if (!snxtitem(ni_esc, EF_PLANE, input_esc, "escort(s)? ")) {
+ if (player->aborted)
+ return -1;
+ pr("No escorts...\n");
+ }
+ return 0;
+}
+
/*
* Get assembly point argument.
* If INPUT is not empty, use it, else prompt for more input using PROMPT.
nships = carriersatxy(target->sct_x, target->sct_y, player->cnum);
if (nships) {
for (;;) {
- if (!(p = getstarg(0, "Carrier #? ", buf)) || !*p)
+ p = getstring("Carrier #? ", buf);
+ if (!p)
+ return -1;
+ if (!*p)
break;
cno = atoi(p);
if (cno < 0
if (cno < 0 || !getship(cno, &ship))
return 0;
- count_planes(&ship);
-
/* for both lists */
for (list = bomb_list;
list;
for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
plp = (struct plist *)qp;
if (cno >= 0) {
- count_planes(&ship);
- if (!could_be_on_ship(&plp->plane, &ship))
+ if (!could_be_on_ship(&plp->plane, &ship, 0, 0, 0, 0))
pr("\t%s cannot land on ship #%d! %s aborts!\n",
prplane(&plp->plane), cno, prplane(&plp->plane));
else if (!put_plane_on_ship(&plp->plane, &ship))
cno, prplane(&plp->plane));
else {
if (plp->plane.pln_own != ship.shp_own) {
-/* plp->plane.pln_own = ship.shp_own;*/
wu(0, ship.shp_own, "%s %s lands on your %s\n",
cname(player->cnum), prplane(&plp->plane),
prship(&ship));
plp->plane.pln_y = ty;
getsect(tx, ty, §);
if (plp->plane.pln_own != sect.sct_own) {
-/* plp->plane.pln_own = sect.sct_own;*/
wu(0, sect.sct_own,
"%s %s lands at your sector %s\n",
cname(player->cnum),
plp->plane.pln_ship = cno;
}
}
- if (cno >= 0)
- putship(ship.shp_uid, &ship);
}
void
pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty,
- void *ptr, int type)
+ int cno)
{
struct emp_qelem *qp;
struct plist *plp;
int amt;
- struct sctstr *sectp;
- struct shpstr *sp;
+ struct sctstr sect;
+ struct shpstr ship;
int there;
int max;
- struct mchrstr *mp;
if (ip == 0)
return;
plp = (struct plist *)qp;
amt += plp->misc;
}
- if (type == EF_SECTOR) {
- sectp = ptr;
- if (!sectp->sct_own) {
- if (sectp->sct_type == SCT_WATER)
+ if (cno < 0) {
+ getsect(tx, ty, §);
+ if (!sect.sct_own) {
+ if (sect.sct_type == SCT_WATER)
pr("Your %s sink like a rock!\n", ip->i_name);
else
pr("Your %s vanish without a trace.\n", ip->i_name);
return;
}
- if (sectp->sct_own != player->cnum
- && getrel(getnatp(sectp->sct_own), player->cnum) != ALLIED) {
+ if (sect.sct_own != player->cnum
+ && getrel(getnatp(sect.sct_own), player->cnum) != ALLIED) {
pr("You don't own %s! Cargo jettisoned...\n",
xyas(tx, ty, player->cnum));
return;
}
- if (ip->i_uid == I_CIVIL && sectp->sct_own != sectp->sct_oldown) {
+ if (ip->i_uid == I_CIVIL && sect.sct_own != sect.sct_oldown) {
pr("%s is occupied. Your civilians suffer from identity crisis and die.\n",
xyas(tx, ty, player->cnum));
return;
}
- there = sectp->sct_item[ip->i_uid];
+ there = sect.sct_item[ip->i_uid];
max = ITEM_MAX;
} else {
- sp = ptr;
- there = sp->shp_item[ip->i_uid];
- mp = &mchr[(int)sp->shp_type];
- max = mp->m_item[ip->i_uid];
+ getship(cno, &ship);
+ there = ship.shp_item[ip->i_uid];
+ max = mchr[ship.shp_type].m_item[ip->i_uid];
}
there += amt;
if (there > max) {
there = max;
}
pr("%d %s landed safely", amt, ip->i_name);
- if (type == EF_SECTOR) {
- sectp = ptr;
- sectp->sct_item[ip->i_uid] = there;
- if (sectp->sct_own != player->cnum)
- wu(0, sectp->sct_own, "%s planes drop %d %s in %s\n",
+ if (cno < 0) {
+ sect.sct_item[ip->i_uid] = there;
+ if (sect.sct_own != player->cnum)
+ wu(0, sect.sct_own, "%s planes drop %d %s in %s\n",
cname(player->cnum), amt, ip->i_name,
- xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
+ xyas(tx, ty, sect.sct_own));
pr(" at %s\n", xyas(tx, ty, player->cnum));
- putsect((struct sctstr *)ptr);
+ putsect(§);
} else {
- struct shpstr *sp = (struct shpstr *)ptr;
- sp->shp_item[ip->i_uid] = there;
- if (sp->shp_own != player->cnum)
- wu(0, sp->shp_own, "%s planes land %d %s on carrier %d\n",
- cname(player->cnum), amt, ip->i_name, sp->shp_uid);
- pr(" on carrier #%d\n", sp->shp_uid);
- putship(sp->shp_uid, sp);
+ ship.shp_item[ip->i_uid] = there;
+ if (ship.shp_own != player->cnum)
+ wu(0, ship.shp_own, "%s planes land %d %s on carrier %d\n",
+ cname(player->cnum), amt, ip->i_name, ship.shp_uid);
+ pr(" on carrier #%d\n", ship.shp_uid);
+ putship(ship.shp_uid, &ship);
}
}
void
-pln_mine(struct emp_qelem *list, struct sctstr *sectp)
+pln_mine(struct emp_qelem *list, coord tx, coord ty)
{
struct emp_qelem *qp;
struct plist *plp;
int amt;
+ struct sctstr sect;
amt = 0;
for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
}
if (amt > 0) {
- if (sectp->sct_type != SCT_WATER) {
+ getsect(tx, ty, §);
+ if (sect.sct_type != SCT_WATER) {
pr("Your seamines have no effect here.\n");
return;
}
- sectp->sct_mines = MIN(sectp->sct_mines + amt, MINES_MAX);
- pr("%d mines laid in %s.\n", amt,
- xyas(sectp->sct_x, sectp->sct_y, player->cnum));
- if (map_set(player->cnum, sectp->sct_x, sectp->sct_y, 'X', 0))
+ sect.sct_mines = MIN(sect.sct_mines + amt, MINES_MAX);
+ pr("%d mines laid in %s.\n", amt, xyas(tx, ty, player->cnum));
+ if (map_set(player->cnum, tx, ty, 'X', 0))
writemap(player->cnum);
- putsect(sectp);
+ putsect(§);
}
}
continue;
if (plane.pln_mobil <= 0)
continue;
+ if (plane.pln_effic < 40) {
+ pr("%s not efficient enough (must be 40%%)\n",
+ prplane(&plane));
+ continue;
+ }
+ if (!pln_capable(&plane, wantflags, nowantflags))
+ continue;
if (opt_MARKET) {
if (ontradingblock(EF_PLANE, &plane)) {
pr("plane #%d inelligible - it's for sale.\n",
pr("%s too far from assembly point\n", prplane(&plane));
continue;
}
- if (plane.pln_effic < 40) {
- pr("%s not efficient enough (must be 40%%)\n",
- prplane(&plane));
- continue;
- }
range += ap_to_target;
range *= rangemult;
pcp = &plchr[(int)plane.pln_type];
- if (!pln_capable(&plane, wantflags, nowantflags))
- continue;
if (plane.pln_range < range) {
pr("%s out of range (%d:%d)\n",
prplane(&plane), plane.pln_range, range);
}
}
-int
+void
pln_arm(struct emp_qelem *list, int dist, char mission, struct ichrstr *ip,
- int flags, int mission_flags)
+ int flags)
{
struct emp_qelem *qp;
struct emp_qelem *next;
struct plist *plp;
+ struct plnstr *pp;
for (qp = list->q_forw; qp != list; qp = next) {
next = qp->q_forw;
plp = (struct plist *)qp;
- if (pln_equip(plp, ip, flags, mission) < 0) {
+ pp = &plp->plane;
+ getplane(pp->pln_uid, pp);
+ if ((pp->pln_flags & PLN_LAUNCHED)
+ || pln_equip(plp, ip, flags, mission) < 0) {
emp_remque(qp);
free(qp);
continue;
}
- if (flags & (P_S | P_I)) {
- if (plp->pcp->pl_flags & P_S)
- mission_flags |= P_S;
- if (plp->pcp->pl_flags & P_I)
- mission_flags |= P_I;
- }
- if (!(plp->pcp->pl_flags & P_H))
- /* no stealth on this mission */
- mission_flags &= ~P_H;
- if (!(plp->pcp->pl_flags & P_X))
- /* no stealth on this mission */
- mission_flags &= ~P_X;
- if (!(plp->pcp->pl_flags & P_A)) {
- /* no asw on this mission */
- mission_flags &= ~P_A;
- /* FIXME escorts turn ASW patrol into ordinary recon */
- }
- if (!(plp->pcp->pl_flags & P_MINE)) {
- /* no asw on this mission */
- mission_flags &= ~P_MINE;
- /* FIXME no effect */
- }
- plp->plane.pln_mobil -= pln_mobcost(dist, &plp->plane, flags);
- pr("%s equipped\n", prplane(&plp->plane));
+ pp->pln_flags |= PLN_LAUNCHED;
+ pp->pln_mobil -= pln_mobcost(dist, pp, flags);
+ putplane(pp->pln_uid, pp);
+ pr("%s equipped\n", prplane(pp));
}
- return mission_flags;
}
static int
{
struct plchrstr *pcp;
struct plnstr *pp;
- int needed;
+ int load, needed;
struct lndstr land;
struct shpstr ship;
struct sctstr sect;
i_type itype;
- int rval;
short *item;
int own;
int abandon_needed;
return -1;
}
item[I_PETROL] -= pcp->pl_fuel;
- rval = 0;
if ((flags & P_F) == 0) {
+ load = pln_load(pp);
itype = I_NONE;
needed = 0;
switch (mission) {
- case 's':
- case 'p':
- if (pp->pln_nuketype == -1) {
+ case 's': /* strategic bomb */
+ case 'p': /* pinpoint bomb */
+ if (nuk_on_plane(pp) < 0) {
itype = I_SHELL;
- needed = pp->pln_load;
+ needed = load;
}
break;
- case 't':
- case 'd':
+ case 't': /* transport */
+ case 'd': /* drop */
if ((pcp->pl_flags & P_C) == 0 || ip == 0)
break;
itype = ip->i_uid;
- needed = (pp->pln_load * 2) / ip->i_lbs;
+ needed = (load * 2) / ip->i_lbs;
break;
- case 'm':
+ case 'm': /* mine */
if ((pcp->pl_flags & P_MINE) == 0)
break;
itype = I_SHELL;
- needed = (pp->pln_load * 2) / ip->i_lbs;
+ needed = (load * 2) / ip->i_lbs;
break;
- case 'a':
+ case 'a': /* paradrop */
if ((pcp->pl_flags & (P_V | P_C)) == 0)
break;
itype = I_MILIT;
- needed = pp->pln_load / ip->i_lbs;
+ needed = load / ip->i_lbs;
break;
- case 'n':
- if (pp->pln_nuketype == -1)
- rval = -1;
+ case 'r': /* reconnaissance */
break;
default:
- break;
+ CANT_REACH();
}
- if (rval < 0 || (itype != I_NONE && needed <= 0)) {
+ if (itype != I_NONE && needed <= 0) {
pr("%s can't contribute to mission\n", prplane(pp));
return -1;
}
}
putsect(§);
}
- return rval;
+ return 0;
}
void
pln_put(struct emp_qelem *list)
{
- struct emp_qelem *qp;
- struct emp_qelem *newqp;
- struct plist *plp;
- struct plnstr *pp;
- struct shpstr ship;
- struct sctstr sect;
+ struct emp_qelem *qp, *next;
- /* Here is where planes return home from bombing runs.
- We need to make sure they still have somewhere to return
- home to! */
- qp = list->q_forw;
- while (qp != list) {
- plp = (struct plist *)qp;
- pp = &plp->plane;
- /* Ok, check out where it wants to land */
- if (pp->pln_ship >= 0) {
- /* It is landing on a carrier */
- getship(pp->pln_ship, &ship);
- /* We should do more, like make sure it's really
- a carrier, etc. but for now just make sure it's
- not sunk. */
- if (ship.shp_effic < SHIP_MINEFF) {
- mpr(pp->pln_own,
- "Ship #%d has been sunk, plane #%d has nowhere to land, and\n"
- "splashes into the sea.\n",
- pp->pln_ship, pp->pln_uid);
- pp->pln_effic = 0;
- }
- } else {
- /* Presume we are landing back in a sector. */
- getsect(pp->pln_x, pp->pln_y, §);
- if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_WASTE) {
- mpr(pp->pln_own,
- "Nowhere to land at %s, plane #%d crashes and burns...\n",
- xyas(pp->pln_x, pp->pln_y, pp->pln_own), pp->pln_uid);
- pp->pln_effic = 0;
- }
- }
- putplane(pp->pln_uid, pp);
- newqp = qp->q_forw;
- emp_remque(qp);
- free(qp);
- qp = newqp;
+ for (qp = list->q_forw; qp != list; qp = next) {
+ next = qp->q_forw;
+ pln_put1((struct plist *)qp);
}
}
void
-pln_removedupes(struct emp_qelem *bomb_list, struct emp_qelem *esc_list)
+pln_put1(struct plist *plp)
{
- struct emp_qelem *bomb;
- struct emp_qelem *esc;
- struct plist *bombp;
- struct plist *escp;
+ struct plnstr *pp;
+ struct shpstr ship;
+ struct sctstr sect;
- if (QEMPTY(bomb_list) || QEMPTY(esc_list))
- return;
- bomb = bomb_list->q_forw;
- while (bomb != bomb_list) {
- if (QEMPTY(esc_list)) {
- bomb = bomb_list;
- continue;
+ pp = &plp->plane;
+
+ if (CANT_HAPPEN((pp->pln_flags & PLN_LAUNCHED)
+ && (plchr[pp->pln_type].pl_flags & P_M)
+ && pp->pln_effic >= PLANE_MINEFF))
+ pp->pln_effic = 0; /* bug: missile launched but not used up */
+
+ if (!(pp->pln_flags & PLN_LAUNCHED))
+ ; /* never took off */
+ else if (pp->pln_effic < PLANE_MINEFF) {
+ ; /* destroyed */
+ } else if (pp->pln_ship >= 0) {
+ /* It is landing on a carrier */
+ getship(pp->pln_ship, &ship);
+ /* We should do more, like make sure it's really
+ a carrier, etc. but for now just make sure it's
+ not sunk. */
+ if (ship.shp_effic < SHIP_MINEFF) {
+ mpr(pp->pln_own,
+ "Ship #%d has been sunk, plane #%d has nowhere to land, and\n"
+ "splashes into the sea.\n",
+ pp->pln_ship, pp->pln_uid);
+ pp->pln_effic = 0;
}
- esc = esc_list->q_forw;
- bombp = (struct plist *)bomb;
- while (esc != esc_list) {
- escp = (struct plist *)esc;
- if (escp->plane.pln_uid == bombp->plane.pln_uid) {
- emp_remque(esc);
- free(esc);
- esc = esc_list;
- } else
- esc = esc->q_forw;
+ } else {
+ /* Presume we are landing back in a sector. */
+ getsect(pp->pln_x, pp->pln_y, §);
+ if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_WASTE) {
+ mpr(pp->pln_own,
+ "Nowhere to land at %s, plane #%d crashes and burns...\n",
+ xyas(pp->pln_x, pp->pln_y, pp->pln_own), pp->pln_uid);
+ pp->pln_effic = 0;
}
- bomb = bomb->q_forw;
}
+ pp->pln_flags &= ~PLN_LAUNCHED;
+ putplane(pp->pln_uid, pp);
+ emp_remque(&plp->queue);
+ free(plp);
}
/*
- * Fit a plane of PP's type on ship SP.
- * Adjust SP's plane counters.
- * Updating the plane accordingly is the caller's job.
- * Return whether it fits.
+ * Can PP be loaded on a ship of SP's type?
+ * Assume that it already carries N planes, of which NCH are choppers,
+ * NXL xlight, NMSL light missiles, and the rest are light fixed-wing
+ * planes.
*/
-static int
-fit_plane_on_ship(struct plnstr *pp, struct shpstr *sp)
+int
+could_be_on_ship(struct plnstr *pp, struct shpstr *sp,
+ int n, int nch, int nxl, int nmsl)
{
- struct plchrstr *pcp = plchr + pp->pln_type;
- struct mchrstr *mcp = mchr + sp->shp_type;
- int wanted;
-
- if (pcp->pl_flags & P_K) {
- /* chopper, try chopper slot first */
- if (sp->shp_nchoppers < mcp->m_nchoppers)
- return ++sp->shp_nchoppers;
- /* else try plane slot */
- wanted = M_FLY;
- } else if (pcp->pl_flags & P_E) {
- /* x-light, try x-light slot first */
- if (sp->shp_nxlight < mcp->m_nxlight)
- return ++sp->shp_nxlight;
- /* else try plane slot */
- wanted = M_MSL | M_FLY;
- } else if (!(pcp->pl_flags & P_L)) {
- /* not light, no go */
- wanted = 0;
- } else if (pcp->pl_flags & P_M) {
- /* missile, use plane slot */
- wanted = M_MSL | M_FLY;
- } else {
- /* fixed-wing plane, use plane slot */
- wanted = M_FLY;
- }
-
- if ((mcp->m_flags & wanted) == 0)
- return 0; /* ship not capable */
-
- if (sp->shp_nplane < mcp->m_nplanes)
- return ++sp->shp_nplane;
-
- return 0;
+ struct plchrstr *pcp = &plchr[pp->pln_type];
+ struct mchrstr *mcp = &mchr[sp->shp_type];
+
+ if (pcp->pl_flags & P_K)
+ nch++;
+ else if (pcp->pl_flags & P_E)
+ nxl++;
+ else if (!(pcp->pl_flags & P_L))
+ return 0;
+ else if (pcp->pl_flags & P_M)
+ nmsl++;
+ n++;
+
+ n -= MIN(nch, mcp->m_nchoppers);
+ n -= MIN(nxl, mcp->m_nxlight);
+ if (nmsl && !(mcp->m_flags & (M_MSL | M_FLY)))
+ return 0; /* missile slots wanted */
+ if (nmsl < n && !(mcp->m_flags & M_FLY))
+ return 0; /* fixed-wing slots wanted */
+ return n <= mcp->m_nplanes;
}
/*
- * Fit a plane of PP's type off ship SP.
- * Adjust SP's plane counters, badly. You need to run count_planes()
- * before the next fit_plane_on_ship().
+ * Fit a plane of PP's type on ship SP.
* Updating the plane accordingly is the caller's job.
+ * Return whether it fits.
*/
-static void
-fit_plane_off_ship(struct plnstr *pp, struct shpstr *sp)
+static int
+fit_plane_on_ship(struct plnstr *pp, struct shpstr *sp)
{
- /*
- * Frees chopper and nxlight slots first, which is why we need to
- * run count_planes() before fit_plane_on_ship().
- */
- struct plchrstr *pcp = plchr + pp->pln_type;
-
- if (pcp->pl_flags & P_K) {
- if (sp->shp_nchoppers) {
- sp->shp_nchoppers--;
- return;
- }
- } else if (pcp->pl_flags & P_E) {
- if (sp->shp_nxlight) {
- sp->shp_nxlight--;
- return;
- }
- }
+ int n, nch, nxl, nmsl;
- if (CANT_HAPPEN(sp->shp_nplane == 0))
- sp->shp_nplane = 1;
- sp->shp_nplane--;
+ n = shp_nplane(sp, &nch, &nxl, &nmsl);
+ return could_be_on_ship(pp, sp, n, nch, nxl, nmsl);
}
int
plane->pln_y = ship->shp_y;
plane->pln_ship = ship->shp_uid;
putplane(plane->pln_uid, plane);
- putship(ship->shp_uid, ship);
return 1;
}
-void
-take_plane_off_ship(struct plnstr *plane, struct shpstr *ship)
-{
- if (CANT_HAPPEN(plane->pln_ship != ship->shp_uid))
- return;
-
- fit_plane_off_ship(plane, ship);
- plane->pln_ship = -1;
- putship(ship->shp_uid, ship);
- putplane(plane->pln_uid, plane);
-}
-
/*
* Fit a plane of PP's type on land unit LP.
- * Adjust LP's plane counters.
* Updating the plane accordingly is the caller's job.
* Return whether it fits.
*/
struct plchrstr *pcp = plchr + pp->pln_type;
struct lchrstr *lcp = lchr + lp->lnd_type;
- if ((pcp->pl_flags & P_E) && lp->lnd_nxlight < lcp->l_nxlight)
- return ++lp->lnd_nxlight;
-
- return 0;
-}
-
-/*
- * Fit a plane of PP's type off land unit LP.
- * Adjust LP's plane counters.
- * Updating the plane accordingly is the caller's job.
- */
-static void
-fit_plane_off_land(struct plnstr *pp, struct lndstr *lp)
-{
- if (CANT_HAPPEN(lp->lnd_nxlight == 0))
- lp->lnd_nxlight = 1;
- lp->lnd_nxlight--;
+ return (pcp->pl_flags & P_E) && lnd_nxlight(lp) < lcp->l_nxlight;
}
int
plane->pln_y = land->lnd_y;
plane->pln_land = land->lnd_uid;
putplane(plane->pln_uid, plane);
- putland(land->lnd_uid, land);
return 1;
}
-void
-take_plane_off_land(struct plnstr *plane, struct lndstr *land)
-{
- if (CANT_HAPPEN(plane->pln_land != land->lnd_uid))
- return;
-
- fit_plane_off_land(plane, land);
- plane->pln_land = -1;
- putland(land->lnd_uid, land);
- putplane(plane->pln_uid, plane);
-}
-
-/*
- * Could a plane of PP's type be on on ship SP?
- */
-int
-could_be_on_ship(struct plnstr *pp, struct shpstr *sp)
-{
- struct shpstr ship;
-
- ship = *sp;
- ship.shp_nplane = ship.shp_nchoppers = ship.shp_nxlight = 0;
- return fit_plane_on_ship(pp, &ship);
-}
-
void
plane_sweep(struct emp_qelem *plane_list, coord x, coord y)
{
if (!(pcp->pl_flags & P_SWEEP)) /* if it isn't an sweep plane */
continue;
- if (chance((100.0 - pp->pln_acc) / 100.0)) {
+ if (chance((100.0 - pln_acc(pp)) / 100.0)) {
pr("Sweep! in %s\n",
xyas(sect.sct_x, sect.sct_y, pp->pln_own));
mines_there--;
putsect(§);
}
-void
-count_planes(struct shpstr *sp)
-{
- struct nstr_item ni;
- struct plnstr plane;
- int nplane, nchoppers, nxlight;
-
- if (sp->shp_effic < SHIP_MINEFF)
- return;
-
- nplane = sp->shp_nplane;
- sp->shp_nplane = 0;
- nchoppers = sp->shp_nchoppers;
- sp->shp_nchoppers = 0;
- nxlight = sp->shp_nxlight;
- sp->shp_nxlight = 0;
-
- snxtitem_xy(&ni, EF_PLANE, sp->shp_x, sp->shp_y);
- while (nxtitem(&ni, &plane)) {
- if (plane.pln_own == 0)
- continue;
- if (plane.pln_ship == sp->shp_uid) {
- if (!fit_plane_on_ship(&plane, sp))
- CANT_REACH();
- }
- }
-
- if (nplane != sp->shp_nplane ||
- nxlight != sp->shp_nxlight || nchoppers != sp->shp_nchoppers) {
- putship(sp->shp_uid, sp);
- }
-}
-
-void
-count_land_planes(struct lndstr *lp)
-{
- struct nstr_item ni;
- struct plnstr plane;
- int nplane;
-
- if (lp->lnd_effic < LAND_MINEFF)
- return;
-
- nplane = lp->lnd_nxlight;
- lp->lnd_nxlight = 0;
-
- snxtitem_all(&ni, EF_PLANE);
- while (nxtitem(&ni, &plane)) {
- if (plane.pln_own == 0)
- continue;
- if (plane.pln_land == lp->lnd_uid)
- if (!fit_plane_on_land(&plane, lp))
- CANT_REACH();
- }
-
- if (lp->lnd_nxlight != nplane)
- putland(lp->lnd_uid, lp);
-}
-
-int
-count_sect_planes(struct sctstr *sp)
-{
- int count = 0;
- struct nstr_item ni;
- struct plnstr plane;
-
- snxtitem_all(&ni, EF_PLANE);
- while (nxtitem(&ni, &plane)) {
- if (!plane.pln_own)
- continue;
- if (plane.pln_flags & PLN_LAUNCHED)
- continue;
- if (plane.pln_x == sp->sct_x && plane.pln_y == sp->sct_y)
- ++count;
- }
-
- return count;
-}
-
int
pln_hitchance(struct plnstr *pp, int hardtarget, int type)
{
struct plchrstr *pcp = plchr + pp->pln_type;
double tfact = (double)(pp->pln_tech - pcp->pl_tech) /
(pp->pln_tech - pcp->pl_tech / 2);
- int acc = pp->pln_acc;
+ int acc = pln_acc(pp);
int hitchance;
if (type == EF_SHIP) {
{
struct nukstr nuke;
struct plchrstr *pcp = plchr + pp->pln_type;
- int i;
+ int load, i;
int hitroll;
int dam = 0;
int aim;
int effective = 1;
int pinbomber = 0;
- if (pp->pln_nuketype != -1) {
- if (nuk_on_plane(&nuke, pp->pln_uid) >= 0) {
- mpr(pp->pln_own, "Releasing RV's for %s detonation...\n",
- pp->pln_flags & PLN_AIRBURST ? "airburst" : "groundburst");
- pp->pln_nuketype = -1;
- *nukedamp = detonate(&nuke, x, y,
- pp->pln_flags & PLN_AIRBURST);
- return 0;
- }
- CANT_REACH();
+ if (getnuke(nuk_on_plane(pp), &nuke)) {
+ mpr(pp->pln_own, "Releasing RV's for %s detonation...\n",
+ pp->pln_flags & PLN_AIRBURST ? "airburst" : "groundburst");
+ *nukedamp = detonate(&nuke, x, y,
+ pp->pln_flags & PLN_AIRBURST);
+ return 0;
}
*nukedamp = 0;
- if (!pp->pln_load) /* e.g. ab, blowing up on launch pad */
+ load = pln_load(pp);
+ if (!load) /* e.g. ab, blowing up on launch pad */
return 0;
- i = roll(pp->pln_load) + 1;
- if (i > pp->pln_load)
- i = pp->pln_load;
+ i = roll(load) + 1;
+ if (i > load)
+ i = load;
if (pcp->pl_flags & P_M) {
if (pcp->pl_flags & P_MAR)
} else if (pcp->pl_flags & P_T)
pinbomber = 1;
- aim = 100 - pp->pln_acc;
+ aim = pln_acc(pp);
if (type == 's') {
- if (pinbomber) {
- aim = pp->pln_acc;
- effective = 0;
- }
- aim += 30;
+ effective = !pinbomber;
+ aim = 30 + (pinbomber ? aim : 100 - aim);
} else {
- if (!pinbomber) {
- effective = 0;
- }
+ effective = pinbomber;
+ aim = 100 - aim;
}
+
while (i--) {
dam += roll(6);
hitroll = roll(100);
if ((flags & P_F) || (flags & P_ESC))
cost /= 2;
- return ldround(cost * dist / pp->pln_range_max + 5, 1);
+ 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);
}
/*
pln_set_tech(struct plnstr *pp, int tlev)
{
struct plchrstr *pcp = plchr + pp->pln_type;
- int limited_range = pp->pln_range < pp->pln_range_max;
+ int limited_range = pp->pln_range < pln_range_max(pp);
+ int range_max;
if (CANT_HAPPEN(tlev < pcp->pl_tech))
tlev = pcp->pl_tech;
-
pp->pln_tech = tlev;
- pp->pln_att = pl_att(pcp, tlev);
- pp->pln_def = pl_def(pcp, tlev);
- pp->pln_acc = pl_acc(pcp, tlev);
- pp->pln_range_max = pl_range(pcp, tlev);
- pp->pln_load = pl_load(pcp, tlev);
-
- if (!limited_range || pp->pln_range > pp->pln_range_max)
- pp->pln_range = pp->pln_range_max;
+
+ range_max = pln_range_max(pp);
+ if (!limited_range || pp->pln_range > range_max)
+ pp->pln_range = range_max;
}