Galactic Bloodshed
enslave.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 /* enslave.c -- ENSLAVE the planet below. */
6 
7 #include "gb/commands/enslave.h"
8 
9 #include <cstdio>
10 #include <cstdlib>
11 #include <cstring>
12 
13 #include "gb/GB_server.h"
14 #include "gb/buffers.h"
15 #include "gb/files_shl.h"
16 #include "gb/getplace.h"
17 #include "gb/max.h"
18 #include "gb/races.h"
19 #include "gb/ships.h"
20 #include "gb/shlmisc.h"
21 #include "gb/vars.h"
22 
23 void enslave(const command_t &argv, GameObj &g) {
24  const player_t Playernum = g.player;
25  const governor_t Governor = g.governor;
26  int APcount = 2;
27  int aliens = 0;
28  int def = 0;
29  int attack = 0;
30  racetype *Race;
31 
32  auto shipno = string_to_shipnum(argv[1]);
33  if (!shipno) return;
34  auto s = getship(*shipno);
35 
36  if (!s) {
37  return;
38  }
39  if (testship(Playernum, Governor, *s)) {
40  return;
41  }
42  if (s->type != ShipType::STYPE_OAP) {
43  sprintf(buf, "This ship is not an %s.\n", Shipnames[ShipType::STYPE_OAP]);
44  notify(Playernum, Governor, buf);
45  return;
46  }
47  if (s->whatorbits != ScopeLevel::LEVEL_PLAN) {
48  sprintf(buf, "%s doesn't orbit a planet.\n", ship_to_string(*s).c_str());
49  notify(Playernum, Governor, buf);
50  return;
51  }
52  if (!enufAP(Playernum, Governor, Stars[s->storbits]->AP[Playernum - 1],
53  APcount)) {
54  return;
55  }
56  auto p = getplanet(s->storbits, s->pnumorbits);
57  if (p.info[Playernum - 1].numsectsowned == 0) {
58  g.out << "You don't have a garrison on the planet.\n";
59  return;
60  }
61 
62  /* add up forces attacking, defending */
63  attack = aliens = def = 0;
64  for (auto i = 1; i < MAXPLAYERS; i++) {
65  if (p.info[i - 1].numsectsowned && i != Playernum) {
66  aliens = 1;
67  def += p.info[i - 1].destruct;
68  }
69  }
70 
71  if (!aliens) {
72  g.out << "There is no one else on this planet to enslave!\n";
73  return;
74  }
75 
76  Race = races[Playernum - 1];
77 
78  Shiplist shiplist(p.ships);
79  for (auto s2 : shiplist) {
80  if (s2.alive && s2.active) {
81  if (p.info[s2.owner].numsectsowned && s2.owner != Playernum)
82  def += s2.destruct;
83  else if (s2.owner == Playernum)
84  attack += s2.destruct;
85  }
86  }
87 
88  deductAPs(Playernum, Governor, APcount, (int)s->storbits, 0);
89 
90  g.out << "\nFor successful enslavement this ship and the other ships here\n";
91  g.out << "that are yours must have a weapons\n";
92  g.out << "capacity greater than twice that the enemy can muster, including\n";
93  g.out << "the planet and all ships orbiting it.\n";
94  sprintf(buf, "\nTotal forces bearing on %s: %d\n", prin_ship_orbits(&*s),
95  attack);
96  notify(Playernum, Governor, buf);
97 
98  sprintf(telegram_buf, "ALERT!!!\n\nPlanet /%s/%s ", Stars[s->storbits]->name,
99  Stars[s->storbits]->pnames[s->pnumorbits]);
100 
101  if (def <= 2 * attack) {
102  p.slaved_to = Playernum;
103  putplanet(p, Stars[s->storbits], (int)s->pnumorbits);
104 
105  /* send telegs to anyone there */
106  sprintf(buf, "ENSLAVED by %s!!\n", ship_to_string(*s).c_str());
107  strcat(telegram_buf, buf);
108  sprintf(buf, "All material produced here will be\ndiverted to %s coffers.",
109  Race->name);
110  strcat(telegram_buf, buf);
111 
112  sprintf(buf,
113  "\nEnslavement successful. All material produced here will\n");
114  notify(Playernum, Governor, buf);
115  sprintf(buf, "be diverted to %s.\n", Race->name);
116  notify(Playernum, Governor, buf);
117  sprintf(buf,
118  "You must maintain a garrison of 0.1%% the population of the\n");
119  notify(Playernum, Governor, buf);
120  sprintf(buf,
121  "planet (at least %.0f); otherwise there is a 50%% chance that\n",
122  p.popn * 0.001);
123  notify(Playernum, Governor, buf);
124  sprintf(buf, "enslaved population will revolt.\n");
125  notify(Playernum, Governor, buf);
126  } else {
127  sprintf(buf, "repulsed attempt at enslavement by %s!!\n",
128  ship_to_string(*s).c_str());
129  strcat(telegram_buf, buf);
130  sprintf(buf, "Enslavement repulsed, defense/attack Ratio : %d to %d.\n",
131  def, attack);
132  strcat(telegram_buf, buf);
133 
134  g.out << "Enslavement repulsed.\n";
135  g.out << "You needed more weapons bearing on the planet...\n";
136  }
137 
138  for (auto i = 1; i < MAXPLAYERS; i++)
139  if (p.info[i - 1].numsectsowned && i != Playernum)
140  warn(i, Stars[s->storbits]->governor[i - 1], telegram_buf);
141 }
void enslave(const command_t &argv, GameObj &g)
Definition: enslave.cc:23
#define MAXPLAYERS
Definition: vars.h:45