(pln_equip, mission_pln_equip): Work directly on item arrays instead
of copies made by getvec(). This is safe, because the old code made single copies and always flushed them back into the unit structures before flushing those. Simplify.
This commit is contained in:
parent
e3390b9e0d
commit
5fb761ab45
2 changed files with 28 additions and 42 deletions
|
@ -1264,32 +1264,26 @@ mission_pln_equip(struct plist *plp, struct ichrstr *ip, int flags,
|
||||||
struct lndstr land;
|
struct lndstr land;
|
||||||
struct shpstr ship;
|
struct shpstr ship;
|
||||||
struct sctstr sect;
|
struct sctstr sect;
|
||||||
int type;
|
|
||||||
s_char *ptr;
|
|
||||||
int itype;
|
int itype;
|
||||||
int rval;
|
int rval;
|
||||||
int vec[I_MAX + 1];
|
short *item;
|
||||||
|
|
||||||
pp = &plp->plane;
|
pp = &plp->plane;
|
||||||
pcp = plp->pcp;
|
pcp = plp->pcp;
|
||||||
if (pp->pln_ship >= 0) {
|
if (pp->pln_ship >= 0) {
|
||||||
getship(pp->pln_ship, &ship);
|
getship(pp->pln_ship, &ship);
|
||||||
type = EF_SHIP;
|
item = ship.shp_item;
|
||||||
ptr = (s_char *)&ship;
|
|
||||||
} else if (pp->pln_land >= 0) {
|
} else if (pp->pln_land >= 0) {
|
||||||
getland(pp->pln_land, &land);
|
getland(pp->pln_land, &land);
|
||||||
type = EF_LAND;
|
item = land.lnd_item;
|
||||||
ptr = (s_char *)&land;
|
|
||||||
} else {
|
} else {
|
||||||
getsect(pp->pln_x, pp->pln_y, §);
|
getsect(pp->pln_x, pp->pln_y, §);
|
||||||
type = EF_SECTOR;
|
item = sect.sct_item;
|
||||||
ptr = (s_char *)§
|
|
||||||
}
|
}
|
||||||
getvec(VT_ITEM, vec, ptr, type);
|
if (pcp->pl_fuel > item[I_PETROL]) {
|
||||||
if (pcp->pl_fuel > vec[I_PETROL]) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
vec[I_PETROL] -= pcp->pl_fuel;
|
item[I_PETROL] -= pcp->pl_fuel;
|
||||||
rval = 0;
|
rval = 0;
|
||||||
if (!(flags & P_F)) {
|
if (!(flags & P_F)) {
|
||||||
itype = 0;
|
itype = 0;
|
||||||
|
@ -1336,24 +1330,23 @@ mission_pln_equip(struct plist *plp, struct ichrstr *ip, int flags,
|
||||||
if (rval < 0 || (itype && needed <= 0)) {
|
if (rval < 0 || (itype && needed <= 0)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (vec[itype] < needed && (itype == I_SHELL))
|
if (item[itype] < needed && (itype == I_SHELL))
|
||||||
vec[itype] += supply_commod(plp->plane.pln_own,
|
item[itype] += supply_commod(plp->plane.pln_own,
|
||||||
plp->plane.pln_x, plp->plane.pln_y,
|
plp->plane.pln_x, plp->plane.pln_y,
|
||||||
I_SHELL, needed);
|
I_SHELL, needed);
|
||||||
if (vec[itype] < needed) {
|
if (item[itype] < needed) {
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
vec[itype] -= needed;
|
item[itype] -= needed;
|
||||||
}
|
}
|
||||||
if (itype == I_SHELL && (mission == 's' || mission == 'p'))
|
if (itype == I_SHELL && (mission == 's' || mission == 'p'))
|
||||||
plp->bombs = needed;
|
plp->bombs = needed;
|
||||||
else
|
else
|
||||||
plp->misc = needed;
|
plp->misc = needed;
|
||||||
}
|
}
|
||||||
putvec(VT_ITEM, vec, ptr, type);
|
if (pp->pln_ship >= 0)
|
||||||
if (type == EF_SHIP)
|
|
||||||
putship(ship.shp_uid, &ship);
|
putship(ship.shp_uid, &ship);
|
||||||
else if (type == EF_LAND)
|
else if (pp->pln_land >= 0)
|
||||||
putland(land.lnd_uid, &land);
|
putland(land.lnd_uid, &land);
|
||||||
else
|
else
|
||||||
putsect(§);
|
putsect(§);
|
||||||
|
|
|
@ -520,29 +520,24 @@ pln_equip(struct plist *plp, struct ichrstr *ip, int flags, s_char mission)
|
||||||
struct lndstr land;
|
struct lndstr land;
|
||||||
struct shpstr ship;
|
struct shpstr ship;
|
||||||
struct sctstr sect;
|
struct sctstr sect;
|
||||||
int type;
|
|
||||||
s_char *ptr;
|
|
||||||
int itype;
|
int itype;
|
||||||
int rval;
|
int rval;
|
||||||
int vec[I_MAX + 1];
|
short *item;
|
||||||
int own;
|
int own;
|
||||||
|
|
||||||
pp = &plp->plane;
|
pp = &plp->plane;
|
||||||
pcp = plp->pcp;
|
pcp = plp->pcp;
|
||||||
if (pp->pln_ship >= 0) {
|
if (pp->pln_ship >= 0) {
|
||||||
getship(pp->pln_ship, &ship);
|
getship(pp->pln_ship, &ship);
|
||||||
type = EF_SHIP;
|
item = ship.shp_item;
|
||||||
ptr = (s_char *)&ship;
|
|
||||||
own = ship.shp_own;
|
own = ship.shp_own;
|
||||||
} else if (pp->pln_land >= 0) {
|
} else if (pp->pln_land >= 0) {
|
||||||
getland(pp->pln_land, &land);
|
getland(pp->pln_land, &land);
|
||||||
type = EF_LAND;
|
item = land.lnd_item;
|
||||||
ptr = (s_char *)&land;
|
|
||||||
own = land.lnd_own;
|
own = land.lnd_own;
|
||||||
} else {
|
} else {
|
||||||
getsect(pp->pln_x, pp->pln_y, §);
|
getsect(pp->pln_x, pp->pln_y, §);
|
||||||
type = EF_SECTOR;
|
item = sect.sct_item;
|
||||||
ptr = (s_char *)§
|
|
||||||
own = sect.sct_oldown;
|
own = sect.sct_oldown;
|
||||||
}
|
}
|
||||||
if (ip) {
|
if (ip) {
|
||||||
|
@ -553,12 +548,11 @@ pln_equip(struct plist *plp, struct ichrstr *ip, int flags, s_char mission)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getvec(VT_ITEM, vec, ptr, type);
|
if (pcp->pl_fuel > item[I_PETROL]) {
|
||||||
if (pcp->pl_fuel > vec[I_PETROL]) {
|
|
||||||
pr("%s not enough petrol there!\n", prplane(pp));
|
pr("%s not enough petrol there!\n", prplane(pp));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
vec[I_PETROL] -= pcp->pl_fuel;
|
item[I_PETROL] -= pcp->pl_fuel;
|
||||||
rval = 0;
|
rval = 0;
|
||||||
if ((flags & P_F) == 0) {
|
if ((flags & P_F) == 0) {
|
||||||
itype = 0;
|
itype = 0;
|
||||||
|
@ -609,31 +603,30 @@ pln_equip(struct plist *plp, struct ichrstr *ip, int flags, s_char mission)
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
/* Supply is broken somewhere, so don't use it for now */
|
/* Supply is broken somewhere, so don't use it for now */
|
||||||
if (vec[itype] < needed && itype == I_SHELL)
|
if (item[itype] < needed && itype == I_SHELL)
|
||||||
vec[itype] += supply_commod(plp->plane.pln_own,
|
item[itype] += supply_commod(plp->plane.pln_own,
|
||||||
plp->plane.pln_x, plp->plane.pln_y,
|
plp->plane.pln_x, plp->plane.pln_y,
|
||||||
I_SHELL, needed);
|
I_SHELL, needed);
|
||||||
#endif
|
#endif
|
||||||
if (vec[itype] < needed) {
|
if (item[itype] < needed) {
|
||||||
pr("Not enough %s for %s\n", ichr[itype].i_name, prplane(pp));
|
pr("Not enough %s for %s\n", ichr[itype].i_name, prplane(pp));
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
vec[itype] -= needed;
|
item[itype] -= needed;
|
||||||
}
|
}
|
||||||
if (itype == I_SHELL && (mission == 's' || mission == 'p'))
|
if (itype == I_SHELL && (mission == 's' || mission == 'p'))
|
||||||
plp->bombs = needed;
|
plp->bombs = needed;
|
||||||
else
|
else
|
||||||
plp->misc = needed;
|
plp->misc = needed;
|
||||||
}
|
}
|
||||||
putvec(VT_ITEM, vec, ptr, type);
|
if (pp->pln_ship >= 0) {
|
||||||
if (type == EF_SHIP) {
|
|
||||||
if (pp->pln_own != ship.shp_own) {
|
if (pp->pln_own != ship.shp_own) {
|
||||||
wu(0, ship.shp_own,
|
wu(0, ship.shp_own,
|
||||||
"%s %s prepares for takeoff from ship %s\n",
|
"%s %s prepares for takeoff from ship %s\n",
|
||||||
cname(pp->pln_own), prplane(pp), prship(&ship));
|
cname(pp->pln_own), prplane(pp), prship(&ship));
|
||||||
}
|
}
|
||||||
putship(ship.shp_uid, &ship);
|
putship(ship.shp_uid, &ship);
|
||||||
} else if (type == EF_LAND) {
|
} else if (pp->pln_land >= 0) {
|
||||||
if (pp->pln_own != land.lnd_own) {
|
if (pp->pln_own != land.lnd_own) {
|
||||||
wu(0, land.lnd_own,
|
wu(0, land.lnd_own,
|
||||||
"%s %s prepares for takeoff from unit %s\n",
|
"%s %s prepares for takeoff from unit %s\n",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue