]> git.pond.sub.org Git - empserver/blob - src/lib/player/init_nats.c
(nat_cap): Scale BTU production by capital's work.
[empserver] / src / lib / player / init_nats.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
22  *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23  *  related information and legal notices. It is expected that any future
24  *  projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  init_nats.c: Initialize country and nation file stuff
29  * 
30  *  Known contributors to this file:
31  *     Dave Pare, 1994
32  *     Steve McClure, 2000
33  */
34
35 #include "prototypes.h"
36 #include "misc.h"
37 #include "player.h"
38 #include "sect.h"
39 #include "nat.h"
40 #include "file.h"
41 #include "optlist.h"
42 #include "common.h"
43 #include "gen.h"
44
45 static int nat_cap(int);
46
47 int
48 init_nats(void)
49 {
50     struct natstr *np;
51
52     if ((np = getnatp(player->cnum)) == 0)
53         return -1;
54     player->nstat = np->nat_stat;
55     player->god = np->nat_stat & STAT_GOD;
56     player->map = ef_ptr(EF_MAP, player->cnum);
57     player->bmap = ef_ptr(EF_BMAP, player->cnum);
58     if (opt_HIDDEN) {
59         putcontact(np, player->cnum, FOUND_SPY);
60     }
61     if (np->nat_money <= 0)
62         player->broke = 1;
63     else {
64         player->nstat |= MONEY;
65         player->broke = 0;
66     }
67     if (nat_cap(np->nat_btu) < 0)
68         return -1;
69     return 0;
70 }
71
72 static int
73 nat_cap(int btu)
74 {
75     struct sctstr sect;
76     struct natstr *np;
77     double d, eff;
78     double civ;
79     int delta;
80
81     np = getnatp(player->cnum);
82     if (!getsect(np->nat_xcap, np->nat_ycap, &sect)) {
83         logerror("can't read %s's cap @ %d,%d",
84                  np->nat_cnam, np->nat_xcap, np->nat_ycap);
85         return -1;
86     }
87     if ((player->nstat & NORM) == NORM) {
88         if (player->owner && (sect.sct_type == SCT_CAPIT ||
89                               sect.sct_type == SCT_MOUNT ||
90                               sect.sct_type == SCT_SANCT))
91             player->nstat |= CAP;
92         else
93             player->nstat &= ~CAP;
94         /* Ok, has the country owner reset his capital yet after it was sacked? */
95         if (np->nat_flags & NF_SACKED)
96             player->nstat &= ~CAP;      /* No capital yet */
97     }
98     delta = 0;
99     if ((player->nstat & CAP) || player->god) {
100         d = (double)(player->curup - np->nat_last_login) / s_p_etu;
101         if (d > 336.0)
102             d = 336.0;
103         civ = sect.sct_item[I_CIVIL];
104         if (civ > 999)
105             civ = 999;
106         eff = sect.sct_effic * sect.sct_work / 100.0;
107         if (eff < 0.5 || sect.sct_type == SCT_MOUNT)
108             eff = 0.5;
109         delta = roundavg(d * civ * eff * btu_build_rate);
110
111         if (delta + btu > max_btus)
112             np->nat_btu = max_btus;
113         else
114             np->nat_btu += delta;
115     }
116     if (np->nat_stat == VIS)
117         np->nat_btu = max_btus;
118     putnat(np);
119     return 0;
120 }