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