New option AUTO_POWER; closes #1009993:

(opt_AUTO_POWER, update_power): New.
(update_main): Implement AUTO_POWER.
(powe): Disable power new when AUTO_POWER is on.

(powe): New power update.
(gen_power): Compute power into buffer passed by caller, make write to
power file optional.
This commit is contained in:
Markus Armbruster 2006-12-31 16:56:34 +00:00
parent 2c0416135e
commit 6b70720318
8 changed files with 80 additions and 46 deletions

View file

@ -155,6 +155,8 @@ EMPCF_COMMENT("# Give range HOUR:MINUTE-HOUR:MINUTE, e.g. 20:00-24:00\n"
EMPCF_COMMENT("\n\n### Options") EMPCF_COMMENT("\n\n### Options")
EMPCF_OPT("ALL_BLEED", opt_ALL_BLEED, EMPCF_OPT("ALL_BLEED", opt_ALL_BLEED,
"Let tech bleed to everyone, not just allies") "Let tech bleed to everyone, not just allies")
EMPCF_OPT("AUTO_POWER", opt_AUTO_POWER,
"Power report is updated only automatically, at the update")
EMPCF_OPT("BLITZ", opt_BLITZ, EMPCF_OPT("BLITZ", opt_BLITZ,
"Enable blitz mode") "Enable blitz mode")
EMPCF_OPT("BRIDGETOWERS", opt_BRIDGETOWERS, EMPCF_OPT("BRIDGETOWERS", opt_BRIDGETOWERS,

View file

@ -77,6 +77,7 @@ extern int check_trade(void);
extern int ontradingblock(int, void *); extern int ontradingblock(int, void *);
extern void trdswitchown(int, void *, int); extern void trdswitchown(int, void *, int);
extern int radar(short); extern int radar(short);
extern void update_power(void);
/* Commands */ /* Commands */
int acce(void); int acce(void);
int add(void); int add(void);

View file

@ -31,6 +31,7 @@ LOSE_CONTACT: In HIDDEN, lose contact after a few updates
INTERDICT_ATT: Interdict units & mil as they move in after an attack INTERDICT_ATT: Interdict units & mil as they move in after an attack
The following options were introduced in the Empire4 Server: The following options were introduced in the Empire4 Server:
AUTO_POWER: Power report is only updated automatically, at the update
BRIDGETOWERS: You can build bridge towers, which allow you to build BRIDGETOWERS: You can build bridge towers, which allow you to build
bridges from them. bridges from them.
GODNEWS: The world is told via news when deities are giving or taking GODNEWS: The world is told via news when deities are giving or taking

View file

@ -1,28 +1,29 @@
.TH Command POWER .TH Command POWER
.NA power "Display arbitrarily measured strengths of countries" .NA power "Display arbitrarily measured strengths of countries"
.LV Basic .LV Basic
.SY "power [num]" .SY "power [new|update] [<NUM>|country <NATS>]"
.SY "power new [num]"
.SY "power country <NATS>"
The power report provides one view of national strengths. The power report provides one view of national strengths.
It can be particularly helpful in planning defense strategies It can be particularly helpful in planning defense strategies
and treaty voting. and treaty voting.
.s1 .s1
If the optional \*Qnum\*U argument is given, only the Normally, the last saved power report is shown.
top num entries in the power chart will be displayed. Note that for The optional arguments \*Qnew\*U and \*Qupdate\*U request a new power
deities, if you give a negative number, only the top num entries in report based on up-to-date information.
This costs 10 BTUs.
The new report is saved for use by future power commands, except when
a deity uses \*Qupdate\*U. This lets deities examine up-to-date power
reports without affecting what players get to see.
.s1
If option AUTO_POWER is enabled, the command doesn't let you save new
power reports. Instead, the power report is updated automatically
right before the update.
.s1
If the optional \*QNUM\*U argument is given, only the
top NUM entries in the power chart will be displayed. Note that for
deities, if you give a negative number, only the top NUM entries in
the power chart will be displayed, and the power number rating will the power chart will be displayed, and the power number rating will
not be displayed. not be displayed.
.s1 .s1
If the optional \*Qnew\*U argument is given,
the program will generate a new power report based on up-to-date
information.
This costs 10 BTUs.
.s1
If the optional \*Qnew\*U argument is not given,
the program will show you the report generated
the last time someone asked for new data.
.s1
If the optional \*Qcountry\*U argument is given, then the information If the optional \*Qcountry\*U argument is given, then the information
is given for those particular countries. is given for those particular countries.
.s1 .s1

View file

@ -51,7 +51,7 @@
static void prpower(char *, struct powstr *, int); static void prpower(char *, struct powstr *, int);
static void out5(double, int, int); static void out5(double, int, int);
static void gen_power(void); static void gen_power(struct powstr *, int);
static int powcmp(const void *, const void *); static int powcmp(const void *, const void *);
static void addtopow(short *, struct powstr *); static void addtopow(short *, struct powstr *);
@ -59,32 +59,45 @@ int
powe(void) powe(void)
{ {
struct natstr *natp; struct natstr *natp;
int i;
time_t pow_time; time_t pow_time;
struct nstr_item ni; struct nstr_item ni;
struct powstr pow; int save = 1;
int num; int num = MAXNOC;
int power_generated = 0; int power_generated = 0;
struct natstr nat; struct natstr nat;
struct powstr powbuf[MAXNOC];
int targets[MAXNOC]; int targets[MAXNOC];
int use_targets = 0; int use_targets = 0;
int no_numbers = 0; int no_numbers = 0;
memset(targets, 0, sizeof(targets)); memset(targets, 0, sizeof(targets));
natp = getnatp(player->cnum);
num = MAXNOC;
i = 1;
if (player->argp[1]) { if (player->argp[1]) {
if (player->argp[1][0] == 'n') { switch (player->argp[1][0]) {
case 'u':
if (player->god)
save = 0;
/* fall through */
case 'n':
i++;
natp = getnatp(player->cnum);
if (natp->nat_btu < 1) if (natp->nat_btu < 1)
pr("\n Insufficient BTUs, using the last report.\n\n"); pr("\n Insufficient BTUs, using the last report.\n\n");
else if (opt_AUTO_POWER && save)
pr("\n power new is disabled, using the last report.\n\n");
else { else {
gen_power(); gen_power(powbuf, save);
pow_time = time(NULL);
power_generated = 1; power_generated = 1;
} }
if (player->argp[2]) }
num = atoi(player->argp[2]); }
} else if (player->argp[1][0] == 'c') {
snxtitem(&ni, EF_NATION, player->argp[2]); if (player->argp[i]) {
if (player->argp[i][0] == 'c') {
snxtitem(&ni, EF_NATION, player->argp[i + 1]);
while (nxtitem(&ni, &nat)) { while (nxtitem(&ni, &nat)) {
if (nat.nat_stat != STAT_ACTIVE) if (nat.nat_stat != STAT_ACTIVE)
continue; continue;
@ -92,7 +105,7 @@ powe(void)
} }
use_targets = 1; use_targets = 1;
} else } else
num = atoi(player->argp[1]); num = atoi(player->argp[i]);
} }
if (num < 0) { if (num < 0) {
@ -103,39 +116,41 @@ powe(void)
} }
if (!power_generated) { if (!power_generated) {
pow_time = ef_mtime(EF_POWER);
snxtitem_all(&ni, EF_POWER); snxtitem_all(&ni, EF_POWER);
if (!nxtitem(&ni, &pow)) { if (!nxtitem(&ni, &powbuf[0])) {
pr("Power for this game has not been built yet. Type 'power new' to build it.\n"); pr("Power for this game has not been built yet. Type 'power new' to build it.\n");
return RET_FAIL; return RET_FAIL;
} }
for (i = 1; i < MAXNOC; i++) {
if (!nxtitem(&ni, &powbuf[i])) {
CANT_REACH();
memset(&powbuf[i], 0, sizeof(powbuf[i]));
}
}
} }
pr(" - = [ Empire Power Report ] = -\n"); pr(" - = [ Empire Power Report ] = -\n");
pow_time = ef_mtime(EF_POWER);
pr(" as of %s\n sects eff civ", ctime(&pow_time)); pr(" as of %s\n sects eff civ", ctime(&pow_time));
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); for (i = 1; i < MAXNOC && num > 0; i++) {
while ((nxtitem(&ni, &pow)) && num > 0) {
if (pow.p_nation == 0)
continue;
if (opt_HIDDEN) { if (opt_HIDDEN) {
if (!player->god && pow.p_nation != player->cnum) if (!player->god && powbuf[i].p_nation != player->cnum)
continue; continue;
} }
if (use_targets && !targets[pow.p_nation]) if (use_targets && !targets[powbuf[i].p_nation])
continue; continue;
if (!use_targets && pow.p_power <= 0.0) if (!use_targets && powbuf[i].p_power <= 0.0)
continue; continue;
prpower(cname(pow.p_nation), &pow, prpower(cname(powbuf[i].p_nation), &powbuf[i],
pow.p_nation != player->cnum && !player->god); powbuf[i].p_nation != player->cnum && !player->god);
if (player->god && !no_numbers) if (player->god && !no_numbers)
pr("%9.2f\n", pow.p_power); pr("%9.2f\n", powbuf[i].p_power);
num--; num--;
} }
if (!opt_HIDDEN || player->god) { if (!opt_HIDDEN || player->god) {
pr(" ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----\n"); pr(" ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----\n");
getpower(0, &pow); prpower("worldwide", &powbuf[0], !player->god);
prpower("worldwide", &pow, !player->god);
pr("\n"); pr("\n");
} }
return RET_OK; return RET_OK;
@ -187,8 +202,16 @@ out5(double value, int round_val, int round_flag)
pr("%4.0fG", value / 1e9); pr("%4.0fG", value / 1e9);
} }
void
update_power(void)
{
struct powstr powbuf[MAXNOC];
gen_power(powbuf, 1);
}
static void static void
gen_power(void) gen_power(struct powstr *powbuf, int save)
{ {
float *f_ptr; float *f_ptr;
float *f_pt2; float *f_pt2;
@ -198,14 +221,13 @@ gen_power(void)
struct plnstr plane; struct plnstr plane;
struct shpstr ship; struct shpstr ship;
struct lndstr land; struct lndstr land;
struct powstr powbuf[MAXNOC];
struct nstr_item ni; struct nstr_item ni;
struct nstr_sect ns; struct nstr_sect ns;
struct natstr *natp; struct natstr *natp;
float f; float f;
player->btused += 10; player->btused += 10;
memset(powbuf, 0, sizeof(powbuf)); memset(powbuf, 0, MAXNOC * sizeof(*powbuf));
snxtsct_all(&ns); snxtsct_all(&ns);
while (nxtsct(&ns, &sect)) { while (nxtsct(&ns, &sect)) {
if (sect.sct_own == 0) if (sect.sct_own == 0)
@ -290,6 +312,8 @@ gen_power(void)
} }
} }
qsort(&powbuf[1], MAXNOC - 1, sizeof(*powbuf), powcmp); qsort(&powbuf[1], MAXNOC - 1, sizeof(*powbuf), powcmp);
if (!save)
return;
for (i = 0; i < MAXNOC; i++) for (i = 0; i < MAXNOC; i++)
putpower(i, &powbuf[i]); putpower(i, &powbuf[i]);
#ifdef _WIN32 #ifdef _WIN32

View file

@ -29,7 +29,7 @@
* *
* Known contributors to this file: * Known contributors to this file:
* Steve McClure, 1998 * Steve McClure, 1998
* Markus Armbruster, 2005 * Markus Armbruster, 2005-2006
*/ */
#include <config.h> #include <config.h>
@ -37,6 +37,7 @@
#include "optlist.h" #include "optlist.h"
int opt_ALL_BLEED = 1; int opt_ALL_BLEED = 1;
int opt_AUTO_POWER = 0;
int opt_BLITZ = 1; int opt_BLITZ = 1;
int opt_BRIDGETOWERS = 1; int opt_BRIDGETOWERS = 1;
int opt_DEMANDUPDATE = 1; int opt_DEMANDUPDATE = 1;

View file

@ -188,7 +188,7 @@ struct cmndstr player_coms[] = {
{"plane <SECTS>", 0, plan, 0, NORM}, {"plane <SECTS>", 0, plan, 0, NORM},
{"players", 0, play, 0, VIS}, {"players", 0, play, 0, VIS},
{"pmap <SECTS|PLANE> [s|l|n|p|*|h]", 0, map, C_MOD, NORM}, {"pmap <SECTS|PLANE> [s|l|n|p|*|h]", 0, map, C_MOD, NORM},
{"power [\"new\"] [<NUMBER OF COUNTRIES>] | \"country\" <NATS>", {"power [\"new\"|\"update\"] [<NUMBER OF COUNTRIES> | \"country\" <NATS>]",
0, powe, C_MOD, VIS}, 0, powe, C_MOD, VIS},
{"pray", 0, tele, C_MOD, NORM}, {"pray", 0, tele, C_MOD, NORM},
{"production <SECTS>", 0, prod, 0, NORM}, {"production <SECTS>", 0, prod, 0, NORM},

View file

@ -79,6 +79,10 @@ update_main(void *unused)
player->proc = empth_self(); player->proc = empth_self();
player->cnum = 0; player->cnum = 0;
player->god = 1; player->god = 1;
if (opt_AUTO_POWER)
update_power();
/* /*
* set up all the variables which get used in the * set up all the variables which get used in the
* sector production routine (for producing education, * sector production routine (for producing education,