Galactic Bloodshed
tech.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 /* tech.c -- increase investment in technological development. */
6 
7 #include "gb/tech.h"
8 
9 #include <cmath>
10 #include <cstdio>
11 #include <cstdlib>
12 
13 #include "gb/GB_server.h"
14 #include "gb/buffers.h"
15 #include "gb/files_shl.h"
16 #include "gb/mobiliz.h"
17 #include "gb/shlmisc.h"
18 #include "gb/tweakables.h"
19 #include "gb/vars.h"
20 
21 void technology(const command_t &argv, GameObj &g) {
22  player_t Playernum = g.player;
23  governor_t Governor = g.governor;
24  int APcount = 1;
25 
26  if (g.level != ScopeLevel::LEVEL_PLAN) {
27  sprintf(buf, "scope must be a planet (%d).\n", g.level);
28  notify(Playernum, Governor, buf);
29  return;
30  }
31  if (!control(Playernum, Governor, Stars[g.snum])) {
32  g.out << "You are not authorized to do that here.\n";
33  return;
34  }
35  if (!enufAP(Playernum, Governor, Stars[g.snum]->AP[Playernum - 1], APcount)) {
36  return;
37  }
38 
39  auto p = getplanet(g.snum, g.pnum);
40 
41  if (argv.size() < 2) {
42  sprintf(buf,
43  "Current investment : %d Technology production/update: %.3f\n",
44  p.info[Playernum - 1].tech_invest,
45  tech_prod((int)(p.info[Playernum - 1].tech_invest),
46  (int)(p.info[Playernum - 1].popn)));
47  notify(Playernum, Governor, buf);
48  return;
49  }
50  short invest = std::stoi(argv[1]);
51 
52  if (invest < 0) {
53  g.out << "Illegal value.\n";
54  return;
55  }
56 
57  p.info[Playernum - 1].tech_invest = invest;
58 
59  putplanet(p, Stars[g.snum], g.pnum);
60 
61  deductAPs(Playernum, Governor, APcount, g.snum, 0);
62 
63  sprintf(buf, " New (ideal) tech production: %.3f (this planet)\n",
64  tech_prod((int)(p.info[Playernum - 1].tech_invest),
65  (int)(p.info[Playernum - 1].popn)));
66  notify(Playernum, Governor, buf);
67 }
68 
69 double tech_prod(int investment, int popn) {
70  double scale = (double)popn / 10000.;
71  return (TECH_INVEST * log10((double)investment * scale + 1.0));
72 }
Planet getplanet(const starnum_t star, const planetnum_t pnum)
Definition: files_shl.cc:335
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
double tech_prod(int investment, int popn)
Definition: tech.cc:69
void putplanet(const Planet &p, startype *star, const int pnum)
Definition: files_shl.cc:934
#define TECH_INVEST
Definition: tweakables.h:162
void technology(const command_t &argv, GameObj &g)
Definition: tech.cc:21
int control(int Playernum, int Governor, startype *star)
Definition: mobiliz.cc:110