Factor common plane damage code into ac_damage_plane()

Out of ac_planedamage() and pinflak_planedamage().
This commit is contained in:
Markus Armbruster 2010-06-17 07:47:45 +02:00
parent 1a4fc50d57
commit aa5bb9790c
3 changed files with 23 additions and 38 deletions

View file

@ -165,6 +165,7 @@ extern int pln_next_on_unit(int);
extern int ac_flak_dam(int, int, int);
extern void ac_encounter(struct emp_qelem *, struct emp_qelem *, coord,
coord, char *, int);
extern int ac_damage_plane(struct plnstr *, natid, int, int, char *);
/* src/lib/subs/aswplnsubs.c */
extern int on_shiplist(int, struct shiplist *);

View file

@ -805,40 +805,16 @@ pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
int flak)
{
int disp;
char dmess[255];
int eff;
natid plane_owner;
char dmess[14];
int dam;
dam = ac_flak_dam(flak, pln_def(pp), pcp->pl_flags);
disp = 0;
plane_owner = pp->pln_own;
eff = pp->pln_effic;
if (dam <= 0)
return 0;
memset(dmess, 0, sizeof(dmess));
eff -= dam;
if (eff < 0)
eff = 0;
if (eff < PLANE_MINEFF) {
sprintf(dmess, " -- shot down");
disp = 1;
} else if (eff < 80 && chance((80 - eff) / 100.0)) {
sprintf(dmess, " -- aborted @%d%%", eff);
disp = 2;
}
PR(plane_owner, " Flak! %s %s takes %d%s.\n",
cname(pp->pln_own), prplane(pp), dam, dmess);
disp = ac_damage_plane(pp, from, dam, 1, dmess);
PR(pp->pln_own, " Flak! %s %s takes %d%s%s.\n",
cname(pp->pln_own), prplane(pp), dam, *dmess ? " --" : "", dmess);
pp->pln_effic = eff;
pp->pln_mobil -= MIN(32 + pp->pln_mobil, dam / 2);
if (disp == 1) {
if (from != 0)
nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
}
putplane(pp->pln_uid, pp);
if (disp > 0)
return 1;
return 0;
return disp > 0;
}

View file

@ -525,17 +525,27 @@ static void
ac_planedamage(struct plist *plp, natid from, int dam, int flak,
char *mesg)
{
struct plnstr *pp;
int disp = ac_damage_plane(&plp->plane, from, dam, flak, mesg);
if (disp) {
pln_put1(plp);
} else
putplane(plp->plane.pln_uid, &plp->plane);
}
int
ac_damage_plane(struct plnstr *pp, natid from, int dam, int flak,
char *mesg)
{
int eff, disp;
*mesg = 0;
if (dam <= 0) {
if (!flak)
snprintf(mesg, 14, " no damage");
return;
return 0;
}
pp = &plp->plane;
eff = pp->pln_effic - dam;
if (eff < 0)
eff = 0;
@ -552,12 +562,10 @@ ac_planedamage(struct plist *plp, natid from, int dam, int flak,
pp->pln_effic = eff;
pp->pln_mobil -= MIN(32 + pp->pln_mobil, dam / 2);
if (disp) {
if (disp == 1 && from != 0 && (plp->pcp->pl_flags & P_M) == 0)
if (disp == 1 && from != 0 && !(plchr[pp->pln_type].pl_flags & P_M))
nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
pln_put1(plp);
} else
putplane(pp->pln_uid, pp);
return disp;
}
static void