WallCrafter progress

This commit is contained in:
Anuken
2021-07-07 16:28:33 -04:00
parent 0543616f15
commit 64ab8328b8
12 changed files with 101 additions and 62 deletions

View File

@@ -81,7 +81,7 @@ public class Blocks implements ContentList{
//production //production
mechanicalDrill, pneumaticDrill, laserDrill, blastDrill, waterExtractor, oilExtractor, cultivator, mechanicalDrill, pneumaticDrill, laserDrill, blastDrill, waterExtractor, oilExtractor, cultivator,
beamDrill, cliffCrusher, beamDrill,
//storage //storage
coreShard, coreFoundation, coreNucleus, vault, container, unloader, coreShard, coreFoundation, coreNucleus, vault, container, unloader,
@@ -377,7 +377,9 @@ public class Blocks implements ContentList{
wall = sporeWall; wall = sporeWall;
}}; }};
stoneWall = new StaticWall("stone-wall"); stoneWall = new StaticWall("stone-wall"){{
attributes.set(Attribute.silicate, 1f);
}};
sporeWall = new StaticWall("spore-wall"); sporeWall = new StaticWall("spore-wall");
@@ -413,10 +415,12 @@ public class Blocks implements ContentList{
ferricStoneWall = new StaticWall("ferric-stone-wall"){{ ferricStoneWall = new StaticWall("ferric-stone-wall"){{
ferricStone.asFloor().wall = this; ferricStone.asFloor().wall = this;
attributes.set(Attribute.silicate, 0.5f);
}}; }};
beryllicStoneWall = new StaticWall("beryllic-stone-wall"){{ beryllicStoneWall = new StaticWall("beryllic-stone-wall"){{
beryllicStone.asFloor().wall = this; beryllicStone.asFloor().wall = this;
attributes.set(Attribute.silicate, 1.2f);
}}; }};
redIceWall = new StaticWall("red-ice-wall"){{ redIceWall = new StaticWall("red-ice-wall"){{
@@ -1509,8 +1513,17 @@ public class Blocks implements ContentList{
consumes.liquid(Liquids.water, 0.15f); consumes.liquid(Liquids.water, 0.15f);
}}; }};
cliffCrusher = new WallCrafter("cliff-crusher"){{
requirements(Category.production, with(Items.copper, 10));
consumes.power(0.2f);
size = 2;
attribute = Attribute.silicate;
output = Items.sand;
}};
beamDrill = new BeamDrill("beam-drill"){{ beamDrill = new BeamDrill("beam-drill"){{
requirements(Category.production, with(Items.copper, 150)); requirements(Category.production, with(Items.copper, 10));
consumes.power(0.2f); consumes.power(0.2f);
tier = 4; tier = 4;
size = 2; size = 2;

View File

@@ -367,7 +367,7 @@ public class Block extends UnlockableContent{
} }
/** Returns whether or not this block can be place on the specified */ /** Returns whether or not this block can be place on the specified */
public boolean canPlaceOn(Tile tile, Team team){ public boolean canPlaceOn(Tile tile, Team team, int rotation){
return true; return true;
} }

View File

@@ -169,7 +169,7 @@ public class Build{
return false; return false;
} }
if(!type.canPlaceOn(tile, team)){ if(!type.canPlaceOn(tile, team, rotation)){
return false; return false;
} }

View File

@@ -40,7 +40,7 @@ public class ThermalGenerator extends PowerGenerator{
} }
@Override @Override
public boolean canPlaceOn(Tile tile, Team team){ public boolean canPlaceOn(Tile tile, Team team, int rotation){
//make sure there's heat at this location //make sure there's heat at this location
return tile.getLinkedTilesAs(this, tempTiles).sumf(other -> other.floor().attributes.get(attribute)) > 0.01f; return tile.getLinkedTilesAs(this, tempTiles).sumf(other -> other.floor().attributes.get(attribute)) > 0.01f;
} }

View File

@@ -99,7 +99,7 @@ public class Drill extends Block{
} }
@Override @Override
public boolean canPlaceOn(Tile tile, Team team){ public boolean canPlaceOn(Tile tile, Team team, int rotation){
if(isMultiblock()){ if(isMultiblock()){
for(Tile other : tile.getLinkedTilesAs(this, tempTiles)){ for(Tile other : tile.getLinkedTilesAs(this, tempTiles)){
if(canMine(other)){ if(canMine(other)){

View File

@@ -62,7 +62,7 @@ public class Pump extends LiquidBlock{
} }
@Override @Override
public boolean canPlaceOn(Tile tile, Team team){ public boolean canPlaceOn(Tile tile, Team team, int rotation){
if(isMultiblock()){ if(isMultiblock()){
Liquid last = null; Liquid last = null;
for(Tile other : tile.getLinkedTilesAs(this, tempTiles)){ for(Tile other : tile.getLinkedTilesAs(this, tempTiles)){

View File

@@ -65,7 +65,7 @@ public class SolidPump extends Pump{
} }
@Override @Override
public boolean canPlaceOn(Tile tile, Team team){ public boolean canPlaceOn(Tile tile, Team team, int rotation){
float sum = tile.getLinkedTilesAs(this, tempTiles).sumf(t -> canPump(t) ? baseEfficiency + (attribute != null ? t.floor().attributes.get(attribute) : 0f) : 0f); float sum = tile.getLinkedTilesAs(this, tempTiles).sumf(t -> canPump(t) ? baseEfficiency + (attribute != null ? t.floor().attributes.get(attribute) : 0f) : 0f);
return sum > 0.00001f; return sum > 0.00001f;
} }

View File

@@ -1,6 +1,7 @@
package mindustry.world.blocks.production; package mindustry.world.blocks.production;
import arc.*; import arc.*;
import arc.func.*;
import arc.graphics.g2d.*; import arc.graphics.g2d.*;
import arc.math.*; import arc.math.*;
import arc.math.geom.*; import arc.math.geom.*;
@@ -9,6 +10,7 @@ import mindustry.annotations.Annotations.*;
import mindustry.content.*; import mindustry.content.*;
import mindustry.entities.*; import mindustry.entities.*;
import mindustry.entities.units.*; import mindustry.entities.units.*;
import mindustry.game.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.type.*; import mindustry.type.*;
import mindustry.world.*; import mindustry.world.*;
@@ -24,7 +26,7 @@ public class WallCrafter extends Block{
/** Effect randomly played while drilling. */ /** Effect randomly played while drilling. */
public Effect updateEffect = Fx.mineSmall; public Effect updateEffect = Fx.mineSmall;
/** Attribute to check for wall output. */ /** Attribute to check for wall output. */
public Attribute attribute = Attribute.oil; //TODO silicates public Attribute attribute = Attribute.silicate;
public Item output = Items.sand; public Item output = Items.sand;
@@ -35,11 +37,23 @@ public class WallCrafter extends Block{
rotate = true; rotate = true;
update = true; update = true;
solid = true; solid = true;
drawArrow = false;
envEnabled |= Env.space; envEnabled |= Env.space;
} }
@Override
public void setBars(){
super.setBars();
}
@Override
public void setStats(){
super.setStats();
stats.add(Stat.output, output);
stats.add(Stat.tiles, StatValues.blocks(attribute, floating, 1f, true, false));
}
@Override @Override
public boolean outputsItems(){ public boolean outputsItems(){
return true; return true;
@@ -63,42 +77,57 @@ public class WallCrafter extends Block{
@Override @Override
public void drawPlace(int x, int y, int rotation, boolean valid){ public void drawPlace(int x, int y, int rotation, boolean valid){
float eff = getEfficiency(x, y, rotation, null);
drawPlaceText(Core.bundle.formatFloat("bar.drillspeed", 60f / drillTime * eff, 2), x, y, valid);
}
@Override
public boolean canPlaceOn(Tile tile, Team team, int rotation){
return getEfficiency(tile.x, tile.y, rotation, null) > 0;
}
float getEfficiency(int tx, int ty, int rotation, @Nullable Cons<Tile> ctile){
float eff = 0f; float eff = 0f;
int cornerX = tx - (size-1)/2, cornerY = ty - (size-1)/2, s = size;
for(int i = 0; i < size; i++){ for(int i = 0; i < size; i++){
getLaserPos(x, y, rotation, Tmp.p1); int rx = 0, ry = 0;
int rx = Tmp.p1.x, ry = Tmp.p1.y;
switch(rotation){
case 0 -> {
rx = cornerX + s;
ry = cornerY + i;
}
case 1 -> {
rx = cornerX + i;
ry = cornerY + s;
}
case 2 -> {
rx = cornerX - 1;
ry = cornerY + i;
}
case 3 -> {
rx = cornerX + i;
ry = cornerY - 1;
}
}
Tile other = world.tile(rx, ry); Tile other = world.tile(rx, ry);
if(other != null && other.solid()){ if(other != null && other.solid()){
eff += other.block().attributes.get(attribute); float at = other.block().attributes.get(attribute);
eff += at;
if(at > 0 && ctile != null){
ctile.get(other);
}
} }
} }
return eff;
drawPlaceText(Core.bundle.formatFloat("bar.drillspeed", 60f / drillTime * eff, 2), x, y, valid);
}
void getLaserPos(int tx, int ty, int rotation, Point2 out){
int cornerX = tx - (size-1)/2, cornerY = ty - (size-1)/2, s = size;
switch(rotation){
case 0 -> out.set(cornerX + s, cornerY + 1);
case 1 -> out.set(cornerX + 1, cornerY + s);
case 2 -> out.set(cornerX - 1, cornerY + 1);
case 3 -> out.set(cornerX + 1, cornerY - 1);
}
} }
public class WallCrafterBuild extends Building{ public class WallCrafterBuild extends Building{
public float time; public float time;
public float warmup; public float warmup;
@Override
public void drawSelect(){
//TODO efficiency
}
@Override @Override
public void updateTile(){ public void updateTile(){
super.updateTile(); super.updateTile();
@@ -106,30 +135,21 @@ public class WallCrafter extends Block{
boolean cons = shouldConsume(); boolean cons = shouldConsume();
warmup = Mathf.lerpDelta(warmup, Mathf.num(consValid()), 0.1f); warmup = Mathf.lerpDelta(warmup, Mathf.num(consValid()), 0.1f);
float eff = 0f; float dx = Geometry.d4x(rotation) * 0.5f, dy = Geometry.d4y(rotation) * 0.5f;
//update facing tiles float eff = getEfficiency(tile.x, tile.y, rotation, dest -> {
for(int p = 0; p < size; p++){ //TODO make not chance based?
getLaserPos(tile.x, tile.y, rotation, Tmp.p1); if(cons && Mathf.chanceDelta(0.05 * warmup)){
updateEffect.at(
int rx = Tmp.p1.x, ry = Tmp.p1.y; dest.worldx() + Mathf.range(3f) - dx,
Tile dest = world.tile(rx, ry); dest.worldy() + Mathf.range(3f) - dy,
if(dest != null && dest.solid()){ output.color
eff += dest.block().attributes.get(attribute); );
//TODO make not chance based?
if(cons && dest.block().attributes.get(attribute) > 0f && Mathf.chanceDelta(0.05 * warmup)){
updateEffect.at(dest.worldx() + Mathf.range(3f), dest.worldy() + Mathf.range(3f));
}
} }
});
if(cons && (time += edelta() * eff) >= drillTime){
} items.add(output, 1);
time += edelta();
if(time >= drillTime){
time %= drillTime; time %= drillTime;
} }

View File

@@ -123,7 +123,7 @@ public class CoreBlock extends StorageBlock{
} }
@Override @Override
public boolean canPlaceOn(Tile tile, Team team){ public boolean canPlaceOn(Tile tile, Team team, int rotation){
if(tile == null) return false; if(tile == null) return false;
CoreBuild core = team.core(); CoreBuild core = team.core();
//must have all requirements //must have all requirements
@@ -168,7 +168,7 @@ public class CoreBlock extends StorageBlock{
public void drawPlace(int x, int y, int rotation, boolean valid){ public void drawPlace(int x, int y, int rotation, boolean valid){
if(world.tile(x, y) == null) return; if(world.tile(x, y) == null) return;
if(!canPlaceOn(world.tile(x, y), player.team())){ if(!canPlaceOn(world.tile(x, y), player.team(), rotation)){
drawPlaceText(Core.bundle.get( drawPlaceText(Core.bundle.get(
(player.team().core() != null && player.team().core().items.has(requirements, state.rules.buildCostMultiplier)) || state.rules.infiniteResources ? (player.team().core() != null && player.team().core().items.has(requirements, state.rules.buildCostMultiplier)) || state.rules.infiniteResources ?

View File

@@ -17,7 +17,9 @@ public class Attribute{
/** Oil content. Used for oil extractor yield. */ /** Oil content. Used for oil extractor yield. */
oil = add("oil"), oil = add("oil"),
/** Light coverage. Negative values decrease solar panel efficiency. */ /** Light coverage. Negative values decrease solar panel efficiency. */
light = add("light"); light = add("light"),
/** Silicate content. Used for sand extraction. */
silicate = add("silicate");
public final int id; public final int id;
public final String name; public final String name;

View File

@@ -112,14 +112,18 @@ public class StatValues{
}; };
} }
public static StatValue floorEfficiency(Floor floor, float multiplier, boolean startZero){ public static StatValue blockEfficiency(Block floor, float multiplier, boolean startZero){
return table -> table.stack( return table -> table.stack(
new Image(floor.uiIcon).setScaling(Scaling.fit), new Image(floor.uiIcon).setScaling(Scaling.fit),
new Table(t -> t.top().right().add((multiplier < 0 ? "[scarlet]" : startZero ? "[accent]" : "[accent]+") + (int)((multiplier) * 100) + "%").style(Styles.outlineLabel)) new Table(t -> t.top().right().add((multiplier < 0 ? "[scarlet]" : startZero ? "[accent]" : "[accent]+") + (int)((multiplier) * 100) + "%").style(Styles.outlineLabel))
); );
} }
public static StatValue floors(Attribute attr, boolean floating, float scale, boolean startZero){ public static StatValue blocks(Attribute attr, boolean floating, float scale, boolean startZero){
return blocks(attr, floating, scale, startZero, true);
}
public static StatValue blocks(Attribute attr, boolean floating, float scale, boolean startZero, boolean checkFloors){
return table -> table.table(c -> { return table -> table.table(c -> {
Runnable[] rebuild = {null}; Runnable[] rebuild = {null};
Map[] lastMap = {null}; Map[] lastMap = {null};
@@ -130,14 +134,14 @@ public class StatValues{
if(state.isGame()){ if(state.isGame()){
var blocks = Vars.content.blocks() var blocks = Vars.content.blocks()
.select(block -> block instanceof Floor f && indexer.isBlockPresent(block) && f.attributes.get(attr) != 0 && !(f.isLiquid && !floating)) .select(block -> (!checkFloors || block instanceof Floor) && indexer.isBlockPresent(block) && block.attributes.get(attr) != 0 && !((block instanceof Floor f && f.isLiquid) && !floating))
.<Floor>as().with(s -> s.sort(f -> f.attributes.get(attr))); .<Floor>as().with(s -> s.sort(f -> f.attributes.get(attr)));
if(blocks.any()){ if(blocks.any()){
int i = 0; int i = 0;
for(var block : blocks){ for(var block : blocks){
floorEfficiency(block, block.attributes.get(attr) * scale, startZero).display(c); blockEfficiency(block, block.attributes.get(attr) * scale, startZero).display(c);
if(++i % 5 == 0){ if(++i % 5 == 0){
c.row(); c.row();
} }

View File

@@ -66,7 +66,7 @@ public class Stats{
} }
public void add(Stat stat, Attribute attr, boolean floating, float scale, boolean startZero){ public void add(Stat stat, Attribute attr, boolean floating, float scale, boolean startZero){
add(stat, StatValues.floors(attr, floating, scale, startZero)); add(stat, StatValues.blocks(attr, floating, scale, startZero));
} }
/** Adds a single string value with this stat. */ /** Adds a single string value with this stat. */