Internal support for legacy launch pads (hidden)
This commit is contained in:
@@ -8,6 +8,7 @@ public class CampaignRules{
|
||||
public boolean showSpawns;
|
||||
public boolean sectorInvasion;
|
||||
public boolean randomWaveAI;
|
||||
public boolean legacyLaunchPads;
|
||||
|
||||
public void apply(Planet planet, Rules rules){
|
||||
rules.staticFog = rules.fog = fog;
|
||||
|
||||
@@ -92,6 +92,9 @@ public class SectorInfo{
|
||||
public ObjectFloatMap<Item> importCooldownTimers = new ObjectFloatMap<>();
|
||||
public @Nullable transient float[] importRateCache;
|
||||
|
||||
/** Temporary seq for last imported items. Do not use. */
|
||||
public transient ItemSeq lastImported = new ItemSeq();
|
||||
|
||||
/** Counter refresh state. */
|
||||
private transient Interval time = new Interval();
|
||||
/** Core item storage input/output deltas. */
|
||||
|
||||
@@ -168,6 +168,33 @@ public class Universe{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(planet.campaignRules.legacyLaunchPads){
|
||||
//first pass: clear import stats
|
||||
for(Sector sector : planet.sectors){
|
||||
if(sector.hasBase() && !sector.isBeingPlayed()){
|
||||
sector.info.lastImported.clear();
|
||||
}
|
||||
}
|
||||
|
||||
//second pass: update export & import statistics
|
||||
for(Sector sector : planet.sectors){
|
||||
if(sector.hasBase() && !sector.isBeingPlayed()){
|
||||
|
||||
//export to another sector
|
||||
if(sector.info.destination != null){
|
||||
Sector to = sector.info.destination;
|
||||
if(to.hasBase() && to.planet == planet){
|
||||
ItemSeq items = new ItemSeq();
|
||||
//calculated exported items to this sector
|
||||
sector.info.export.each((item, stat) -> items.add(item, (int)(stat.mean * newSecondsPassed * sector.getProductionScale())));
|
||||
to.addItems(items);
|
||||
to.info.lastImported.add(items);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//third pass: everything else
|
||||
for(Sector sector : planet.sectors){
|
||||
if(sector.hasBase()){
|
||||
@@ -229,13 +256,15 @@ public class Universe{
|
||||
//add production, making sure that it's capped
|
||||
sector.info.production.each((item, stat) -> sector.info.items.add(item, Math.min((int)(stat.mean * newSecondsPassed * scl), sector.info.storageCapacity - sector.info.items.get(item))));
|
||||
|
||||
sector.info.export.each((item, stat) -> {
|
||||
if(sector.info.items.get(item) <= 0 && sector.info.production.get(item, ExportStat::new).mean < 0 && stat.mean > 0){
|
||||
//cap export by import when production is negative.
|
||||
//TODO remove
|
||||
stat.mean = Math.min(0f, stat.mean);
|
||||
}
|
||||
});
|
||||
if(planet.campaignRules.legacyLaunchPads){
|
||||
sector.info.export.each((item, stat) -> {
|
||||
if(sector.info.items.get(item) <= 0 && sector.info.production.get(item, ExportStat::new).mean < 0 && stat.mean > 0){
|
||||
//cap export by import when production is negative.
|
||||
//TODO remove
|
||||
stat.mean = Math.min(sector.info.lastImported.get(item) / (float)newSecondsPassed, stat.mean);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//prevent negative values with unloaders
|
||||
sector.info.items.checkNegative();
|
||||
|
||||
Reference in New Issue
Block a user