001package com.fs.starfarer.api.impl.combat; 002 003import com.fs.starfarer.api.Global; 004import com.fs.starfarer.api.combat.FighterLaunchBayAPI; 005import com.fs.starfarer.api.combat.MutableShipStatsAPI; 006import com.fs.starfarer.api.combat.ShipAPI; 007import com.fs.starfarer.api.combat.ShipSystemAPI; 008import com.fs.starfarer.api.loading.FighterWingSpecAPI; 009 010public class ReserveWingStats extends BaseShipSystemScript { 011 012 public static String RD_NO_EXTRA_CRAFT = "rd_no_extra_craft"; 013 public static String RD_FORCE_EXTRA_CRAFT = "rd_force_extra_craft"; 014 015// public static float EXTRA_FIGHTER_DURATION = 15; 016// public static float RATE_COST = 0.25f; 017// public static float RATE_COST_1_BAY = 0.15f; 018 public static float EXTRA_FIGHTER_DURATION = 30; 019 public static float RATE_COST = 0f; 020 public static float RATE_COST_1_BAY = 0f; 021 022 public static float getRateCost(int bays) { 023 if (bays <= 1) return RATE_COST_1_BAY; 024 return RATE_COST; 025 } 026 027 public void apply(MutableShipStatsAPI stats, String id, State state, float effectLevel) { 028 ShipAPI ship = null; 029 if (stats.getEntity() instanceof ShipAPI) { 030 ship = (ShipAPI) stats.getEntity(); 031 } else { 032 return; 033 } 034 035 if (effectLevel == 1) { 036 037 //need to make this more balanced 038 //possibly don't count the "added" fighters to helping restore the replacement rate? 039 //also: need to adjust the AI to be more conservative using this 040 041 042 float minRate = Global.getSettings().getFloat("minFighterReplacementRate"); 043 044 int bays = ship.getLaunchBaysCopy().size(); 045 float cost = getRateCost(bays); 046 for (FighterLaunchBayAPI bay : ship.getLaunchBaysCopy()) { 047 if (bay.getWing() == null) continue; 048 049 float rate = Math.max(minRate, bay.getCurrRate() - cost); 050 bay.setCurrRate(rate); 051 052 bay.makeCurrentIntervalFast(); 053 FighterWingSpecAPI spec = bay.getWing().getSpec(); 054 055 int addForWing = getAdditionalFor(spec, bays); 056 int maxTotal = spec.getNumFighters() + addForWing; 057 int actualAdd = maxTotal - bay.getWing().getWingMembers().size(); 058 //int actualAdd = addForWing; 059 //actualAdd = Math.min(spec.getNumFighters(), actualAdd); 060 if (actualAdd > 0) { 061 bay.setFastReplacements(bay.getFastReplacements() + addForWing); 062 bay.setExtraDeployments(actualAdd); 063 bay.setExtraDeploymentLimit(maxTotal); 064 bay.setExtraDuration(EXTRA_FIGHTER_DURATION); 065 //bay.setExtraDuration(99999999999f); 066 } 067 } 068 } 069 } 070 071 public static int getAdditionalFor(FighterWingSpecAPI spec, int bays) { 072 //if (spec.isBomber() && !spec.hasTag(RD_FORCE_EXTRA_CRAFT)) return 0; 073 if (spec.hasTag(RD_NO_EXTRA_CRAFT)) return 0; 074 075 int size = spec.getNumFighters(); 076 if (true) return size; 077 078 if (bays == 1) { 079 return Math.max(size, 2); 080 } 081 082// if (size <= 3) return 1; 083// return 2; 084 if (size <= 3) return 1; 085 if (size <= 5) return 2; 086 return 3; 087 } 088 089 090 public void unapply(MutableShipStatsAPI stats, String id) { 091 } 092 093 094 095 public StatusData getStatusData(int index, State state, float effectLevel) { 096// if (index == 0) { 097// return new StatusData("deploying additional fighters", false); 098// } 099 return null; 100 } 101 102 103 @Override 104 public boolean isUsable(ShipSystemAPI system, ShipAPI ship) { 105 return true; 106 } 107 108 109 110} 111 112 113 114 115 116 117 118