Galactic Bloodshed
mobiliz.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 mobiliz.c
6 /// \brief Persuade people to build military stuff.
7 
8 /*
9  * Sectors that are mobilized produce Destructive Potential in
10  * proportion to the % they are mobilized. they are also more
11  * damage-resistant.
12  */
13 
14 #include "gb/mobiliz.h"
15 
16 #include <cstdio>
17 #include <cstdlib>
18 
19 #include "gb/GB_server.h"
20 #include "gb/buffers.h"
21 #include "gb/files_shl.h"
22 #include "gb/races.h"
23 #include "gb/shlmisc.h"
24 #include "gb/vars.h"
25 
26 void mobilize(const command_t &argv, GameObj &g) {
27  player_t Playernum = g.player;
28  governor_t Governor = g.governor;
29  int APcount = 1;
30 
31  if (g.level != ScopeLevel::LEVEL_PLAN) {
32  g.out << "scope must be a planet.\n";
33  return;
34  }
35  if (!control(Playernum, Governor, Stars[g.snum])) {
36  g.out << "You are not authorized to do this here.\n";
37  return;
38  }
39  if (!enufAP(Playernum, Governor, Stars[g.snum]->AP[Playernum - 1], APcount)) {
40  return;
41  }
42 
43  auto p = getplanet(g.snum, g.pnum);
44 
45  if (argv.size() < 2) {
46  sprintf(buf, "Current mobilization: %d Quota: %d\n",
47  p.info[Playernum - 1].comread, p.info[Playernum - 1].mob_set);
48  notify(Playernum, Governor, buf);
49  return;
50  }
51  int sum_mob = std::stoi(argv[1]);
52 
53  if (sum_mob > 100 || sum_mob < 0) {
54  g.out << "Illegal value.\n";
55  return;
56  }
57  p.info[Playernum - 1].mob_set = sum_mob;
58  putplanet(p, Stars[g.snum], g.pnum);
59  deductAPs(Playernum, Governor, APcount, g.snum, 0);
60 }
61 
62 void tax(const command_t &argv, GameObj &g) {
63  player_t Playernum = g.player;
64  governor_t Governor = g.governor;
65  int APcount = 0;
66 
67  if (g.level != ScopeLevel::LEVEL_PLAN) {
68  g.out << "scope must be a planet.\n";
69  return;
70  }
71  if (!control(Playernum, Governor, Stars[g.snum])) {
72  g.out << "You are not authorized to do that here.\n";
73  return;
74  }
75  racetype *Race = races[Playernum - 1];
76  if (!Race->Gov_ship) {
77  g.out << "You have no government center active.\n";
78  return;
79  }
80  if (Race->Guest) {
81  g.out << "Sorry, but you can't do this when you are a guest.\n";
82  return;
83  }
84  if (!enufAP(Playernum, Governor, Stars[g.snum]->AP[Playernum - 1], APcount)) {
85  return;
86  }
87 
88  auto p = getplanet(g.snum, g.pnum);
89 
90  if (argv.size() < 2) {
91  sprintf(buf, "Current tax rate: %d%% Target: %d%%\n",
92  p.info[Playernum - 1].tax, p.info[Playernum - 1].newtax);
93  notify(Playernum, Governor, buf);
94  return;
95  }
96 
97  int sum_tax = std::stoi(argv[1]);
98 
99  if (sum_tax > 100 || sum_tax < 0) {
100  g.out << "Illegal value.\n";
101  return;
102  }
103  p.info[Playernum - 1].newtax = sum_tax;
104  putplanet(p, Stars[g.snum], g.pnum);
105 
106  deductAPs(Playernum, Governor, APcount, g.snum, 0);
107  g.out << "Set.\n";
108 }
109 
110 int control(int Playernum, int Governor, startype *star) {
111  return (!Governor || star->governor[Playernum - 1] == Governor);
112 }
Planet getplanet(const starnum_t star, const planetnum_t pnum)
Definition: files_shl.cc:335
void tax(const command_t &argv, GameObj &g)
Definition: mobiliz.cc:62
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
int control(int Playernum, int Governor, startype *star)
Definition: mobiliz.cc:110
void mobilize(const command_t &argv, GameObj &g)
Definition: mobiliz.cc:26