Spore storms / Weather attribute effects
This commit is contained in:
@@ -1,15 +1,51 @@
|
||||
package mindustry.world.blocks;
|
||||
|
||||
import arc.util.serialization.*;
|
||||
import arc.util.serialization.Json.*;
|
||||
import mindustry.world.meta.Attribute;
|
||||
|
||||
public class Attributes{
|
||||
private float[] array = new float[Attribute.values().length];
|
||||
import java.util.*;
|
||||
|
||||
public class Attributes implements Serializable{
|
||||
private final float[] arr = new float[Attribute.all.length];
|
||||
|
||||
public void clear(){
|
||||
Arrays.fill(arr, 0);
|
||||
}
|
||||
|
||||
public float get(Attribute attr){
|
||||
return array[attr.ordinal()];
|
||||
return arr[attr.ordinal()];
|
||||
}
|
||||
|
||||
public void set(Attribute attr, float value){
|
||||
array[attr.ordinal()] = value;
|
||||
arr[attr.ordinal()] = value;
|
||||
}
|
||||
|
||||
public void add(Attributes other){
|
||||
for(int i = 0; i < arr.length; i++){
|
||||
arr[i] += other.arr[i];
|
||||
}
|
||||
}
|
||||
|
||||
public void add(Attributes other, float scl){
|
||||
for(int i = 0; i < arr.length; i++){
|
||||
arr[i] += other.arr[i] * scl;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Json json){
|
||||
for(Attribute at : Attribute.all){
|
||||
if(arr[at.ordinal()] != 0){
|
||||
json.writeValue(at.name(), arr[at.ordinal()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(Json json, JsonValue data){
|
||||
for(Attribute at : Attribute.all){
|
||||
arr[at.ordinal()] = data.getFloat(at.name(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package mindustry.world.blocks.power;
|
||||
|
||||
import arc.math.*;
|
||||
import arc.struct.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
@@ -23,7 +24,10 @@ public class SolarGenerator extends PowerGenerator{
|
||||
public class SolarGeneratorEntity extends GeneratorEntity{
|
||||
@Override
|
||||
public void updateTile(){
|
||||
productionEfficiency = state.rules.solarPowerMultiplier < 0 ? (state.rules.lighting ? 1f - state.rules.ambientLight.a : 1f) : state.rules.solarPowerMultiplier;
|
||||
productionEfficiency =
|
||||
Mathf.maxZero(Attribute.light.env() + state.rules.solarPowerMultiplier < 0 ?
|
||||
(state.rules.lighting ? 1f - state.rules.ambientLight.a : 1f) :
|
||||
state.rules.solarPowerMultiplier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,8 +37,12 @@ public class ThermalGenerator extends PowerGenerator{
|
||||
}
|
||||
|
||||
public class ThermalGeneratorEntity extends GeneratorEntity{
|
||||
public float sum;
|
||||
|
||||
@Override
|
||||
public void updateTile(){
|
||||
productionEfficiency = sum + attribute.env();
|
||||
|
||||
if(productionEfficiency > 0.1f && Mathf.chance(0.05 * delta())){
|
||||
generateEffect.at(x + Mathf.range(3f), y + Mathf.range(3f));
|
||||
}
|
||||
@@ -53,14 +57,7 @@ public class ThermalGenerator extends PowerGenerator{
|
||||
public void onProximityAdded(){
|
||||
super.onProximityAdded();
|
||||
|
||||
productionEfficiency = sumAttribute(attribute, tile.x, tile.y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPowerProduction(){
|
||||
//in this case, productionEfficiency means 'total heat'
|
||||
//thus, it may be greater than 1.0
|
||||
return powerProduction * productionEfficiency;
|
||||
sum = sumAttribute(attribute, tile.x, tile.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class Cultivator extends GenericCrafter{
|
||||
super.setBars();
|
||||
bars.add("multiplier", (CultivatorEntity entity) -> new Bar(() ->
|
||||
Core.bundle.formatFloat("bar.efficiency",
|
||||
((entity.boost + 1f) * entity.warmup) * 100f, 1),
|
||||
((entity.boost + 1f + attribute.env()) * entity.warmup) * 100f, 1),
|
||||
() -> Pal.ammo,
|
||||
() -> entity.warmup));
|
||||
}
|
||||
@@ -101,7 +101,7 @@ public class Cultivator extends GenericCrafter{
|
||||
|
||||
@Override
|
||||
public float getProgressIncrease(float baseTime){
|
||||
return super.getProgressIncrease(baseTime) * (1f + boost);
|
||||
return super.getProgressIncrease(baseTime) * (1f + boost + attribute.env());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -120,7 +120,7 @@ public class SolidPump extends Pump{
|
||||
if(canPump(tile)) fraction = 1f;
|
||||
}
|
||||
|
||||
fraction += boost;
|
||||
fraction += boost + (attribute == null ? 0 : attribute.env());
|
||||
fraction = Math.max(fraction, 0);
|
||||
|
||||
if(cons.valid() && typeLiquid() < liquidCapacity - 0.001f){
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package mindustry.world.meta;
|
||||
|
||||
import mindustry.*;
|
||||
|
||||
public enum Attribute{
|
||||
/** Heat of this block. Used for calculating output of thermal generators. */
|
||||
heat,
|
||||
@@ -8,5 +10,15 @@ public enum Attribute{
|
||||
/** Water content of this block. Used for increasing water extractor yield. */
|
||||
water,
|
||||
/** Oil content of this block. Used for increasing oil extractor yield. */
|
||||
oil
|
||||
oil,
|
||||
/** Light coverage. Negative values decrease solar panel efficiency. */
|
||||
light;
|
||||
|
||||
public static final Attribute[] all = values();
|
||||
|
||||
/** @return the envrionmental value for this attribute. */
|
||||
public float env(){
|
||||
if(Vars.state == null) return 0;
|
||||
return Vars.state.envAttrs.get(this);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user