(sctstr): Member sct_che encoded number of che and their target.

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.
This commit is contained in:
Markus Armbruster 2004-03-04 13:49:25 +00:00
parent eccc5cb7d7
commit 5bad9875a5
11 changed files with 56 additions and 59 deletions

View 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_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 */
@ -183,6 +184,9 @@ 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
/* Each cost is per point of efficency */
struct sctintrins {
char *in_name;

View file

@ -66,13 +66,6 @@
#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)

View file

@ -187,6 +187,7 @@ add(void)
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");

View file

@ -77,8 +77,8 @@ anti(void)
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;
@ -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_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);
@ -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;
set_che_value(sect.sct_che, n_cheleft);
} else
sect.sct_che = n_cheleft;
} else {
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;

View file

@ -273,10 +273,8 @@ grab_sect(register struct sctstr *sp, natid 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;
}

View 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);
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_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);
@ -586,11 +587,19 @@ doland(s_char op, int arg, s_char *p, struct sctstr *sect)
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;
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);

View 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,
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");
}

View 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_che_target = 0;
}

View 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_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},

View file

@ -51,7 +51,6 @@ takeover(register struct sctstr *sp, natid newown)
struct plnstr *pp;
struct lndstr *lp;
int civ;
int che;
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];
oldche = get_che_value(sp->sct_che);
oldche = sp->sct_che;
/*
* 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;
che = 0;
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;
set_che_value(che, che_count);
sp->sct_che = che_count;
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) {
/*

View file

@ -59,15 +59,11 @@ revolt(struct sctstr *sp)
int che_uw;
int civ;
int uw;
u_short che_combo;
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];
@ -98,9 +94,8 @@ revolt(struct sctstr *sp)
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)
@ -153,7 +148,6 @@ guerrilla(struct sctstr *sp)
int convert;
natid actor;
natid victim;
u_short che_combo;
int vec[I_MAX + 1];
int tmp;
int min_mil;
@ -166,9 +160,8 @@ guerrilla(struct sctstr *sp)
recruit = 0;
convert = 0;
move = 0;
if ((n = sp->sct_che) <= 0)
if (!sp->sct_che)
return;
che_combo = n;
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;
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);
@ -214,10 +207,11 @@ guerrilla(struct sctstr *sp)
/* Security forces killed all the che */
if (che <= 0) {
sp->sct_che = 0;
sp->sct_che_target = 0;
return;
}
target = get_che_cnum(che_combo);
target = sp->sct_che_target;
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;
sp->sct_che_target = 0;
sp->sct_item[I_CIVIL] = civ;
return;
}
@ -402,11 +397,10 @@ guerrilla(struct sctstr *sp)
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;
if (get_che_value(che_combo) + che > CHE_MAX)
if (nsp->sct_che + che > CHE_MAX)
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) {
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) {
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_target = 0;
}
if (mc > 0 || cc > 0) {
/* don't tell who won just to be mean */
wu(0, target,