Commandable blocks
This commit is contained in:
@@ -177,6 +177,8 @@ public class Block extends UnlockableContent implements Senseable{
|
||||
public int unitCapModifier = 0;
|
||||
/** Whether the block can be tapped and selected to configure. */
|
||||
public boolean configurable;
|
||||
/** If true, this building can be selected like a unit when commanding. */
|
||||
public boolean commandable;
|
||||
/** If true, the building inventory can be shown with the config. */
|
||||
public boolean allowConfigInventory = true;
|
||||
/** If true, this block can be configured by logic. */
|
||||
|
||||
@@ -3,6 +3,7 @@ package mindustry.world.blocks.units;
|
||||
import arc.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
@@ -13,6 +14,7 @@ import mindustry.entities.units.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.io.*;
|
||||
import mindustry.logic.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
@@ -31,6 +33,7 @@ public class Reconstructor extends UnitBlock{
|
||||
super(name);
|
||||
regionRotated1 = 1;
|
||||
regionRotated2 = 2;
|
||||
commandable = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -108,11 +111,22 @@ public class Reconstructor extends UnitBlock{
|
||||
}
|
||||
|
||||
public class ReconstructorBuild extends UnitBuild{
|
||||
public @Nullable Vec2 commandPos;
|
||||
|
||||
public float fraction(){
|
||||
return progress / constructTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec2 getCommandPosition(){
|
||||
return commandPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(Vec2 target){
|
||||
commandPos = target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptUnitPayload(Unit unit){
|
||||
return hasUpgrade(unit.type) && !upgrade(unit.type).isBanned();
|
||||
@@ -213,6 +227,9 @@ public class Reconstructor extends UnitBlock{
|
||||
//upgrade the unit
|
||||
if(progress >= constructTime){
|
||||
payload.unit = upgrade(payload.unit.type).create(payload.unit.team());
|
||||
if(commandPos != null && payload.unit.isCommandable()){
|
||||
payload.unit.command().commandPosition(commandPos);
|
||||
}
|
||||
progress %= 1f;
|
||||
Effect.shake(2f, 3f, this);
|
||||
Fx.producesmoke.at(this);
|
||||
@@ -261,7 +278,7 @@ public class Reconstructor extends UnitBlock{
|
||||
|
||||
@Override
|
||||
public byte version(){
|
||||
return 1;
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -269,16 +286,20 @@ public class Reconstructor extends UnitBlock{
|
||||
super.write(write);
|
||||
|
||||
write.f(progress);
|
||||
TypeIO.writeVecNullable(write, commandPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
|
||||
if(revision == 1){
|
||||
if(revision >= 1){
|
||||
progress = read.f();
|
||||
}
|
||||
|
||||
if(revision >= 2){
|
||||
commandPos = TypeIO.readVecNullable(read);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import mindustry.entities.units.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.io.*;
|
||||
import mindustry.logic.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
@@ -52,6 +53,7 @@ public class UnitAssembler extends PayloadBlock{
|
||||
regionRotated1 = 1;
|
||||
sync = true;
|
||||
group = BlockGroup.units;
|
||||
commandable = true;
|
||||
}
|
||||
|
||||
public Rect getRect(Rect rect, float x, float y, int rotation){
|
||||
@@ -190,6 +192,7 @@ public class UnitAssembler extends PayloadBlock{
|
||||
//holds drone IDs that have been sent, but not synced yet - add to list as soon as possible
|
||||
protected IntSeq whenSyncedUnits = new IntSeq();
|
||||
|
||||
public @Nullable Vec2 commandPos;
|
||||
public Seq<Unit> units = new Seq<>();
|
||||
public Seq<UnitAssemblerModuleBuild> modules = new Seq<>();
|
||||
public PayloadSeq blocks = new PayloadSeq();
|
||||
@@ -398,6 +401,9 @@ public class UnitAssembler extends PayloadBlock{
|
||||
|
||||
if(!net.client()){
|
||||
var unit = plan.unit.create(team);
|
||||
if(unit != null && unit.isCommandable()){
|
||||
unit.command().commandPosition(commandPos);
|
||||
}
|
||||
unit.set(spawn.x + Mathf.range(0.001f), spawn.y + Mathf.range(0.001f));
|
||||
unit.rotation = 90f;
|
||||
unit.add();
|
||||
@@ -546,6 +552,21 @@ public class UnitAssembler extends PayloadBlock{
|
||||
plan.requirements.contains(b -> b.item == payload.content() && blocks.get(payload.content()) < b.amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec2 getCommandPosition(){
|
||||
return commandPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(Vec2 target){
|
||||
commandPos = target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte version(){
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
@@ -557,6 +578,7 @@ public class UnitAssembler extends PayloadBlock{
|
||||
}
|
||||
|
||||
blocks.write(write);
|
||||
TypeIO.writeVecNullable(write, commandPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -571,6 +593,9 @@ public class UnitAssembler extends PayloadBlock{
|
||||
whenSyncedUnits.clear();
|
||||
|
||||
blocks.read(read);
|
||||
if(revision >= 1){
|
||||
commandPos = TypeIO.readVecNullable(read);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import arc.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.scene.style.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.*;
|
||||
@@ -15,6 +16,7 @@ import mindustry.entities.units.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.io.*;
|
||||
import mindustry.logic.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
@@ -39,6 +41,7 @@ public class UnitFactory extends UnitBlock{
|
||||
outputsPayload = true;
|
||||
rotate = true;
|
||||
regionRotated1 = 1;
|
||||
commandable = true;
|
||||
|
||||
config(Integer.class, (UnitFactoryBuild tile, Integer i) -> {
|
||||
if(!configurable) return;
|
||||
@@ -143,12 +146,23 @@ public class UnitFactory extends UnitBlock{
|
||||
}
|
||||
|
||||
public class UnitFactoryBuild extends UnitBuild{
|
||||
public @Nullable Vec2 commandPos;
|
||||
public int currentPlan = -1;
|
||||
|
||||
public float fraction(){
|
||||
return currentPlan == -1 ? 0 : progress / plans.get(currentPlan).time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec2 getCommandPosition(){
|
||||
return commandPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(Vec2 target){
|
||||
commandPos = target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object senseObject(LAccess sensor){
|
||||
if(sensor == LAccess.config) return currentPlan == -1 ? null : plans.get(currentPlan).unit;
|
||||
@@ -252,7 +266,11 @@ public class UnitFactory extends UnitBlock{
|
||||
if(progress >= plan.time && consValid()){
|
||||
progress %= 1f;
|
||||
|
||||
payload = new UnitPayload(plan.unit.create(team));
|
||||
Unit unit = plan.unit.create(team);
|
||||
if(commandPos != null && unit.isCommandable()){
|
||||
unit.command().commandPosition(commandPos);
|
||||
}
|
||||
payload = new UnitPayload(unit);
|
||||
payVector.setZero();
|
||||
consume();
|
||||
Events.fire(new UnitCreateEvent(payload.unit, this));
|
||||
@@ -287,7 +305,7 @@ public class UnitFactory extends UnitBlock{
|
||||
|
||||
@Override
|
||||
public byte version(){
|
||||
return 1;
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -295,6 +313,7 @@ public class UnitFactory extends UnitBlock{
|
||||
super.write(write);
|
||||
write.f(progress);
|
||||
write.s(currentPlan);
|
||||
TypeIO.writeVecNullable(write, commandPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -302,6 +321,9 @@ public class UnitFactory extends UnitBlock{
|
||||
super.read(read, revision);
|
||||
progress = read.f();
|
||||
currentPlan = read.s();
|
||||
if(revision >= 2){
|
||||
commandPos = TypeIO.readVecNullable(read);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user