001package com.fs.starfarer.api.impl.campaign.intel.group;
002
003import java.awt.Color;
004import java.util.List;
005
006import com.fs.starfarer.api.Global;
007import com.fs.starfarer.api.campaign.FactionAPI;
008import com.fs.starfarer.api.campaign.StarSystemAPI;
009import com.fs.starfarer.api.campaign.econ.MarketAPI;
010import com.fs.starfarer.api.impl.campaign.ids.Conditions;
011import com.fs.starfarer.api.impl.campaign.intel.group.FGBlockadeAction.FGBlockadeParams;
012import com.fs.starfarer.api.ui.Alignment;
013import com.fs.starfarer.api.ui.LabelAPI;
014import com.fs.starfarer.api.ui.TooltipMakerAPI;
015import com.fs.starfarer.api.util.IntervalUtil;
016import com.fs.starfarer.api.util.Misc;
017
018public class BlockadeFGI extends GenericRaidFGI {
019
020        protected FGBlockadeParams blockadeParams;
021        protected IntervalUtil interval = new IntervalUtil(0.1f, 0.3f);
022        
023        public BlockadeFGI(GenericRaidParams params, FGBlockadeParams blockadeParams) {
024                super(null);
025                if (params.noun == null) {
026                        params.noun = "blockade";
027                }
028                if (params.forcesNoun == null) {
029                        params.forcesNoun = "blockading forces";
030                }
031                
032                
033                this.params = params;
034                this.blockadeParams = blockadeParams;
035                setRandom(params.random);
036                
037                initActions();
038        }
039        
040        protected GenericPayloadAction createPayloadAction() {
041                return new FGBlockadeAction(blockadeParams, params.payloadDays);
042        }
043        
044        public float getAccessibilityPenalty() {
045                int str = getRelativeFGStrength(getTargetSystem());
046                if (str < 0) {
047                        return 0f;
048                } else if (str == 0) {
049                        return blockadeParams.accessibilityPenalty * 0.5f;
050                } else {
051                        return blockadeParams.accessibilityPenalty;
052                }
053        }
054        
055        
056        public void advance(float amount) {
057                super.advance(amount);
058                
059                if (isEnded() || isEnding() || isAborted() || isSpawning()) return;
060                
061                float days = Misc.getDays(amount);
062                interval.advance(days);
063                if (interval.intervalElapsed()) {
064                        
065                        if (isCurrent(PAYLOAD_ACTION)) {
066                                applyBlockadeCondition();
067                        } else {
068                                unapplyBlockadeCondition();
069                        }
070                        
071                        periodicUpdate();
072                }
073        }
074        
075        protected void periodicUpdate() {
076                
077        }
078        
079        protected void applyBlockadeCondition() {
080                int str = getRelativeFGStrength(getTargetSystem());
081                if (str < 0) {
082                        unapplyBlockadeCondition();
083                        return;
084                }
085                
086                for (MarketAPI market : Misc.getMarketsInLocation(getTargetSystem(), blockadeParams.targetFaction)) {
087                        if (!market.hasCondition(Conditions.BLOCKADED)) {
088                                market.addCondition(Conditions.BLOCKADED, this);
089                        }
090                }
091        }
092        
093        protected void unapplyBlockadeCondition() {
094                for (MarketAPI market : Misc.getMarketsInLocation(getTargetSystem(), blockadeParams.targetFaction)) {
095                        market.removeCondition(Conditions.BLOCKADED);
096                }
097        }
098        
099
100        @Override
101        protected void notifyEnding() {
102                super.notifyEnding();
103                
104                unapplyBlockadeCondition();
105        }
106
107        @Override
108        protected void addBasicDescription(TooltipMakerAPI info, float width, float height, float opad) {
109                info.addImage(getFaction().getLogo(), width, 128, opad);
110                
111                StarSystemAPI system = raidAction.getWhere();
112                
113                String noun = getNoun();
114                
115                info.addPara(Misc.ucFirst(faction.getPersonNamePrefixAOrAn()) + " %s " + noun + " " + getOfString() + " "
116                                + "the " + system.getNameWithLowercaseTypeShort() + ".", opad,
117                                faction.getBaseUIColor(), faction.getPersonNamePrefix());
118        }
119        
120        protected String getOfString() {
121                return "of";
122        }
123        
124        protected void addAssessmentSection(TooltipMakerAPI info, float width, float height, float opad) {
125                Color h = Misc.getHighlightColor();
126                Color bad = Misc.getNegativeHighlightColor();
127                
128                FactionAPI faction = getFaction();
129                
130                List<MarketAPI> targets = params.raidParams.allowedTargets;
131                
132                String noun = getNoun();
133                String forcesNoun = getForcesNoun();
134                if (!isEnding() && !isSucceeded() && !isFailed()) {
135                        
136                        FactionAPI other = Global.getSector().getFaction(blockadeParams.targetFaction);
137                        boolean hostile = getFaction().isHostileTo(blockadeParams.targetFaction);
138                        
139                        info.addSectionHeading("Assessment", 
140                                                        faction.getBaseUIColor(), faction.getDarkUIColor(), Alignment.MID, opad);
141                        
142                        boolean started = isCurrent(PAYLOAD_ACTION);
143                        float remaining = getETAUntil(PAYLOAD_ACTION, true) - getETAUntil(TRAVEL_ACTION, true);
144                        if (remaining > 0 && remaining < 1) remaining = 1;
145                        String days = (int)remaining == 1 ? "day" : "days";
146                        
147                        if (started) days = "more " + days;
148                        
149                        LabelAPI label = info.addPara("The " + noun + " will last for approximately %s " + days
150                                        + ", causing a %s accessibility penalty "
151                                        + "for all %s colonies in the " + 
152                                        getTargetSystem().getNameWithLowercaseTypeShort() + ".", opad, h,
153                                        "" + (int) remaining,
154                                        "" + (int) Math.round(blockadeParams.accessibilityPenalty * 100f) + "%",
155                                        other.getPersonNamePrefix());
156                        label.setHighlight("" + (int) remaining, 
157                                                           "" + (int) Math.round(blockadeParams.accessibilityPenalty * 100f) + "%",
158                                                           other.getPersonNamePrefix());
159                        label.setHighlightColors(h, h, other.getBaseUIColor());
160                        
161                        if (!hostile) {
162                                info.addPara("The " + forcesNoun + " are not nominally hostile, but will harass shipping and "
163                                                + "attempt to maintain control over the system's jump-points.", opad, 
164                                                Misc.getHighlightColor(), "not nominally hostile");
165                        } else {
166                                info.addPara("The " + forcesNoun + " are actively hostile, but will not directly attack colonies "
167                                                + "in the system and will instead "
168                                                + "attempt to maintain control over the system's jump-points. If a defended planet "
169                                                + "happens to be near a jump-point, however, the situation is apt to get hot very quickly.", 
170                                                opad, Misc.getNegativeHighlightColor(), "actively hostile");
171                        }
172                        
173                        addStrengthDesc(info, opad, getTargetSystem(), forcesNoun, 
174                                        "the " + noun + " is unlikely to be effective",
175                                        "the " + noun + " is likely to only be partially effective",
176                                        "the " + noun + " is likely to be fully effective");
177                        
178                        addPostAssessmentSection(info, width, height, opad);
179                }
180        }
181        
182        protected void addPostAssessmentSection(TooltipMakerAPI info, float width, float height, float opad) {
183                
184        }
185
186        public FGBlockadeParams getBlockadeParams() {
187                return blockadeParams;
188        }
189        
190}
191
192
193
194
195
196
197
198
199