1package com.fs.starfarer.api.impl.campaign.submarkets;
4import java.util.Random;
6import org.apache.log4j.Logger;
8import com.fs.starfarer.api.Global;
9import com.fs.starfarer.api.campaign.CampaignUIAPI.CoreUITradeMode;
10import com.fs.starfarer.api.campaign.CargoStackAPI;
11import com.fs.starfarer.api.campaign.CoreUIAPI;
12import com.fs.starfarer.api.campaign.FactionDoctrineAPI;
13import com.fs.starfarer.api.campaign.RepLevel;
14import com.fs.starfarer.api.campaign.econ.CommodityOnMarketAPI;
15import com.fs.starfarer.api.campaign.econ.SubmarketAPI;
16import com.fs.starfarer.api.combat.ShipAPI.HullSize;
17import com.fs.starfarer.api.fleet.FleetMemberAPI;
18import com.fs.starfarer.api.impl.campaign.ids.Commodities;
19import com.fs.starfarer.api.impl.campaign.ids.Factions;
20import com.fs.starfarer.api.loading.FighterWingSpecAPI;
21import com.fs.starfarer.api.loading.HullModSpecAPI;
22import com.fs.starfarer.api.loading.WeaponSpecAPI;
23import com.fs.starfarer.api.util.Highlights;
24import com.fs.starfarer.api.util.Misc;
44 int weapons = 7 + Math.max(0,
market.getSize() - 1) * 2;
45 int fighters = 2 + Math.max(0,
market.getSize() - 3);
50 float stability =
market.getStabilityValue();
51 float sMult = Math.max(0.1f, stability / 10f);
52 getCargo().getMothballedShips().clear();
57 int size =
submarket.getFaction().getDoctrine().getShipSize();
61 }
else if (stability <= 6) {
66 if (size > 5) size = 5;
68 FactionDoctrineAPI doctrineOverride =
submarket.getFaction().getDoctrine().clone();
69 doctrineOverride.setShipSize(size);
93 getCargo().getMothballedShips().clear();
101 if (
submarket.getFaction().getId().equals(Factions.LUDDIC_CHURCH)) {
102 return "Knights of Ludd";
104 return Misc.ucFirst(
submarket.getFaction().getPersonNamePrefix()) +
"\n" +
"Military";
108 if (!
submarket.getFaction().getCustomBoolean(Factions.CUSTOM_OFFERS_COMMISSIONS))
return false;
110 if (req.isAtWorst(RepLevel.WELCOMING))
return true;
115 return submarket.getFaction().getId().equals(Misc.getCommissionFactionId());
120 if (Commodities.CREW.equals(com.getId()))
return true;
121 return com.getCommodity().hasTag(Commodities.TAG_MILITARY);
137 limit *= 0.9f + 0.2f * random.nextFloat();
139 float sm =
market.getStabilityValue() / 10f;
140 limit *= (0.25f + 0.75f * sm);
142 if (limit < 0) limit = 0;
149 boolean illegal =
market.isIllegal(commodityId);
150 RepLevel req = getRequiredLevelAssumingLegal(commodityId, action);
152 if (req ==
null)
return illegal;
155 boolean legal = level.isAtWorst(req);
163 if (stack.isCommodityStack()) {
167 RepLevel req = getRequiredLevelAssumingLegal(stack, action);
168 if (req ==
null)
return false;
172 boolean legal = level.isAtWorst(req);
181 RepLevel req = getRequiredLevelAssumingLegal(stack, action);
186 submarket.getFaction().getDisplayName() +
" - " + req.getDisplayName().toLowerCase() +
", " +
190 submarket.getFaction().getDisplayName() +
" - " + req.getDisplayName().toLowerCase();
193 return "Illegal to trade in " + stack.getDisplayName() +
" here";
198 RepLevel req = getRequiredLevelAssumingLegal(stack, action);
200 Color c = Misc.getNegativeHighlightColor();
201 Highlights h =
new Highlights();
203 if (!level.isAtWorst(req)) {
204 h.append(
submarket.getFaction().getDisplayName() +
" - " + req.getDisplayName().toLowerCase(), c);
207 h.append(
"commission", c);
214 private RepLevel getRequiredLevelAssumingLegal(CargoStackAPI stack, TransferAction action) {
216 if (stack.isWeaponStack()) {
217 WeaponSpecAPI spec = stack.getWeaponSpecIfWeapon();
218 tier = spec.getTier();
219 }
else if (stack.isModSpecStack()) {
220 HullModSpecAPI spec = stack.getHullModSpecIfHullMod();
221 tier = spec.getTier();
222 }
else if (stack.isFighterWingStack()) {
223 FighterWingSpecAPI spec = stack.getFighterWingSpecIfWing();
224 tier = spec.getTier();
228 if (action == TransferAction.PLAYER_BUY) {
230 case 0:
return RepLevel.FAVORABLE;
231 case 1:
return RepLevel.WELCOMING;
232 case 2:
return RepLevel.FRIENDLY;
233 case 3:
return RepLevel.COOPERATIVE;
236 return RepLevel.VENGEFUL;
239 if (!stack.isCommodityStack())
return null;
240 return getRequiredLevelAssumingLegal((String) stack.getData(), action);
243 private RepLevel getRequiredLevelAssumingLegal(String commodityId, TransferAction action) {
244 if (action == TransferAction.PLAYER_SELL) {
246 return RepLevel.VENGEFUL;
249 CommodityOnMarketAPI com =
market.getCommodityData(commodityId);
250 boolean isMilitary = com.getCommodity().getTags().contains(Commodities.TAG_MILITARY);
252 if (com.isPersonnel()) {
253 return RepLevel.COOPERATIVE;
255 return RepLevel.FAVORABLE;
261 if (action == TransferAction.PLAYER_SELL && Misc.isAutomated(member)) {
265 RepLevel req = getRequiredLevelAssumingLegal(member, action);
266 if (req ==
null)
return false;
270 boolean legal = level.isAtWorst(req);
279 RepLevel req = getRequiredLevelAssumingLegal(member, action);
283 if (!level.isAtWorst(req)) {
284 str +=
"Req: " +
submarket.getFaction().getDisplayName() +
" - " + req.getDisplayName().toLowerCase();
287 if (!str.isEmpty()) str +=
"\n";
288 str +=
"Req: " +
submarket.getFaction().getDisplayName() +
" - " +
"commission";
300 if (action == TransferAction.PLAYER_BUY) {
301 return "Illegal to buy";
303 return "Illegal to sell";
310 RepLevel req = getRequiredLevelAssumingLegal(member, action);
312 Color c = Misc.getNegativeHighlightColor();
313 Highlights h =
new Highlights();
315 if (!level.isAtWorst(req)) {
316 h.append(
"Req: " +
submarket.getFaction().getDisplayName() +
" - " + req.getDisplayName().toLowerCase(), c);
319 h.append(
"Req: " +
submarket.getFaction().getDisplayName() +
" - commission", c);
326 private RepLevel getRequiredLevelAssumingLegal(FleetMemberAPI member, TransferAction action) {
327 if (action == TransferAction.PLAYER_BUY) {
328 int fp = member.getFleetPointCost();
329 HullSize size = member.getHullSpec().getHullSize();
331 if (size == HullSize.CAPITAL_SHIP || fp > 15)
return RepLevel.COOPERATIVE;
332 if (size == HullSize.CRUISER || fp > 10)
return RepLevel.FRIENDLY;
333 if (size == HullSize.DESTROYER || fp > 5)
return RepLevel.WELCOMING;
334 return RepLevel.FAVORABLE;
341 private RepLevel minStanding = RepLevel.FAVORABLE;
344 if (ui.getTradeMode() == CoreUITradeMode.SNEAK)
return false;
347 return level.isAtWorst(minStanding);
351 return OnClickAction.OPEN_SUBMARKET;
356 return "Requires: " +
submarket.getFaction().getDisplayName() +
" - " + minStanding.getDisplayName().toLowerCase();
358 if (ui.getTradeMode() == CoreUITradeMode.SNEAK) {
359 return "Requires: proper docking authorization";
366 if (appendix ==
null)
return null;
368 Highlights h =
new Highlights();
370 h.setColors(Misc.getNegativeHighlightColor());
376 return PlayerEconomyImpactMode.PLAYER_SELL_ONLY;
static Logger getLogger(Class c)
static SectorAPI getSector()
void pruneWeapons(float keepFraction)
boolean okToUpdateShipsAndWeapons()
void addShips(String factionId, float combat, float freighter, float tanker, float transport, float liner, float utility, Float qualityOverride, float qualityMod, ShipPickMode modeOverride, FactionDoctrineAPI doctrineOverride)
float sinceLastCargoUpdate
void addHullMods(int maxTier, int num)
void addFighters(int min, int max, int maxTier, WeightedRandomPicker< String > factionPicker)
void addAndRemoveStockpiledResources(float amount, boolean withShortageCountering, boolean withDecreaseToLimit, boolean withCargoUpdate)
void addWeapons(int min, int max, int maxTier, String factionId)
OnClickAction getOnClickAction(CoreUIAPI ui)
String getTooltipAppendix(CoreUIAPI ui)
boolean isMilitaryMarket()
boolean isIllegalOnSubmarket(FleetMemberAPI member, TransferAction action)
int getStockpileLimit(CommodityOnMarketAPI com)
void init(SubmarketAPI submarket)
boolean isIllegalOnSubmarket(CargoStackAPI stack, TransferAction action)
Highlights getIllegalTransferTextHighlights(FleetMemberAPI member, TransferAction action)
boolean requiresCommission(RepLevel req)
boolean shouldHaveCommodity(CommodityOnMarketAPI com)
PlayerEconomyImpactMode getPlayerEconomyImpactMode()
String getIllegalTransferText(FleetMemberAPI member, TransferAction action)
String getIllegalTransferText(CargoStackAPI stack, TransferAction action)
Highlights getIllegalTransferTextHighlights(CargoStackAPI stack, TransferAction action)
boolean isIllegalOnSubmarket(String commodityId, TransferAction action)
Highlights getTooltipAppendixHighlights(CoreUIAPI ui)
void updateCargoPrePlayerInteraction()
boolean isEnabled(CoreUIAPI ui)
static float getBaseStockpileLimit(CommodityOnMarketAPI com)