(powe): Rewrite computation of targets[] for power c using

snxtitem()/nxtitem(), for simplicity and more uniform syntax.  Country
names no longer work when specifying more than one country (snxtitem()
restriction).  As usual with nxtitem(), silently ignore unsuitable
items (the old code complained and failed).  Don't skip powerless
countries for power c.  Closes #1025607.
(set_target): Unused, remove.
This commit is contained in:
Markus Armbruster 2006-05-16 18:59:19 +00:00
parent 6e148e3176
commit 6e3b478377

View file

@ -63,7 +63,6 @@ static void addtopow(short *vec, struct powstr *pow);
static void gen_power(void); static void gen_power(void);
static void out5(double value, int round_val, int round_flag); static void out5(double value, int round_val, int round_flag);
static int powcmp(const void *, const void *); static int powcmp(const void *, const void *);
static int set_target(char *, int *);
int int
powe(void) powe(void)
@ -76,9 +75,9 @@ powe(void)
struct powstr pow; struct powstr pow;
int num; int num;
int power_generated = 0; int power_generated = 0;
struct natstr nat;
int targets[MAXNOC]; int targets[MAXNOC];
int use_targets = 0; int use_targets = 0;
int got_targets = 0;
int no_numbers = 0; int no_numbers = 0;
char *p; char *p;
@ -100,15 +99,11 @@ powe(void)
} }
} }
} else if (player->argp[1] && player->argp[1][0] == 'c') { } else if (player->argp[1] && player->argp[1][0] == 'c') {
if (!player->argp[2]) snxtitem(&ni, EF_NATION, player->argp[2]);
return RET_SYN; while (nxtitem(&ni, &nat)) {
if (strchr(player->argp[2], '/')) { if (nat.nat_stat != STAT_ACTIVE)
p = strtok(player->argp[2], "/"); continue;
do { targets[nat.nat_cnum] = 1;
got_targets |= set_target(p, targets);
} while (NULL != (p = strtok(0, "/")));
} else {
got_targets |= set_target(player->argp[2], targets);
} }
use_targets = 1; use_targets = 1;
} else if (player->argp[1] && (num = atoi(player->argp[1])) < 0) { } else if (player->argp[1] && (num = atoi(player->argp[1])) < 0) {
@ -121,9 +116,6 @@ powe(void)
return RET_SYN; return RET_SYN;
} }
if (use_targets && !got_targets)
return RET_FAIL;
if (!power_generated) { if (!power_generated) {
snxtitem_all(&ni, EF_POWER); snxtitem_all(&ni, EF_POWER);
if (!nxtitem(&ni, &pow)) { if (!nxtitem(&ni, &pow)) {
@ -137,7 +129,7 @@ powe(void)
pr(" mil shell gun pet iron dust oil pln ship unit money\n"); pr(" mil shell gun pet iron dust oil pln ship unit money\n");
snxtitem_all(&ni, EF_POWER); snxtitem_all(&ni, EF_POWER);
while ((nxtitem(&ni, &pow)) && num > 0) { while ((nxtitem(&ni, &pow)) && num > 0) {
if (pow.p_nation == 0 || pow.p_power <= 0.0) if (pow.p_nation == 0)
continue; continue;
if (opt_HIDDEN) { if (opt_HIDDEN) {
if (!player->god && pow.p_nation != player->cnum) if (!player->god && pow.p_nation != player->cnum)
@ -148,6 +140,8 @@ powe(void)
continue; continue;
if (use_targets && !targets[pow.p_nation]) if (use_targets && !targets[pow.p_nation])
continue; continue;
if (!use_targets && pow.p_power <= 0.0)
continue;
if (pow.p_nation != player->cnum && !player->god) if (pow.p_nation != player->cnum && !player->god)
round_flag = 1; round_flag = 1;
else else
@ -372,24 +366,3 @@ addtopow(short *vec, struct powstr *pow)
pow->p_power += vec[I_LCM] / 10.0; pow->p_power += vec[I_LCM] / 10.0;
pow->p_power += vec[I_HCM] / 5.0; pow->p_power += vec[I_HCM] / 5.0;
} }
static int
set_target(char *p, int *targets)
{
int target;
struct natstr *natp;
if (!p)
return 0;
target = natarg(p, NULL);
if (target < 0)
return 0;
natp = getnatp(target);
if (natp->nat_stat != STAT_ACTIVE) {
pr("Country '%s' is not a normal country\n", p);
return 0;
}
targets[target] = 1;
return 1;
}