Minor cleanup / Tick reset fix
This commit is contained in:
Binary file not shown.
@@ -107,6 +107,8 @@ public class Logic implements ApplicationListener{
|
|||||||
weather.cooldown = sum + Mathf.random(weather.maxFrequency);
|
weather.cooldown = sum + Mathf.random(weather.maxFrequency);
|
||||||
sum += weather.cooldown;
|
sum += weather.cooldown;
|
||||||
}
|
}
|
||||||
|
//tick resets on new save play
|
||||||
|
state.tick = 0f;
|
||||||
});
|
});
|
||||||
|
|
||||||
Events.on(WorldLoadEvent.class, e -> {
|
Events.on(WorldLoadEvent.class, e -> {
|
||||||
|
|||||||
@@ -1369,7 +1369,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
|
|
||||||
public void displayConsumption(Table table){
|
public void displayConsumption(Table table){
|
||||||
table.left();
|
table.left();
|
||||||
for(Consume cons : block.consumes.all()){
|
for(Consume cons : block.consumes.all){
|
||||||
if(cons.isOptional() && cons.isBoost()) continue;
|
if(cons.isOptional() && cons.isBoost()) continue;
|
||||||
cons.build(self(), table);
|
cons.build(self(), table);
|
||||||
}
|
}
|
||||||
@@ -1708,11 +1708,13 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
public void update(){
|
public void update(){
|
||||||
if(state.isEditor()) return;
|
if(state.isEditor()) return;
|
||||||
|
|
||||||
|
//TODO refactor to timestamp-based system
|
||||||
timeScaleDuration -= Time.delta;
|
timeScaleDuration -= Time.delta;
|
||||||
if(timeScaleDuration <= 0f || !block.canOverdrive){
|
if(timeScaleDuration <= 0f || !block.canOverdrive){
|
||||||
timeScale = 1f;
|
timeScale = 1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO unacceptable overhead?
|
||||||
if(!enabled && block.autoResetEnabled){
|
if(!enabled && block.autoResetEnabled){
|
||||||
noSleep();
|
noSleep();
|
||||||
enabledControlTime -= Time.delta;
|
enabledControlTime -= Time.delta;
|
||||||
@@ -1722,10 +1724,12 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO this check should not be here, just remove unsupported buildings instead
|
||||||
if(team == Team.derelict || !block.supportsEnv(state.rules.environment)){
|
if(team == Team.derelict || !block.supportsEnv(state.rules.environment)){
|
||||||
enabled = false;
|
enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO separate system for sound?
|
||||||
if(!headless){
|
if(!headless){
|
||||||
if(sound != null){
|
if(sound != null){
|
||||||
sound.update(x, y, shouldActiveSound());
|
sound.update(x, y, shouldActiveSound());
|
||||||
@@ -1736,6 +1740,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO consume module is not necessary for every building, e.g. conveyors should not have it - perhaps it should be nullable?
|
||||||
if(cons != null){
|
if(cons != null){
|
||||||
cons.update();
|
cons.update();
|
||||||
}
|
}
|
||||||
@@ -1744,6 +1749,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
updateTile();
|
updateTile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO unnecessary updates?
|
||||||
if(items != null){
|
if(items != null){
|
||||||
items.update(updateFlow);
|
items.update(updateFlow);
|
||||||
}
|
}
|
||||||
@@ -1752,6 +1758,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
liquids.update(updateFlow);
|
liquids.update(updateFlow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO power graph should be separate entity
|
||||||
if(power != null){
|
if(power != null){
|
||||||
power.graph.update();
|
power.graph.update();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import arc.struct.*;
|
|||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
import mindustry.*;
|
import mindustry.*;
|
||||||
import mindustry.ai.types.*;
|
import mindustry.ai.types.*;
|
||||||
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
import mindustry.core.*;
|
import mindustry.core.*;
|
||||||
import mindustry.ctype.*;
|
import mindustry.ctype.*;
|
||||||
@@ -1326,5 +1327,43 @@ public class LExecutor{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class ExplosionI implements LInstruction{
|
||||||
|
public int team, x, y, radius, damage, air, ground, pierce;
|
||||||
|
|
||||||
|
public ExplosionI(int team, int x, int y, int radius, int damage, int air, int ground, int pierce){
|
||||||
|
this.team = team;
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.radius = radius;
|
||||||
|
this.damage = damage;
|
||||||
|
this.air = air;
|
||||||
|
this.ground = ground;
|
||||||
|
this.pierce = pierce;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExplosionI(){
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(LExecutor exec){
|
||||||
|
if(net.client()) return;
|
||||||
|
|
||||||
|
Team t = exec.obj(team) instanceof Team te ? te : null;
|
||||||
|
//note that there is a radius cap
|
||||||
|
Call.logicExplosion(t, World.unconv(exec.numf(x)), World.unconv(exec.numf(y)), World.unconv(Math.min(exec.numf(radius), 100)), exec.numf(damage), exec.bool(air), exec.bool(ground), exec.bool(pierce));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Remote(called = Loc.server, unreliable = true)
|
||||||
|
public static void logicExplosion(Team team, float x, float y, float radius, float damage, boolean air, boolean ground, boolean pierce){
|
||||||
|
|
||||||
|
Damage.damage(team, x, y, radius, damage, pierce, air, ground);
|
||||||
|
if(pierce){
|
||||||
|
Fx.spawnShockwave.at(x, y, World.conv(radius));
|
||||||
|
}else{
|
||||||
|
Fx.dynamicExplosion.at(x, y, World.conv(radius) / 8f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -348,7 +348,7 @@ public class PowerGraph{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean otherConsumersAreValid(Building build, Consume consumePower){
|
private boolean otherConsumersAreValid(Building build, Consume consumePower){
|
||||||
for(Consume cons : build.block.consumes.all()){
|
for(Consume cons : build.block.consumes.all){
|
||||||
if(cons != consumePower && !cons.isOptional() && !cons.valid(build)){
|
if(cons != consumePower && !cons.isOptional() && !cons.valid(build)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,5 +4,7 @@ public enum ConsumeType{
|
|||||||
item,
|
item,
|
||||||
power,
|
power,
|
||||||
liquid,
|
liquid,
|
||||||
payload
|
payload;
|
||||||
|
|
||||||
|
public static final ConsumeType[] all = values();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,9 @@ import mindustry.world.blocks.power.*;
|
|||||||
import mindustry.world.meta.*;
|
import mindustry.world.meta.*;
|
||||||
|
|
||||||
public class Consumers{
|
public class Consumers{
|
||||||
private Consume[] map = new Consume[ConsumeType.values().length];
|
private Consume[] map = new Consume[ConsumeType.all.length];
|
||||||
private Consume[] results, optionalResults;
|
|
||||||
|
public Consume[] all = {}, optionals = {};
|
||||||
|
|
||||||
public final Bits itemFilters = new Bits(Vars.content.items().size);
|
public final Bits itemFilters = new Bits(Vars.content.items().size);
|
||||||
public final Bits liquidfilters = new Bits(Vars.content.liquids().size);
|
public final Bits liquidfilters = new Bits(Vars.content.liquids().size);
|
||||||
@@ -25,7 +26,7 @@ public class Consumers{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean any(){
|
public boolean any(){
|
||||||
return results != null && results.length > 0;
|
return all.length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void each(Cons<Consume> c){
|
public void each(Cons<Consume> c){
|
||||||
@@ -37,10 +38,10 @@ public class Consumers{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void init(){
|
public void init(){
|
||||||
results = Structs.filter(Consume.class, map, m -> m != null);
|
all = Structs.filter(Consume.class, map, m -> m != null);
|
||||||
optionalResults = Structs.filter(Consume.class, map, m -> m != null && m.isOptional());
|
optionals = Structs.filter(Consume.class, map, m -> m != null && m.isOptional());
|
||||||
|
|
||||||
for(Consume cons : results){
|
for(Consume cons : all){
|
||||||
cons.applyItemFilter(itemFilters);
|
cons.applyItemFilter(itemFilters);
|
||||||
cons.applyLiquidFilter(liquidfilters);
|
cons.applyLiquidFilter(liquidfilters);
|
||||||
}
|
}
|
||||||
@@ -126,18 +127,20 @@ public class Consumers{
|
|||||||
return (T)map[type.ordinal()];
|
return (T)map[type.ordinal()];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
public @Nullable <T extends Consume>T getOrNull(ConsumeType type){
|
||||||
public <T extends Consume> T getOrNull(ConsumeType type){
|
|
||||||
return (T)map[type.ordinal()];
|
return (T)map[type.ordinal()];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
/** @deprecated unnecessary getter */
|
||||||
|
@Deprecated
|
||||||
public Consume[] all(){
|
public Consume[] all(){
|
||||||
return results;
|
return all;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @deprecated unnecessary getter */
|
||||||
|
@Deprecated
|
||||||
public Consume[] optionals(){
|
public Consume[] optionals(){
|
||||||
return optionalResults;
|
return optionals;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void display(Stats stats){
|
public void display(Stats stats){
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public class ConsumeModule extends BlockModule{
|
|||||||
optionalValid = true;
|
optionalValid = true;
|
||||||
boolean docons = entity.shouldConsume() && entity.productionValid();
|
boolean docons = entity.shouldConsume() && entity.productionValid();
|
||||||
|
|
||||||
for(Consume cons : entity.block.consumes.all()){
|
for(Consume cons : entity.block.consumes.all){
|
||||||
if(cons.isOptional()) continue;
|
if(cons.isOptional()) continue;
|
||||||
|
|
||||||
if(docons && cons.isUpdate() && prevValid && cons.valid(entity)){
|
if(docons && cons.isUpdate() && prevValid && cons.valid(entity)){
|
||||||
@@ -51,7 +51,7 @@ public class ConsumeModule extends BlockModule{
|
|||||||
valid &= cons.valid(entity);
|
valid &= cons.valid(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(Consume cons : entity.block.consumes.optionals()){
|
for(Consume cons : entity.block.consumes.optionals){
|
||||||
if(docons && cons.isUpdate() && prevValid && cons.valid(entity)){
|
if(docons && cons.isUpdate() && prevValid && cons.valid(entity)){
|
||||||
cons.update(entity);
|
cons.update(entity);
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@ public class ConsumeModule extends BlockModule{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void trigger(){
|
public void trigger(){
|
||||||
for(Consume cons : entity.block.consumes.all()){
|
for(Consume cons : entity.block.consumes.all){
|
||||||
cons.trigger(entity);
|
cons.trigger(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public class PowerTestFixture{
|
|||||||
Tile tile = new Tile(x, y);
|
Tile tile = new Tile(x, y);
|
||||||
|
|
||||||
//workaround since init() is not called for custom blocks
|
//workaround since init() is not called for custom blocks
|
||||||
if(block.consumes.all() == null){
|
if(block.consumes.all == null || block.consumes.all.length == 0){
|
||||||
block.consumes.init();
|
block.consumes.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user