]> git.pond.sub.org Git - empserver/blob - src/lib/commands/coun.c
Import of Empire 4.2.12
[empserver] / src / lib / commands / coun.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2000, 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  *  coun.c: Do a country roster
29  * 
30  *  Known contributors to this file:
31  *     
32  */
33
34 #include "misc.h"
35 #include "player.h"
36 #include "var.h"
37 #include "sect.h"
38 #include "nat.h"
39 #include "xy.h"
40 #include "nsc.h"
41 #include "file.h"
42 #include "deity.h"
43 #include <fcntl.h>
44 #include <ctype.h>
45 #include "commands.h"
46
47 static void coun_header(void);
48 static void coun_list(natid cn, struct natstr *natp);
49
50 int
51 coun(void)
52 {
53         struct  nstr_item ni;
54         struct  natstr nat;
55         int     first;
56
57         pr("The 'country' command is temporarily out of order.\n");
58         pr("Please use the 'players' command instead.\n");
59         if (!snxtitem(&ni, EF_NATION, player->argp[1]))
60                 return RET_SYN;
61         first = 1;
62         while (nxtitem(&ni, (s_char *)&nat)) {
63                 if ((nat.nat_stat & STAT_INUSE) == 0)
64                         continue;
65                 if (((nat.nat_stat & GOD) != GOD) && !player->god)
66                         continue;
67                 if (first) {
68                         coun_header();
69                         first = 0;
70                 }
71                 coun_list((natid)ni.cur, &nat);
72         }
73         return RET_OK;
74 }
75
76 static void
77 coun_header(void)
78 {
79         prdate();
80         pr("  #   last access       time\tstatus\t\t country name\n");
81 }
82
83 static void
84 coun_list(natid cn, struct natstr *natp)
85 {
86         s_char  *status;
87         struct  sctstr sect;
88
89         if (natp->nat_connected)
90                 pr("%3d  %-16.16s   [%d]",cn," Now logged on",
91                         natp->nat_btu);
92         else
93                 pr("%3d  %-16.16s   [%d]", cn, ctime(&natp->nat_last_login),
94                         natp->nat_btu);
95
96         if (natp->nat_stat & STAT_GOD)
97                 status = "DEITY";
98         else if (natp->nat_stat & STAT_NEW)
99                 status = "New";
100         else if (natp->nat_stat & STAT_SANCT)
101                 status = "Sanctuary";
102         else if (natp->nat_stat & STAT_NORM) {
103                 getsect(natp->nat_xcap, natp->nat_ycap, &sect);
104                 if (sect.sct_own != cn ||
105                     (sect.sct_type != SCT_CAPIT &&
106                     sect.sct_type != SCT_MOUNT))
107                         status = "In flux";
108                 else if (natp->nat_money < 0)
109                         status = "Broke";
110                 else
111                         status = "Active";
112         } else {
113                 status = "Visitor";
114         }
115         pr("\t%-9.9s\t %s\n", status, natp->nat_cnam);
116 }