Get rid of msl_launch_mindam()

It's awkward, especially in shp_missile_interdiction().  Inline into
callers and simplify.
This commit is contained in:
Markus Armbruster 2009-10-10 16:32:18 -04:00
parent e043ea4531
commit eace95fab8
5 changed files with 96 additions and 101 deletions

View file

@ -497,8 +497,6 @@ extern int msl_hit(struct plnstr *, int, int, int, int, char *,
coord, coord, int);
extern void msl_sel(struct emp_qelem *, coord, coord, natid, int,
int, int);
extern int msl_launch_mindam(struct emp_qelem *, coord, coord, int,
int, int, char *, int);
/* mtch.c */
extern int comtch(char *, struct cmndstr *, int);
/* natarg.c */

View file

@ -718,25 +718,47 @@ static int
lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
natid victim)
{
int dam;
int mindam = lnd_count(list) * 20;
int hardtarget = lnd_easiest_target(list);
int dam, newdam;
struct plist *plp;
struct emp_qelem msl_list, *qp, *newqp;
msl_sel(&msl_list, newx, newy, victim, P_T, P_MAR, MI_INTERDICT);
dam = msl_launch_mindam(&msl_list, newx, newy,
lnd_easiest_target(list), EF_LAND,
lnd_count(list) * 20, "troops", victim);
dam = 0;
for (qp = msl_list.q_back; qp != &msl_list; qp = newqp) {
newqp = qp->q_back;
plp = (struct plist *)qp;
if (dam < mindam && mission_pln_equip(plp, NULL, 'p') >= 0) {
if (msl_hit(&plp->plane, hardtarget, EF_LAND,
N_LND_MISS, N_LND_SMISS,
"troops", newx, newy, victim)) {
newdam = pln_damage(&plp->plane, 'p', 1);
dam += newdam;
#if 0
/*
* FIXME want collateral damage on miss, but we get here
* too when launch fails or missile is intercepted
*/
} else {
/* Missiles that miss have to hit somewhere! */
newdam = pln_damage(&plp->plane, 'p', 0);
collateral_damage(newx, newy, newdam);
#endif
}
plp->plane.pln_effic = 0;
putplane(plp->plane.pln_uid, &plp->plane);
}
emp_remque(qp);
free(qp);
}
if (dam) {
mpr(victim, "missile interdiction mission does %d damage!\n", dam);
collateral_damage(newx, newy, dam);
}
qp = msl_list.q_forw;
while (qp != msl_list.q_forw) {
newqp = qp->q_forw;
emp_remque(qp);
free(qp);
qp = newqp;
}
return dam;
}

View file

@ -389,7 +389,7 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
struct plchrstr *pcp;
int dam = 0, dam2;
natid plane_owner = 0;
int md, range, air_dam = 0;
int md, range, air_dam;
double hitchance, vrange;
int targeting_ships = *s == 's'; /* "subs" or "ships" FIXME gross! */
@ -547,19 +547,36 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
break;
}
}
if (!QEMPTY(&missiles)) {
/* I arbitrarily chose 100 mindam -KHS */
dam +=
msl_launch_mindam(&missiles, x, y, hardtarget, EF_SECTOR, 100,
"sector", victim);
qp = missiles.q_forw;
while (qp != (&missiles)) {
newqp = qp->q_forw;
air_dam = 0;
for (qp = missiles.q_back; qp != &missiles; qp = newqp) {
newqp = qp->q_back;
plp = (struct plist *)qp;
if (air_dam < 100 && mission_pln_equip(plp, NULL, 'p') >= 0) {
if (msl_hit(&plp->plane, hardtarget, EF_SECTOR,
N_SCT_MISS, N_SCT_SMISS,
"sector", x, y, victim)) {
dam2 = pln_damage(&plp->plane, 'p', 1);
air_dam += dam2;
#if 0
/*
* FIXME want collateral damage on miss, but we get here
* too when launch fails or missile is intercepted
*/
} 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;
putplane(plp->plane.pln_uid, &plp->plane);
}
emp_remque(qp);
free(qp);
qp = newqp;
}
}
dam += air_dam;
if (QEMPTY(&bombers)) {
qp = list->q_forw;
@ -593,6 +610,7 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
add_airport(&airp, plp->plane.pln_x, plp->plane.pln_y);
}
air_dam = 0;
for (qp = airp.q_forw; qp != (&airp); qp = qp->q_forw) {
struct airport *air;
char buf[512];

View file

@ -353,57 +353,3 @@ msl_intercept(coord x, coord y, natid bombown, int hardtarget,
}
return 0;
}
/* Keep launching missiles on list until mindam damage has been done */
int
msl_launch_mindam(struct emp_qelem *list, coord x, coord y, int hardtarget,
int type, int mindam, char *whatp, int victim)
{
struct emp_qelem *qp;
struct emp_qelem *next;
struct plist *plp;
int newdam, dam = 0;
int news_item;
int snews_item;
if (type == EF_SHIP) {
news_item = N_SHP_MISS;
snews_item = N_SHP_SMISS;
} else if (type == EF_LAND) {
news_item = N_LND_MISS;
snews_item = N_LND_SMISS;
} else {
news_item = N_SCT_MISS;
snews_item = N_SCT_SMISS;
}
for (qp = list->q_back; qp != list && dam < mindam;
qp = next) {
next = qp->q_back;
plp = (struct plist *)qp;
if (mission_pln_equip(plp, NULL, 'p') >= 0) {
if (msl_hit(&plp->plane,
hardtarget, type, news_item, snews_item,
whatp, x, y, victim)) {
newdam = pln_damage(&plp->plane, 'p', 1);
dam += newdam;
#if 0
/*
* FIXME want collateral damage on miss, but we get here
* too when launch fails or missile is intercepted
*/
} else {
/* Missiles that miss have to hit somewhere! */
newdam = pln_damage(&plp->plane, 'p', 0);
collateral_damage(x, y, newdam);
#endif
}
plp->plane.pln_effic = 0;
putplane(plp->plane.pln_uid, &plp->plane);
emp_remque(qp);
free(qp);
}
}
return dam;
}

View file

@ -479,37 +479,48 @@ shp_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
natid victim)
{
int dam;
int twotries;
int stopping = 0;
struct emp_qelem msl_list, *qp, *newqp;
struct plist *plp;
struct ulist *mvs;
char what[512];
msl_sel(&msl_list, newx, newy, victim, P_T | P_MAR, 0, MI_INTERDICT);
twotries = 0;
while (!QEMPTY(&msl_list) && (mvs = most_valuable_ship(list))) {
sprintf(what, "%s", prship(&mvs->unit.ship));
dam = msl_launch_mindam(&msl_list, newx, newy,
for (qp = msl_list.q_back; qp != &msl_list; qp = newqp) {
newqp = qp->q_back;
plp = (struct plist *)qp;
mvs = most_valuable_ship(list);
if (mvs && mission_pln_equip(plp, NULL, 'p') >= 0) {
if (msl_hit(&plp->plane,
shp_hardtarget(&mvs->unit.ship),
EF_SHIP, 1, what, victim);
EF_SHIP, N_SHP_MISS, N_SHP_SMISS,
prship(&mvs->unit.ship),
newx, newy, victim)) {
dam = pln_damage(&plp->plane, 'p', 1);
if (dam) {
mpr(victim,
"missile interdiction mission does %d damage to %s!\n",
dam, what);
dam, prship(&mvs->unit.ship));
shp_damage_one(mvs, dam);
twotries = 0;
stopping |= 1;
} else if (++twotries >= 2) {
break;
stopping = 1;
}
#if 0
/*
* FIXME want collateral damage on miss, but we get here
* too when launch fails or missile is intercepted
*/
} else {
/* Missiles that miss have to hit somewhere! */
dam = pln_damage(&plp->plane, 'p', 0);
collateral_damage(newx, newy, dam);
#endif
}
plp->plane.pln_effic = 0;
putplane(plp->plane.pln_uid, &plp->plane);
}
qp = msl_list.q_forw;
while (qp != msl_list.q_forw) {
newqp = qp->q_forw;
emp_remque(qp);
free(qp);
qp = newqp;
}
return stopping;