Starsector API
Loading...
Searching...
No Matches
MusicPlayerPluginImpl.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl;
2
3import java.util.HashMap;
4import java.util.Map;
5
6import com.fs.starfarer.api.Global;
7import com.fs.starfarer.api.MusicPlayerPluginWithVolumeControl;
8import com.fs.starfarer.api.campaign.CampaignFleetAPI;
9import com.fs.starfarer.api.campaign.FactionAPI;
10import com.fs.starfarer.api.campaign.RepLevel;
11import com.fs.starfarer.api.campaign.SectorEntityToken;
12import com.fs.starfarer.api.campaign.StarSystemAPI;
13import com.fs.starfarer.api.campaign.ai.ModularFleetAIAPI;
14import com.fs.starfarer.api.campaign.econ.MarketAPI;
15import com.fs.starfarer.api.campaign.rules.MemoryAPI;
16import com.fs.starfarer.api.combat.CombatEngineAPI;
17import com.fs.starfarer.api.impl.campaign.ids.Entities;
18import com.fs.starfarer.api.impl.campaign.ids.Factions;
19import com.fs.starfarer.api.impl.campaign.ids.Tags;
20import com.fs.starfarer.api.impl.campaign.tutorial.TutorialMissionIntel;
21import com.fs.starfarer.api.util.Misc;
22
24
25 public static String KEEP_PLAYING_LOCATION_MUSIC_DURING_ENCOUNTER_MEM_KEY = "$playLocationMusicDuringEnc";
26 public static String COMBAT_MUSIC_SET_MEM_KEY = "$combatMusicSetId";
27 public static String COMBAT_MUSIC_SET_FACTION_KEY = "music_combat_set";
28 public static String MUSIC_SET_MEM_KEY = "$musicSetId";
29 public static String MUSIC_SET_MEM_KEY_MISSION = "$musicSetIdForMission";
30
31
32 public static String MUSIC_ENCOUNTER_MYSTERIOUS_AGGRO = "music_encounter_mysterious";
33 public static String MUSIC_ENCOUNTER_MYSTERIOUS_NON_AGGRESSIVE = "music_encounter_mysterious_non_aggressive";
34 public static String MUSIC_ENCOUNTER_NEUTRAL = "music_encounter_neutral";
35 public static String MUSIC_GALATIA_ACADEMY = "music_galatia_academy";
36
37
38 public static Object CAMPAIGN_SYSTEM = new Object();
39 public static Object CAMPAIGN_HYPERSPACE = new Object();
40 public static Object NO_MUSIC = new Object();
41 public static Object COMBAT = new Object();
42 public static Object TITLE = new Object();
43 public static Object MARKET = new Object();
44 public static Object ENCOUNTER = new Object();
45 public static Object PLANET_SURVEY = new Object();
46
47 public static Object CUSTOM = new Object();
48
49 public static Map<String, String> stringTokens = new HashMap<String, String>();
50
56 public static Object getToken(String str) {
57 if (!stringTokens.containsKey(str)) {
58 stringTokens.put(str, str);
59 }
60 return stringTokens.get(str);
61 }
62
63 public static String SYSTEM_MUSIC_PREFIX = "core_sys_music_";
64
67 if (playerFleet.getContainingLocation() instanceof StarSystemAPI) {
68 /*
69 Just returning CAMPAIGN_SYSTEM and letting getMusicSetIdForCampaignStateToken()
70 return the musicSetId misses the case where there's a transition between
71 two star systems with different music, without hyperspace travel in between -
72 since there would be no state transition (due to it being the same CAMPAIGN_SYSTEM state),
73 a restart of the music - and a change to a different music set - would not be triggered.
74
75 Since the state ID includes the music set id, this means that moving between
76 two systems with the same $musicSetId will not trigger a state change and
77 the same music will just keep playing uninterrupted.
78 */
79 StarSystemAPI system = (StarSystemAPI) playerFleet.getContainingLocation();
81 if (musicSetId != null) {
82 return getToken(SYSTEM_MUSIC_PREFIX + musicSetId);
83 }
85 if (musicSetId != null) {
86 return getToken(SYSTEM_MUSIC_PREFIX + musicSetId);
87 }
88 return CAMPAIGN_SYSTEM;
89 }
90// float depth = Misc.getAbyssalDepthOfPlayer();
91// if (depth > 0.5f) {
92// return NO_MUSIC;
93// }
95 }
96
98 if (engine.getContext() != null && engine.getContext().getOtherFleet() != null) {
99 CampaignFleetAPI other = engine.getContext().getOtherFleet();
100 MemoryAPI mem = other.getMemoryWithoutUpdate();
103 }
104 String factionSet = other.getFaction().getMusicMap().get(COMBAT_MUSIC_SET_FACTION_KEY);
105 if (factionSet != null) return factionSet;
106 }
107 return "music_combat";
108 }
109
110 public String getMusicSetIdForTitle() {
111 return "music_title";
112 }
113
114
115 public float getMusicSetVolumeForCampaignStateToken(Object token, Object param) {
116 if (token == CAMPAIGN_HYPERSPACE) {
117 //float depth = Misc.getAbyssalDepthOfPlayer();
118 // need to check this way so that the hyperspace track doesn't fade back in
119 // right after transitiong to an abyssal system (as the track fades out)
121 float depth = 0f;
122 if (pf != null) depth = Misc.getAbyssalDepth(pf.getLocationInHyperspace());
123 float vol = 1f - depth;
124 if (vol > 1f) vol = 1f;
125 if (vol < 0f) vol = 0f;
126 return vol;
127 }
128 return 1f;
129 }
130
131 public String getMusicSetIdForCampaignStateToken(Object token, Object param) {
132 if (token == MARKET) {
133 return getMarketMusicSetId(param);
134 }
135 if (token == ENCOUNTER) {
136 return getEncounterMusicSetId(param);
137 }
138 if (token == CAMPAIGN_SYSTEM ||
139 (token instanceof String && ((String)token).startsWith(SYSTEM_MUSIC_PREFIX))) {
141 }
142 if (token == CAMPAIGN_HYPERSPACE) {
144 }
145 if (token == PLANET_SURVEY) {
146 return getPlanetSurveyMusicSetId(param);
147 }
148 if (token == NO_MUSIC) {
149 return null;
150 }
151 return null;
152 }
153
158 protected String getPlanetSurveyMusicSetId(Object param) {
159 SectorEntityToken token = null;
160 if (param instanceof SectorEntityToken) {
161 token = (SectorEntityToken) param;
162 } else if (param instanceof MarketAPI) {
163 token = ((MarketAPI)param).getPlanetEntity();
164 }
165 if (token != null) {
167 if (musicSetId != null) return musicSetId;
169 if (musicSetId != null) return musicSetId;
170 }
171 return "music_survey_and_scavenge";
172 }
173
174 protected String getHyperspaceMusicSetId() {
175 return "music_campaign_hyperspace";
176 }
177
178 protected String getStarSystemMusicSetId() {
180 if (playerFleet.getContainingLocation() instanceof StarSystemAPI) {
181 StarSystemAPI system = (StarSystemAPI) playerFleet.getContainingLocation();
182 String musicSetId = system.getMemoryWithoutUpdate().getString(MUSIC_SET_MEM_KEY_MISSION);
183 if (musicSetId != null) return musicSetId;
185 if (musicSetId != null) return musicSetId;
186
187 if (system.hasTag(Tags.SYSTEM_ABYSSAL)) {
188 return "music_campaign_abyssal";
189 }
190 if (system.hasTag(Tags.THEME_CORE) ||
191 !Misc.getMarketsInLocation(system, Factions.PLAYER).isEmpty()) {
192 return "music_campaign";
193 }
194 }
195
196 return "music_campaign_non_core";
197 }
198
199 protected String getEncounterMusicSetId(Object param) {
200 if (param instanceof SectorEntityToken) {
201 SectorEntityToken token = (SectorEntityToken) param;
202
204 if (musicSetId != null) return musicSetId;
206 if (musicSetId != null) return musicSetId;
207
208 if (Entities.ABYSSAL_LIGHT.equals(token.getCustomEntityType())) {
210 }
211 if (Entities.CORONAL_TAP.equals(token.getCustomEntityType())) {
213 }
214 if (Entities.WRECK.equals(token.getCustomEntityType())) {
216 }
219 }
220
222 return "music_survey_and_scavenge";
223 }
224 if (token.hasTag(Tags.GATE)) {
226 }
227 if (token.hasTag(Tags.OBJECTIVE)) {
229 }
230 if (token.hasTag(Tags.SALVAGEABLE)) {
231 if (token.getMemoryWithoutUpdate() != null && token.getMemoryWithoutUpdate().getBoolean("$hasDefenders")) {
232 if (token.getMemoryWithoutUpdate().getBoolean("$limboMiningStation")) {
234 }
235 if (token.getMemoryWithoutUpdate().getBoolean("$limboWormholeCache")) {
237 }
239 }
240 return "music_survey_and_scavenge";
241 }
242 if (token.hasTag(Tags.SALVAGE_MUSIC)) {
243 return "music_survey_and_scavenge";
244 }
245
246// MemoryAPI memory = token.getMemoryWithoutUpdate();
247// if (!memory.getBoolean("$defenderFleetDefeated") && memory.getBoolean("$hasDefenders")) {
248// CampaignFleetAPI defenders = memory.getFleet("$defenderFleet");
249// if (defenders != null) token = defenders;
250// }
251
252 if (token.getFaction() != null) {
253 FactionAPI faction = (FactionAPI) token.getFaction();
254 String type = null;
255 //MemoryAPI mem = token.getMemoryWithoutUpdate();
256 boolean hostile = false;
257 boolean knowsWhoPlayerIs = false;
258 if (token instanceof CampaignFleetAPI) {
259 CampaignFleetAPI fleet = (CampaignFleetAPI) token;
260 if (fleet.getAI() instanceof ModularFleetAIAPI) {
261 hostile = ((ModularFleetAIAPI) fleet.getAI()).isHostileTo(Global.getSector().getPlayerFleet());
262 }
263 knowsWhoPlayerIs = fleet.knowsWhoPlayerIs();
264 }
265
266 if (faction.isAtWorst(Factions.PLAYER, RepLevel.FAVORABLE) && knowsWhoPlayerIs && !hostile) {
267 type = "encounter_friendly";
268 } else if ((faction.isAtBest(Factions.PLAYER, RepLevel.SUSPICIOUS) && knowsWhoPlayerIs) || hostile) {
269 type = "encounter_hostile";
270 } else {
271 type = "encounter_neutral";
272 }
273
274 if (type != null) {
275 musicSetId = faction.getMusicMap().get(type);
276 if (musicSetId != null) {
277 return musicSetId;
278 }
279 }
280
281 musicSetId = null;
283 musicSetId = "music_default_encounter_friendly";
284 } else if (faction.isAtBest(Factions.PLAYER, RepLevel.SUSPICIOUS)) {
285 musicSetId = "music_default_encounter_hostile";
286 } else {
287 musicSetId = "music_default_encounter_neutral";
288 }
289 return musicSetId;
290 }
291 }
292 return null;
293 }
294
295
296 protected String getMarketMusicSetId(Object param) {
297 if (param instanceof MarketAPI) {
298 MarketAPI market = (MarketAPI) param;
299
300 String musicSetId = market.getMemoryWithoutUpdate().getString(MUSIC_SET_MEM_KEY_MISSION);
301 if (musicSetId != null) return musicSetId;
303 if (musicSetId != null) return musicSetId;
304
305 if (market.getPrimaryEntity() != null &&
306 market.getPrimaryEntity().getMemoryWithoutUpdate().getBoolean("$abandonedStation")) {
307 return getPlanetSurveyMusicSetId(param);
308 }
309
310 if (market.getPrimaryEntity() != null &&
311 market.getPrimaryEntity().getId().equals("station_galatia_academy")) {
314 }
316 }
317
318 FactionAPI faction = market.getFaction();
319 if (faction != null) {
320 String type = null;
322 type = "market_friendly";
323 } else if (faction.isAtBest(Factions.PLAYER, RepLevel.SUSPICIOUS)) {
324 type = "market_hostile";
325 } else {
326 type = "market_neutral";
327 }
328
329 if (type != null) {
330 musicSetId = faction.getMusicMap().get(type);
331 if (musicSetId != null) {
332 return musicSetId;
333 }
334 }
335
336 musicSetId = null;
338 musicSetId = "music_default_market_friendly";
339 } else if (faction.isAtBest(Factions.PLAYER, RepLevel.SUSPICIOUS)) {
340 musicSetId = "music_default_market_hostile";
341 } else {
342 musicSetId = "music_default_market_neutral";
343 }
344 return musicSetId;
345 }
346 }
347 return null;
348 }
349}
350
351
352
353
354
355
356
357
static SectorAPI getSector()
Definition Global.java:65
String getMusicSetIdForCampaignStateToken(Object token, Object param)
float getMusicSetVolumeForCampaignStateToken(Object token, Object param)
static List< MarketAPI > getMarketsInLocation(LocationAPI location, String factionId)
Definition Misc.java:936
static float getAbyssalDepth(Vector2f loc)
Definition Misc.java:2330
Map< String, String > getMusicMap()
boolean isAtWorst(String id, RepLevel level)
boolean isAtBest(String id, RepLevel level)