Starsector API
Loading...
Searching...
No Matches
FactionHostilityIntel.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.intel;
2
3import java.awt.Color;
4import java.util.Random;
5import java.util.Set;
6
7import org.apache.log4j.Logger;
8
9import com.fs.starfarer.api.Global;
10import com.fs.starfarer.api.campaign.FactionAPI;
11import com.fs.starfarer.api.campaign.RepLevel;
12import com.fs.starfarer.api.campaign.SectorEntityToken;
13import com.fs.starfarer.api.impl.campaign.ids.Tags;
14import com.fs.starfarer.api.ui.LabelAPI;
15import com.fs.starfarer.api.ui.SectorMapAPI;
16import com.fs.starfarer.api.ui.TooltipMakerAPI;
17import com.fs.starfarer.api.util.Misc;
18
20
21 public static Logger log = Global.getLogger(FactionHostilityIntel.class);
22
23 public static final float MIN_DAYS = 180f;
24 public static final float CHECK_INTERVAL = 60f;
25 public static final float END_PROB = 0.25f;
26
27
28 protected FactionAPI one;
29 protected FactionAPI two;
30 protected String id;
31 protected float daysUntilCheck;
32
33 protected float initialRelationship;
34
35 protected Random random = new Random();
36
37 public FactionHostilityIntel(FactionAPI one, FactionAPI two) {
38 FactionAPI temp = two;
39 if (one.getDisplayName().compareTo(two.getDisplayName()) > 0) {
40 two = one;
41 one = temp;
42 }
43
44 this.one = one;
45 this.two = two;
46
47
49
50 log.info(String.format("Making factions hostile: %s <-> %s", one.getDisplayName(), two.getDisplayName()));
51 initialRelationship = one.getRelationship(two.getId());
52 one.setRelationship(two.getId(), RepLevel.HOSTILE);
53
55
56 // let the player find out regardless of where they are - they could by checking
57 // the relationship in the intel screen anyway
58 Global.getSector().getIntelManager().addIntel(this);
59 }
60
61 public void endHostilties() {
62 log.info(String.format("Ending hostilities: %s <-> %s", one.getDisplayName(), two.getDisplayName()));
64 one.setRelationship(two.getId(), initialRelationship);
66 sendUpdateIfPlayerHasIntel(new Object(), false);
67 }
68
69 @Override
70 protected void advanceImpl(float amount) {
71
72 float days = Global.getSector().getClock().convertToDays(amount);
73 daysUntilCheck -= days;
74
75 if (daysUntilCheck <= 0) {
76 daysUntilCheck = CHECK_INTERVAL * (0.5f + 1f * random.nextFloat());
77 if (random.nextFloat() < END_PROB) {
79 }
80 }
81 }
82
83
84 public String getId() {
85 return id;
86 }
87
88 public FactionAPI getOne() {
89 return one;
90 }
91
92 public FactionAPI getTwo() {
93 return two;
94 }
95
96
97 protected void addBulletPoints(TooltipMakerAPI info, ListInfoMode mode) {
98
99 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
static SettingsAPI getSettings()
Definition Global.java:51
static Logger getLogger(Class c)
Definition Global.java:26
static SectorAPI getSector()
Definition Global.java:59
void sendUpdateIfPlayerHasIntel(Object listInfoParam, TextPanelAPI textPanel)
void addBulletPoints(TooltipMakerAPI info, ListInfoMode mode)
void createIntelInfo(TooltipMakerAPI info, ListInfoMode mode)
void createSmallDescription(TooltipMakerAPI info, float width, float height)
String getSpriteName(String category, String id)