]> git.pond.sub.org Git - empserver/blob - src/lib/player/init_nats.c
Update copyright notice.
[empserver] / src / lib / player / init_nats.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2004, 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 "var.h"
39 #include "sect.h"
40 #include "nat.h"
41 #include "file.h"
42 #include "optlist.h"
43 #include "common.h"
44 #include "gen.h"
45
46 static int nat_cap(int);
47
48 int
49 init_nats(void)
50 {
51     struct natstr *np;
52
53     if ((np = getnatp(player->cnum)) == 0)
54         return -1;
55     player->nstat = np->nat_stat;
56     player->god = np->nat_stat & STAT_GOD;
57     player->map = ef_ptr(EF_MAP, player->cnum);
58     player->bmap = ef_ptr(EF_BMAP, player->cnum);
59     if (opt_HIDDEN) {
60         putcontact(np, player->cnum, FOUND_SPY);
61     }
62     if (np->nat_money <= 0)
63         player->broke = 1;
64     else {
65         player->nstat |= MONEY;
66         player->broke = 0;
67     }
68     if (nat_cap(np->nat_btu) < 0)
69         return -1;
70     return 0;
71 }
72
73 static int
74 nat_cap(int btu)
75 {
76     struct sctstr sect;
77     struct natstr *np;
78     double d;
79     double civ;
80     int delta;
81
82     np = getnatp(player->cnum);
83     if (!getsect(np->nat_xcap, np->nat_ycap, &sect)) {
84         logerror("can't read %s's cap @ %d,%d",
85                  np->nat_cnam, np->nat_xcap, np->nat_ycap);
86         return -1;
87     }
88     if ((player->nstat & NORM) == NORM) {
89         if (player->owner && (sect.sct_type == SCT_CAPIT ||
90                               sect.sct_type == SCT_MOUNT ||
91                               sect.sct_type == SCT_SANCT))
92             player->nstat |= CAP;
93         else
94             player->nstat &= ~CAP;
95         /* Ok, has the country owner reset his capital yet after it was sacked? */
96         if (np->nat_flags & NF_SACKED)
97             player->nstat &= ~CAP;      /* No capital yet */
98     }
99     delta = 0;
100     if ((player->nstat & CAP) || player->god) {
101         d = (double)(player->curup - np->nat_last_login) / s_p_etu;
102         if (d > 336.0)
103             d = 336.0;
104         civ = sect.sct_item[I_CIVIL];
105         if (civ > 999)
106             civ = 999;
107         if ((sect.sct_effic) && (sect.sct_type != SCT_MOUNT))
108             delta = roundavg(d * civ * sect.sct_effic * btu_build_rate);
109         else                    /* Assume 1/2% efficiency minimum */
110             delta = roundavg(d * civ * btu_build_rate / 2.0);
111         if (player->god)
112             delta = max_btus - btu;
113         if (delta + btu > max_btus)
114             delta = max_btus - btu;
115         if (btu > max_btus)
116             delta = max_btus - btu;
117         if (opt_BLITZ)
118             delta = max_btus - btu;
119
120         if (delta > 0) {
121             /* set date if BTUs made */
122             np->nat_btu += delta;
123         }
124         if (btu > max_btus)
125             np->nat_btu = max_btus;
126     }
127     if (np->nat_stat == VIS)
128         np->nat_btu = max_btus;
129     putnat(np);
130     return 0;
131 }