/* Sector flags */
#define MOVE_IN_PROGRESS bit(0) /* move in progress */
-/* maximal number of che, must fit into struct sctstr member sct_che */
-#define CHE_MAX 255
+/* maximum number of che, must fit into struct sctstr member sct_che */
+#define CHE_MAX 255
+/* maximum number of mines, must fit into struct sctstr member sct_mines */
+#define MINES_MAX 65535
/* Each cost is per point of efficency */
struct sctintrins {
sect->sct_avail = new;
break;
case 'M':
- sect->sct_mines = arg;
- pr("Mines changed to %d\n", arg);
+ new = errcheck(arg, 0, MINES_MAX);
+ sect->sct_mines = new;
+ pr("Mines changed to %d\n", new);
break;
case 'L':
if (!sarg_xy(p, &newx, &newy))
if (!snxtitem(&ni, EF_SHIP, player->argp[1]))
return RET_SYN;
- mines =
- onearg(player->argp[2], "Drop how many mines from each ship? ");
+ mines = onearg(player->argp[2],
+ "Drop how many mines from each ship? ");
if (mines <= 0)
return RET_SYN;
while (nxtitem(&ni, (s_char *)&ship)) {
pr("You can't lay mines there!!\n");
continue;
}
- sect.sct_mines += mines_avail;
+ sect.sct_mines = min(sect.sct_mines + mines_avail, MINES_MAX);
ship.shp_item[I_SHELL] = shells - mines_avail;
putsect(§);
ship.shp_mission = 0;
shells = min(shells, land.lnd_mobil);
}
getsect(sect.sct_x, sect.sct_y, §);
- sect.sct_mines += total_mines_laid;
+ sect.sct_mines = min(sect.sct_mines + total_mines_laid, MINES_MAX);
putsect(§);
if (total_mines_laid == mines_wanted) {
pr("%s laid a total of %d mines in %s",
current += amt;
if (current < 0)
current = 0;
+ if (current > MINES_MAX)
+ current = MINES_MAX;
if (sect.sct_own != 0)
resnoise(§, 1, "Mines", sect.sct_mines, current);
sect.sct_mines = current;
sectp = ptr;
if (sectp->sct_type == SCT_WATER && ip->i_vtype == V_SHELL) {
/* aerial mining */
- sectp->sct_mines += amt;
+ sectp->sct_mines = min(sectp->sct_mines + amt, MINES_MAX);
pr("%d mines laid in %s.\n", amt,
xyas(sectp->sct_x, sectp->sct_y, player->cnum));
if (amt > 0