Starsector API
Loading...
Searching...
No Matches
CommRelayEntityPlugin.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign;
2
3import com.fs.starfarer.api.Global;
4import com.fs.starfarer.api.campaign.InteractionDialogAPI;
5import com.fs.starfarer.api.campaign.SectorEntityToken;
6import com.fs.starfarer.api.campaign.TextPanelAPI;
7import com.fs.starfarer.api.campaign.comm.IntelInfoPlugin;
8import com.fs.starfarer.api.campaign.econ.MarketAPI;
9import com.fs.starfarer.api.impl.campaign.econ.CommRelayCondition;
10import com.fs.starfarer.api.impl.campaign.ids.Conditions;
11import com.fs.starfarer.api.impl.campaign.ids.MemFlags;
12import com.fs.starfarer.api.impl.campaign.ids.Tags;
13import com.fs.starfarer.api.impl.campaign.intel.BaseIntelPlugin;
14import com.fs.starfarer.api.impl.campaign.intel.misc.CommSnifferIntel;
15import com.fs.starfarer.api.ui.TooltipMakerAPI;
16import com.fs.starfarer.api.util.Misc;
17
19
20 public static interface CommSnifferReadableIntel {
21 boolean canMakeVisibleToCommSniffer(boolean playerInRelayRange, SectorEntityToken relay);
22 }
23
24
25 public void init(SectorEntityToken entity, Object pluginParams) {
26 super.init(entity, pluginParams);
27 readResolve();
28 }
29
30 Object readResolve() {
31 return this;
32 }
33
34 public void advance(float amount) {
35 if (entity.getContainingLocation() == null || entity.isInHyperspace()) return;
36
37 if (entity.getMemoryWithoutUpdate().getBoolean(MemFlags.OBJECTIVE_NON_FUNCTIONAL)) return;
38
39 // everything else is handled by the relay condition - it picks what relay to use and when to remove itself
40 for (MarketAPI market : Misc.getMarketsInLocation(entity.getContainingLocation())) {
41 CommRelayCondition mc = CommRelayCondition.get(market);
42 if (mc == null) {
43 market.addCondition(Conditions.COMM_RELAY);
44 mc = CommRelayCondition.get(market);
45 }
46 if (mc != null) {
47 mc.getRelays().add(entity);
48 }
49 }
50
51 checkIntelFromCommSniffer();
52 }
53
54
55
56 protected boolean isMakeshift() {
57 return entity.hasTag(Tags.MAKESHIFT);
58 }
59
60
61 public void printNonFunctionalAndHackDescription(TextPanelAPI text) {
62 if (entity.getMemoryWithoutUpdate().getBoolean(MemFlags.OBJECTIVE_NON_FUNCTIONAL)) {
63 text.addPara("This one, however, is not connected to the Sector-wide network and is not emitting the hyperwave radiation typically indicative of relay operation. The cause of its lack of function is unknown.");
64 }
65 if (isHacked()) {
66 text.addPara("You have a comm sniffer running on this relay.");
67 }
68 }
69
70
71 public void printEffect(TooltipMakerAPI text, float pad) {
72// int bonus = Math.abs(Math.round(
73// CommRelayCondition.NO_RELAY_PENALTY - CommRelayCondition.COMM_RELAY_BONUS));
74// if (isMakeshift()) {
75// bonus = Math.abs(Math.round(
76// CommRelayCondition.NO_RELAY_PENALTY - CommRelayCondition.MAKESHIFT_COMM_RELAY_BONUS));
77// }
78 int bonus = Math.abs(Math.round(
79 CommRelayCondition.COMM_RELAY_BONUS));
80 if (isMakeshift()) {
81 bonus = Math.abs(Math.round(
82 CommRelayCondition.MAKESHIFT_COMM_RELAY_BONUS));
83 }
84 text.addPara(BaseIntelPlugin.INDENT + "%s stability for same-faction colonies in system",
85 pad, Misc.getHighlightColor(), "+" + bonus);
86 }
87
88 public void addHackStatusToTooltip(TooltipMakerAPI text, float pad) {
89// int bonus = Math.abs(Math.round(
90// CommRelayCondition.NO_RELAY_PENALTY - CommRelayCondition.COMM_RELAY_BONUS));
91// if (isMakeshift()) {
92// bonus = Math.abs(Math.round(
93// CommRelayCondition.NO_RELAY_PENALTY - CommRelayCondition.MAKESHIFT_COMM_RELAY_BONUS));
94// }
95 int bonus = Math.abs(Math.round(
96 CommRelayCondition.COMM_RELAY_BONUS));
97 if (isMakeshift()) {
98 bonus = Math.abs(Math.round(
99 CommRelayCondition.MAKESHIFT_COMM_RELAY_BONUS));
100 }
101
102 if (isHacked()) {
103 text.addPara("%s stability for in-system colonies",
104 pad, Misc.getHighlightColor(), "+" + bonus);
105 text.addPara("Comm sniffer installed", Misc.getTextColor(), pad);
106 } else {
107 text.addPara("%s stability for same-faction colonies in-system",
108 pad, Misc.getHighlightColor(), "+" + bonus);
109
110 }
111 }
112
113 @Override
114 public void setHacked(boolean hacked) {
115 if (hacked) {
116 setHacked(hacked, -1f);
117 boolean found = CommSnifferIntel.getExistingSnifferIntelForRelay(entity) != null;
118 if (!found) {
119 CommSnifferIntel intel = new CommSnifferIntel(entity);
120 InteractionDialogAPI dialog = Global.getSector().getCampaignUI().getCurrentInteractionDialog();
121 if (dialog != null) {
122 Global.getSector().getIntelManager().addIntelToTextPanel(intel, dialog.getTextPanel());
123 }
124 }
125 } else {
126 setHacked(hacked, -1f);
127 }
128 }
129
130
131
132 private void checkIntelFromCommSniffer() {
133 if (!isHacked()) return;
134
135 boolean playerInRelayRange = Global.getSector().getIntelManager().isPlayerInRangeOfCommRelay();
136 for (IntelInfoPlugin intel : Global.getSector().getIntelManager().getCommQueue()) {
137 if (intel instanceof CommSnifferReadableIntel) {
138 CommSnifferReadableIntel csi = (CommSnifferReadableIntel) intel;
139 if (csi.canMakeVisibleToCommSniffer(playerInRelayRange, entity)) {
140 intel.setForceAddNextFrame(true);
141 }
142 }
143 }
144 }
145
146}
147
148
149
static SectorAPI getSector()
Definition Global.java:59
void init(SectorEntityToken entity, Object pluginParams)