]> git.pond.sub.org Git - empserver/blob - src/lib/player/init_nats.c
COPYING duplicates information from README. Remove. Move GPL from
[empserver] / src / lib / player / init_nats.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2006, 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 files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future 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 <config.h>
36
37 #include "prototypes.h"
38 #include "misc.h"
39 #include "player.h"
40 #include "sect.h"
41 #include "nat.h"
42 #include "file.h"
43 #include "optlist.h"
44 #include "common.h"
45 #include "gen.h"
46
47 static int nat_cap(int);
48
49 int
50 init_nats(void)
51 {
52     static int nstat[] = {
53         /* must match nat_status */
54         0, VIS, VIS, SANCT, NORM, GOD
55     };
56     struct natstr *np;
57
58     if ((np = getnatp(player->cnum)) == 0)
59         return -1;
60     player->nstat = nstat[np->nat_stat];
61     player->god = np->nat_stat == STAT_GOD;
62     player->map = ef_ptr(EF_MAP, player->cnum);
63     player->bmap = ef_ptr(EF_BMAP, player->cnum);
64     if (opt_HIDDEN) {
65         putcontact(np, player->cnum, FOUND_SPY);
66     }
67     if (np->nat_money <= 0)
68         player->broke = 1;
69     else {
70         player->nstat |= MONEY;
71         player->broke = 0;
72     }
73     if (nat_cap(np->nat_btu) < 0)
74         return -1;
75     return 0;
76 }
77
78 static int
79 nat_cap(int btu)
80 {
81     struct sctstr sect;
82     struct natstr *np;
83     double d, eff;
84     double civ;
85     int delta;
86
87     np = getnatp(player->cnum);
88     if (!getsect(np->nat_xcap, np->nat_ycap, &sect)) {
89         logerror("can't read %s's cap @ %d,%d",
90                  np->nat_cnam, np->nat_xcap, np->nat_ycap);
91         return -1;
92     }
93     if (np->nat_stat >= STAT_ACTIVE) {
94         if (influx(np))
95             player->nstat &= ~CAP;
96         else
97             player->nstat |= CAP;
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         eff = sect.sct_effic * sect.sct_work / 100.0;
108         if (eff < 0.5 || sect.sct_type == SCT_MOUNT)
109             eff = 0.5;
110         delta = roundavg(d * civ * eff * btu_build_rate);
111
112         if (delta + btu > max_btus)
113             np->nat_btu = max_btus;
114         else
115             np->nat_btu += delta;
116     }
117     if (np->nat_stat == STAT_VIS)
118         np->nat_btu = max_btus;
119     putnat(np);
120     return 0;
121 }