]> git.pond.sub.org Git - empserver/commitdiff
(MINES_MAX): New.
authorMarkus Armbruster <armbru@pond.sub.org>
Thu, 4 Mar 2004 15:54:46 +0000 (15:54 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Thu, 4 Mar 2004 15:54:46 +0000 (15:54 +0000)
(doland, mine, landmine, setsector, pln_dropoff): Use it.  With
variables, mining beyond the capacity of variables (65535) was
ignored.  Now the mines saturate at MINES_MAX.

include/sect.h
src/lib/commands/edit.c
src/lib/commands/mine.c
src/lib/commands/setsect.c
src/lib/subs/plnsub.c

index dd2224e0e14478ba9a623c110fa1fec1718a5c8f..3db5219806e8473f35a61dce595c02281bc44fc4 100644 (file)
@@ -184,8 +184,10 @@ extern struct dchrstr bigcity_dchr;
 /* 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 {
index f22d9b8080a34cc5e7dfa8f0b07dc619c9dceed8..274c0075b3efc89dfccf9703bd297edb30987227 100644 (file)
@@ -627,8 +627,9 @@ doland(s_char op, int arg, s_char *p, struct sctstr *sect)
        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))
index 964c0d497b442759b0a2a17e3f080947f98d9905..5fd0b7431efff00df7a8cea5244d8f5bfb0726ee 100644 (file)
@@ -59,8 +59,8 @@ mine(void)
 
     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)) {
@@ -77,7 +77,7 @@ mine(void)
            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(&sect);
        ship.shp_mission = 0;
@@ -151,7 +151,7 @@ landmine(void)
            shells = min(shells, land.lnd_mobil);
        }
        getsect(sect.sct_x, sect.sct_y, &sect);
-       sect.sct_mines += total_mines_laid;
+       sect.sct_mines = min(sect.sct_mines + total_mines_laid, MINES_MAX);
        putsect(&sect);
        if (total_mines_laid == mines_wanted) {
            pr("%s laid a total of %d mines in %s",
index e11b5c81492eefc832ec5ba37deec51ba91a9b4a..e1136fa04d0788329130ff54bf0c9f2d7495330e 100644 (file)
@@ -222,6 +222,8 @@ setsector(void)
                current += amt;
                if (current < 0)
                    current = 0;
+               if (current > MINES_MAX)
+                   current = MINES_MAX;
                if (sect.sct_own != 0)
                    resnoise(&sect, 1, "Mines", sect.sct_mines, current);
                sect.sct_mines = current;
index 277bf4935c521617d20fc11dd76e72d30c7473e3..38b6f56db1d28381996d6259c2602817703ee64e 100644 (file)
@@ -230,7 +230,7 @@ pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty,
        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