62 public boolean execute(String ruleId, InteractionDialogAPI dialog, List<Token> params, Map<String, MemoryAPI> memoryMap) {
63 if (dialog ==
null)
return false;
64 if (!(dialog.getInteractionTarget() instanceof CampaignFleetAPI))
return false;
67 CampaignFleetAPI other = (CampaignFleetAPI) dialog.getInteractionTarget();
69 FactionAPI faction = other.getFaction();
71 CargoScanResult result =
new CargoScanResult();
74 float totalLegalCargo = 0;
75 float totalIllegal = 0;
76 float totalIllegalFound = 0;
81 float totalCargo = playerFleet.getCargo().getSpaceUsed();
82 float totalCrew = playerFleet.getCargo().getTotalPersonnel();
83 float totalFuel = playerFleet.getCargo().getFuel();
85 for (CargoStackAPI stack : playerFleet.getCargo().getStacksCopy()) {
86 boolean legal = !faction.isIllegal(stack);
88 totalLegal += stack.getSize();
89 totalLegalCargo += stack.getCargoSpace();
91 totalIllegal += stack.getSize();
93 all.addFromStack(stack);
98 float shieldedFraction = Misc.getShieldedCargoFraction(playerFleet);
99 float unshieldedFraction = 1f - shieldedFraction;
101 float shieldedMult = (0.25f + 0.75f * unshieldedFraction);
103 MarketAPI market = Misc.getSourceMarket(other);
104 float level = market.getMemory().getFloat(MemFlags.MEMORY_MARKET_SMUGGLING_SUSPICION_LEVEL);
105 float suspicionMult = 0f;
106 if (market !=
null) {
107 if (level >= 0.05f) {
108 suspicionMult = 0.5f + 0.5f * level;
112 totalLegalCargo *= shieldedMult;
115 boolean suspicious =
false;
116 boolean suspiciousDueToLevel =
false;
117 if (totalLegalCargo > 50 || totalLegalCargo > playerFleet.getCargo().getMaxCapacity() * 0.5f) {
118 totalLegalCargo *= suspicionMult;
119 suspicious = totalLegalCargo * guiltMult * (float) Math.random() >
120 playerFleet.getCargo().getMaxCapacity() * (float) Math.random();
126 if (!suspicious && level >= 0.5f) {
127 float r = (float) Math.random();
128 suspicious |= r * r < level;
130 suspiciousDueToLevel =
true;
134 if (totalLegal + totalIllegal > 0) {
135 List<CargoStackAPI> stacks = all.getStacksCopy();
136 Collections.shuffle(stacks);
138 float illegalCargoSoFar = 0;
139 float illegalCrewSoFar = 0;
140 float illegalFuelSoFar = 0;
141 for (CargoStackAPI stack : stacks) {
142 if (stack.getSize() <= 0)
continue;
143 boolean legal = !faction.isIllegal(stack);
144 float chanceToFind = 0f;
145 if (stack.isPersonnelStack()) {
147 if (!legal) illegalCrewSoFar += stack.getSize();
148 chanceToFind = illegalCrewSoFar / totalCrew;
150 }
else if (stack.isFuelStack()) {
152 if (!legal) illegalFuelSoFar += stack.getSize();
153 chanceToFind = illegalFuelSoFar / totalFuel;
156 if (totalCargo > 0) {
157 if (!legal) illegalCargoSoFar += stack.getCargoSpace();
158 chanceToFind = illegalCargoSoFar / totalCargo;
162 chanceToFind *= guiltMult;
163 chanceToFind *= shieldedMult;
170 legalFound.addFromStack(stack);
171 }
else if ((
float) Math.random() < chanceToFind) {
172 float qty = stack.getSize();
173 qty = qty * (0.33f + (float) Math.random() * 0.67f);
175 qty = Math.round(qty);
176 if (qty < 1) qty = 1;
177 illegalFound.addItems(stack.getType(), stack.getData(), qty);
184 if (suspicious && illegalFound.isEmpty()) {
185 WeightedRandomPicker<FleetMemberAPI> picker =
new WeightedRandomPicker<FleetMemberAPI>();
186 for (FleetMemberAPI member : playerFleet.getFleetData().getMembersListCopy()) {
187 if (member.isMothballed() && member.getRepairTracker().getBaseCR() < 0.2f)
continue;
188 picker.add(member, member.getFleetPointCost());
190 if (picker.isEmpty()) {
193 float totalDamage = Math.min(playerFleet.getFleetPoints(), other.getFleetPoints()) *
INSPECTION_DAMAGE_MULT;
195 while (picked < totalDamage && !picker.isEmpty()) {
196 FleetMemberAPI pick = picker.pickAndRemove();
197 result.shipsToDamage.add(pick);
198 picked += pick.getFleetPointCost();
203 result.setLegalFound(legalFound);
204 result.setIllegalFound(illegalFound);
206 MemoryAPI memory = memoryMap.get(MemKeys.LOCAL);
211 float maxPodsDist = 1500f;
212 OUTER:
for (SectorEntityToken entity : other.getContainingLocation().getAllEntities()) {
213 if (Entities.CARGO_PODS.equals(entity.getCustomEntityType())) {
214 VisibilityLevel vLevel = entity.getVisibilityLevelTo(other);
216 float dist = Misc.getDistance(playerFleet, entity);
217 if (dist > maxPodsDist)
continue;
220 if (plugin.
getElapsed() <= 1f && entity.getCargo() !=
null) {
221 if (vLevel == VisibilityLevel.COMPOSITION_DETAILS ||
222 vLevel == VisibilityLevel.COMPOSITION_AND_FACTION_DETAILS) {
223 for (CargoStackAPI stack : entity.getCargo().getStacksCopy()) {
224 boolean legal = !faction.isIllegal(stack);
227 Misc.fadeAndExpire(entity);
238 TextPanelAPI text = dialog.getTextPanel();
241 text.setFontSmallInsignia();
243 Color hl = Misc.getHighlightColor();
244 Color red = Misc.getNegativeHighlightColor();
245 text.addParagraph(
"-----------------------------------------------------------------------------");
247 if (!illegalFound.isEmpty()) {
248 text.addParagraph(
"Contraband found!", red);
250 List<String> highlights =
new ArrayList<String>();
251 for (CargoStackAPI stack : illegalFound.getStacksCopy()) {
252 para += stack.getDisplayName() +
" " + Strings.X +
" " + (int)stack.getSize() +
"\n";
253 highlights.add(
"" + (
int)stack.getSize());
255 para = para.substring(0, para.length() - 1);
256 text.addParagraph(para);
257 text.highlightInLastPara(hl, highlights.toArray(
new String [0]));
258 }
else if (suspicious) {
259 if (suspiciousDueToLevel) {
260 text.addParagraph(
"Vessels flagged for inspection due to overall suspicion level!", hl);
262 text.addParagraph(
"Suspicious cargo found!", hl);
265 text.addParagraph(
"No contraband or suspicious cargo found.");
268 text.addParagraph(
"-----------------------------------------------------------------------------");
270 text.setFontInsignia();
272 for (CargoStackAPI stack : illegalFound.getStacksCopy()) {
273 totalIllegalFound += stack.getSize();
276 float capacity = playerFleet.getCargo().getMaxCapacity();
277 float repLoss = totalIllegalFound / 5f * totalIllegalFound / capacity;
278 repLoss = Math.round(repLoss);
279 if (repLoss > 5) repLoss = 5f;
280 if (repLoss == 0 && totalIllegalFound > 0) repLoss = 1f;
285 RepActionEnvelope envelope =
new RepActionEnvelope(RepActions.CUSTOMS_CAUGHT_SMUGGLING, repLoss, dialog.getTextPanel());
288 envelope =
new RepActionEnvelope(RepActions.CUSTOMS_CAUGHT_SMUGGLING, repLoss * 2f, dialog.getTextPanel());
289 Global.
getSector().adjustPlayerReputation(envelope, dialog.getInteractionTarget().getActivePerson());