Sectors need space for items, deliveries and distribution thresholds.
To save space, the ancients invented `variables': a collection of key-value pairs, missing means zero value, space for `enough' keys. This complicates the code, as assigning to a `variable' can fail for lack of space. Over time, `enough' increased, and for quite some time now `variables' have been *wasting* space. This changeset replaces them, except in struct mchrstr, struct lchrstr and struct pchrstr, where they are read-only, and will be replaced later. It is only a first step; further cleanup is required. To simplify and minimize this necessarily huge changeset, the new item[] arrays have an unused slot 0, and the old variable types V_CIVIL, ... are still defined, but must have the same values as the item types I_CIVIL, ...
This commit is contained in:
parent
ba86513b01
commit
eccc5cb7d7
86 changed files with 853 additions and 1226 deletions
|
@ -56,7 +56,6 @@ mine(void)
|
|||
int mines;
|
||||
int shells;
|
||||
int mines_avail;
|
||||
int mines_there;
|
||||
|
||||
if (!snxtitem(&ni, EF_SHIP, player->argp[1]))
|
||||
return RET_SYN;
|
||||
|
@ -70,7 +69,7 @@ mine(void)
|
|||
mp = &mchr[(int)ship.shp_type];
|
||||
if ((mp->m_flags & M_MINE) == 0)
|
||||
continue;
|
||||
if ((shells = getvar(V_SHELL, (s_char *)&ship, EF_SHIP)) == 0)
|
||||
if ((shells = ship.shp_item[I_SHELL]) == 0)
|
||||
continue;
|
||||
mines_avail = min(shells, mines);
|
||||
if (getsect(ship.shp_x, ship.shp_y, §) == 0 ||
|
||||
|
@ -78,10 +77,8 @@ mine(void)
|
|||
pr("You can't lay mines there!!\n");
|
||||
continue;
|
||||
}
|
||||
mines_there = getvar(V_MINE, (s_char *)§, EF_SECTOR);
|
||||
putvar(V_SHELL, shells - mines_avail, (s_char *)&ship, EF_SHIP);
|
||||
putvar(V_MINE, mines_avail + mines_there, (s_char *)§,
|
||||
EF_SECTOR);
|
||||
sect.sct_mines += mines_avail;
|
||||
ship.shp_item[I_SHELL] = shells - mines_avail;
|
||||
putsect(§);
|
||||
ship.shp_mission = 0;
|
||||
putship(ship.shp_uid, &ship);
|
||||
|
@ -104,7 +101,6 @@ landmine(void)
|
|||
struct lchrstr *lp;
|
||||
struct nstr_item ni;
|
||||
int shells;
|
||||
int mines_there;
|
||||
int mines_wanted;
|
||||
int mines_laid;
|
||||
int total_mines_laid;
|
||||
|
@ -124,7 +120,7 @@ landmine(void)
|
|||
}
|
||||
resupply_commod(&land, I_SHELL);
|
||||
putland(land.lnd_uid, &land);
|
||||
if (!(shells = getvar(V_SHELL, (s_char *)&land, EF_LAND)))
|
||||
if (!(shells = land.lnd_item[I_SHELL]))
|
||||
continue;
|
||||
shells = min(shells, land.lnd_mobil);
|
||||
if (!getsect(land.lnd_x, land.lnd_y, §) ||
|
||||
|
@ -132,10 +128,9 @@ landmine(void)
|
|||
pr("You can't lay mines there!!\n");
|
||||
continue;
|
||||
}
|
||||
mines_there = getvar(V_MINE, (s_char *)§, EF_SECTOR);
|
||||
if (sect.sct_own == sect.sct_oldown)
|
||||
pr("There are currently %d mines in %s\n",
|
||||
mines_there, xyas(sect.sct_x, sect.sct_y, player->cnum));
|
||||
sect.sct_mines, xyas(sect.sct_x, sect.sct_y, player->cnum));
|
||||
sprintf(prompt, "Drop how many mines from %s? ", prland(&land));
|
||||
mines_wanted = onearg(player->argp[2], prompt);
|
||||
if (!check_land_ok(&land))
|
||||
|
@ -146,18 +141,17 @@ landmine(void)
|
|||
total_mines_laid = 0;
|
||||
while (shells > 0 && total_mines_laid < mines_wanted) {
|
||||
mines_laid = min(shells, mines_wanted - total_mines_laid);
|
||||
putvar(V_SHELL, shells - mines_laid, (s_char *)&land, EF_LAND);
|
||||
land.lnd_item[I_SHELL] = shells - mines_laid;
|
||||
land.lnd_mobil -= mines_laid;
|
||||
putland(land.lnd_uid, &land);
|
||||
resupply_commod(&land, I_SHELL); /* Get more shells */
|
||||
putland(land.lnd_uid, &land);
|
||||
total_mines_laid += mines_laid;
|
||||
shells = getvar(V_SHELL, (s_char *)&land, EF_LAND);
|
||||
shells = land.lnd_item[I_SHELL];
|
||||
shells = min(shells, land.lnd_mobil);
|
||||
}
|
||||
getsect(sect.sct_x, sect.sct_y, §);
|
||||
putvar(V_MINE, total_mines_laid + mines_there, (s_char *)§,
|
||||
EF_SECTOR);
|
||||
sect.sct_mines += total_mines_laid;
|
||||
putsect(§);
|
||||
if (total_mines_laid == mines_wanted) {
|
||||
pr("%s laid a total of %d mines in %s",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue