]> git.pond.sub.org Git - empserver/commitdiff
Support definition of additional sector types in sector.config,
authorMarkus Armbruster <armbru@pond.sub.org>
Thu, 22 Jun 2006 20:21:48 +0000 (20:21 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Thu, 22 Jun 2006 20:21:48 +0000 (20:21 +0000)
missing bits:
(budg, calc_all, update_main): Use SCT_TYPE_MAX instead of SCT_MAXDEF
to size tables.
(map_char): Update sanity check; use CANT_HAPPEN().
(show_sect_build, show_sect_stats, show_sect_capab): Use the sentinel
instead of SCT_MAXDEF.

src/lib/commands/budg.c
src/lib/common/maps.c
src/lib/subs/show.c
src/lib/update/main.c

index 41185ebaaf2a67f7406b766e73c42d5bc5aa779a..f13652b56f90a750bd33f0247db4cd9cc5d3906a 100644 (file)
@@ -64,7 +64,7 @@ int
 budg(void)
 {
     int i;
 budg(void)
 {
     int i;
-    long p_sect[SCT_MAXDEF+2][2];
+    long p_sect[SCT_TYPE_MAX+2][2];
     int taxes, Ncivs, Nuws, bars, Nbars, mil;
     int ships, sbuild, nsbuild, smaint;
     int units, lbuild, nlbuild, lmaint;
     int taxes, Ncivs, Nuws, bars, Nbars, mil;
     int ships, sbuild, nsbuild, smaint;
     int units, lbuild, nlbuild, lmaint;
@@ -90,7 +90,7 @@ budg(void)
     income = taxes + bars;
     expenses = 0;
     pr("Sector Type\t\t\tProduction\t\t\t    Cost\n");
     income = taxes + bars;
     expenses = 0;
     pr("Sector Type\t\t\tProduction\t\t\t    Cost\n");
-    for (i = 0; i <= SCT_MAXDEF; i++) {
+    for (i = 0; i <= SCT_TYPE_MAX; i++) {
        if (!p_sect[i][1] || i == SCT_CAPIT)
            continue;
        pr("%-17s\t\t", dchr[i].d_name);
        if (!p_sect[i][1] || i == SCT_CAPIT)
            continue;
        pr("%-17s\t\t", dchr[i].d_name);
@@ -198,7 +198,7 @@ calc_all(long p_sect[][2],
     int etu = etu_per_update;
 
     mil_dbl_pay = 0;
     int etu = etu_per_update;
 
     mil_dbl_pay = 0;
-    memset(p_sect, 0, sizeof(**p_sect) * (SCT_MAXDEF+2) * 2);
+    memset(p_sect, 0, sizeof(**p_sect) * (SCT_TYPE_MAX+2) * 2);
     *taxes = *Ncivs = *Nuws = *bars = *Nbars = *mil = 0;
     *ships = *sbuild = *nsbuild = *smaint = 0;
     *units = *lbuild = *nlbuild = *lmaint = 0;
     *taxes = *Ncivs = *Nuws = *bars = *Nbars = *mil = 0;
     *ships = *sbuild = *nsbuild = *smaint = 0;
     *units = *lbuild = *nlbuild = *lmaint = 0;
index 796c642f47047142119cbe1ff8d72f4e56f96ade..23a23ac74c66cf9f4399a55e54e066ec4ca19710 100644 (file)
@@ -290,10 +290,8 @@ bmnxtsct(struct nstr_sect *np)
 static char
 map_char(unsigned char type, natid own, int owner_or_god)
 {
 static char
 map_char(unsigned char type, natid own, int owner_or_god)
 {
-    if (type > SCT_MAXDEF) {
-       logerror("bad sector type %d\n", type);
+    if (CANT_HAPPEN(type > SCT_TYPE_MAX || !dchr[type].d_mnem))
        return '?';
        return '?';
-    }
     if (owner_or_god
        || type == SCT_WATER || type == SCT_MOUNT || type == SCT_WASTE
        || (!own && (type == SCT_RURAL || type == SCT_PLAINS)))
     if (owner_or_god
        || type == SCT_WATER || type == SCT_MOUNT || type == SCT_WASTE
        || (!own && (type == SCT_RURAL || type == SCT_PLAINS)))
index a9e5b6b2fb8d6ea5996c66d5540efef22da80313..f79536d04976d25846a25e7cf0ad534e05ae2f11 100644 (file)
@@ -32,6 +32,7 @@
  *     Jeff Bailey, 1990
  *     Steve McClure, 1996
  *     Ron Koenderink, 2005
  *     Jeff Bailey, 1990
  *     Steve McClure, 1996
  *     Ron Koenderink, 2005
+ *     Markus Armbruster, 2006
  */
 
 #include <config.h>
  */
 
 #include <config.h>
@@ -499,7 +500,7 @@ show_sect_build(int foo)
     int x, first;
 
     first = 1;
     int x, first;
 
     first = 1;
-    for (x = 0; x <= SCT_MAXDEF; x++) {
+    for (x = 0; dchr[x].d_name; x++) {
        if (dchr[x].d_mnem == 0)
            continue;
        if (dchr[x].d_cost < 0)
        if (dchr[x].d_mnem == 0)
            continue;
        if (dchr[x].d_cost < 0)
@@ -537,7 +538,7 @@ show_sect_stats(int foo)
     struct natstr *natp;
 
     natp = getnatp(player->cnum);
     struct natstr *natp;
 
     natp = getnatp(player->cnum);
-    for (x = 0; x <= SCT_MAXDEF; x++) {
+    for (x = 0; dchr[x].d_name; x++) {
        if (dchr[x].d_mnem == 0)
            continue;
        if (first) {
        if (dchr[x].d_mnem == 0)
            continue;
        if (first) {
@@ -567,7 +568,7 @@ show_sect_capab(int foo)
     int x, first = 1, i, j;
     char *tmpstr;
 
     int x, first = 1, i, j;
     char *tmpstr;
 
-    for (x = 0; x <= SCT_MAXDEF; x++) {
+    for (x = 0; dchr[x].d_name; x++) {
        if (dchr[x].d_mnem == 0 || dchr[x].d_prd < 0)
            continue;
        if (first) {
        if (dchr[x].d_mnem == 0 || dchr[x].d_prd < 0)
            continue;
        if (first) {
index 3afc83490dfbdc4abc33191fc9099baafd630320..9e24675a89c790cabf8b02b5d1a3669d3a469dc7 100644 (file)
@@ -112,7 +112,7 @@ update_main(void *unused)
     logerror("done preparing sectors.");
     logerror("producing for countries...");
     for (x = 0; x < MAXNOC; x++) {
     logerror("done preparing sectors.");
     logerror("producing for countries...");
     for (x = 0; x < MAXNOC; x++) {
-       long p_sect[SCT_MAXDEF+2][2];
+       long p_sect[SCT_TYPE_MAX+2][2];
 
        memset(p_sect, 0, sizeof(p_sect));
        mil_dbl_pay = 0;
 
        memset(p_sect, 0, sizeof(p_sect));
        mil_dbl_pay = 0;