]> git.pond.sub.org Git - empserver/blob - src/lib/commands/togg.c
Indented with src/scripts/indent-emp.
[empserver] / src / lib / commands / togg.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  *  togg.c: Set player flags
29  * 
30  *  Known contributors to this file:
31  *     Ken Stevens, 1995
32  *     Steve McClure, 1996
33  */
34
35 #include "misc.h"
36 #include "player.h"
37 #include "file.h"
38 #include "nat.h"
39 #include "commands.h"
40
41 int
42 togg(void)
43 {
44     int flag = 0;
45     int pos;
46     s_char *name;
47     struct natstr *np;
48
49     np = getnatp(player->cnum);
50     if (player->argp[1]) {
51         switch (*player->argp[1]) {
52         case 'i':
53             name = "inform";
54             flag = NF_INFORM;
55             break;
56         case 'f':
57             name = "flash";
58             flag = NF_FLASH;
59             break;
60         case 'b':
61             name = "beep";
62             flag = NF_BEEP;
63             break;
64         case 'c':
65             name = "coastwatch";
66             flag = NF_COASTWATCH;
67             break;
68         case 's':
69             name = "sonar";
70             flag = NF_SONAR;
71             break;
72         case 't':
73             name = "techlists";
74             flag = NF_TECHLISTS;
75             break;
76         default:
77             return RET_SYN;
78         }
79         if (player->argp[2])
80             if (!strcmp(player->argp[2], "on"))
81                 pos = 1;
82             else if (!strcmp(player->argp[2], "off"))
83                 pos = 0;
84             else
85                 return RET_SYN;
86         else
87             pos = !(np->nat_flags & flag);
88         if (pos)
89             np->nat_flags |= flag;
90         else
91             np->nat_flags &= ~flag;
92         putnat(np);
93         pr("%s flag %s\n", name, pos ? "on" : "off");
94     } else {
95         if (np->nat_flags & NF_INFORM)
96             pr("inform flag on\n");
97         else
98             pr("inform flag off\n");
99         if (np->nat_flags & NF_FLASH)
100             pr("flash flag on\n");
101         else
102             pr("flash flag off\n");
103         if (np->nat_flags & NF_BEEP)
104             pr("beep flag on\n");
105         else
106             pr("beep flag off\n");
107         if (np->nat_flags & NF_COASTWATCH)
108             pr("coastwatch flag on\n");
109         else
110             pr("coastwatch flag off\n");
111         if (np->nat_flags & NF_SONAR)
112             pr("sonar flag on\n");
113         else
114             pr("sonar flag off\n");
115         if (np->nat_flags & NF_TECHLISTS)
116             pr("techlists flag on\n");
117         else
118             pr("techlists flag off\n");
119     }
120
121     return RET_OK;
122 }