Galactic Bloodshed
fix.cc
Go to the documentation of this file.
1 // Copyright 2019 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 /// \file fix.cc
6 
7 #include "gb/commands/fix.h"
8 
9 #include <cctype>
10 #include <cmath>
11 #include <cstdio>
12 #include <cstdlib>
13 #include <cstring>
14 #include <ctime>
15 #include <sstream>
16 #include <string>
17 
18 #include "gb/GB_server.h"
19 #include "gb/buffers.h"
20 #include "gb/files.h"
21 #include "gb/files_shl.h"
22 #include "gb/max.h"
23 #include "gb/races.h"
24 #include "gb/ships.h"
25 #include "gb/shlmisc.h"
26 #include "gb/tweakables.h"
27 #include "gb/vars.h"
28 
29 /** Deity fix-it utilities */
30 void fix(const command_t &argv, GameObj &g) {
31  player_t Playernum = g.player;
32  governor_t Governor = g.governor;
33  if (!g.god) {
34  notify(Playernum, Governor,
35  "This command is only available to the deity.\n");
36  return;
37  }
38 
39  if (argv[1] == "planet") {
40  if (g.level != ScopeLevel::LEVEL_PLAN) {
41  g.out << "Change scope to the planet first.\n";
42  return;
43  }
44  auto p = getplanet(g.snum, g.pnum);
45  if (argv[2] == "Maxx") {
46  if (argv.size() > 3) p.Maxx = std::stoi(argv[3]);
47  sprintf(buf, "Maxx = %d\n", p.Maxx);
48  } else if (argv[2] == "Maxy") {
49  if (argv.size() > 3) p.Maxy = std::stoi(argv[3]);
50  sprintf(buf, "Maxy = %d\n", p.Maxy);
51  } else if (argv[2] == "xpos") {
52  if (argv.size() > 3) p.xpos = (double)std::stoi(argv[3]);
53  sprintf(buf, "xpos = %f\n", p.xpos);
54  } else if (argv[2] == "ypos") {
55  if (argv.size() > 3) p.ypos = (double)std::stoi(argv[3]);
56  sprintf(buf, "ypos = %f\n", p.ypos);
57  } else if (argv[2] == "ships") {
58  if (argv.size() > 3) p.ships = std::stoi(argv[3]);
59  sprintf(buf, "ships = %ld\n", p.ships);
60  } else if (argv[2] == "rtemp") {
61  if (argv.size() > 3) p.conditions[RTEMP] = std::stoi(argv[3]);
62  sprintf(buf, "RTEMP = %d\n", p.conditions[RTEMP]);
63  } else if (argv[2] == "temperature") {
64  if (argv.size() > 3) p.conditions[TEMP] = std::stoi(argv[3]);
65  sprintf(buf, "TEMP = %d\n", p.conditions[TEMP]);
66  } else if (argv[2] == "methane") {
67  if (argv.size() > 3) p.conditions[METHANE] = std::stoi(argv[3]);
68  sprintf(buf, "METHANE = %d\n", p.conditions[METHANE]);
69  } else if (argv[2] == "oxygen") {
70  if (argv.size() > 3) p.conditions[OXYGEN] = std::stoi(argv[3]);
71  sprintf(buf, "OXYGEN = %d\n", p.conditions[OXYGEN]);
72  } else if (argv[2] == "co2") {
73  if (argv.size() > 3) p.conditions[CO2] = std::stoi(argv[3]);
74  sprintf(buf, "CO2 = %d\n", p.conditions[CO2]);
75  } else if (argv[2] == "hydrogen") {
76  if (argv.size() > 3) p.conditions[HYDROGEN] = std::stoi(argv[3]);
77  sprintf(buf, "HYDROGEN = %d\n", p.conditions[HYDROGEN]);
78  } else if (argv[2] == "nitrogen") {
79  if (argv.size() > 3) p.conditions[NITROGEN] = std::stoi(argv[3]);
80  sprintf(buf, "NITROGEN = %d\n", p.conditions[NITROGEN]);
81  } else if (argv[2] == "sulfur") {
82  if (argv.size() > 3) p.conditions[SULFUR] = std::stoi(argv[3]);
83  sprintf(buf, "SULFUR = %d\n", p.conditions[SULFUR]);
84  } else if (argv[2] == "helium") {
85  if (argv.size() > 3) p.conditions[HELIUM] = std::stoi(argv[3]);
86  sprintf(buf, "HELIUM = %d\n", p.conditions[HELIUM]);
87  } else if (argv[2] == "other") {
88  if (argv.size() > 3) p.conditions[OTHER] = std::stoi(argv[3]);
89  sprintf(buf, "OTHER = %d\n", p.conditions[OTHER]);
90  } else if (argv[2] == "toxic") {
91  if (argv.size() > 3) p.conditions[TOXIC] = std::stoi(argv[3]);
92  sprintf(buf, "TOXIC = %d\n", p.conditions[TOXIC]);
93  } else {
94  g.out << "No such option for 'fix planet'.\n";
95  return;
96  }
97  notify(Playernum, Governor, buf);
98  if (argv.size() > 3) putplanet(p, Stars[g.snum], g.pnum);
99  return;
100  }
101  if (argv[1] == "ship") {
102  if (g.level != ScopeLevel::LEVEL_SHIP) {
103  notify(Playernum, Governor,
104  "Change scope to the ship you wish to fix.\n");
105  return;
106  }
107  auto s = getship(g.shipno);
108  if (argv[2] == "fuel") {
109  if (argv.size() > 3) s->fuel = (double)std::stoi(argv[3]);
110  sprintf(buf, "fuel = %f\n", s->fuel);
111  } else if (argv[2] == "max_fuel") {
112  if (argv.size() > 3) s->max_fuel = std::stoi(argv[3]);
113  sprintf(buf, "fuel = %d\n", s->max_fuel);
114  } else if (argv[2] == "destruct") {
115  if (argv.size() > 3) s->destruct = std::stoi(argv[3]);
116  sprintf(buf, "destruct = %d\n", s->destruct);
117  } else if (argv[2] == "resource") {
118  if (argv.size() > 3) s->resource = std::stoi(argv[3]);
119  sprintf(buf, "resource = %lu\n", s->resource);
120  } else if (argv[2] == "damage") {
121  if (argv.size() > 3) s->damage = std::stoi(argv[3]);
122  sprintf(buf, "damage = %d\n", s->damage);
123  } else if (argv[2] == "alive") {
124  s->alive = 1;
125  s->damage = 0;
126  sprintf(buf, "%s resurrected\n", ship_to_string(*s).c_str());
127  } else if (argv[2] == "dead") {
128  s->alive = 0;
129  s->damage = 100;
130  sprintf(buf, "%s destroyed\n", ship_to_string(*s).c_str());
131  } else {
132  g.out << "No such option for 'fix ship'.\n";
133  return;
134  }
135  notify(Playernum, Governor, buf);
136  putship(&*s);
137  return;
138  }
139  g.out << "Fix what?\n";
140 }
#define HELIUM
Definition: tweakables.h:37
#define SULFUR
Definition: tweakables.h:36
#define METHANE
Definition: tweakables.h:31
Planet getplanet(const starnum_t star, const planetnum_t pnum)
Definition: files_shl.cc:335
#define OXYGEN
Definition: tweakables.h:32
#define TOXIC
Definition: tweakables.h:39
#define CO2
Definition: tweakables.h:33
#define TEMP
Definition: tweakables.h:30
#define OTHER
Definition: tweakables.h:38
void putplanet(const Planet &p, startype *star, const int pnum)
Definition: files_shl.cc:934
#define HYDROGEN
Definition: tweakables.h:34
void fix(const command_t &argv, GameObj &g)
Definition: fix.cc:30
#define NITROGEN
Definition: tweakables.h:35
#define RTEMP
Definition: tweakables.h:29