Use new snxtitem_cargo() to simplify a couple of loops
Change snxtitem_all() loops that skip everything but a carrier's cargo to use snxtitem_cargo() in scra(), scuttle_ship(), scuttle_land(), takeover_ship(), takeover_land(), trade_desc(), feed_ship().
This commit is contained in:
parent
3cf29456fe
commit
2a9b89693e
5 changed files with 138 additions and 198 deletions
|
@ -178,11 +178,8 @@ scra(void)
|
||||||
sect.sct_item[I_LCM] += mp->m_lcm * 2 / 3 * eff;
|
sect.sct_item[I_LCM] += mp->m_lcm * 2 / 3 * eff;
|
||||||
sect.sct_item[I_HCM] += mp->m_hcm * 2 / 3 * eff;
|
sect.sct_item[I_HCM] += mp->m_hcm * 2 / 3 * eff;
|
||||||
getsect(item.ship.shp_x, item.ship.shp_y, §2);
|
getsect(item.ship.shp_x, item.ship.shp_y, §2);
|
||||||
snxtitem_all(&ni2, EF_PLANE);
|
snxtitem_cargo(&ni2, EF_PLANE, EF_SHIP, item.ship.shp_uid);
|
||||||
while (nxtitem(&ni2, &plane)) {
|
while (nxtitem(&ni2, &plane)) {
|
||||||
if (plane.pln_own == 0)
|
|
||||||
continue;
|
|
||||||
if (plane.pln_ship == item.ship.shp_uid) {
|
|
||||||
wu(0, plane.pln_own,
|
wu(0, plane.pln_own,
|
||||||
"Plane %d transferred off ship %d to %s\n",
|
"Plane %d transferred off ship %d to %s\n",
|
||||||
ni2.cur, item.ship.shp_uid,
|
ni2.cur, item.ship.shp_uid,
|
||||||
|
@ -199,12 +196,8 @@ scra(void)
|
||||||
plane.pln_own = sect2.sct_own;
|
plane.pln_own = sect2.sct_own;
|
||||||
putplane(plane.pln_uid, &plane);
|
putplane(plane.pln_uid, &plane);
|
||||||
}
|
}
|
||||||
}
|
snxtitem_cargo(&ni2, EF_LAND, EF_SHIP, item.ship.shp_uid);
|
||||||
snxtitem_all(&ni2, EF_LAND);
|
|
||||||
while (nxtitem(&ni2, &land)) {
|
while (nxtitem(&ni2, &land)) {
|
||||||
if (land.lnd_own == 0)
|
|
||||||
continue;
|
|
||||||
if (land.lnd_ship == item.ship.shp_uid) {
|
|
||||||
wu(0, land.lnd_own,
|
wu(0, land.lnd_own,
|
||||||
"Land unit %d transferred off ship %d to %s\n",
|
"Land unit %d transferred off ship %d to %s\n",
|
||||||
ni2.cur, item.ship.shp_uid,
|
ni2.cur, item.ship.shp_uid,
|
||||||
|
@ -221,7 +214,6 @@ scra(void)
|
||||||
land.lnd_own = sect2.sct_own;
|
land.lnd_own = sect2.sct_own;
|
||||||
putland(land.lnd_uid, &land);
|
putland(land.lnd_uid, &land);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
item.ship.shp_effic = 0;
|
item.ship.shp_effic = 0;
|
||||||
putship(item.ship.shp_uid, &item.ship);
|
putship(item.ship.shp_uid, &item.ship);
|
||||||
} else if (type == EF_LAND) {
|
} else if (type == EF_LAND) {
|
||||||
|
@ -235,11 +227,8 @@ scra(void)
|
||||||
sect.sct_item[I_HCM] += lp->l_hcm * 2 / 3 * eff;
|
sect.sct_item[I_HCM] += lp->l_hcm * 2 / 3 * eff;
|
||||||
getsect(item.land.lnd_x, item.land.lnd_y, §2);
|
getsect(item.land.lnd_x, item.land.lnd_y, §2);
|
||||||
|
|
||||||
snxtitem_all(&ni2, EF_LAND);
|
snxtitem_cargo(&ni2, EF_LAND, EF_LAND, item.land.lnd_uid);
|
||||||
while (nxtitem(&ni2, &land)) {
|
while (nxtitem(&ni2, &land)) {
|
||||||
if (land.lnd_own == 0)
|
|
||||||
continue;
|
|
||||||
if (land.lnd_land == item.land.lnd_uid) {
|
|
||||||
wu(0, land.lnd_own,
|
wu(0, land.lnd_own,
|
||||||
"Land unit %d transferred off land unit %d to %s\n",
|
"Land unit %d transferred off land unit %d to %s\n",
|
||||||
land.lnd_uid, item.land.lnd_uid,
|
land.lnd_uid, item.land.lnd_uid,
|
||||||
|
@ -256,13 +245,9 @@ scra(void)
|
||||||
land.lnd_own = sect2.sct_own;
|
land.lnd_own = sect2.sct_own;
|
||||||
putland(land.lnd_uid, &land);
|
putland(land.lnd_uid, &land);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
snxtitem_all(&ni2, EF_PLANE);
|
snxtitem_cargo(&ni2, EF_PLANE, EF_LAND, item.land.lnd_uid);
|
||||||
while (nxtitem(&ni2, &plane)) {
|
while (nxtitem(&ni2, &plane)) {
|
||||||
if (plane.pln_own == 0)
|
|
||||||
continue;
|
|
||||||
if (plane.pln_land == item.land.lnd_uid) {
|
|
||||||
wu(0, plane.pln_own,
|
wu(0, plane.pln_own,
|
||||||
"Plane %d transferred off land unit %d to %s\n",
|
"Plane %d transferred off land unit %d to %s\n",
|
||||||
ni2.cur, item.land.lnd_uid,
|
ni2.cur, item.land.lnd_uid,
|
||||||
|
@ -279,7 +264,6 @@ scra(void)
|
||||||
plane.pln_own = sect2.sct_own;
|
plane.pln_own = sect2.sct_own;
|
||||||
putplane(plane.pln_uid, &plane);
|
putplane(plane.pln_uid, &plane);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
item.land.lnd_effic = 0;
|
item.land.lnd_effic = 0;
|
||||||
putland(item.land.lnd_uid, &item.land);
|
putland(item.land.lnd_uid, &item.land);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -244,11 +244,8 @@ scuttle_ship(struct shpstr *sp)
|
||||||
struct lndstr land;
|
struct lndstr land;
|
||||||
|
|
||||||
getsect(sp->shp_x, sp->shp_y, §);
|
getsect(sp->shp_x, sp->shp_y, §);
|
||||||
snxtitem_all(&ni, EF_PLANE);
|
snxtitem_cargo(&ni, EF_PLANE, EF_SHIP, sp->shp_uid);
|
||||||
while (nxtitem(&ni, &plane)) {
|
while (nxtitem(&ni, &plane)) {
|
||||||
if (plane.pln_own == 0)
|
|
||||||
continue;
|
|
||||||
if (plane.pln_ship == sp->shp_uid) {
|
|
||||||
plane.pln_ship = -1;
|
plane.pln_ship = -1;
|
||||||
if (sect.sct_own != sp->shp_own) {
|
if (sect.sct_own != sp->shp_own) {
|
||||||
wu(0, plane.pln_own, "Plane %d scuttled in %s\n",
|
wu(0, plane.pln_own, "Plane %d scuttled in %s\n",
|
||||||
|
@ -263,12 +260,8 @@ scuttle_ship(struct shpstr *sp)
|
||||||
}
|
}
|
||||||
putplane(plane.pln_uid, &plane);
|
putplane(plane.pln_uid, &plane);
|
||||||
}
|
}
|
||||||
}
|
snxtitem_cargo(&ni, EF_LAND, EF_SHIP, sp->shp_uid);
|
||||||
snxtitem_all(&ni, EF_LAND);
|
|
||||||
while (nxtitem(&ni, &land)) {
|
while (nxtitem(&ni, &land)) {
|
||||||
if (land.lnd_own == 0)
|
|
||||||
continue;
|
|
||||||
if (land.lnd_ship == sp->shp_uid) {
|
|
||||||
land.lnd_ship = -1;
|
land.lnd_ship = -1;
|
||||||
if (sect.sct_own == sp->shp_own) {
|
if (sect.sct_own == sp->shp_own) {
|
||||||
wu(0, land.lnd_own,
|
wu(0, land.lnd_own,
|
||||||
|
@ -279,7 +272,6 @@ scuttle_ship(struct shpstr *sp)
|
||||||
} else
|
} else
|
||||||
scuttle_land(&land);
|
scuttle_land(&land);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
sp->shp_effic = 0;
|
sp->shp_effic = 0;
|
||||||
putship(sp->shp_uid, sp);
|
putship(sp->shp_uid, sp);
|
||||||
}
|
}
|
||||||
|
@ -293,11 +285,8 @@ scuttle_land(struct lndstr *lp)
|
||||||
struct lndstr land;
|
struct lndstr land;
|
||||||
|
|
||||||
getsect(lp->lnd_x, lp->lnd_y, §);
|
getsect(lp->lnd_x, lp->lnd_y, §);
|
||||||
snxtitem_all(&ni, EF_PLANE);
|
snxtitem_cargo(&ni, EF_PLANE, EF_LAND, lp->lnd_uid);
|
||||||
while (nxtitem(&ni, &plane)) {
|
while (nxtitem(&ni, &plane)) {
|
||||||
if (plane.pln_own == 0)
|
|
||||||
continue;
|
|
||||||
if (plane.pln_land == lp->lnd_uid) {
|
|
||||||
plane.pln_land = -1;
|
plane.pln_land = -1;
|
||||||
if (sect.sct_own != lp->lnd_own) {
|
if (sect.sct_own != lp->lnd_own) {
|
||||||
wu(0, plane.pln_own, "Plane %d scuttled in %s\n",
|
wu(0, plane.pln_own, "Plane %d scuttled in %s\n",
|
||||||
|
@ -312,12 +301,8 @@ scuttle_land(struct lndstr *lp)
|
||||||
}
|
}
|
||||||
putplane(plane.pln_uid, &plane);
|
putplane(plane.pln_uid, &plane);
|
||||||
}
|
}
|
||||||
}
|
snxtitem_cargo(&ni, EF_LAND, EF_LAND, lp->lnd_uid);
|
||||||
snxtitem_all(&ni, EF_LAND);
|
|
||||||
while (nxtitem(&ni, &land)) {
|
while (nxtitem(&ni, &land)) {
|
||||||
if (land.lnd_own == 0)
|
|
||||||
continue;
|
|
||||||
if (land.lnd_land == lp->lnd_uid) {
|
|
||||||
land.lnd_land = -1;
|
land.lnd_land = -1;
|
||||||
if (sect.sct_own == lp->lnd_own) {
|
if (sect.sct_own == lp->lnd_own) {
|
||||||
wu(0, land.lnd_own,
|
wu(0, land.lnd_own,
|
||||||
|
@ -328,7 +313,6 @@ scuttle_land(struct lndstr *lp)
|
||||||
} else
|
} else
|
||||||
scuttle_land(&land);
|
scuttle_land(&land);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
lp->lnd_effic = 0;
|
lp->lnd_effic = 0;
|
||||||
putland(lp->lnd_uid, lp);
|
putland(lp->lnd_uid, lp);
|
||||||
}
|
}
|
||||||
|
|
|
@ -229,12 +229,8 @@ takeover_ship(struct shpstr *sp, natid newown, int hostile)
|
||||||
pp = &p;
|
pp = &p;
|
||||||
lp = &llp;
|
lp = &llp;
|
||||||
/* Take over planes */
|
/* Take over planes */
|
||||||
snxtitem_all(&ni, EF_PLANE);
|
snxtitem_cargo(&ni, EF_PLANE, EF_SHIP, sp->shp_uid);
|
||||||
while (nxtitem(&ni, pp)) {
|
while (nxtitem(&ni, pp)) {
|
||||||
if (pp->pln_ship != sp->shp_uid)
|
|
||||||
continue;
|
|
||||||
if (pp->pln_own == 0)
|
|
||||||
continue;
|
|
||||||
if (hostile) {
|
if (hostile) {
|
||||||
if (pp->pln_effic > PLANE_MINEFF)
|
if (pp->pln_effic > PLANE_MINEFF)
|
||||||
pp->pln_effic = PLANE_MINEFF;
|
pp->pln_effic = PLANE_MINEFF;
|
||||||
|
@ -249,14 +245,9 @@ takeover_ship(struct shpstr *sp, natid newown, int hostile)
|
||||||
putplane(pp->pln_uid, pp);
|
putplane(pp->pln_uid, pp);
|
||||||
}
|
}
|
||||||
/* Take over land units */
|
/* Take over land units */
|
||||||
snxtitem_all(&ni, EF_LAND);
|
snxtitem_cargo(&ni, EF_LAND, EF_SHIP, sp->shp_uid);
|
||||||
while (nxtitem(&ni, lp)) {
|
while (nxtitem(&ni, lp))
|
||||||
if (lp->lnd_ship != sp->shp_uid)
|
|
||||||
continue;
|
|
||||||
if (lp->lnd_own == 0)
|
|
||||||
continue;
|
|
||||||
takeover_land(lp, newown, hostile);
|
takeover_land(lp, newown, hostile);
|
||||||
}
|
|
||||||
putship(sp->shp_uid, sp);
|
putship(sp->shp_uid, sp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,12 +276,8 @@ takeover_land(struct lndstr *landp, natid newown, int hostile)
|
||||||
pp = &p;
|
pp = &p;
|
||||||
lp = &llp;
|
lp = &llp;
|
||||||
/* Take over planes */
|
/* Take over planes */
|
||||||
snxtitem_all(&ni, EF_PLANE);
|
snxtitem_cargo(&ni, EF_PLANE, EF_LAND, landp->lnd_uid);
|
||||||
while (nxtitem(&ni, pp)) {
|
while (nxtitem(&ni, pp)) {
|
||||||
if (pp->pln_land != landp->lnd_uid)
|
|
||||||
continue;
|
|
||||||
if (pp->pln_own == 0)
|
|
||||||
continue;
|
|
||||||
if (hostile) {
|
if (hostile) {
|
||||||
if (pp->pln_effic > PLANE_MINEFF)
|
if (pp->pln_effic > PLANE_MINEFF)
|
||||||
pp->pln_effic = PLANE_MINEFF;
|
pp->pln_effic = PLANE_MINEFF;
|
||||||
|
@ -305,13 +292,8 @@ takeover_land(struct lndstr *landp, natid newown, int hostile)
|
||||||
putplane(pp->pln_uid, pp);
|
putplane(pp->pln_uid, pp);
|
||||||
}
|
}
|
||||||
/* Take over land units */
|
/* Take over land units */
|
||||||
snxtitem_all(&ni, EF_LAND);
|
snxtitem_cargo(&ni, EF_LAND, EF_LAND, landp->lnd_uid);
|
||||||
while (nxtitem(&ni, lp)) {
|
while (nxtitem(&ni, lp))
|
||||||
if (lp->lnd_land != landp->lnd_uid)
|
|
||||||
continue;
|
|
||||||
if (lp->lnd_own == 0)
|
|
||||||
continue;
|
|
||||||
takeover_land(lp, newown, hostile);
|
takeover_land(lp, newown, hostile);
|
||||||
}
|
|
||||||
putland(landp->lnd_uid, landp);
|
putland(landp->lnd_uid, landp);
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,9 +130,8 @@ trade_desc(struct trdstr *tp, union empobj_storage *tgp)
|
||||||
}
|
}
|
||||||
pr("] #%d", tp->trd_unitid);
|
pr("] #%d", tp->trd_unitid);
|
||||||
if (opt_SHOWPLANE) {
|
if (opt_SHOWPLANE) {
|
||||||
snxtitem_all(&ni, EF_PLANE);
|
snxtitem_cargo(&ni, EF_PLANE, EF_SHIP, sp->shp_uid);
|
||||||
while (nxtitem(&ni, &plane)) {
|
while (nxtitem(&ni, &plane)) {
|
||||||
if (plane.pln_ship == sp->shp_uid && plane.pln_own != 0) {
|
|
||||||
pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
|
pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
|
||||||
plane.pln_tech,
|
plane.pln_tech,
|
||||||
plane.pln_effic,
|
plane.pln_effic,
|
||||||
|
@ -140,18 +139,15 @@ trade_desc(struct trdstr *tp, union empobj_storage *tgp)
|
||||||
if (getnuke(nuk_on_plane(&plane), &nuke))
|
if (getnuke(nuk_on_plane(&plane), &nuke))
|
||||||
pr("(%s)", nchr[nuke.nuk_type].n_name);
|
pr("(%s)", nchr[nuke.nuk_type].n_name);
|
||||||
}
|
}
|
||||||
}
|
snxtitem_cargo(&ni, EF_LAND, EF_SHIP, sp->shp_uid);
|
||||||
snxtitem_all(&ni, EF_LAND);
|
|
||||||
while (nxtitem(&ni, &land)) {
|
while (nxtitem(&ni, &land)) {
|
||||||
if (land.lnd_ship == sp->shp_uid && land.lnd_own != 0) {
|
|
||||||
pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
|
pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
|
||||||
land.lnd_tech,
|
land.lnd_tech,
|
||||||
land.lnd_effic,
|
land.lnd_effic,
|
||||||
lchr[(int)land.lnd_type].l_name, land.lnd_uid);
|
lchr[(int)land.lnd_type].l_name, land.lnd_uid);
|
||||||
if (pln_first_on_land(&land) >= 0) {
|
if (pln_first_on_land(&land) >= 0) {
|
||||||
snxtitem_all(&ni, EF_PLANE);
|
snxtitem_cargo(&ni, EF_PLANE, EF_LAND, land.lnd_uid);
|
||||||
while (nxtitem(&ni, &plane)) {
|
while (nxtitem(&ni, &plane)) {
|
||||||
if (plane.pln_land == land.lnd_uid) {
|
|
||||||
pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
|
pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
|
||||||
plane.pln_tech,
|
plane.pln_tech,
|
||||||
plane.pln_effic,
|
plane.pln_effic,
|
||||||
|
@ -163,8 +159,6 @@ trade_desc(struct trdstr *tp, union empobj_storage *tgp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
getsect(sp->shp_x, sp->shp_y, §);
|
getsect(sp->shp_x, sp->shp_y, §);
|
||||||
if (sect.sct_type != SCT_WATER)
|
if (sect.sct_type != SCT_WATER)
|
||||||
pr(" in a %s %s",
|
pr(" in a %s %s",
|
||||||
|
@ -184,9 +178,8 @@ trade_desc(struct trdstr *tp, union empobj_storage *tgp)
|
||||||
}
|
}
|
||||||
pr("] #%d", tp->trd_unitid);
|
pr("] #%d", tp->trd_unitid);
|
||||||
if (opt_SHOWPLANE) {
|
if (opt_SHOWPLANE) {
|
||||||
snxtitem_all(&ni, EF_PLANE);
|
snxtitem_cargo(&ni, EF_PLANE, EF_LAND, lp->lnd_uid);
|
||||||
while (nxtitem(&ni, &plane)) {
|
while (nxtitem(&ni, &plane)) {
|
||||||
if (plane.pln_land == lp->lnd_uid && plane.pln_own != 0) {
|
|
||||||
pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
|
pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
|
||||||
plane.pln_tech,
|
plane.pln_tech,
|
||||||
plane.pln_effic,
|
plane.pln_effic,
|
||||||
|
@ -195,7 +188,6 @@ trade_desc(struct trdstr *tp, union empobj_storage *tgp)
|
||||||
pr("(%s)", nchr[nuke.nuk_type].n_name);
|
pr("(%s)", nchr[nuke.nuk_type].n_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
getsect(lp->lnd_x, lp->lnd_y, §);
|
getsect(lp->lnd_x, lp->lnd_y, §);
|
||||||
break;
|
break;
|
||||||
case EF_PLANE:
|
case EF_PLANE:
|
||||||
|
|
|
@ -388,10 +388,8 @@ feed_ship(struct shpstr *sp, int etus)
|
||||||
needed - sp->shp_item[I_FOOD]);
|
needed - sp->shp_item[I_FOOD]);
|
||||||
if (needed > sp->shp_item[I_FOOD]) {
|
if (needed > sp->shp_item[I_FOOD]) {
|
||||||
/* take from embarked land units, but don't starve them */
|
/* take from embarked land units, but don't starve them */
|
||||||
snxtitem_all(&ni, EF_LAND);
|
snxtitem_cargo(&ni, EF_LAND, EF_SHIP, sp->shp_uid);
|
||||||
while ((lp = nxtitemp(&ni)) && needed > sp->shp_item[I_FOOD]) {
|
while ((lp = nxtitemp(&ni)) && needed > sp->shp_item[I_FOOD]) {
|
||||||
if (lp->lnd_ship != sp->shp_uid)
|
|
||||||
continue;
|
|
||||||
give = lp->lnd_item[I_FOOD] - food_needed(lp->lnd_item, etus);
|
give = lp->lnd_item[I_FOOD] - food_needed(lp->lnd_item, etus);
|
||||||
if (give < 1.0)
|
if (give < 1.0)
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue