Starsector API
Loading...
Searching...
No Matches
SleeperPodsSpecial.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.rulecmd.salvage.special;
2
3import com.fs.starfarer.api.Global;
4import com.fs.starfarer.api.campaign.CampaignFleetAPI;
5import com.fs.starfarer.api.campaign.InteractionDialogAPI;
6import com.fs.starfarer.api.characters.PersonAPI;
7import com.fs.starfarer.api.impl.campaign.ids.Commodities;
8import com.fs.starfarer.api.impl.campaign.rulecmd.AddRemoveCommodity;
9import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.SalvageSpecialInteraction.SalvageSpecialData;
10import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.SalvageSpecialInteraction.SalvageSpecialPlugin;
11
13
14 public static final String OPEN = "open";
15 public static final String NOT_NOW = "not_now";
16
17 public static enum SleeperSpecialType {
18 CREW,
19 MARINES,
20 OFFICER,
21 ADMIN,
22 ORGANS,
23 }
24// public static enum SleeperSpecialQuantity {
25// LOW,
26// MEDIUM,
27// HIGH,
28// }
29
30 public static class SleeperPodsSpecialData implements SalvageSpecialData {
31 public SleeperSpecialType type;
32 //public SleeperSpecialQuantity quantity;
33 public int min, max;
34 public PersonAPI officer;
35 public SleeperPodsSpecialData(SleeperSpecialType type, PersonAPI officer) {
36 this.type = type;
37 this.officer = officer;
38 min = max = 1;
39 }
40 public SleeperPodsSpecialData(SleeperSpecialType type, int min, int max) {
41 this.type = type;
42 this.min = min;
43 this.max = max;
44 }
45
46 public SalvageSpecialPlugin createSpecialPlugin() {
47 return new SleeperPodsSpecial();
48 }
49 }
50
51 private SleeperPodsSpecialData data;
52
53 private int quantity = 1;
54
56 }
57
58 @Override
59 public void init(InteractionDialogAPI dialog, Object specialData) {
60 super.init(dialog, specialData);
61
62 data = (SleeperPodsSpecialData) specialData;
63
64// if (data.quantity != null) {
65// switch (data.quantity) {
66// case LOW:
67// quantity = random.nextInt(10) + 5;
68// break;
69// case MEDIUM:
70// quantity = random.nextInt(20) + 10;
71// break;
72// case HIGH:
73// quantity = random.nextInt(50) + 25;
74// break;
75// }
76// }
77 quantity = data.min + random.nextInt(data.max - data.min + 1);
78
79 if (data.type == SleeperSpecialType.ORGANS) {
80 //quantity *= 0.5f;
81 if (quantity < 1) quantity = 1;
82 }
83
84 CampaignFleetAPI player = Global.getSector().getPlayerFleet();
85
86 int crewBerths = (int) (player.getCargo().getMaxPersonnel() - player.getCargo().getTotalPersonnel());
87// int officerBerths = (int) (Global.getSector().getPlayerPerson().getStats().getOfficerNumber().getModifiedValue() -
88// player.getFleetData().getOfficersCopy().size());
89 if (crewBerths < 0) crewBerths = 0;
90// if (officerBerths < 0) officerBerths = 0;
91
92 SleeperSpecialType type = data.type;
93
94 if (type == SleeperSpecialType.CREW) quantity = Math.min(crewBerths, quantity);
95 if (type == SleeperSpecialType.MARINES) quantity = Math.min(crewBerths, quantity);
96 //if (type == SleeperSpecialType.OFFICER) quantity = Math.min(officerBerths, quantity);
97 if (type == SleeperSpecialType.ADMIN || type == SleeperSpecialType.OFFICER) quantity = 1;
98
99 switch (type) {
100 case CREW:
101 initCrew();
102 break;
103 case MARINES:
104 initMarines();
105 break;
106 case OFFICER:
107 initOfficer();
108 break;
109 case ADMIN:
110 initOfficer();
111 break;
112 case ORGANS:
113 initOrgans();
114 break;
115 }
116 }
117
118
119 protected void initCrew() {
120 if (quantity <= 0) {
121 initNothing();
122 } else {
123 addText("While making a preliminary assessment, your salvage crews " +
124 "find some occupied sleeper pods still running on backup power.");
125
126 options.clearOptions();
127 options.addOption("Attempt to open the pods", OPEN);
128 options.addOption("Not now", NOT_NOW);
129 }
130 }
131
132 protected void initMarines() {
133 if (quantity <= 0) {
134 initNothing();
135 } else {
136 addText("While making a preliminary assessment, your salvage crews " +
137 "find some occupied mil-grade sleeper pods still running on backup power.");
138
139 options.clearOptions();
140 options.addOption("Attempt to open the pods", OPEN);
141 options.addOption("Not now", NOT_NOW);
142 }
143 }
144
145 protected void initOfficer() {
146 if (quantity <= 0) {
147 initNothing();
148 } else {
149 addText("While making a preliminary assessment, your salvage crews " +
150 "find a single occupied sleeper pod still running on backup power.");
151
152 options.clearOptions();
153 options.addOption("Attempt to open the pod", OPEN);
154 options.addOption("Not now", NOT_NOW);
155 }
156
157 }
158
159 protected void initOrgans() {
160 if (quantity <= 0) {
161 initNothing();
162 } else {
163 addText("While making a preliminary assessment, your salvage crews " +
164 "find some occupied sleeper pods still running on backup power.");
165
166 options.clearOptions();
167 options.addOption("Attempt to open the pods", OPEN);
168 options.addOption("Not now", NOT_NOW);
169 }
170
171 }
172
173
174 @Override
175 public void optionSelected(String optionText, Object optionData) {
176 if (OPEN.equals(optionData)) {
177
178 switch (data.type) {
179 case CREW:
180 addText("One by one, the pods begin to open as the thawing process completes. " +
181 "Most of the occupants come through alive, if somewhat dazed.");
182
183 playerFleet.getCargo().addCommodity(Commodities.CREW, quantity);
184 AddRemoveCommodity.addCommodityGainText(Commodities.CREW, quantity, text);
185
186 break;
187 case MARINES:
188 addText("One by one, the pods begin to open as the thawing process completes. " +
189 "Most of the occupants come through alive, if somewhat dazed.");
190
191 playerFleet.getCargo().addCommodity(Commodities.MARINES, quantity);
192 AddRemoveCommodity.addCommodityGainText(Commodities.MARINES, quantity, text);
193
194 break;
195 case OFFICER:
196 addText("The thawing process completes, and the pod opens. " +
197 "It contains an experienced officer, who joins you out of gratitude for being rescued.");
198
199 playerFleet.getFleetData().addOfficer(data.officer);
201 break;
202 case ADMIN:
203 addText("The thawing process completes, and the pod opens. " +
204 "It contains an experienced planetary administrator, who joins you out of gratitude for being rescued.");
205
206 Global.getSector().getCharacterData().addAdmin(data.officer);
208 break;
209 case ORGANS:
210 addText("One by one, the pods begin to open as the thawing process completes. " +
211 "Unfortunately, it's been too long, or something went wrong along the way, and there are no survivors - at least, not with any brain activity.");
212
213 playerFleet.getCargo().addCommodity(Commodities.ORGANS, quantity);
214 AddRemoveCommodity.addCommodityGainText(Commodities.ORGANS, quantity, text);
215 break;
216 }
217
218
219 setDone(true);
220 setShowAgain(false);
221 } else if (NOT_NOW.equals(optionData)) {
222 setDone(true);
223 setEndWithContinue(false);
224 setShowAgain(true);
225 }
226 }
227
228
229
230}
231
232
static SectorAPI getSector()
Definition Global.java:59
static void addAdminGainText(PersonAPI admin, TextPanelAPI text)
static void addOfficerGainText(PersonAPI officer, TextPanelAPI text)
static void addCommodityGainText(String commodityId, int quantity, TextPanelAPI text)