001package com.fs.starfarer.api.campaign;
002
003import java.util.List;
004import java.util.Map;
005
006import java.awt.Color;
007
008import org.lwjgl.util.vector.Vector2f;
009
010import com.fs.starfarer.api.EveryFrameScript;
011import com.fs.starfarer.api.campaign.CampaignEventListener.FleetDespawnReason;
012import com.fs.starfarer.api.campaign.JumpPointAPI.JumpDestination;
013import com.fs.starfarer.api.campaign.ReputationActionResponsePlugin.ReputationAdjustmentResult;
014import com.fs.starfarer.api.campaign.comm.IntelManagerAPI;
015import com.fs.starfarer.api.campaign.comm.MessagePriority;
016import com.fs.starfarer.api.campaign.econ.EconomyAPI;
017import com.fs.starfarer.api.campaign.econ.MarketAPI;
018import com.fs.starfarer.api.campaign.events.CampaignEventManagerAPI;
019import com.fs.starfarer.api.campaign.events.CampaignEventPlugin;
020import com.fs.starfarer.api.campaign.listeners.ListenerManagerAPI;
021import com.fs.starfarer.api.campaign.rules.MemoryAPI;
022import com.fs.starfarer.api.campaign.rules.RulesAPI;
023import com.fs.starfarer.api.characters.AbilityPlugin;
024import com.fs.starfarer.api.characters.ImportantPeopleAPI;
025import com.fs.starfarer.api.characters.MutableCharacterStatsAPI;
026import com.fs.starfarer.api.characters.PersonAPI;
027import com.fs.starfarer.api.combat.EngagementResultAPI;
028import com.fs.starfarer.api.combat.ViewportAPI;
029import com.fs.starfarer.api.loading.CampaignPingSpec;
030
031
032/**
033 * Note: generics can not be used in scripts.
034 * They are used in this API purely to show the return/parameter types of functions more clearly.
035 * @author Alex Mosolov
036 *
037 * Copyright 2012 Fractal Softworks, LLC
038 */
039@SuppressWarnings("unchecked")
040public interface SectorAPI {
041        /**
042         * Can be used (including by classes that are not part of the savegame - i.e. ModPlugin or 
043         * transient CampaignPlugin implementations) to save data between sessions.
044         * @return
045         */
046        Map<String, Object> getPersistentData();
047        
048        void registerPlugin(CampaignPlugin plugin);
049        void unregisterPlugin(String pluginId);
050        
051        StarSystemAPI getStarSystem(String name);
052        StarSystemAPI createStarSystem(String name);
053        List<StarSystemAPI> getStarSystems();
054        void removeStarSystem(StarSystemAPI system);
055        void setCurrentLocation(LocationAPI location);
056        
057        LocationAPI getHyperspace();
058        
059        /**
060         * @param fleet
061         * @param jumpLocation can be null. If not, fleet will attempt to reach it before jumping. Failure will result in aborted jump.
062         * @param dest
063         */
064        void doHyperspaceTransition(CampaignFleetAPI fleet, SectorEntityToken jumpLocation, JumpDestination dest);
065        
066        
067        //CampaignFleetAPI createFleet(String factionId, String fleetTypeId);
068        CampaignClockAPI getClock();
069        
070        CampaignFleetAPI getPlayerFleet();
071        
072        FactionAPI getFaction(String factionId);
073        List<FactionAPI> getAllFactions();
074        
075        List<String> getAllWeaponIds();
076        List<String> getAllEmptyVariantIds();
077        List<String> getAllFighterWingIds();
078        
079        
080        CampaignUIAPI getCampaignUI();
081        
082        CampaignEventManagerAPI getEventManager();
083        
084        void setPaused(boolean paused);
085        boolean isPaused();
086        
087        void addScript(EveryFrameScript script);
088        void removeScriptsOfClass(Class c);
089        void removeScript(EveryFrameScript script);
090        
091        void addTransientScript(EveryFrameScript script);
092        void removeTransientScript(EveryFrameScript script);
093        
094        
095        LocationAPI getCurrentLocation();
096        
097        LocationAPI getRespawnLocation();
098        void setRespawnLocation(LocationAPI respawnLocation);
099        Vector2f getRespawnCoordinates();
100        
101        
102        CharacterDataAPI getCharacterData();
103        
104        
105        /**
106         * Does nothing. Replaced with getIntelManager().
107         */
108        @Deprecated void reportEventStage(CampaignEventPlugin event, String stage, MessagePriority priority);
109        
110        /**
111         * Does nothing. Replaced with getIntelManager().
112         */
113        @Deprecated void reportEventStage(CampaignEventPlugin event, String stage, SectorEntityToken sendFrom, MessagePriority priority);
114        
115        /**
116         * Does nothing. Replaced with getIntelManager().
117         */
118        @Deprecated void reportEventStage(CampaignEventPlugin event, String stage, SectorEntityToken sendFrom, MessagePriority priority, OnMessageDeliveryScript onDelivery);
119        
120        RulesAPI getRules();
121        
122        
123        long getLastPlayerBattleTimestamp();
124        boolean isLastPlayerBattleWon();
125        
126        /**
127         * "global" memory.
128         * @return
129         */
130        MemoryAPI getMemory();
131        MemoryAPI getMemoryWithoutUpdate();
132        
133        IntelDataAPI getIntel();
134        
135        
136        /**
137         * Will look for the entity in all LocationAPIs.
138         * @param id
139         * @return
140         */
141        SectorEntityToken getEntityById(String id);
142        
143
144        /**
145         * Iterates through hyperspace and all star systems.
146         * @param tag
147         * @return
148         */
149        List<SectorEntityToken> getEntitiesWithTag(String tag);
150        
151        
152        EconomyAPI getEconomy();
153
154        
155        
156        
157        void addListener(CampaignEventListener listener);
158        void addTransientListener(CampaignEventListener listener);
159        void addListenerWithTimeout(CampaignEventListener listener, float daysToKeep);
160        void removeListener(CampaignEventListener listener);
161        List<CampaignEventListener> getAllListeners();
162        
163        void reportPlayerMarketTransaction(PlayerMarketTransaction transaction);
164        void reportFleetDespawned(CampaignFleetAPI fleet, FleetDespawnReason reason, Object param);
165        
166        
167        // this gets called automatically when a fleet is added to a location for the first time
168        //void reportFleetSpawned(CampaignFleetAPI fleet);
169        
170        
171        void reportFleetJumped(CampaignFleetAPI fleet, SectorEntityToken from, JumpDestination to);
172        void reportFleetReachedEntity(CampaignFleetAPI fleet, SectorEntityToken entity);
173        
174        
175        /**
176         * Called once per each autoresolve round of the battle.
177         * Also called after a player battle occurred.
178         * 
179         * Fleets and their compositons snapshotted right before the autoresolve round.
180         * @param battle
181         * @param primaryWinner 
182         */
183        void reportBattleOccurred(CampaignFleetAPI primaryWinner, BattleAPI battle);
184        
185        /**
186         * Called after an autoresolve round that finishes a battle, after reportBattleOccurred.
187         * Also called after a player battle occurred.
188         * 
189         * Fleets and their compositons snapshotted right before the autoresolve round.
190         * @param battle
191         * @param primaryWinner
192         */
193        void reportBattleFinished(CampaignFleetAPI primaryWinner, BattleAPI battle);
194
195        
196        /**
197         * Adjust the player's reputation with the specified faction, based on the action.
198         * 
199         * This method will pick the highest-priority ReputationActionResponsePlugin and
200         * call its handlePlayerReputationAction() method with these parameters.
201         * 
202         * See CoreCampaignPluginImpl.handlePlayerReputationAction() for an implementation example.
203         * 
204         * @param action
205         * @param faction
206         * @return
207         */
208        ReputationAdjustmentResult adjustPlayerReputation(Object action, String factionId);
209        
210        /**
211         * Adjust the player's reputation with the specified person, based on the action.
212         * 
213         * This method will pick the highest-priority ReputationActionResponsePlugin and
214         * call its handlePlayerReputationAction() method with these parameters.
215         * 
216         * See CoreCampaignPluginImpl.handlePlayerReputationAction() for an implementation example.
217         * 
218         * @param action
219         * @param person
220         * @return
221         */
222        ReputationAdjustmentResult adjustPlayerReputation(Object action, PersonAPI person);
223
224        
225        /**
226         * See data/campaign/pings.json for ping types.
227         * @param entity
228         * @param pingType
229         */
230        EveryFrameScript addPing(SectorEntityToken entity, String pingType);
231
232        
233        /**
234         * Shouldn't have to call this as the relevant showInteractionDialog() methods already do.
235         * @param dialog
236         */
237        void reportShowInteractionDialog(InteractionDialogAPI dialog);
238
239        
240        /**
241         * Player opened the core UI while interacting with an entity that has a market.
242         * @param market
243         */
244        void reportPlayerOpenedMarket(MarketAPI market);
245
246        
247        void reportPlayerReputationChange(String faction, float delta);
248        void reportPlayerReputationChange(PersonAPI person, float delta);
249        
250        void reportPlayerEngagement(EngagementResultAPI result);
251        
252        /**
253         * true during the during-game-creation time passing.
254         * @return
255         */
256        boolean isInFastAdvance();
257
258        PersonAPI getPlayerPerson();
259
260        
261        void reportPlayerOpenedMarketAndCargoUpdated(MarketAPI market);
262        void reportEncounterLootGenerated(FleetEncounterContextPlugin plugin, CargoAPI loot);
263        void reportPlayerClosedMarket(MarketAPI market);
264
265        void reportPlayerActivatedAbility(AbilityPlugin ability, Object param);
266        void reportPlayerDeactivatedAbility(AbilityPlugin ability, Object param);
267        
268        void reportPlayerDumpedCargo(CargoAPI cargo);
269        
270        ImportantPeopleAPI getImportantPeople();
271
272        FactionAPI getPlayerFaction();
273
274        EveryFrameScript addPing(SectorEntityToken entity, String pingType, Color colorOverride);
275
276        ViewportAPI getViewport();
277
278        /**
279         * All star systems and hyperspace.
280         * @return
281         */
282        List<LocationAPI> getAllLocations();
283
284        String getDifficulty();
285        void setDifficulty(String difficulty);
286
287        boolean isIronMode();
288
289        boolean hasScript(Class<?> clazz);
290
291        PluginPickerAPI getPluginPicker();
292
293        String getSeedString();
294        void setSeedString(String seedString);
295
296        String genUID();
297
298        PersistentUIDataAPI getUIData();
299
300        void setInFastAdvance(boolean isInNewGameAdvance);
301        boolean isInNewGameAdvance();
302        void setInNewGameAdvance(boolean isInNewGameAdvance);
303
304        void setPlayerFleet(CampaignFleetAPI playerFleet);
305
306        void setLastPlayerBattleTimestamp(long lastPlayerBattleTimestamp);
307
308        void setLastPlayerBattleWon(boolean lastPlayerBattleWon);
309
310        void reportPlayerDidNotTakeCargo(CargoAPI cargo);
311
312        List<EveryFrameScript> getScripts();
313        List<EveryFrameScript> getTransientScripts();
314
315        GenericPluginManagerAPI getGenericPlugins();
316
317        EveryFrameScript addPing(SectorEntityToken entity, CampaignPingSpec custom);
318
319        void reportEconomyMonthEnd();
320        void reportEconomyTick(int iterIndex);
321
322        MutableCharacterStatsAPI getPlayerStats();
323
324        AutofitVariantsAPI getAutofitVariants();
325
326        IntelManagerAPI getIntelManager();
327        
328        ListenerManagerAPI getListenerManager();
329
330        void removeTransientScriptsOfClass(Class c);
331
332        long getPlayerBattleSeed();
333        void setPlayerBattleSeed(long nextPlayerBattleSeed);
334
335        NascentGravityWellAPI createNascentGravityWell(SectorEntityToken target, float radius);
336
337        boolean hasTransientScript(Class<?> clazz);
338
339        List<SectorEntityToken> getCustomEntitiesWithTag(String tag);
340
341        void doHyperspaceTransition(CampaignFleetAPI fleetAPI, SectorEntityToken jumpLocation, JumpDestination dest, float initialDelay);
342
343        void layInCourseFor(SectorEntityToken target);
344
345        boolean isFastForwardIteration();
346
347        void setFastForwardIteration(boolean isFastForwardIteration);
348
349        /**
350         * Same as getCharacterData().getMemoryWithoutUpdate()
351         * @return
352         */
353        MemoryAPI getPlayerMemoryWithoutUpdate();
354
355        /**
356         * Useful for remove star systems from scripts etc where using removeStarSystem() would cause a 
357         * ConcurrentModificationException.
358         * @param system
359         */
360        void removeStarSystemNextFrame(StarSystemAPI system);
361
362        SectorEntityToken getMousedOverEntity();
363
364        MarketAPI getCurrentlyOpenMarket();
365        void setCurrentlyOpenMarket(MarketAPI currentlyOpenMarket);
366
367        boolean isInSectorGen();
368        void setInSectorGen(boolean isInSectorGen);
369
370}
371
372
373
374
375
376