Galactic Bloodshed
examine.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 /* examine -- check out an object */
6 
7 #include "gb/commands/examine.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.h"
16 #include "gb/files_shl.h"
17 #include "gb/ships.h"
18 #include "gb/shlmisc.h"
19 #include "gb/vars.h"
20 
21 void examine(const command_t &argv, GameObj &g) {
22  const int APcount = 0;
23  FILE *fd;
24  char ch;
25 
26  if (argv.size() < 2) {
27  g.out << "Examine what?\n";
28  return;
29  }
30 
31  auto shipno = string_to_shipnum(argv[1]);
32 
33  if (!shipno) {
34  return;
35  }
36 
37  auto ship = getship(*shipno);
38 
39  if (!ship) {
40  return;
41  }
42 
43  if (!ship->alive) {
44  g.out << "that ship is dead.\n";
45  return;
46  }
47  if (ship->whatorbits == ScopeLevel::LEVEL_UNIV ||
48  isclr(Stars[ship->storbits]->inhabited, g.player)) {
49  g.out << "That ship it not visible to you.\n";
50  return;
51  }
52 
53  if ((fd = fopen(EXAM_FL, "r")) == nullptr) {
54  perror(EXAM_FL);
55  return;
56  }
57 
58  /* look through ship data file */
59  for (int t = 0; t <= ship->type; t++)
60  while (fgetc(fd) != '~')
61  ;
62 
63  /* look through ship data file */
64  sprintf(buf, "\n");
65  /* give report */
66  while ((ch = fgetc(fd)) != '~') {
67  sprintf(temp, "%c", ch);
68  strcat(buf, temp);
69  }
70  notify(g.player, g.governor, buf);
71  fclose(fd);
72 
73  if (!ship->examined) {
74  if (ship->whatorbits == ScopeLevel::LEVEL_UNIV)
75  deductAPs(g.player, g.governor, APcount, 0, 1); /* ded from sdata */
76  else
77  deductAPs(g.player, g.governor, APcount, ship->storbits, 0);
78 
79  ship->examined = 1;
80  putship(&*ship);
81  }
82 
83  if (has_switch(*ship)) {
84  g.out << "This device has an on/off switch that can be set with order.\n";
85  }
86  if (!ship->active) {
87  g.out << "This device has been irradiated;\n";
88  g.out << "Its crew is dying and it cannot move for the time being.\n";
89  }
90 }
void examine(const command_t &argv, GameObj &g)
Definition: examine.cc:21
#define EXAM_FL
Definition: files.h:24
#define isclr(a, i)
Definition: vars.h:313
void deductAPs(const player_t Playernum, const governor_t Governor, unsigned int n, starnum_t snum, int sdata)
Definition: shlmisc.cc:214