]> git.pond.sub.org Git - empserver/commitdiff
Don't store plane stats in struct plnstr
authorMarkus Armbruster <armbru@pond.sub.org>
Tue, 4 Mar 2008 20:09:32 +0000 (21:09 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Fri, 14 Mar 2008 19:25:41 +0000 (20:25 +0100)
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.

15 files changed:
include/plane.h
src/lib/commands/arm.c
src/lib/commands/bomb.c
src/lib/commands/buil.c
src/lib/commands/laun.c
src/lib/commands/pdump.c
src/lib/commands/plan.c
src/lib/commands/pstat.c
src/lib/commands/rang.c
src/lib/commands/sona.c
src/lib/global/nsc.c
src/lib/global/plane.c
src/lib/subs/aircombat.c
src/lib/subs/mission.c
src/lib/subs/plnsub.c

index 9528ea5aeb082c49348ddfad4b86a1392cb8811c..6356a1ebd6d2ac375dcc9019a86c26083b72caff 100644 (file)
@@ -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);
index 03faadef89ed2cfb38e753476cb36b91d45f6688..ce6db075143ced5e1dfe055de0b06189482ac9b3 100644 (file)
@@ -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;
index a0f8c62959d682c4f481333c4de9975793dcfe9f..74df69faa5e339a4619368e3ed7ae1600883ad0c 100644 (file)
@@ -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;
index 9905729772d991e72e7bd47e89d5412bf682bea3..5e8519bd09733fbed4e43792a21dd16f27dc108f 100644 (file)
@@ -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;
index 5d9e73962e704a5a72ad8d4a65751056399e2d7a..f51e17ba9f8d0799c73730a2c7b6474b34d8e397 100644 (file)
@@ -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;
index b019683bcbd60a1a18f4a5180d7153ceaf602507..7869420409adade2eefd66e6454ae7ffc87e74f4 100644 (file)
@@ -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);
index 263926f3142f68a5b53d6a727bde6bd78981090b..6a49c770424dfefdb96e2cea14bfe1bb83c96247 100644 (file)
@@ -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);
index ba7d26e7c20e3180a15991b34892bd7c0c0cb358..5106d0f3323198884356ba36880021515672c7d0 100644 (file)
@@ -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");
     }
index 19c2b61251b130ec6d7ac9cbd4003ef27dfed3e8..dbf69e8c7dc48358c20bddb636cb036bd5225fdd 100644 (file)
@@ -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);
 
index 50b21cba6b8f731a2f21a294f842641fdd6a51f4..53bde0ea3df93808559aaf9d3fc747e1cbdc6fc1 100644 (file)
@@ -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)
index 84f0dc64d53200488856f4081cefe5523ec02073..f83d2682925190f0f968c4aba3d9168e14099611 100644 (file)
@@ -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;
+}
index e64e78a8a560c301455aae32c9bf9a10f8572b9f..d2be188f0d9409452ad5af70bcf75dce23d58c02 100644 (file)
@@ -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);
+}
index 53df1daa21797f41a6c473dc59ddc3fb04f7d3b6..cb20fe473e0dbb0d57ef0cae8321769cdee72768 100644 (file)
@@ -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);
     }
 }
index 362b15f409ab637904000f9f204686ab37cf94ca..3ddf8e1692256073e0c904003d619d3193fadcf5 100644 (file)
@@ -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:
index fd494c66bb09e630135deac2e3b835bb840ebaa2..efe9fbbdff82a9ccded501ad955879fff81b99fb 100644 (file)
@@ -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;
 }