001package com.fs.starfarer.api.impl.campaign.missions.hub;
002
003import java.util.Random;
004
005import com.fs.starfarer.api.Global;
006import com.fs.starfarer.api.campaign.RepLevel;
007import com.fs.starfarer.api.impl.campaign.ids.Tags;
008import com.fs.starfarer.api.loading.PersonMissionSpec;
009
010public class BaseHubMissionCreator implements HubMissionCreator {
011
012        protected int numCompleted = 0;
013        protected int numFailed = 0;
014        protected long seed;
015        protected transient Random genRandom = null;
016        
017        //protected Float requiredRep = null;
018        
019        protected transient PersonMissionSpec spec = null;
020        protected String specId = null;
021        
022        protected boolean wasAutoAdded = false;
023        protected boolean isActive = true;
024        
025        public BaseHubMissionCreator(PersonMissionSpec spec) {
026                this.spec = spec;
027                if (spec != null) {
028                        specId = spec.getMissionId();
029                }
030        }
031        
032        protected Object readResolve() {
033                spec = Global.getSettings().getMissionSpec(specId);
034                return this;
035        }
036        
037        public PersonMissionSpec getSpec() {
038                return spec;
039        }
040
041        public String getSpecId() {
042                return specId;
043        }
044
045        public HubMission createHubMission(MissionHub hub) {
046                return spec.createMission();
047        }
048        
049//      public void updateSeed() {
050//              seed = Misc.genRandomSeed();
051//      }
052        public void setSeed(long seed) {
053                this.seed = seed;
054        }
055        
056        public void updateRandom() {
057                genRandom = new Random(seed);
058        }
059        
060        public void incrCompleted() {
061                numCompleted++;
062        }
063
064        public int getNumCompleted() {
065                return numCompleted;
066        }
067
068        public void setNumCompleted(int numCompleted) {
069                this.numCompleted = numCompleted;
070        }
071        
072        public void incrFailed() {
073                numFailed++;
074        }
075
076        public int getNumFailed() {
077                return numFailed;
078        }
079
080        public void setNumFailed(int numFailed) {
081                this.numFailed = numFailed;
082        }
083        
084        
085        public float getFrequencyWeight() {
086                return spec.getFreq();
087        }
088
089        public float getWasShownTimeoutDuration() {
090                return 0f;
091        }
092        
093        public float getAcceptedTimeoutDuration() {
094                return spec.getMinTimeout() + (float) Math.random() * (spec.getMaxTimeout() - spec.getMinTimeout());
095        }
096        
097        public float getCompletedTimeoutDuration() {
098                return spec.getMinTimeout() + (float) Math.random() * (spec.getMaxTimeout() - spec.getMinTimeout());
099        }
100        
101        public float getFailedTimeoutDuration() {
102                return spec.getMinTimeout() + (float) Math.random() * (spec.getMaxTimeout() - spec.getMinTimeout());
103        }
104
105//      public float getAcceptedTimeoutDuration() {
106//              return 0f;
107//      }
108//      
109//      public float getCompletedTimeoutDuration() {
110//              return 30f + (float) Math.random() * 30f;
111//      }
112//      
113//      public float getFailedTimeoutDuration() {
114//              return 30f + (float) Math.random() * 30f;
115//      }
116
117        public boolean isPriority() {
118                return spec.hasTag(Tags.MISSION_PRIORITY);
119        }
120        
121        public boolean matchesRep(float rep) {
122                RepLevel level = RepLevel.getLevelFor(rep);
123                if (spec.getMinRep() != null) {
124                        if (!level.isAtWorst(spec.getMinRep())) return false; 
125                }
126                if (spec.getMaxRep() != null) {
127                        if (!level.isAtBest(spec.getMaxRep())) return false; 
128                }
129                return true;
130        }
131        
132//      public float getRequiredRep() {
133//              //return 0f;
134//              if (requiredRep != null) return requiredRep;
135//              return -RepLevel.INHOSPITABLE.getMax() + 0.01f;
136//      }
137
138        public Random getGenRandom() {
139                return genRandom;
140        }
141
142        public boolean wasAutoAdded() {
143                return wasAutoAdded;
144        }
145
146        public void setWasAutoAdded(boolean wasAutoAdded) {
147                this.wasAutoAdded = wasAutoAdded;
148        }
149
150        public boolean isActive() {
151                return isActive;
152        }
153
154        public void setActive(boolean isActive) {
155                this.isActive = isActive;
156        }
157
158}