]> git.pond.sub.org Git - empserver/commitdiff
(sctstr): Member sct_che encoded number of che and their target.
authorMarkus Armbruster <armbru@pond.sub.org>
Thu, 4 Mar 2004 13:49:25 +0000 (13:49 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Thu, 4 Mar 2004 13:49:25 +0000 (13:49 +0000)
Simplify.  Split into member sct_che (number) and sct_che_target.
Users changed.
(get_che_cnum, set_che_cnum, get_che_value, get_che_value): Che
encoding/decoding functions; remove.
(CHE_MAX): Move from var.h to sect.h.
(prsect, doland): Print / edit the new field.

include/sect.h
include/var.h
src/lib/commands/add.c
src/lib/commands/anti.c
src/lib/commands/cede.c
src/lib/commands/edit.c
src/lib/commands/hidd.c
src/lib/common/bridgefall.c
src/lib/global/nsc.c
src/lib/subs/takeover.c
src/lib/update/revolt.c

index 5f186910c6849fa555c41ec251fbb8c99ef95be3..dd2224e0e14478ba9a623c110fa1fec1718a5c8f 100644 (file)
@@ -77,7 +77,8 @@ struct sctstr {
     u_short sct_mines;         /* number of mines */
     u_short sct_pstage;                /* plague stage */
     u_short sct_ptime;         /* how many etus remain in this stage */
     u_short sct_mines;         /* number of mines */
     u_short sct_pstage;                /* plague stage */
     u_short sct_ptime;         /* how many etus remain in this stage */
-    u_short sct_che;           /* che combo */
+    u_char sct_che;            /* number of guerrillas */
+    natid sct_che_target;      /* nation targeted by che */
     u_short sct_fallout;
     time_t sct_access;         /* Last time mob was updated (MOB_ACCESS) */
     u_char sct_road;           /* Road value of a sector */
     u_short sct_fallout;
     time_t sct_access;         /* Last time mob was updated (MOB_ACCESS) */
     u_char sct_road;           /* Road value of a sector */
@@ -183,6 +184,9 @@ extern struct dchrstr bigcity_dchr;
 /* Sector flags */
 #define MOVE_IN_PROGRESS       bit(0)  /* move in progress */
 
 /* 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
+
 /* Each cost is per point of efficency */
 struct sctintrins {
     char *in_name;
 /* Each cost is per point of efficency */
 struct sctintrins {
     char *in_name;
index 1509e7844a816c2f6f1b9295b79fc70ef2f3a19c..9fe13de58a0dc46a9b4015acff738b6e5b1f8bd2 100644 (file)
 #define I_RAD          14
 #define I_MAX          14
 
 #define I_RAD          14
 #define I_MAX          14
 
-/* should this be here?? */
-#define CHE_MAX                 255
-#define        get_che_cnum(x)         ((x) >> 8)
-#define set_che_cnum(x, cn)    ((x) = ((x) & 0xff) | ((cn) << 8))
-#define get_che_value(x)       ((x) & 0xff)
-#define set_che_value(x, n)    ((x) = ((x) & 0xff00) | (n))
-
 #define        V_CIVIL         V_ITEM(I_CIVIL)
 #define        V_MILIT         V_ITEM(I_MILIT)
 #define        V_SHELL         V_ITEM(I_SHELL)
 #define        V_CIVIL         V_ITEM(I_CIVIL)
 #define        V_MILIT         V_ITEM(I_MILIT)
 #define        V_SHELL         V_ITEM(I_SHELL)
index 3a300b9abc093f44f248cb8ac98539ef1f10a8aa..ea6d0926ec34cbfe4e9f7525b2fc00a8bef6cdf8 100644 (file)
@@ -187,6 +187,7 @@ add(void)
                sect.sct_pstage = PLG_HEALTHY;
                sect.sct_ptime = 0;
                sect.sct_che = 0;
                sect.sct_pstage = PLG_HEALTHY;
                sect.sct_ptime = 0;
                sect.sct_che = 0;
+               sect.sct_che_target = 0;
                sect.sct_fallout = 0;
                putsect(&sect);
                pr("wiped\n");
                sect.sct_fallout = 0;
                putsect(&sect);
                pr("wiped\n");
index dc8d0d6931038d140f707973a190d3d252dc7d62..3cef7fac8eaee2cff3d3323525a36c9ac3812ac3 100644 (file)
@@ -77,8 +77,8 @@ anti(void)
            pr("  ----    --------------------------\n");
        }
        mil = sect.sct_item[I_MILIT];
            pr("  ----    --------------------------\n");
        }
        mil = sect.sct_item[I_MILIT];
-       che = get_che_value(sect.sct_che);
-       target = get_che_cnum(sect.sct_che);
+       che = sect.sct_che;
+       target = sect.sct_che_target;
        avail_mil = sect.sct_mobil / 2;
        if (mil <= avail_mil)
            avail_mil = mil;
        avail_mil = sect.sct_mobil / 2;
        if (mil <= avail_mil)
            avail_mil = mil;
@@ -114,8 +114,8 @@ anti(void)
                sect.sct_mobil = sect.sct_mobil - chekilled - milkilled;
                sect.sct_item[I_MILIT] = mil - milkilled;
                if (ache == 0)
                sect.sct_mobil = sect.sct_mobil - chekilled - milkilled;
                sect.sct_item[I_MILIT] = mil - milkilled;
                if (ache == 0)
-                   sect.sct_che = 0;
-               set_che_value(sect.sct_che, ache);
+                   sect.sct_che_target = 0;
+               sect.sct_che = ache;
                putsect(&sect);
                pr("          Body count:  Military %d - Guerillas %d.\n",
                   milkilled, chekilled);
                putsect(&sect);
                pr("          Body count:  Military %d - Guerillas %d.\n",
                   milkilled, chekilled);
@@ -138,9 +138,11 @@ anti(void)
                    /* Ok, now leave anywhere from 16% to 25% of the che */
                    n_cheleft = (ache / (n_cheleft + 3));
                    ache -= n_cheleft;
                    /* Ok, now leave anywhere from 16% to 25% of the che */
                    n_cheleft = (ache / (n_cheleft + 3));
                    ache -= n_cheleft;
-                   set_che_value(sect.sct_che, n_cheleft);
-               } else
+                   sect.sct_che = n_cheleft;
+               } else {
                    sect.sct_che = 0;
                    sect.sct_che = 0;
+                   sect.sct_che_target = 0;
+               }
                sect.sct_item[I_MILIT] = ache;
                if (sect.sct_own == sect.sct_oldown)
                    sect.sct_oldown = 0;
                sect.sct_item[I_MILIT] = ache;
                if (sect.sct_own == sect.sct_oldown)
                    sect.sct_oldown = 0;
index 50a7d74f92e50d7c9955667f1b57dc5517263950..8b1162dc773177cf71944bd9772099749a69db14 100644 (file)
@@ -273,10 +273,8 @@ grab_sect(register struct sctstr *sp, natid to)
     sp->sct_avail = 0;
 
     if (sp->sct_oldown == to) {
     sp->sct_avail = 0;
 
     if (sp->sct_oldown == to) {
-       oldche = get_che_value(sp->sct_che);
-       set_che_value(oldche, 0);
-       set_che_cnum(oldche, 0);
-       sp->sct_che = oldche;
+       sp->sct_che = 0;        /* FIXME where do these guys go? */
+       sp->sct_che_target = 0;
        sp->sct_loyal = 0;
     }
 
        sp->sct_loyal = 0;
     }
 
index dd902dad68c9f53cc900ac145fcd1caa5e4c0f74..f22d9b8080a34cc5e7dfa8f0b07dc619c9dceed8 100644 (file)
@@ -284,13 +284,14 @@ prsect(struct sctstr *sect)
        xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum));
     pr("Designation <s>: %c\t New designation <S>: %c\n",
        dchr[sect->sct_type].d_mnem, dchr[sect->sct_newtype].d_mnem);
        xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum));
     pr("Designation <s>: %c\t New designation <S>: %c\n",
        dchr[sect->sct_type].d_mnem, dchr[sect->sct_newtype].d_mnem);
-    pr("own  oo eff mob min gld frt oil urn wrk lty  che plg ptime fall avail\n");
-    pr("  o   O   e   m   i   g   f   c   u   w   l    x   p     t    F     a\n");
-    pr("%3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %4d %3d %5d %4d %5d\n",
+    pr("own  oo eff mob min gld frt oil urn wrk lty che ctg plg ptime fall avail\n");
+    pr("  o   O   e   m   i   g   f   c   u   w   l   x   X   p     t    F     a\n");
+    pr("%3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %5d %4d %5d\n",
        sect->sct_own, sect->sct_oldown, sect->sct_effic, sect->sct_mobil,
        sect->sct_min, sect->sct_gmin, sect->sct_fertil, sect->sct_oil,
        sect->sct_uran, sect->sct_work, sect->sct_loyal,
        sect->sct_own, sect->sct_oldown, sect->sct_effic, sect->sct_mobil,
        sect->sct_min, sect->sct_gmin, sect->sct_fertil, sect->sct_oil,
        sect->sct_uran, sect->sct_work, sect->sct_loyal,
-       sect->sct_che, sect->sct_pstage, sect->sct_ptime,
+       sect->sct_che, sect->sct_che_target,
+       sect->sct_pstage, sect->sct_ptime,
        sect->sct_fallout, sect->sct_avail);
 
     pr("Mines <M>: %d\t", sect->sct_mines);
        sect->sct_fallout, sect->sct_avail);
 
     pr("Mines <M>: %d\t", sect->sct_mines);
@@ -586,11 +587,19 @@ doland(s_char op, int arg, s_char *p, struct sctstr *sect)
        break;
     case 'x':
        old = sect->sct_che;
        break;
     case 'x':
        old = sect->sct_che;
-       new = errcheck(arg, 0, 65536);
-       pr("Guerillas in %s changed from %d to %d%\n",
+       new = errcheck(arg, 0, CHE_MAX);
+       pr("Guerillas in %s changed from %d to %d\n",
           xyas(sect->sct_x, sect->sct_y, player->cnum), old, new);
        sect->sct_che = new;
        break;
           xyas(sect->sct_x, sect->sct_y, player->cnum), old, new);
        sect->sct_che = new;
        break;
+    case 'X':
+       old = sect->sct_che_target;
+       new = errcheck(arg, 0, MAXNOC - 1);
+       pr("Old owner of %s changed from %s (#%d) to %s (#%d).\n",
+          xyas(sect->sct_x, sect->sct_y, player->cnum),
+          cname(old), old, cname(new), new);
+       sect->sct_che_target = new;
+       break;
     case 'p':
        old = sect->sct_pstage;
        new = errcheck(arg, 0, PLG_EXPOSED);
     case 'p':
        old = sect->sct_pstage;
        new = errcheck(arg, 0, PLG_EXPOSED);
index 732f2d14424c23697b74c0b04420b16819f6ab74..8b23ea25a1506f7e254c1c58f73b430f850c8d8f 100644 (file)
@@ -71,8 +71,7 @@ hidd(void)
        pr(" %c  %3d%% %3d   %3d  %3d  %3d    %3d   %3d  %3d",
           dchr[sect.sct_type].d_mnem, sect.sct_effic,
           sect.sct_oldown, sect.sct_loyal,
        pr(" %c  %3d%% %3d   %3d  %3d  %3d    %3d   %3d  %3d",
           dchr[sect.sct_type].d_mnem, sect.sct_effic,
           sect.sct_oldown, sect.sct_loyal,
-          get_che_cnum(sect.sct_che),
-          get_che_value(sect.sct_che),
+          sect.sct_che_target, sect.sct_che,
           sect.sct_pstage, sect.sct_ptime, sect.sct_mines);
        pr("\n");
     }
           sect.sct_pstage, sect.sct_ptime, sect.sct_mines);
        pr("\n");
     }
index 7589cf39874f4bbbc8897140a2f21c2a84f30398..13fc7ed28d4d82ea4177f96dd2640f0cd97a7137 100644 (file)
@@ -166,4 +166,5 @@ knockdown(struct sctstr *sp, struct emp_qelem *list)
     sp->sct_pstage = PLG_HEALTHY;
     sp->sct_ptime = 0;
     sp->sct_che = 0;
     sp->sct_pstage = PLG_HEALTHY;
     sp->sct_ptime = 0;
     sp->sct_che = 0;
+    sp->sct_che_target = 0;
 }
 }
index 455c93f676ce2afa4b45a6ff0dfa601ffc173631..5b4e4a7156d3a7fc103cbeb3917c1e5b8544e942 100644 (file)
@@ -130,6 +130,7 @@ struct castr sect_ca[] = {
     {NSC_DEITY | NSC_USHORT | NSC_OFF | fldoff(sctstr, sct_pstage), "pstage", 0},
     {NSC_DEITY | NSC_USHORT | NSC_OFF | fldoff(sctstr, sct_ptime), "ptime", 0},
     {NSC_DEITY | NSC_USHORT | NSC_OFF | fldoff(sctstr, sct_che), "che", 0},
     {NSC_DEITY | NSC_USHORT | NSC_OFF | fldoff(sctstr, sct_pstage), "pstage", 0},
     {NSC_DEITY | NSC_USHORT | NSC_OFF | fldoff(sctstr, sct_ptime), "ptime", 0},
     {NSC_DEITY | NSC_USHORT | NSC_OFF | fldoff(sctstr, sct_che), "che", 0},
+    {NSC_DEITY | NSC_USHORT | NSC_OFF | fldoff(sctstr, sct_che_target), "che_target", 0},
     {NSC_USHORT | NSC_OFF | fldoff(sctstr, sct_fallout), "fallout", 0},
     {NSC_UCHAR | NSC_OFF | fldoff(sctstr, sct_road), "road", 0},
     {NSC_UCHAR | NSC_OFF | fldoff(sctstr, sct_rail), "rail", 0},
     {NSC_USHORT | NSC_OFF | fldoff(sctstr, sct_fallout), "fallout", 0},
     {NSC_UCHAR | NSC_OFF | fldoff(sctstr, sct_road), "road", 0},
     {NSC_UCHAR | NSC_OFF | fldoff(sctstr, sct_rail), "rail", 0},
index 84411a3f93125eb38a648baf3c1b9178e5016203..7e2d7d28a29c83176622f7e2109a6480e82055d3 100644 (file)
@@ -51,7 +51,6 @@ takeover(register struct sctstr *sp, natid newown)
     struct plnstr *pp;
     struct lndstr *lp;
     int civ;
     struct plnstr *pp;
     struct lndstr *lp;
     int civ;
-    int che;
     int che_count;
     int oldche;
     int n;
     int che_count;
     int oldche;
     int n;
@@ -116,7 +115,7 @@ takeover(register struct sctstr *sp, natid newown)
 
     sp->sct_avail = 0;
     civ = sp->sct_item[I_CIVIL];
 
     sp->sct_avail = 0;
     civ = sp->sct_item[I_CIVIL];
-    oldche = get_che_value(sp->sct_che);
+    oldche = sp->sct_che;
     /*
      * create guerrillas from civilians
      * how spunky are these guys?
     /*
      * create guerrillas from civilians
      * how spunky are these guys?
@@ -124,7 +123,6 @@ takeover(register struct sctstr *sp, natid newown)
      */
     n = (50 - sp->sct_loyal) + ((random() % 100) - 25);
     che_count = 0;
      */
     n = (50 - sp->sct_loyal) + ((random() % 100) - 25);
     che_count = 0;
-    che = 0;
     if (n > 0 && sp->sct_own == sp->sct_oldown) {
        che_count = (civ * n / 3000) + 5;
        if (che_count * 2 > civ)
     if (n > 0 && sp->sct_own == sp->sct_oldown) {
        che_count = (civ * n / 3000) + 5;
        if (che_count * 2 > civ)
@@ -139,10 +137,9 @@ takeover(register struct sctstr *sp, natid newown)
            che_count = oldche;
     } else
        che_count = oldche;
            che_count = oldche;
     } else
        che_count = oldche;
-    set_che_value(che, che_count);
+    sp->sct_che = che_count;
     if (newown != sp->sct_oldown)
     if (newown != sp->sct_oldown)
-       set_che_cnum(che, newown);
-    sp->sct_che = che;
+       sp->sct_che_target = newown;
     sp->sct_item[I_CIVIL] = civ;
     if (sp->sct_oldown == newown || civ == 0) {
        /*
     sp->sct_item[I_CIVIL] = civ;
     if (sp->sct_oldown == newown || civ == 0) {
        /*
index 75e79bac0502fb86d4db88730485b1c1ded4cc03..5f550024e2b88c41ca6fa5bbc8b3a1adc558e843 100644 (file)
@@ -59,15 +59,11 @@ revolt(struct sctstr *sp)
     int che_uw;
     int civ;
     int uw;
     int che_uw;
     int civ;
     int uw;
-    u_short che_combo;
     int che;
     int n;
     int che;
     int n;
-    int target;
 
 
-    che_combo = sp->sct_che;
-    che = get_che_value(che_combo);
-    target = get_che_cnum(che_combo);
-    if (che_combo != 0 && (target != sp->sct_own || che >= CHE_MAX))
+    che = sp->sct_che;
+    if (che != 0 && (sp->sct_che_target != sp->sct_own || che >= CHE_MAX))
        return;
     civ = sp->sct_item[I_CIVIL];
     uw = sp->sct_item[I_UW];
        return;
     civ = sp->sct_item[I_CIVIL];
     uw = sp->sct_item[I_UW];
@@ -98,9 +94,8 @@ revolt(struct sctstr *sp)
     if (che_civ + che_uw > 0) {
        civ -= che_civ;
        uw -= che_uw;
     if (che_civ + che_uw > 0) {
        civ -= che_civ;
        uw -= che_uw;
-       set_che_cnum(che_combo, sp->sct_own);
-       set_che_value(che_combo, che);
-       sp->sct_che = che_combo;
+       sp->sct_che_target = sp->sct_own;
+       sp->sct_che = che;
        if (che_civ > 0)
            sp->sct_item[I_CIVIL] = civ;
        if (che_uw > 0)
        if (che_civ > 0)
            sp->sct_item[I_CIVIL] = civ;
        if (che_uw > 0)
@@ -153,7 +148,6 @@ guerrilla(struct sctstr *sp)
     int convert;
     natid actor;
     natid victim;
     int convert;
     natid actor;
     natid victim;
-    u_short che_combo;
     int vec[I_MAX + 1];
     int tmp;
     int min_mil;
     int vec[I_MAX + 1];
     int tmp;
     int min_mil;
@@ -166,9 +160,8 @@ guerrilla(struct sctstr *sp)
     recruit = 0;
     convert = 0;
     move = 0;
     recruit = 0;
     convert = 0;
     move = 0;
-    if ((n = sp->sct_che) <= 0)
+    if (!sp->sct_che)
        return;
        return;
-    che_combo = n;
     if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0)
        return;
     civ = vec[I_CIVIL];
     if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0)
        return;
     civ = vec[I_CIVIL];
@@ -176,7 +169,7 @@ guerrilla(struct sctstr *sp)
     uw = vec[I_UW];
     victim = sp->sct_own;
     actor = sp->sct_oldown;
     uw = vec[I_UW];
     victim = sp->sct_own;
     actor = sp->sct_oldown;
-    che = get_che_value(che_combo);
+    che = sp->sct_che;
 
     mil = vec[I_MILIT];
     snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
 
     mil = vec[I_MILIT];
     snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
@@ -214,10 +207,11 @@ guerrilla(struct sctstr *sp)
     /* Security forces killed all the che */
     if (che <= 0) {
        sp->sct_che = 0;
     /* Security forces killed all the che */
     if (che <= 0) {
        sp->sct_che = 0;
+       sp->sct_che_target = 0;
        return;
     }
 
        return;
     }
 
-    target = get_che_cnum(che_combo);
+    target = sp->sct_che_target;
     if (target == 0) {
        /* the deity can't be a target! */
        return;
     if (target == 0) {
        /* the deity can't be a target! */
        return;
@@ -228,6 +222,7 @@ guerrilla(struct sctstr *sp)
        logerror("%d Che targeted at country %d retiring", che, target);
        civ += che;
        sp->sct_che = 0;
        logerror("%d Che targeted at country %d retiring", che, target);
        civ += che;
        sp->sct_che = 0;
+       sp->sct_che_target = 0;
        sp->sct_item[I_CIVIL] = civ;
        return;
     }
        sp->sct_item[I_CIVIL] = civ;
        return;
     }
@@ -402,11 +397,10 @@ guerrilla(struct sctstr *sp)
                continue;
            if (nsp->sct_own != target)
                continue;
                continue;
            if (nsp->sct_own != target)
                continue;
-           if ((val = nsp->sct_che) > 0) {
-               che_combo = val;
-               if (get_che_cnum(che_combo) != target)
+           if (nsp->sct_che > 0) {
+               if (nsp->sct_che_target != target)
                    continue;
                    continue;
-               if (get_che_value(che_combo) + che > CHE_MAX)
+               if (nsp->sct_che + che > CHE_MAX)
                    continue;
            }
            val = nsp->sct_item[I_MILIT];
                    continue;
            }
            val = nsp->sct_item[I_MILIT];
@@ -422,20 +416,18 @@ guerrilla(struct sctstr *sp)
        }
        /* if we found a nice sector, go there */
        if (nicest_sp != 0) {
        }
        /* if we found a nice sector, go there */
        if (nicest_sp != 0) {
-           che_combo = nicest_sp->sct_che;
-           che += get_che_value(che_combo);
-           set_che_value(che_combo, che);
-           set_che_cnum(che_combo, target);
-           nicest_sp->sct_che = che_combo;
+           nicest_sp->sct_che += che;
+           nicest_sp->sct_che_target = target;
            che = 0;
        }
     }
     if (che > 0) {
            che = 0;
        }
     }
     if (che > 0) {
-       set_che_value(che_combo, che);
-       set_che_cnum(che_combo, target);
-       sp->sct_che = che_combo;
-    } else
+       sp->sct_che = che;
+       sp->sct_che_target = target;
+    } else {
        sp->sct_che = 0;
        sp->sct_che = 0;
+       sp->sct_che_target = 0;
+    }
     if (mc > 0 || cc > 0) {
        /* don't tell who won just to be mean */
        wu(0, target,
     if (mc > 0 || cc > 0) {
        /* don't tell who won just to be mean */
        wu(0, target,