From ffc5d0cfd76db1a3565ee34cd7a614dfdb24aa7f Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 4 Mar 2008 21:09:32 +0100 Subject: [PATCH] Don't store plane stats in struct plnstr New pln_att(), pln_def(), pln_acc(), pln_range_max(), pln_load() replace the struct plnstr members with the same names. Make plane selectors att and def virtual. --- include/plane.h | 11 ++++---- src/lib/commands/arm.c | 2 +- src/lib/commands/bomb.c | 2 +- src/lib/commands/buil.c | 1 - src/lib/commands/laun.c | 2 +- src/lib/commands/pdump.c | 10 +++---- src/lib/commands/plan.c | 2 +- src/lib/commands/pstat.c | 8 +++--- src/lib/commands/rang.c | 6 ++--- src/lib/commands/sona.c | 2 +- src/lib/global/nsc.c | 20 ++++++++++++-- src/lib/global/plane.c | 30 +++++++++++++++++++++ src/lib/subs/aircombat.c | 16 +++++------ src/lib/subs/mission.c | 15 ++++++----- src/lib/subs/plnsub.c | 57 ++++++++++++++++++---------------------- 15 files changed, 111 insertions(+), 73 deletions(-) diff --git a/include/plane.h b/include/plane.h index 9528ea5a..6356a1eb 100644 --- a/include/plane.h +++ b/include/plane.h @@ -62,14 +62,8 @@ struct plnstr { short pln_radius; /* mission radius */ /* end of part matching struct empobj */ unsigned char pln_range; /* total distance, not radius */ - unsigned char pln_range_max; /* max range for this plane */ short pln_ship; /* pointer to carrier */ short pln_land; /* pointer to carrier */ - int pln_att; /* plane air-air attack/defense values */ - int pln_def; - int pln_acc; - int pln_load; - int pln_fuel; /* (unused) */ signed char pln_harden; /* for missiles */ signed char pln_nuketype; /* type of nuclear armament (if any) */ signed char pln_flags; /* State of the plane */ @@ -154,6 +148,11 @@ extern int pl_def(struct plchrstr *, int); extern int pl_acc(struct plchrstr *, int); extern int pl_range(struct plchrstr *, int); extern int pl_load(struct plchrstr *, int); +extern int pln_att(struct plnstr *); +extern int pln_def(struct plnstr *); +extern int pln_acc(struct plnstr *); +extern int pln_range_max(struct plnstr *); +extern int pln_load(struct plnstr *); /* src/lib/subs/aircombat.c */ extern void ac_combat_headers(natid, natid); diff --git a/src/lib/commands/arm.c b/src/lib/commands/arm.c index 03faadef..ce6db075 100644 --- a/src/lib/commands/arm.c +++ b/src/lib/commands/arm.c @@ -90,7 +90,7 @@ arm(void) } } ncp = &nchr[nuke.nuk_type]; - if (pl.pln_load < ncp->n_weight) { + if (pln_load(&pl) < ncp->n_weight) { pr("A %s cannot carry %s devices!\n", plc->pl_name, ncp->n_name); return RET_FAIL; diff --git a/src/lib/commands/bomb.c b/src/lib/commands/bomb.c index a0f8c629..74df69fa 100644 --- a/src/lib/commands/bomb.c +++ b/src/lib/commands/bomb.c @@ -849,7 +849,7 @@ pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from, natid plane_owner; int dam; - dam = ac_flak_dam(flak, pp->pln_def, 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; diff --git a/src/lib/commands/buil.c b/src/lib/commands/buil.c index 99057297..5e8519bd 100644 --- a/src/lib/commands/buil.c +++ b/src/lib/commands/buil.c @@ -783,7 +783,6 @@ build_plane(struct sctstr *sp, struct plchrstr *pp, short *vec, int tlev) plane.pln_opy = 0; plane.pln_radius = 0; plane.pln_range = UCHAR_MAX; /* will be adjusted by pln_set_tech() */ - plane.pln_range_max = plane.pln_range; plane.pln_wing = 0; plane.pln_ship = -1; plane.pln_land = -1; diff --git a/src/lib/commands/laun.c b/src/lib/commands/laun.c index 5d9e7396..f51e17ba 100644 --- a/src/lib/commands/laun.c +++ b/src/lib/commands/laun.c @@ -202,7 +202,7 @@ launch_as(struct plnstr *pp) pr("No satellites there!\n"); return RET_FAIL; } - if (msl_hit(pp, plane.pln_def, EF_PLANE, N_SAT_KILL, N_SAT_KILL, + if (msl_hit(pp, pln_def(&plane), EF_PLANE, N_SAT_KILL, N_SAT_KILL, prplane(&plane), sx, sy, plane.pln_own)) { dam = pln_damage(pp, sx, sy, 'p', &nukedam, 1); oldown = plane.pln_own; diff --git a/src/lib/commands/pdump.c b/src/lib/commands/pdump.c index b019683b..78694204 100644 --- a/src/lib/commands/pdump.c +++ b/src/lib/commands/pdump.c @@ -228,22 +228,22 @@ pdump(void) pr(" %d", plane.pln_tech); break; case 8: - pr(" %d", plane.pln_att); + pr(" %d", pln_att(&plane)); break; case 9: - pr(" %d", plane.pln_def); + pr(" %d", pln_def(&plane)); break; case 10: - pr(" %d", plane.pln_acc); + pr(" %d", pln_acc(&plane)); break; case 11: pr(" %d", plane.pln_range); break; case 12: - pr(" %d", plane.pln_range_max); + pr(" %d", pln_range_max(&plane)); break; case 13: - pr(" %d", plane.pln_load); + pr(" %d", pln_load(&plane)); break; case 14: pr(" %d", plchr[(int)plane.pln_type].pl_fuel); diff --git a/src/lib/commands/plan.c b/src/lib/commands/plan.c index 263926f3..6a49c770 100644 --- a/src/lib/commands/plan.c +++ b/src/lib/commands/plan.c @@ -66,7 +66,7 @@ plan(void) prxy("%4d,%-4d", plane.pln_x, plane.pln_y, player->cnum); pr(" %1.1s %c%3d%% %3d %3d %4d %3d %3d", &plane.pln_wing, plane.pln_off ? '!' : ' ', plane.pln_effic, - plane.pln_mobil, plane.pln_def, plane.pln_tech, + plane.pln_mobil, pln_def(&plane), plane.pln_tech, plane.pln_range, plane.pln_harden); if (plane.pln_ship >= 0) pr("%5dS", plane.pln_ship); diff --git a/src/lib/commands/pstat.c b/src/lib/commands/pstat.c index ba7d26e7..5106d0f3 100644 --- a/src/lib/commands/pstat.c +++ b/src/lib/commands/pstat.c @@ -58,10 +58,10 @@ pstat(void) pr(" %3d%% %4d %3d %3d %3d %3d %4d %4d", plane.pln_effic, plane.pln_tech, - plane.pln_att, - plane.pln_def, - plane.pln_acc, - plane.pln_range_max, plane.pln_load, + pln_att(&plane), + pln_def(&plane), + pln_acc(&plane), + pln_range_max(&plane), pln_load(&plane), plchr[(int)plane.pln_type].pl_fuel); pr("\n"); } diff --git a/src/lib/commands/rang.c b/src/lib/commands/rang.c index 19c2b612..dbf69e8c 100644 --- a/src/lib/commands/rang.c +++ b/src/lib/commands/rang.c @@ -42,7 +42,7 @@ range(void) { struct nstr_item np; struct plnstr plane; - int i; + int i, rmax; char *p; char buf[1024]; @@ -56,8 +56,8 @@ range(void) return RET_SYN; if (!p || (i = atoi(p)) < 0) continue; - plane.pln_range = (plane.pln_range_max < i) ? - plane.pln_range_max : i; + rmax = pln_range_max(&plane); + plane.pln_range = MIN(rmax, i); pr("Plane %d range changed to %d\n", plane.pln_uid, plane.pln_range); diff --git a/src/lib/commands/sona.c b/src/lib/commands/sona.c index 50b21cba..53bde0ea 100644 --- a/src/lib/commands/sona.c +++ b/src/lib/commands/sona.c @@ -239,7 +239,7 @@ plane_sona(struct emp_qelem *plane_list, int x, int y, pcp = ip->pcp; if (!(pcp->pl_flags & P_A)) /* if it isn't an ASW plane */ continue; - range = (int)techfact(pp->pln_tech, (100.0 - pp->pln_acc) / 10.0); + range = (int)techfact(pp->pln_tech, (100.0 - pln_acc(pp)) / 10.0); for (i = 0; getship(i, &s); i++) { targ = &s; if (targ->shp_own == pp->pln_own || targ->shp_own == 0) diff --git a/src/lib/global/nsc.c b/src/lib/global/nsc.c index 84f0dc64..f83d2682 100644 --- a/src/lib/global/nsc.c +++ b/src/lib/global/nsc.c @@ -46,6 +46,8 @@ #include "product.h" static void *nsc_ver(struct valstr *, natid, void *); +static void *nsc_pln_att(struct valstr *, natid, void *); +static void *nsc_pln_def(struct valstr *, natid, void *); /* Ugly hack to improve legibility by avoid long lines */ #define fldoff(fld) offsetof(CURSTR, fld) @@ -282,8 +284,6 @@ struct castr plane_ca[] = { {"range", fldoff(pln_range), NSC_UCHAR, 0, NULL, EF_BAD, 0}, {"ship", fldoff(pln_ship), NSC_SHORT, 0, NULL, EF_BAD, 0}, {"land", fldoff(pln_land), NSC_SHORT, 0, NULL, EF_BAD, 0}, - {"att", fldoff(pln_att), NSC_INT, 0, NULL, EF_BAD, NSC_EXTRA}, - {"def", fldoff(pln_def), NSC_INT, 0, NULL, EF_BAD, NSC_EXTRA}, {"harden", fldoff(pln_harden), NSC_CHAR, 0, NULL, EF_BAD, 0}, {"nuketype", fldoff(pln_nuketype), NSC_CHAR, 0, NULL, EF_BAD, 0}, {"flags", fldoff(pln_flags), NSC_CHAR, 0, NULL, @@ -292,6 +292,8 @@ struct castr plane_ca[] = { {"timestamp", fldoff(pln_timestamp), NSC_TIME, 0, NULL, EF_BAD, NSC_EXTRA}, {"theta", fldoff(pln_theta), NSC_FLOAT, 0, NULL, EF_BAD, 0}, + {"att", 0, NSC_LONG, 0, nsc_pln_att, EF_BAD, NSC_EXTRA}, + {"def", 0, NSC_LONG, 0, nsc_pln_def, EF_BAD, NSC_EXTRA}, {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0} #undef CURSTR }; @@ -725,3 +727,17 @@ nsc_ver(struct valstr *val, natid cnum, void *ptr) val->val_as.sym.get = NULL; return kp->km_data; } + +static void * +nsc_pln_def(struct valstr *val, natid cnum, void *ptr) +{ + val->val_as.lng = pln_def(ptr);; + return NULL; +} + +static void * +nsc_pln_att(struct valstr *val, natid cnum, void *ptr) +{ + val->val_as.lng = pln_att(ptr); + return NULL; +} diff --git a/src/lib/global/plane.c b/src/lib/global/plane.c index e64e78a8..d2be188f 100644 --- a/src/lib/global/plane.c +++ b/src/lib/global/plane.c @@ -84,3 +84,33 @@ pl_load(struct plchrstr *pcp, int tech) { return PLN_LOAD(pcp->pl_load, MAX(0, tech - pcp->pl_tech)); } + +int +pln_att(struct plnstr *pp) +{ + return pl_att(plchr + pp->pln_type, pp->pln_tech); +} + +int +pln_def(struct plnstr *pp) +{ + return pl_def(plchr + pp->pln_type, pp->pln_tech); +} + +int +pln_acc(struct plnstr *pp) +{ + return pl_acc(plchr + pp->pln_type, pp->pln_tech); +} + +int +pln_range_max(struct plnstr *pp) +{ + return pl_range(plchr + pp->pln_type, pp->pln_tech); +} + +int +pln_load(struct plnstr *pp) +{ + return pl_load(plchr + pp->pln_type, pp->pln_tech); +} diff --git a/src/lib/subs/aircombat.c b/src/lib/subs/aircombat.c index 53df1daa..cb20fe47 100644 --- a/src/lib/subs/aircombat.c +++ b/src/lib/subs/aircombat.c @@ -622,15 +622,13 @@ ac_dog(struct plist *ap, struct plist *dp) PR(def_own, " %3.3s #%-4d %3.3s #%-4d", dp->pcp->pl_name, dp->plane.pln_uid, ap->pcp->pl_name, ap->plane.pln_uid); - if (ap->plane.pln_att == 0) { - att = ap->plane.pln_def * ap->plane.pln_effic / 100; - att = MAX(att, ap->pcp->pl_def / 2); - } else { - att = ap->plane.pln_att * ap->plane.pln_effic / 100; - att = MAX(att, ap->pcp->pl_att / 2); - } + att = pln_att(&ap->plane); + if (att == 0) + att = pln_def(&ap->plane); + att = att * ap->plane.pln_effic / 100; + att = MAX(att, ap->pcp->pl_def / 2); - def = dp->plane.pln_def * dp->plane.pln_effic / 100; + def = pln_def(&dp->plane) * dp->plane.pln_effic / 100; def = MAX(def, dp->pcp->pl_def / 2); if ((ap->pcp->pl_flags & P_F) && ap->bombs != 0) @@ -954,7 +952,7 @@ ac_fireflak(struct emp_qelem *list, natid from, int guns) for (qp = list->q_forw; qp != list; qp = next) { next = qp->q_forw; plp = (struct plist *)qp; - n = ac_flak_dam(guns, plp->plane.pln_def, plp->pcp->pl_flags); + n = ac_flak_dam(guns, pln_def(&plp->plane), plp->pcp->pl_flags); ac_planedamage(plp, from, n, 0, 2, 1, msg); } } diff --git a/src/lib/subs/mission.c b/src/lib/subs/mission.c index 362b15f4..3ddf8e16 100644 --- a/src/lib/subs/mission.c +++ b/src/lib/subs/mission.c @@ -988,7 +988,7 @@ mission_pln_equip(struct plist *plp, struct ichrstr *ip, int flags, { struct plchrstr *pcp; struct plnstr *pp; - int needed; + int load, needed; struct lndstr land; struct shpstr ship; struct sctstr sect; @@ -1014,6 +1014,7 @@ mission_pln_equip(struct plist *plp, struct ichrstr *ip, int flags, item[I_PETROL] -= pcp->pl_fuel; rval = 0; if (!(flags & P_F)) { + load = pln_load(pp); itype = I_NONE; needed = 0; switch (mission) { @@ -1021,35 +1022,35 @@ mission_pln_equip(struct plist *plp, struct ichrstr *ip, int flags, case 'p': if (pp->pln_nuketype == -1) { itype = I_SHELL; - needed = pp->pln_load; + needed = load; } break; case 't': if ((pcp->pl_flags & P_C) == 0 || ip == 0) break; itype = ip->i_uid; - needed = (pp->pln_load * 2) / ip->i_lbs; + needed = (load * 2) / ip->i_lbs; break; case 'd': if ((pcp->pl_flags & P_C) == 0 || ip == 0) break; itype = ip->i_uid; - needed = (pp->pln_load * 2) / ip->i_lbs; + needed = (load * 2) / ip->i_lbs; break; case 'a': if ((pcp->pl_flags & (P_V | P_C)) == 0) break; itype = I_MILIT; - needed = pp->pln_load / ip->i_lbs; + needed = load / ip->i_lbs; break; case 'n': if (pp->pln_nuketype == -1) rval = -1; break; case 'i': /* missile interception */ - if (pp->pln_load) { + if (load) { itype = I_SHELL; - needed = pp->pln_load; + needed = load; } break; default: diff --git a/src/lib/subs/plnsub.c b/src/lib/subs/plnsub.c index fd494c66..efe9fbbd 100644 --- a/src/lib/subs/plnsub.c +++ b/src/lib/subs/plnsub.c @@ -595,7 +595,7 @@ pln_equip(struct plist *plp, struct ichrstr *ip, int flags, char mission) { struct plchrstr *pcp; struct plnstr *pp; - int needed; + int load, needed; struct lndstr land; struct shpstr ship; struct sctstr sect; @@ -635,6 +635,7 @@ pln_equip(struct plist *plp, struct ichrstr *ip, int flags, char mission) item[I_PETROL] -= pcp->pl_fuel; rval = 0; if ((flags & P_F) == 0) { + load = pln_load(pp); itype = I_NONE; needed = 0; switch (mission) { @@ -642,7 +643,7 @@ pln_equip(struct plist *plp, struct ichrstr *ip, int flags, char mission) case 'p': if (pp->pln_nuketype == -1) { itype = I_SHELL; - needed = pp->pln_load; + needed = load; } break; case 't': @@ -650,19 +651,19 @@ pln_equip(struct plist *plp, struct ichrstr *ip, int flags, char mission) if ((pcp->pl_flags & P_C) == 0 || ip == 0) break; itype = ip->i_uid; - needed = (pp->pln_load * 2) / ip->i_lbs; + needed = (load * 2) / ip->i_lbs; break; case 'm': if ((pcp->pl_flags & P_MINE) == 0) break; itype = I_SHELL; - needed = (pp->pln_load * 2) / ip->i_lbs; + needed = (load * 2) / ip->i_lbs; break; case 'a': if ((pcp->pl_flags & (P_V | P_C)) == 0) break; itype = I_MILIT; - needed = pp->pln_load / ip->i_lbs; + needed = load / ip->i_lbs; break; case 'n': if (pp->pln_nuketype == -1) @@ -1010,7 +1011,7 @@ plane_sweep(struct emp_qelem *plane_list, coord x, coord y) if (!(pcp->pl_flags & P_SWEEP)) /* if it isn't an sweep plane */ continue; - if (chance((100.0 - pp->pln_acc) / 100.0)) { + if (chance((100.0 - pln_acc(pp)) / 100.0)) { pr("Sweep! in %s\n", xyas(sect.sct_x, sect.sct_y, pp->pln_own)); mines_there--; @@ -1109,7 +1110,7 @@ pln_hitchance(struct plnstr *pp, int hardtarget, int type) struct plchrstr *pcp = plchr + pp->pln_type; double tfact = (double)(pp->pln_tech - pcp->pl_tech) / (pp->pln_tech - pcp->pl_tech / 2); - int acc = pp->pln_acc; + int acc = pln_acc(pp); int hitchance; if (type == EF_SHIP) { @@ -1137,7 +1138,7 @@ pln_damage(struct plnstr *pp, coord x, coord y, char type, int *nukedamp, { struct nukstr nuke; struct plchrstr *pcp = plchr + pp->pln_type; - int i; + int load, i; int hitroll; int dam = 0; int aim; @@ -1157,12 +1158,13 @@ pln_damage(struct plnstr *pp, coord x, coord y, char type, int *nukedamp, } *nukedamp = 0; - if (!pp->pln_load) /* e.g. ab, blowing up on launch pad */ + load = pln_load(pp); + if (!load) /* e.g. ab, blowing up on launch pad */ return 0; - i = roll(pp->pln_load) + 1; - if (i > pp->pln_load) - i = pp->pln_load; + i = roll(load) + 1; + if (i > load) + i = load; if (pcp->pl_flags & P_M) { if (pcp->pl_flags & P_MAR) @@ -1170,18 +1172,15 @@ pln_damage(struct plnstr *pp, coord x, coord y, char type, int *nukedamp, } else if (pcp->pl_flags & P_T) pinbomber = 1; - aim = 100 - pp->pln_acc; + aim = pln_acc(pp); if (type == 's') { - if (pinbomber) { - aim = pp->pln_acc; - effective = 0; - } - aim += 30; + effective = !pinbomber; + aim = 30 + (pinbomber ? aim : 100 - aim); } else { - if (!pinbomber) { - effective = 0; - } + effective = pinbomber; + aim = 100 - aim; } + while (i--) { dam += roll(6); hitroll = roll(100); @@ -1225,7 +1224,7 @@ pln_mobcost(int dist, struct plnstr *pp, int flags) if ((flags & P_F) || (flags & P_ESC)) cost /= 2; - return ldround(cost * dist / pp->pln_range_max + 5, 1); + return ldround(cost * dist / pln_range_max(pp) + 5, 1); } /* @@ -1235,18 +1234,14 @@ void pln_set_tech(struct plnstr *pp, int tlev) { struct plchrstr *pcp = plchr + pp->pln_type; - int limited_range = pp->pln_range < pp->pln_range_max; + int limited_range = pp->pln_range < pln_range_max(pp); + int range_max; if (CANT_HAPPEN(tlev < pcp->pl_tech)) tlev = pcp->pl_tech; - pp->pln_tech = tlev; - pp->pln_att = pl_att(pcp, tlev); - pp->pln_def = pl_def(pcp, tlev); - pp->pln_acc = pl_acc(pcp, tlev); - pp->pln_range_max = pl_range(pcp, tlev); - pp->pln_load = pl_load(pcp, tlev); - if (!limited_range || pp->pln_range > pp->pln_range_max) - pp->pln_range = pp->pln_range_max; + range_max = pln_range_max(pp); + if (!limited_range || pp->pln_range > range_max) + pp->pln_range = range_max; }