001package com.fs.starfarer.api.impl.campaign.procgen; 002 003import java.util.HashMap; 004import java.util.HashSet; 005import java.util.Map; 006import java.util.Set; 007 008import org.json.JSONException; 009import org.json.JSONObject; 010 011public class ConditionGenDataSpec { 012 013 public static String NO_PICK_SUFFIX = "_no_pick"; 014 015 //id group rank order hazard reqSurvey xpMult requiresAll requiresAny requiresNotAny 016 //cat_barren rocky_unstable rocky_ice barren_desert lava lava_minor cat_frozen 017 //cryovolcanic irradiated cat_toxic toxic_cold terran terran-eccentric jungle water arid tundra desert 018 //multipliers >>> tectonic_activity extreme_tectonic_activity low_gravity high_gravity very_hot 019 private String id, group; 020 private float rank, order, hazard, xpMult; 021 private boolean requiresSurvey = false; 022 023 private Map<String, Float> multipliers = new HashMap<String, Float>(); 024 private Set<String> requiresAll = new HashSet<String>(); 025 private Set<String> requiresAny = new HashSet<String>(); 026 private Set<String> requiresNotAny = new HashSet<String>(); 027 028 public ConditionGenDataSpec(JSONObject row) throws JSONException { 029 id = row.getString("id"); 030 group = row.getString("group"); 031 rank = (float) row.optDouble("rank", 0); 032 order = (float) row.optDouble("order", 0); 033 hazard = (float) row.optDouble("hazard", 0); 034 xpMult = (float) row.optDouble("xpMult", 0); 035 036 requiresSurvey = row.optBoolean("reqSurvey", false); 037 038 039// for (Object o : Global.getSettings().getAllSpecs(CategoryGenDataSpec.class)) { 040// ConditionGenDataSpec spec = (ConditionGenDataSpec) o; 041// if (spec.getId().equals("ore_no_pick")) { 042// spec.getMultipliers().put("<your planet id>", 0f); 043// } 044// if (spec.getId().equals("ore_sparse")) { 045// spec.getMultipliers().put("<your planet id>", 4f); 046// } 047// if (spec.getId().equals("ore_moderate")) { 048// spec.getMultipliers().put("<your planet id>", 10f); 049// } 050// if (spec.getId().equals("ore_abundant")) { 051// spec.getMultipliers().put("<your planet id>", 5f); 052// } 053// if (spec.getId().equals("ore_rich")) { 054// spec.getMultipliers().put("<your planet id>", 2f); 055// } 056// if (spec.getId().equals("ore_ultrarich")) { 057// spec.getMultipliers().put("<your planet id>", 1f); 058// } 059// } 060 061 for (String key : JSONObject.getNames(row)) { 062 float mult = (float) row.optDouble(key, 1f); 063 //if (mult != 1) { 064 if (row.has(key) && !row.getString(key).isEmpty()) { 065 multipliers.put(key, mult); 066 } 067 } 068 069 String requiresAllStr = row.optString("requiresAll", null); 070 if (requiresAllStr != null) { 071 String [] split = requiresAllStr.split(","); 072 for (String condition : split) { 073 condition = condition.trim(); 074 if (condition.isEmpty()) continue; 075 addRequiresAll(condition); 076 } 077 } 078 079 String requiresAnyStr = row.optString("requiresAny", null); 080 if (requiresAnyStr != null) { 081 String [] split = requiresAnyStr.split(","); 082 for (String condition : split) { 083 condition = condition.trim(); 084 if (condition.isEmpty()) continue; 085 addRequiresAny(condition); 086 } 087 } 088 089 String requiresNotAny = row.optString("requiresNotAny", null); 090 if (requiresNotAny != null) { 091 String [] split = requiresNotAny.split(","); 092 for (String condition : split) { 093 condition = condition.trim(); 094 if (condition.isEmpty()) continue; 095 addRequiresNotAny(condition); 096 } 097 } 098 } 099 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}