Galactic Bloodshed
relation.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 /* relation.c -- state relations among players */
6 
7 #include "gb/commands/relation.h"
8 
9 #include <cstdio>
10 
11 #include "gb/GB_server.h"
12 #include "gb/buffers.h"
13 #include "gb/races.h"
14 #include "gb/shlmisc.h"
15 #include "gb/vars.h"
16 
17 static auto allied(const Race &r, const player_t p) {
18  if (isset(r.atwar, p)) return "WAR";
19  if (isset(r.allied, p)) return "ALLIED";
20  return "neutral";
21 }
22 
23 void relation(const command_t &argv, GameObj &g) {
24  const player_t Playernum = g.player;
25  const governor_t Governor = g.governor;
26  player_t q;
27  if (argv.size() == 1) {
28  q = Playernum;
29  } else {
30  if (!(q = get_player(argv[1]))) {
31  g.out << "No such player.\n";
32  return;
33  }
34  }
35 
36  auto Race = races[q - 1];
37 
38  sprintf(buf, "\n Racial Relations Report for %s\n\n",
39  Race->name);
40  notify(Playernum, Governor, buf);
41  g.out << " # know Race name Yours Theirs\n";
42  g.out << " - ---- --------- ----- ------\n";
43  for (auto r : races) {
44  if (r->Playernum == Race->Playernum) continue;
45  sprintf(buf, "%2hhu %s (%3d%%) %20.20s : %10s %10s\n", r->Playernum,
46  ((Race->God || (Race->translate[r->Playernum - 1] > 30)) &&
47  r->Metamorph && (Playernum == q))
48  ? "Morph"
49  : " ",
50  Race->translate[r->Playernum - 1], r->name,
51  allied(*Race, r->Playernum), allied(*r, q));
52  notify(Playernum, Governor, buf);
53  }
54 }
void relation(const command_t &argv, GameObj &g)
Definition: relation.cc:23
#define isset(a, i)
Definition: vars.h:312
static auto allied(const Race &r, const player_t p)
Definition: relation.cc:17