-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHSystem.cs
141 lines (125 loc) · 4.12 KB
/
HSystem.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HazeronProspector
{
public class HSystem
{
protected Dictionary<string, CelestialBody> _celestialBodies = new Dictionary<string, CelestialBody>();
public Dictionary<string, CelestialBody> CelestialBodies
{
get { return _celestialBodies; }
}
protected Sector _hostSector;
public Sector HostSector
{
get { return _hostSector; }
set { _hostSector = value; }
}
protected string _name;
public string Name
{
get { return _name; }
}
protected string _catalogName;
public string CatalogName
{
get { return _catalogName; }
}
protected string _id;
public string ID
{
get { return _id; }
}
protected Coordinate _coord;
public Coordinate Coord
{
get { return _coord; }
}
protected string _eod;
public string EOD
{
get { return _eod; }
}
public bool Unexplored
{
get { return EOD == "Unexplored"; }
}
public bool Explored
{
get { return EOD == "Explored"; }
}
public bool Surveyed
{
get { return EOD == "Surveyed"; }
}
protected bool _initialized = false;
public bool Initialized
{
get { return _initialized; }
set { _initialized = value; }
}
protected List<HSystem> _wormholeLinks = new List<HSystem>();
public List<HSystem> WormholeLinks
{
get { return _wormholeLinks; }
}
public HSystem(string id, string name, string catalog, string x, string y, string z, string eod)
{
_id = id;
_name = name;
_catalogName = catalog is null ? name : catalog;
double nX = Convert.ToDouble(x, System.Globalization.CultureInfo.CreateSpecificCulture("en-US"));
double nY = Convert.ToDouble(y, System.Globalization.CultureInfo.CreateSpecificCulture("en-US"));
double nZ = Convert.ToDouble(z, System.Globalization.CultureInfo.CreateSpecificCulture("en-US"));
_coord = new Coordinate(nX, nY, nZ);
_eod = eod;
}
public void AddCelestialBody(CelestialBody celestialBody)
{
_celestialBodies.Add(celestialBody.ID, celestialBody);
celestialBody.HostSystem = this;
}
public void AddWormholeLink(HSystem destination)
{
if (destination is null || destination == this)
return;
if (!_wormholeLinks.Contains(destination))
_wormholeLinks.Add(destination);
}
public Dictionary<ResourceType, Resource> BestResources(bool excludeUncolonizable = false)
{
List<Dictionary<ResourceType, Resource>> resourceLists = new List<Dictionary<ResourceType, Resource>>();
foreach (CelestialBody body in _celestialBodies.Values)
{
foreach (Zone zone in body.ResourceZones)
{
resourceLists.Add(body.BestResources(excludeUncolonizable));
}
}
return resourceLists.SelectMany(dict => dict)
.ToLookup(pair => pair.Key, pair => pair.Value)
.ToDictionary(k => k.Key, v => v.Aggregate((i, j) => i.Quality > j.Quality ? i : j));
}
public int HabitbleCount()
{
return _celestialBodies.Values.Count(x => x.IsHabitable);
}
public override string ToString()
{
return _name;
}
//public override bool Equals(object obj)
//{
// HSystem system = obj as HSystem;
// if (system is null)
// return false;
// return Equals(system);
//}
//public bool Equals(HSystem system)
//{
// return _id == system.ID;
//}
}
}