Starsector API
Loading...
Searching...
No Matches
MonthlyReport.java
Go to the documentation of this file.
1package com.fs.starfarer.api.campaign.econ;
2
3import java.util.ArrayList;
4import java.util.Arrays;
5import java.util.LinkedHashMap;
6import java.util.LinkedList;
7import java.util.List;
8
9import com.fs.starfarer.api.Global;
10import com.fs.starfarer.api.campaign.CargoAPI;
11import com.fs.starfarer.api.campaign.SectorEntityToken;
12import com.fs.starfarer.api.impl.campaign.MonthlyReportNodeTooltipCreator;
13import com.fs.starfarer.api.impl.campaign.ids.Factions;
14import com.fs.starfarer.api.ui.TooltipMakerAPI.TooltipCreator;
15
16public class MonthlyReport {
17
18 public static String CREW = "node_id_crew";
19 public static String MARINES = "node_id_marines";
20 public static String FLEET = "node_id_fleet";
21 public static String OUTPOSTS = "node_id_outposts";
22 public static String PRODUCTION = "node_id_prod";
23 public static String PRODUCTION_WEAPONS = "node_id_prod_weapons";
24 //public static String SURPLUS = "node_id_surplus";
25 public static String OVERHEAD = "node_id_overhead";
26 public static String STOCKPILING = "node_id_stockpiling";
27 public static String RESTOCKING = "node_id_restocking";
28
29 public static String INCENTIVES = "node_id_incentives";
30 public static String INDUSTRIES = "node_id_industries";
31 public static String EXPORTS = "node_id_exports";
32 public static String STORAGE = "node_id_storage";
33 public static String ADMIN = "node_id_admin";
34 public static String STORAGE_CARGO = "node_id_storage_cargo";
35 public static String STORAGE_SHIPS = "node_id_storage_ships";
36
37 public static String LAST_MONTH_DEBT = "node_id_last_month_debt";
38 //public static String IMPORTS = "node_id_imports";
39
40 public static String OFFICERS = "node_id_officers";
41
49 public static class FDNode {
50 protected LinkedHashMap<String, FDNode> children;
51 public FDNode parent;
52 //public String sortString;
53 public String name;
54 public String icon;
55
56 public float income;
57 public float upkeep;
58 public float totalIncome;
59 public float totalUpkeep;
60
61 public Object custom;
62 public Object custom2;
63 public SectorEntityToken mapEntity;
64
65 public TooltipCreator tooltipCreator = null;
66 public Object tooltipParam;
67
68 public LinkedHashMap<String, FDNode> getChildren() {
69 if (children == null) return new LinkedHashMap<String, FDNode>();
70 return children;
71 }
72
73 public int getDepth() {
74 FDNode curr = this;
75 int count = 0;
76 while (curr.parent != null) {
77 curr = curr.parent;
78 count++;
79 }
80 return count;
81 }
82 }
83
84 private FDNode root = new FDNode();
85 private long timestamp;
86 private int debt = 0;
87 private int previousDebt = 0;
88
89 private MonthlyReportNodeTooltipCreator monthlyReportTooltip;
90 public MonthlyReportNodeTooltipCreator getMonthlyReportTooltip() {
91 if (monthlyReportTooltip == null) {
92 monthlyReportTooltip = new MonthlyReportNodeTooltipCreator();
93 }
94 return monthlyReportTooltip;
95 }
96
97 public void computeTotals() {
98 computeTotals(root);
99 }
100
101 public long getTimestamp() {
102 return timestamp;
103 }
104
105 public void setTimestamp(long timestamp) {
106 this.timestamp = timestamp;
107 }
108
109 public int getPreviousDebt() {
110 return previousDebt;
111 }
112
113 public void setPreviousDebt(int previousDebt) {
114 this.previousDebt = previousDebt;
115 }
116
117 public int getDebt() {
118 return debt;
119 }
120
121 public void setDebt(int debt) {
122 this.debt = debt;
123 }
124
125 public FDNode getRoot() {
126 return root;
127 }
128
129 protected void computeTotals(FDNode curr) {
130 curr.totalIncome = curr.income;
131 curr.totalUpkeep = curr.upkeep;
132
133 for (FDNode child : curr.getChildren().values()) {
134 computeTotals(child);
135 }
136
137 if (curr.parent != null) {
138 curr.parent.totalIncome += curr.totalIncome;
139 curr.parent.totalUpkeep += curr.totalUpkeep;
140 }
141 }
142
143 public List<FDNode> getAllNodes() {
144 List<FDNode> all = new ArrayList<FDNode>();
145 getAllNodes(root, all);
146 return all;
147 }
148
149 protected void getAllNodes(FDNode curr, List<FDNode> nodes) {
150 nodes.add(curr);
151
152 for (FDNode child : curr.getChildren().values()) {
153 getAllNodes(child, nodes);
154 }
155 }
156
157 public FDNode getNode(String ... path) {
158 return getNode(root, new LinkedList<String>(Arrays.asList(path)));
159 }
160
161 public FDNode getNode(FDNode from, String ... path) {
162 return getNode(from, new LinkedList<String>(Arrays.asList(path)));
163 }
164 public FDNode getNode(FDNode from, List<String> path) {
165 if (path.isEmpty()) return from;
166
167 String nextId = path.remove(0);
168 FDNode next = from.children == null ? null : from.children.get(nextId);
169 if (next == null) {
170 if (from.children == null) {
171 from.children = new LinkedHashMap<String, FDNode>();
172 }
173 next = new FDNode();
174 next.parent = from;
175 from.children.put(nextId, next);
176 }
177 return getNode(next, path);
178 }
179
180
181 public FDNode getColoniesNode() {
182 FDNode marketsNode = getNode(MonthlyReport.OUTPOSTS);
183 if (marketsNode.name == null) {
184 marketsNode.name = "Colonies";
185 marketsNode.custom = MonthlyReport.OUTPOSTS;
186 marketsNode.tooltipCreator = getMonthlyReportTooltip();
187 }
188 return marketsNode;
189 }
190
191 public FDNode getMarketNode(MarketAPI market) {
192 FDNode marketsNode = getColoniesNode();
193
194 FDNode mNode = getNode(marketsNode, market.getId());
195 if (mNode.name == null) {
196 mNode.name = market.getName() + " (" + market.getSize() + ")";
197 mNode.custom = market;
198 }
199 return mNode;
200 }
201
202 public FDNode getCounterShortageNode(MarketAPI market) {
203 FDNode mNode = getMarketNode(market);
204
205 FDNode sNode = getNode(mNode, MonthlyReport.STOCKPILING);
206 if (sNode.name == null) {
207 sNode.name = "Stockpiles used to counter shortages";
208 sNode.custom = MonthlyReport.STOCKPILING;
209 sNode.custom2 = Global.getFactory().createCargo(true);
210 ((CargoAPI)sNode.custom2).initMothballedShips(Factions.PLAYER);
211 sNode.tooltipCreator = getMonthlyReportTooltip();
212 }
213 return sNode;
214 }
215
216 public FDNode getRestockingNode(MarketAPI market) {
217 //FDNode mNode = getMarketNode(market);
218
219 FDNode mNode = getColoniesNode();
220
221 FDNode sNode = getNode(mNode, MonthlyReport.RESTOCKING);
222 if (sNode.name == null) {
223 sNode.name = "Stockpiles drawn by your fleet";
224 sNode.custom = MonthlyReport.RESTOCKING;
225 sNode.custom2 = Global.getFactory().createCargo(true);
226 ((CargoAPI)sNode.custom2).initMothballedShips(Factions.PLAYER);
227 sNode.tooltipCreator = getMonthlyReportTooltip();
228 }
229 return sNode;
230 }
231
232 public FDNode getDebtNode() {
233 FDNode debtNode = getNode(MonthlyReport.LAST_MONTH_DEBT);
234 if (debtNode.name == null) {
235 debtNode.name = "Last month's debt";
236 debtNode.custom = MonthlyReport.LAST_MONTH_DEBT;
237 debtNode.icon = Global.getSettings().getSpriteName("income_report", "generic_expense");
238 debtNode.tooltipCreator = getMonthlyReportTooltip();
239 }
240 return debtNode;
241 }
242
243 public static void main(String[] args) {
244 MonthlyReport data = new MonthlyReport();
245
246 data.getNode("test", "test1", "test2").income = 10;
247
248 System.out.println(data);
249 }
250}
251
252
253
254
255
static SettingsAPI getSettings()
Definition Global.java:51
static FactoryAPI getFactory()
Definition Global.java:35
FDNode getNode(FDNode from, String ... path)
void getAllNodes(FDNode curr, List< FDNode > nodes)
FDNode getNode(FDNode from, List< String > path)
MonthlyReportNodeTooltipCreator getMonthlyReportTooltip()
CargoAPI createCargo(boolean unlimitedStacks)
String getSpriteName(String category, String id)