More unit assembler progress
This commit is contained in:
@@ -3312,6 +3312,7 @@ public class Blocks{
|
||||
//endregion
|
||||
//region units - erekir
|
||||
|
||||
//TODO 5x5?
|
||||
//TODO completely unfinished
|
||||
tankAssembler = new UnitAssembler("tank-assembler"){{
|
||||
requirements(Category.units, with(Items.graphite, 10));
|
||||
|
||||
@@ -4,6 +4,7 @@ import arc.func.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.*;
|
||||
@@ -94,9 +95,11 @@ public class EntityCollisions{
|
||||
entity.trns(r1.x - r2.x, r1.y - r2.y);
|
||||
}
|
||||
|
||||
public boolean overlapsTile(Rect rect){
|
||||
public boolean overlapsTile(Rect rect, @Nullable SolidPred solidChecker){
|
||||
if(solidChecker == null) return false;
|
||||
|
||||
rect.getCenter(vector);
|
||||
int r = 1;
|
||||
int r = Math.max(Math.round(r1.width / tilesize), 1);
|
||||
|
||||
//assumes tiles are centered
|
||||
int tilex = Math.round(vector.x / tilesize);
|
||||
@@ -105,10 +108,9 @@ public class EntityCollisions{
|
||||
for(int dx = -r; dx <= r; dx++){
|
||||
for(int dy = -r; dy <= r; dy++){
|
||||
int wx = dx + tilex, wy = dy + tiley;
|
||||
if(solid(wx, wy)){
|
||||
r2.setSize(tilesize).setCenter(wx * tilesize, wy * tilesize);
|
||||
if(solidChecker.solid(wx, wy)){
|
||||
|
||||
if(r2.overlaps(rect)){
|
||||
if(r2.setCentered(wx * tilesize, wy * tilesize, tilesize).overlaps(rect)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,6 +135,10 @@ public class Units{
|
||||
return anyEntities(tile, true);
|
||||
}
|
||||
|
||||
public static boolean anyEntities(float x, float y, float size){
|
||||
return anyEntities(x - size/2f, y - size/2f, size, size, true);
|
||||
}
|
||||
|
||||
public static boolean anyEntities(float x, float y, float width, float height){
|
||||
return anyEntities(x, y, width, height, true);
|
||||
}
|
||||
|
||||
@@ -783,6 +783,10 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
||||
return null;
|
||||
}
|
||||
|
||||
public @Nullable BlockSeq getBlockPayloads(){
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to put this item into a nearby container, if there are no available
|
||||
* containers, it gets added to the block's inventory.
|
||||
|
||||
@@ -84,9 +84,9 @@ public class Drawf{
|
||||
|
||||
public static void dashRect(Color color, Rect rect){
|
||||
dashLine(color, rect.x, rect.y, rect.x + rect.width, rect.y);
|
||||
dashLine(color, rect.x, rect.y, rect.x, rect.y + rect.height);
|
||||
dashLine(color, rect.x + rect.width, rect.y, rect.x + rect.width, rect.y + rect.height);
|
||||
dashLine(color, rect.x, rect.y + rect.height, rect.x + rect.width, rect.y + rect.height);
|
||||
dashLine(color, rect.x + rect.width, rect.y + rect.height, rect.x, rect.y + rect.height);
|
||||
dashLine(color, rect.x, rect.y + rect.height, rect.x, rect.y);
|
||||
}
|
||||
|
||||
public static void target(float x, float y, float rad, Color color){
|
||||
|
||||
@@ -917,9 +917,9 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
}
|
||||
|
||||
unit.hitbox(rect);
|
||||
rect.grow(6f);
|
||||
rect.grow(4f);
|
||||
|
||||
player.boosting = collisions.overlapsTile(rect) || !unit.within(targetPos, 85f);
|
||||
player.boosting = collisions.overlapsTile(rect, unit.solidity()) || !unit.within(targetPos, 85f);
|
||||
|
||||
unit.movePref(movement);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mindustry.world.blocks.units;
|
||||
|
||||
import arc.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
@@ -40,6 +41,7 @@ public class UnitAssembler extends PayloadBlock{
|
||||
update = solid = true;
|
||||
rotate = true;
|
||||
rotateDraw = false;
|
||||
acceptsPayload = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -87,7 +89,7 @@ public class UnitAssembler extends PayloadBlock{
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
consumes.add(new ConsumePayloads(requirements, (UnitAssemblerBuild build) -> build.blocks));
|
||||
consumes.add(new ConsumePayloads(requirements));
|
||||
|
||||
super.init();
|
||||
}
|
||||
@@ -96,6 +98,8 @@ public class UnitAssembler extends PayloadBlock{
|
||||
public Seq<Unit> units = new Seq<>();
|
||||
public BlockSeq blocks = new BlockSeq();
|
||||
|
||||
public boolean wasOccupied = false;
|
||||
|
||||
//TODO progress
|
||||
//TODO how should payloads be stored exactly? counts of blocks? intmap? references?
|
||||
|
||||
@@ -130,8 +134,10 @@ public class UnitAssembler extends PayloadBlock{
|
||||
|
||||
Vec2 spawn = getUnitSpawn();
|
||||
|
||||
wasOccupied = checkSolid(spawn);
|
||||
|
||||
//check if all requirements are met
|
||||
if(consValid() & Units.canCreate(team, output)){
|
||||
if(!wasOccupied && consValid() & Units.canCreate(team, output)){
|
||||
|
||||
//TODO ???? should this even be part of a trigger
|
||||
consume();
|
||||
@@ -172,9 +178,23 @@ public class UnitAssembler extends PayloadBlock{
|
||||
Draw.mixcol(Pal.accent, 1f);
|
||||
Draw.alpha(0.4f + Mathf.absin(10f, 0.2f));
|
||||
Draw.rect(output.fullIcon, spawn.x, spawn.y);
|
||||
|
||||
//TODO dash rect for output, fades in/out
|
||||
Draw.color(!wasOccupied ? Color.green : Color.red);
|
||||
Lines.square(spawn.x, spawn.y, output.hitSize/2f);
|
||||
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
public boolean checkSolid(Vec2 v){
|
||||
return !output.flying && (collisions.overlapsTile(Tmp.r1.setCentered(v.x, v.y, output.hitSize), EntityCollisions::solid) || Units.anyEntities(v.x, v.y, output.hitSize));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockSeq getBlockPayloads(){
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePayload(Building source, Payload payload){
|
||||
//super.handlePayload(source, payload);
|
||||
@@ -184,6 +204,7 @@ public class UnitAssembler extends PayloadBlock{
|
||||
//payloads.add((BuildPayload)payload);
|
||||
}
|
||||
|
||||
//TODO doesn't accept from payload source
|
||||
@Override
|
||||
public boolean acceptPayload(Building source, Payload payload){
|
||||
return payload instanceof BuildPayload bp && requirements.contains(b -> b.block == bp.block() && blocks.get(bp.block()) < b.amount);
|
||||
|
||||
@@ -9,24 +9,20 @@ import mindustry.ui.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
public class ConsumePayloads extends Consume{
|
||||
//TODO bad, should be part of Building + dynamic
|
||||
protected Func<Building, BlockSeq> inventory;
|
||||
|
||||
public Seq<BlockStack> payloads;
|
||||
|
||||
public <T extends Building> ConsumePayloads(Seq<BlockStack> payloads, Func<T, BlockSeq> inventory){
|
||||
public <T extends Building> ConsumePayloads(Seq<BlockStack> payloads){
|
||||
this.payloads = payloads;
|
||||
this.inventory = (Func<Building, BlockSeq>)inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(Building build){
|
||||
return inventory.get(build).contains(payloads);
|
||||
return build.getBlockPayloads().contains(payloads);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trigger(Building build){
|
||||
inventory.get(build).remove(payloads);
|
||||
build.getBlockPayloads().remove(payloads);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,7 +39,7 @@ public class ConsumePayloads extends Consume{
|
||||
|
||||
@Override
|
||||
public void build(Building build, Table table){
|
||||
var inv = inventory.get(build);
|
||||
var inv = build.getBlockPayloads();
|
||||
|
||||
table.table(c -> {
|
||||
int i = 0;
|
||||
|
||||
Reference in New Issue
Block a user