Galactic Bloodshed
capital.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 /* capital.c -- designate a capital */
6 
7 #include "gb/commands/capital.h"
8 
9 #include <cstdio>
10 #include <cstdlib>
11 
12 #include "gb/GB_server.h"
13 #include "gb/buffers.h"
14 #include "gb/files_shl.h"
15 #include "gb/fire.h"
16 #include "gb/getplace.h"
17 #include "gb/races.h"
18 #include "gb/ships.h"
19 #include "gb/shlmisc.h"
20 #include "gb/vars.h"
21 
22 void capital(const command_t &argv, GameObj &g) {
23  player_t Playernum = g.player;
24  governor_t Governor = g.governor;
25  int APcount = 50;
26  racetype *Race;
27 
28  Race = races[Playernum - 1];
29  if (Governor) {
30  g.out << "Only the leader may designate the capital.\n";
31  return;
32  }
33 
34  shipnum_t shipno;
35  if (argv.size() != 2)
36  shipno = Race->Gov_ship;
37  else {
38  auto shiptmp = string_to_shipnum(argv[1]);
39  if (!shiptmp) {
40  g.out << "Specify a valid ship number.\n";
41  return;
42  }
43  shipno = *shiptmp;
44  }
45 
46  auto s = getship(shipno);
47  if (!s) {
48  g.out << "Change the capital to be what ship?\n";
49  return;
50  }
51 
52  if (argv.size() == 2) {
53  shipnum_t snum = s->storbits;
54  if (testship(Playernum, Governor, *s)) {
55  g.out << "You can't do that!\n";
56  return;
57  }
58  if (!landed(*s)) {
59  g.out << "Try landing this ship first!\n";
60  return;
61  }
62  if (!enufAP(Playernum, Governor, Stars[snum]->AP[Playernum - 1], APcount)) {
63  return;
64  }
65  if (s->type != ShipType::OTYPE_GOV) {
66  sprintf(buf, "That ship is not a %s.\n", Shipnames[ShipType::OTYPE_GOV]);
67  notify(Playernum, Governor, buf);
68  return;
69  }
70  deductAPs(Playernum, Governor, APcount, snum, 0);
71  Race->Gov_ship = shipno;
72  putrace(Race);
73  }
74 
75  sprintf(buf, "Efficiency of governmental center: %.0f%%.\n",
76  ((double)s->popn / (double)max_crew(*s)) * (100 - (double)s->damage));
77  notify(Playernum, Governor, buf);
78 }
void capital(const command_t &argv, GameObj &g)
Definition: capital.cc:22
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 putrace(Race *r)
Definition: files_shl.cc:808