001package com.fs.starfarer.api.impl.hullmods;
002
003import com.fs.starfarer.api.GameState;
004import com.fs.starfarer.api.Global;
005import com.fs.starfarer.api.combat.BaseHullMod;
006import com.fs.starfarer.api.combat.FighterLaunchBayAPI;
007import com.fs.starfarer.api.combat.MutableShipStatsAPI;
008import com.fs.starfarer.api.combat.ShipAPI;
009import com.fs.starfarer.api.combat.ShipAPI.HullSize;
010import com.fs.starfarer.api.combat.listeners.AdvanceableListener;
011import com.fs.starfarer.api.loading.FighterWingSpecAPI;
012
013public class BDeck extends BaseHullMod {
014
015        public static float REPLACEMENT_RATE_THRESHOLD = 0.4f;
016        public static float REPLACEMENT_RATE_RESET = 1f;
017        public static float CR_COST_MULT = 0f;
018        
019        
020        
021        public void applyEffectsBeforeShipCreation(HullSize hullSize, MutableShipStatsAPI stats, String id) {
022
023        }
024        
025        @Override
026        public void advanceInCombat(ShipAPI ship, float amount) {
027                super.advanceInCombat(ship, amount);
028        }
029
030        @Override
031        public void applyEffectsAfterShipCreation(ShipAPI ship, String id) {
032                ship.addListener(new BDeckListener(ship));
033        }
034        
035        public static Object STATUS_KEY = new Object();
036        
037        public static class BDeckListener implements AdvanceableListener {
038                protected ShipAPI ship;
039                protected boolean fired = false;
040                public BDeckListener(ShipAPI ship) {
041                        this.ship = ship;
042                }
043
044                public void advance(float amount) {
045                        float cr = ship.getCurrentCR();
046                        float crCost = ship.getDeployCost() * CR_COST_MULT;
047                        
048                        if (!fired && cr >= crCost) {
049                                if (ship.getSharedFighterReplacementRate() <= REPLACEMENT_RATE_THRESHOLD) {
050                                        fired = true;
051                                        
052                                        for (FighterLaunchBayAPI bay : ship.getLaunchBaysCopy()) {
053                                                if (bay.getWing() == null) continue;
054                                                
055                                                float rate = REPLACEMENT_RATE_RESET;
056                                                bay.setCurrRate(rate);
057                                                
058                                                bay.makeCurrentIntervalFast();
059                                                FighterWingSpecAPI spec = bay.getWing().getSpec();
060                                                
061                                                int maxTotal = spec.getNumFighters();
062                                                int actualAdd = maxTotal - bay.getWing().getWingMembers().size();
063                                                if (actualAdd > 0) {
064                                                        bay.setFastReplacements(bay.getFastReplacements() + actualAdd);
065//                                                      bay.setExtraDeployments(actualAdd);
066//                                                      bay.setExtraDeploymentLimit(maxTotal);
067//                                                      bay.setExtraDuration(EXTRA_FIGHTER_DURATION);
068                                                }
069                                                
070                                                if (crCost > 0) {
071                                                        ship.setCurrentCR(ship.getCurrentCR() - crCost);
072                                                }
073                                        }
074                                }
075                        }
076                        
077                        if (Global.getCurrentState() == GameState.COMBAT &&
078                                        Global.getCombatEngine() != null && Global.getCombatEngine().getPlayerShip() == ship) {
079
080                                String status = "ON STANDBY";
081                                boolean penalty = false;
082                                if (fired) status = "OPERATIONAL";
083                                if (!fired && cr < crCost) {
084                                        status = "NOT READY";
085                                        penalty = true;
086                                }
087                                Global.getCombatEngine().maintainStatusForPlayerShip(STATUS_KEY,
088                                                Global.getSettings().getSpriteName("ui", "icon_tactical_bdeck"),
089                                                "B-DECK", status, penalty);
090                        }
091                }
092                
093        }
094        
095        
096        public String getDescriptionParam(int index, HullSize hullSize) {
097                if (index == 0) {
098                        return (int) Math.round(REPLACEMENT_RATE_THRESHOLD * 100f) + "%";
099                }
100                if (index == 1) {
101                        return (int) Math.round(REPLACEMENT_RATE_RESET * 100f) + "%";
102                }
103                return null;
104        }
105//      
106//      @Override
107//      public boolean shouldAddDescriptionToTooltip(HullSize hullSize, ShipAPI ship, boolean isForModSpec) {
108//              return false;
109//      }
110//
111//      @Override
112//      public void addPostDescriptionSection(TooltipMakerAPI tooltip, HullSize hullSize, ShipAPI ship, float width, boolean isForModSpec) {
113//              float pad = 3f;
114//              float opad = 10f;
115//              Color h = Misc.getHighlightColor();
116//              Color bad = Misc.getNegativeHighlightColor();
117//              
118//              
119//              if (!Misc.isAutomated(ship)) {
120//                      tooltip.addPara("Originally designed by the Tri-Tachyon Corporation for use on its combat droneships, "
121//                                      + "the coherence field strengh has to be dialed down to allow operation on crewed vessels.", opad);
122//                      tooltip.addPara("Increases the base range of all non-beam Energy and Hybrid weapons by %s.", opad, h,
123//                                      "" + (int)CREWED_RANGE_BONUS);
124//                      tooltip.addPara("The coherence field is unstable under combat conditions, with stresses on the hull "
125//                                      + "resulting in spot failures that release bursts of lethal radiation. "
126//                                      + "Crew casualties in combat are increased by %s.", opad, h,
127//                                      "" + (int) CREW_CASUALTIES + "%");
128//              } else {
129//                      tooltip.addPara("Increases the base range of all non-beam Energy and Hybrid weapons by %s.", opad, h,
130//                              "" + (int)RANGE_BONUS);
131//              }
132//              
133//              tooltip.addSectionHeading("Interactions with other modifiers", Alignment.MID, opad);
134//              tooltip.addPara("Since the base range is increased, this range modifier"
135//                              + " - unlike most other flat modifiers in the game - "
136//                              + "is increased by percentage modifiers from other hullmods and skills.", opad);
137//      }
138//      
139////    @Override
140////    public boolean isApplicableToShip(ShipAPI ship) {
141////            return getUnapplicableReason(ship) == null;
142////    }
143////    
144////    public String getUnapplicableReason(ShipAPI ship) {
145////            if (ship != null && 
146////                            ship.getHullSize() != HullSize.CAPITAL_SHIP && 
147////                            ship.getHullSize() != HullSize.DESTROYER && 
148////                            ship.getHullSize() != HullSize.CRUISER) {
149////                    return "Can only be installed on destroyer-class hulls and larger";
150////            }
151////            return null;
152////    }
153        
154}
155
156
157
158
159
160
161
162
163