Galactic Bloodshed
declare.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 /* declare.c -- declare alliance, neutrality, war, the basic thing. */
6 
7 #include "gb/declare.h"
8 
9 #include <cstdio>
10 
11 #include "gb/GB_server.h"
12 #include "gb/buffers.h"
13 #include "gb/config.h"
14 #include "gb/files.h"
15 #include "gb/files_shl.h"
16 #include "gb/races.h"
17 #include "gb/shlmisc.h"
18 #include "gb/tele.h"
19 #include "gb/tweakables.h"
20 #include "gb/utils/rand.h"
21 #include "gb/vars.h"
22 
23 static void show_votes(int, int);
24 
25 /* invite people to join your alliance block */
26 void invite(const command_t &argv, GameObj &g) {
27  const player_t Playernum = g.player;
28  const governor_t Governor = g.governor;
29  bool mode = argv[0] == "invite";
30 
31  int n;
32  racetype *Race;
33  racetype *alien;
34 
35  if (Governor) {
36  g.out << "Only leaders may invite.\n";
37  return;
38  }
39  if (!(n = get_player(argv[1]))) {
40  g.out << "No such player.\n";
41  return;
42  }
43  if (n == Playernum) {
44  g.out << "Not needed, you are the leader.\n";
45  return;
46  }
47  Race = races[Playernum - 1];
48  alien = races[n - 1];
49  if (mode) {
50  setbit(Blocks[Playernum - 1].invite, n);
51  sprintf(buf, "%s [%d] has invited you to join %s\n", Race->name, Playernum,
52  Blocks[Playernum - 1].name);
53  warn_race(n, buf);
54  sprintf(buf, "%s [%d] has been invited to join %s [%d]\n", alien->name, n,
55  Blocks[Playernum - 1].name, Playernum);
56  warn_race(Playernum, buf);
57  } else {
58  clrbit(Blocks[Playernum - 1].invite, n);
59  sprintf(buf, "You have been blackballed from %s [%d]\n",
60  Blocks[Playernum - 1].name, Playernum);
61  warn_race(n, buf);
62  sprintf(buf, "%s [%d] has been blackballed from %s [%d]\n", alien->name, n,
63  Blocks[Playernum - 1].name, Playernum);
64  warn_race(Playernum, buf);
65  }
67 
68  Putblock(Blocks);
69 }
70 
71 /* declare that you wish to be included in the alliance block */
72 void pledge(const command_t &argv, GameObj &g) {
73  const player_t Playernum = g.player;
74  const governor_t Governor = g.governor;
75  bool mode = argv[0] == "pledge";
76  int n;
77  racetype *Race;
78 
79  if (Governor) {
80  g.out << "Only leaders may pledge.\n";
81  return;
82  }
83  if (!(n = get_player(argv[1]))) {
84  g.out << "No such player.\n";
85  return;
86  }
87  if (n == Playernum) {
88  g.out << "Not needed, you are the leader.\n";
89  return;
90  }
91  Race = races[Playernum - 1];
92  if (mode) {
93  setbit(Blocks[n - 1].pledge, Playernum);
94  sprintf(buf, "%s [%d] has pledged %s.\n", Race->name, Playernum,
95  Blocks[n - 1].name);
96  warn_race(n, buf);
97  sprintf(buf, "You have pledged allegiance to %s.\n", Blocks[n - 1].name);
98  warn_race(Playernum, buf);
99 
100  switch (int_rand(1, 20)) {
101  case 1:
102  sprintf(
103  buf,
104  "%s [%d] joins the band wagon and pledges allegiance to %s [%d]!\n",
105  Race->name, Playernum, Blocks[n - 1].name, n);
106  break;
107  default:
108  sprintf(buf, "%s [%d] pledges allegiance to %s [%d].\n", Race->name,
109  Playernum, Blocks[n - 1].name, n);
110  break;
111  }
112  } else {
113  clrbit(Blocks[n - 1].pledge, Playernum);
114  sprintf(buf, "%s [%d] has quit %s [%d].\n", Race->name, Playernum,
115  Blocks[n - 1].name, n);
116  warn_race(n, buf);
117  sprintf(buf, "You have quit %s\n", Blocks[n - 1].name);
118  warn_race(Playernum, buf);
119 
120  switch (int_rand(1, 20)) {
121  case 1:
122  sprintf(buf, "%s [%d] calls %s [%d] a bunch of geeks and QUITS!\n",
123  Race->name, Playernum, Blocks[n - 1].name, n);
124  break;
125  default:
126  sprintf(buf, "%s [%d] has QUIT %s [%d]!\n", Race->name, Playernum,
127  Blocks[n - 1].name, n);
128  break;
129  }
130  }
131 
132  post(buf, DECLARATION);
133 
134  compute_power_blocks();
135  Putblock(Blocks);
136 }
137 
138 void declare(const command_t &argv, GameObj &g) {
139  const player_t Playernum = g.player;
140  const governor_t Governor = g.governor;
141  const int APcount = 1;
142  int n;
143  int d_mod;
144  racetype *Race;
145  racetype *alien;
146 
147  if (Governor) {
148  g.out << "Only leaders may declare.\n";
149  return;
150  }
151 
152  if (!(n = get_player(argv[1]))) {
153  g.out << "No such player.\n";
154  return;
155  }
156 
157  /* look in sdata for APs first */
158  /* enufAPs would print something */
159  if ((int)Sdata.AP[Playernum - 1] >= APcount) {
160  deductAPs(Playernum, Governor, APcount, 0, 1);
161  /* otherwise use current star */
162  } else if ((g.level == ScopeLevel::LEVEL_STAR ||
163  g.level == ScopeLevel::LEVEL_PLAN) &&
164  enufAP(Playernum, Governor, Stars[g.snum]->AP[Playernum - 1],
165  APcount)) {
166  deductAPs(Playernum, Governor, APcount, g.snum, 0);
167  } else {
168  sprintf(buf, "You don't have enough AP's (%d)\n", APcount);
169  notify(Playernum, Governor, buf);
170  return;
171  }
172 
173  Race = races[Playernum - 1];
174  alien = races[n - 1];
175 
176  switch (*argv[2].c_str()) {
177  case 'a':
178  setbit(Race->allied, n);
179  clrbit(Race->atwar, n);
180  if (success(5)) {
181  sprintf(buf, "But would you want your sister to marry one?\n");
182  notify(Playernum, Governor, buf);
183  } else {
184  sprintf(buf, "Good for you.\n");
185  notify(Playernum, Governor, buf);
186  }
187  sprintf(buf, " Player #%d (%s) has declared an alliance with you!\n",
188  Playernum, Race->name);
189  warn_race(n, buf);
190  sprintf(buf, "%s [%d] declares ALLIANCE with %s [%d].\n", Race->name,
191  Playernum, alien->name, n);
192  d_mod = 30;
193  if (argv.size() > 3) d_mod = std::stoi(argv[3]);
194  d_mod = std::max(d_mod, 30);
195  break;
196  case 'n':
197  clrbit(Race->allied, n);
198  clrbit(Race->atwar, n);
199  sprintf(buf, "Done.\n");
200  notify(Playernum, Governor, buf);
201 
202  sprintf(buf, " Player #%d (%s) has declared neutrality with you!\n",
203  Playernum, Race->name);
204  warn_race(n, buf);
205  sprintf(buf, "%s [%d] declares a state of neutrality with %s [%d].\n",
206  Race->name, Playernum, alien->name, n);
207  d_mod = 30;
208  break;
209  case 'w':
210  setbit(Race->atwar, n);
211  clrbit(Race->allied, n);
212  if (success(4)) {
213  sprintf(buf,
214  "Your enemies flaunt their secondary male reproductive "
215  "glands in your\ngeneral direction.\n");
216  notify(Playernum, Governor, buf);
217  } else {
218  sprintf(buf, "Give 'em hell!\n");
219  notify(Playernum, Governor, buf);
220  }
221  sprintf(buf, " Player #%d (%s) has declared war against you!\n",
222  Playernum, Race->name);
223  warn_race(n, buf);
224  switch (int_rand(1, 5)) {
225  case 1:
226  sprintf(buf, "%s [%d] declares WAR on %s [%d].\n", Race->name,
227  Playernum, alien->name, n);
228  break;
229  case 2:
230  sprintf(buf, "%s [%d] has had enough of %s [%d] and declares WAR!\n",
231  Race->name, Playernum, alien->name, n);
232  break;
233  case 3:
234  sprintf(
235  buf,
236  "%s [%d] decided that it is time to declare WAR on %s [%d]!\n",
237  Race->name, Playernum, alien->name, n);
238  break;
239  case 4:
240  sprintf(buf,
241  "%s [%d] had no choice but to declare WAR against %s [%d]!\n",
242  Race->name, Playernum, alien->name, n);
243  break;
244  case 5:
245  sprintf(buf,
246  "%s [%d] says 'screw it!' and declares WAR on %s [%d]!\n",
247  Race->name, Playernum, alien->name, n);
248  break;
249  default:
250  break;
251  }
252  d_mod = 30;
253  break;
254  default:
255  g.out << "I don't understand.\n";
256  return;
257  }
258 
259  post(buf, DECLARATION);
260  warn_race(Playernum, buf);
261 
262  /* They, of course, learn more about you */
263  alien->translate[Playernum - 1] =
264  MIN(alien->translate[Playernum - 1] + d_mod, 100);
265 
266  putrace(alien);
267  putrace(Race);
268 }
269 
270 #ifdef VOTING
271 void vote(const command_t &argv, GameObj &g) {
272  const player_t Playernum = g.player;
273  const governor_t Governor = g.governor;
274  racetype *Race;
275  int check;
276  int nvotes;
277  int nays;
278  int yays;
279 
280  Race = races[Playernum - 1];
281 
282  if (Race->God) {
283  sprintf(buf, "Your vote doesn't count, however, here is the count.\n");
284  notify(Playernum, Governor, buf);
285  show_votes(Playernum, Governor);
286  return;
287  }
288  if (Race->Guest) {
289  sprintf(buf, "You are not allowed to vote, but, here is the count.\n");
290  notify(Playernum, Governor, buf);
291  show_votes(Playernum, Governor);
292  return;
293  }
294 
295  if (argv.size() > 2) {
296  check = 0;
297  if (argv[1] == "update") {
298  if (argv[2] == "go") {
299  Race->votes |= VOTE_UPDATE_GO;
300  check = 1;
301  } else if (argv[2] == "wait")
302  Race->votes &= ~VOTE_UPDATE_GO;
303  else {
304  sprintf(buf, "No such update choice '%s'\n", argv[2].c_str());
305  notify(Playernum, Governor, buf);
306  return;
307  }
308  } else {
309  sprintf(buf, "No such vote '%s'\n", argv[1].c_str());
310  notify(Playernum, Governor, buf);
311  return;
312  }
313  putrace(Race);
314 
315  if (check) {
316  /* Ok...someone voted yes. Tally them all up and see if */
317  /* we should do something. */
318  nays = 0;
319  yays = 0;
320  nvotes = 0;
321  for (player_t pnum = 1; pnum <= Num_races; pnum++) {
322  Race = races[pnum - 1];
323  if (Race->God || Race->Guest) continue;
324  nvotes++;
325  if (Race->votes & VOTE_UPDATE_GO)
326  yays++;
327  else
328  nays++;
329  }
330  /* Is Update/Movement vote unanimous now? */
331  if (nvotes > 0 && nvotes == yays && nays == 0) {
332  /* Do it... */
333  do_next_thing();
334  }
335  }
336  } else {
337  sprintf(buf, "Your vote on updates is %s\n",
338  (Race->votes & VOTE_UPDATE_GO) ? "go" : "wait");
339  notify(Playernum, Governor, buf);
340  show_votes(Playernum, Governor);
341  }
342 }
343 
344 static void show_votes(int Playernum, int Governor) {
345  int nvotes;
346  int nays;
347  int yays;
348  int pnum;
349  racetype *Race;
350 
351  nays = yays = nvotes = 0;
352  for (pnum = 1; pnum <= Num_races; pnum++) {
353  Race = races[pnum - 1];
354  if (Race->God || Race->Guest) continue;
355  nvotes++;
356  if (Race->votes & VOTE_UPDATE_GO) {
357  yays++;
358  sprintf(buf, " %s voted go.\n", Race->name);
359  } else {
360  nays++;
361  sprintf(buf, " %s voted wait.\n", Race->name);
362  }
363  if (races[Playernum - 1]->God) notify(Playernum, Governor, buf);
364  }
365  sprintf(buf, " Total votes = %d, Go = %d, Wait = %d.\n", nvotes, yays, nays);
366  notify(Playernum, Governor, buf);
367 }
368 #endif
void vote(const command_t &argv, GameObj &g)
Definition: declare.cc:271
void declare(const command_t &argv, GameObj &g)
Definition: declare.cc:138
void post(const char *origmsg, int type)
Definition: tele.cc:63
#define clrbit(a, i)
Definition: vars.h:311
#define setbit(a, i)
Definition: vars.h:310
#define VOTE_UPDATE_GO
Definition: races.h:99
#define MIN(x, y)
Definition: tweakables.h:213
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
static void show_votes(int, int)
Definition: declare.cc:344
void invite(const command_t &argv, GameObj &g)
Definition: declare.cc:26
#define DECLARATION
Definition: files.h:17
void Putblock(struct block b[MAXPLAYERS])
Definition: files_shl.cc:1649
void pledge(const command_t &argv, GameObj &g)
Definition: declare.cc:72
#define VOTING
Definition: config.h:31
void putrace(Race *r)
Definition: files_shl.cc:808