mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-09 07:17:36 +07:00
Campaign core item incineration + better idle gen
This commit is contained in:
@ -348,6 +348,11 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
//endregion
|
//endregion
|
||||||
//region handler methods
|
//region handler methods
|
||||||
|
|
||||||
|
/** Called when an unloader takes an item. */
|
||||||
|
public void itemTaken(Item item){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/** Called when this block is dropped as a payload. */
|
/** Called when this block is dropped as a payload. */
|
||||||
public void dropped(){
|
public void dropped(){
|
||||||
|
|
||||||
|
@ -10,6 +10,8 @@ import mindustry.world.*;
|
|||||||
import mindustry.world.blocks.storage.CoreBlock.*;
|
import mindustry.world.blocks.storage.CoreBlock.*;
|
||||||
import mindustry.world.modules.*;
|
import mindustry.world.modules.*;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
public class SectorInfo{
|
public class SectorInfo{
|
||||||
@ -42,7 +44,15 @@ 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 to prevent spoofing. */
|
||||||
private transient int[] lastCoreItems;
|
private transient int[] coreItemCounts;
|
||||||
|
|
||||||
|
/** Handles core item changes. */
|
||||||
|
public void handleCoreItem(Item item, int amount){
|
||||||
|
if(coreItemCounts == null){
|
||||||
|
coreItemCounts = new int[content.items().size];
|
||||||
|
}
|
||||||
|
coreItemCounts[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 */
|
||||||
public Sector getRealDestination(){
|
public Sector getRealDestination(){
|
||||||
@ -105,12 +115,6 @@ public class SectorInfo{
|
|||||||
universe.runTurn();
|
universe.runTurn();
|
||||||
}
|
}
|
||||||
|
|
||||||
//create last stored core items
|
|
||||||
if(lastCoreItems == null){
|
|
||||||
lastCoreItems = new int[content.items().size];
|
|
||||||
updateCoreDeltas();
|
|
||||||
}
|
|
||||||
|
|
||||||
CoreBuild ent = state.rules.defaultTeam.core();
|
CoreBuild ent = state.rules.defaultTeam.core();
|
||||||
|
|
||||||
//refresh throughput
|
//refresh throughput
|
||||||
@ -124,15 +128,16 @@ public class SectorInfo{
|
|||||||
stat.loaded = true;
|
stat.loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//how the resources changed - only interested in negative deltas, since that's what happens during spoofing
|
|
||||||
int coreDelta = Math.min(ent == null ? 0 : ent.items.get(item) - lastCoreItems[item.id], 0);
|
|
||||||
|
|
||||||
//add counter, subtract how many items were taken from the core during this time
|
//add counter, subtract how many items were taken from the core during this time
|
||||||
stat.means.add(Math.max(stat.counter + coreDelta, 0));
|
stat.means.add(Math.max(stat.counter, 0));
|
||||||
stat.counter = 0;
|
stat.counter = 0;
|
||||||
stat.mean = stat.means.rawMean();
|
stat.mean = stat.means.rawMean();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if(coreItemCounts == null){
|
||||||
|
coreItemCounts = 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);
|
ExportStat stat = production.get(item, ExportStat::new);
|
||||||
@ -143,21 +148,14 @@ public class SectorInfo{
|
|||||||
|
|
||||||
//get item delta
|
//get item delta
|
||||||
//TODO is preventing negative production a good idea?
|
//TODO is preventing negative production a good idea?
|
||||||
int delta = Math.max((ent == null ? 0 : ent.items.get(item)) - lastCoreItems[item.id], 0);
|
int delta = Math.max(ent == null ? 0 : coreItemCounts[item.id], 0);
|
||||||
|
|
||||||
//store means
|
//store means
|
||||||
stat.means.add(delta);
|
stat.means.add(delta);
|
||||||
stat.mean = stat.means.rawMean();
|
stat.mean = stat.means.rawMean();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCoreDeltas();
|
Arrays.fill(coreItemCounts, 0);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateCoreDeltas(){
|
|
||||||
CoreBuild ent = state.rules.defaultTeam.core();
|
|
||||||
for(int i = 0; i < lastCoreItems.length; i++){
|
|
||||||
lastCoreItems[i] = ent == null ? 0 : ent.items.get(i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,10 +158,10 @@ public class Universe{
|
|||||||
if(sector.save != null && sector.save.meta != null && sector.save.meta.secinfo != null && sector.save.meta.secinfo.destination != null){
|
if(sector.save != null && sector.save.meta != null && sector.save.meta.secinfo != null && sector.save.meta.secinfo.destination != null){
|
||||||
Sector to = sector.save.meta.secinfo.destination;
|
Sector to = sector.save.meta.secinfo.destination;
|
||||||
if(to.save != null){
|
if(to.save != null){
|
||||||
ItemSeq items = to.getExtraItems();
|
ItemSeq items = new ItemSeq();
|
||||||
//calculated exported items to this sector
|
//calculated exported items to this sector
|
||||||
sector.save.meta.secinfo.export.each((item, stat) -> items.add(item, (int)(stat.mean * newSecondsPassed)));
|
sector.save.meta.secinfo.export.each((item, stat) -> items.add(item, (int)(stat.mean * newSecondsPassed)));
|
||||||
to.setExtraItems(items);
|
to.addItems(items);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,9 +143,15 @@ public class Sector{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void removeItem(Item item, int amount){
|
public void removeItem(Item item, int amount){
|
||||||
|
ItemSeq seq = new ItemSeq();
|
||||||
|
seq.add(item, -amount);
|
||||||
|
addItems(seq);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addItems(ItemSeq items){
|
||||||
if(isBeingPlayed()){
|
if(isBeingPlayed()){
|
||||||
if(state.rules.defaultTeam.core() != null){
|
if(state.rules.defaultTeam.core() != null){
|
||||||
state.rules.defaultTeam.items().remove(item, amount);
|
state.rules.defaultTeam.items().add(items);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
ItemSeq recv = getExtraItems();
|
ItemSeq recv = getExtraItems();
|
||||||
@ -170,7 +176,7 @@ public class Sector{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
recv.remove(item, amount);
|
recv.add(items);
|
||||||
|
|
||||||
setExtraItems(recv);
|
setExtraItems(recv);
|
||||||
}
|
}
|
||||||
|
@ -157,6 +157,7 @@ public class CoreBlock extends StorageBlock{
|
|||||||
public int storageCapacity;
|
public int storageCapacity;
|
||||||
//note that this unit is never actually used for control; the possession handler makes the player respawn when this unit is controlled
|
//note that this unit is never actually used for control; the possession handler makes the player respawn when this unit is controlled
|
||||||
public BlockUnitc unit = Nulls.blockUnit;
|
public BlockUnitc unit = Nulls.blockUnit;
|
||||||
|
public boolean noEffect = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void created(){
|
public void created(){
|
||||||
@ -195,7 +196,7 @@ public class CoreBlock extends StorageBlock{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean acceptItem(Building source, Item item){
|
public boolean acceptItem(Building source, Item item){
|
||||||
return items.get(item) < getMaximumAccepted(item);
|
return items.get(item) < getMaximumAccepted(item) || incinerate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -264,6 +265,10 @@ public class CoreBlock extends StorageBlock{
|
|||||||
return tile instanceof StorageBuild && (((StorageBuild)tile).linkedCore == core || ((StorageBuild)tile).linkedCore == null);
|
return tile instanceof StorageBuild && (((StorageBuild)tile).linkedCore == core || ((StorageBuild)tile).linkedCore == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean incinerate(){
|
||||||
|
return state.isCampaign();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float handleDamage(float amount){
|
public float handleDamage(float amount){
|
||||||
if(player != null && team == player.team()){
|
if(player != null && team == player.team()){
|
||||||
@ -298,16 +303,35 @@ public class CoreBlock extends StorageBlock{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void placed(){
|
public void placed(){
|
||||||
super.placed();
|
super.placed();
|
||||||
state.teams.registerCore(this);
|
state.teams.registerCore(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void itemTaken(Item item){
|
||||||
|
if(state.isCampaign()){
|
||||||
|
//update item taken amount
|
||||||
|
state.secinfo.handleCoreItem(item, -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleItem(Building source, Item item){
|
public void handleItem(Building source, Item item){
|
||||||
if(net.server() || !net.active()){
|
if(net.server() || !net.active()){
|
||||||
super.handleItem(source, item);
|
|
||||||
|
if(items.get(item) >= getMaximumAccepted(item)){
|
||||||
|
//create item incineration effect at random intervals
|
||||||
|
if(!noEffect){
|
||||||
|
incinerateEffect(this, source);
|
||||||
|
}
|
||||||
|
noEffect = false;
|
||||||
|
}else{
|
||||||
|
super.handleItem(source, item);
|
||||||
|
}
|
||||||
|
|
||||||
if(state.rules.tutorial){
|
if(state.rules.tutorial){
|
||||||
Events.fire(new CoreItemDeliverEvent());
|
Events.fire(new CoreItemDeliverEvent());
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
package mindustry.world.blocks.storage;
|
package mindustry.world.blocks.storage;
|
||||||
|
|
||||||
|
import arc.math.*;
|
||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import mindustry.content.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
import mindustry.world.*;
|
import mindustry.world.*;
|
||||||
|
import mindustry.world.blocks.storage.CoreBlock.*;
|
||||||
import mindustry.world.meta.*;
|
import mindustry.world.meta.*;
|
||||||
|
|
||||||
public class StorageBlock extends Block{
|
public class StorageBlock extends Block{
|
||||||
@ -22,6 +25,16 @@ public class StorageBlock extends Block{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void incinerateEffect(Building self, Building source){
|
||||||
|
if(Mathf.chance(0.1)){
|
||||||
|
Tile edge = Edges.getFacingEdge(source, self);
|
||||||
|
Tile edge2 = Edges.getFacingEdge(self, source);
|
||||||
|
if(edge != null && edge2 != null){
|
||||||
|
Fx.fuelburn.at((edge.worldx() + edge2.worldx())/2f, (edge.worldy() + edge2.worldy())/2f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class StorageBuild extends Building{
|
public class StorageBuild extends Building{
|
||||||
protected @Nullable Building linkedCore;
|
protected @Nullable Building linkedCore;
|
||||||
|
|
||||||
@ -30,6 +43,17 @@ public class StorageBlock extends Block{
|
|||||||
return linkedCore != null ? linkedCore.acceptItem(source, item) : items.get(item) < getMaximumAccepted(item);
|
return linkedCore != null ? linkedCore.acceptItem(source, item) : items.get(item) < getMaximumAccepted(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleItem(Building source, Item item){
|
||||||
|
if(linkedCore != null){
|
||||||
|
incinerateEffect(this, source);
|
||||||
|
((CoreBuild)linkedCore).noEffect = true;
|
||||||
|
linkedCore.handleItem(source, item);
|
||||||
|
}else{
|
||||||
|
super.handleItem(source, item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMaximumAccepted(Item item){
|
public int getMaximumAccepted(Item item){
|
||||||
return itemCapacity;
|
return itemCapacity;
|
||||||
|
@ -66,6 +66,7 @@ public class Unloader extends Block{
|
|||||||
}else{
|
}else{
|
||||||
other.items.remove(item, 1);
|
other.items.remove(item, 1);
|
||||||
}
|
}
|
||||||
|
other.itemTaken(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user