Starsector API
Loading...
Searching...
No Matches
CargoPodsEntityPlugin.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign;
2
3import com.fs.starfarer.api.Global;
4import com.fs.starfarer.api.campaign.CampaignEngineLayers;
5import com.fs.starfarer.api.campaign.CustomCampaignEntityAPI;
6import com.fs.starfarer.api.campaign.SectorEntityToken;
7import com.fs.starfarer.api.campaign.SectorEntityToken.VisibilityLevel;
8import com.fs.starfarer.api.combat.ViewportAPI;
9import com.fs.starfarer.api.impl.campaign.ids.Entities;
10import com.fs.starfarer.api.util.Misc;
11
13
14 public static float computeDetectionRange(float radius) {
15 float range = 500f + radius * 20f;
16 if (range > 2000) range = 2000;
17 return range;
18 }
19
20
21 //protected CustomCampaignEntityAPI entity;
22 protected transient GenericFieldItemManager manager;
23
24 protected float elapsed = 0;
25 protected float maxDays = 1f;
26 protected float extraDays = 0f;
27 protected Boolean neverExpire = null;
28
29 public void init(SectorEntityToken entity, Object pluginParams) {
30 super.init(entity, pluginParams);
31 entity.setDetectionRangeDetailsOverrideMult(0.5f);
32 //this.entity = (CustomCampaignEntityAPI) entity;
33 readResolve();
34
35// entity.getMemoryWithoutUpdate().set("$locked", true);
36// entity.getMemoryWithoutUpdate().set("$canUnlock", true);
37// entity.getMemoryWithoutUpdate().set("$trapped", true);
38 }
39
40 Object readResolve() {
42 manager.category = "misc";
43 manager.key = "cargoPods";
44 manager.cellSize = 32;
45
46 manager.minSize = 10;
47 manager.maxSize = 10;
48 //manager.numPieces = 15;
49
50 return this;
51 }
52
53 public void advance(float amount) {
54 float days = Global.getSector().getClock().convertToDays(amount);
55
56 float depth = Misc.getAbyssalDepth(entity);
57 if (depth >= 1f) {
58 days *= 5f;
59 }
60
61 elapsed += days;
62
63 if (!isNeverExpire()) {
64 if (elapsed >= maxDays + extraDays && maxDays >= 0) {
65 VisibilityLevel vis = entity.getVisibilityLevelToPlayerFleet();
66 boolean playerCanSee = entity.isInCurrentLocation() &&
67 (vis == VisibilityLevel.COMPOSITION_AND_FACTION_DETAILS ||
68 vis == VisibilityLevel.COMPOSITION_DETAILS);
69 if (!playerCanSee) {
70 maxDays = -1;
71 Misc.fadeAndExpire(entity);
72 neverExpire = true;
73 }
74 }
75 }
76
77 if (entity.isInCurrentLocation()) {
79 float radius = 10f + 10f * (float) Math.sqrt(manager.numPieces);
80
81 float range = computeDetectionRange(radius);
82 entity.getDetectedRangeMod().modifyFlat("gen", range);
83 }
84
85 manager.advance(amount);
86 }
87
88 public void updateBaseMaxDays() {
89 if (entity == null || entity.getCargo() == null) return;
90
91 float totalCapacity = entity.getCargo().getSpaceUsed() +
92 entity.getCargo().getFuel() +
93 entity.getCargo().getTotalPersonnel();
94
95 int minPieces = 5;
96 int numPieces = (int) (Math.sqrt(totalCapacity) / 1);
97 if (numPieces < minPieces) numPieces = minPieces;
98 if (numPieces > 40) numPieces = 40;
99
100 boolean cryo = entity.getCargo().getTotalPersonnel() > entity.getCargo().getSpaceUsed() + entity.getCargo().getFuel();
101 if (cryo) {
102 entity.setCustomDescriptionId("cryopods");
103 entity.setName("Cryo Pods");
104 } else {
105 entity.setCustomDescriptionId(Entities.CARGO_PODS);
106 entity.setName("Cargo Pods");
107 }
108
109 manager.numPieces = numPieces;
110
111 float radius = 10f + 10f * (float) Math.sqrt(manager.numPieces - (minPieces - 1));
112 ((CustomCampaignEntityAPI)entity).setRadius(radius);
113
114 maxDays = 5f + (numPieces - minPieces);
115 }
116
117 public float getRenderRange() {
118 return entity.getRadius() + 100f;
119 }
120
121 public void render(CampaignEngineLayers layer, ViewportAPI viewport) {
122 manager.render(layer, viewport);
123 }
124
125 public void setNeverExpire(Boolean neverExpire) {
126 this.neverExpire = neverExpire;
127 }
128
129 public Boolean isNeverExpire() {
130 return neverExpire != null && neverExpire;
131 }
132
133 public float getDaysLeft() {
134 return maxDays + extraDays - elapsed;
135 }
136
137
138 public float getElapsed() {
139 return elapsed;
140 }
141
142 public void setElapsed(float elapsed) {
143 this.elapsed = elapsed;
144 }
145
146 public float getExtraDays() {
147 return extraDays;
148 }
149
150 public void setExtraDays(float extraDays) {
151 this.extraDays = extraDays;
152 }
153
154}
155
156
157
static SectorAPI getSector()
Definition Global.java:59
void render(CampaignEngineLayers layer, ViewportAPI viewport)
void init(SectorEntityToken entity, Object pluginParams)
void render(CampaignEngineLayers layer, ViewportAPI viewport)