Starsector API
Loading...
Searching...
No Matches
ConditionGenDataSpec.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.procgen;
2
3import java.util.HashMap;
4import java.util.HashSet;
5import java.util.Map;
6import java.util.Set;
7
8import org.json.JSONException;
9import org.json.JSONObject;
10
12
13 public static String NO_PICK_SUFFIX = "_no_pick";
14
15 //id group rank order hazard reqSurvey xpMult requiresAll requiresAny requiresNotAny
16 //cat_barren rocky_unstable rocky_ice barren_desert lava lava_minor cat_frozen
17 //cryovolcanic irradiated cat_toxic toxic_cold terran terran-eccentric jungle water arid tundra desert
18 //multipliers >>> tectonic_activity extreme_tectonic_activity low_gravity high_gravity very_hot
19 private String id, group;
20 private float rank, order, hazard, xpMult;
21 private boolean requiresSurvey = false;
22
23 private Map<String, Float> multipliers = new HashMap<String, Float>();
24 private Set<String> requiresAll = new HashSet<String>();
25 private Set<String> requiresAny = new HashSet<String>();
26 private Set<String> requiresNotAny = new HashSet<String>();
27
28 public ConditionGenDataSpec(JSONObject row) throws JSONException {
29 id = row.getString("id");
30 group = row.getString("group");
31 rank = (float) row.optDouble("rank", 0);
32 order = (float) row.optDouble("order", 0);
33 hazard = (float) row.optDouble("hazard", 0);
34 xpMult = (float) row.optDouble("xpMult", 0);
35
36 requiresSurvey = row.optBoolean("reqSurvey", false);
37
38
39// for (Object o : Global.getSettings().getAllSpecs(CategoryGenDataSpec.class)) {
40// ConditionGenDataSpec spec = (ConditionGenDataSpec) o;
41// if (spec.getId().equals("ore_no_pick")) {
42// spec.getMultipliers().put("<your planet id>", 0f);
43// }
44// if (spec.getId().equals("ore_sparse")) {
45// spec.getMultipliers().put("<your planet id>", 4f);
46// }
47// if (spec.getId().equals("ore_moderate")) {
48// spec.getMultipliers().put("<your planet id>", 10f);
49// }
50// if (spec.getId().equals("ore_abundant")) {
51// spec.getMultipliers().put("<your planet id>", 5f);
52// }
53// if (spec.getId().equals("ore_rich")) {
54// spec.getMultipliers().put("<your planet id>", 2f);
55// }
56// if (spec.getId().equals("ore_ultrarich")) {
57// spec.getMultipliers().put("<your planet id>", 1f);
58// }
59// }
60
61 for (String key : JSONObject.getNames(row)) {
62 float mult = (float) row.optDouble(key, 1f);
63 //if (mult != 1) {
64 if (row.has(key) && !row.getString(key).isEmpty()) {
65 multipliers.put(key, mult);
66 }
67 }
68
69 String requiresAllStr = row.optString("requiresAll", null);
70 if (requiresAllStr != null) {
71 String [] split = requiresAllStr.split(",");
72 for (String condition : split) {
73 condition = condition.trim();
74 if (condition.isEmpty()) continue;
75 addRequiresAll(condition);
76 }
77 }
78
79 String requiresAnyStr = row.optString("requiresAny", null);
80 if (requiresAnyStr != null) {
81 String [] split = requiresAnyStr.split(",");
82 for (String condition : split) {
83 condition = condition.trim();
84 if (condition.isEmpty()) continue;
85 addRequiresAny(condition);
86 }
87 }
88
89 String requiresNotAny = row.optString("requiresNotAny", null);
90 if (requiresNotAny != null) {
91 String [] split = requiresNotAny.split(",");
92 for (String condition : split) {
93 condition = condition.trim();
94 if (condition.isEmpty()) continue;
95 addRequiresNotAny(condition);
96 }
97 }
98 }
99
100
101 public float getXpMult() {
102 return xpMult;
103 }
104
105 public void setXpMult(float xpMult) {
106 this.xpMult = xpMult;
107 }
108
109
110 public float getMultiplier(String key) {
111 if (!multipliers.containsKey(key)) return 1f;
112 return multipliers.get(key);
113 }
114
115 public boolean hasMultiplier(String key) {
116 return multipliers.containsKey(key);
117 }
118
119 public Set<String> getRequiresAll() {
120 return requiresAll;
121 }
122
123 public void addRequiresAll(String condition) {
124 requiresAll.add(condition);
125 }
126
127 public boolean requiresAllContains(String condition) {
128 return requiresAll.contains(condition);
129 }
130
131 public Set<String> getRequiresAny() {
132 return requiresAny;
133 }
134
135 public void addRequiresAny(String condition) {
136 requiresAny.add(condition);
137 }
138
139 public boolean requiresAnyContains(String condition) {
140 return requiresAny.contains(condition);
141 }
142 public Set<String> getRequiresNotAny() {
143 return requiresNotAny;
144 }
145
146 public void addRequiresNotAny(String condition) {
147 requiresNotAny.add(condition);
148 }
149
150 public boolean requiresNotAnyContains(String condition) {
151 return requiresNotAny.contains(condition);
152 }
153
154 public Map<String, Float> getMultipliers() {
155 return multipliers;
156 }
157
158
159 public String getId() {
160 return id;
161 }
162
163
164 public void setId(String id) {
165 this.id = id;
166 }
167
168
169 public String getGroup() {
170 return group;
171 }
172
173
174 public void setGroup(String group) {
175 this.group = group;
176 }
177
178
179 public float getRank() {
180 return rank;
181 }
182
183 public void setRank(float rank) {
184 this.rank = rank;
185 }
186
187
188 public float getOrder() {
189 return order;
190 }
191
192 public void setOrder(float order) {
193 this.order = order;
194 }
195
196
197 public boolean isRequiresSurvey() {
198 return requiresSurvey;
199 }
200
201 public void setRequiresSurvey(boolean requiresSurvey) {
202 this.requiresSurvey = requiresSurvey;
203 }
204
205 public float getHazard() {
206 return hazard;
207 }
208
209 public void setHazard(float hazard) {
210 this.hazard = hazard;
211 }
212
213}