Starsector API
Loading...
Searching...
No Matches
GenericFieldItemManager.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import org.lwjgl.opengl.GL11;
7
8import com.fs.starfarer.api.Global;
9import com.fs.starfarer.api.campaign.CampaignEngineLayers;
10import com.fs.starfarer.api.campaign.SectorEntityToken;
11import com.fs.starfarer.api.combat.ViewportAPI;
12
14
15 protected transient List<GenericFieldItemSprite> items;
16 protected transient boolean inited = false;
17
18 protected SectorEntityToken entity;
19
20 public int numPieces, cellSize;
21 public float minSize, maxSize;
22 public String category, key;
23
24 public GenericFieldItemManager(SectorEntityToken entity) {
25 this.entity = entity;
26 }
27
28 Object readResolve() {
29 return this;
30 }
31
32 public void advance(float amount) {
33 if (amount <= 0) {
34 return; // happens during game load
35 }
36 if (!entity.isInCurrentLocation()) {
37 items = null;
38 inited = false;
39 return;
40 }
41
42 float days = Global.getSector().getClock().convertToDays(amount);
44
45 List<GenericFieldItemSprite> remove = new ArrayList<GenericFieldItemSprite>();
46 for (GenericFieldItemSprite item : items) {
47 item.advance(days);
48 if (item.isDone()) {
49 remove.add(item);
50 }
51 }
52 items.removeAll(remove);
53
55 }
56
57 public void render(CampaignEngineLayers layer, ViewportAPI viewport) {
58 float alphaMult = viewport.getAlphaMult();
59 alphaMult *= entity.getSensorFaderBrightness();
60 alphaMult *= entity.getSensorContactFaderBrightness();
61 if (alphaMult <= 0) return;
62
63
64 GL11.glPushMatrix();
65 GL11.glTranslatef(entity.getLocation().x, entity.getLocation().y, 0);
66
68 for (GenericFieldItemSprite item : items) {
69 item.render(alphaMult);
70 }
71
72 GL11.glPopMatrix();
73 }
74
75 protected void addPiecesToMax() {
76 while (items.size() < numPieces) {
77 float size = minSize + (maxSize - minSize) * (float) Math.random();
79 entity.getRadius() * 0.75f);
80 items.add(item);
81 }
82 }
83
84 protected void initDebrisIfNeeded() {
85 if (inited) return;
86 inited = true;
87
88 items = new ArrayList<GenericFieldItemSprite>();
90 for (GenericFieldItemSprite piece : items) {
91 piece.advance(0.1f);
92 }
93 }
94
95
96
97}
static SectorAPI getSector()
Definition Global.java:59
void render(CampaignEngineLayers layer, ViewportAPI viewport)