Starsector API
Loading...
Searching...
No Matches
TerrainGenDataSpec.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.procgen;
2
3import java.awt.Color;
4import java.util.HashMap;
5import java.util.HashSet;
6import java.util.Map;
7import java.util.Set;
8
9import org.json.JSONException;
10import org.json.JSONObject;
11
12public class TerrainGenDataSpec implements EntityGenDataSpec {
13 //id category frequency habOffsetMin habOffsetMax minRadius maxRadius minColor maxColor
14 private String id, category;
15 private float frequency, habOffsetMin, habOffsetMax, minRadius, maxRadius;
16 private float probOrbits, minOrbits, maxOrbits;
17 private Color minColor, maxColor;
18
19 private float habOffsetYOUNG, habOffsetAVERAGE, habOffsetOLD;
20
21 private Map<String, Float> multipliers = new HashMap<String, Float>();
22 private Set<String> tags = new HashSet<String>();
23
24 public TerrainGenDataSpec(JSONObject row) throws JSONException {
25 id = row.getString("id");
26 category = row.getString("category");
27 frequency = (float) row.getDouble("frequency");
28 habOffsetMin = (float) row.optDouble("habOffsetMin", -1000);
29 habOffsetMax = (float) row.optDouble("habOffsetMax", 1000);
30 minRadius = (float) row.optDouble("minRadius", 0);
31 maxRadius = (float) row.optDouble("maxRadius", 0);
32
33 habOffsetYOUNG = (float) row.optDouble("habOffsetYOUNG", 0);
34 habOffsetAVERAGE = (float) row.optDouble("habOffsetAVERAGE", 0);
35 habOffsetOLD = (float) row.optDouble("habOffsetOLD", 0);
36
37 probOrbits = (float) row.optDouble("probOrbits", 0);
38 minOrbits = (float) row.optDouble("minOrbits", 0);
39 maxOrbits = (float) row.optDouble("maxOrbits", 0);
40
41 for (String key : JSONObject.getNames(row)) {
42 float frequency = (float) row.optDouble(key, 1f);
43 if (frequency != 1) {
44 multipliers.put(key, frequency);
45 }
46 }
47
48 String tags = row.optString("tags", null);
49 if (tags != null) {
50 String [] split = tags.split(",");
51 for (String tag : split) {
52 tag = tag.trim();
53 if (tag.isEmpty()) continue;
54 addTag(tag);
55 }
56 }
57
58 minColor = StarGenDataSpec.parseColor(row.optString("minColor", null) + " 255", " ");
59 maxColor = StarGenDataSpec.parseColor(row.optString("maxColor", null) + " 255", " ");
60 }
61
62 public String toString() {
63 return getId();
64 }
65
66 public String getCategory() {
67 return category;
68 }
69
70 public float getFrequency() {
71 return frequency;
72 }
73
74 public String getId() {
75 return id;
76 }
77
78 public float getHabOffsetMin() {
79 return habOffsetMin;
80 }
81
82 public float getHabOffsetMax() {
83 return habOffsetMax;
84 }
85
86 public float getMinRadius() {
87 return minRadius;
88 }
89
90 public float getMaxRadius() {
91 return maxRadius;
92 }
93
94 public Color getMinColor() {
95 return minColor;
96 }
97
98 public Color getMaxColor() {
99 return maxColor;
100 }
101
102 public float getMultiplier(String key) {
103 if (!multipliers.containsKey(key)) return 1f;
104 return multipliers.get(key);
105 }
106
107 public Set<String> getTags() {
108 return tags;
109 }
110
111 public void addTag(String tag) {
112 tags.add(tag);
113 }
114
115 public boolean hasTag(String tag) {
116 return tags.contains(tag);
117 }
118
119 public Map<String, Float> getMultipliers() {
120 return multipliers;
121 }
122
123 public float getProbOrbits() {
124 return probOrbits;
125 }
126
127 public float getMinOrbits() {
128 return minOrbits;
129 }
130
131 public float getMaxOrbits() {
132 return maxOrbits;
133 }
134
135 public float getHabOffsetYOUNG() {
136 return habOffsetYOUNG;
137 }
138
139 public float getHabOffsetAVERAGE() {
140 return habOffsetAVERAGE;
141 }
142
143 public float getHabOffsetOLD() {
144 return habOffsetOLD;
145 }
146
147
148}
149
150
151