This commit is contained in:
Anuken
2021-08-08 20:42:48 -04:00
parent cc0d7af610
commit 01f759a992
4 changed files with 38 additions and 18 deletions

View File

@@ -147,8 +147,35 @@ public class Universe{
//update relevant sectors
for(Planet planet : content.planets()){
//first pass: clear import stats
for(Sector sector : planet.sectors){
if(sector.hasSave() && sector.hasBase()){
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()){
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()){
//if it is being attacked, capture time is 0; otherwise, increment the timer
if(sector.isAttacked()){
@@ -198,26 +225,16 @@ public class Universe{
float scl = sector.getProductionScale();
//export to another sector
if(sector.info.destination != null){
Sector to = sector.info.destination;
if(to.hasBase()){
ItemSeq items = new ItemSeq();
//calculated exported items to this sector
sector.info.export.each((item, stat) -> items.add(item, (int)(stat.mean * newSecondsPassed * scl)));
to.addItems(items);
}
}
//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, amount) -> {
if(sector.info.items.get(item) <= 0 && sector.info.production.get(item, ExportStat::new).mean < 0){
//disable export when production is negative.
sector.info.export.get(item).mean = 0f;
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.
stat.mean = Math.min(sector.info.lastImported.get(item) / (float)newSecondsPassed, stat.mean);
}
});
//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))));
//prevent negative values with unloaders
sector.info.items.checkNegative();