5 #include "gb/dosector.h" 10 #include "gb/tweakables.h" 11 #include "gb/utils/rand.h" 14 static const int x_adj[] = {-1, 0, 1, -1, 1, -1, 0, 1};
15 static const int y_adj[] = {1, 1, 1, 0, 0, -1, -1, -1};
17 static void Migrate2(
const Planet &,
int,
int, Sector &,
int *, SectorMap &);
18 static void plate(Sector &);
21 void produce(startype *star,
const Planet &planet, Sector &s) {
32 Race = races[s.owner - 1];
34 if (s.resource && success(s.eff)) {
35 prod = round_rand(Race->metabolism) * int_rand(1, s.eff);
36 prod = std::min(prod, s.resource);
38 pfuel = prod * (1 + (s.condition == SectorType::SEC_GAS));
39 if (success(s.mobilization))
43 prod_fuel[s.owner - 1] += pfuel;
44 prod_res[s.owner - 1] += pres;
45 prod_destruct[s.owner - 1] += pdes;
50 if (s.crystals &&
Crystal(Race) && success(s.eff)) {
51 prod_crystals[s.owner - 1]++;
54 const auto pinf = &planet.info[s.owner - 1];
57 if (s.mobilization < pinf->mob_set) {
58 if (pinf->resource + prod_res[s.owner - 1] > 0) {
60 prod_res[s.owner - 1] -= round_rand(
MOB_COST);
63 }
else if (s.mobilization > pinf->mob_set) {
68 avg_mob[s.owner - 1] += s.mobilization;
73 chance = round_rand((100.0 - (
double)planet.info[s.owner - 1].tax) *
74 Race->likes[s.condition]);
75 if (success(chance)) {
76 s.eff += round_rand(Race->metabolism);
82 if ((s.condition != SectorType::SEC_WASTED) && Race->fertilize &&
84 s.fert += (int_rand(0, 100) < Race->fertilize);
85 if (s.fert > 100) s.fert = 100;
87 if (s.condition == SectorType::SEC_WASTED && success(
NATURAL_REPAIR))
91 if ((diff = s.popn - maxsup) < 0) {
92 if (s.popn >= Race->number_sexes)
93 ss = round_rand(-(
double)diff * Race->birthrate);
97 ss = -int_rand(0, std::min(2 *
static_cast<
unsigned long>(diff), s.popn));
101 Race->governor[star->governor[s.owner - 1]].maintain +=
108 void spread(
const Planet &pl, Sector &s,
int x,
int y, SectorMap &smap) {
116 if (!s.owner)
return;
117 if (pl.slaved_to && pl.slaved_to != s.owner)
120 Race = races[s.owner - 1];
123 people = round_rand((
double)Race->adventurism * (
double)s.popn *
124 (100. - (
double)s.fert) / 100.) -
128 check = round_rand(6.0 * Race->adventurism);
130 while (people > 0 && check) {
139 static void Migrate2(
const Planet &planet,
int xd,
int yd, Sector &ps,
140 int *people, SectorMap &smap) {
144 if (yd > planet.Maxy - 1 || yd < 0)
return;
147 xd = planet.Maxx - 1;
148 else if (xd > planet.Maxx - 1)
151 auto &pd = smap.get(xd, yd);
154 move = (
int)((
double)(*people) * Compat[ps.owner - 1] *
155 races[ps.owner - 1]->likes[pd.condition] / 100.0);
170 void explore(
const Planet &planet, Sector &s,
int x,
int y,
int p) {
174 if (Sectinfo[x][y].explored) {
175 Sectinfo[
mod(x - 1, planet.Maxx, d)][y].explored = p;
176 Sectinfo[
mod(x + 1, planet.Maxx, d)][y].explored = p;
178 Sectinfo[x][1].explored = p;
179 }
else if (y == planet.Maxy - 1) {
180 Sectinfo[x][y - 1].explored = p;
182 Sectinfo[x][y - 1].explored = Sectinfo[x][y + 1].explored = p;
185 }
else if (s.owner == p)
186 Sectinfo[x][y].explored = p;
191 if (s.condition != SectorType::SEC_GAS) s.condition = SectorType::SEC_PLATED;
void explore(const Planet &, Sector &, int, int, int)
void spread(const Planet &, Sector &, int, int, SectorMap &)
#define UPDATE_TROOP_COST
static void Migrate2(const Planet &, int, int, Sector &, int *, SectorMap &)
int maxsupport(const Race *r, const Sector &s, const double c, const int toxic)
void produce(startype *, const Planet &, Sector &)
static void plate(Sector &)