Galactic Bloodshed
toggle.cc
Go to the documentation of this file.
1 // Copyright 2014 The Galactic Bloodshed Authors. All rights reserved.
2 // Use of this source code is governed by a license that can be
3 // found in the COPYING file.
4 
5 /* toggle.c -- toggles some options */
6 
7 #include "gb/commands/toggle.h"
8 
9 #include <cstdio>
10 
11 #include "gb/GB_server.h"
12 #include "gb/buffers.h"
13 #include "gb/files_shl.h"
14 #include "gb/races.h"
15 #include "gb/shlmisc.h"
16 #include "gb/vars.h"
17 
18 namespace {
19 void tog(const player_t Playernum, const governor_t Governor, char *op,
20  const char *name) {
21  *op = !(*op);
22  sprintf(buf, "%s is now %s\n", name, *op ? "on" : "off");
23  notify(Playernum, Governor, buf);
24 }
25 } // namespace
26 
27 void toggle(const command_t &argv, GameObj &g) {
28  player_t Playernum = g.player;
29  governor_t Governor = g.governor;
30  // TODO(jeffbailey): int APcount = 0;
31  racetype *Race;
32 
33  Race = races[Playernum - 1];
34 
35  if (argv.size() > 1) {
36  if (argv[1] == "inverse")
37  tog(Playernum, Governor, &Race->governor[Governor].toggle.inverse,
38  "inverse");
39  else if (argv[1] == "double_digits")
40  tog(Playernum, Governor, &Race->governor[Governor].toggle.double_digits,
41  "double_digits");
42  else if (argv[1] == "geography")
43  tog(Playernum, Governor, &Race->governor[Governor].toggle.geography,
44  "geography");
45  else if (argv[1] == "gag")
46  tog(Playernum, Governor, &Race->governor[Governor].toggle.gag, "gag");
47  else if (argv[1] == "autoload")
48  tog(Playernum, Governor, &Race->governor[Governor].toggle.autoload,
49  "autoload");
50  else if (argv[1] == "color")
51  tog(Playernum, Governor, &Race->governor[Governor].toggle.color, "color");
52  else if (argv[1] == "visible")
53  tog(Playernum, Governor, &Race->governor[Governor].toggle.invisible,
54  "invisible");
55  else if (Race->God && argv[1] == "monitor")
56  tog(Playernum, Governor, &Race->monitor, "monitor");
57  else if (argv[1] == "compatibility")
58  tog(Playernum, Governor, &Race->governor[Governor].toggle.compat,
59  "compatibility");
60  else {
61  sprintf(buf, "No such option '%s'\n", argv[1].c_str());
62  notify(Playernum, Governor, buf);
63  return;
64  }
65  putrace(Race);
66  } else {
67  sprintf(buf, "gag is %s\n",
68  Race->governor[Governor].toggle.gag ? "ON" : "OFF");
69  notify(Playernum, Governor, buf);
70  sprintf(buf, "inverse is %s\n",
71  Race->governor[Governor].toggle.inverse ? "ON" : "OFF");
72  notify(Playernum, Governor, buf);
73  sprintf(buf, "double_digits is %s\n",
74  Race->governor[Governor].toggle.double_digits ? "ON" : "OFF");
75  notify(Playernum, Governor, buf);
76  sprintf(buf, "geography is %s\n",
77  Race->governor[Governor].toggle.geography ? "ON" : "OFF");
78  notify(Playernum, Governor, buf);
79  sprintf(buf, "autoload is %s\n",
80  Race->governor[Governor].toggle.autoload ? "ON" : "OFF");
81  notify(Playernum, Governor, buf);
82  sprintf(buf, "color is %s\n",
83  Race->governor[Governor].toggle.color ? "ON" : "OFF");
84  notify(Playernum, Governor, buf);
85  sprintf(buf, "compatibility is %s\n",
86  Race->governor[Governor].toggle.compat ? "ON" : "OFF");
87  notify(Playernum, Governor, buf);
88  sprintf(
89  buf, "%s\n",
90  Race->governor[Governor].toggle.invisible ? "INVISIBLE" : "VISIBLE");
91  notify(Playernum, Governor, buf);
92  sprintf(buf, "highlight player %d\n",
93  Race->governor[Governor].toggle.highlight);
94  notify(Playernum, Governor, buf);
95  if (Race->God) {
96  sprintf(buf, "monitor is %s\n", Race->monitor ? "ON" : "OFF");
97  notify(Playernum, Governor, buf);
98  }
99  }
100 }
void tog(const player_t Playernum, const governor_t Governor, char *op, const char *name)
Definition: toggle.cc:19
void toggle(const command_t &argv, GameObj &g)
Definition: toggle.cc:27
void putrace(Race *r)
Definition: files_shl.cc:808