Simplify control flow in spy()
Rearrange so that we make contact (each way) and print the spy report in just one place. No functional change.
This commit is contained in:
parent
ee6927122c
commit
89e33f6218
1 changed files with 34 additions and 46 deletions
|
@ -57,7 +57,6 @@ static void spyline(struct sctstr *sp);
|
||||||
int
|
int
|
||||||
spy(void)
|
spy(void)
|
||||||
{
|
{
|
||||||
int caught;
|
|
||||||
natid own;
|
natid own;
|
||||||
int relat;
|
int relat;
|
||||||
coord x, y;
|
coord x, y;
|
||||||
|
@ -145,56 +144,45 @@ spy(void)
|
||||||
insert(table, &t_len, nx, ny);
|
insert(table, &t_len, nx, ny);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* catch spy N/200 chance, N = # military */
|
|
||||||
caught = chance(dsect.sct_item[I_MILIT] / 200.0);
|
|
||||||
own = dsect.sct_own;
|
own = dsect.sct_own;
|
||||||
/* determine spyee relations with spyer */
|
|
||||||
relat = getrel(getnatp(own), player->cnum);
|
relat = getrel(getnatp(own), player->cnum);
|
||||||
if (relat == NEUTRAL && caught) {
|
if (relat <= NEUTRAL
|
||||||
/* neutral spy-ee */
|
&& chance(dsect.sct_item[I_MILIT] / 200.0)) {
|
||||||
pr("Spy deported from %s\n", xyas(nx, ny, player->cnum));
|
/* spy caught */
|
||||||
if (own != 0)
|
if (relat == NEUTRAL) {
|
||||||
wu(0, own, "%s (#%d) spy deported from %s\n",
|
/* deport spy */
|
||||||
cname(player->cnum), player->cnum,
|
pr("Spy deported from %s\n",
|
||||||
xyas(nx, ny, own));
|
xyas(nx, ny, player->cnum));
|
||||||
|
if (own != 0)
|
||||||
|
wu(0, own, "%s (#%d) spy deported from %s\n",
|
||||||
|
cname(player->cnum), player->cnum,
|
||||||
|
xyas(nx, ny, own));
|
||||||
|
} else {
|
||||||
|
/* execute spy */
|
||||||
|
pr("BANG!! A spy was shot in %s\n",
|
||||||
|
xyas(nx, ny, player->cnum));
|
||||||
|
military--;
|
||||||
|
if (own != 0)
|
||||||
|
wu(0, own, "%s (#%d) spy caught in %s\n",
|
||||||
|
cname(player->cnum), player->cnum,
|
||||||
|
xyas(nx, ny, own));
|
||||||
|
}
|
||||||
if (opt_HIDDEN)
|
if (opt_HIDDEN)
|
||||||
setcont(own, player->cnum, FOUND_SPY);
|
setcont(own, player->cnum, FOUND_SPY);
|
||||||
} else if (relat < NEUTRAL && caught) {
|
if (!nrecon) /* unless you have a recon unit */
|
||||||
/* hostile spy-ee */
|
continue; /* no report from caught spy */
|
||||||
pr("BANG!! A spy was shot in %s\n",
|
|
||||||
xyas(nx, ny, player->cnum));
|
|
||||||
military--;
|
|
||||||
if (own != 0)
|
|
||||||
wu(0, own, "%s (#%d) spy caught in %s\n",
|
|
||||||
cname(player->cnum), player->cnum,
|
|
||||||
xyas(nx, ny, own));
|
|
||||||
nreport(player->cnum, N_SPY_SHOT, own, 1);
|
|
||||||
if (opt_HIDDEN)
|
|
||||||
setcont(own, player->cnum, FOUND_SPY);
|
|
||||||
} else {
|
|
||||||
insert(table, &t_len, nx, ny);
|
|
||||||
spyline(&dsect);
|
|
||||||
changed += map_set(player->cnum, dsect.sct_x, dsect.sct_y,
|
|
||||||
dchr[dsect.sct_type].d_mnem, 0);
|
|
||||||
prunits(dsect.sct_x, dsect.sct_y);
|
|
||||||
prplanes(dsect.sct_x, dsect.sct_y);
|
|
||||||
if (opt_HIDDEN)
|
|
||||||
setcont(player->cnum, own, FOUND_SPY);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* If you have a recon unit, it'll
|
|
||||||
* see the sector anyway...
|
|
||||||
*/
|
|
||||||
if (nrecon && caught) {
|
|
||||||
insert(table, &t_len, nx, ny);
|
|
||||||
spyline(&dsect);
|
|
||||||
changed += map_set(player->cnum, dsect.sct_x, dsect.sct_y,
|
|
||||||
dchr[dsect.sct_type].d_mnem, 0);
|
|
||||||
prunits(dsect.sct_x, dsect.sct_y);
|
|
||||||
prplanes(dsect.sct_x, dsect.sct_y);
|
|
||||||
if (opt_HIDDEN)
|
|
||||||
setcont(player->cnum, own, FOUND_SPY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* spy report */
|
||||||
|
insert(table, &t_len, nx, ny);
|
||||||
|
spyline(&dsect);
|
||||||
|
changed += map_set(player->cnum, dsect.sct_x, dsect.sct_y,
|
||||||
|
dchr[dsect.sct_type].d_mnem, 0);
|
||||||
|
prunits(dsect.sct_x, dsect.sct_y);
|
||||||
|
prplanes(dsect.sct_x, dsect.sct_y);
|
||||||
|
if (opt_HIDDEN)
|
||||||
|
setcont(player->cnum, own, FOUND_SPY);
|
||||||
}
|
}
|
||||||
/* subtract any military if necessary */
|
/* subtract any military if necessary */
|
||||||
if ((savemil != military) && (savemil > 0)) {
|
if ((savemil != military) && (savemil > 0)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue