/*
* 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
* ---
*
* bomb.c: Fly bombing missions
- *
+ *
* Known contributors to this file:
* Dave Pare, 1986
* Ken Stevens, 1995
* Steve McClure, 1998-2000
- * Markus Armbruster, 2004-2008
+ * Markus Armbruster, 2004-2009
*/
#include <config.h>
#include "item.h"
#include "land.h"
#include "news.h"
+#include "nuke.h"
#include "optlist.h"
#include "path.h"
#include "plane.h"
bomb(void)
{
char *p;
- int mission_flags;
coord tx, ty;
coord ax, ay;
int ap_to_target;
char buf[1024];
wantflags = 0;
- if (!snxtitem(&ni_bomb, EF_PLANE, player->argp[1]))
+ if (get_planes(&ni_bomb, &ni_esc, player->argp[1], player->argp[2]) < 0)
return RET_SYN;
- if (!snxtitem(&ni_esc, EF_PLANE,
- getstarg(player->argp[2], "escort(s)? ", buf)))
- pr("No escorts...\n");
p = getstarg(player->argp[3], "pinpoint, or strategic? ", buf);
- if (!p)
+ if (!p || !*p)
return RET_SYN;
mission = *p;
if (strchr("ps", mission) == 0)
/*
* select planes within range
*/
- mission_flags = 0;
pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target,
2, wantflags, P_M | P_O);
pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target,
/*
* now arm and equip the bombers, transports, whatever.
*/
- mission_flags |= P_X; /* stealth (shhh) */
- mission_flags |= P_H; /* gets turned off if not all choppers */
- mission_flags = pln_arm(&bomb_list, 2 * ap_to_target, mission,
- ip, 0, mission_flags);
+ pln_arm(&bomb_list, 2 * ap_to_target, mission, ip, 0);
if (QEMPTY(&bomb_list)) {
pr("No planes could be equipped for the mission.\n");
return RET_FAIL;
}
- mission_flags = pln_arm(&esc_list, 2 * ap_to_target, mission,
- ip, P_F | P_ESC, mission_flags);
- ac_encounter(&bomb_list, &esc_list, ax, ay,
- flightpath, mission_flags, 0);
+ pln_arm(&esc_list, 2 * ap_to_target, mission, ip, P_F | P_ESC);
+ ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, 0);
if (QEMPTY(&bomb_list)) {
pr("No planes got through fighter defenses\n");
} else if (target.sct_type == SCT_SANCT) {
plp = (struct plist *)qp;
if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
continue;
- if (plp->bombs || plp->plane.pln_nuketype != -1)
+ if (plp->bombs || nuk_on_plane(&plp->plane) >= 0)
dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
'p', &nukedam, 1);
}
plp = (struct plist *)qp;
if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
continue;
- if (plp->bombs || plp->plane.pln_nuketype != -1)
+ if (plp->bombs || nuk_on_plane(&plp->plane) >= 0)
dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
'p', &nukedam, 1);
}
int n;
struct emp_qelem *qp;
int shipno;
- int ignore;
struct shpstr ship;
int nships = 0;
struct shiplist *head = NULL;
int nukedam;
int flak;
int gun;
- int shell;
- for (qp = list->q_forw; qp != list && !player->aborted;
- qp = qp->q_forw) {
+ for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
free_shiplist(&head);
plp = (struct plist *)qp;
if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
}
(void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
prplane(&plp->plane), plp->bombs);
- ignore = 0;
shipno = -1;
- while (shipno < 0 && !player->aborted && !ignore) {
- if ((q = getstring(prompt, buf)) == 0 || *q == 0)
- continue;
- if (*q == '~') {
- ignore = 1;
+ while (shipno < 0) {
+ if ((q = getstring(prompt, buf)) == 0)
+ goto out;
+ if (*q == 0)
continue;
- }
+ if (*q == '~')
+ break;
if (*q == '?') {
if (plp->pcp->pl_flags & P_A)
print_shiplist(head);
shipsatxy(target->sct_x, target->sct_y, 0, M_SUB, 0);
continue;
}
- if (*q == 'd')
- goto next;
- if (!isdigit(*q))
- continue;
n = atoi(q);
if (n < 0)
continue;
- if ((plp->pcp->pl_flags & P_A) && !on_shiplist(n, head))
- continue;
- if (getship(n, &ship) && ship.shp_own &&
+ if ((!(plp->pcp->pl_flags & P_A) || on_shiplist(n, head)) &&
+ getship(n, &ship) && ship.shp_own &&
ship.shp_x == target->sct_x && ship.shp_y == target->sct_y)
shipno = n;
+ else
+ pr("Ship #%d not spotted\n", n);
}
if (shipno < 0)
continue;
if ((plp->pcp->pl_flags & P_A) && !on_shiplist(shipno, head))
continue;
- shell = 0;
gun = shp_usable_guns(&ship);
- if (gun > 0) {
- shell = ship.shp_item[I_SHELL];
- if (shell <= 0)
- shell = supply_commod(ship.shp_own,
- ship.shp_x, ship.shp_y, I_SHELL, 1);
- }
mcp = &mchr[(int)ship.shp_type];
- if (gun > 0 && shell > 0 && !(mcp->m_flags & M_SUB)) {
+ if (gun > 0 && !(mcp->m_flags & M_SUB)) {
flak = (int)(techfact(ship.shp_tech, gun) * 2.0);
- ship.shp_item[I_SHELL] = shell;
- putship(ship.shp_uid, &ship);
PR(ship.shp_own, "Flak! Firing %d guns from ship %s\n",
flak, prship(&ship));
if (pinflak_planedamage(&plp->plane, plp->pcp, ship.shp_own, flak))
}
dam = 0;
- if (plp->plane.pln_nuketype != -1)
+ if (nuk_on_plane(&plp->plane) >= 0)
hitchance = 100;
else {
hitchance = pln_hitchance(&plp->plane,
xyas(target->sct_x, target->sct_y, player->cnum));
}
collateral_damage(target->sct_x, target->sct_y, dam / 2);
- next:
- ;
}
+out:
free_shiplist(&head);
}
struct plnstr plane;
struct emp_qelem *qp;
int planeno;
- int ignore;
struct plist *plp;
char prompt[128];
char buf[1024];
(void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
prplane(&plp->plane), plp->bombs);
planeno = -1;
- ignore = 0;
- while (planeno < 0 && !player->aborted && !ignore) {
- if ((q = getstring(prompt, buf)) == 0 || *q == 0)
+ while (planeno < 0) {
+ if ((q = getstring(prompt, buf)) == 0)
+ return;
+ if (*q == 0)
continue;
- if (*q == '~') {
- ignore = 1;
- continue;
- }
+ if (*q == '~')
+ break;
if (*q == '?') {
planesatxy(target->sct_x, target->sct_y, 0, 0);
continue;
}
- if (*q == 'd')
- goto next;
n = atoi(q);
if (n < 0)
continue;
if (getplane(n, &plane) &&
plane.pln_x == target->sct_x &&
plane.pln_y == target->sct_y &&
+ plane.pln_ship < 0 && plane.pln_land < 0 &&
!(plane.pln_flags & PLN_LAUNCHED))
planeno = n;
else
if (planeno < 0)
continue;
dam = 0;
- if (plp->plane.pln_nuketype != -1)
+ if (nuk_on_plane(&plp->plane) >= 0)
hitchance = 100;
else {
hitchance = pln_hitchance(&plp->plane, 0, EF_PLANE);
xyas(target->sct_x, target->sct_y, own));
putplane(plane.pln_uid, &plane);
collateral_damage(target->sct_x, target->sct_y, dam);
- next:
- ;
}
}
struct lndstr land;
struct emp_qelem *qp;
int unitno;
- int ignore, aaf, flak, hitchance;
+ int aaf, flak, hitchance;
struct plist *plp;
int nukedam;
int nunits;
(void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
prplane(&plp->plane), plp->bombs);
unitno = -1;
- ignore = 0;
- while (unitno < 0 && !player->aborted && !ignore) {
- if ((q = getstring(prompt, buf)) == 0 || *q == 0)
- continue;
- if (*q == '~') {
- ignore = 1;
+ while (unitno < 0) {
+ if ((q = getstring(prompt, buf)) == 0)
+ return;
+ if (*q == 0)
continue;
- }
+ if (*q == '~')
+ break;
if (*q == '?') {
unitsatxy(target->sct_x, target->sct_y, 0, 0);
continue;
}
- if (*q == 'd')
- goto next;
n = atoi(q);
if (n < 0)
continue;
if (getland(n, &land) && land.lnd_own &&
+ land.lnd_ship < 0 && land.lnd_land < 0 &&
land.lnd_x == target->sct_x && land.lnd_y == target->sct_y)
unitno = n;
else
continue;
aaf = lnd_aaf(&land);
- flak = (int)(techfact(land.lnd_tech, aaf) * 3.0);
- if (flak) {
+ if (aaf) {
+ flak = roundavg(techfact(land.lnd_tech,
+ aaf * 3.0 * land.lnd_effic / 100.0));
PR(land.lnd_own,
"Flak! Firing flak guns from unit %s (aa rating %d)\n",
prland(&land), aaf);
}
dam = 0;
- if (plp->plane.pln_nuketype != -1)
+ if (nuk_on_plane(&plp->plane) >= 0)
hitchance = 100;
else {
hitchance = pln_hitchance(&plp->plane,
nreport(player->cnum, N_UNIT_BOMB, own, 1);
putland(land.lnd_uid, &land);
collateral_damage(target->sct_x, target->sct_y, dam);
- next:
- ;
}
}
plp = (struct plist *)qp;
if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
continue;
- if (plp->bombs || plp->plane.pln_nuketype != -1)
+ if (plp->bombs || nuk_on_plane(&plp->plane) >= 0)
dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
's', &nukedam, 1);
}