Galactic Bloodshed
max.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 /*
6  * maxsupport() -- return how many people one sector can support
7  * compatibility() -- return how much race is compatible with planet
8  * gravity() -- return gravity for planet
9  * prin_ship_orbits() -- prints place ship orbits
10  */
11 
12 #include "gb/max.h"
13 
14 #include <cstdio>
15 #include <cstdlib>
16 #include <cstring>
17 
18 #include "gb/files_shl.h"
19 #include "gb/races.h"
20 #include "gb/ships.h"
21 #include "gb/tweakables.h"
22 #include "gb/vars.h"
23 
25 
26 int maxsupport(const Race *r, const Sector &s, const double c,
27  const int toxic) {
28  if (!r->likes[s.condition]) return 0.0;
29  double a = ((double)s.eff + 1.0) * (double)s.fert;
30  double b = (.01 * c);
31 
32  int val = (int)(a * b * .01 * (100.0 - (double)toxic));
33 
34  return val;
35 }
36 
37 double compatibility(const Planet &planet, const Race *race) {
38  int i;
39  int add;
40  double sum;
41  double atmosphere = 1.0;
42 
43  /* make an adjustment for planetary temperature */
44  add = 0.1 * ((double)planet.conditions[TEMP] - race->conditions[TEMP]);
45  sum = 1.0 - (double)abs(add) / 100.0;
46 
47  /* step through and report compatibility of each planetary gas */
48  for (i = TEMP + 1; i <= OTHER; i++) {
49  add = (double)planet.conditions[i] - race->conditions[i];
50  atmosphere *= 1.0 - (double)abs(add) / 100.0;
51  }
52  sum *= atmosphere;
53  sum *= 100.0 - planet.conditions[TOXIC];
54 
55  if (sum < 0.0) return 0.0;
56  return (sum);
57 }
58 
59 double gravity(const Planet &p) {
60  return (double)(p.Maxx) * (double)(p.Maxy) * GRAV_FACTOR;
61 }
62 
63 char *prin_ship_orbits(Ship *s) {
64  char *motherorbits;
65 
66  switch (s->whatorbits) {
67  case ScopeLevel::LEVEL_UNIV:
68  sprintf(Dispshiporbits_buf, "/(%.0f,%.0f)", s->xpos, s->ypos);
69  break;
70  case ScopeLevel::LEVEL_STAR:
71  sprintf(Dispshiporbits_buf, "/%s", Stars[s->storbits]->name);
72  break;
73  case ScopeLevel::LEVEL_PLAN:
74  sprintf(Dispshiporbits_buf, "/%s/%s", Stars[s->storbits]->name,
75  Stars[s->storbits]->pnames[s->pnumorbits]);
76  break;
77  case ScopeLevel::LEVEL_SHIP:
78  if (auto mothership = getship(s->destshipno); mothership) {
79  motherorbits = prin_ship_orbits(&*mothership);
80  strcpy(Dispshiporbits_buf, motherorbits);
81  } else
82  strcpy(Dispshiporbits_buf, "/");
83  break;
84  }
85  return Dispshiporbits_buf;
86 }
static char Dispshiporbits_buf[PLACENAMESIZE+13]
Definition: max.cc:24
#define PLACENAMESIZE
Definition: tweakables.h:70
#define TOXIC
Definition: tweakables.h:39
char * prin_ship_orbits(Ship *s)
Definition: max.cc:63
#define TEMP
Definition: tweakables.h:30
#define GRAV_FACTOR
Definition: tweakables.h:147
double compatibility(const Planet &planet, const Race *race)
Definition: max.cc:37
#define OTHER
Definition: tweakables.h:38
double gravity(const Planet &p)
Definition: max.cc:59
int maxsupport(const Race *r, const Sector &s, const double c, const int toxic)
Definition: max.cc:26