Sector bugfixes / More sector info
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package mindustry.game;
|
||||
|
||||
import arc.func.*;
|
||||
import arc.math.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
@@ -21,6 +22,7 @@ public class SectorInfo{
|
||||
private static final int valueWindow = 60;
|
||||
/** refresh period of export in ticks */
|
||||
private static final float refreshPeriod = 60;
|
||||
private static float returnf;
|
||||
|
||||
/** Core input statistics. */
|
||||
public ObjectMap<Item, ExportStat> production = new ObjectMap<>();
|
||||
@@ -265,23 +267,29 @@ public class SectorInfo{
|
||||
return map;
|
||||
}
|
||||
|
||||
public boolean anyExports(){
|
||||
if(export.size == 0) return false;
|
||||
returnf = 0f;
|
||||
export.each((i, e) -> returnf += e.mean);
|
||||
return returnf >= 0.01f;
|
||||
}
|
||||
|
||||
/** @return a newly allocated map with import statistics. Use sparingly. */
|
||||
//TODO this can be a float map
|
||||
public ObjectMap<Item, ExportStat> importStats(){
|
||||
public ObjectMap<Item, ExportStat> importStats(Planet planet){
|
||||
ObjectMap<Item, ExportStat> imports = new ObjectMap<>();
|
||||
//for all sectors on all planets that have bases and export to this sector
|
||||
for(Planet planet : content.planets()){
|
||||
for(Sector sector : planet.sectors){
|
||||
Sector dest = sector.info.getRealDestination();
|
||||
if(sector.hasBase() && sector.info != this && dest != null && dest.info == this){
|
||||
//add their exports to our imports
|
||||
sector.info.export.each((item, stat) -> {
|
||||
imports.get(item, ExportStat::new).mean += stat.mean;
|
||||
});
|
||||
}
|
||||
eachImport(planet, sector -> sector.info.export.each((item, stat) -> imports.get(item, ExportStat::new).mean += stat.mean));
|
||||
return imports;
|
||||
}
|
||||
|
||||
/** Iterates through every sector this one imports from. */
|
||||
public void eachImport(Planet planet, Cons<Sector> cons){
|
||||
for(Sector sector : planet.sectors){
|
||||
Sector dest = sector.info.getRealDestination();
|
||||
if(sector.hasBase() && sector.info != this && dest != null && dest.info == this){
|
||||
cons.get(sector);
|
||||
}
|
||||
}
|
||||
return imports;
|
||||
}
|
||||
|
||||
public static class ExportStat{
|
||||
|
||||
Reference in New Issue
Block a user