001package com.fs.starfarer.api;
002
003import com.fs.starfarer.api.combat.AutofireAIPlugin;
004import com.fs.starfarer.api.combat.DroneLauncherShipSystemAPI;
005import com.fs.starfarer.api.combat.MissileAIPlugin;
006import com.fs.starfarer.api.combat.MissileAPI;
007import com.fs.starfarer.api.combat.ShipAIPlugin;
008import com.fs.starfarer.api.combat.ShipAPI;
009import com.fs.starfarer.api.combat.WeaponAPI;
010import com.fs.starfarer.api.fleet.FleetMemberAPI;
011import com.thoughtworks.xstream.XStream;
012
013/**
014 * Extend this class instead of implementing ModPlugin for convenience if you do not
015 * intend to implement all the methods. This will also help avoid your mod breaking
016 * when new methods are added to ModPlugin, since default implemenations will be
017 * added here and your implementation will inherit them.
018 *
019 * <hr>
020 *
021 * <p>
022 * While having a ModPlugin for your mod is not strictly necessary, it serves as an entry point for all kinds
023 * of useful things, such as faction initialization, adding custom scripts and picking AI plugins.
024 * <p>
025 * You need to instruct the game to load your implementation of this class by e.g. adding it to your mod_info.json:
026 * "modPlugin":"my.package.name.MyModBasePlugin"
027 * 
028 * @author Alex Mosolov
029 *
030 *
031 * Copyright 2013 Fractal Softworks, LLC
032 */
033public class BaseModPlugin implements ModPlugin {
034
035        /**
036         *
037         * {@inheritDoc}
038         * <hr>
039         *
040         * Code in here gets executed after the game gets saved. The main use for this is in combination with beforeGameSave.
041         * If you did clean-up code in beforeGameSave, you can re-add your stuff in here.
042         *
043         * <p>Example:</p>
044         * <pre>
045         *     <code>
046         *         Global.getSector().getListenerManager().addListener(new MyListener());
047         *     </code>
048         * </pre>
049         *
050         */
051        public void afterGameSave() {
052                
053        }
054
055        /**
056         *
057         * {@inheritDoc}
058         *
059         * <hr>
060         *
061         * Code in here gets executed before the game gets saved. This is mainly useful for doing cleanup.
062         * Anything that is part of the sector gets serialized when the game is saved. If you, for instance, add custom
063         * listeners to the sector and the game gets saved, they are added to the save file. If you
064         * then later e.g. rename the class of those listeners, that will break mod compatibility and users won't be able
065         * to upgrade your mod in an ongoing campaign. Also, players won't be able to remove your mod from an ongoing
066         * campaign. To avoid this issue, you can simply clean up anything that you added to the sector that doesn't need to
067         * be saved in this method and then re-add it in the afterGameSave-method.
068         *
069         * <p>Example:</p>
070         * <pre>
071         *     <code>
072         *                      while (Global.getSector().getListenerManager().hasListenerOfClass(MyListener.class)){
073         *             Global.getSector().getListenerManager().removeListenerOfClass(MyListener.class);
074         *         }
075         *     </code>
076         * </pre>
077         *
078         */
079        public void beforeGameSave() {
080                
081        }
082
083        /**
084         * {@inheritDoc}
085         */
086        public void onGameSaveFailed() {
087                
088        }
089
090        /**
091         * {@inheritDoc}
092         */
093        public void onApplicationLoad() throws Exception {
094                
095        }
096
097        /**
098         * {@inheritDoc}
099         */
100        public void onEnabled(boolean wasEnabledBefore) {
101                
102        }
103
104        /**
105         * {@inheritDoc}
106         * <hr>
107         * <p>
108         * In here, you should do all kinds of initialization logic, such as adding transient scripts,
109         * registering campaign plugins, adding custom sensor ghosts etc.
110         * <p>
111         *
112         * @param newGame if true, a new campaign has just been started. Sector generation logic should only
113         *                be executed if this is true.
114         */
115        public void onGameLoad(boolean newGame) {
116                
117        }
118
119        /**
120         * {@inheritDoc}
121         */
122        public void onNewGame() {
123                
124        }
125
126        /**
127         * {@inheritDoc}
128         */
129        public void onNewGameAfterEconomyLoad() {
130                
131        }
132
133        /**
134         * {@inheritDoc}
135         * <hr>
136         *
137         * <p>Example:</p>
138         * <pre>
139         *     <code>
140         *                      if(ship.getVariant().getHullVariantId().equals("myVariantId")){
141         *             return new PluginPick<ShipAIPlugin>(new MyAi(), CampaignPlugin.PickPriority.MOD_GENERAL)
142         *         }
143         *         return null;
144         *     </code>
145         * </pre>
146         * <p>
147         *
148         * @param member fleetMemeber of the ship in question. Can be used to inform your decision if/which AI to choose
149         * @param ship the ship in question
150         * @return a plugin pick containing the chosen ship AI, or simply null to use the default AI
151         */
152        public PluginPick<ShipAIPlugin> pickShipAI(FleetMemberAPI member, ShipAPI ship) {
153                return null;
154        }
155
156        /**
157         *
158         * {@inheritDoc}
159         * <hr>
160         *
161         * This code gets executed whenever the game selects an autofire AI for a weapon, which is usually at start of combat
162         * This is mainly relevant if your weapon has some quirks that the regular AI doesn't understand.
163         *
164         * <p>Example:</p>
165         * <pre>
166         *     <code>
167         *         if(weapon.getId().equals("myWeaponId")){
168         *             return new PluginPick<>(new MyAi(), CampaignPlugin.PickPriority.MOD_GENERAL);
169         *         }
170         *         return null;
171         *     </code>
172         * </pre>
173         * <p>
174         *
175         * @param weapon the weapon in question
176         * @return a plugin pick containing the chosen AI, or simply null to use the default
177         */
178        public PluginPick<AutofireAIPlugin> pickWeaponAutofireAI(WeaponAPI weapon) {
179                return null;
180        }
181
182        public PluginPick<ShipAIPlugin> pickDroneAI(ShipAPI drone,
183                        ShipAPI mothership, DroneLauncherShipSystemAPI system) {
184                return null;
185        }
186
187        /**
188         *
189         * {@inheritDoc}
190         * <hr>
191         *
192         * This method is how you can assign custom AI to missiles. If you want to write your own missile AI,
193         * I would recommend having a look at the MagicMissileAI available in MagicLib for inspiration.
194         *
195         * <p>Example:</p>
196         * <pre>
197         *     <code>
198         *         if(missile.getProjectileSpecId().equals("myMissileProjId")){
199         *             return new PluginPick<>(new MyAi(), CampaignPlugin.PickPriority.MOD_GENERAL);
200         *         }
201         *         return null;
202         *     </code>
203         * </pre>
204         *
205         * @param missile the missile in question. This is usually the main deciding factor.
206         * @param launchingShip the ship that launched the missile. This can usually be ignored
207         * @return a plugin pick containing the chosen AI, or simply null to use the default
208         */
209        public PluginPick<MissileAIPlugin> pickMissileAI(MissileAPI missile,
210                        ShipAPI launchingShip) {
211                return null;
212        }
213
214        /**
215         * {@inheritDoc}
216         */
217        public void onNewGameAfterTimePass() {
218                
219        }
220
221        public void configureXStream(XStream x) {
222                
223        }
224
225        public void onNewGameAfterProcGen() {
226                // TODO Auto-generated method stub
227                
228        }
229
230        /**
231         * {@inheritDoc}
232         */
233        public void onDevModeF8Reload() {
234                // TODO Auto-generated method stub
235                
236        }
237
238        @Override
239        public void onAboutToStartGeneratingCodex() {
240                // TODO Auto-generated method stub
241                
242        }
243
244        @Override
245        public void onAboutToLinkCodexEntries() {
246                // TODO Auto-generated method stub
247                
248        }
249
250        @Override
251        public void onCodexDataGenerated() {
252                // TODO Auto-generated method stub
253                
254        }
255
256}