]> git.pond.sub.org Git - empserver/commitdiff
Don't store ship stats in struct shpstr
authorMarkus Armbruster <armbru@pond.sub.org>
Tue, 4 Mar 2008 20:15:59 +0000 (21:15 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Fri, 14 Mar 2008 19:25:41 +0000 (20:25 +0100)
New shp_armor(), shp_speed(), shp_visib(), shp_frnge(), shp_glim()
replace the struct shpstr members with the same names.

13 files changed:
include/ship.h
src/lib/commands/look.c
src/lib/commands/mfir.c
src/lib/commands/sdump.c
src/lib/commands/sona.c
src/lib/commands/sstat.c
src/lib/global/ship.c
src/lib/subs/attsub.c
src/lib/subs/damage.c
src/lib/subs/landgun.c
src/lib/subs/radmap.c
src/lib/subs/shpsub.c
src/lib/update/ship.c

index 923865843bfd9e9e55319613f9a9caa742d7f406..0cfab53c97962371b774055e7cabc32393c524ca 100644 (file)
@@ -79,11 +79,6 @@ struct shpstr {
     /* end of part matching struct empobj */
     unsigned char shp_nplane;  /* number of planes on board */
     unsigned char shp_nland;   /* number of land units on board */
-    short shp_armor;
-    short shp_speed;
-    short shp_visib;
-    short shp_frnge;
-    short shp_glim;
     coord shp_destx[2];                /* location for ship destination */
     coord shp_desty[2];
     i_type shp_tstart[TMAX];   /* what goods to pick up at start point */
@@ -182,6 +177,11 @@ extern int m_speed(struct mchrstr *, int);
 extern int m_visib(struct mchrstr *, int);
 extern int m_frnge(struct mchrstr *, int);
 extern int m_glim(struct mchrstr *, int);
+extern int shp_armor(struct shpstr *);
+extern int shp_speed(struct shpstr *);
+extern int shp_visib(struct shpstr *);
+extern int shp_frnge(struct shpstr *);
+extern int shp_glim(struct shpstr *);
 
 extern int shp_dchrg(struct shpstr *);
 extern int shp_fire(struct shpstr *);
index 51e76a2cb4a9465e601b9b8937c1af0226083734..86b1e659afe14ac12afe30519feb0be999b7f2e5 100644 (file)
@@ -161,9 +161,9 @@ look_ship(struct shpstr *lookship)
            continue;
        tmcp = &mchr[(int)sp->shp_type];
        if (smcp->m_flags & M_SUB)
-           vrange = (int)(sp->shp_visib * range / 30.0);
+           vrange = (int)(shp_visib(sp) * range / 30.0);
        else
-           vrange = (int)(sp->shp_visib * range / 20.0);
+           vrange = (int)(shp_visib(sp) * range / 20.0);
        getsect(sp->shp_x, sp->shp_y, &sect);
        if (sect.sct_type != SCT_WATER)
            vrange = MAX(1, vrange);
index c9ba7b453f2265c65e4b0c524ea6af2238ad06c8..702e13d09ee4e125717bac8774fe34346902e19d 100644 (file)
@@ -183,7 +183,7 @@ multifire(void)
                pr("Not enough mil on ship #%d\n", item.ship.shp_uid);
                continue;
            }
-           if (item.ship.shp_glim == 0) {
+           if (mchr[item.ship.shp_type].m_glim == 0) {
                pr("Ships %d cannot fire guns!\n", item.ship.shp_uid);
                continue;
            }
index 105f6f9f06c204d5779a4ad5fc04e1612d1a825a..849ae615c420a7469a2c985f2b9295a9cb45f31d 100644 (file)
@@ -354,19 +354,19 @@ sdump(void)
                pr(" %d", ship.shp_item[I_RAD]);
                break;
            case 27:
-               pr(" %d", ship.shp_armor);
+               pr(" %d", shp_armor(&ship));
                break;
            case 28:
-               pr(" %d", ship.shp_speed);
+               pr(" %d", shp_speed(&ship));
                break;
            case 29:
-               pr(" %d", ship.shp_visib);
+               pr(" %d", shp_visib(&ship));
                break;
            case 30:
-               pr(" %d", ship.shp_frnge);
+               pr(" %d", shp_frnge(&ship));
                break;
            case 31:
-               pr(" %d", ship.shp_glim);
+               pr(" %d", shp_glim(&ship));
                break;
            case 32:
                /*
index 53bde0ea3df93808559aaf9d3fc747e1cbdc6fc1..35579ee182f113315a0aab8bb2100791eb176e51 100644 (file)
@@ -56,7 +56,7 @@ sona(void)
     struct mchrstr *tmcp;
     struct nstr_sect ns;
     int range;
-    int pingrange;
+    int visib, pingrange;
     int srange;
     int vrange;
     int dist;
@@ -147,7 +147,8 @@ sona(void)
            if (targ.shp_own == player->cnum || targ.shp_own == 0)
                continue;
            tmcp = &mchr[(int)targ.shp_type];
-           pingrange = MIN(7, MAX(targ.shp_visib, 10) * range / 10);
+           visib = shp_visib(&targ);
+           pingrange = MIN(7, MAX(visib, 10) * range / 10);
            vrange = pingrange * ship.shp_effic / 200;
            dist = mapdist(targ.shp_x, targ.shp_y, ship.shp_x, ship.shp_y);
            pingrange = (MAX(pingrange, 2) * targ.shp_effic) / 100;
@@ -173,11 +174,11 @@ sona(void)
                continue;
            if (tmcp->m_flags & M_SUB &&
                getrel(getnatp(targ.shp_own), player->cnum) < FRIENDLY) {
-               if (mcp->m_vrnge + targ.shp_visib < 8)
+               if (mcp->m_vrnge + visib < 8)
                    pr("Sonar detects sub #%d @ %s\n",
                       targ.shp_uid,
                       xyas(targ.shp_x, targ.shp_y, player->cnum));
-               else if (mcp->m_vrnge + targ.shp_visib < 10)
+               else if (mcp->m_vrnge + visib < 10)
                    pr("Sonar detects %s @ %s\n",
                       prship(&targ),
                       xyas(targ.shp_x, targ.shp_y, player->cnum));
@@ -190,8 +191,8 @@ sona(void)
                   cname(targ.shp_own), prship(&targ),
                   xyas(targ.shp_x, targ.shp_y, player->cnum));
 
-           if (targ.shp_visib > vis[y][x]) {
-               vis[y][x] = targ.shp_visib;
+           if (visib > vis[y][x]) {
+               vis[y][x] = visib;
                /* &~0x20 makes it a cap letter */
                rad[y][x] = (*mchr[(int)targ.shp_type].m_name) & ~0x20;
            }
@@ -224,7 +225,7 @@ plane_sona(struct emp_qelem *plane_list, int x, int y,
     struct plist *ip;
     struct sctstr sect;
     int found = 0;
-    int range, i;
+    int range, i, vis;
     int pingrange;
     int vrange;
     int dist;
@@ -252,7 +253,8 @@ plane_sona(struct emp_qelem *plane_list, int x, int y,
            if (roll(100) > pln_identchance(pp, shp_hardtarget(targ),
                                            EF_SHIP))
                continue;
-           pingrange = MAX(targ->shp_visib, 10) * range / 10;
+           vis = shp_visib(targ);
+           pingrange = MAX(vis, 10) * range / 10;
            vrange = pingrange * (pp->pln_effic / 200.0);
            dist = mapdist(targ->shp_x, targ->shp_y, x, y);
            pingrange = (MAX(pingrange, 2) * targ->shp_effic);
index 16e26e43a50edf6bde017038d9b4a148a795ad6b..0498e1b1017228bee976efce9b2e14831eeee8ee 100644 (file)
@@ -63,8 +63,8 @@ sstat(void)
        pr(" %3d%% %4d %3d %3d %3d %3d %3d",
           ship.shp_effic,
           ship.shp_tech,
-          ship.shp_armor,
-          ship.shp_speed, ship.shp_visib, ship.shp_frnge, ship.shp_glim);
+          shp_armor(&ship), shp_speed(&ship), shp_visib(&ship),
+          shp_frnge(&ship), shp_glim(&ship));
        pr("\n");
     }
     if (nships == 0) {
index 6226a76cbeb04522b02d8287db25c1248018a5f8..6c5734873444d663ee10c373b0d8782c948dfe53 100644 (file)
@@ -88,3 +88,33 @@ m_glim(struct mchrstr *mcp, int tech)
 {
     return SHP_FIR(mcp->m_glim, MAX(0, tech - mcp->m_tech));
 }
+
+int
+shp_armor(struct shpstr *sp)
+{
+    return m_armor(mchr + sp->shp_type, sp->shp_tech);
+}
+
+int
+shp_speed(struct shpstr *sp)
+{
+    return m_speed(mchr + sp->shp_type, sp->shp_tech);
+}
+
+int
+shp_visib(struct shpstr *sp)
+{
+    return m_visib(mchr + sp->shp_type, sp->shp_tech);
+}
+
+int
+shp_frnge(struct shpstr *sp)
+{
+    return m_frnge(mchr + sp->shp_type, sp->shp_tech);
+}
+
+int
+shp_glim(struct shpstr *sp)
+{
+    return m_glim(mchr + sp->shp_type, sp->shp_tech);
+}
index 1284a14315f63dd978bc040246f47c628ffc2607..691b4b1cd8479e6aafb4a9e86422589d225cb172 100644 (file)
@@ -576,8 +576,8 @@ board_abort(struct combat *off, struct combat *def)
        }
        getship(off->shp_uid, &aship);
        getship(def->shp_uid, &dship);
-       if (techfact(aship.shp_tech, 1.0) * aship.shp_speed * off->eff
-           <= techfact(dship.shp_tech, 1.0) * dship.shp_speed * def->eff) {
+       if (techfact(aship.shp_tech, shp_speed(&aship)) * off->eff
+           <= techfact(dship.shp_tech, shp_speed(&dship)) * def->eff) {
            pr("Victim ship moves faster than you do!\n");
            if (def->own)
                wu(0, def->own,
@@ -893,7 +893,7 @@ calc_mobcost(int combat_mode, struct combat *off, struct combat *def,
        case EF_SHIP:
            /* the 2 in the formula below is a fudge factor */
            getship(def->shp_uid, &ship);
-           off->mobcost += (def->eff / 100) * (ship.shp_speed / 2);
+           off->mobcost += (def->eff / 100) * (shp_speed(&ship) / 2);
        }
     }
 }
@@ -1141,7 +1141,7 @@ att_combat_eff(struct combat *com)
            eff = sector_strength(getsectp(com->x, com->y));
     } else if (com->type == EF_SHIP && com->own != player->cnum) {
        getship(com->shp_uid, &ship);
-       eff = 1.0 + ship.shp_armor / 100.0;
+       eff = 1.0 + shp_armor(&ship) / 100.0;
     }
     return eff;
 }
index 11684fb6f53c52b383e066238a10b91f55a812b0..250fce7ddd3894ef20e72e19df2bd0a7e7c61514 100644 (file)
@@ -82,7 +82,7 @@ ship_damage(struct shpstr *sp, int dam)
 void
 shipdamage(struct shpstr *sp, int dam)
 {
-    ship_damage(sp, (int)(dam / (1.0 + sp->shp_armor / 100.0)));
+    ship_damage(sp, (int)(dam / (1.0 + shp_armor(sp) / 100.0)));
 }
 
 void
index 9654aacef18ed85437a330e929e8720796668d00..737054f6c134f365280eb603b89e772e55188a63 100644 (file)
@@ -222,7 +222,7 @@ lnd_fire(struct lndstr *lp)
 int
 shp_usable_guns(struct shpstr *sp)
 {
-    return MIN(sp->shp_glim, sp->shp_item[I_GUN]);
+    return MIN(shp_glim(sp), sp->shp_item[I_GUN]);
 }
 
 /*
@@ -259,7 +259,7 @@ fortrange(struct sctstr *sp)
 double
 shp_fire_range(struct shpstr *sp)
 {
-    return effrange(sp->shp_frnge, sp->shp_tech);
+    return effrange(shp_frnge(sp), sp->shp_tech);
 }
 
 /*
@@ -268,7 +268,7 @@ shp_fire_range(struct shpstr *sp)
 double
 torprange(struct shpstr *sp)
 {
-    return effrange(sp->shp_frnge * 2, sp->shp_tech)
+    return effrange(shp_frnge(sp) * 2, sp->shp_tech)
        * sp->shp_effic / 100.0;
 }
 
@@ -278,7 +278,7 @@ torprange(struct shpstr *sp)
 double
 shp_torp_hitchance(struct shpstr *sp, int range)
 {
-    return DTORP_HITCHANCE(range, sp->shp_visib);
+    return DTORP_HITCHANCE(range, shp_visib(sp));
 }
 
 /*
index d3c2101b23b939b424ecb88bb986e3906eb6c37e..ea5579caefe75968acca71a9fe121d59a151a099 100644 (file)
@@ -79,7 +79,7 @@ static void
 radmap2(int owner,
        int cx, int cy, int eff, int range, double seesub, int pr_flag)
 {
-    int rng;
+    int visib, rng;
     struct sctstr sect;
     struct shpstr ship;
     struct plnstr plane;
@@ -158,14 +158,15 @@ radmap2(int owner,
        x = deltx(&ns.range, (int)ship.shp_x);
        y = delty(&ns.range, (int)ship.shp_y);
 
-       rng = (int)(range * ship.shp_visib / 20.0);
+       visib = shp_visib(&ship);
+       rng = (int)(range * visib / 20.0);
        if (ni.curdist > rng)
            continue;
        if ((mchr[(int)ship.shp_type].m_flags & M_SUB) &&
            ni.curdist > rng * seesub)
            continue;
-       if (ship.shp_visib > vis[y][x]) {
-           vis[y][x] = ship.shp_visib;
+       if (visib > vis[y][x]) {
+           vis[y][x] = visib;
            /* &~0x20 makes it a cap letter */
            rad[y][x] = (*mchr[(int)ship.shp_type].m_name) & ~0x20;
        }
index dd0cdee625c628fcd1b95ab245cfeaf2360aae2d..fe76714e4abf42bfc6c174c2344a4f99fec0272a 100644 (file)
@@ -690,13 +690,13 @@ shp_hardtarget(struct shpstr *sp)
     int vis, onsea;
     struct mchrstr *mcp = mchr + sp->shp_type;
 
-    vis = sp->shp_visib;
+    vis = shp_visib(sp);
     getsect(sp->shp_x, sp->shp_y, &sect);
     onsea = sect.sct_type == SCT_WATER;
     if (mcp->m_flags & M_SUB)
        vis *= 4;
     return (int)((sp->shp_effic / 100.0) *
-                (20 + sp->shp_speed * onsea / 2.0 - vis));
+                (20 + shp_speed(sp) * onsea / 2.0 - vis));
 }
 
 static int
@@ -952,7 +952,7 @@ shp_missdef(struct shpstr *sp, natid victim)
 double
 shp_mobcost(struct shpstr *sp)
 {
-    return speed_factor(sp->shp_effic * 0.01 * sp->shp_speed,
+    return speed_factor(sp->shp_effic * 0.01 * shp_speed(sp),
                        sp->shp_tech);
 }
 
@@ -968,9 +968,4 @@ shp_set_tech(struct shpstr *sp, int tlev)
        tlev = mcp->m_tech;
 
     sp->shp_tech = tlev;
-    sp->shp_armor = m_armor(mcp, tlev);
-    sp->shp_speed = m_speed(mcp, tlev);
-    sp->shp_visib = m_visib(mcp, tlev);
-    sp->shp_frnge = m_frnge(mcp, tlev);
-    sp->shp_glim  = m_glim(mcp, tlev);
 }
index 77a8816a1c24353ddad801059f6cb99c8ce65b58..3904d0bd478a1dbdffe7df5eb5487449148f77b5 100644 (file)
@@ -291,7 +291,7 @@ shiprepair(struct shpstr *ship, struct natstr *np, struct bp *bp, int etus)
 
     wf = 0;
     /* only military can work on a military boat */
-    if (ship->shp_glim > 0)
+    if (mp->m_glim != 0)
        wf = etus * ship->shp_item[I_MILIT] / 2;
     else
        wf = etus * (ship->shp_item[I_CIVIL] / 2 + ship->shp_item[I_MILIT] / 5);