Campaign production fixes
This commit is contained in:
@@ -14,6 +14,7 @@ import arc.scene.ui.layout.*;
|
|||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
import arc.util.io.*;
|
import arc.util.io.*;
|
||||||
|
import mindustry.*;
|
||||||
import mindustry.annotations.Annotations.*;
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.audio.*;
|
import mindustry.audio.*;
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
@@ -29,8 +30,8 @@ import mindustry.logic.*;
|
|||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
import mindustry.ui.*;
|
import mindustry.ui.*;
|
||||||
import mindustry.world.*;
|
import mindustry.world.*;
|
||||||
import mindustry.world.blocks.*;
|
|
||||||
import mindustry.world.blocks.ConstructBlock.*;
|
import mindustry.world.blocks.ConstructBlock.*;
|
||||||
|
import mindustry.world.blocks.*;
|
||||||
import mindustry.world.blocks.environment.*;
|
import mindustry.world.blocks.environment.*;
|
||||||
import mindustry.world.blocks.payloads.*;
|
import mindustry.world.blocks.payloads.*;
|
||||||
import mindustry.world.blocks.power.*;
|
import mindustry.world.blocks.power.*;
|
||||||
@@ -621,6 +622,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
* containers, it gets added to the block's inventory.
|
* containers, it gets added to the block's inventory.
|
||||||
*/
|
*/
|
||||||
public void offload(Item item){
|
public void offload(Item item){
|
||||||
|
produced(item, 1);
|
||||||
int dump = this.cdump;
|
int dump = this.cdump;
|
||||||
if(!net.client() && state.isCampaign() && team == state.rules.defaultTeam) item.unlock();
|
if(!net.client() && state.isCampaign() && team == state.rules.defaultTeam) item.unlock();
|
||||||
|
|
||||||
@@ -654,6 +656,14 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void produced(Item item){
|
||||||
|
produced(item, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void produced(Item item, int amount){
|
||||||
|
if(Vars.state.rules.sector != null && team == state.rules.defaultTeam) Vars.state.rules.sector.info.handleProduction(item, amount);
|
||||||
|
}
|
||||||
|
|
||||||
/** Try dumping any item near the */
|
/** Try dumping any item near the */
|
||||||
public boolean dump(){
|
public boolean dump(){
|
||||||
return dump(null);
|
return dump(null);
|
||||||
|
|||||||
@@ -76,6 +76,8 @@ abstract class MinerComp implements Itemsc, Posc, Teamc, Rotc, Drawc{
|
|||||||
if(mineTimer >= 50f + item.hardness*15f){
|
if(mineTimer >= 50f + item.hardness*15f){
|
||||||
mineTimer = 0;
|
mineTimer = 0;
|
||||||
|
|
||||||
|
if(state.rules.sector != null && team() == state.rules.defaultTeam) state.rules.sector.info.handleProduction(item, 1);
|
||||||
|
|
||||||
if(core != null && within(core, mineTransferRange) && core.acceptStack(item, 1, this) == 1 && offloadImmediately()){
|
if(core != null && within(core, mineTransferRange) && core.acceptStack(item, 1, this) == 1 && offloadImmediately()){
|
||||||
//add item to inventory before it is transferred
|
//add item to inventory before it is transferred
|
||||||
if(item() == item) addItem(item);
|
if(item() == item) addItem(item);
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ public class SectorInfo{
|
|||||||
|
|
||||||
/** Core input statistics. */
|
/** Core input statistics. */
|
||||||
public ObjectMap<Item, ExportStat> production = new ObjectMap<>();
|
public ObjectMap<Item, ExportStat> production = new ObjectMap<>();
|
||||||
|
/** Raw item production statistics. */
|
||||||
|
public ObjectMap<Item, ExportStat> rawProduction = new ObjectMap<>();
|
||||||
/** Export statistics. */
|
/** Export statistics. */
|
||||||
public ObjectMap<Item, ExportStat> export = new ObjectMap<>();
|
public ObjectMap<Item, ExportStat> export = new ObjectMap<>();
|
||||||
/** Items stored in all cores. */
|
/** Items stored in all cores. */
|
||||||
@@ -77,15 +79,21 @@ public class SectorInfo{
|
|||||||
|
|
||||||
/** Counter refresh state. */
|
/** Counter refresh state. */
|
||||||
private transient Interval time = new Interval();
|
private transient Interval time = new Interval();
|
||||||
/** Core item storage to prevent spoofing. */
|
/** Core item storage input/output deltas. */
|
||||||
private transient int[] coreItemCounts;
|
private @Nullable transient int[] coreDeltas;
|
||||||
|
/** Core item storage input/output deltas. */
|
||||||
|
private @Nullable transient int[] productionDeltas;
|
||||||
|
|
||||||
/** Handles core item changes. */
|
/** Handles core item changes. */
|
||||||
public void handleCoreItem(Item item, int amount){
|
public void handleCoreItem(Item item, int amount){
|
||||||
if(coreItemCounts == null){
|
if(coreDeltas == null) coreDeltas = new int[content.items().size];
|
||||||
coreItemCounts = new int[content.items().size];
|
coreDeltas[item.id] += amount;
|
||||||
}
|
}
|
||||||
coreItemCounts[item.id] += amount;
|
|
||||||
|
/** Handles raw production stats. */
|
||||||
|
public void handleProduction(Item item, int amount){
|
||||||
|
if(productionDeltas == null) productionDeltas = new int[content.items().size];
|
||||||
|
productionDeltas[item.id] += amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return the real location items go when launched on this sector */
|
/** @return the real location items go when launched on this sector */
|
||||||
@@ -176,6 +184,11 @@ public class SectorInfo{
|
|||||||
damage = 0;
|
damage = 0;
|
||||||
hasSpawns = spawner.countSpawns() > 0;
|
hasSpawns = spawner.countSpawns() > 0;
|
||||||
|
|
||||||
|
//cap production at raw production.
|
||||||
|
production.each((item, stat) -> {
|
||||||
|
stat.mean = Math.min(stat.mean, rawProduction.get(item, ExportStat::new).mean);
|
||||||
|
});
|
||||||
|
|
||||||
if(state.rules.sector != null){
|
if(state.rules.sector != null){
|
||||||
state.rules.sector.saveInfo();
|
state.rules.sector.saveInfo();
|
||||||
}
|
}
|
||||||
@@ -189,8 +202,6 @@ public class SectorInfo{
|
|||||||
//updating in multiplayer as a client doesn't make sense
|
//updating in multiplayer as a client doesn't make sense
|
||||||
if(net.client()) return;
|
if(net.client()) return;
|
||||||
|
|
||||||
CoreBuild ent = state.rules.defaultTeam.core();
|
|
||||||
|
|
||||||
//refresh throughput
|
//refresh throughput
|
||||||
if(time.get(refreshPeriod)){
|
if(time.get(refreshPeriod)){
|
||||||
|
|
||||||
@@ -208,30 +219,37 @@ public class SectorInfo{
|
|||||||
stat.mean = stat.means.rawMean();
|
stat.mean = stat.means.rawMean();
|
||||||
});
|
});
|
||||||
|
|
||||||
if(coreItemCounts == null){
|
if(coreDeltas == null) coreDeltas = new int[content.items().size];
|
||||||
coreItemCounts = new int[content.items().size];
|
if(productionDeltas == null) productionDeltas = new int[content.items().size];
|
||||||
}
|
|
||||||
|
|
||||||
//refresh core items
|
//refresh core items
|
||||||
for(Item item : content.items()){
|
for(Item item : content.items()){
|
||||||
ExportStat stat = production.get(item, ExportStat::new);
|
updateDelta(item, production, coreDeltas);
|
||||||
if(!stat.loaded){
|
updateDelta(item, rawProduction, productionDeltas);
|
||||||
stat.means.fill(stat.mean);
|
|
||||||
stat.loaded = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//get item delta
|
production.get(item).mean = Math.min(production.get(item).mean, rawProduction.get(item).mean);
|
||||||
int delta = coreItemCounts[item.id];
|
|
||||||
|
|
||||||
//store means
|
|
||||||
stat.means.add(delta);
|
|
||||||
stat.mean = stat.means.rawMean();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Arrays.fill(coreItemCounts, 0);
|
Arrays.fill(coreDeltas, 0);
|
||||||
|
Arrays.fill(productionDeltas, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateDelta(Item item, ObjectMap<Item, ExportStat> map, int[] deltas){
|
||||||
|
ExportStat stat = map.get(item, ExportStat::new);
|
||||||
|
if(!stat.loaded){
|
||||||
|
stat.means.fill(stat.mean);
|
||||||
|
stat.loaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//get item delta
|
||||||
|
int delta = deltas[item.id];
|
||||||
|
|
||||||
|
//store means
|
||||||
|
stat.means.add(delta);
|
||||||
|
stat.mean = stat.means.rawMean();
|
||||||
|
}
|
||||||
|
|
||||||
public ObjectFloatMap<Item> exportRates(){
|
public ObjectFloatMap<Item> exportRates(){
|
||||||
ObjectFloatMap<Item> map = new ObjectFloatMap<>();
|
ObjectFloatMap<Item> map = new ObjectFloatMap<>();
|
||||||
export.each((item, value) -> map.put(item, value.mean));
|
export.each((item, value) -> map.put(item, value.mean));
|
||||||
|
|||||||
Reference in New Issue
Block a user