]> git.pond.sub.org Git - empserver/commitdiff
(prod, produce, upd_ship): struct pchrstr p_nrndx refers to u_char,
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 19 Feb 2005 17:28:30 +0000 (17:28 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 19 Feb 2005 17:28:30 +0000 (17:28 +0000)
not s_char.  Fix types.

(upd_ship): Catch resource underflow (should not happen).

src/lib/commands/prod.c
src/lib/update/produce.c
src/lib/update/ship.c

index 16494b39ce208aa6f2c6b31fe30dd0018a5895f5..4f894cf35fccaefc928c424e759c55f88d4f2879 100644 (file)
@@ -87,7 +87,7 @@ prod(void)
     int wforce;
     i_type it;
     i_type vtype;
-    s_char *resource;
+    u_char *resource;
     s_char maxc[MAXPRCON][10];
     s_char use[MAXPRCON][10];
     int lcms, hcms;
@@ -204,7 +204,7 @@ prod(void)
            goto is_enlist;
        if (pp->p_nrndx != 0) {
            unit_work++;
-           resource = ((s_char *)&sect) + pp->p_nrndx;
+           resource = (u_char *)&sect + pp->p_nrndx;
            p_e = (*resource * p_e) / 100.0;
        }
        /*
index ee35f74a0fa183b1be433f8bf859f1a578e34266..6a69f2e2ff2eb42146e3972c4dd6dbf34e1e176d 100644 (file)
@@ -57,7 +57,7 @@ produce(struct natstr *np, struct sctstr *sp, short *vec, int work,
     struct pchrstr *product;
     double p_e;
     double prodeff;
-    s_char *resource;
+    u_char *resource;
     double output;
     int actual;
     int unit_work;
@@ -82,7 +82,7 @@ produce(struct natstr *np, struct sctstr *sp, short *vec, int work,
     p_e = neweff / 100.0;
     if (product->p_nrndx != 0) {
        unit_work++;
-       resource = ((s_char *)sp) + product->p_nrndx;
+       resource = (u_char *)sp + product->p_nrndx;
        p_e = (*resource * p_e) / 100.0;
     }
     /*
index 68adce714277c5637251afc35bfc497c99a25970..861304a10a4112a8becb2318bd51a462c31ea2e8 100644 (file)
@@ -121,6 +121,7 @@ upd_ship(struct shpstr *sp, int etus,
     int max_food;
     struct pchrstr *product;
     s_char *resource;
+    int dep;
     int n;
     int mult;
     int needed;
@@ -180,9 +181,11 @@ upd_ship(struct shpstr *sp, int etus,
                    oil_gained = max_oil - sp->shp_item[I_OIL];
                sp->shp_item[I_OIL] += oil_gained;
                if (product->p_nrdep != 0 && oil_gained > 0) {
-                   resource = ((s_char *)sectp) + product->p_nrndx;
-                   *resource -= roundavg(oil_gained *
-                                         product->p_nrdep / 100.0);
+                   resource = (u_char *)sectp + product->p_nrndx;
+                   dep = roundavg(oil_gained * product->p_nrdep / 100.0);
+                   if (CANT_HAPPEN(dep > *resource))
+                       dep = *resource;
+                   *resource -= dep;
                }
            }
            if ((mp->m_flags & M_FOOD) && sectp->sct_type == SCT_WATER) {