Galactic Bloodshed
toxicity.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 /// \file toxicity.cc
6 /// \brief Change threshold in toxicity to build a wc.
7 
8 #include "gb/commands/toxicity.h"
9 
10 #include "gb/GB_server.h"
11 #include "gb/files_shl.h"
12 #include "gb/shlmisc.h"
13 #include "gb/vars.h"
14 
15 void toxicity(const command_t &argv, GameObj &g) {
16  int APcount = 1;
17 
18  if (argv.size() != 2) {
19  g.out << "Provide exactly one value between 0 and 100.\n";
20  return;
21  }
22 
23  int thresh = std::stoi(argv[1]);
24 
25  if (thresh > 100 || thresh < 0) {
26  g.out << "Illegal value.\n";
27  return;
28  }
29 
30  if (g.level != ScopeLevel::LEVEL_PLAN) {
31  g.out << "scope must be a planet.\n";
32  return;
33  }
34  if (!enufAP(g.player, g.governor, Stars[g.snum]->AP[g.player - 1], APcount)) {
35  return;
36  }
37 
38  auto p = getplanet(g.snum, g.pnum);
39  p.info[g.player - 1].tox_thresh = thresh;
40  putplanet(p, Stars[g.snum], g.pnum);
41  deductAPs(g.player, g.governor, APcount, g.snum, 0);
42 
43  g.out << " New threshold is: " << p.info[g.player - 1].tox_thresh
44  << std::endl;
45 }
Planet getplanet(const starnum_t star, const planetnum_t pnum)
Definition: files_shl.cc:335
void toxicity(const command_t &argv, GameObj &g)
Definition: toxicity.cc:15
void deductAPs(const player_t Playernum, const governor_t Governor, unsigned int n, starnum_t snum, int sdata)
Definition: shlmisc.cc:214
int enufAP(int Playernum, int Governor, unsigned short AP, int x)
Definition: shlmisc.cc:131
void putplanet(const Planet &p, startype *star, const int pnum)
Definition: files_shl.cc:934