Starsector API
Loading...
Searching...
No Matches
FusionLampEntityPlugin.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign;
2
3import java.awt.Color;
4
5import org.lwjgl.util.vector.Vector2f;
6import org.lwjgl.util.vector.Vector3f;
7
8import com.fs.starfarer.api.Global;
9import com.fs.starfarer.api.campaign.CampaignEngineLayers;
10import com.fs.starfarer.api.campaign.CustomEntitySpecAPI;
11import com.fs.starfarer.api.campaign.PlanetAPI;
12import com.fs.starfarer.api.campaign.SectorEntityToken;
13import com.fs.starfarer.api.combat.ViewportAPI;
14import com.fs.starfarer.api.graphics.SpriteAPI;
15import com.fs.starfarer.api.util.FlickerUtilV2;
16import com.fs.starfarer.api.util.Misc;
17
19
20 public static Color GLOW_COLOR = new Color(255,165,100,255);
21 public static Color LIGHT_COLOR = new Color(255,165,100,255);
22
23 public static String VOLATILES_SHORTAGE_KEY = "$core_volatilesShortage";
24
25 public static String GLOW_COLOR_KEY = "$core_lampGlowColor";
26 public static String LIGHT_COLOR_KEY = "$core_lampLightColor";
27 public static float GLOW_FREQUENCY = 0.2f; // on/off cycles per second
28
29
30 transient private SpriteAPI sprite;
31 transient private SpriteAPI glow;
32
33 public void init(SectorEntityToken entity, Object pluginParams) {
34 super.init(entity, pluginParams);
35 //this.entity = entity;
36 entity.setDetectionRangeDetailsOverrideMult(0.75f);
37 readResolve();
38 }
39
40 Object readResolve() {
41 //sprite = Global.getSettings().getSprite("campaignEntities", "fusion_lamp");
42 glow = Global.getSettings().getSprite("campaignEntities", "fusion_lamp_glow");
43 return this;
44 }
45
46 protected float phase = 0f;
47 protected FlickerUtilV2 flicker = new FlickerUtilV2();
48
49 public void advance(float amount) {
50 phase += amount * GLOW_FREQUENCY;
51 while (phase > 1) phase --;
52
53 flicker.advance(amount * 1f);
54
55 SectorEntityToken focus = entity.getOrbitFocus();
56 if (focus instanceof PlanetAPI) {
57 PlanetAPI planet = (PlanetAPI) focus;
58 float lightAlpha = getLightAlpha();
59 lightAlpha *= entity.getSensorFaderBrightness();
60 lightAlpha *= entity.getSensorContactFaderBrightness();
61 planet.setSecondLight(
62 new Vector3f(entity.getLocation().x, entity.getLocation().y, entity.getCircularOrbitRadius() * 0.75f),
63 Misc.scaleColor(getLightColor(), lightAlpha));
64 }
65 }
66
67 public float getFlickerBasedMult() {
68 float shortage = entity.getMemoryWithoutUpdate().getFloat(VOLATILES_SHORTAGE_KEY);
69 shortage *= 0.33f;
70 if (shortage <= 0f) return 1f;
71
72 //float f = (1f - shortage) + (shortage * flicker.getBrightness());
73 float f = 1f - shortage * flicker.getBrightness();
74 return f;
75 }
76
77 public float getGlowAlpha() {
78 float glowAlpha = 0f;
79 if (phase < 0.5f) glowAlpha = phase * 2f;
80 if (phase >= 0.5f) glowAlpha = (1f - (phase - 0.5f) * 2f);
81 glowAlpha = 0.75f + glowAlpha * 0.25f;
82 glowAlpha *= getFlickerBasedMult();
83 if (glowAlpha < 0) glowAlpha = 0;
84 if (glowAlpha > 1) glowAlpha = 1;
85 return glowAlpha;
86 }
87 public float getLightAlpha() {
88 //if (true) return 0f;
89 float lightAlpha = 0f;
90 if (phase < 0.5f) lightAlpha = phase * 2f;
91 if (phase >= 0.5f) lightAlpha = (1f - (phase - 0.5f) * 2f);
92 lightAlpha = 0.5f + lightAlpha * 0.5f;
93 lightAlpha *= getFlickerBasedMult();
94 if (lightAlpha < 0) lightAlpha = 0;
95 if (lightAlpha > 1) lightAlpha = 1;
96 return lightAlpha;
97 }
98
99 public Color getGlowColor() {
100 Color glowColor = GLOW_COLOR;
101 if (entity.getMemoryWithoutUpdate().contains(GLOW_COLOR_KEY)) {
102 glowColor = (Color) entity.getMemoryWithoutUpdate().get(GLOW_COLOR_KEY);
103 }
104 return glowColor;
105 }
106 public Color getLightColor() {
107 Color lightColor = LIGHT_COLOR;
108 if (entity.getMemoryWithoutUpdate().contains(LIGHT_COLOR_KEY)) {
109 lightColor = (Color) entity.getMemoryWithoutUpdate().get(LIGHT_COLOR_KEY);
110 }
111 return lightColor;
112 }
113
114 public void setGlowColor(Color color) {
115 entity.getMemoryWithoutUpdate().set(GLOW_COLOR_KEY, color);
116 }
117 public void setLightColor(Color color) {
118 entity.getMemoryWithoutUpdate().set(LIGHT_COLOR_KEY, color);
119 }
120
121 public float getRenderRange() {
122 return entity.getRadius() + 1200f;
123 }
124
125 public void render(CampaignEngineLayers layer, ViewportAPI viewport) {
126 float alphaMult = viewport.getAlphaMult();
127 alphaMult *= entity.getSensorFaderBrightness();
128 alphaMult *= entity.getSensorContactFaderBrightness();
129 if (alphaMult <= 0) return;
130
131 CustomEntitySpecAPI spec = entity.getCustomEntitySpec();
132 if (spec == null) return;
133
134 float w = spec.getSpriteWidth();
135 float h = spec.getSpriteHeight();
136
137 Vector2f loc = entity.getLocation();
138
139 if (sprite != null) {
140 sprite.setAngle(entity.getFacing() - 90f);
141 sprite.setSize(w, h);
142 sprite.setAlphaMult(alphaMult);
143 sprite.setNormalBlend();
144 sprite.renderAtCenter(loc.x, loc.y);
145 }
146
147
148 float glowAlpha = getGlowAlpha();
149
150 float glowAngle1 = (((phase * 1.3f) % 1) - 0.5f) * 12f;
151 float glowAngle2 = (((phase * 1.9f) % 1) - 0.5f) * 12f;
152
153 glow.setColor(getGlowColor());
154
155 w = 600f;
156 h = 600f;
157
158 glow.setSize(w, h);
159 glow.setAlphaMult(alphaMult * glowAlpha * 0.5f);
160 glow.setAdditiveBlend();
161
162 glow.renderAtCenter(loc.x, loc.y);
163
164 for (int i = 0; i < 5; i++) {
165 w *= 0.3f;
166 h *= 0.3f;
167 //glow.setSize(w * 0.1f, h * 0.1f);
168 glow.setSize(w, h);
169 glow.setAlphaMult(alphaMult * glowAlpha * 0.67f);
170 glow.renderAtCenter(loc.x, loc.y);
171 }
172
173// glow.setSize(w, h);
174// glow.setAlphaMult(alphaMult * glowAlpha);
175// glow.setAdditiveBlend();
176//
177// glow.setAngle(entity.getFacing() - 90f + glowAngle1);
178// glow.renderAtCenter(loc.x, loc.y);
179//
180// glow.setAngle(entity.getFacing() - 90f + glowAngle2);
181// glow.setAlphaMult(alphaMult * glowAlpha * 0.5f);
182// glow.renderAtCenter(loc.x, loc.y);
183 }
184
185
186// @Override
187// public void createMapTooltip(TooltipMakerAPI tooltip, boolean expanded) {
188// String post = "";
189// Color color = entity.getFaction().getBaseUIColor();
190// Color postColor = color;
191// if (entity.getMemoryWithoutUpdate().getBoolean(RemnantSystemType.DESTROYED.getBeaconFlag())) {
192// post = " - Low";
193// postColor = Misc.getPositiveHighlightColor();
194// } else if (entity.getMemoryWithoutUpdate().getBoolean(RemnantSystemType.SUPPRESSED.getBeaconFlag())) {
195// post = " - Medium";
196// postColor = Misc.getHighlightColor();
197// } else if (entity.getMemoryWithoutUpdate().getBoolean(RemnantSystemType.RESURGENT.getBeaconFlag())) {
198// post = " - High";
199// postColor = Misc.getNegativeHighlightColor();
200// }
201//
202// tooltip.addPara(entity.getName() + post, 0f, color, postColor, post.replaceFirst(" - ", ""));
203// }
204//
205// @Override
206// public boolean hasCustomMapTooltip() {
207// return true;
208// }
209//
210// @Override
211// public void appendToCampaignTooltip(TooltipMakerAPI tooltip, VisibilityLevel level) {
212// if (level == VisibilityLevel.COMPOSITION_AND_FACTION_DETAILS ||
213// level == VisibilityLevel.COMPOSITION_DETAILS) {
214//
215// String post = "";
216// Color color = Misc.getTextColor();
217// Color postColor = color;
218// if (entity.getMemoryWithoutUpdate().getBoolean(RemnantSystemType.DESTROYED.getBeaconFlag())) {
219// post = "low";
220// postColor = Misc.getPositiveHighlightColor();
221// } else if (entity.getMemoryWithoutUpdate().getBoolean(RemnantSystemType.SUPPRESSED.getBeaconFlag())) {
222// post = "medium";
223// postColor = Misc.getHighlightColor();
224// } else if (entity.getMemoryWithoutUpdate().getBoolean(RemnantSystemType.RESURGENT.getBeaconFlag())) {
225// post = "high";
226// postColor = Misc.getNegativeHighlightColor();
227// }
228// if (!post.isEmpty()) {
229// tooltip.setParaFontDefault();
230// tooltip.addPara(BaseIntelPlugin.BULLET + "Danger level: " + post, 10f, color, postColor, post);
231// }
232// }
233//
234// }
235}
236
237
238
239
240
241
242
243
244
static SettingsAPI getSettings()
Definition Global.java:51
void init(SectorEntityToken entity, Object pluginParams)
void render(CampaignEngineLayers layer, ViewportAPI viewport)
SpriteAPI getSprite(String filename)