Implemented nuclear reactor functionality and explosiveness

This commit is contained in:
Anuken 2017-11-28 14:34:53 -05:00
parent 63d8aed9a5
commit 6fb5cb839e
21 changed files with 872 additions and 636 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 538 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 540 B

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 50 KiB

View File

@ -12,7 +12,6 @@ import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.mindustry.world.blocks.ProductionBlocks;
import io.anuke.mindustry.world.blocks.types.Wall;
import io.anuke.ucore.core.Effects;
@ -63,11 +62,8 @@ public class TileEntity extends Entity{
Block block = tile.block();
block.onDestroyed(tile);
for(Tile other : tile.getLinkedTiles()){
other.setBlock(Blocks.air);
}
tile.setBlock(Blocks.air);
Vars.world.removeBlock(tile);
}
public void collision(Bullet other){
@ -105,6 +101,10 @@ public class TileEntity extends Entity{
return sum;
}
public int getItem(Item item){
return items.get(item, 0);
}
public boolean hasItem(Item item){
return items.get(item, 0) > 0;
}

View File

@ -3,6 +3,7 @@ package io.anuke.mindustry.entities.effect;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.entities.Entities;
@ -11,6 +12,15 @@ import io.anuke.ucore.util.Mathf;
//TODO
public class DamageArea{
public static void damageEntities(float x, float y, float radius, int damage){
damage(true, x, y, radius, damage);
if(!Vars.android){
Player player = Vars.player;
int amount = calculateDamage(x, y, player.x, player.y, radius, damage);
player.damage(amount);
}
}
public static void damage(boolean enemies, float x, float y, float radius, int damage){
if(enemies){
@ -35,6 +45,12 @@ public class DamageArea{
}
}
}
if(!Vars.android){
Player player = Vars.player;
int amount = calculateDamage(x, y, player.x, player.y, radius, damage);
player.damage(amount);
}
}
}

View File

@ -26,6 +26,33 @@ public class Fx{
});
}),
reactorsmoke = new Effect(17, e -> {
Angles.randLenVectors(e.id, 4, e.ifract()*8f, (x, y)->{
float size = 1f+e.fract()*5f;
Draw.color(Color.LIGHT_GRAY, Color.GRAY, e.ifract());
Draw.rect("circle", e.x + x, e.y + y, size, size);
Draw.reset();
});
}),
nuclearsmoke = new Effect(40, e -> {
Angles.randLenVectors(e.id, 4, e.ifract()*13f, (x, y)->{
float size = e.sfract()*4f;
Draw.color(Color.LIGHT_GRAY, Color.GRAY, e.ifract());
Draw.rect("circle", e.x + x, e.y + y, size, size);
Draw.reset();
});
}),
nuclearcloud = new Effect(90, e -> {
Angles.randLenVectors(e.id, 10, e.powfract()*90f, (x, y)->{
float size = e.fract()*14f;
Draw.color(Color.LIME, Color.GRAY, e.ifract());
Draw.rect("circle", e.x + x, e.y + y, size, size);
Draw.reset();
});
}),
chainshot = new Effect(9f, e -> {
Draw.color(Color.WHITE, lightOrange, e.ifract());
Draw.thick(e.fract()*4f);
@ -86,6 +113,13 @@ public class Fx{
Draw.reset();
}),
nuclearShockwave = new Effect(10f, e -> {
Draw.color(Color.WHITE, Color.LIGHT_GRAY, e.ifract());
Draw.thick(e.fract()*3f + 0.2f);
Draw.polygon(40, e.x, e.y, e.ifract()*140f);
Draw.reset();
}),
shockwaveSmall = new Effect(10f, e -> {
Draw.color(Color.WHITE, Color.LIGHT_GRAY, e.ifract());
Draw.thick(e.fract()*2f + 0.1f);

View File

@ -17,7 +17,7 @@ import io.anuke.ucore.util.Mathf;
public class Shield extends Entity{
public boolean active;
public boolean hitPlayers = true;
public boolean hitPlayers = false;
private float uptime = 0f;
private final Tile tile;

View File

@ -73,7 +73,7 @@ public class Tile{
if(dst > rad || (dx == 0 && dy == 0)) continue;
Tile other = Vars.world.tile(x + dx, y + dy);
if(other.entity != null){
if(other != null && other.entity != null){
other.entity.damage((int)(amount * Mathf.lerp(1f-dst/rad, 1f, falloff)));
}
}

View File

@ -339,6 +339,19 @@ public class World extends Module{
}
}
public void removeBlock(Tile tile){
if(!tile.block().isMultiblock() && !tile.isLinked()){
tile.setBlock(Blocks.air);
}else{
Tile target = tile.isLinked() ? tile.getLinked() : tile;
Array<Tile> removals = target.getLinkedTiles();
for(Tile toremove : removals){
//note that setting a new block automatically unlinks it
toremove.setBlock(Blocks.air);
}
}
}
public boolean validBreak(int x, int y){
Tile tile = tile(x, y);

View File

@ -44,7 +44,7 @@ public class DistributionBlocks{
//TODO
pulseconveyor = new Conveyor("poweredconveyor"){{
health = 90;
health = 75;
speed = 0.09f;
description = "Moves items even faster.";
formalName = "pulse conveyor";

View File

@ -257,20 +257,14 @@ public class ProductionBlocks{
fullDescription = "Generates small amounts of power from the radioactive decay of uranium. Outputs power as lasers to its 4 sides.";
}
},
nuclearReactor = new LiquidItemPowerGenerator("nuclearreactor"){
nuclearReactor = new NuclearReactor("nuclearreactor"){
{
//TODO
formalName = "nuclear reactor";
width = 3;
height = 3;
generateLiquid = Liquid.water;
generateItem = Item.uranium;
itemCapacity = 60;
itemInput = 6;
inputLiquid = 2f;
health = 500;
breaktime *= 2.2f;
powerCapacity = 100f;
health = 600;
breaktime *= 2.3f;
description = "Generates power from uranium + water.";
fullDescription = "The ultimate power generator. Highly volatile. Generates power from uranium. Requires constant cooling in the form of water. "
+ "Will explode violently if insufficient amounts of coolant are supplied. ";

View File

@ -147,7 +147,6 @@ public class WeaponBlocks{
range = 70;
reload = 15f;
bullet = BulletType.shell;
ammo = Item.coal;
health = 140;
fullDescription = "Advanced multi-target turret. Uses power. Medium range. Never misses."
+ "Average to low damage, but can hit multiple enemies simultaneously with chain lighting.";
@ -189,6 +188,7 @@ public class WeaponBlocks{
health = 430;
width = height = 2;
shootCone = 9f;
ammoMultiplier = 8;
shots = 2;
fullDescription = "The ultimate rapid-fire turret. Uses uranium as ammo. Shoots large slugs at a high fire rate. "
+ "Medium range. Spans multiple tiles. Extremely tough.";
@ -223,7 +223,7 @@ public class WeaponBlocks{
bullet = BulletType.titanshell;
ammo = Item.uranium;
health = 800;
ammoMultiplier = 5;
ammoMultiplier = 4;
width = height = 3;
rotatespeed = 0.07f;
shootCone = 9f;

View File

@ -38,7 +38,9 @@ public class RepairTurret extends PowerTurret{
public void update(Tile tile){
PowerTurretEntity entity = tile.entity();
if(entity.power < powerUsed) return;
if(entity.power < powerUsed){
return;
}
if(Timers.get(entity, "blocktarget", targetInterval)){
entity.blockTarget = Vars.world.findTileTarget(tile.worldx(), tile.worldy(), tile, range, true);
@ -70,9 +72,9 @@ public class RepairTurret extends PowerTurret{
@Override
public void drawOver(Tile tile){
TurretEntity entity = tile.entity();
PowerTurretEntity entity = tile.entity();
if(entity.blockTarget != null && Angles.angleDist(entity.angleTo(entity.blockTarget), entity.rotation) < 10){
if(entity.power >= powerUsed && entity.blockTarget != null && Angles.angleDist(entity.angleTo(entity.blockTarget), entity.rotation) < 10){
Tile targetTile = entity.blockTarget.tile;
Vector2 offset = targetTile.block().getPlaceOffset();
float x = tile.worldx(), y = tile.worldy();

View File

@ -31,7 +31,7 @@ public class ShieldBlock extends PowerBlock{
}
if(entity.power > powerPerDamage){
if(!entity.shield.active && entity.power > powerDrain * Timers.delta() * 10f){
if(!entity.shield.active && entity.power > powerPerDamage * 8f){
entity.shield.add();
}

View File

@ -14,9 +14,7 @@ import io.anuke.ucore.core.Draw;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Hue;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.*;
public class Generator extends PowerBlock{
public static final int powerTime = 2;
@ -118,13 +116,15 @@ public class Generator extends PowerBlock{
Tile target = laserTarget(tile, rotation);
if(target != null){
Tmp.v1.set(Angles.translation(rotation * 90, target.block().width * Vars.tilesize/2 + 2f));
Angles.translation(rotation * 90, width * Vars.tilesize/2 + 2f);
Draw.tint(Hue.mix(Color.GRAY, Color.WHITE, 0.902f + Mathf.sin(Timers.time(), 1.7f, 0.08f)));
float r = 0f;
Draw.laser("laser", "laserend", tile.worldx() + Angles.x() + Mathf.range(r), tile.worldy() + Angles.y() + Mathf.range(r), target.worldx() - Angles.x() + Mathf.range(r), target.worldy() - Angles.y() + Mathf.range(r), 0.7f + Mathf.sin(Timers.time(), 2f, 0.1f * 0));
Draw.laser("laser", "laserend", tile.worldx() + Angles.x() + Mathf.range(r), tile.worldy() + Angles.y() + Mathf.range(r),
target.worldx() - Tmp.v1.x + Mathf.range(r), target.worldy() - Tmp.v1.y + Mathf.range(r), 0.7f + Mathf.sin(Timers.time(), 2f, 0.1f * 0));
Draw.color();
}

View File

@ -48,14 +48,17 @@ public class LiquidPowerGenerator extends Generator implements LiquidAcceptor{
if(entity.liquid == null) return;
Vector2 offset = getPlaceOffset();
Draw.color(entity.liquid.color);
Draw.alpha(entity.liquidAmount / liquidCapacity);
Draw.rect("blank", tile.worldx() + offset.x, tile.worldy() + offset.y, 2, 2);
drawLiquidCenter(tile);
Draw.color();
}
public void drawLiquidCenter(Tile tile){
Vector2 offset = getPlaceOffset();
Draw.rect("black", tile.worldx() + offset.x, tile.worldy() + offset.y, 2, 2);
}
@Override
public void update(Tile tile){
LiquidPowerEntity entity = tile.entity();

View File

@ -1,10 +1,170 @@
package io.anuke.mindustry.world.blocks.types.production;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.entities.effect.DamageArea;
import io.anuke.mindustry.entities.effect.Fx;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.resource.Liquid;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Draw;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Tmp;
public class NuclearReactor extends LiquidItemPowerGenerator{
protected Color coolColor = new Color(1, 1, 1, 0f);
protected Color hotColor = Color.valueOf("ff9575a3");
protected int fuelUseTime = 120; //time to consume 1 fuel
protected float powerMultiplier = 0.08f; //power per frame, depends on full capacity
protected float heating = 0.007f; //heating per frame
protected float coolantPower = 0.007f; //how much heat decreases per coolant unit
protected float smokeThreshold = 0.3f; //threshold at which block starts smoking
protected int explosionRadius = 19;
protected int explosionDamage = 128;
protected float flashThreshold = 0.5f;
//TODO make it explode when broken
public NuclearReactor(String name) {
super(name);
generateItem = Item.uranium;
generateLiquid = Liquid.water;
itemCapacity = 30;
liquidCapacity = 50;
explosionEffect = Fx.nuclearShockwave;
explosive = true;
powerCapacity = 80f;
}
@Override
public void update(Tile tile){
NuclearReactorEntity entity = tile.entity();
int fuel = entity.getItem(generateItem);
float fullness = (float)fuel / itemCapacity;
if(fuel > 0){
entity.heat += fullness * heating;
entity.power += powerMultiplier * fullness;
if(Timers.get(tile, "fuelRemove", fuelUseTime)){
entity.removeItem(generateItem, 1);
}
}
if(entity.liquidAmount > 0){
float maxCool = Math.min(entity.liquidAmount * coolantPower, entity.heat);
entity.heat -= maxCool; //TODO steam when cooling large amounts?
entity.liquidAmount -= maxCool / coolantPower;
}
if(entity.heat > smokeThreshold){
float smoke = 1.0f + (entity.heat - smokeThreshold) / (1f - smokeThreshold); //ranges from 1.0 to 2.0
if(Mathf.chance(smoke / 20.0 * Timers.delta())){
Effects.effect(Fx.reactorsmoke, tile.worldx() + Mathf.range(width * Vars.tilesize / 2f),
tile.worldy() + Mathf.random(height * Vars.tilesize / 2f));
}
}
if(entity.heat >= 1f){
onDestroyed(tile);
Vars.world.removeBlock(tile);
}else{
distributeLaserPower(tile);
}
}
@Override
public void drawLiquidCenter(Tile tile){
Vector2 offset = getPlaceOffset();
Draw.rect(name + "-center", tile.worldx() + offset.x, tile.worldy() + offset.y);
}
@Override
public void onDestroyed(Tile tile){
super.onDestroyed(tile);
int waves = 6;
float delay = 8f;
for(int i = 0; i < waves; i ++){
float rad = (float)i /waves * explosionRadius;
Timers.run(i * delay, ()->{
tile.damageNearby((int)rad, explosionDamage / waves, 0.4f);
});
}
Effects.shake(6f, 16f, tile.worldx(), tile.worldy());
Effects.effect(explosionEffect, tile.worldx(), tile.worldy());
for(int i = 0; i < 6; i ++){
Timers.run(Mathf.random(40), ()->{
Effects.effect(Fx.nuclearcloud, tile.worldx(), tile.worldy());
});
}
DamageArea.damageEntities(tile.worldx(), tile.worldy(), explosionRadius * Vars.tilesize, explosionDamage * 4);
for(int i = 0; i < 20; i ++){
Timers.run(Mathf.random(50), ()->{
Tmp.v1.setToRandomDirection().setLength(Mathf.random(40f));
Effects.effect(Fx.explosion, Tmp.v1.x + tile.worldx(), Tmp.v1.y + tile.worldy());
});
}
for(int i = 0; i < 70; i ++){
Timers.run(Mathf.random(80), ()->{
Tmp.v1.setToRandomDirection().setLength(Mathf.random(120f));
Effects.effect(Fx.nuclearsmoke, Tmp.v1.x + tile.worldx(), Tmp.v1.y + tile.worldy());
});
}
}
@Override
public void drawPixelOverlay(Tile tile){
super.drawPixelOverlay(tile);
NuclearReactorEntity entity = tile.entity();
float fract = entity.heat;
if(fract > 0)
fract = Mathf.clamp(fract + 0.2f, 0.24f, 1f);
Vector2 offset = getPlaceOffset();
Vars.renderer.drawBar(Color.ORANGE, tile.worldx() + offset.x,
tile.worldy() + Vars.tilesize * height/2f + 10 + offset.y, fract);
}
@Override
public void draw(Tile tile){
super.draw(tile);
NuclearReactorEntity entity = tile.entity();
Vector2 offset = getPlaceOffset();
Draw.color(coolColor, hotColor, entity.heat);
Draw.rect("white", tile.worldx() + offset.x, tile.worldy() + offset.y, width * Vars.tilesize, height * Vars.tilesize);
if(entity.heat > flashThreshold){
float flash = 9f - ((entity.heat - flashThreshold) / (1f - flashThreshold)) * 4f;
Draw.color(Color.RED, Color.YELLOW, Mathf.absin(Timers.time(), flash, 1f));
Draw.alpha(0.6f);
Draw.rect(name + "-lights", tile.worldx() + offset.x, tile.worldy() + offset.y);
}
Draw.color();
}
@Override
public TileEntity getEntity(){
return new NuclearReactorEntity();
}
public static class NuclearReactorEntity extends LiquidPowerEntity{
public float heat;
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.