Don't store land unit stats in struct lndstr, part 2
struct lndstr members lnd_spy, lnd_rad, lnd_ammo, lnd_fuelc, lnd_fuelu, lnd_maxlight, lnd_maxlight are mere copies of struct lchrstr members l_spy, l_rad, l_ammo, l_fuelc, l_fuelu, l_nxlight, l_nland. Remove them. Make land unit selectors spy, rmax, ammo, fuelc, fuelu, maxlight virtual.
This commit is contained in:
parent
cdf1bcfa22
commit
c75d19b082
12 changed files with 57 additions and 57 deletions
|
@ -79,13 +79,6 @@ struct lndstr {
|
|||
short lnd_land; /* pointer to transporting unit */
|
||||
unsigned char lnd_nland;
|
||||
short lnd_access; /* Last tick mob was updated (MOB_ACCESS) */
|
||||
int lnd_spy; /* Seeing distance */
|
||||
int lnd_rad; /* reaction radius */
|
||||
int lnd_ammo; /* firing ammu used per shot */
|
||||
unsigned char lnd_fuelc; /* fuel capacity */
|
||||
unsigned char lnd_fuelu; /* fuel used per 10 mob */
|
||||
unsigned char lnd_maxlight; /* maximum number of xlight planes */
|
||||
unsigned char lnd_maxland; /* maximum number of units */
|
||||
time_t lnd_timestamp; /* Last time this unit was touched */
|
||||
};
|
||||
|
||||
|
|
|
@ -293,7 +293,7 @@ fuel(void)
|
|||
if ((oil_amt + pet_amt) == 0)
|
||||
sector = 0;
|
||||
|
||||
if ((item.land.lnd_fuelu == 0)
|
||||
if (lcp->l_fuelu == 0
|
||||
&& (item.land.lnd_own == player->cnum)) {
|
||||
pr("%s does not use fuel!\n", prland(&item.land));
|
||||
continue;
|
||||
|
@ -303,7 +303,7 @@ fuel(void)
|
|||
land_fuel = item.land.lnd_fuel;
|
||||
oil_amt = sect.sct_item[I_OIL];
|
||||
pet_amt = sect.sct_item[I_PETROL];
|
||||
max_amt = item.land.lnd_fuelc - land_fuel;
|
||||
max_amt = lcp->l_fuelc - land_fuel;
|
||||
|
||||
if (max_amt == 0) {
|
||||
pr("%s already has a full fuel load.\n",
|
||||
|
@ -385,7 +385,7 @@ fuel(void)
|
|||
land_fuel = item.land.lnd_fuel;
|
||||
oil_amt = item2.land.lnd_item[I_OIL];
|
||||
pet_amt = item2.land.lnd_item[I_PETROL];
|
||||
max_amt = item.land.lnd_fuelc - land_fuel;
|
||||
max_amt = lcp->l_fuelc - land_fuel;
|
||||
|
||||
if (max_amt == 0) {
|
||||
pr("%s already has a full fuel load.\n",
|
||||
|
|
|
@ -409,10 +409,10 @@ ldump(void)
|
|||
pr(" %d", lnd_vis(&land));
|
||||
break;
|
||||
case 33:
|
||||
pr(" %d", land.lnd_spy);
|
||||
pr(" %d", lchr[land.lnd_type].l_spy);
|
||||
break;
|
||||
case 34:
|
||||
pr(" %d", land.lnd_rad);
|
||||
pr(" %d", lchr[land.lnd_type].l_rad);
|
||||
break;
|
||||
case 35:
|
||||
pr(" %d", lnd_frg(&land));
|
||||
|
@ -424,7 +424,7 @@ ldump(void)
|
|||
pr(" %d", lnd_dam(&land));
|
||||
break;
|
||||
case 38:
|
||||
pr(" %d", land.lnd_ammo);
|
||||
pr(" %d", lchr[land.lnd_type].l_ammo);
|
||||
break;
|
||||
case 39:
|
||||
pr(" %d", lnd_aaf(&land));
|
||||
|
|
|
@ -745,14 +745,15 @@ load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
|
|||
char *p;
|
||||
char prompt[512];
|
||||
char buf[1024];
|
||||
struct lchrstr *lcp = lchr + lp->lnd_type;
|
||||
|
||||
if (!lp->lnd_maxlight) {
|
||||
if (!lcp->l_nxlight) {
|
||||
if (noisy)
|
||||
pr("%s cannot carry extra-light planes.\n", prland(lp));
|
||||
return 0;
|
||||
}
|
||||
count_land_planes(lp);
|
||||
if (load_unload == LOAD && lp->lnd_nxlight >= lp->lnd_maxlight) {
|
||||
if (load_unload == LOAD && lp->lnd_nxlight >= lcp->l_nxlight) {
|
||||
if (noisy)
|
||||
pr("%s doesn't have room for any more extra-light planes\n",
|
||||
prland(lp));
|
||||
|
@ -931,7 +932,8 @@ load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
|
|||
|
||||
lnd_count_units(lp);
|
||||
|
||||
if (load_unload == LOAD && lp->lnd_nland >= lp->lnd_maxland) {
|
||||
if (load_unload == LOAD
|
||||
&& lp->lnd_nland >= lchr[lp->lnd_type].l_nland) {
|
||||
if (noisy) {
|
||||
if (lp->lnd_nland)
|
||||
pr("%s doesn't have room for any more land units!\n",
|
||||
|
@ -1003,7 +1005,7 @@ load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
|
|||
/* Fit unit on ship */
|
||||
if (load_unload == LOAD) {
|
||||
lnd_count_units(lp);
|
||||
if (lp->lnd_nland >= lp->lnd_maxland) {
|
||||
if (lp->lnd_nland >= lchr[lp->lnd_type].l_nland) {
|
||||
if (noisy) {
|
||||
if (lp->lnd_nland)
|
||||
pr("%s doesn't have room for any more land units!\n",
|
||||
|
|
|
@ -207,7 +207,7 @@ look_land(struct lndstr *lookland)
|
|||
int i;
|
||||
int dist;
|
||||
|
||||
drange = techfact(lookland->lnd_tech, lookland->lnd_spy);
|
||||
drange = techfact(lookland->lnd_tech, lchr[lookland->lnd_type].l_spy);
|
||||
drange *= lookland->lnd_effic / 100.0;
|
||||
range = ldround(drange, 1);
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ lsta(void)
|
|||
int nunits;
|
||||
struct nstr_item ni;
|
||||
struct lndstr land;
|
||||
struct lchrstr *lcp;
|
||||
|
||||
if (!snxtitem(&ni, EF_LAND, player->argp[1]))
|
||||
return RET_SYN;
|
||||
|
@ -50,6 +51,7 @@ lsta(void)
|
|||
while (nxtitem(&ni, &land)) {
|
||||
if (!player->owner || land.lnd_own == 0)
|
||||
continue;
|
||||
lcp = lchr + land.lnd_type;
|
||||
count_land_planes(&land);
|
||||
|
||||
if (nunits++ == 0) {
|
||||
|
@ -57,16 +59,16 @@ lsta(void)
|
|||
pr(" %16.16s p i p a n c i m a\n", "");
|
||||
pr("lnd# %16.16s x,y eff tech att def vul d s y d g c r m f\n", "unit-type");
|
||||
}
|
||||
pr("%4d %-16.16s ", land.lnd_uid, lchr[(int)land.lnd_type].l_name);
|
||||
pr("%4d %-16.16s ", land.lnd_uid, lcp->l_name);
|
||||
prxy("%4d,%-4d", land.lnd_x, land.lnd_y, player->cnum);
|
||||
pr(" %3d%% %3d %1.1f %1.1f %3d ",
|
||||
land.lnd_effic, land.lnd_tech, lnd_att(&land), lnd_def(&land),
|
||||
lnd_vul(&land));
|
||||
pr("%2d %2d %2d %2d ",
|
||||
lnd_spd(&land), lnd_vis(&land), land.lnd_spy, land.lnd_rad);
|
||||
lnd_spd(&land), lnd_vis(&land), lcp->l_spy, lcp->l_rad);
|
||||
pr("%2d %2d %2d %2d %2d ",
|
||||
lnd_frg(&land),
|
||||
lnd_acc(&land), lnd_dam(&land), land.lnd_ammo, lnd_aaf(&land));
|
||||
lnd_frg(&land), lnd_acc(&land), lnd_dam(&land),
|
||||
lcp->l_ammo, lnd_aaf(&land));
|
||||
pr("\n");
|
||||
}
|
||||
if (nunits == 0) {
|
||||
|
|
|
@ -112,7 +112,8 @@ radar(short type)
|
|||
pr("Units on ships can't use radar!\n");
|
||||
continue;
|
||||
}
|
||||
tech = techfact(item.land.lnd_tech, item.land.lnd_spy);
|
||||
tech = techfact(item.land.lnd_tech,
|
||||
lchr[item.land.lnd_type].l_spy);
|
||||
}
|
||||
|
||||
pr("%s at ", obj_nameof(&item.gen));
|
||||
|
|
|
@ -72,7 +72,6 @@ lrange(void)
|
|||
{
|
||||
struct nstr_item np;
|
||||
struct lndstr land;
|
||||
struct lchrstr *lcp;
|
||||
int i;
|
||||
char *p;
|
||||
char prompt[128];
|
||||
|
@ -83,7 +82,6 @@ lrange(void)
|
|||
while (nxtitem(&np, &land)) {
|
||||
if (!player->owner || land.lnd_own == 0)
|
||||
continue;
|
||||
lcp = &lchr[(int)land.lnd_type];
|
||||
sprintf(prompt, "New range for %s? ", prland(&land));
|
||||
if ((p = getstarg(player->argp[2], prompt, buf)) == 0)
|
||||
return RET_SYN;
|
||||
|
@ -91,7 +89,7 @@ lrange(void)
|
|||
return RET_SYN;
|
||||
if ((i = atoi(p)) < 0)
|
||||
continue;
|
||||
land.lnd_rad_max = (i < land.lnd_rad) ? i : land.lnd_rad;
|
||||
land.lnd_rad_max = MIN(i, lchr[land.lnd_type].l_rad);
|
||||
pr("%s reaction radius changed to %d\n",
|
||||
prland(&land), land.lnd_rad_max);
|
||||
putland(land.lnd_uid, &land);
|
||||
|
|
|
@ -57,6 +57,7 @@ static void *nsc_lnd_frg(struct valstr *, natid, void *);
|
|||
static void *nsc_lnd_acc(struct valstr *, natid, void *);
|
||||
static void *nsc_lnd_dam(struct valstr *, natid, void *);
|
||||
static void *nsc_lnd_aaf(struct valstr *, natid, void *);
|
||||
static void *nsc_lchr(struct valstr *, natid, void *);
|
||||
|
||||
/* Ugly hack to improve legibility by avoid long lines */
|
||||
#define fldoff(fld) offsetof(CURSTR, fld)
|
||||
|
@ -350,13 +351,6 @@ struct castr land_ca[] = {
|
|||
{"land", fldoff(lnd_land), NSC_SHORT, 0, NULL, EF_BAD, 0},
|
||||
{"nland", fldoff(lnd_nland), NSC_UCHAR, 0, NULL, EF_BAD, NSC_EXTRA},
|
||||
{"access", fldoff(lnd_access), NSC_SHORT, 0, NULL, EF_BAD, 0},
|
||||
{"spy", fldoff(lnd_spy), NSC_INT, 0, NULL, EF_BAD, NSC_EXTRA},
|
||||
{"rmax", fldoff(lnd_rad), NSC_INT, 0, NULL, EF_BAD, NSC_EXTRA},
|
||||
{"ammo", fldoff(lnd_ammo), NSC_INT, 0, NULL, EF_BAD, NSC_EXTRA},
|
||||
{"fuelc", fldoff(lnd_fuelc), NSC_UCHAR, 0, NULL, EF_BAD, NSC_EXTRA},
|
||||
{"fuelu", fldoff(lnd_fuelu), NSC_UCHAR, 0, NULL, EF_BAD, NSC_EXTRA},
|
||||
{"maxlight", fldoff(lnd_maxlight), NSC_UCHAR, 0, NULL,
|
||||
EF_BAD, NSC_EXTRA},
|
||||
{"timestamp", fldoff(lnd_timestamp), NSC_TIME, 0, NULL,
|
||||
EF_BAD, NSC_EXTRA},
|
||||
{"att", 0, NSC_DOUBLE, 0, nsc_lnd_att, EF_BAD, NSC_EXTRA},
|
||||
|
@ -368,6 +362,15 @@ struct castr land_ca[] = {
|
|||
{"acc", 0, NSC_LONG, 0, nsc_lnd_acc, EF_BAD, NSC_EXTRA},
|
||||
{"dam", 0, NSC_LONG, 0, nsc_lnd_dam, EF_BAD, NSC_EXTRA},
|
||||
{"aaf", 0, NSC_LONG, 0, nsc_lnd_aaf, EF_BAD, NSC_EXTRA},
|
||||
#undef CURSTR
|
||||
#define CURSTR struct lchrstr
|
||||
{"spy", fldoff(l_spy), NSC_INT, 0, nsc_lchr, EF_BAD, NSC_EXTRA},
|
||||
{"rmax", fldoff(l_rad), NSC_INT, 0, nsc_lchr, EF_BAD, NSC_EXTRA},
|
||||
{"ammo", fldoff(l_ammo), NSC_INT, 0, nsc_lchr, EF_BAD, NSC_EXTRA},
|
||||
{"fuelc", fldoff(l_fuelc), NSC_UCHAR, 0, nsc_lchr, EF_BAD, NSC_EXTRA},
|
||||
{"fuelu", fldoff(l_fuelu), NSC_UCHAR, 0, nsc_lchr, EF_BAD, NSC_EXTRA},
|
||||
{"maxlight", fldoff(l_nxlight), NSC_UCHAR, 0, nsc_lchr,
|
||||
EF_BAD, NSC_EXTRA},
|
||||
{NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
|
||||
#undef CURSTR
|
||||
};
|
||||
|
@ -813,3 +816,10 @@ nsc_lnd_aaf(struct valstr *val, natid cnum, void *ptr)
|
|||
val->val_as.lng = lnd_aaf(ptr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *
|
||||
nsc_lchr(struct valstr *val, natid cnum, void *ptr)
|
||||
{
|
||||
val->val_as.sym.get = NULL;
|
||||
return lchr + ((struct lndstr *)ptr)->lnd_type;
|
||||
}
|
||||
|
|
|
@ -322,9 +322,9 @@ int
|
|||
lnd_spyval(struct lndstr *lp)
|
||||
{
|
||||
if (lchr[(int)lp->lnd_type].l_flags & L_RECON)
|
||||
return lp->lnd_spy * (lp->lnd_effic / 100.0) + 2;
|
||||
return lchr[lp->lnd_type].l_spy * (lp->lnd_effic / 100.0) + 2;
|
||||
else
|
||||
return lp->lnd_spy * (lp->lnd_effic / 100.0);
|
||||
return lchr[lp->lnd_type].l_spy * (lp->lnd_effic / 100.0);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1236,11 +1236,4 @@ lnd_set_tech(struct lndstr *lp, int tlev)
|
|||
tlev = 0;
|
||||
|
||||
lp->lnd_tech = tlev;
|
||||
lp->lnd_spy = lcp->l_spy;
|
||||
lp->lnd_rad = lcp->l_rad;
|
||||
lp->lnd_ammo = lcp->l_ammo;
|
||||
lp->lnd_fuelc = lcp->l_fuelc;
|
||||
lp->lnd_fuelu = lcp->l_fuelu;
|
||||
lp->lnd_maxlight = lcp->l_nxlight;
|
||||
lp->lnd_maxland = lcp->l_nland;
|
||||
}
|
||||
|
|
|
@ -106,13 +106,13 @@ resupply_commod(struct lndstr *lp, i_type type)
|
|||
}
|
||||
|
||||
if (opt_FUEL && type == I_PETROL) {
|
||||
int fuel_needed = lp->lnd_fuelu
|
||||
int fuel_needed = lchr[lp->lnd_type].l_fuelu
|
||||
* ((float)etu_per_update * land_mob_scale) / 10.0;
|
||||
|
||||
while ((lp->lnd_fuel < fuel_needed) && lp->lnd_item[I_PETROL]) {
|
||||
lp->lnd_fuel += 10;
|
||||
if (lp->lnd_fuel > lp->lnd_fuelc)
|
||||
lp->lnd_fuel = lp->lnd_fuelc;
|
||||
if (lp->lnd_fuel > lchr[lp->lnd_type].l_fuelc)
|
||||
lp->lnd_fuel = lchr[lp->lnd_type].l_fuelc;
|
||||
lp->lnd_item[I_PETROL]--;
|
||||
}
|
||||
}
|
||||
|
@ -433,7 +433,7 @@ get_minimum(struct lndstr *lp, i_type type)
|
|||
want = (int)ceil(food_needed(lp->lnd_item, etu_per_update));
|
||||
break;
|
||||
case I_SHELL:
|
||||
want = lp->lnd_ammo;
|
||||
want = lcp->l_ammo;
|
||||
break;
|
||||
|
||||
/*
|
||||
|
@ -443,7 +443,7 @@ get_minimum(struct lndstr *lp, i_type type)
|
|||
case I_PETROL:
|
||||
if (opt_FUEL == 0)
|
||||
return 0;
|
||||
want = lp->lnd_fuelu * ((float)etu_per_update * land_mob_scale)
|
||||
want = lcp->l_fuelu * ((float)etu_per_update * land_mob_scale)
|
||||
/ 10.0;
|
||||
want -= lp->lnd_fuel;
|
||||
if (want > 0) {
|
||||
|
@ -487,7 +487,7 @@ has_supply(struct lndstr *lp)
|
|||
|
||||
}
|
||||
|
||||
shells_needed = lp->lnd_ammo;
|
||||
shells_needed = lchr[lp->lnd_type].l_ammo;
|
||||
shells = keepshells = lp->lnd_item[I_SHELL];
|
||||
if (shells < shells_needed) {
|
||||
lp->lnd_item[I_SHELL] = 0;
|
||||
|
@ -502,7 +502,7 @@ has_supply(struct lndstr *lp)
|
|||
return 0;
|
||||
|
||||
if (opt_FUEL) {
|
||||
fuel_needed = lp->lnd_fuelu;
|
||||
fuel_needed = lchr[lp->lnd_type].l_fuelu;
|
||||
fuel = lp->lnd_fuel;
|
||||
if (fuel < fuel_needed) {
|
||||
petrol_needed =
|
||||
|
|
|
@ -285,6 +285,7 @@ do_mob_land(struct lndstr *lp, int etus)
|
|||
int value;
|
||||
int can_add, have_fuel_for, total_add;
|
||||
double d;
|
||||
struct lchrstr *lcp = lchr + lp->lnd_type;
|
||||
|
||||
if (CANT_HAPPEN(etus < 0))
|
||||
etus = 0;
|
||||
|
@ -292,7 +293,7 @@ do_mob_land(struct lndstr *lp, int etus)
|
|||
if (lp->lnd_own == 0)
|
||||
return;
|
||||
|
||||
if (opt_FUEL == 0 || lp->lnd_fuelu == 0) {
|
||||
if (opt_FUEL == 0 || lcp->l_fuelu == 0) {
|
||||
value = lp->lnd_mobil + ((float)etus * land_mob_scale);
|
||||
if (value > land_mob_max) {
|
||||
if (lp->lnd_harden < land_mob_max && !opt_MOB_ACCESS) {
|
||||
|
@ -323,13 +324,13 @@ do_mob_land(struct lndstr *lp, int etus)
|
|||
if (can_add > (float)etus * land_mob_scale)
|
||||
can_add = (float)etus * land_mob_scale;
|
||||
|
||||
have_fuel_for = (lp->lnd_fuel / lp->lnd_fuelu) * fuel_mult;
|
||||
have_fuel_for = (lp->lnd_fuel / lcp->l_fuelu) * fuel_mult;
|
||||
|
||||
if (can_add > have_fuel_for) {
|
||||
int need;
|
||||
need = can_add - have_fuel_for;
|
||||
d = need;
|
||||
d *= lp->lnd_fuelu;
|
||||
d *= lcp->l_fuelu;
|
||||
d /= fuel_mult;
|
||||
d /= 5.0;
|
||||
if (d - (int)d > 0.0)
|
||||
|
@ -340,13 +341,13 @@ do_mob_land(struct lndstr *lp, int etus)
|
|||
lp->lnd_fuel += newfuel * 5;
|
||||
}
|
||||
|
||||
have_fuel_for = (lp->lnd_fuel / lp->lnd_fuelu) * fuel_mult;
|
||||
have_fuel_for = (lp->lnd_fuel / lcp->l_fuelu) * fuel_mult;
|
||||
|
||||
if (can_add > have_fuel_for) {
|
||||
int need;
|
||||
need = can_add - have_fuel_for;
|
||||
d = need;
|
||||
d *= lp->lnd_fuelu;
|
||||
d *= lcp->l_fuelu;
|
||||
d /= fuel_mult;
|
||||
d /= 50.0;
|
||||
if (d - (int)d > 0.0)
|
||||
|
@ -357,17 +358,17 @@ do_mob_land(struct lndstr *lp, int etus)
|
|||
lp->lnd_fuel += newfuel * 50;
|
||||
}
|
||||
|
||||
have_fuel_for = (lp->lnd_fuel / lp->lnd_fuelu) * fuel_mult;
|
||||
have_fuel_for = (lp->lnd_fuel / lcp->l_fuelu) * fuel_mult;
|
||||
|
||||
if (can_add > have_fuel_for) {
|
||||
total_add = have_fuel_for;
|
||||
} else
|
||||
total_add = can_add;
|
||||
d = total_add;
|
||||
d *= lp->lnd_fuelu;
|
||||
d *= lcp->l_fuelu;
|
||||
d /= fuel_mult;
|
||||
lp->lnd_fuel -= ldround(d, 1);
|
||||
lp->lnd_fuel = MIN(lp->lnd_fuel, lp->lnd_fuelc);
|
||||
lp->lnd_fuel = MIN(lp->lnd_fuel, lcp->l_fuelc);
|
||||
lp->lnd_mobil += total_add;
|
||||
/* No excess mobility here, hence no automatic fortification */
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue