-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplanet.cpp
More file actions
124 lines (107 loc) · 2.87 KB
/
planet.cpp
File metadata and controls
124 lines (107 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include "math.h"
#include "game.h"
#include "dict.h"
int sattp[5][5] = {
{ },
{ 0 },
{ 1, 1 },
{ 1, 2, 2 },
{ 2, 2, 2, 2 },
};
Planet::Planet(System *s, int ord, int sz, int min, int atmos)
: SObject(s, (ord+1)*600){
name = dict[rand()%dict_size];
size = sz;
minerals = min;
atmosphere = atmos;
temperature = (10-ord)*(10-ord)*4+33;
radiation = (10-ord)*(10-ord)/2;
num_satellites = (rand()%4)+1;
satellites = new Satellite*[num_satellites];
for(int ctr=0; ctr<num_satellites; ++ctr) {
satellites[ctr] = new Satellite(rand()&65535, sattp[num_satellites][ctr]);
}
};
Planet::~Planet() {
for(int ctr=0; ctr < num_satellites; ++ctr) {
delete satellites[ctr];
}
delete [] satellites;
satellites = NULL;
}
int Planet::Type() {
return 0;
}
int Planet::Radiation() {
int rad = radiation-Atmosphere();
for(int col=0; col<int(colonies.size()); ++col) {
for(int ctr=0; ctr<int(colonies[col]->objs.size()); ++ctr) {
rad += cur_tree->Radiation(colonies[col]->objs[ctr],
colonies[col]->oqty[ctr], colonies[col]);
}
}
return max(0, rad);
}
int Planet::Temperature() {
int tmp = temperature;
for(int col=0; col<int(colonies.size()); ++col) {
for(int ctr=0; ctr<int(colonies[col]->objs.size()); ++ctr) {
tmp += cur_tree->Temperature(colonies[col]->objs[ctr],
colonies[col]->oqty[ctr], colonies[col]);
}
}
return tmp;
}
int Planet::Atmosphere() {
int atm = atmosphere;
for(int col=0; col<int(colonies.size()); ++col) {
for(int ctr=0; ctr<int(colonies[col]->objs.size()); ++ctr) {
atm += cur_tree->Atmosphere(colonies[col]->objs[ctr],
colonies[col]->oqty[ctr], colonies[col]);
}
}
return max(0, atm);
}
int Planet::Minerals() {
int min = minerals;
for(int col=0; col<int(colonies.size()); ++col) {
for(int ctr=0; ctr<int(colonies[col]->objs.size()); ++ctr) {
min += cur_tree->Minerals(colonies[col]->objs[ctr],
colonies[col]->oqty[ctr], colonies[col]);
}
}
return max(0, min);
}
void Planet::TakeTurn() {
for(int ctr=0; ctr<int(colonies.size()); ++ctr) colonies[ctr]->TakeTurn();
for(int ctr=0; ctr<num_satellites; ++ctr) satellites[ctr]->TakeTurn();
}
int Planet::Owner() {
if(colonies.size() < 1) return -1;
return colonies[0]->Owner();
}
int Planet::SMove() {
return 0;
}
int Planet::GMove() {
return 0;
}
Planet::Planet(FILE *f) : SObject() {
LoadFrom(f);
}
void Planet::SaveTo(FILE *f) {
SObject::SaveTo(f);
fprintf(f, "%s\n", name.c_str());
fprintf(f, "%d %d %d %d %d %d\n",
order, size, minerals, atmosphere, temperature, radiation);
}
void Planet::LoadFrom(FILE *f) {
SObject::LoadFrom(f);
char buf[1024] = {0};
fscanf(f, "%[^\n]\n", buf); name = buf;
fscanf(f, "%d %d %d %d %d %d\n",
&order, &size, &minerals, &atmosphere, &temperature, &radiation);
}