mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-03-10 04:40:10 +07:00
WIP "wall crafter"
This commit is contained in:
parent
1462443f7c
commit
0543616f15
@ -25,6 +25,7 @@ import mindustry.graphics.*;
|
||||
import mindustry.graphics.MultiPacker.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.blocks.*;
|
||||
import mindustry.world.blocks.environment.*;
|
||||
import mindustry.world.blocks.power.*;
|
||||
import mindustry.world.consumers.*;
|
||||
@ -112,6 +113,8 @@ public class Block extends UnlockableContent{
|
||||
public boolean useColor = true;
|
||||
/** item that drops from this block, used for drills */
|
||||
public @Nullable Item itemDrop = null;
|
||||
/** Array of affinities to certain things. */
|
||||
public Attributes attributes = new Attributes();
|
||||
/** tile entity health */
|
||||
public int health = -1;
|
||||
/** base block explosiveness */
|
||||
|
@ -15,7 +15,6 @@ import mindustry.graphics.*;
|
||||
import mindustry.graphics.MultiPacker.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
@ -54,8 +53,6 @@ public class Floor extends Block{
|
||||
public Block blendGroup = this;
|
||||
/** Effect displayed when randomly updated. */
|
||||
public Effect updateEffect = Fx.none;
|
||||
/** Array of affinities to certain things. */
|
||||
public Attributes attributes = new Attributes();
|
||||
/** Whether this ore generates in maps by default. */
|
||||
public boolean oreDefault = false;
|
||||
/** Ore generation params. */
|
||||
|
153
core/src/mindustry/world/blocks/production/WallCrafter.java
Normal file
153
core/src/mindustry/world/blocks/production/WallCrafter.java
Normal file
@ -0,0 +1,153 @@
|
||||
package mindustry.world.blocks.production;
|
||||
|
||||
import arc.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class WallCrafter extends Block{
|
||||
public @Load("@-top") TextureRegion topRegion;
|
||||
|
||||
/** Time to produce one item at 100% efficiency. */
|
||||
public float drillTime = 200f;
|
||||
/** Effect randomly played while drilling. */
|
||||
public Effect updateEffect = Fx.mineSmall;
|
||||
/** Attribute to check for wall output. */
|
||||
public Attribute attribute = Attribute.oil; //TODO silicates
|
||||
|
||||
public Item output = Items.sand;
|
||||
|
||||
public WallCrafter(String name){
|
||||
super(name);
|
||||
|
||||
hasItems = true;
|
||||
rotate = true;
|
||||
update = true;
|
||||
solid = true;
|
||||
drawArrow = false;
|
||||
|
||||
envEnabled |= Env.space;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean outputsItems(){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean rotatedOutput(int x, int y){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureRegion[] icons(){
|
||||
return new TextureRegion[]{region, topRegion};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawRequestRegion(BuildPlan req, Eachable<BuildPlan> list){
|
||||
Draw.rect(region, req.drawx(), req.drawy());
|
||||
Draw.rect(topRegion, req.drawx(), req.drawy(), req.rotation * 90);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawPlace(int x, int y, int rotation, boolean valid){
|
||||
float eff = 0f;
|
||||
|
||||
for(int i = 0; i < size; i++){
|
||||
getLaserPos(x, y, rotation, Tmp.p1);
|
||||
int rx = Tmp.p1.x, ry = Tmp.p1.y;
|
||||
|
||||
Tile other = world.tile(rx, ry);
|
||||
if(other != null && other.solid()){
|
||||
eff += other.block().attributes.get(attribute);
|
||||
}
|
||||
}
|
||||
|
||||
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 float time;
|
||||
public float warmup;
|
||||
|
||||
@Override
|
||||
public void drawSelect(){
|
||||
|
||||
//TODO efficiency
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTile(){
|
||||
super.updateTile();
|
||||
|
||||
boolean cons = shouldConsume();
|
||||
|
||||
warmup = Mathf.lerpDelta(warmup, Mathf.num(consValid()), 0.1f);
|
||||
float eff = 0f;
|
||||
|
||||
//update facing tiles
|
||||
for(int p = 0; p < size; p++){
|
||||
getLaserPos(tile.x, tile.y, rotation, Tmp.p1);
|
||||
|
||||
int rx = Tmp.p1.x, ry = Tmp.p1.y;
|
||||
Tile dest = world.tile(rx, ry);
|
||||
if(dest != null && dest.solid()){
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
time += edelta();
|
||||
|
||||
if(time >= drillTime){
|
||||
|
||||
time %= drillTime;
|
||||
}
|
||||
|
||||
if(timer(timerDump, dumpTime)){
|
||||
dump();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldConsume(){
|
||||
return items.total() < itemCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
//TODO draw spinner drill thingies
|
||||
Draw.rect(block.region, x, y);
|
||||
Draw.rect(topRegion, x, y, rotdeg());
|
||||
}
|
||||
}
|
||||
}
|
@ -10,4 +10,4 @@ kapt.include.compile.classpath=false
|
||||
kotlin.stdlib.default.dependency=false
|
||||
#needed for android compilation
|
||||
android.useAndroidX=true
|
||||
archash=ca296ad37aeca186fcef3290bb8a6e9143bdd245
|
||||
archash=33c4976f8084fbb6fc26cfdcca2dda3442711d17
|
||||
|
Loading…
Reference in New Issue
Block a user