Get rid of ship and land unit load counters
Load counters are redundant; they can be computed from the carrier uids. Keeping them up-to-date as the carriers change is a pain, and we never got that quite complete. Computing load counters straight from the carrier uids every time we need them would be rather inefficient, but computing them from cargo lists is not. So do that. Remove the load counters: struct shpstr members shp_nplane, shp_nchoppers, shp_nxlight, shp_nland, and struct lndstr members lnd_nxlight and lnd_nland. Don't compute/update load counters in build_ship(), build_land(), land(), ldump(), load_plane_ship(), load_land_ship(), load_plane_land(), load_land_land(), lstat(), sdump(), shi(), sstat(), tend_land(), check_trade(), put_combat(), pln_oneway_to_carrier_ok), pln_newlanding(), fit_plane_on_ship(), fit_plane_on_land(), unit_list(). Nothing left in fit_plane_off_ship(), fit_plane_off_land(), so remove them. load_land_ship(), load_land_land(), check_trade(), pln_newlanding(), put_plane_on_ship(), take_plane_off_ship(), put_plane_on_land(), take_plane_off_land() no longer change the carrier, so don't put it. Remove functions to recompute the load counters from carrier uids: count_units(), lnd_count_units(), count_planes(), count_land_planes(), pln_fixup() and lnd_fixup(), along with the latter two's private copies of fit_plane_on_ship() and fit_plane_on_land(). New cargo list functions to compute load counts: unit_cargo_count() and unit_nplane(), with convenience wrappers shp_nplane(), shp_nland(), lnd_nxlight(), lnd_nland(). Use them to make ship selectors nplane, nchoppers, nxlight, nland virtual. They now reflect what is loaded, not how the load uses the available slots. This makes a difference when x-light planes or choppers use plane slots. Use them to make land unit selectors nxlight and nland virtual. Use them to get load counts in land(), ldump(), load_plane_ship(), load_land_ship(), load_plane_land(), load_land_land(), sdump(), shi(), tend_land(), fit_plane_on_land(), trade_desc(), unit_list(). Rewrite fit_plane_on_ship() and could_be_on_ship() to use shp_nplane(). could_be_on_ship() now takes load count arguments, as computed by shp_nplane(), so it can be used for checking against an existing load as well.
This commit is contained in:
parent
8b1470e3a8
commit
3e370da58c
22 changed files with 215 additions and 449 deletions
|
@ -359,10 +359,6 @@ build_ship(struct sctstr *sp, struct mchrstr *mp, short *vec, int tlev)
|
|||
} else {
|
||||
ship.shp_mobil = 0;
|
||||
}
|
||||
ship.shp_nplane = 0;
|
||||
ship.shp_nland = 0;
|
||||
ship.shp_nxlight = 0;
|
||||
ship.shp_nchoppers = 0;
|
||||
ship.shp_fleet = 0;
|
||||
memset(ship.shp_item, 0, sizeof(ship.shp_item));
|
||||
ship.shp_pstage = PLG_HEALTHY;
|
||||
|
@ -484,10 +480,8 @@ build_land(struct sctstr *sp, struct lchrstr *lp, short *vec, int tlev)
|
|||
land.lnd_flags = 0;
|
||||
land.lnd_ship = -1;
|
||||
land.lnd_land = -1;
|
||||
land.lnd_nland = 0;
|
||||
land.lnd_harden = 0;
|
||||
land.lnd_retreat = morale_base;
|
||||
land.lnd_nxlight = 0;
|
||||
land.lnd_rflags = 0;
|
||||
memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
|
||||
land.lnd_rad_max = 0;
|
||||
|
|
|
@ -53,9 +53,6 @@ land(void)
|
|||
continue;
|
||||
if (!player->owner && !player->god)
|
||||
continue;
|
||||
count_land_planes(&land);
|
||||
lnd_count_units(&land);
|
||||
|
||||
if (nunits++ == 0) {
|
||||
if (player->god)
|
||||
pr("own ");
|
||||
|
@ -78,8 +75,8 @@ land(void)
|
|||
pr("%4d ", land.lnd_tech);
|
||||
pr("%3d%%", land.lnd_retreat);
|
||||
pr("%3d", land.lnd_rad_max);
|
||||
pr("%3d", land.lnd_nxlight);
|
||||
pr("%3d", land.lnd_nland);
|
||||
pr("%3d", lnd_nxlight(&land));
|
||||
pr("%3d", lnd_nland(&land));
|
||||
if (land.lnd_ship >= 0)
|
||||
pr(" %4dS", land.lnd_ship);
|
||||
else if (land.lnd_land >= 0)
|
||||
|
|
|
@ -299,9 +299,6 @@ ldump(void)
|
|||
continue;
|
||||
if (!player->owner && !player->god)
|
||||
continue;
|
||||
count_land_planes(&land);
|
||||
lnd_count_units(&land);
|
||||
|
||||
nunits++;
|
||||
if (player->god)
|
||||
pr("%d ", land.lnd_own);
|
||||
|
@ -349,10 +346,10 @@ ldump(void)
|
|||
pr(" %d", land.lnd_rad_max);
|
||||
break;
|
||||
case 14:
|
||||
pr(" %d", land.lnd_nxlight);
|
||||
pr(" %d", lnd_nxlight(&land));
|
||||
break;
|
||||
case 15:
|
||||
pr(" %d", land.lnd_nland);
|
||||
pr(" %d", lnd_nland(&land));
|
||||
break;
|
||||
case 16:
|
||||
pr(" %d", land.lnd_land);
|
||||
|
|
|
@ -356,11 +356,9 @@ load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
|
|||
pr("%s cannot carry planes\n", prship(sp));
|
||||
return 0;
|
||||
}
|
||||
count_planes(sp);
|
||||
if (load_unload == LOAD &&
|
||||
sp->shp_nchoppers >= mcp->m_nchoppers &&
|
||||
sp->shp_nxlight >= mcp->m_nxlight &&
|
||||
sp->shp_nplane >= mcp->m_nplanes) {
|
||||
shp_nplane(sp, NULL, NULL, NULL)
|
||||
>= mcp->m_nchoppers + mcp->m_nxlight + mcp->m_nplanes) {
|
||||
if (noisy)
|
||||
pr("%s doesn't have room for any more planes\n", prship(sp));
|
||||
return 0;
|
||||
|
@ -419,7 +417,7 @@ load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
|
|||
continue;
|
||||
|
||||
/* ship to (plane or missle) sanity */
|
||||
if (!could_be_on_ship(&pln, sp)) {
|
||||
if (!could_be_on_ship(&pln, sp, 0, 0, 0, 0)) {
|
||||
if (plchr[(int)pln.pln_type].pl_flags & P_L) {
|
||||
strcpy(buf, "planes");
|
||||
} else if (plchr[(int)pln.pln_type].pl_flags & P_K) {
|
||||
|
@ -477,12 +475,11 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
|
|||
char buf[1024];
|
||||
int load_spy = 0;
|
||||
|
||||
count_units(sp);
|
||||
if (load_unload == LOAD) {
|
||||
if (opt_LANDSPIES) {
|
||||
if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
|
||||
(mchr[(int)sp->shp_type].m_nland == 0)) {
|
||||
if (sp->shp_nland >= 2) {
|
||||
if (shp_nland(sp) >= 2) {
|
||||
pr("Non-land unit carrying subs can only carry up to two spy units.\n");
|
||||
return 0;
|
||||
}
|
||||
|
@ -490,8 +487,7 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
|
|||
load_spy = 1;
|
||||
}
|
||||
}
|
||||
if ((!load_spy) &&
|
||||
(sp->shp_nland >= mchr[(int)sp->shp_type].m_nland)) {
|
||||
if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) {
|
||||
if (noisy) {
|
||||
if (mchr[(int)sp->shp_type].m_nland)
|
||||
pr("%s doesn't have room for any more land units!\n",
|
||||
|
@ -533,8 +529,7 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
|
|||
prland(&land), land.lnd_land);
|
||||
continue;
|
||||
}
|
||||
lnd_count_units(&land);
|
||||
if (land.lnd_nland > 0) {
|
||||
if (lnd_nland(&land)) {
|
||||
if (noisy)
|
||||
pr("%s cannot be loaded since it is carrying units\n",
|
||||
prland(&land));
|
||||
|
@ -574,12 +569,11 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
|
|||
}
|
||||
/* Fit unit on ship */
|
||||
if (load_unload == LOAD) {
|
||||
count_units(sp);
|
||||
/* We have to check again, since it may have changed */
|
||||
if (opt_LANDSPIES) {
|
||||
if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
|
||||
(mchr[(int)sp->shp_type].m_nland == 0)) {
|
||||
if (sp->shp_nland >= 2) {
|
||||
if (shp_nland(sp) >= 2) {
|
||||
pr("Non-land unit carrying subs can only carry up to two spy units.\n");
|
||||
return 0;
|
||||
}
|
||||
|
@ -587,8 +581,7 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
|
|||
load_spy = 1;
|
||||
}
|
||||
}
|
||||
if (!load_spy &&
|
||||
(sp->shp_nland >= mchr[(int)sp->shp_type].m_nland)) {
|
||||
if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) {
|
||||
if (noisy) {
|
||||
if (mchr[(int)sp->shp_type].m_nland)
|
||||
pr("%s doesn't have room for any more land units!\n",
|
||||
|
@ -605,11 +598,9 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
|
|||
land.lnd_harden = 0;
|
||||
land.lnd_mission = 0;
|
||||
resupply_all(&land);
|
||||
sp->shp_nland++;
|
||||
putland(land.lnd_uid, &land);
|
||||
if (!has_supply(&land))
|
||||
pr("WARNING: %s is out of supply!\n", prland(&land));
|
||||
putship(sp->shp_uid, sp);
|
||||
snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
|
||||
while (nxtitem(&pni, &plane)) {
|
||||
if (plane.pln_flags & PLN_LAUNCHED)
|
||||
|
@ -630,9 +621,7 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
|
|||
if (!(lchr[(int)land.lnd_type].l_flags & L_SPY))
|
||||
gift(sectp->sct_own, player->cnum, &land, buf);
|
||||
land.lnd_ship = -1;
|
||||
sp->shp_nland--;
|
||||
putland(land.lnd_uid, &land);
|
||||
putship(sp->shp_uid, sp);
|
||||
|
||||
/* Spies are unloaded quietly, others aren't, and
|
||||
in the off chance they can carry a plane (missile?)
|
||||
|
@ -759,8 +748,7 @@ load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
|
|||
pr("%s cannot carry extra-light planes.\n", prland(lp));
|
||||
return 0;
|
||||
}
|
||||
count_land_planes(lp);
|
||||
if (load_unload == LOAD && lp->lnd_nxlight >= lcp->l_nxlight) {
|
||||
if (load_unload == LOAD && lnd_nxlight(lp) >= lcp->l_nxlight) {
|
||||
if (noisy)
|
||||
pr("%s doesn't have room for any more extra-light planes\n",
|
||||
prland(lp));
|
||||
|
@ -946,12 +934,10 @@ load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
|
|||
char prompt[512];
|
||||
char buf[1024];
|
||||
|
||||
lnd_count_units(lp);
|
||||
|
||||
if (load_unload == LOAD
|
||||
&& lp->lnd_nland >= lchr[lp->lnd_type].l_nland) {
|
||||
&& lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
|
||||
if (noisy) {
|
||||
if (lp->lnd_nland)
|
||||
if (lchr[lp->lnd_type].l_nland)
|
||||
pr("%s doesn't have room for any more land units!\n",
|
||||
prland(lp));
|
||||
else
|
||||
|
@ -991,8 +977,7 @@ load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
|
|||
prland(&land), land.lnd_land);
|
||||
continue;
|
||||
}
|
||||
lnd_count_units(&land);
|
||||
if (land.lnd_nland > 0) {
|
||||
if (lnd_nland(&land)) {
|
||||
if (noisy)
|
||||
pr("%s cannot be loaded since it is carrying units\n",
|
||||
prland(&land));
|
||||
|
@ -1022,10 +1007,9 @@ 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 >= lchr[lp->lnd_type].l_nland) {
|
||||
if (lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
|
||||
if (noisy) {
|
||||
if (lp->lnd_nland)
|
||||
if (lchr[lp->lnd_type].l_nland)
|
||||
pr("%s doesn't have room for any more land units!\n",
|
||||
prland(lp));
|
||||
else
|
||||
|
@ -1040,11 +1024,9 @@ load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
|
|||
land.lnd_harden = 0;
|
||||
land.lnd_mission = 0;
|
||||
resupply_all(&land);
|
||||
lp->lnd_nland++;
|
||||
putland(land.lnd_uid, &land);
|
||||
if (!has_supply(&land))
|
||||
pr("WARNING: %s is out of supply!\n", prland(&land));
|
||||
putland(lp->lnd_uid, lp);
|
||||
snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
|
||||
while (nxtitem(&pni, &plane)) {
|
||||
if (plane.pln_flags & PLN_LAUNCHED)
|
||||
|
@ -1062,9 +1044,7 @@ load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
|
|||
xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
|
||||
gift(sectp->sct_own, player->cnum, &land, buf);
|
||||
land.lnd_land = -1;
|
||||
lp->lnd_nland--;
|
||||
putland(land.lnd_uid, &land);
|
||||
putland(lp->lnd_uid, lp);
|
||||
snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
|
||||
while (nxtitem(&pni, &plane)) {
|
||||
if (plane.pln_flags & PLN_LAUNCHED)
|
||||
|
|
|
@ -52,8 +52,6 @@ lsta(void)
|
|||
if (!player->owner || land.lnd_own == 0)
|
||||
continue;
|
||||
lcp = lchr + land.lnd_type;
|
||||
count_land_planes(&land);
|
||||
|
||||
if (nunits++ == 0) {
|
||||
pr(" %16.16s s v s r r a f a a\n", "");
|
||||
pr(" %16.16s p i p a n c i m a\n", "");
|
||||
|
|
|
@ -47,7 +47,7 @@ sdump(void)
|
|||
struct shpstr ship;
|
||||
int field[128];
|
||||
struct natstr *np;
|
||||
int n, i;
|
||||
int n, i, npln, nch, nxl;
|
||||
time_t now;
|
||||
|
||||
if (!snxtitem(&ni, EF_SHIP, player->argp[1], NULL))
|
||||
|
@ -263,9 +263,8 @@ sdump(void)
|
|||
while (nxtitem(&ni, &ship)) {
|
||||
if (!player->owner || ship.shp_own == 0)
|
||||
continue;
|
||||
count_planes(&ship);
|
||||
count_units(&ship);
|
||||
nships++;
|
||||
npln = shp_nplane(&ship, &nch, &nxl, NULL);
|
||||
if (player->god)
|
||||
pr("%d ", ship.shp_own);
|
||||
pr("%d", ni.cur);
|
||||
|
@ -300,16 +299,16 @@ sdump(void)
|
|||
pr(" %d", ship.shp_item[I_FOOD]);
|
||||
break;
|
||||
case 10:
|
||||
pr(" %d", ship.shp_nplane);
|
||||
pr(" %d", npln - nch - nxl);
|
||||
break;
|
||||
case 11:
|
||||
pr(" %d", ship.shp_nchoppers);
|
||||
pr(" %d", nch);
|
||||
break;
|
||||
case 12:
|
||||
pr(" %d", ship.shp_nxlight);
|
||||
pr(" %d", nxl);
|
||||
break;
|
||||
case 13:
|
||||
pr(" %d", ship.shp_nland);
|
||||
pr(" %d", shp_nland(&ship));
|
||||
break;
|
||||
case 14:
|
||||
pr(" %d", ship.shp_mobil);
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
int
|
||||
shi(void)
|
||||
{
|
||||
int nships, noff;
|
||||
int nships, noff, npln, nch, nxl;
|
||||
struct nstr_item ni;
|
||||
struct shpstr ship;
|
||||
|
||||
|
@ -52,8 +52,6 @@ shi(void)
|
|||
while (nxtitem(&ni, &ship)) {
|
||||
if (!player->owner || ship.shp_own == 0)
|
||||
continue;
|
||||
count_planes(&ship);
|
||||
count_units(&ship);
|
||||
if (nships++ == 0) {
|
||||
if (player->god)
|
||||
pr("own ");
|
||||
|
@ -76,10 +74,9 @@ shi(void)
|
|||
pr("%4d", ship.shp_item[I_UW]);
|
||||
pr("%4d", ship.shp_item[I_FOOD]);
|
||||
|
||||
pr("%3d", ship.shp_nplane);
|
||||
pr("%3d", ship.shp_nchoppers);
|
||||
pr("%3d", ship.shp_nxlight);
|
||||
pr("%3d", ship.shp_nland);
|
||||
npln = shp_nplane(&ship, &nch, &nxl, NULL);
|
||||
pr("%3d%3d%3d", npln - nch - nxl, nch, nxl);
|
||||
pr("%3d", shp_nland(&ship));
|
||||
pr("%4d", ship.shp_mobil);
|
||||
pr("%5d\n", ship.shp_tech);
|
||||
if (ship.shp_name[0] != 0) {
|
||||
|
|
|
@ -51,9 +51,6 @@ sstat(void)
|
|||
while (nxtitem(&ni, &ship)) {
|
||||
if (!player->owner || ship.shp_own == 0)
|
||||
continue;
|
||||
count_planes(&ship);
|
||||
count_units(&ship);
|
||||
|
||||
if (nships++ == 0) {
|
||||
pr("shp# %22.22s x,y eff tech def spd vis rng fir\n",
|
||||
"ship-type");
|
||||
|
|
|
@ -242,7 +242,6 @@ tend_land(struct shpstr *tenderp, char *units)
|
|||
continue;
|
||||
|
||||
/* Fit unit on ship */
|
||||
count_units(&target);
|
||||
getship(target.shp_uid, &target);
|
||||
|
||||
if ((!(lchr[(int)land.lnd_type].l_flags & L_LIGHT)) &&
|
||||
|
@ -257,12 +256,12 @@ tend_land(struct shpstr *tenderp, char *units)
|
|||
if ((mchr[(int)target.shp_type].m_flags & M_SUB) &&
|
||||
(lchr[(int)land.lnd_type].l_flags & L_SPY) &&
|
||||
!mchr[(int)target.shp_type].m_nland) {
|
||||
if (target.shp_nland > 1) {
|
||||
if (shp_nland(&target) > 1) {
|
||||
pr("%s doesn't have room for more than two spy units!\n",
|
||||
prship(&target));
|
||||
continue;
|
||||
}
|
||||
} else if (target.shp_nland >= mchr[(int)target.shp_type].m_nland) {
|
||||
} else if (shp_nland(&target) >= mchr[target.shp_type].m_nland) {
|
||||
if (mchr[(int)target.shp_type].m_nland)
|
||||
pr("%s doesn't have room for any more land units!\n",
|
||||
prship(&target));
|
||||
|
@ -279,11 +278,9 @@ tend_land(struct shpstr *tenderp, char *units)
|
|||
land.lnd_ship = target.shp_uid;
|
||||
land.lnd_harden = 0;
|
||||
land.lnd_mission = 0;
|
||||
target.shp_nland++;
|
||||
putland(land.lnd_uid, &land);
|
||||
expose_ship(tenderp, &target);
|
||||
putship(target.shp_uid, &target);
|
||||
count_units(tenderp);
|
||||
putship(tenderp->shp_uid, tenderp);
|
||||
snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
|
||||
while (nxtitem(&pni, &plane)) {
|
||||
|
|
|
@ -379,12 +379,6 @@ check_trade(void)
|
|||
case EF_LAND:
|
||||
tg.land.lnd_x = trade.trd_x;
|
||||
tg.land.lnd_y = trade.trd_y;
|
||||
if (tg.land.lnd_ship >= 0) {
|
||||
struct shpstr ship;
|
||||
getship(tg.land.lnd_ship, &ship);
|
||||
ship.shp_nland--;
|
||||
putship(ship.shp_uid, &ship);
|
||||
}
|
||||
tg.land.lnd_own = trade.trd_maxbidder;
|
||||
tg.land.lnd_army = 0;
|
||||
/* no cheap version of fly */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue