1package com.fs.starfarer.api.impl.campaign.intel.bar.events;
4import java.util.ArrayList;
5import java.util.LinkedHashSet;
7import java.util.Random;
10import com.fs.starfarer.api.Global;
11import com.fs.starfarer.api.campaign.CargoAPI;
12import com.fs.starfarer.api.campaign.FactionAPI;
13import com.fs.starfarer.api.campaign.OptionPanelAPI;
14import com.fs.starfarer.api.campaign.TextPanelAPI;
15import com.fs.starfarer.api.campaign.econ.CommodityOnMarketAPI;
16import com.fs.starfarer.api.campaign.econ.MarketAPI;
17import com.fs.starfarer.api.characters.PersonAPI;
18import com.fs.starfarer.api.impl.campaign.ids.Conditions;
19import com.fs.starfarer.api.impl.campaign.ids.Factions;
20import com.fs.starfarer.api.impl.campaign.ids.Ranks;
21import com.fs.starfarer.api.impl.campaign.ids.Sounds;
22import com.fs.starfarer.api.impl.campaign.ids.Tags;
23import com.fs.starfarer.api.impl.campaign.rulecmd.AddRemoveCommodity;
24import com.fs.starfarer.api.impl.campaign.rulecmd.SetStoryOption;
25import com.fs.starfarer.api.impl.campaign.rulecmd.SetStoryOption.BaseOptionStoryPointActionDelegate;
26import com.fs.starfarer.api.impl.campaign.rulecmd.SetStoryOption.StoryOptionParams;
27import com.fs.starfarer.api.ui.TooltipMakerAPI;
28import com.fs.starfarer.api.util.Misc;
29import com.fs.starfarer.api.util.WeightedRandomPicker;
54 protected DestinationData
data;
62 if (!super.shouldShowAtMarket(
market))
return false;
96 if (this.market !=
market) {
112 public static class DestinationData {
118 public boolean fromHasPA =
false;
119 public boolean fromHasCells =
false;
121 public boolean hasPA =
false;
122 public boolean hasCells =
false;
124 public boolean illegal =
false;
126 public float score = 0;
131 this.comFrom = comFrom;
142 score += Math.min(distLY, 10f);
144 if (fromHasPA) score += 10f;
145 if (fromHasCells) score += 5f;
146 if (hasPA) score += 10f;
147 if (hasCells) score += 5f;
165 List<CommodityOnMarketAPI> commodities =
new ArrayList<CommodityOnMarketAPI>();
168 if (com.
isMeta())
continue;
175 commodities.add(com);
178 List<DestinationData> potential =
new ArrayList<DestinationData>();
183 if (other ==
market)
continue;
184 if (other.isHidden())
continue;
185 if (other.isInvalidMissionTarget())
continue;
188 if (other.getEconGroup() !=
null && !other.getEconGroup().equals(
market.
getEconGroup()))
continue;
190 if (other.getStarSystem() ==
null)
continue;
198 DestinationData
data =
new DestinationData(
market, other, com, otherCom);
199 if (
data.illegal)
continue;
200 if (
data.score > maxScore) {
201 maxScore =
data.score;
203 if (
data.distLY > maxDist) {
204 maxDist =
data.distLY;
209 if (maxDist > 10) maxDist = 10;
212 for (
int i = 0; i < potential.size(); i++) {
213 DestinationData d = potential.get(i);
214 if (d.score > maxScore * 0.5f && d.distLY > maxDist * 0.5f) {
215 picker.
add(d, d.score * d.score * d.score);
232 DestinationData pick = picker.
pick();
234 if (pick ==
null)
return;
242 if (pick.com.isFuel()) {
252 if (pick.com.isFuel()) {
269 quantity *= Math.min(1f, 200f / pick.comFrom.getCommodity().getBasePrice());
271 int limit = (int) (pick.comFrom.getAvailable() * pick.comFrom.getCommodity().getEconUnit());
272 limit *= 0.75f + 0.5f *
random.nextFloat();
285 float base = pick.comFrom.getMarket().getSupplyPrice(pick.comFrom.getId(), 1,
true);
288 base = Math.min(100, 4000 /
quantity);
295 float minBase = 100f - 50f * Math.min(1f,
quantity / 500f);
296 minBase = (base + minBase) * 0.75f;
298 if (base < minBase) base = minBase;
302 float mult = pick.score / 30f;
306 if (mult < 0.75f) mult = 0.75f;
320 escrow = (int) (
quantity * pick.comFrom.getCommodity().getBasePrice());
337 return (
int) (
reward * 1.5f);
341 String
id =
"negotiate_id";
348 new BaseOptionStoryPointActionDelegate(
dialog, params) {
351 public void confirm() {
362 public String getTitle() {
374 info.
addPara(
"You're able to negotiate the delivery fee from %s up to " +
380 addActionCostSection(info);
388 if (
escrow <= 0)
return true;
390 boolean canAfford = credits >=
escrow;
419 super.adjustPerson(
person);
449 return "At a corner table, a concerned-looking " +
getManOrWoman() +
452 return "At a corner table, a concerned-looking " +
getManOrWoman() +
469 str =
"\"Oh, it's you, " + sir +
"!\", " +
getHeOrShe() +
470 " exclaims. Taking a moment to recover " +
getHisOrHer() +
" composure, " +
getHeOrShe() +
" says \"We've got a little logistical problem that could use " +
471 "your personal touch. " +
476 str +=
"However, recent pirate activity has been making that difficult, and the regular trade fleets " +
477 "aren't quite up to the task.\"";
478 }
else if (
data.fromHasCells ||
data.hasCells) {
479 str +=
"However, recent Pather cell activity has been making that difficult, and the regular trade fleets " +
480 "aren't quite up to the task.\"";
482 str +=
"But, well, you know what trader captains are like. " +
483 "There have been some disagreements over hazard pay, and it's left us in the lurch.\"";
486 str =
"After a brief introduction, " +
getHeOrShe() +
" wastes no time in getting to the point.\n\n" +
491 str +=
"Recent pirate activity has been making that difficult, but you look like someone that could " +
492 "get the job done.\"";
493 }
else if (
data.fromHasCells ||
data.hasCells) {
494 str +=
"Recent Pather cell activity has been making that difficult, but I'm sure you can handle " +
497 str +=
"We've had some disputes with the regular shipping company, and it's left us in the lurch. " +
498 "Should be a milk run for someone like you, though.\"";
504 String where =
"located in hyperspace,";
510 str +=
"\n\nYou recall that " +
data.dest.
getName() +
" is under %s control, and " + where +
".";
516 str +=
" Your fleet's fuel tanks can hold an additional %s units of fuel.";
518 str +=
"%sYour fleet's fuel tanks are currently full.";
523 str +=
" Your fleet's holds can accommodate an additional %s units of cargo.";
525 str +=
"%sYour fleet's cargo holds are currently full.";
531 "\"The customer will pay %s upon delivery within %s days. Can you take this on?\"";
535 "\"The offer is %s credits, payable upon delivery within %s days. You'll also have to " +
536 "transfer %s to an escrow account. This will be returned to you " +
537 "when you complete the delivery - " +
538 "standard insurance procedure, you understand.\"";
541 "\"The offer is %s credits, payable upon delivery within %s days. You in?\"";
581 return "Agree to handle the contract";
583 return "Accept the delivery contract";
588 " does not appear too displeased. You consider that the initial offer " +
589 "was probably on the low side.";
595 return "Decline, explaining that you've got other urgent business to attend to";
597 return "Decline the offer, explaining that you've got other plans";
602 return "You receive authorization codes to access a dockside warehouse, and " +
603 "contact your quartermaster with instructions to begin loading the cargo.";
641 super.showTotalAndOptions();
645 Set<String> tags =
new LinkedHashSet<String>();
650 true, icon,
text, tags);
static SettingsAPI getSettings()
static SectorAPI getSector()
static final String PIRATE_ACTIVITY
static final String PATHER_CELLS
static final String LUDDIC_PATH
static final String PIRATES
static final String INDEPENDENT
static String POST_TRADER
static String POST_INVESTOR
static String POST_COMMODITIES_AGENT
static String POST_MERCHANT
static String STORY_POINT_SPEND_INDUSTRY
transient TextPanelAPI text
transient OptionPanelAPI options
transient InteractionDialogAPI dialog
PersonImportance pickImportance()
static final String OPTION_CONFIRM
String pickOne(String ... options)
static float ACCEPTED_AT_THIS_MARKET_DURATION
void showTotalAndOptions()
DestinationData getData()
static String KEY_FAILED_RECENTLY
static String KEY_ACCEPTED_AT_THIS_MARKET_RECENTLY
void regen(MarketAPI market)
int getNegotiatedAmount()
String getNegotiatedText()
void doStandardConfirmActions()
static String KEY_SAW_DELIVERY_EVENT_RECENTLY
MarketAPI getDestination()
String[] getMainTextTokens()
static float SAW_RECENTLY_DURATION
String getPersonFaction()
boolean shouldShowAtMarket(MarketAPI market)
Color[] getMainTextColors()
static float FAILED_RECENTLY_DURATION
void computeData(MarketAPI market)
static float PROB_TO_SHOW
void adjustPerson(PersonAPI person)
static float PROB_HIGHER_CAPACITY
static void addCommodityGainText(String commodityId, int quantity, TextPanelAPI text)
static void addCreditsLossText(int credits, TextPanelAPI text)
static boolean set(String ruleId, InteractionDialogAPI dialog, Map< String, MemoryAPI > memoryMap, String params)
static Color getTextColor()
static String getDGSCredits(float num)
static String getWithDGS(float num)
static float getDistanceLY(SectorEntityToken from, SectorEntityToken to)
static String ucFirst(String str)
static Color getHighlightColor()
CommoditySpecAPI getCommoditySpec(String commodityId)
MutableValue getCredits()
void addCommodity(String commodityId, float quantity)
String getPersonNamePrefixAOrAn()
String getPersonNamePrefix()
TextPanelAPI getTextPanel()
VisualPanelAPI getVisualPanel()
OptionPanelAPI getOptionPanel()
String getNameWithLowercaseType()
void addOption(String text, Object data)
CampaignFleetAPI getPlayerFleet()
FactionAPI getFaction(String factionId)
PersonAPI getPlayerPerson()
MemoryAPI getMemoryWithoutUpdate()
LabelAPI addPara(String text)
void showMapMarker(SectorEntityToken marker, String title, Color titleColor, boolean withIntel, String icon, String text, Set< String > intelTags)
CommoditySpecAPI getCommodity()
String getLowerCaseName()
List< MarketAPI > getMarketsCopy()
MemoryAPI getMemoryWithoutUpdate()
List< CommodityOnMarketAPI > getCommoditiesCopy()
boolean isIllegal(String commodityId)
Vector2f getLocationInHyperspace()
StarSystemAPI getStarSystem()
boolean hasCondition(String id)
void set(String key, Object value)
boolean getBoolean(String key)
void setImportanceAndVoice(PersonImportance importance, Random random)