Turn logic / Cross-sector production / Pad tweaks

This commit is contained in:
Anuken
2020-05-15 11:03:21 -04:00
parent 603cb4295a
commit b68e0a8562
16 changed files with 188 additions and 39 deletions

View File

@@ -167,7 +167,7 @@ public class Saves{
public class SaveSlot{
public final Fi file;
boolean requestedPreview;
SaveMeta meta;
public SaveMeta meta;
public SaveSlot(Fi file){
this.file = file;
@@ -242,6 +242,10 @@ public class Saves{
return isSector();
}
public ObjectFloatMap<Item> getProductionRates(){
return meta.productionRates;
}
public String getPlayTime(){
return Strings.formatMillis(current == this ? totalPlaytime : meta.timePlayed);
}

View File

@@ -5,8 +5,6 @@ import arc.struct.*;
import arc.util.*;
import mindustry.type.*;
import java.util.*;
import static mindustry.Vars.content;
public class Stats{
@@ -30,36 +28,44 @@ public class Stats{
/** Friendly buildings destroyed. */
public int buildingsDestroyed;
/** Item production means. Holds means per period. */
private transient WindowedMean[] itemExport = new WindowedMean[content.items().size];
/** Counters of items recieved this period. */
private transient float[] itemCounters = new float[content.items().size];
/** Counter refresh state. */
private transient Interval time = new Interval();
public Stats(){
for(int i = 0; i < itemExport.length; i++){
itemExport[i] = new WindowedMean(exportWindow);
}
}
/** Export statistics. */
public ObjectMap<Item, ProductionStat> production = new ObjectMap<>();
/** Updates export statistics. */
public void handleItemExport(ItemStack stack){
itemCounters[stack.item.id] += stack.amount;
production.getOr(stack.item, ProductionStat::new).counter += stack.amount;
}
public float getExport(Item item){
return production.getOr(item, ProductionStat::new).mean;
}
public void update(){
//refresh throughput
if(time.get(refreshPeriod)){
for(int i = 0; i < itemCounters.length; i++){
itemExport[i].add(itemCounters[i]);
}
for(ProductionStat stat : production.values()){
//initialize stat after loading
if(!stat.loaded){
stat.means.fill(stat.mean);
stat.loaded = true;
}
Arrays.fill(itemCounters, 0);
stat.means.add(stat.counter);
stat.counter = 0;
stat.mean = stat.means.rawMean();
}
}
}
public ObjectFloatMap<Item> productionRates(){
ObjectFloatMap<Item> map = new ObjectFloatMap<>();
production.each((item, value) -> map.put(item, value.mean));
return map;
}
public RankResult calculateRank(Sector zone, boolean launched){
float score = 0;
@@ -106,7 +112,15 @@ public class Stats{
}
}
public enum Rank{
F, D, C, B, A, S, SS
}
public static class ProductionStat{
public transient float counter;
public transient WindowedMean means = new WindowedMean(content.items().size);
public transient boolean loaded;
public float mean;
}
}

View File

@@ -2,8 +2,10 @@ package mindustry.game;
import arc.*;
import arc.math.*;
import arc.struct.ObjectFloatMap.*;
import arc.util.*;
import mindustry.content.*;
import mindustry.io.*;
import mindustry.type.*;
import static mindustry.Vars.*;
@@ -69,7 +71,24 @@ public class Universe{
}
private void onTurn(){
//create a random event here, e.g. invasion
//TODO run waves on hostile sectors, damage them
//calculate passive items
for(Planet planet : content.planets()){
for(Sector sector : planet.sectors){
if(sector.hasSave()){
SaveMeta meta = sector.save.meta;
for(Entry<Item> entry : meta.productionRates){
//total is calculated by items/sec (value) * turn duration in seconds
int total = (int)(entry.value * turnDuration / 60f);
//add the items to global data
data.addItem(entry.key, total);
}
}
}
}
}
public float secondsMod(float mod, float scale){