Starsector API
Loading...
Searching...
No Matches
BlueprintOfferCreator.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.intel.bar.events.historian;
2
3import java.util.HashSet;
4import java.util.List;
5import java.util.Random;
6import java.util.Set;
7
8import com.fs.starfarer.api.campaign.PlanetAPI;
9import com.fs.starfarer.api.campaign.SectorEntityToken;
10import com.fs.starfarer.api.impl.campaign.intel.bar.events.historian.HistorianData.HistorianOffer;
11import com.fs.starfarer.api.util.WeightedRandomPicker;
12
13public abstract class BlueprintOfferCreator extends BaseHistorianOfferCreator {
14
18
19 public String getOfferId(BaseHistorianOffer offer) {
20 return null;
21 }
22
23 public String getBlueprintIdFromOfferId(String offerId) {
24 return null;
25 }
26
27 @Override
28 public HistorianOffer createOffer(Random random, List<HistorianOffer> soFar) {
30
31 SectorEntityToken entity = pickEntity(random, false);
32 if (entity == null || random.nextFloat() < getProbabilityRuins()) {
33 PlanetAPI planet = pickUnexploredRuins(random);
34 if (planet != null) entity = planet;
35 }
36 if (entity == null) {
37 entity = createEntity(random);
38 }
39
40 if (entity == null) return null;
41
42 WeightedRandomPicker<String> picker = new WeightedRandomPicker<String>(random);
43
44 Set<String> already = new HashSet<String>();
45 for (HistorianOffer offer : soFar) {
46 String id = getAlreadyUsedIdFromOffer(offer);
47 if (id != null) already.add(id);
48 }
49
50 for (String id : hd.getGivenOffers()) {
51 String bpId = getBlueprintIdFromOfferId(id);
52 if (bpId != null) {
53 already.add(bpId);
54 }
55 }
56
57 for (Object spec : getAllSpecs()) {
58 String id = getIdForSpec(spec);
59 if (already.contains(id)) continue;
60 if (playerKnowsSpecAlready(id)) continue;
61
62 float w = hd.getWeightForTags(getTagsForSpec(spec));
63 if (w <= 0) continue;
64
65 w *= getRarityForSpec(spec);
66 picker.add(id, w);
67 }
68
69 String data = picker.pick();
70 if (data == null) return null;
71
72 HistorianOffer offer = createOffer(entity, data);
73 return offer;
74 }
75
76 protected abstract BaseHistorianOfferWithLocation createOffer(SectorEntityToken entity, String data);
77
78 protected abstract String getAlreadyUsedIdFromOffer(HistorianOffer offer);
79 protected abstract List<Object> getAllSpecs();
80 protected abstract Set<String> getTagsForSpec(Object spec);
81 protected abstract String getIdForSpec(Object spec);
82 protected abstract boolean playerKnowsSpecAlready(String id);
83
84 protected float getRarityForSpec(Object spec) {
85 return 1f;
86 }
87
88 protected float getProbabilityRuins() {
89 return 0.33f;
90 }
91
92}
93
94
95
96
97
98
99
abstract BaseHistorianOfferWithLocation createOffer(SectorEntityToken entity, String data)