Spore storms / Weather attribute effects

This commit is contained in:
Anuken
2020-07-28 17:13:21 -04:00
parent 7cc94057a1
commit 3251dde4a8
15 changed files with 177 additions and 21 deletions

View File

@@ -11,6 +11,7 @@ import mindustry.ctype.*;
import mindustry.gen.*;
import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.meta.*;
import static mindustry.Vars.*;
@@ -18,7 +19,8 @@ public class Weathers implements ContentList{
public static Weather
rain,
snow,
sandstorm;
sandstorm,
sporestorm;
@Override
public void load(){
@@ -26,6 +28,10 @@ public class Weathers implements ContentList{
TextureRegion region;
float yspeed = 2f, xspeed = 0.25f, padding = 16f, size = 12f, density = 1200f;
{
attrs.set(Attribute.light, -0.15f);
}
@Override
public void load(){
super.load();
@@ -69,6 +75,11 @@ public class Weathers implements ContentList{
float yspeed = 5f, xspeed = 1.5f, padding = 16f, size = 40f, density = 1200f;
TextureRegion[] splashes = new TextureRegion[12];
{
attrs.set(Attribute.light, -0.2f);
attrs.set(Attribute.water, 0.2f);
}
@Override
public void load(){
super.load();
@@ -164,6 +175,10 @@ public class Weathers implements ContentList{
Color color = Color.valueOf("f7cba4");
Texture noise;
{
attrs.set(Attribute.light, -0.1f);
}
@Override
public void load(){
region = Core.atlas.find("circle-shadow");
@@ -229,5 +244,76 @@ public class Weathers implements ContentList{
}
}
};
sporestorm = new Weather("sporestorm"){
TextureRegion region;
float yspeed = 1f, xspeed = 4f, size = 5f, padding = size, invDensity = 2000f;
Color color = Color.valueOf("7457ce");
Texture noise;
{
attrs.set(Attribute.spores, 0.5f);
attrs.set(Attribute.light, -0.1f);
}
@Override
public void load(){
region = Core.atlas.find("circle-shadow");
noise = new Texture("sprites/noiseAlpha.png");
noise.setWrap(TextureWrap.repeat);
noise.setFilter(TextureFilter.linear);
}
@Override
public void dispose(){
noise.dispose();
}
@Override
public void drawOver(WeatherState state){
Draw.alpha(state.opacity * 0.8f);
Draw.tint(color);
float scale = 1f / 2000f;
float scroll = Time.time() * scale;
Tmp.tr1.setTexture(noise);
Core.camera.bounds(Tmp.r1);
Tmp.tr1.set(Tmp.r1.x*scale, Tmp.r1.y*scale, (Tmp.r1.x + Tmp.r1.width)*scale, (Tmp.r1.y + Tmp.r1.height)*scale);
Tmp.tr1.scroll(-xspeed * scroll, -yspeed * scroll);
Draw.rect(Tmp.tr1, Core.camera.position.x, Core.camera.position.y, Core.camera.width, -Core.camera.height);
rand.setSeed(0);
Tmp.r1.setCentered(Core.camera.position.x, Core.camera.position.y, Core.graphics.getWidth() / renderer.minScale(), Core.graphics.getHeight() / renderer.minScale());
Tmp.r1.grow(padding);
Core.camera.bounds(Tmp.r2);
int total = (int)(Tmp.r1.area() / invDensity * state.intensity());
Draw.tint(color);
float baseAlpha = state.opacity;
Draw.alpha(baseAlpha);
for(int i = 0; i < total; i++){
float scl = rand.random(0.5f, 1f);
float scl2 = rand.random(0.5f, 1f);
float sscl = rand.random(0.5f, 1f);
float x = (rand.random(0f, world.unitWidth()) + Time.time() * xspeed * scl2);
float y = (rand.random(0f, world.unitHeight()) - Time.time() * yspeed * scl);
float alpha = rand.random(0.1f, 0.8f);
x += Mathf.sin(y, rand.random(30f, 80f), rand.random(1f, 7f));
x -= Tmp.r1.x;
y -= Tmp.r1.y;
x = Mathf.mod(x, Tmp.r1.width);
y = Mathf.mod(y, Tmp.r1.height);
x += Tmp.r1.x;
y += Tmp.r1.y;
if(Tmp.r3.setCentered(x, y, size * sscl).overlaps(Tmp.r2)){
Draw.alpha(alpha * baseAlpha);
Fill.circle(x, y, size * sscl / 2f);
}
}
}
};
}
}

View File

@@ -7,6 +7,7 @@ import mindustry.game.*;
import mindustry.gen.*;
import mindustry.maps.*;
import mindustry.type.*;
import mindustry.world.blocks.*;
import static mindustry.Vars.*;
@@ -23,6 +24,8 @@ public class GameState{
public Rules rules = new Rules();
/** Statistics for this save/game. Displayed after game over. */
public Stats stats = new Stats();
/** Global attributes of the environment, calculated by weather. */
public Attributes envAttrs = new Attributes();
/** Sector information. Only valid in the campaign. */
public SectorInfo secinfo = new SectorInfo();
/** Team data. Gets reset every new game. */

View File

@@ -352,6 +352,10 @@ public class Logic implements ApplicationListener{
runWave();
}
//apply weather attributes
state.envAttrs.clear();
Groups.weather.each(w -> state.envAttrs.add(w.weather.attrs, w.opacity));
Groups.update();
}

View File

@@ -139,7 +139,7 @@ public class WaveGraph extends Table{
for(Mode m : Mode.all){
t.button("$wavemode." + m.name(), Styles.fullTogglet, () -> {
mode = m;
}).group(group).height(32f).update(b -> b.setChecked(m == mode)).width(100f);
}).group(group).height(32f).update(b -> b.setChecked(m == mode)).width(130f);
}
}).growX();
}
@@ -201,6 +201,7 @@ public class WaveGraph extends Table{
enum Mode{
counts, totals, health;
static Mode[] all = values();
}
}

View File

@@ -703,7 +703,11 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
}
public float getProgressIncrease(float baseTime){
return 1f / baseTime * delta() * efficiency();
return 1f / baseTime * edelta();
}
public float getDisplayEfficiency(){
return getProgressIncrease(1f) / edelta();
}
/** @return whether this block should play its active sound.*/

View File

@@ -390,6 +390,8 @@ public class Sector{
/** Has sandstorms. */
desert,
/** Has an enemy base. */
base
base,
/** Has spore weather. */
spores
}
}

View File

@@ -8,12 +8,14 @@ import mindustry.annotations.Annotations.*;
import mindustry.ctype.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.world.blocks.*;
import static mindustry.Vars.renderer;
public abstract class Weather extends MappableContent{
/** Default duration of this weather event in ticks. */
public float duration = 15f * Time.toMinutes;
public Attributes attrs = new Attributes();
//internals
public Rand rand = new Rand();

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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

View File

@@ -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){

View File

@@ -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);
}
}