-
Notifications
You must be signed in to change notification settings - Fork 0
/
Planet.cs
148 lines (145 loc) · 5.55 KB
/
Planet.cs
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
////////////////////////////////////////////////////////////////////////////////
// //
// Planet.cs //
// Planet class //
// Created by: Jay Mirecki, July 27, 2019 //
// Modified by: Jay Mirecki, March 17, 2020 //
// //
// The Planet class represents a planet in the galaxy. This //
// structure stores information about its location, //
// population, and industry. Additionally, the class //
// implements methods to update the dynamic parameters as //
// the simulation runs. //
// //
////////////////////////////////////////////////////////////////////////////////
using System;
using System.Runtime.Serialization;
using System.Xml.Serialization;
using System.Collections.Generic;
namespace GSWS {
[Serializable] public class Planet : IObject {
#region Properties
[XmlAttribute] public string ID;
public string Name, Demonym, Description;
public string kGovernment;
public float Population, Wealth;
[XmlIgnore] public HashSet<Fleet> Fleets { get; private set; }
private Body _body;
[XmlIgnore] public Body Body {
set { if (value.ID == ID)
_body = value; }
private get { return _body; }
}
[XmlIgnore] public Government Government;
[XmlIgnore] public Coordinate Position {
get { return Body.Position; }
}
[XmlIgnore] public string System {
get { return Body.kSystem; }
}
[XmlIgnore] public string Sector {
get { return Body.kSystem; }
}
[XmlIgnore] public Region Region {
get { return Body.Region; }
}
[XmlIgnore] public Class Class {
get { return Body.Class; }
}
[XmlIgnore] public Atmosphere Atmosphere {
get { return Body.Atmosphere; }
}
[XmlIgnore] public Government Faction {
get { return Government.Faction; }
}
#endregion
#region Constructing
public Planet() {
ID = "";
Name = Demonym = Description = "";
kGovernment = "";
Population = Wealth = 0f;
Fleets = new HashSet<Fleet>();
_body = new Body();
}
#endregion
#region Boiler Plate
public string DatapadDescription() {
string description =
Name + "\n\n" +
Position.ToString() + ", " + System + ", " + Sector + ", " + Region + "\n\n" +
Description;
return description;
}
public override string ToString() {
return "{" + ID + ", " + Name + "}";
}
public void UpdateValues(Database db) {
Body body;
if (db.Bodies.TryGetValue(ID, out body))
Body = body;
Government government;
if (db.Governments.TryGetValue(kGovernment, out government))
Government = government;
}
public void UpdateKeys() {
kGovernment = Government.ID;
}
public void VerifySubGroups() {
foreach (Fleet f in Fleets) {
if (f.Orbiting != this)
Fleets.Remove(f);
}
}
public void UpdateSuperGroups() {
Government.MemberPlanets.Add(this);
}
#endregion
#region Value Calculations
public float Value() {
return ResidentialValue();// + IndustrialValue();
}
public float ResidentialValue() {
return Wealth * Population;
}
// public float IndustrialValue() {
// return Productivity * Industrialization;
// }
// public void GenerateUnknownInfo() {
// if (Description == "")
// Description = "A planet in the " + System + "system";
// }
public string ValueString() {
float value = Value();
string valueString;
if (value > 1000000000000000000000000000f)
valueString =
value.ToString("###,###,###,###,###,,,,,,,,,.00") + " octillion";
else if (value > 1000000000000000000000000f)
valueString =
value.ToString("###,###,###,###,###,,,,,,,,.00") + " septillion";
else if (value > 1000000000000000000000f)
valueString =
value.ToString("###,###,###,###,###,,,,,,,.00") + " sextillion";
else if (value > 1000000000000000000f)
valueString =
value.ToString("###,###,###,###,###,,,,,,.00") + " quintillion";
else if (value > 1000000000000000f)
valueString =
value.ToString("###,###,###,###,###,,,,,.00") + " quadrillion";
else if (value > 1000000000000f)
valueString =
value.ToString("###,###,###,###,###,,,,.00") + " trillion";
else if (value > 1000000000f)
valueString =
value.ToString("###,###,###,###,###,,,.00") + " billion";
else if (value > 1000000f)
valueString =
value.ToString("###,###,###,###,###,,.00") + " million";
else
valueString =
value.ToString("###,###.00");
return valueString + " credits per year";
}
#endregion
}}