Make assembler plans support items and liquids, allow changing sap bullet regions (#9413)
* make assembler plans support items and liquids, allow changing sap bullet regions * leftover copypaste * hhhhhhhhhhhhhhh * may want to add this as well --------- Co-authored-by: Anuken <arnukren@gmail.com>
This commit is contained in:
@@ -15,6 +15,18 @@ public class SapBulletType extends BulletType{
|
|||||||
public float sapStrength = 0.5f;
|
public float sapStrength = 0.5f;
|
||||||
public Color color = Color.white.cpy();
|
public Color color = Color.white.cpy();
|
||||||
public float width = 0.4f;
|
public float width = 0.4f;
|
||||||
|
public String sprite = "laser";
|
||||||
|
|
||||||
|
public TextureRegion laserRegion;
|
||||||
|
public TextureRegion laserEndRegion;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load(){
|
||||||
|
super.load();
|
||||||
|
|
||||||
|
laserRegion = Core.atlas.find(sprite);
|
||||||
|
laserEndRegion = Core.atlas.find(sprite + "-end");
|
||||||
|
}
|
||||||
|
|
||||||
public SapBulletType(){
|
public SapBulletType(){
|
||||||
speed = 0f;
|
speed = 0f;
|
||||||
@@ -37,7 +49,7 @@ public class SapBulletType extends BulletType{
|
|||||||
Tmp.v1.set(data).lerp(b, b.fin());
|
Tmp.v1.set(data).lerp(b, b.fin());
|
||||||
|
|
||||||
Draw.color(color);
|
Draw.color(color);
|
||||||
Drawf.laser(Core.atlas.find("laser"), Core.atlas.find("laser-end"),
|
Drawf.laser(laserRegion, laserEndRegion,
|
||||||
b.x, b.y, Tmp.v1.x, Tmp.v1.y, width * b.fout());
|
b.x, b.y, Tmp.v1.x, Tmp.v1.y, width * b.fout());
|
||||||
|
|
||||||
Draw.reset();
|
Draw.reset();
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import arc.scene.ui.layout.*;
|
|||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
import arc.util.io.*;
|
import arc.util.io.*;
|
||||||
|
import mindustry.Vars;
|
||||||
import mindustry.ai.types.*;
|
import mindustry.ai.types.*;
|
||||||
import mindustry.annotations.Annotations.*;
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
@@ -40,17 +41,19 @@ public class UnitAssembler extends PayloadBlock{
|
|||||||
public UnitType droneType = UnitTypes.assemblyDrone;
|
public UnitType droneType = UnitTypes.assemblyDrone;
|
||||||
public int dronesCreated = 4;
|
public int dronesCreated = 4;
|
||||||
public float droneConstructTime = 60f * 4f;
|
public float droneConstructTime = 60f * 4f;
|
||||||
|
public int[] capacities = {};
|
||||||
|
|
||||||
public Seq<AssemblerUnitPlan> plans = new Seq<>(4);
|
public Seq<AssemblerUnitPlan> plans = new Seq<>(4);
|
||||||
|
|
||||||
protected @Nullable ConsumePayloadDynamic consPayload;
|
protected @Nullable ConsumePayloadDynamic consPayload;
|
||||||
|
protected @Nullable ConsumeItemDynamic consItem;
|
||||||
|
|
||||||
public UnitAssembler(String name){
|
public UnitAssembler(String name){
|
||||||
super(name);
|
super(name);
|
||||||
update = solid = true;
|
update = solid = true;
|
||||||
rotate = true;
|
rotate = true;
|
||||||
rotateDraw = false;
|
rotateDraw = false;
|
||||||
acceptsPayload = true;
|
acceptsPayload = hasItems = true;
|
||||||
flags = EnumSet.of(BlockFlag.unitAssembler);
|
flags = EnumSet.of(BlockFlag.unitAssembler);
|
||||||
regionRotated1 = 1;
|
regionRotated1 = 1;
|
||||||
sync = true;
|
sync = true;
|
||||||
@@ -96,6 +99,21 @@ public class UnitAssembler extends PayloadBlock{
|
|||||||
public void setBars(){
|
public void setBars(){
|
||||||
super.setBars();
|
super.setBars();
|
||||||
|
|
||||||
|
boolean planLiquids = false;
|
||||||
|
for(int i = 0; i < plans.size; i++){
|
||||||
|
var req = plans.get(i).liquidReq;
|
||||||
|
if(req != null && req.length > 0){
|
||||||
|
for(var stack : req){
|
||||||
|
addLiquidBar(stack.liquid);
|
||||||
|
}
|
||||||
|
planLiquids = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(planLiquids){
|
||||||
|
removeBar("liquid");
|
||||||
|
}
|
||||||
|
|
||||||
addBar("progress", (UnitAssemblerBuild e) -> new Bar("bar.progress", Pal.ammo, () -> e.progress));
|
addBar("progress", (UnitAssemblerBuild e) -> new Bar("bar.progress", Pal.ammo, () -> e.progress));
|
||||||
|
|
||||||
addBar("units", (UnitAssemblerBuild e) ->
|
addBar("units", (UnitAssemblerBuild e) ->
|
||||||
@@ -125,11 +143,30 @@ public class UnitAssembler extends PayloadBlock{
|
|||||||
@Override
|
@Override
|
||||||
public void init(){
|
public void init(){
|
||||||
updateClipRadius(areaSize * tilesize);
|
updateClipRadius(areaSize * tilesize);
|
||||||
|
|
||||||
consume(consPayload = new ConsumePayloadDynamic((UnitAssemblerBuild build) -> build.plan().requirements));
|
consume(consPayload = new ConsumePayloadDynamic((UnitAssemblerBuild build) -> build.plan().requirements));
|
||||||
|
consume(consItem = new ConsumeItemDynamic((UnitAssemblerBuild build) -> build.plan().itemReq != null ? build.plan().itemReq : ItemStack.empty));
|
||||||
|
consume(new ConsumeLiquidsDynamic((UnitAssemblerBuild build) -> build.plan().liquidReq != null ? build.plan().liquidReq : LiquidStack.empty));
|
||||||
|
|
||||||
consumeBuilder.each(c -> c.multiplier = b -> state.rules.unitCost(b.team));
|
consumeBuilder.each(c -> c.multiplier = b -> state.rules.unitCost(b.team));
|
||||||
|
|
||||||
super.init();
|
super.init();
|
||||||
|
|
||||||
|
capacities = new int[Vars.content.items().size];
|
||||||
|
for(AssemblerUnitPlan plan : plans){
|
||||||
|
if(plan.itemReq != null){
|
||||||
|
for(ItemStack stack : plan.itemReq){
|
||||||
|
capacities[stack.item.id] = Math.max(capacities[stack.item.id], stack.amount * 2);
|
||||||
|
itemCapacity = Math.max(itemCapacity, stack.amount * 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(plan.liquidReq != null){
|
||||||
|
for(LiquidStack stack : plan.liquidReq){
|
||||||
|
liquidFilter[stack.liquid.id] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -163,16 +200,40 @@ public class UnitAssembler extends PayloadBlock{
|
|||||||
}).left();
|
}).left();
|
||||||
|
|
||||||
t.table(req -> {
|
t.table(req -> {
|
||||||
req.right();
|
req.table().grow(); //it refuses to go to the right unless I do this. please help.
|
||||||
for(int i = 0; i < plan.requirements.size; i++){
|
|
||||||
if(i % 6 == 0){
|
req.table(solid -> {
|
||||||
req.row();
|
int length = 0;
|
||||||
|
if(plan.itemReq != null){
|
||||||
|
for(int i = 0; i < plan.itemReq.length; i++){
|
||||||
|
if(length % 6 == 0){
|
||||||
|
solid.row();
|
||||||
|
}
|
||||||
|
solid.add(StatValues.stack(plan.itemReq[i])).pad(5);
|
||||||
|
length++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PayloadStack stack = plan.requirements.get(i);
|
for(int i = 0; i < plan.requirements.size; i++){
|
||||||
req.add(StatValues.stack(stack)).pad(5);
|
if(length % 6 == 0){
|
||||||
|
solid.row();
|
||||||
|
}
|
||||||
|
solid.add(StatValues.stack(plan.requirements.get(i))).pad(5);
|
||||||
|
length++;
|
||||||
|
}
|
||||||
|
}).right();
|
||||||
|
|
||||||
|
LiquidStack[] stacks = plan.liquidReq;
|
||||||
|
if(stacks != null){
|
||||||
|
for(int i = 0; i < plan.liquidReq.length; i++){
|
||||||
|
req.row();
|
||||||
|
|
||||||
|
req.table().grow(); //another one.
|
||||||
|
|
||||||
|
req.add(StatValues.displayLiquid(stacks[i].liquid, stacks[i].amount * 60f, true)).right();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}).right().grow().pad(10f);
|
}).grow().pad(10f);
|
||||||
}else{
|
}else{
|
||||||
t.image(Icon.lock).color(Pal.darkerGray).size(40).pad(10);
|
t.image(Icon.lock).color(Pal.darkerGray).size(40).pad(10);
|
||||||
}
|
}
|
||||||
@@ -185,7 +246,9 @@ public class UnitAssembler extends PayloadBlock{
|
|||||||
|
|
||||||
public static class AssemblerUnitPlan{
|
public static class AssemblerUnitPlan{
|
||||||
public UnitType unit;
|
public UnitType unit;
|
||||||
public Seq<PayloadStack> requirements;
|
@Nullable public Seq<PayloadStack> requirements;
|
||||||
|
@Nullable public ItemStack[] itemReq;
|
||||||
|
@Nullable public LiquidStack[] liquidReq;
|
||||||
public float time;
|
public float time;
|
||||||
|
|
||||||
public AssemblerUnitPlan(UnitType unit, float time, Seq<PayloadStack> requirements){
|
public AssemblerUnitPlan(UnitType unit, float time, Seq<PayloadStack> requirements){
|
||||||
@@ -296,7 +359,7 @@ public class UnitAssembler extends PayloadBlock{
|
|||||||
@Override
|
@Override
|
||||||
public boolean shouldConsume(){
|
public boolean shouldConsume(){
|
||||||
//liquid is only consumed when building is being done
|
//liquid is only consumed when building is being done
|
||||||
return enabled && !wasOccupied && Units.canCreate(team, plan().unit) && consPayload.efficiency(this) > 0;
|
return enabled && !wasOccupied && Units.canCreate(team, plan().unit) && consPayload.efficiency(this) > 0 && consItem.efficiency(this) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -601,6 +664,17 @@ public class UnitAssembler extends PayloadBlock{
|
|||||||
plan.requirements.contains(b -> b.item == payload.content() && blocks.get(payload.content()) < Mathf.round(b.amount * state.rules.unitCost(team)));
|
plan.requirements.contains(b -> b.item == payload.content() && blocks.get(payload.content()) < Mathf.round(b.amount * state.rules.unitCost(team)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaximumAccepted(Item item){
|
||||||
|
return Mathf.round(capacities[item.id] * state.rules.unitCost(team));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean acceptItem(Building source, Item item){
|
||||||
|
return plan().itemReq != null && items.get(item) < getMaximumAccepted(item) &&
|
||||||
|
Structs.contains(plan().itemReq, stack -> stack.item == item);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Vec2 getCommandPosition(){
|
public Vec2 getCommandPosition(){
|
||||||
return commandPos;
|
return commandPos;
|
||||||
|
|||||||
Reference in New Issue
Block a user