001package com.fs.starfarer.api.impl.campaign.intel;
002
003import java.awt.Color;
004import java.util.Random;
005import java.util.Set;
006
007import org.apache.log4j.Logger;
008
009import com.fs.starfarer.api.Global;
010import com.fs.starfarer.api.campaign.FactionAPI;
011import com.fs.starfarer.api.campaign.RepLevel;
012import com.fs.starfarer.api.campaign.SectorEntityToken;
013import com.fs.starfarer.api.impl.campaign.ids.Tags;
014import com.fs.starfarer.api.ui.LabelAPI;
015import com.fs.starfarer.api.ui.SectorMapAPI;
016import com.fs.starfarer.api.ui.TooltipMakerAPI;
017import com.fs.starfarer.api.util.Misc;
018
019public class FactionHostilityIntel extends BaseIntelPlugin {
020
021        public static Logger log = Global.getLogger(FactionHostilityIntel.class);
022        
023        public static final float MIN_DAYS = 180f;
024        public static final float CHECK_INTERVAL = 60f;
025        public static final float END_PROB = 0.25f;
026        
027        
028        protected FactionAPI one;
029        protected FactionAPI two;
030        protected String id;
031        protected float daysUntilCheck;
032        
033        protected float initialRelationship;
034        
035        protected Random random = new Random();
036        
037        public FactionHostilityIntel(FactionAPI one, FactionAPI two) {
038                FactionAPI temp = two;
039                if (one.getDisplayName().compareTo(two.getDisplayName()) > 0) {
040                        two = one;
041                        one = temp;
042                }
043                
044                this.one = one;
045                this.two = two;
046                
047                
048                id = FactionHostilityManager.getConflictId(one, two);
049                
050                log.info(String.format("Making factions hostile: %s <-> %s", one.getDisplayName(), two.getDisplayName()));
051                initialRelationship = one.getRelationship(two.getId());
052                one.setRelationship(two.getId(), RepLevel.HOSTILE);
053                
054                daysUntilCheck = MIN_DAYS;
055                
056                // let the player find out regardless of where they are - they could by checking
057                // the relationship in the intel screen anyway
058                Global.getSector().getIntelManager().addIntel(this);
059        }
060        
061        public void endHostilties() {
062                log.info(String.format("Ending hostilities: %s <-> %s", one.getDisplayName(), two.getDisplayName()));
063                FactionHostilityManager.getInstance().notifyRecentlyEnded(id);
064                one.setRelationship(two.getId(), initialRelationship);
065                endAfterDelay();
066                sendUpdateIfPlayerHasIntel(new Object(), false);
067        }
068        
069        @Override
070        protected void advanceImpl(float amount) {
071                
072                float days = Global.getSector().getClock().convertToDays(amount);
073                daysUntilCheck -= days;
074                
075                if (daysUntilCheck <= 0) {
076                        daysUntilCheck = CHECK_INTERVAL * (0.5f + 1f * random.nextFloat());
077                        if (random.nextFloat() < END_PROB) {
078                                endHostilties();
079                        }
080                }
081        }
082
083
084        public String getId() {
085                return id;
086        }
087
088        public FactionAPI getOne() {
089                return one;
090        }
091
092        public FactionAPI getTwo() {
093                return two;
094        }
095        
096        
097        protected void addBulletPoints(TooltipMakerAPI info, ListInfoMode mode) {
098                
099                Color h = Misc.getHighlightColor();
100                Color g = Misc.getGrayColor();
101                float pad = 3f;
102                float opad = 10f;
103                
104                float initPad = pad;
105                if (mode == ListInfoMode.IN_DESC) initPad = opad;
106                
107                Color tc = getBulletColorForMode(mode);
108                
109                bullet(info);
110                //boolean isUpdate = getListInfoParam() != null;
111                
112//              info.addPara("Factions: ", tc, initPad);
113//              indent(info);
114//              LabelAPI label = info.addPara("%s and %s", 0f, tc,
115//                               h, one.getDisplayName(), two.getDisplayName());
116//              label.setHighlight(one.getDisplayName(), two.getDisplayName());
117//              label.setHighlightColors(one.getBaseUIColor(), two.getBaseUIColor());
118                
119                info.addPara(one.getDisplayName(), 0f, tc,
120                                         one.getBaseUIColor(), one.getDisplayName());
121                info.addPara(two.getDisplayName(), 0f, tc,
122                                         two.getBaseUIColor(), two.getDisplayName());
123                        
124                unindent(info);
125        }
126        
127        @Override
128        public void createIntelInfo(TooltipMakerAPI info, ListInfoMode mode) {
129                Color h = Misc.getHighlightColor();
130                Color g = Misc.getGrayColor();
131                Color c = getTitleColor(mode);
132                float pad = 3f;
133                float opad = 10f;
134                
135                info.addPara(getName(), c, 0f);
136                
137                addBulletPoints(info, mode);
138        }
139        
140        public String getSortString() {
141                return "Hostilities";
142        }
143        
144        public String getName() {
145                String base = "Hostilities";
146                if (isEnding()) {
147                        if (isSendingUpdate()) {
148                                return base + " Ended";
149                        }
150                        return base + " (Ended)";
151                }
152                return base;
153        }
154        
155        @Override
156        public FactionAPI getFactionForUIColors() {
157                return Global.getSector().getPlayerFaction();
158        }
159
160        public String getSmallDescriptionTitle() {
161                return getName();
162        }
163        
164        public void createSmallDescription(TooltipMakerAPI info, float width, float height) {
165                
166                Color h = Misc.getHighlightColor();
167                Color g = Misc.getGrayColor();
168                Color tc = Misc.getTextColor();
169                float pad = 3f;
170                float opad = 10f;
171
172                info.addImages(width, 128, opad, opad, one.getCrest(), two.getCrest());
173                
174                if (isEnding()) {
175                        LabelAPI label = info.addPara("Open conflict between " + one.getDisplayNameWithArticle() + 
176                                        " and " + two.getDisplayNameWithArticle() + " has recently ended.",
177                                        opad);
178                        label.setHighlight(one.getDisplayNameWithArticleWithoutArticle(), two.getDisplayNameWithArticleWithoutArticle());
179                        label.setHighlightColors(one.getBaseUIColor(), two.getBaseUIColor());
180                } else {
181                        LabelAPI label = info.addPara("Simmering tensions between " + one.getDisplayNameWithArticle() + 
182                                        " and " + two.getDisplayNameWithArticle() + " have broken out into open conflict.",
183                                        opad);
184                        label.setHighlight(one.getDisplayNameWithArticleWithoutArticle(), two.getDisplayNameWithArticleWithoutArticle());
185                        label.setHighlightColors(one.getBaseUIColor(), two.getBaseUIColor());
186                }
187                
188//              LabelAPI header = info.addSectionHeading("${data.defaultValue}", Alignment.MID, 0f);
189//              header.getPosition().inTL(1.4f, 10f);
190                
191//              String font = Global.getSettings().getString("defaultFont");
192//              info.addCheckbox(200, 28, "Testing!", UICheckboxSize.TINY, opad);
193//              info.addCheckbox(200, 28, "Testing!", UICheckboxSize.SMALL, opad);
194//              info.addCheckbox(200, 28, "Testing!", font, Misc.getHighlightColor(), UICheckboxSize.LARGE, opad);
195//              info.addTextField(200, opad);
196                
197//              info.addPara("FEWFWEFWE", opad);
198                
199//              info.addPara("wkefhuiwehfuweffewfewfeddewefewewefwefwewefwefweehfuwefwewefwefwehfuwefwewefwefwehfuwefwewefwefwkwejfwffhwejkfhkwejfh423wfwhel" +
200//                              "fewfwefwefwefweh[%s]fh2fwfwefwefwefwefwfkwghfieuwhfekhwejkuhfiohwef1wef2wef3wef4wefewfwefwenABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ\n"
201//                              + "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ\n\nABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ", 10f,
202//                              tc, h, "5%/6%/7%/8%");
203//              info.addPara("wkefhuiwehfuweffewfewfe[%s]wefwefweee123eee" + "\u3002" + 
204//                              "ddewefewewefwefwe[%s]wefwefweehfuwdfeefwewefwefwehfuwefwe[%s]wefwefwehfuwefwewefwefwkwejfwffhwejkfhkwejfh423wfwhel" +
205//                              "fewfwefwef[%s]fh2fwfwefwefwefwefwfkwghfieuwhfekhwejkuhfiohwef1w[%s]ef2wef3wef4wefewfwefwe", 10f,
206//                              tc, h, "20", "4X", "103", "5%/6%/7%/8%", "54%");
207//              
208//              info.addPara("wkefhuiwehfuweffewfewfe[%s]wefwefweeeeddewefewewefwefwe[%s]wefwefweehfuwdfeefwewefwefwehfuwefwe[%s]wefwefwehfuwefwewefwefwkwejfwffhwejkfhkwejfh423wfwhel" +
209//                              "fewfwefwefwefweh[%s]fh2fwfwefwefwefwefwfkwghfieuwhfekhwejkuhfiohwef1w[%s]ef2wef3wef4wefewfwefwe", 10f,
210//                              tc, h, "20", "4X", "103", "5%/6%/7%/8%", "54%");
211
212//        TooltipMakerAPI listPanel = info;
213//        List<ShipVariantAPI> blueprints = new ArrayList<ShipVariantAPI>();
214//        for (int i = 0; i < 20; i++) {
215//            blueprints.add(Global.getSettings().getVariant("crig_Standard"));
216//        }
217//        float summaryOffset = 0f;
218//        for (ShipVariantAPI blueprint : blueprints) {
219//            addBlueprintEntry(listPanel, blueprint);
220//            //summaryOffset += 9f;
221//            summaryOffset += 0f;
222//        }
223//        listPanel.addSpacer(-summaryOffset);
224//
225//        addGenericButton(info, width, "TESTING", "TESTING");
226//        addGenericButton(info, width, "TESTING", "TESTING");
227//        addGenericButton(info, width, "TESTING", "TESTING");
228//        addGenericButton(info, width, "TESTING", "TESTING");
229//        addGenericButton(info, width, "TESTING", "TESTING");
230//        addGenericButton(info, width, "TESTING", "TESTING");
231//        addGenericButton(info, width, "TESTING", "TESTING");
232//        addGenericButton(info, width, "TESTING", "TESTING");
233//        addGenericButton(info, width, "TESTING", "TESTING");
234//        addGenericButton(info, width, "TESTING", "TESTING");
235//        addGenericButton(info, width, "TESTING", "TESTING");
236//        addGenericButton(info, width, "TESTING", "TESTING");
237//        addGenericButton(info, width, "TESTING", "TESTING");
238//        addGenericButton(info, width, "TESTING", "TESTING");
239//        addGenericButton(info, width, "TESTING", "TESTING");
240//        addGenericButton(info, width, "TESTING", "TESTING");
241//        addGenericButton(info, width, "TESTING", "TESTING");
242//        addGenericButton(info, width, "TESTING", "TESTING");
243//        addGenericButton(info, width, "TESTING", "TESTING");
244                
245//              PersonAPI person = OfficerManagerEvent.createOfficer(Global.getSector().getPlayerFaction(), 5);
246//              info.addSkillPanel(person, opad);
247//              info.addSkillPanelOneColumn(person, opad);
248                
249//              PlanetAPI jangala = (PlanetAPI) Global.getSector().getEntityById("jangala");
250//              info.showPlanetInfo(jangala, opad);
251//              info.showPlanetInfo(jangala, 100, 100, true, opad);
252//              info.showPlanetInfo(jangala, 50, 50, false, opad);
253//              info.showPlanetInfo(jangala, width, width, true, opad);
254//              info.addCheckbox(300, 20, "Test", "TEST", UICheckboxSize.LARGE, 10f);
255        }
256        
257//    @Override
258//      public void buttonPressConfirmed(Object buttonId, IntelUIAPI ui) {
259//              super.buttonPressConfirmed(buttonId, ui);
260//              System.out.println("TESTING " + buttonId);
261//      }
262//
263//      private static void addBlueprintEntry(TooltipMakerAPI listPanel, ShipVariantAPI blueprint) {
264//        ButtonAPI checkbox = listPanel.addAreaCheckbox("", null, Misc.getDarkPlayerColor(),
265//                Misc.getDarkPlayerColor(), Misc.getDarkPlayerColor(),
266//                300f, 30f, 1f);
267//        checkbox.getPosition().setXAlignOffset(0f);
268//        listPanel.addSpacer(0f);
269//        //listPanel.getPrev().getPosition().setXAlignOffset(-15f);
270//        FleetMemberAPI dummyMember = Global.getFactory().createFleetMember(FleetMemberType.SHIP, blueprint);
271//        List<FleetMemberAPI> memberAsList = new ArrayList<FleetMemberAPI>();
272//        memberAsList.add(dummyMember);
273//        listPanel.addShipList(1, 1, 30f, Misc.getDarkPlayerColor(), memberAsList, 0f);
274//        UIComponentAPI hullIcon = listPanel.getPrev();
275//        hullIcon.getPosition().setYAlignOffset(30f);
276//        listPanel.addSpacer(10f);
277//        //listPanel.getPrev().getPosition().setXAlignOffset(25f);
278//    }
279    
280        
281        public String getIcon() {
282                return Global.getSettings().getSpriteName("intel", "hostilities");
283        }
284        
285        public Set<String> getIntelTags(SectorMapAPI map) {
286                Set<String> tags = super.getIntelTags(map);
287                tags.add(Tags.INTEL_HOSTILITIES);
288                tags.add(one.getId());
289                tags.add(two.getId());
290                return tags;
291        }
292
293        @Override
294        public SectorEntityToken getMapLocation(SectorMapAPI map) {
295                return null;
296        }
297
298
299}
300
301
302