001package com.fs.starfarer.api.campaign;
002
003import java.awt.Color;
004import java.util.LinkedHashSet;
005import java.util.List;
006import java.util.Map;
007import java.util.Random;
008import java.util.Set;
009
010import org.json.JSONObject;
011
012import com.fs.starfarer.api.campaign.rules.HasMemory;
013import com.fs.starfarer.api.campaign.rules.MemoryAPI;
014import com.fs.starfarer.api.characters.FullName.Gender;
015import com.fs.starfarer.api.characters.PersonAPI;
016import com.fs.starfarer.api.characters.RelationshipAPI;
017import com.fs.starfarer.api.fleet.ShipFilter;
018import com.fs.starfarer.api.fleet.ShipRolePick;
019import com.fs.starfarer.api.util.WeightedRandomPicker;
020
021/**
022 * @author Alex Mosolov
023 *
024 * Copyright 2012 Fractal Softworks, LLC
025 */
026public interface FactionAPI extends HasMemory {
027        
028        public static enum ShipPickMode {
029                IMPORTED,
030                ALL,
031                PRIORITY_THEN_ALL,
032                PRIORITY_ONLY,
033        }
034        public static class ShipPickParams implements Cloneable {
035                public ShipPickMode mode;
036                public int maxFP = 1000;
037                public Long timestamp = null;
038                public Boolean blockFallback = null;
039                
040                public ShipPickParams(ShipPickMode mode, int maxFP, Long timestamp, Boolean blockFallback) {
041                        this.mode = mode;
042                        this.maxFP = maxFP;
043                        this.timestamp = timestamp;
044                        this.blockFallback = blockFallback;
045                }
046                public ShipPickParams(ShipPickMode mode, int maxFP, Long timestamp) {
047                        this.mode = mode;
048                        this.maxFP = maxFP;
049                        this.timestamp = timestamp;
050                }
051                public ShipPickParams(ShipPickMode mode, int maxFP) {
052                        this(mode, maxFP, null);
053                }
054                public ShipPickParams(ShipPickMode mode) {
055                        this(mode, 1000);
056                }
057                public ShipPickParams() {
058                        this(ShipPickMode.PRIORITY_THEN_ALL, 1000);
059                }
060                @Override
061                public ShipPickParams clone() {
062                        try {
063                                return (ShipPickParams) super.clone();
064                        } catch (CloneNotSupportedException e) {
065                                return null;
066                        }
067                }
068        
069                public static ShipPickParams all() {
070                        return new ShipPickParams(ShipPickMode.ALL);
071                }
072                public static ShipPickParams priority() {
073                        return new ShipPickParams(ShipPickMode.PRIORITY_THEN_ALL);
074                }
075                public static ShipPickParams imported() {
076                        return new ShipPickParams(ShipPickMode.IMPORTED);
077                }
078        }
079        
080        
081        void adjustRelationship(String id, float delta);
082        boolean adjustRelationship(String id, float delta, RepLevel limit);
083        void setRelationship(String id, float newValue);
084        void setRelationship(String id, RepLevel level);
085        
086        boolean ensureAtBest(String id, RepLevel level);
087        boolean ensureAtWorst(String id, RepLevel level);
088
089        RepLevel getRelationshipLevel(FactionAPI faction);
090        RepLevel getRelationshipLevel(String id);
091
092        /**
093         * True if the faction (identified by id) is equal to or friendlier than the given level.
094         * @param id faction id
095         * @param level the least friendly the faction can be
096         */
097        boolean isAtWorst(String id, RepLevel level);
098        /**
099         * True if the faction (identified by other) is equal to or friendlier than the given level.
100         * @param other faction
101         * @param level the least friendly the faction can be
102         */
103        boolean isAtWorst(FactionAPI other, RepLevel level);
104        /**
105         * True if the faction (identified by id) is equal to or more hostile than the given level.
106         * @param id faction id
107         * @param level the least hostile the faction can be
108         */
109        boolean isAtBest(String id, RepLevel level);
110        /**
111         * True if the faction (identified by other) is equal to or more hostile than the given level.
112         * @param other faction
113         * @param level the least hostile the faction can be
114         */
115        boolean isAtBest(FactionAPI other, RepLevel level);
116        /**
117         * True if the faction is hostile to the given faction.
118         */
119        boolean isHostileTo(FactionAPI other);
120        /**
121         * True if the faction is hostile to the given faction id.
122         * @param other faction id
123         */
124        boolean isHostileTo(String other);
125        
126//      boolean isNeutralTo(FactionAPI other);
127//      boolean isFriendlyTo(FactionAPI other);
128//      boolean isNeutralTo(String other);
129//      boolean isFriendlyTo(String other);
130        
131        
132        float getRelationship(String id);
133        String getId();
134        String getDisplayName();
135        String getDisplayNameWithArticle();
136        
137        Color getColor();
138        Color getBaseUIColor();
139        Color getGridUIColor();
140        Color getDarkUIColor();
141        Color getSecondaryUIColor();
142        
143        /**
144         * Brighter/slightly cyan version of getBaseUIColor()
145         * @return
146         */
147        Color getBrightUIColor();
148                
149        boolean isNeutralFaction();
150        boolean isPlayerFaction();
151        
152        
153        List<String> getStockFleetIds();
154
155//      boolean isIllegal(String commodityId);
156        //boolean isHostile(FactionAPI other);
157        
158        MemoryAPI getMemory();
159        
160        
161        
162        /**
163         * May add more than one ship if a fallback specifies to add multiple ships.
164         * (For example, 2 small freighters if a medium freighter isn't available.)
165         * 
166         * Returns a total weight of ships added to the fleet. Generally will return
167         * 1 when ships were added, 0 when they weren't, and a number >1 when adding, say,
168         * a medium ship instead of a small one because no small ones are available.
169         * @param role
170         * @param maxFP
171         * @param fleet
172         * @return
173         */
174        float pickShipAndAddToFleet(String role, ShipPickParams params, CampaignFleetAPI fleet);
175        
176        String getFleetTypeName(String type);
177        String getDisplayNameLong();
178        String getDisplayNameLongWithArticle();
179        String getEntityNamePrefix();
180        
181        
182        Color getRelColor(String otherFactionId);
183        Set<String> getIllegalCommodities();
184        boolean isIllegal(String commodityId);
185        boolean isIllegal(CargoStackAPI stack);
186        
187        List<ShipRolePick> pickShip(String role, ShipPickParams params);
188        List<ShipRolePick> pickShip(String role, ShipPickParams params, ShipFilter filter, Random random);
189        
190        void makeCommodityIllegal(String commodityId);
191        void makeCommodityLegal(String commodityId);
192        
193        float getTariffFraction();
194        float getTollFraction();
195        float getFineFraction();
196        String getInternalCommsChannel();
197        
198        PersonAPI createRandomPerson();
199        PersonAPI createRandomPerson(Gender gender);
200        String getLogo();
201        
202        JSONObject getCustom();
203        MemoryAPI getMemoryWithoutUpdate();
204        Color getRelColor(RepLevel level);
205        RelationshipAPI getRelToPlayer();
206        
207        String getRank(String id);
208        String getPost(String id);
209        String getDisplayNameIsOrAre();
210        
211        String pickPersonality();
212        boolean getCustomBoolean(String key);
213        String getCustomString(String key);
214        
215        
216        boolean isShowInIntelTab();
217        void setShowInIntelTab(boolean isShowInIntelTab);
218        String getCrest();
219        String getPersonNamePrefix();
220        String getPersonNamePrefixAOrAn();
221        String pickRandomShipName();
222        float pickShipAndAddToFleet(String role, ShipPickParams params, CampaignFleetAPI fleet, Random random);
223        
224        Set<String> getVariantsForRole(String roleId);
225        PersonAPI createRandomPerson(Gender gender, Random random);
226        PersonAPI createRandomPerson(Random random);
227        float getCustomFloat(String key);
228        int getSecondarySegments();
229        
230        String getDisplayNameOverride();
231        void setDisplayNameOverride(String displayNameOverride);
232        String getDisplayNameWithArticleOverride();
233        void setDisplayNameWithArticleOverride(String displayNameWithArticleOverride);
234        String getDisplayIsOrAreOverride();
235        void setDisplayIsOrAreOverride(String displayIsOrAreOverride);
236        String getShipNamePrefixOverride();
237        void setShipNamePrefixOverride(String shipNamePrefixOverride);
238        String getPersonNamePrefixAOrAnOverride();
239        void setPersonNamePrefixAOrAnOverride(String personNamePrefixAOrAnOverride);
240        String getFactionLogoOverride();
241        void setFactionLogoOverride(String factionLogoOverride);
242        String getFactionCrestOverride();
243        void setFactionCrestOverride(String factionCrestOverride);
244        WeightedRandomPicker<String> getPortraits(Gender gender);
245        
246        Set<String> getKnownShips();
247        void addKnownShip(String hullId, boolean setTimestamp);
248        
249        /**
250         * All of the blueprints specified in the .faction file are re-added to the faction 
251         * every time a savegame is loaded. To make blueprint removal permanent, the list of 
252         * things-to-remove needs to be stored and they need to be re-removed on every game load.
253         */
254        void removeKnownShip(String hullId);
255        Set<String> getKnownWeapons();
256        void addKnownWeapon(String weaponId, boolean setTimestamp);
257        
258        /**
259         * All of the blueprints specified in the .faction file are re-added to the faction 
260         * every time a savegame is loaded. To make blueprint removal permanent, the list of 
261         * things-to-remove needs to be stored and they need to be re-removed on every game load.
262         */
263        void removeKnownWeapon(String weaponId);
264        Set<String> getKnownFighters();
265        void addKnownFighter(String wingId, boolean setTimestamp);
266        
267        /**
268         * All of the blueprints specified in the .faction file are re-added to the faction 
269         * every time a savegame is loaded. To make blueprint removal permanent, the list of 
270         * things-to-remove needs to be stored and they need to be re-removed on every game load.
271         */
272        void removeKnownFighter(String wingId);
273        Set<String> getKnownIndustries();
274        void addKnownIndustry(String industryId);
275        void removeKnownIndustry(String industryId);
276        boolean knowsShip(String hullId);
277        boolean knowsWeapon(String weaponId);
278        boolean knowsFighter(String wingId);
279        boolean knowsIndustry(String industryId);
280        
281        Set<String> getPriorityShips();
282        void addPriorityShip(String hullId);
283        void removePriorityShip(String hullId);
284        boolean isShipPriority(String hullId);
285        Set<String> getPriorityWeapons();
286        void addPriorityWeapon(String weaponId);
287        void removePriorityWeapon(String weaponId);
288        boolean isWeaponPriority(String weaponId);
289        Set<String> getPriorityFighters();
290        void addPriorityFighter(String wingId);
291        void removePriorityFighter(String wingId);
292        boolean isFighterPriority(String wingId);
293        
294        
295        boolean isAutoEnableKnownWeapons();
296        void setAutoEnableKnownWeapons(boolean autoEnableKnownWeapons);
297        boolean isAutoEnableKnownShips();
298        void setAutoEnableKnownShips(boolean autoEnableKnownShips);
299        boolean isAutoEnableKnownFighters();
300        void setAutoEnableKnownFighters(boolean autoEnableKnownFighters);
301        boolean isAutoEnableKnownHullmods();
302        void setAutoEnableKnownHullmods(boolean autoEnableKnownHullmods);
303        
304        void addKnownHullMod(String modId);
305        void removeKnownHullMod(String modId);
306        boolean knowsHullMod(String modId);
307        Set<String> getKnownHullMods();
308        void addPriorityHullMod(String modId);
309        void removePriorityHullMod(String modId);
310        boolean isHullModPriority(String modId);
311        Set<String> getPriorityHullMods();
312        FactionDoctrineAPI getDoctrine();
313        Map<String, Float> getVariantOverrides();
314        
315        /**
316         * Hulls that are restricted to specific variants, defined in "variantOverrides" section of the .faction file.
317         * @return
318         */
319        LinkedHashSet<String> getOverriddenHulls();
320        Map<String, Float> getHullFrequency();
321        
322        /**
323         * Hulls that will be in fleets even when the market's ship & weapons supply is from another faction.
324         * Generally faction-specific skins of base hulls known to all factions.
325         * @return
326         */
327        Set<String> getAlwaysKnownShips();
328        void addUseWhenImportingShip(String hullId);
329        void removeUseWhenImportingShip(String hullId);
330        boolean useWhenImportingShip(String hullId);
331        
332        /**
333         * Should be called after direct manipulation of the faction's known/always known/priority ship hulls.
334         * Automatically called by the add/removeXXXShip methods.
335         */
336        void clearShipRoleCache();
337        WeightedRandomPicker<String> getPersonalityPicker();
338        FactionProductionAPI getProduction();
339        Map<String, Long> getWeaponTimestamps();
340        Map<String, Long> getFighterTimestamps();
341        Map<String, Long> getShipTimestamps();
342        void setShipTimestampToNow(String hullId);
343        void setWeaponTimestampToNow(String weaponId);
344        void setFighterTimestampToNow(String wingId);
345        
346        boolean isShipKnownAt(String hullId, Long timestamp);
347        boolean isWeaponKnownAt(String weaponId, Long timestamp);
348        boolean isFighterKnownAt(String wing, Long timestamp);
349        int getNumAvailableForRole(String roleId, ShipPickMode mode);
350        
351        String getDisplayNameHasOrHave();
352        String getDisplayNameWithArticleWithoutArticle();
353        String pickRandomShipName(Random random);
354        
355        /**
356         * Used to figure out how many fleet points raids/expeditions etc divide out for each "large" fleet.
357         * When going above 30 ships, fleets replace some smaller ships with larger ones. This FP limit is
358         * where that still produces fleets that aren't *too* top-heavy.
359         * @return
360         */
361        float getApproximateMaxFPPerFleet(ShipPickMode mode);
362        Map<String, String> getMusicMap();
363        String getBarSound();
364        int getRepInt(String id);
365        String pickVoice(PersonImportance importance, Random random);
366        String getShipNamePrefix();
367        
368        Map<String, Float> getWeaponSellFrequency();
369        Map<String, Float> getFighterSellFrequency();
370        Map<String, Float> getHullmodSellFrequency();
371        FactionSpecAPI getFactionSpec();
372        
373        void initSpecIfNeeded();
374        JSONObject getCustomJSONObject(String key);
375        float getVariantWeightForRole(String roleId, ShipPickMode mode);
376        Color getSecondaryColorOverride();
377        void setSecondaryColorOverride(Color secondaryOverride);
378        int getSecondaryColorSegmentsOverride();
379        void setSecondaryColorSegmentsOverride(int secondaryColorSegmentsOverride);
380        String pickRandomShipName(String prefix);
381        LinkedHashSet<String> getRestrictToVariants();
382        
383        
384}
385
386
387
388