001package com.fs.starfarer.api.impl.campaign.procgen;
002
003import java.awt.Color;
004import java.util.HashMap;
005import java.util.HashSet;
006import java.util.Map;
007import java.util.Set;
008
009import org.json.JSONException;
010import org.json.JSONObject;
011
012public class TerrainGenDataSpec implements EntityGenDataSpec {
013        //id    category        frequency       habOffsetMin    habOffsetMax    minRadius       maxRadius       minColor        maxColor
014        private String id, category;
015        private float frequency, habOffsetMin, habOffsetMax, minRadius, maxRadius;
016        private float probOrbits, minOrbits, maxOrbits;
017        private Color minColor, maxColor;
018        
019        private float habOffsetYOUNG, habOffsetAVERAGE, habOffsetOLD;
020        
021        private Map<String, Float> multipliers = new HashMap<String, Float>();
022        private Set<String> tags = new HashSet<String>();
023        
024        public TerrainGenDataSpec(JSONObject row) throws JSONException {
025                id = row.getString("id");
026                category = row.getString("category");
027                frequency = (float) row.getDouble("frequency");
028                habOffsetMin = (float) row.optDouble("habOffsetMin", -1000);
029                habOffsetMax = (float) row.optDouble("habOffsetMax", 1000);
030                minRadius = (float) row.optDouble("minRadius", 0);
031                maxRadius = (float) row.optDouble("maxRadius", 0);
032                
033                habOffsetYOUNG = (float) row.optDouble("habOffsetYOUNG", 0);
034                habOffsetAVERAGE = (float) row.optDouble("habOffsetAVERAGE", 0);
035                habOffsetOLD = (float) row.optDouble("habOffsetOLD", 0);
036                
037                probOrbits = (float) row.optDouble("probOrbits", 0);
038                minOrbits = (float) row.optDouble("minOrbits", 0);
039                maxOrbits = (float) row.optDouble("maxOrbits", 0);
040                
041                for (String key : JSONObject.getNames(row)) {
042                        float frequency = (float) row.optDouble(key, 1f);
043                        if (frequency != 1) {
044                                multipliers.put(key, frequency);
045                        }
046                }
047                
048                String tags = row.optString("tags", null);
049                if (tags != null) {
050                        String [] split = tags.split(",");
051                        for (String tag : split) {
052                                tag = tag.trim();
053                                if (tag.isEmpty()) continue;
054                                addTag(tag);
055                        }
056                }
057                
058                minColor = StarGenDataSpec.parseColor(row.optString("minColor", null) + " 255", " ");
059                maxColor = StarGenDataSpec.parseColor(row.optString("maxColor", null) + " 255", " ");
060        }
061        
062        public String toString() {
063                return getId();
064        }
065
066        public String getCategory() {
067                return category;
068        }
069
070        public float getFrequency() {
071                return frequency;
072        }
073        
074        public String getId() {
075                return id;
076        }
077
078        public float getHabOffsetMin() {
079                return habOffsetMin;
080        }
081
082        public float getHabOffsetMax() {
083                return habOffsetMax;
084        }
085
086        public float getMinRadius() {
087                return minRadius;
088        }
089
090        public float getMaxRadius() {
091                return maxRadius;
092        }
093
094        public Color getMinColor() {
095                return minColor;
096        }
097
098        public Color getMaxColor() {
099                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