53 CommodityIconCounts counts =
new CommodityIconCounts(
com);
55 int deficit = counts.deficit;
56 int available = Math.max(0, counts.available - counts.extra);
57 int extra = counts.extra;
60 iconGroup.addIconGroup(Commodities.SHIP_WEAPONS, IconRenderMode.NORMAL, available,
null);
63 iconGroup.addIconGroup(Commodities.SHIP_WEAPONS, IconRenderMode.RED, deficit,
null);
66 iconGroup.addIconGroup(Commodities.SHIP_WEAPONS, IconRenderMode.GREEN, extra,
null);
175 public int performRaid(CargoAPI loot, Random random,
float lootMult, TextPanelAPI text) {
180 WeightedRandomPicker<WeaponSpecAPI> pickerW =
new WeightedRandomPicker<WeaponSpecAPI>(random);
181 WeightedRandomPicker<FighterWingSpecAPI> pickerF =
new WeightedRandomPicker<FighterWingSpecAPI>(random);
182 WeightedRandomPicker<HullModSpecAPI> pickerH =
new WeightedRandomPicker<HullModSpecAPI>(random);
184 WeightedRandomPicker<WeaponSpecAPI> weaponSubset =
new WeightedRandomPicker<WeaponSpecAPI>(random);
185 WeightedRandomPicker<FighterWingSpecAPI> fighterSubset =
new WeightedRandomPicker<FighterWingSpecAPI>(random);
187 String factionId =
market.getFactionId();
188 float quality = Misc.getShipQuality(
market, factionId);
192 if (
market.getSize() >= 6) {
195 if (Misc.hasHeavyIndustry(
market) || Misc.isMilitary(
market)) {
202 for (String
id : faction.getKnownWeapons()) {
204 switch (spec.getSize()) {
216 float numTotal = numSmall + numMedium + numLarge + 1f;
218 for (String
id : faction.getKnownWeapons()) {
220 if (spec.getAIHints().contains(AIHints.SYSTEM))
continue;
221 if (spec.getTier() > maxTier)
continue;
223 float p = 1f * spec.getRarity() + quality *
getQMult(spec.getTier());
224 switch (spec.getSize()) {
226 p *= 1f - numLarge / numTotal;
230 p *= 1f - numMedium / numTotal;
234 p *= 1f - numSmall / numTotal;
238 pickerW.add(spec, p);
241 WeaponSpecAPI spec = pickerW.pick();
243 float w = pickerW.getWeight(spec);
244 weaponSubset.add(spec, w);
245 pickerW.remove(spec);
249 for (String
id : faction.getKnownFighters()) {
251 if (spec.getTier() > maxTier)
continue;
253 float p = 1f * spec.getRarity() + quality *
getQMult(spec.getTier());
254 pickerF.add(spec, p);
257 FighterWingSpecAPI spec = pickerF.pick();
259 float w = pickerF.getWeight(spec);
260 fighterSubset.add(spec, w);
261 pickerF.remove(spec);
265 for (String
id : faction.getKnownHullMods()) {
267 if (spec.isHidden())
continue;
268 if (spec.isAlwaysUnlocked())
continue;
269 if (spec.hasTag(Tags.NO_DROP))
continue;
270 if (spec.getTier() > maxTier)
continue;
272 float p = 1f * spec.getRarity();
276 pickerH.add(spec, p);
281 targetValue *= lootMult;
282 float mult = 0.9f + random.nextFloat() * 0.2f;
287 float weaponWeight = faction.getDoctrine().getWarships() + faction.getDoctrine().getPhaseShips();
288 float fighterWeight = 1f + faction.getDoctrine().getCarriers();
289 float hullmodWeight = 1f + quality * 1f;
290 float totalWeight = weaponWeight + fighterWeight + hullmodWeight;
292 float weaponValue = targetValue * weaponWeight / totalWeight;
293 float fighterValue = targetValue * fighterWeight / totalWeight;
294 float hullmodValue = targetValue * hullmodWeight / totalWeight;
296 float totalValue = 0;
301 while (weaponValue > 0 && tries < 100) {
303 WeaponSpecAPI weapon = weaponSubset.pick();
304 if (weapon !=
null) {
305 int min = 1, max = 2;
312 float val = weapon.getBaseValue() *
SELL_MULT;
313 int num = min + random.nextInt(max - min + 1);
314 num = (int) Math.min(num, weaponValue / val);
316 if (random.nextFloat() < weaponValue / val) num = 1;
319 looted.addWeapons(weapon.getWeaponId(), num);
320 weaponValue -= val * num;
321 totalValue += val * num;
330 fighterValue += Math.max(0, weaponValue);
333 while (fighterValue > 0 && tries < 100) {
335 FighterWingSpecAPI fighter = fighterSubset.pick();
336 if (fighter !=
null) {
337 int min = 1, max = 2;
338 switch (fighter.getRole()) {
351 float val = fighter.getBaseValue() *
SELL_MULT;
352 int num = min + random.nextInt(max - min + 1);
353 num = (int) Math.min(num, fighterValue / val);
355 if (random.nextFloat() < fighterValue / val) num = 1;
358 looted.addFighters(fighter.getId(), num);
359 fighterValue -= val * num;
360 totalValue += val * num;
369 hullmodValue += Math.max(0, fighterValue);
372 while (hullmodValue > 0 && tries < 100) {
374 HullModSpecAPI mod = pickerH.pickAndRemove();
376 float val = mod.getBaseValue();
378 if (random.nextFloat() < hullmodValue / val) num = 1;
380 looted.addHullmods(mod.getId(), num);
381 hullmodValue -= val * num;
382 totalValue += val * num;