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:
parent
2c0416135e
commit
6b70720318
8 changed files with 80 additions and 46 deletions
|
@ -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_OPT("ALL_BLEED", opt_ALL_BLEED,
|
||||
"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,
|
||||
"Enable blitz mode")
|
||||
EMPCF_OPT("BRIDGETOWERS", opt_BRIDGETOWERS,
|
||||
|
|
|
@ -77,6 +77,7 @@ extern int check_trade(void);
|
|||
extern int ontradingblock(int, void *);
|
||||
extern void trdswitchown(int, void *, int);
|
||||
extern int radar(short);
|
||||
extern void update_power(void);
|
||||
/* Commands */
|
||||
int acce(void);
|
||||
int add(void);
|
||||
|
|
|
@ -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
|
||||
|
||||
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
|
||||
bridges from them.
|
||||
GODNEWS: The world is told via news when deities are giving or taking
|
||||
|
|
31
info/power.t
31
info/power.t
|
@ -1,28 +1,29 @@
|
|||
.TH Command POWER
|
||||
.NA power "Display arbitrarily measured strengths of countries"
|
||||
.LV Basic
|
||||
.SY "power [num]"
|
||||
.SY "power new [num]"
|
||||
.SY "power country <NATS>"
|
||||
.SY "power [new|update] [<NUM>|country <NATS>]"
|
||||
The power report provides one view of national strengths.
|
||||
It can be particularly helpful in planning defense strategies
|
||||
and treaty voting.
|
||||
.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
|
||||
Normally, the last saved power report is shown.
|
||||
The optional arguments \*Qnew\*U and \*Qupdate\*U request a new power
|
||||
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
|
||||
not be displayed.
|
||||
.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
|
||||
is given for those particular countries.
|
||||
.s1
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
|
||||
static void prpower(char *, struct powstr *, 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 void addtopow(short *, struct powstr *);
|
||||
|
||||
|
@ -59,32 +59,45 @@ int
|
|||
powe(void)
|
||||
{
|
||||
struct natstr *natp;
|
||||
int i;
|
||||
time_t pow_time;
|
||||
struct nstr_item ni;
|
||||
struct powstr pow;
|
||||
int num;
|
||||
int save = 1;
|
||||
int num = MAXNOC;
|
||||
int power_generated = 0;
|
||||
struct natstr nat;
|
||||
struct powstr powbuf[MAXNOC];
|
||||
int targets[MAXNOC];
|
||||
int use_targets = 0;
|
||||
int no_numbers = 0;
|
||||
|
||||
memset(targets, 0, sizeof(targets));
|
||||
natp = getnatp(player->cnum);
|
||||
num = MAXNOC;
|
||||
|
||||
i = 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)
|
||||
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 {
|
||||
gen_power();
|
||||
gen_power(powbuf, save);
|
||||
pow_time = time(NULL);
|
||||
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)) {
|
||||
if (nat.nat_stat != STAT_ACTIVE)
|
||||
continue;
|
||||
|
@ -92,7 +105,7 @@ powe(void)
|
|||
}
|
||||
use_targets = 1;
|
||||
} else
|
||||
num = atoi(player->argp[1]);
|
||||
num = atoi(player->argp[i]);
|
||||
}
|
||||
|
||||
if (num < 0) {
|
||||
|
@ -103,39 +116,41 @@ powe(void)
|
|||
}
|
||||
|
||||
if (!power_generated) {
|
||||
pow_time = ef_mtime(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");
|
||||
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");
|
||||
pow_time = ef_mtime(EF_POWER);
|
||||
pr(" as of %s\n sects eff civ", ctime(&pow_time));
|
||||
pr(" mil shell gun pet iron dust oil pln ship unit money\n");
|
||||
snxtitem_all(&ni, EF_POWER);
|
||||
while ((nxtitem(&ni, &pow)) && num > 0) {
|
||||
if (pow.p_nation == 0)
|
||||
continue;
|
||||
for (i = 1; i < MAXNOC && num > 0; i++) {
|
||||
if (opt_HIDDEN) {
|
||||
if (!player->god && pow.p_nation != player->cnum)
|
||||
if (!player->god && powbuf[i].p_nation != player->cnum)
|
||||
continue;
|
||||
}
|
||||
if (use_targets && !targets[pow.p_nation])
|
||||
if (use_targets && !targets[powbuf[i].p_nation])
|
||||
continue;
|
||||
if (!use_targets && pow.p_power <= 0.0)
|
||||
if (!use_targets && powbuf[i].p_power <= 0.0)
|
||||
continue;
|
||||
prpower(cname(pow.p_nation), &pow,
|
||||
pow.p_nation != player->cnum && !player->god);
|
||||
prpower(cname(powbuf[i].p_nation), &powbuf[i],
|
||||
powbuf[i].p_nation != player->cnum && !player->god);
|
||||
if (player->god && !no_numbers)
|
||||
pr("%9.2f\n", pow.p_power);
|
||||
pr("%9.2f\n", powbuf[i].p_power);
|
||||
num--;
|
||||
}
|
||||
if (!opt_HIDDEN || player->god) {
|
||||
pr(" ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----\n");
|
||||
getpower(0, &pow);
|
||||
prpower("worldwide", &pow, !player->god);
|
||||
prpower("worldwide", &powbuf[0], !player->god);
|
||||
pr("\n");
|
||||
}
|
||||
return RET_OK;
|
||||
|
@ -187,8 +202,16 @@ out5(double value, int round_val, int round_flag)
|
|||
pr("%4.0fG", value / 1e9);
|
||||
}
|
||||
|
||||
void
|
||||
update_power(void)
|
||||
{
|
||||
struct powstr powbuf[MAXNOC];
|
||||
|
||||
gen_power(powbuf, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
gen_power(void)
|
||||
gen_power(struct powstr *powbuf, int save)
|
||||
{
|
||||
float *f_ptr;
|
||||
float *f_pt2;
|
||||
|
@ -198,14 +221,13 @@ gen_power(void)
|
|||
struct plnstr plane;
|
||||
struct shpstr ship;
|
||||
struct lndstr land;
|
||||
struct powstr powbuf[MAXNOC];
|
||||
struct nstr_item ni;
|
||||
struct nstr_sect ns;
|
||||
struct natstr *natp;
|
||||
float f;
|
||||
|
||||
player->btused += 10;
|
||||
memset(powbuf, 0, sizeof(powbuf));
|
||||
memset(powbuf, 0, MAXNOC * sizeof(*powbuf));
|
||||
snxtsct_all(&ns);
|
||||
while (nxtsct(&ns, §)) {
|
||||
if (sect.sct_own == 0)
|
||||
|
@ -290,6 +312,8 @@ gen_power(void)
|
|||
}
|
||||
}
|
||||
qsort(&powbuf[1], MAXNOC - 1, sizeof(*powbuf), powcmp);
|
||||
if (!save)
|
||||
return;
|
||||
for (i = 0; i < MAXNOC; i++)
|
||||
putpower(i, &powbuf[i]);
|
||||
#ifdef _WIN32
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
*
|
||||
* Known contributors to this file:
|
||||
* Steve McClure, 1998
|
||||
* Markus Armbruster, 2005
|
||||
* Markus Armbruster, 2005-2006
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -37,6 +37,7 @@
|
|||
#include "optlist.h"
|
||||
|
||||
int opt_ALL_BLEED = 1;
|
||||
int opt_AUTO_POWER = 0;
|
||||
int opt_BLITZ = 1;
|
||||
int opt_BRIDGETOWERS = 1;
|
||||
int opt_DEMANDUPDATE = 1;
|
||||
|
|
|
@ -188,7 +188,7 @@ struct cmndstr player_coms[] = {
|
|||
{"plane <SECTS>", 0, plan, 0, NORM},
|
||||
{"players", 0, play, 0, VIS},
|
||||
{"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},
|
||||
{"pray", 0, tele, C_MOD, NORM},
|
||||
{"production <SECTS>", 0, prod, 0, NORM},
|
||||
|
|
|
@ -79,6 +79,10 @@ update_main(void *unused)
|
|||
player->proc = empth_self();
|
||||
player->cnum = 0;
|
||||
player->god = 1;
|
||||
|
||||
if (opt_AUTO_POWER)
|
||||
update_power();
|
||||
|
||||
/*
|
||||
* set up all the variables which get used in the
|
||||
* sector production routine (for producing education,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue