(natstr): New member nat_access.
(cou_ca): New selector access.
(grant_btus, accrued_btus): New.
(prod_nat, init_nat): Use grant_btus(). BTUs are now made at the
update in addition to login, because that lets us get away with a
simple ETU stamp (nat_access).
(nat_cap): Replaced by grant_btus(), remove.
unsigned short nat_ann; /* # of annos pending */
unsigned short nat_minused; /* number of minutes used today */
short nat_btu; /* bureaucratic time units */
+ short nat_access; /* The tick when BTUs were last updated */
long nat_reserve; /* military reserves */
long nat_money; /* moola */
time_t nat_last_login; /* time of last login, 0 menas never */
extern void agecontact(struct natstr *np);
extern int influx(struct natstr *np);
+extern int grant_btus(struct natstr *, int );
+
/* nation flags */
#define NF_INFORM bit(0) /* Inform me of telegrams right away */
#define NF_FLASH bit(1) /* Allow other players to flash me (sicko :) */
--- /dev/null
+/*
+ * Empire - A multi-player, client/server Internet based war game.
+ * Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Ken Stevens, Steve McClure
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * ---
+ *
+ * See files README, COPYING and CREDITS in the root of the source
+ * tree for related information and legal notices. It is expected
+ * that future projects/authors will amend these files as needed.
+ *
+ * ---
+ *
+ * btu.c: Dealing with BTUs
+ *
+ * Known contributors to this file:
+ * Markus Armbruster, 2007
+ */
+
+#include <config.h>
+
+#include "file.h"
+#include "nat.h"
+#include "optlist.h"
+#include "prototypes.h"
+#include "sect.h"
+
+/*
+ * Return BTUs produced by CAP in ETU ETUs.
+ */
+static int
+accrued_btus(struct sctstr *cap, int etu)
+{
+ double eff, civ;
+
+ switch (cap->sct_type) {
+ case SCT_CAPIT:
+ case SCT_SANCT:
+ eff = cap->sct_effic;
+ break;
+ case SCT_MOUNT:
+ eff = 0;
+ break;
+ default:
+ return 0;
+ }
+
+ eff *= cap->sct_work / 100.0;
+ if (eff < 0.5)
+ eff = 0.5;
+
+ civ = cap->sct_item[I_CIVIL];
+ if (civ > 999)
+ civ = 999;
+
+ return roundavg(etu * civ * eff * btu_build_rate);
+}
+
+/*
+ * Grant nation NP the BTUs produced by its capital in ETU ETUs.
+ * Return whether it has a capital.
+ */
+int
+grant_btus(struct natstr *np, int etu)
+{
+ int has_cap, delta;
+ struct sctstr sect;
+
+ getsect(np->nat_xcap, np->nat_ycap, §);
+ has_cap = np->nat_stat >= STAT_ACTIVE && !influx(np);
+
+ if (has_cap) {
+ delta = accrued_btus(§, etu);
+ if (delta + np->nat_btu > max_btus)
+ np->nat_btu = max_btus;
+ else
+ np->nat_btu += delta;
+ }
+ if (np->nat_stat == STAT_VIS || np->nat_stat == STAT_GOD)
+ np->nat_btu = max_btus;
+
+ return has_cap;
+}
{NSC_USHORT, 0, 0, fldoff(natstr, nat_ann), "ann", EF_BAD},
{NSC_USHORT, 0, 0, fldoff(natstr, nat_minused), "minused", EF_BAD},
{NSC_SHORT, 0, 0, fldoff(natstr, nat_btu), "btu", EF_BAD},
+ {NSC_SHORT, 0, 0, fldoff(natstr, nat_access), "access", EF_BAD},
{NSC_LONG, 0, 0, fldoff(natstr, nat_reserve), "milreserve", EF_BAD},
{NSC_LONG, 0, 0, fldoff(natstr, nat_money), "money", EF_BAD},
{NSC_TIME, 0, 0, fldoff(natstr, nat_last_login), "login", EF_BAD},
* Known contributors to this file:
* Dave Pare, 1994
* Steve McClure, 2000
+ * Markus Armbruster, 2007
*/
#include <config.h>
#include "file.h"
+#include "game.h"
#include "misc.h"
#include "nat.h"
#include "optlist.h"
#include "prototypes.h"
#include "sect.h"
-static int nat_cap(int);
-
int
init_nats(void)
{
player->nstat |= MONEY;
player->broke = 0;
}
- if (nat_cap(np->nat_btu) < 0)
- return -1;
- return 0;
-}
-
-static int
-nat_cap(int btu)
-{
- struct sctstr sect;
- struct natstr *np;
- double d, eff;
- double civ;
- int delta;
-
- np = getnatp(player->cnum);
- if (!getsect(np->nat_xcap, np->nat_ycap, §)) {
- CANT_HAPPEN("read cap");
- return -1;
- }
- if (np->nat_stat >= STAT_ACTIVE) {
- if (influx(np))
- player->nstat &= ~CAP;
- else
- player->nstat |= CAP;
- }
- delta = 0;
- if ((player->nstat & CAP) || player->god) {
- d = (double)(player->curup - np->nat_last_login) / s_p_etu;
- if (d > 336.0)
- d = 336.0;
- civ = sect.sct_item[I_CIVIL];
- if (civ > 999)
- civ = 999;
- eff = sect.sct_effic * sect.sct_work / 100.0;
- if (eff < 0.5 || sect.sct_type == SCT_MOUNT)
- eff = 0.5;
- delta = roundavg(d * civ * eff * btu_build_rate);
-
- if (delta + btu > max_btus)
- np->nat_btu = max_btus;
- else
- np->nat_btu += delta;
- }
- if (np->nat_stat == STAT_VIS)
- np->nat_btu = max_btus;
+ if (grant_btus(np, game_tick_to_now(&np->nat_access)))
+ player->nstat |= CAP;
putnat(np);
return 0;
}
struct natstr *cnp;
for (n = 0; NULL != (np = getnatp(n)); n++) {
+ grant_btus(np, etu_per_update - np->nat_access);
+ np->nat_access = 0;
if (np->nat_stat < STAT_ACTIVE)
continue;
/*