Fix and enable collateral damage for missing missiles
Collateral damage was disabled, because after msl_hit() reported a miss, the missile may or may not have reached the target. Fix by splitting msl_launch() off msl_hit(). Drop the disabled collateral damage code for sector targets, because sectors can't be missed. Enable it for ships and land units. Since msl_launch() returns whether the missile is sub-launched, drop launch_missile() parameter sublaunch, and simplify its caller.
This commit is contained in:
parent
e7fec28009
commit
fd894d9864
6 changed files with 66 additions and 81 deletions
|
@ -492,8 +492,9 @@ extern int move_ground(struct sctstr *, struct sctstr *,
|
||||||
int, int *);
|
int, int *);
|
||||||
extern int fly_map(coord, coord);
|
extern int fly_map(coord, coord);
|
||||||
/* mslsub.c */
|
/* mslsub.c */
|
||||||
extern int msl_hit(struct plnstr *, int, int, int, int, char *,
|
extern int msl_launch(struct plnstr *, int, char *, coord, coord, natid,
|
||||||
coord, coord, int);
|
int *);
|
||||||
|
extern int msl_hit(struct plnstr *, int, int, int, int, int, natid);
|
||||||
extern void msl_sel(struct emp_qelem *, coord, coord, natid, int,
|
extern void msl_sel(struct emp_qelem *, coord, coord, natid, int,
|
||||||
int, int);
|
int, int);
|
||||||
extern int msl_abm_intercept(struct plnstr *, coord, coord, int);
|
extern int msl_abm_intercept(struct plnstr *, coord, coord, int);
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
#include "ship.h"
|
#include "ship.h"
|
||||||
|
|
||||||
static int launch_as(struct plnstr *pp);
|
static int launch_as(struct plnstr *pp);
|
||||||
static int launch_missile(struct plnstr *pp, int sublaunch);
|
static int launch_missile(struct plnstr *pp);
|
||||||
static int launch_sat(struct plnstr *pp);
|
static int launch_sat(struct plnstr *pp);
|
||||||
static int msl_equip(struct plnstr *, char);
|
static int msl_equip(struct plnstr *, char);
|
||||||
|
|
||||||
|
@ -59,8 +59,6 @@ laun(void)
|
||||||
{
|
{
|
||||||
struct nstr_item nstr;
|
struct nstr_item nstr;
|
||||||
struct plnstr plane;
|
struct plnstr plane;
|
||||||
struct shpstr ship;
|
|
||||||
int sublaunch;
|
|
||||||
struct plchrstr *pcp;
|
struct plchrstr *pcp;
|
||||||
int retval, gone;
|
int retval, gone;
|
||||||
|
|
||||||
|
@ -101,17 +99,11 @@ laun(void)
|
||||||
}
|
}
|
||||||
if (!pln_airbase_ok(&plane, 1, 1))
|
if (!pln_airbase_ok(&plane, 1, 1))
|
||||||
continue;
|
continue;
|
||||||
sublaunch = 0;
|
|
||||||
if (plane.pln_ship >= 0) {
|
|
||||||
getship(plane.pln_ship, &ship);
|
|
||||||
if (mchr[(int)ship.shp_type].m_flags & M_SUB)
|
|
||||||
sublaunch = 1;
|
|
||||||
}
|
|
||||||
pr("%s at %s; range %d, eff %d%%\n", prplane(&plane),
|
pr("%s at %s; range %d, eff %d%%\n", prplane(&plane),
|
||||||
xyas(plane.pln_x, plane.pln_y, player->cnum),
|
xyas(plane.pln_x, plane.pln_y, player->cnum),
|
||||||
plane.pln_range, plane.pln_effic);
|
plane.pln_range, plane.pln_effic);
|
||||||
if (!(pcp->pl_flags & P_O)) {
|
if (!(pcp->pl_flags & P_O)) {
|
||||||
retval = launch_missile(&plane, sublaunch);
|
retval = launch_missile(&plane);
|
||||||
gone = 1;
|
gone = 1;
|
||||||
} else if ((pcp->pl_flags & (P_M | P_O)) == (P_M | P_O)) {
|
} else if ((pcp->pl_flags & (P_M | P_O)) == (P_M | P_O)) {
|
||||||
retval = launch_as(&plane);
|
retval = launch_as(&plane);
|
||||||
|
@ -160,8 +152,10 @@ launch_as(struct plnstr *pp)
|
||||||
}
|
}
|
||||||
if (msl_equip(pp, 'i') < 0)
|
if (msl_equip(pp, 'i') < 0)
|
||||||
return RET_FAIL;
|
return RET_FAIL;
|
||||||
if (msl_hit(pp, pln_def(&plane), EF_PLANE, 0, 0,
|
if (msl_launch(pp, EF_PLANE, prplane(&plane),
|
||||||
prplane(&plane), plane.pln_x, plane.pln_y, plane.pln_own)) {
|
plane.pln_x, plane.pln_y, plane.pln_own, NULL) < 0)
|
||||||
|
return RET_OK;
|
||||||
|
if (msl_hit(pp, pln_def(&plane), EF_PLANE, 0, 0, 0, plane.pln_own)) {
|
||||||
pr("Satellite shot down\n");
|
pr("Satellite shot down\n");
|
||||||
mpr(plane.pln_own, "%s anti-sat destroyed %s over %s\n",
|
mpr(plane.pln_own, "%s anti-sat destroyed %s over %s\n",
|
||||||
cname(player->cnum), prplane(&plane),
|
cname(player->cnum), prplane(&plane),
|
||||||
|
@ -175,16 +169,15 @@ launch_as(struct plnstr *pp)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Launch missile PP.
|
* Launch missile PP.
|
||||||
* If SUBLAUNCH, it's sub-launched.
|
|
||||||
* Return RET_OK if launched (even when missile explodes),
|
* Return RET_OK if launched (even when missile explodes),
|
||||||
* else RET_SYN or RET_FAIL.
|
* else RET_SYN or RET_FAIL.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
launch_missile(struct plnstr *pp, int sublaunch)
|
launch_missile(struct plnstr *pp)
|
||||||
{
|
{
|
||||||
struct plchrstr *pcp = plchr + pp->pln_type;
|
struct plchrstr *pcp = plchr + pp->pln_type;
|
||||||
coord sx, sy;
|
coord sx, sy;
|
||||||
int n, dam;
|
int n, dam, sublaunch;
|
||||||
char *cp;
|
char *cp;
|
||||||
struct mchrstr *mcp;
|
struct mchrstr *mcp;
|
||||||
struct shpstr target_ship;
|
struct shpstr target_ship;
|
||||||
|
@ -250,18 +243,12 @@ launch_missile(struct plnstr *pp, int sublaunch)
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!msl_hit(pp, SECT_HARDTARGET, EF_SECTOR, N_SCT_MISS,
|
if (msl_launch(pp, EF_SECTOR, "sector", sx, sy, sect.sct_own,
|
||||||
N_SCT_SMISS, "sector", sx, sy, sect.sct_own)) {
|
&sublaunch) < 0)
|
||||||
#if 0
|
|
||||||
/*
|
|
||||||
* FIXME want collateral damage on miss, but we get here
|
|
||||||
* too when launch fails or missile is intercepted
|
|
||||||
*/
|
|
||||||
dam = pln_damage(pp, 's', 0);
|
|
||||||
collateral_damage(sect.sct_x, sect.sct_y, dam, 0);
|
|
||||||
#endif
|
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
if (!msl_hit(pp, SECT_HARDTARGET, EF_SECTOR,
|
||||||
|
N_SCT_MISS, N_SCT_SMISS, sublaunch, sect.sct_own))
|
||||||
|
CANT_REACH();
|
||||||
if (getnuke(nuk_on_plane(pp), &nuke))
|
if (getnuke(nuk_on_plane(pp), &nuke))
|
||||||
detonate(&nuke, sx, sy, pp->pln_flags & PLN_AIRBURST);
|
detonate(&nuke, sx, sy, pp->pln_flags & PLN_AIRBURST);
|
||||||
else {
|
else {
|
||||||
|
@ -285,15 +272,16 @@ launch_missile(struct plnstr *pp, int sublaunch)
|
||||||
} else {
|
} else {
|
||||||
if (msl_equip(pp, 'p') < 0)
|
if (msl_equip(pp, 'p') < 0)
|
||||||
return RET_FAIL;
|
return RET_FAIL;
|
||||||
|
if (msl_launch(pp, EF_SHIP, prship(&target_ship),
|
||||||
|
target_ship.shp_x, target_ship.shp_y,
|
||||||
|
target_ship.shp_own, &sublaunch) < 0)
|
||||||
|
return RET_OK;
|
||||||
if (!msl_hit(pp, shp_hardtarget(&target_ship), EF_SHIP,
|
if (!msl_hit(pp, shp_hardtarget(&target_ship), EF_SHIP,
|
||||||
N_SHP_MISS, N_SHP_SMISS, prship(&target_ship),
|
N_SHP_MISS, N_SHP_SMISS, sublaunch,
|
||||||
target_ship.shp_x, target_ship.shp_y,
|
|
||||||
target_ship.shp_own)) {
|
target_ship.shp_own)) {
|
||||||
pr("splash\n");
|
pr("splash\n");
|
||||||
#if 0 /* FIXME see above */
|
|
||||||
dam = pln_damage(pp, 'p', 0);
|
dam = pln_damage(pp, 'p', 0);
|
||||||
collateral_damage(target_ship.shp_x, target_ship.shp_y, dam, 0);
|
collateral_damage(target_ship.shp_x, target_ship.shp_y, dam);
|
||||||
#endif
|
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
dam = pln_damage(pp, 'p', 1);
|
dam = pln_damage(pp, 'p', 1);
|
||||||
|
|
|
@ -720,7 +720,7 @@ lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
|
||||||
{
|
{
|
||||||
int mindam = lnd_count(list) * 20;
|
int mindam = lnd_count(list) * 20;
|
||||||
int hardtarget = lnd_easiest_target(list);
|
int hardtarget = lnd_easiest_target(list);
|
||||||
int dam, newdam;
|
int dam, newdam, sublaunch;
|
||||||
struct plist *plp;
|
struct plist *plp;
|
||||||
struct emp_qelem msl_list, *qp, *newqp;
|
struct emp_qelem msl_list, *qp, *newqp;
|
||||||
|
|
||||||
|
@ -732,22 +732,18 @@ lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
|
||||||
plp = (struct plist *)qp;
|
plp = (struct plist *)qp;
|
||||||
|
|
||||||
if (dam < mindam && mission_pln_equip(plp, NULL, 'p') >= 0) {
|
if (dam < mindam && mission_pln_equip(plp, NULL, 'p') >= 0) {
|
||||||
|
if (msl_launch(&plp->plane, EF_LAND, "troops",
|
||||||
|
newx, newy, victim, &sublaunch) < 0)
|
||||||
|
goto use_up_msl;
|
||||||
if (msl_hit(&plp->plane, hardtarget, EF_LAND,
|
if (msl_hit(&plp->plane, hardtarget, EF_LAND,
|
||||||
N_LND_MISS, N_LND_SMISS,
|
N_LND_MISS, N_LND_SMISS, sublaunch, victim)) {
|
||||||
"troops", newx, newy, victim)) {
|
|
||||||
newdam = pln_damage(&plp->plane, 'p', 1);
|
newdam = pln_damage(&plp->plane, 'p', 1);
|
||||||
dam += newdam;
|
dam += newdam;
|
||||||
#if 0
|
|
||||||
/*
|
|
||||||
* FIXME want collateral damage on miss, but we get here
|
|
||||||
* too when launch fails or missile is intercepted
|
|
||||||
*/
|
|
||||||
} else {
|
} else {
|
||||||
/* Missiles that miss have to hit somewhere! */
|
|
||||||
newdam = pln_damage(&plp->plane, 'p', 0);
|
newdam = pln_damage(&plp->plane, 'p', 0);
|
||||||
collateral_damage(newx, newy, newdam);
|
collateral_damage(newx, newy, newdam);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
use_up_msl:
|
||||||
plp->plane.pln_effic = 0;
|
plp->plane.pln_effic = 0;
|
||||||
putplane(plp->plane.pln_uid, &plp->plane);
|
putplane(plp->plane.pln_uid, &plp->plane);
|
||||||
}
|
}
|
||||||
|
|
|
@ -389,7 +389,7 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
|
||||||
struct plchrstr *pcp;
|
struct plchrstr *pcp;
|
||||||
int dam = 0, dam2;
|
int dam = 0, dam2;
|
||||||
natid plane_owner = 0;
|
natid plane_owner = 0;
|
||||||
int md, range, air_dam;
|
int md, range, air_dam, sublaunch;
|
||||||
double hitchance, vrange;
|
double hitchance, vrange;
|
||||||
int targeting_ships = *s == 's'; /* "subs" or "ships" FIXME gross! */
|
int targeting_ships = *s == 's'; /* "subs" or "ships" FIXME gross! */
|
||||||
|
|
||||||
|
@ -562,22 +562,15 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
|
||||||
&& !CANT_HAPPEN(hardtarget != SECT_HARDTARGET
|
&& !CANT_HAPPEN(hardtarget != SECT_HARDTARGET
|
||||||
|| (plp->pcp->pl_flags & P_MAR))
|
|| (plp->pcp->pl_flags & P_MAR))
|
||||||
&& mission_pln_equip(plp, NULL, 'p') >= 0) {
|
&& mission_pln_equip(plp, NULL, 'p') >= 0) {
|
||||||
if (msl_hit(&plp->plane, SECT_HARDTARGET, EF_SECTOR,
|
if (msl_launch(&plp->plane, EF_SECTOR, "sector", x, y, victim,
|
||||||
N_SCT_MISS, N_SCT_SMISS,
|
&sublaunch) < 0)
|
||||||
"sector", x, y, victim)) {
|
goto use_up_msl;
|
||||||
dam2 = pln_damage(&plp->plane, 'p', 1);
|
if (!msl_hit(&plp->plane, SECT_HARDTARGET, EF_SECTOR,
|
||||||
air_dam += dam2;
|
N_SCT_MISS, N_SCT_SMISS, sublaunch, victim))
|
||||||
#if 0
|
CANT_REACH();
|
||||||
/*
|
dam2 = pln_damage(&plp->plane, 'p', 1);
|
||||||
* FIXME want collateral damage on miss, but we get here
|
air_dam += dam2;
|
||||||
* too when launch fails or missile is intercepted
|
use_up_msl:
|
||||||
*/
|
|
||||||
} else {
|
|
||||||
/* Missiles that miss have to hit somewhere! */
|
|
||||||
dam2 = pln_damage(&plp->plane, 'p', 0);
|
|
||||||
collateral_damage(x, y, dam2);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
plp->plane.pln_effic = 0;
|
plp->plane.pln_effic = 0;
|
||||||
putplane(plp->plane.pln_uid, &plp->plane);
|
putplane(plp->plane.pln_uid, &plp->plane);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
* Known contributors to this file:
|
* Known contributors to this file:
|
||||||
* Ken Stevens, 1995
|
* Ken Stevens, 1995
|
||||||
* Steve McClure, 1996-2000
|
* Steve McClure, 1996-2000
|
||||||
|
* Markus Armbruster, 2004-2009
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
@ -54,15 +55,13 @@
|
||||||
#include "xy.h"
|
#include "xy.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
msl_hit(struct plnstr *pp, int hardtarget, int type, int news_item,
|
msl_launch(struct plnstr *pp, int type, char *what, coord x, coord y,
|
||||||
int snews_item, char *what, coord x, coord y, int victim)
|
natid victim, int *sublaunchp)
|
||||||
{
|
{
|
||||||
int hit;
|
|
||||||
struct shpstr ship;
|
struct shpstr ship;
|
||||||
struct sctstr sect;
|
struct sctstr sect;
|
||||||
int sublaunch = 0;
|
int sublaunch = 0;
|
||||||
struct plchrstr *pcp = plchr + pp->pln_type;
|
struct plchrstr *pcp = plchr + pp->pln_type;
|
||||||
int hitchance;
|
|
||||||
char *from;
|
char *from;
|
||||||
int dam;
|
int dam;
|
||||||
|
|
||||||
|
@ -108,7 +107,7 @@ msl_hit(struct plnstr *pp, int hardtarget, int type, int news_item,
|
||||||
putsect(§);
|
putsect(§);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
CANT_HAPPEN(pp->pln_flags & PLN_LAUNCHED);
|
CANT_HAPPEN(pp->pln_flags & PLN_LAUNCHED);
|
||||||
|
@ -123,14 +122,26 @@ msl_hit(struct plnstr *pp, int hardtarget, int type, int news_item,
|
||||||
|
|
||||||
if ((pcp->pl_flags & P_T && !(pcp->pl_flags & P_MAR))) {
|
if ((pcp->pl_flags & P_T && !(pcp->pl_flags & P_MAR))) {
|
||||||
if (msl_abm_intercept(pp, x, y, sublaunch))
|
if (msl_abm_intercept(pp, x, y, sublaunch))
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
if (pcp->pl_flags & P_MAR) {
|
if (pcp->pl_flags & P_MAR) {
|
||||||
if (shp_missile_defense(x, y, pp->pln_own, pln_def(pp))) {
|
if (shp_missile_defense(x, y, pp->pln_own, pln_def(pp))) {
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sublaunchp)
|
||||||
|
*sublaunchp = sublaunch;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
msl_hit(struct plnstr *pp, int hardtarget, int type,
|
||||||
|
int news_item, int snews_item, int sublaunch, natid victim)
|
||||||
|
{
|
||||||
|
struct plchrstr *pcp = plchr + pp->pln_type;
|
||||||
|
int hitchance, hit;
|
||||||
|
|
||||||
if (nuk_on_plane(pp) >= 0) {
|
if (nuk_on_plane(pp) >= 0) {
|
||||||
mpr(pp->pln_own, "\tArming nuclear warheads...\n");
|
mpr(pp->pln_own, "\tArming nuclear warheads...\n");
|
||||||
hit = 1;
|
hit = 1;
|
||||||
|
@ -294,8 +305,9 @@ msl_intercept(struct plnstr *msl, struct sctstr *sp, int sublaunch,
|
||||||
def_name, who, att_name, cname(sp->sct_own));
|
def_name, who, att_name, cname(sp->sct_own));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msl_hit(pp, pln_def(msl), EF_PLANE, 0, 0,
|
if (msl_launch(pp, EF_PLANE, att_name, sp->sct_x, sp->sct_y,
|
||||||
att_name, sp->sct_x, sp->sct_y, msl->pln_own)) {
|
msl->pln_own, NULL) >= 0
|
||||||
|
&& msl_hit(pp, pln_def(msl), EF_PLANE, 0, 0, 0, msl->pln_own)) {
|
||||||
mpr(msl->pln_own, "%s destroyed by %s %s!\n",
|
mpr(msl->pln_own, "%s destroyed by %s %s!\n",
|
||||||
att_name, cname(pp->pln_own), def_name);
|
att_name, cname(pp->pln_own), def_name);
|
||||||
mpr(sp->sct_own, "%s %s intercepted!\n", who, att_name);
|
mpr(sp->sct_own, "%s %s intercepted!\n", who, att_name);
|
||||||
|
|
|
@ -480,7 +480,7 @@ static int
|
||||||
shp_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
|
shp_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
|
||||||
natid victim)
|
natid victim)
|
||||||
{
|
{
|
||||||
int dam;
|
int dam, sublaunch;
|
||||||
int stopping = 0;
|
int stopping = 0;
|
||||||
struct emp_qelem msl_list, *qp, *newqp;
|
struct emp_qelem msl_list, *qp, *newqp;
|
||||||
struct plist *plp;
|
struct plist *plp;
|
||||||
|
@ -494,11 +494,12 @@ shp_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
|
||||||
|
|
||||||
mvs = most_valuable_ship(list, newx, newy);
|
mvs = most_valuable_ship(list, newx, newy);
|
||||||
if (mvs && mission_pln_equip(plp, NULL, 'p') >= 0) {
|
if (mvs && mission_pln_equip(plp, NULL, 'p') >= 0) {
|
||||||
|
if (msl_launch(&plp->plane, EF_SHIP, prship(&mvs->unit.ship),
|
||||||
|
newx, newy, victim, &sublaunch) < 0)
|
||||||
|
goto use_up_msl;
|
||||||
if (msl_hit(&plp->plane,
|
if (msl_hit(&plp->plane,
|
||||||
shp_hardtarget(&mvs->unit.ship),
|
shp_hardtarget(&mvs->unit.ship), EF_SHIP,
|
||||||
EF_SHIP, N_SHP_MISS, N_SHP_SMISS,
|
N_SHP_MISS, N_SHP_SMISS, sublaunch, victim)) {
|
||||||
prship(&mvs->unit.ship),
|
|
||||||
newx, newy, victim)) {
|
|
||||||
dam = pln_damage(&plp->plane, 'p', 1);
|
dam = pln_damage(&plp->plane, 'p', 1);
|
||||||
if (dam) {
|
if (dam) {
|
||||||
mpr(victim,
|
mpr(victim,
|
||||||
|
@ -507,17 +508,11 @@ shp_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
|
||||||
shp_damage_one(mvs, dam);
|
shp_damage_one(mvs, dam);
|
||||||
stopping = 1;
|
stopping = 1;
|
||||||
}
|
}
|
||||||
#if 0
|
|
||||||
/*
|
|
||||||
* FIXME want collateral damage on miss, but we get here
|
|
||||||
* too when launch fails or missile is intercepted
|
|
||||||
*/
|
|
||||||
} else {
|
} else {
|
||||||
/* Missiles that miss have to hit somewhere! */
|
|
||||||
dam = pln_damage(&plp->plane, 'p', 0);
|
dam = pln_damage(&plp->plane, 'p', 0);
|
||||||
collateral_damage(newx, newy, dam);
|
collateral_damage(newx, newy, dam);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
use_up_msl:
|
||||||
plp->plane.pln_effic = 0;
|
plp->plane.pln_effic = 0;
|
||||||
putplane(plp->plane.pln_uid, &plp->plane);
|
putplane(plp->plane.pln_uid, &plp->plane);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue