Factor common plane damage code into ac_damage_plane()
Out of ac_planedamage() and pinflak_planedamage().
This commit is contained in:
parent
1a4fc50d57
commit
aa5bb9790c
3 changed files with 23 additions and 38 deletions
|
@ -165,6 +165,7 @@ extern int pln_next_on_unit(int);
|
||||||
extern int ac_flak_dam(int, int, int);
|
extern int ac_flak_dam(int, int, int);
|
||||||
extern void ac_encounter(struct emp_qelem *, struct emp_qelem *, coord,
|
extern void ac_encounter(struct emp_qelem *, struct emp_qelem *, coord,
|
||||||
coord, char *, int);
|
coord, char *, int);
|
||||||
|
extern int ac_damage_plane(struct plnstr *, natid, int, int, char *);
|
||||||
|
|
||||||
/* src/lib/subs/aswplnsubs.c */
|
/* src/lib/subs/aswplnsubs.c */
|
||||||
extern int on_shiplist(int, struct shiplist *);
|
extern int on_shiplist(int, struct shiplist *);
|
||||||
|
|
|
@ -805,40 +805,16 @@ pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
|
||||||
int flak)
|
int flak)
|
||||||
{
|
{
|
||||||
int disp;
|
int disp;
|
||||||
char dmess[255];
|
char dmess[14];
|
||||||
int eff;
|
|
||||||
natid plane_owner;
|
|
||||||
int dam;
|
int dam;
|
||||||
|
|
||||||
dam = ac_flak_dam(flak, pln_def(pp), pcp->pl_flags);
|
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)
|
if (dam <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
memset(dmess, 0, sizeof(dmess));
|
disp = ac_damage_plane(pp, from, dam, 1, dmess);
|
||||||
eff -= dam;
|
PR(pp->pln_own, " Flak! %s %s takes %d%s%s.\n",
|
||||||
if (eff < 0)
|
cname(pp->pln_own), prplane(pp), dam, *dmess ? " --" : "", dmess);
|
||||||
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);
|
|
||||||
|
|
||||||
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);
|
putplane(pp->pln_uid, pp);
|
||||||
|
return disp > 0;
|
||||||
if (disp > 0)
|
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -525,17 +525,27 @@ static void
|
||||||
ac_planedamage(struct plist *plp, natid from, int dam, int flak,
|
ac_planedamage(struct plist *plp, natid from, int dam, int flak,
|
||||||
char *mesg)
|
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;
|
int eff, disp;
|
||||||
|
|
||||||
*mesg = 0;
|
*mesg = 0;
|
||||||
if (dam <= 0) {
|
if (dam <= 0) {
|
||||||
if (!flak)
|
if (!flak)
|
||||||
snprintf(mesg, 14, " no damage");
|
snprintf(mesg, 14, " no damage");
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pp = &plp->plane;
|
|
||||||
eff = pp->pln_effic - dam;
|
eff = pp->pln_effic - dam;
|
||||||
if (eff < 0)
|
if (eff < 0)
|
||||||
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_effic = eff;
|
||||||
pp->pln_mobil -= MIN(32 + pp->pln_mobil, dam / 2);
|
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);
|
nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
|
||||||
pln_put1(plp);
|
return disp;
|
||||||
} else
|
|
||||||
putplane(pp->pln_uid, pp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue