]> 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-2009, 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  *     Markus Armbruster, 2007
34  */
35
36 #include <config.h>
37
38 #include "file.h"
39 #include "game.h"
40 #include "misc.h"
41 #include "nat.h"
42 #include "optlist.h"
43 #include "player.h"
44 #include "prototypes.h"
45 #include "sect.h"
46
47 int
48 init_nats(void)
49 {
50     struct natstr *np;
51
52     np = getnatp(player->cnum);
53     if (CANT_HAPPEN(!np))
54         return -1;
55
56     player->map = ef_ptr(EF_MAP, player->cnum);
57     player->bmap = ef_ptr(EF_BMAP, player->cnum);
58
59     if (opt_HIDDEN)
60         putcontact(np, player->cnum, FOUND_SPY);
61
62     player_set_nstat(player, np);
63     grant_btus(np, game_tick_to_now(&np->nat_access));
64
65     putnat(np);
66     return 0;
67 }
68
69 int
70 player_set_nstat(struct player *pl, struct natstr *np)
71 {
72     static int nstat[] = {
73         /* must match nat_status */
74         0, VIS, VIS, SANCT, NORM, GOD | CAP | MONEY
75     };
76
77     if (CANT_HAPPEN(pl->cnum != np->nat_cnum))
78         return pl->nstat;
79     pl->god = np->nat_stat == STAT_GOD;
80     pl->nstat = nstat[np->nat_stat];
81     if (np->nat_money >= 0)
82         pl->nstat |= MONEY;
83     if (np->nat_stat == STAT_ACTIVE && !influx(np))
84         pl->nstat |= CAP;
85     pl->nstat |= EXEC;
86     return pl->nstat;
87 }