Get rid of msl_launch_mindam()
It's awkward, especially in shp_missile_interdiction(). Inline into callers and simplify.
This commit is contained in:
parent
e043ea4531
commit
eace95fab8
5 changed files with 96 additions and 101 deletions
|
@ -497,8 +497,6 @@ extern int msl_hit(struct plnstr *, int, int, int, int, char *,
|
||||||
coord, coord, int);
|
coord, coord, int);
|
||||||
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_launch_mindam(struct emp_qelem *, coord, coord, int,
|
|
||||||
int, int, char *, int);
|
|
||||||
/* mtch.c */
|
/* mtch.c */
|
||||||
extern int comtch(char *, struct cmndstr *, int);
|
extern int comtch(char *, struct cmndstr *, int);
|
||||||
/* natarg.c */
|
/* natarg.c */
|
||||||
|
|
|
@ -718,25 +718,47 @@ static int
|
||||||
lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
|
lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
|
||||||
natid victim)
|
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;
|
struct emp_qelem msl_list, *qp, *newqp;
|
||||||
|
|
||||||
msl_sel(&msl_list, newx, newy, victim, P_T, P_MAR, MI_INTERDICT);
|
msl_sel(&msl_list, newx, newy, victim, P_T, P_MAR, MI_INTERDICT);
|
||||||
|
|
||||||
dam = msl_launch_mindam(&msl_list, newx, newy,
|
dam = 0;
|
||||||
lnd_easiest_target(list), EF_LAND,
|
for (qp = msl_list.q_back; qp != &msl_list; qp = newqp) {
|
||||||
lnd_count(list) * 20, "troops", victim);
|
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) {
|
if (dam) {
|
||||||
mpr(victim, "missile interdiction mission does %d damage!\n", dam);
|
mpr(victim, "missile interdiction mission does %d damage!\n", dam);
|
||||||
collateral_damage(newx, newy, 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;
|
return dam;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 = 0;
|
int md, range, air_dam;
|
||||||
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! */
|
||||||
|
|
||||||
|
@ -547,19 +547,36 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!QEMPTY(&missiles)) {
|
|
||||||
/* I arbitrarily chose 100 mindam -KHS */
|
air_dam = 0;
|
||||||
dam +=
|
for (qp = missiles.q_back; qp != &missiles; qp = newqp) {
|
||||||
msl_launch_mindam(&missiles, x, y, hardtarget, EF_SECTOR, 100,
|
newqp = qp->q_back;
|
||||||
"sector", victim);
|
plp = (struct plist *)qp;
|
||||||
qp = missiles.q_forw;
|
|
||||||
while (qp != (&missiles)) {
|
if (air_dam < 100 && mission_pln_equip(plp, NULL, 'p') >= 0) {
|
||||||
newqp = qp->q_forw;
|
if (msl_hit(&plp->plane, hardtarget, EF_SECTOR,
|
||||||
emp_remque(qp);
|
N_SCT_MISS, N_SCT_SMISS,
|
||||||
free(qp);
|
"sector", x, y, victim)) {
|
||||||
qp = newqp;
|
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);
|
||||||
}
|
}
|
||||||
|
dam += air_dam;
|
||||||
|
|
||||||
if (QEMPTY(&bombers)) {
|
if (QEMPTY(&bombers)) {
|
||||||
qp = list->q_forw;
|
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);
|
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) {
|
for (qp = airp.q_forw; qp != (&airp); qp = qp->q_forw) {
|
||||||
struct airport *air;
|
struct airport *air;
|
||||||
char buf[512];
|
char buf[512];
|
||||||
|
|
|
@ -353,57 +353,3 @@ msl_intercept(coord x, coord y, natid bombown, int hardtarget,
|
||||||
}
|
}
|
||||||
return 0;
|
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;
|
|
||||||
}
|
|
||||||
|
|
|
@ -479,37 +479,48 @@ shp_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
|
||||||
natid victim)
|
natid victim)
|
||||||
{
|
{
|
||||||
int dam;
|
int dam;
|
||||||
int twotries;
|
|
||||||
int stopping = 0;
|
int stopping = 0;
|
||||||
struct emp_qelem msl_list, *qp, *newqp;
|
struct emp_qelem msl_list, *qp, *newqp;
|
||||||
|
struct plist *plp;
|
||||||
struct ulist *mvs;
|
struct ulist *mvs;
|
||||||
char what[512];
|
|
||||||
|
|
||||||
msl_sel(&msl_list, newx, newy, victim, P_T | P_MAR, 0, MI_INTERDICT);
|
msl_sel(&msl_list, newx, newy, victim, P_T | P_MAR, 0, MI_INTERDICT);
|
||||||
|
|
||||||
twotries = 0;
|
for (qp = msl_list.q_back; qp != &msl_list; qp = newqp) {
|
||||||
while (!QEMPTY(&msl_list) && (mvs = most_valuable_ship(list))) {
|
newqp = qp->q_back;
|
||||||
sprintf(what, "%s", prship(&mvs->unit.ship));
|
plp = (struct plist *)qp;
|
||||||
dam = msl_launch_mindam(&msl_list, newx, newy,
|
|
||||||
shp_hardtarget(&mvs->unit.ship),
|
mvs = most_valuable_ship(list);
|
||||||
EF_SHIP, 1, what, victim);
|
if (mvs && mission_pln_equip(plp, NULL, 'p') >= 0) {
|
||||||
if (dam) {
|
if (msl_hit(&plp->plane,
|
||||||
mpr(victim,
|
shp_hardtarget(&mvs->unit.ship),
|
||||||
"missile interdiction mission does %d damage to %s!\n",
|
EF_SHIP, N_SHP_MISS, N_SHP_SMISS,
|
||||||
dam, what);
|
prship(&mvs->unit.ship),
|
||||||
shp_damage_one(mvs, dam);
|
newx, newy, victim)) {
|
||||||
twotries = 0;
|
dam = pln_damage(&plp->plane, 'p', 1);
|
||||||
stopping |= 1;
|
if (dam) {
|
||||||
} else if (++twotries >= 2) {
|
mpr(victim,
|
||||||
break;
|
"missile interdiction mission does %d damage to %s!\n",
|
||||||
|
dam, prship(&mvs->unit.ship));
|
||||||
|
shp_damage_one(mvs, dam);
|
||||||
|
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);
|
emp_remque(qp);
|
||||||
free(qp);
|
free(qp);
|
||||||
qp = newqp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return stopping;
|
return stopping;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue