]> git.pond.sub.org Git - empserver/commitdiff
(FALLOUT_MAX): New.
authorMarkus Armbruster <armbru@pond.sub.org>
Thu, 4 Mar 2004 16:19:50 +0000 (16:19 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Thu, 4 Mar 2004 16:19:50 +0000 (16:19 +0000)
(doland, detonate, spread_fallout): Use it.  With variables, fallout
beyond the capacity of variables (65535) was ignored, except in
doland(), where it saturated at 9999, and spread_fallout, where it
could overflow.  Now it always saturates at FALLOUT_MAX.

include/sect.h
src/lib/commands/edit.c
src/lib/subs/detonate.c
src/lib/update/sect.c

index 3db5219806e8473f35a61dce595c02281bc44fc4..6cfcef69732f8ce025d23be0e1b3a8f36d3bf74f 100644 (file)
@@ -188,6 +188,8 @@ extern struct dchrstr bigcity_dchr;
 #define CHE_MAX 255
 /* maximum number of mines, must fit into struct sctstr member sct_mines */
 #define MINES_MAX 65535
+/* maximum fallout, must fit into struct sctstr member sct_fallout */
+#define FALLOUT_MAX 9999
 
 /* Each cost is per point of efficency */
 struct sctintrins {
index 274c0075b3efc89dfccf9703bd297edb30987227..c5064ac85fb4bf91258d0d493ef9b415727d6e83 100644 (file)
@@ -616,7 +616,7 @@ doland(s_char op, int arg, s_char *p, struct sctstr *sect)
        break;
     case 'F':
        old = sect->sct_fallout;
-       new = errcheck(arg, 0, 9999);
+       new = errcheck(arg, 0, FALLOUT_MAX);
        pr("Fallout for sector %s changed from %d to %d\n",
           xyas(sect->sct_x, sect->sct_y, player->cnum), old, new);
        sect->sct_fallout = new;
index 3265410d1643adb7d0f7480fdfcafbb34426dc84..b1b3dbac735dda9edd3a7dc0bc22b9366369a9b4 100644 (file)
@@ -112,7 +112,7 @@ detonate(struct plnstr *pp, int x, int y)
                fallout += damage * 30;
            else
                fallout += damage * 3;
-           sect.sct_fallout = fallout;
+           sect.sct_fallout = min(fallout, FALLOUT_MAX);
        }
        if (damage > 100) {
            makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x, sect.sct_y);
index 4ae30aeda4643fd267e5fb47df3a4913315d52df..01e63c06182d2f7b57322815eedb8f1fb081d0ef 100644 (file)
@@ -307,7 +307,7 @@ spread_fallout(struct sctstr *sp, int etus)
 #endif
        if (inc < 0)
            inc = 0;
-       ap->sct_fallout += inc;
+       ap->sct_fallout = min(ap->sct_fallout + inc, FALLOUT_MAX);
     }
 }
 
@@ -327,8 +327,7 @@ decay_fallout(struct sctstr *sp, int etus)
           sp->sct_y, decay, sp->sct_fallout);
 #endif
 
-    sp->sct_fallout =
-       (decay < sp->sct_fallout) ? (sp->sct_fallout - decay) : 0;
+    sp->sct_fallout = decay < sp->sct_fallout ? sp->sct_fallout - decay : 0;
 }
 
 #define SHOULD_PRODUCE(sp,t)   (((sp->sct_type == t) || (t == -1)) ? 1 : 0)