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.combat.CombatEngineAPI;
16import com.fs.starfarer.api.impl.campaign.ids.Entities;
17import com.fs.starfarer.api.impl.campaign.ids.Factions;
18import com.fs.starfarer.api.impl.campaign.ids.Tags;
19import com.fs.starfarer.api.util.Misc;
20
22
23 public static String KEEP_PLAYING_LOCATION_MUSIC_DURING_ENCOUNTER_MEM_KEY = "$playLocationMusicDuringEnc";
24 public static String MUSIC_SET_MEM_KEY = "$musicSetId";
25
26
27 public static String MUSIC_ENCOUNTER_MYSTERIOUS_AGGRO = "music_encounter_mysterious";
28 public static String MUSIC_ENCOUNTER_MYSTERIOUS_NON_AGGRESSIVE = "music_encounter_mysterious_non_aggressive";
29 public static String MUSIC_ENCOUNTER_NEUTRAL = "music_encounter_neutral";
30
31
32 public static Object CAMPAIGN_SYSTEM = new Object();
33 public static Object CAMPAIGN_HYPERSPACE = new Object();
34 public static Object NO_MUSIC = new Object();
35 public static Object COMBAT = new Object();
36 public static Object TITLE = new Object();
37 public static Object MARKET = new Object();
38 public static Object ENCOUNTER = new Object();
39 public static Object PLANET_SURVEY = new Object();
40
41 public static Object CUSTOM = new Object();
42
43 public static Map<String, String> stringTokens = new HashMap<String, String>();
44
50 public static Object getToken(String str) {
51 if (!stringTokens.containsKey(str)) {
52 stringTokens.put(str, str);
53 }
54 return stringTokens.get(str);
55 }
56
57 public static String SYSTEM_MUSIC_PREFIX = "core_sys_music_";
58
60 CampaignFleetAPI playerFleet = Global.getSector().getPlayerFleet();
61 if (playerFleet.getContainingLocation() instanceof StarSystemAPI) {
62 /*
63 Just returning CAMPAIGN_SYSTEM and letting getMusicSetIdForCampaignStateToken()
64 return the musicSetId misses the case where there's a transition between
65 two star systems with different music, without hyperspace travel in between -
66 since there would be no state transition (due to it being the same CAMPAIGN_SYSTEM state),
67 a restart of the music - and a change to a different music set - would not be triggered.
68
69 Since the state ID includes the music set id, this means that moving between
70 two systems with the same $musicSetId will not trigger a state change and
71 the same music will just keep playing uninterrupted.
72 */
73 StarSystemAPI system = (StarSystemAPI) playerFleet.getContainingLocation();
74 String musicSetId = system.getMemoryWithoutUpdate().getString(MUSIC_SET_MEM_KEY);
75 if (musicSetId != null) {
76 return getToken(SYSTEM_MUSIC_PREFIX + musicSetId);
77 }
78 return CAMPAIGN_SYSTEM;
79 }
80// float depth = Misc.getAbyssalDepthOfPlayer();
81// if (depth > 0.5f) {
82// return NO_MUSIC;
83// }
85 }
86
87 public String getMusicSetIdForCombat(CombatEngineAPI engine) {
88 return "music_combat";
89 }
90
91 public String getMusicSetIdForTitle() {
92 return "music_title";
93 }
94
95
96 public float getMusicSetVolumeForCampaignStateToken(Object token, Object param) {
97 if (token == CAMPAIGN_HYPERSPACE) {
98 //float depth = Misc.getAbyssalDepthOfPlayer();
99 // need to check this way so that the hyperspace track doesn't fade back in
100 // right after transitiong to an abyssal system (as the track fades out)
101 CampaignFleetAPI pf = Global.getSector().getPlayerFleet();
102 float depth = 0f;
103 if (pf != null) depth = Misc.getAbyssalDepth(pf.getLocationInHyperspace());
104 float vol = 1f - depth;
105 if (vol > 1f) vol = 1f;
106 if (vol < 0f) vol = 0f;
107 return vol;
108 }
109 return 1f;
110 }
111
112 public String getMusicSetIdForCampaignStateToken(Object token, Object param) {
113 if (token == MARKET) {
114 return getMarketMusicSetId(param);
115 }
116 if (token == ENCOUNTER) {
117 return getEncounterMusicSetId(param);
118 }
119 if (token == CAMPAIGN_SYSTEM ||
120 (token instanceof String && ((String)token).startsWith(SYSTEM_MUSIC_PREFIX))) {
122 }
123 if (token == CAMPAIGN_HYPERSPACE) {
125 }
126 if (token == PLANET_SURVEY) {
127 return getPlanetSurveyMusicSetId(param);
128 }
129 if (token == NO_MUSIC) {
130 return null;
131 }
132 return null;
133 }
134
139 protected String getPlanetSurveyMusicSetId(Object param) {
140 return "music_survey_and_scavenge";
141 }
142
143 protected String getHyperspaceMusicSetId() {
144 return "music_campaign_hyperspace";
145 }
146
147 protected String getStarSystemMusicSetId() {
148 CampaignFleetAPI playerFleet = Global.getSector().getPlayerFleet();
149 if (playerFleet.getContainingLocation() instanceof StarSystemAPI) {
150 StarSystemAPI system = (StarSystemAPI) playerFleet.getContainingLocation();
151 String musicSetId = system.getMemoryWithoutUpdate().getString(MUSIC_SET_MEM_KEY);
152 if (musicSetId != null) return musicSetId;
153
154 if (system.hasTag(Tags.THEME_CORE) ||
155 !Misc.getMarketsInLocation(system, Factions.PLAYER).isEmpty()) {
156 return "music_campaign";
157 }
158 }
159
160 return "music_campaign_non_core";
161 }
162
163 protected String getEncounterMusicSetId(Object param) {
164 if (param instanceof SectorEntityToken) {
165 SectorEntityToken token = (SectorEntityToken) param;
166
167 String musicSetId = token.getMemoryWithoutUpdate().getString(MUSIC_SET_MEM_KEY);
168 if (musicSetId != null) return musicSetId;
169
170 if (Entities.ABYSSAL_LIGHT.equals(token.getCustomEntityType())) {
172 }
173 if (Entities.CORONAL_TAP.equals(token.getCustomEntityType())) {
175 }
176 if (Entities.WRECK.equals(token.getCustomEntityType())) {
178 }
179 if (Entities.DERELICT_GATEHAULER.equals(token.getCustomEntityType())) {
181 }
182
183 if (Entities.DEBRIS_FIELD_SHARED.equals(token.getCustomEntityType())) {
184 return "music_survey_and_scavenge";
185 }
186 if (token.hasTag(Tags.GATE)) {
188 }
189 if (token.hasTag(Tags.SALVAGEABLE)) {
190 if (token.getMemoryWithoutUpdate() != null && token.getMemoryWithoutUpdate().getBoolean("$hasDefenders")) {
191 if (token.getMemoryWithoutUpdate().getBoolean("$limboMiningStation")) {
193 }
194 if (token.getMemoryWithoutUpdate().getBoolean("$limboWormholeCache")) {
196 }
198 }
199 return "music_survey_and_scavenge";
200 }
201 if (token.hasTag(Tags.SALVAGE_MUSIC)) {
202 return "music_survey_and_scavenge";
203 }
204
205 if (token.getFaction() != null) {
206 FactionAPI faction = (FactionAPI) token.getFaction();
207 String type = null;
208 //MemoryAPI mem = token.getMemoryWithoutUpdate();
209 boolean hostile = false;
210 boolean knowsWhoPlayerIs = false;
211 if (token instanceof CampaignFleetAPI) {
212 CampaignFleetAPI fleet = (CampaignFleetAPI) token;
213 if (fleet.getAI() instanceof ModularFleetAIAPI) {
214 hostile = ((ModularFleetAIAPI) fleet.getAI()).isHostileTo(Global.getSector().getPlayerFleet());
215 }
216 knowsWhoPlayerIs = fleet.knowsWhoPlayerIs();
217 }
218
219 if (faction.isAtWorst(Factions.PLAYER, RepLevel.FAVORABLE) && knowsWhoPlayerIs && !hostile) {
220 type = "encounter_friendly";
221 } else if ((faction.isAtBest(Factions.PLAYER, RepLevel.SUSPICIOUS) && knowsWhoPlayerIs) || hostile) {
222 type = "encounter_hostile";
223 } else {
224 type = "encounter_neutral";
225 }
226
227 if (type != null) {
228 musicSetId = faction.getMusicMap().get(type);
229 if (musicSetId != null) {
230 return musicSetId;
231 }
232 }
233
234 musicSetId = null;
235 if (faction.isAtWorst(Factions.PLAYER, RepLevel.FAVORABLE)) {
236 musicSetId = "music_default_encounter_friendly";
237 } else if (faction.isAtBest(Factions.PLAYER, RepLevel.SUSPICIOUS)) {
238 musicSetId = "music_default_encounter_hostile";
239 } else {
240 musicSetId = "music_default_encounter_neutral";
241 }
242 return musicSetId;
243 }
244 }
245 return null;
246 }
247
248
249 protected String getMarketMusicSetId(Object param) {
250 if (param instanceof MarketAPI) {
251 MarketAPI market = (MarketAPI) param;
252
253 String musicSetId = market.getMemoryWithoutUpdate().getString(MUSIC_SET_MEM_KEY);
254 if (musicSetId != null) return musicSetId;
255
256 if (market.getPrimaryEntity() != null &&
257 market.getPrimaryEntity().getMemoryWithoutUpdate().getBoolean("$abandonedStation")) {
258 return getPlanetSurveyMusicSetId(param);
259 }
260
261 FactionAPI faction = market.getFaction();
262 if (faction != null) {
263 String type = null;
264 if (faction.isAtWorst(Factions.PLAYER, RepLevel.FAVORABLE)) {
265 type = "market_friendly";
266 } else if (faction.isAtBest(Factions.PLAYER, RepLevel.SUSPICIOUS)) {
267 type = "market_hostile";
268 } else {
269 type = "market_neutral";
270 }
271
272 if (type != null) {
273 musicSetId = faction.getMusicMap().get(type);
274 if (musicSetId != null) {
275 return musicSetId;
276 }
277 }
278
279 musicSetId = null;
280 if (faction.isAtWorst(Factions.PLAYER, RepLevel.FAVORABLE)) {
281 musicSetId = "music_default_market_friendly";
282 } else if (faction.isAtBest(Factions.PLAYER, RepLevel.SUSPICIOUS)) {
283 musicSetId = "music_default_market_hostile";
284 } else {
285 musicSetId = "music_default_market_neutral";
286 }
287 return musicSetId;
288 }
289 }
290 return null;
291 }
292}
293
294
295
296
297
298
299
300
static SectorAPI getSector()
Definition Global.java:59
String getMusicSetIdForCampaignStateToken(Object token, Object param)
float getMusicSetVolumeForCampaignStateToken(Object token, Object param)