Starsector API
Loading...
Searching...
No Matches
ConditionManager.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.econ.impl;
2
3import com.fs.starfarer.api.Global;
4import com.fs.starfarer.api.campaign.econ.Industry;
5import com.fs.starfarer.api.campaign.econ.MarketAPI;
6import com.fs.starfarer.api.campaign.econ.EconomyAPI.EconomyUpdateListener;
7import com.fs.starfarer.api.impl.campaign.ids.Conditions;
8import com.fs.starfarer.api.impl.campaign.ids.Industries;
9
10public class ConditionManager implements EconomyUpdateListener {
11
12 public static final String KEY = "$core_marketConditionManager";
13
14 public static ConditionManager getInstance() {
15 Object test = Global.getSector().getMemoryWithoutUpdate().get(KEY);
16 if (test == null) {
17 test = new ConditionManager();
18 Global.getSector().getMemoryWithoutUpdate().set(KEY, test);
19 }
20 return (ConditionManager) test;
21 }
22
23 protected Object readResolve() {
24 return this;
25 }
26
28 Global.getSector().getEconomy().addUpdateListener(this);
29 }
30
31
32 public void economyUpdated() {
33
34 for (MarketAPI market : Global.getSector().getEconomy().getMarketsCopy()) {
35 if (market.isHidden()) continue;
36
37 int urban = 0;
38 int industrial = 0;
39 int rural = 0;
40 int pollution = 0;
41
42 for (Industry curr : market.getIndustries()) {
43 if (!curr.isIndustry()) continue;
44
45 if (curr.getSpec().hasTag(Industries.TAG_URBAN)) {
46 urban++;
47 }
48 if (curr.getSpec().hasTag(Industries.TAG_RURAL)) {
49 rural++;
50 }
51 if (curr.getSpec().hasTag(Industries.TAG_INDUSTRIAL)) {
52 industrial++;
53 pollution++;
54 }
55 }
56
57 if (market.hasCondition(Conditions.URBANIZED_POLITY)) {
58 if (urban <= 0 || industrial > 0 || rural > 0) {
59 market.removeCondition(Conditions.URBANIZED_POLITY);
60 }
61 }
62 if (market.hasCondition(Conditions.RURAL_POLITY)) {
63 if (rural <= 0 || urban > 0 || industrial > 0) {
64 market.removeCondition(Conditions.RURAL_POLITY);
65 }
66 }
67 if (market.hasCondition(Conditions.INDUSTRIAL_POLITY)) {
68 if (industrial <= 0 || urban > 0 || rural > 0) {
69 market.removeCondition(Conditions.INDUSTRIAL_POLITY);
70 }
71 }
72
73 if (market.getSize() <= 3) {
74 continue;
75 }
76
77 if (!market.hasCondition(Conditions.URBANIZED_POLITY)) {
78 if (urban > 0 && industrial + rural <= 0) {
79 market.addCondition(Conditions.URBANIZED_POLITY);
80 }
81 }
82 if (!market.hasCondition(Conditions.RURAL_POLITY)) {
83 if (rural > 0 && industrial + urban <= 0) {
84 market.addCondition(Conditions.RURAL_POLITY);
85 }
86 }
87 if (!market.hasCondition(Conditions.INDUSTRIAL_POLITY)) {
88 if (industrial > 0 && rural + urban <= 0) {
89 market.addCondition(Conditions.INDUSTRIAL_POLITY);
90 }
91 }
92
93 if (!market.hasCondition(Conditions.POLLUTION) && market.hasCondition(Conditions.HABITABLE) &&
94 market.getSize() >= 5 && pollution >= 3) {
95 market.addCondition(Conditions.POLLUTION);
96 }
97
98 }
99
100 }
101
102 public void commodityUpdated(String commodityId) {
103
104 }
105
106 public boolean isEconomyListenerExpired() {
107 return false;
108 }
109
110}
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
static SectorAPI getSector()
Definition Global.java:59