Finalized launch pad mechanics

This commit is contained in:
Anuken
2025-02-02 18:10:15 -05:00
parent c6d82bec66
commit 7aee34bafa
19 changed files with 310 additions and 52 deletions

View File

@@ -30,6 +30,9 @@ public class SectorInfo{
public ObjectMap<Item, ExportStat> rawProduction = new ObjectMap<>();
/** Export statistics. */
public ObjectMap<Item, ExportStat> export = new ObjectMap<>();
//TODO: there is an obvious exploit with launch pad redirection here; pads can be redirected after leaving a sector, which doesn't update calculations.
/** Import statistics, based on what launch pads are actually receiving. TODO: this is not actually used or displayed anywhere (yet) */
public ObjectMap<Item, ExportStat> imports = new ObjectMap<>();
/** Items stored in all cores. */
public ItemSeq items = new ItemSeq();
/** The best available core type. */
@@ -118,10 +121,20 @@ public class SectorInfo{
export.get(item, ExportStat::new).counter += amount;
}
/** Updates import statistics. */
public void handleItemImport(Item item, int amount){
imports.get(item, ExportStat::new).counter += amount;
}
public float getExport(Item item){
return export.get(item, ExportStat::new).mean;
}
public boolean hasExport(Item item){
var exp = export.get(item);
return exp != null && exp.mean > 0f;
}
public void refreshImportRates(Planet planet){
if(importRateCache == null || importRateCache.length != content.items().size){
importRateCache = new float[content.items().size];
@@ -140,7 +153,7 @@ public class SectorInfo{
return importRateCache;
}
/** @return the import rate of an item as item/second. */
/** @return the import rate of an item as item/second. This is the *raw* max import rate, not what landing pads are actually using. */
public float getImportRate(Planet planet, Item item){
return getImportRates(planet)[item.id];
}
@@ -239,19 +252,8 @@ public class SectorInfo{
//refresh throughput
if(time.get(refreshPeriod)){
//refresh export
export.each((item, stat) -> {
//initialize stat after loading
if(!stat.loaded){
stat.means.fill(stat.mean);
stat.loaded = true;
}
//add counter, subtract how many items were taken from the core during this time
stat.means.add(Math.max(stat.counter, 0));
stat.counter = 0;
stat.mean = stat.means.rawMean();
});
updateStats(export);
updateStats(imports);
if(coreDeltas == null) coreDeltas = new int[content.items().size];
if(productionDeltas == null) productionDeltas = new int[content.items().size];
@@ -268,6 +270,11 @@ public class SectorInfo{
//export can, at most, be the raw items being produced from factories + the items being taken from the core
export.get(item).mean = Math.min(export.get(item).mean, rawProduction.get(item).mean + Math.max(-production.get(item).mean, 0));
}
if(imports.containsKey(item)){
//import can't exceed max import rate
imports.get(item).mean = Math.min(imports.get(item).mean, getImportRate(state.getPlanet(), item));
}
}
Arrays.fill(coreDeltas, 0);
@@ -275,6 +282,20 @@ public class SectorInfo{
}
}
void updateStats(ObjectMap<Item, ExportStat> map){
map.each((item, stat) -> {
//initialize stat after loading
if(!stat.loaded){
stat.means.fill(stat.mean);
stat.loaded = true;
}
stat.means.add(Math.max(stat.counter, 0));
stat.counter = 0;
stat.mean = stat.means.rawMean();
});
}
void updateDelta(Item item, ObjectMap<Item, ExportStat> map, int[] deltas){
ExportStat stat = map.get(item, ExportStat::new);
if(!stat.loaded){