Unit spawn instruction
This commit is contained in:
@@ -198,7 +198,8 @@ public class WaveSpawner{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void spawnEffect(Unit unit){
|
/** Applies the standard wave spawn effects to a unit - invincibility, unmoving. */
|
||||||
|
public void spawnEffect(Unit unit){
|
||||||
unit.rotation = unit.angleTo(world.width()/2f * tilesize, world.height()/2f * tilesize);
|
unit.rotation = unit.angleTo(world.width()/2f * tilesize, world.height()/2f * tilesize);
|
||||||
unit.apply(StatusEffects.unmoving, 30f);
|
unit.apply(StatusEffects.unmoving, 30f);
|
||||||
unit.apply(StatusEffects.invincible, 60f);
|
unit.apply(StatusEffects.invincible, 60f);
|
||||||
|
|||||||
@@ -3744,9 +3744,7 @@ public class Blocks{
|
|||||||
hasLiquids = true;
|
hasLiquids = true;
|
||||||
|
|
||||||
instructionsPerTick = 25;
|
instructionsPerTick = 25;
|
||||||
|
|
||||||
range = 8 * 42;
|
range = 8 * 42;
|
||||||
|
|
||||||
size = 3;
|
size = 3;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
@@ -3783,7 +3781,8 @@ public class Blocks{
|
|||||||
//currently incomplete, debugOnly for now
|
//currently incomplete, debugOnly for now
|
||||||
requirements(Category.logic, BuildVisibility.debugOnly, with());
|
requirements(Category.logic, BuildVisibility.debugOnly, with());
|
||||||
|
|
||||||
instructionsPerTick = 2;
|
//TODO customizable IPT
|
||||||
|
instructionsPerTick = 8;
|
||||||
forceDark = true;
|
forceDark = true;
|
||||||
privileged = true;
|
privileged = true;
|
||||||
size = 1;
|
size = 1;
|
||||||
|
|||||||
@@ -118,6 +118,9 @@ public class TypeIO{
|
|||||||
write.b((byte)19);
|
write.b((byte)19);
|
||||||
write.f(v.x);
|
write.f(v.x);
|
||||||
write.f(v.y);
|
write.f(v.y);
|
||||||
|
}else if(object instanceof Team t){
|
||||||
|
write.b((byte)20);
|
||||||
|
write.b(t.id);
|
||||||
}else{
|
}else{
|
||||||
throw new IllegalArgumentException("Unknown object type: " + object.getClass());
|
throw new IllegalArgumentException("Unknown object type: " + object.getClass());
|
||||||
}
|
}
|
||||||
@@ -177,6 +180,7 @@ public class TypeIO{
|
|||||||
yield out;
|
yield out;
|
||||||
}
|
}
|
||||||
case 19 -> new Vec2(read.f(), read.f());
|
case 19 -> new Vec2(read.f(), read.f());
|
||||||
|
case 20 -> Team.all[read.ub()];
|
||||||
default -> throw new IllegalArgumentException("Unknown object type: " + type);
|
default -> throw new IllegalArgumentException("Unknown object type: " + type);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import mindustry.*;
|
|||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
import mindustry.ctype.*;
|
import mindustry.ctype.*;
|
||||||
import mindustry.entities.units.*;
|
import mindustry.entities.units.*;
|
||||||
|
import mindustry.game.*;
|
||||||
import mindustry.logic.LExecutor.*;
|
import mindustry.logic.LExecutor.*;
|
||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
import mindustry.world.*;
|
import mindustry.world.*;
|
||||||
@@ -53,6 +54,10 @@ public class GlobalConstants{
|
|||||||
|
|
||||||
//store base content
|
//store base content
|
||||||
|
|
||||||
|
for(Team team : Team.baseTeams){
|
||||||
|
put("@" + team.name, team);
|
||||||
|
}
|
||||||
|
|
||||||
for(Item item : Vars.content.items()){
|
for(Item item : Vars.content.items()){
|
||||||
put("@" + item.name, item);
|
put("@" + item.name, item);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ public class LExecutor{
|
|||||||
//no units of this type found
|
//no units of this type found
|
||||||
exec.setconst(varUnit, null);
|
exec.setconst(varUnit, null);
|
||||||
}
|
}
|
||||||
}else if(exec.obj(type) instanceof Unit u && u.team == exec.team && u.type.logicControllable){
|
}else if(exec.obj(type) instanceof Unit u && (u.team == exec.team || exec.privileged) && u.type.logicControllable){
|
||||||
//bind to specific unit object
|
//bind to specific unit object
|
||||||
exec.setconst(varUnit, u);
|
exec.setconst(varUnit, u);
|
||||||
}else{
|
}else{
|
||||||
@@ -966,6 +966,7 @@ public class LExecutor{
|
|||||||
obj instanceof Building build ? build.block.name :
|
obj instanceof Building build ? build.block.name :
|
||||||
obj instanceof Unit unit ? unit.type.name :
|
obj instanceof Unit unit ? unit.type.name :
|
||||||
obj instanceof Enum<?> e ? e.name() :
|
obj instanceof Enum<?> e ? e.name() :
|
||||||
|
obj instanceof Team team ? team.name :
|
||||||
"[object]";
|
"[object]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1156,5 +1157,36 @@ public class LExecutor{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class SpawnUniI implements LInstruction{
|
||||||
|
public int type, x, y, rotation, team, result;
|
||||||
|
public boolean effect;
|
||||||
|
|
||||||
|
public SpawnUniI(int type, int x, int y, int rotation, int team, boolean effect, int result){
|
||||||
|
this.type = type;
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.rotation = rotation;
|
||||||
|
this.team = team;
|
||||||
|
this.effect = effect;
|
||||||
|
this.result = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SpawnUniI(){
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(LExecutor exec){
|
||||||
|
if(exec.obj(type) instanceof UnitType type && !type.hidden && exec.obj(team) instanceof Team team && Units.canCreate(team, type)){
|
||||||
|
//random offset to prevent stacking
|
||||||
|
var unit = type.spawn(team, World.unconv(exec.numf(x)) + Mathf.range(0.01f), World.unconv(exec.numf(y)) + Mathf.range(0.01f));
|
||||||
|
unit.rotation = exec.numf(rotation);
|
||||||
|
if(effect){
|
||||||
|
spawner.spawnEffect(unit);
|
||||||
|
}
|
||||||
|
exec.setobj(result, unit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,8 +105,8 @@ public abstract class LStatement{
|
|||||||
return field(table, value, setter).width(85f).padRight(10).left();
|
return field(table, value, setter).width(85f).padRight(10).left();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void fields(Table table, String value, Cons<String> setter){
|
protected Cell<TextField> fields(Table table, String value, Cons<String> setter){
|
||||||
field(table, value, setter).width(85f);
|
return field(table, value, setter).width(85f);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void row(Table table){
|
protected void row(Table table){
|
||||||
|
|||||||
@@ -1154,4 +1154,55 @@ public class LStatements{
|
|||||||
return new SetBlockI(builder.var(x), builder.var(y), builder.var(block), builder.var(team), builder.var(rotation), layer);
|
return new SetBlockI(builder.var(x), builder.var(y), builder.var(block), builder.var(team), builder.var(rotation), layer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RegisterStatement("spawn")
|
||||||
|
public static class SpawnUnitStatement extends LStatement{
|
||||||
|
public String type = "@dagger", x = "10", y = "10", rotation = "90", team = "@sharded", result = "result";
|
||||||
|
public boolean effect = true;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void build(Table table){
|
||||||
|
fields(table, result, str -> result = str);
|
||||||
|
|
||||||
|
table.add(" = spawn ");
|
||||||
|
field(table, type, str -> type = str);
|
||||||
|
|
||||||
|
row(table);
|
||||||
|
|
||||||
|
table.add(" at ");
|
||||||
|
fields(table, x, str -> x = str);
|
||||||
|
|
||||||
|
table.add(", ");
|
||||||
|
fields(table, y, str -> y = str);
|
||||||
|
|
||||||
|
table.row();
|
||||||
|
|
||||||
|
table.add();
|
||||||
|
|
||||||
|
table.add("team ");
|
||||||
|
field(table, team, str -> team = str);
|
||||||
|
|
||||||
|
table.add(" rot ");
|
||||||
|
fields(table, rotation, str -> rotation = str).left();
|
||||||
|
|
||||||
|
//effect mostly unnecessary and looks bad
|
||||||
|
//row(table);
|
||||||
|
//table.check("effect", effect, val -> effect = val);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean privileged(){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Color color(){
|
||||||
|
return Pal.logicWorld;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LInstruction build(LAssembler builder){
|
||||||
|
return new SpawnUniI(builder.var(type), builder.var(x), builder.var(y), builder.var(rotation), builder.var(team), effect, builder.var(result));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -384,6 +384,7 @@ public class UnitAssembler extends PayloadBlock{
|
|||||||
var plan = plan();
|
var plan = plan();
|
||||||
|
|
||||||
//draw the unit construction as outline
|
//draw the unit construction as outline
|
||||||
|
//TODO flashes when no gallium
|
||||||
Draw.draw(Layer.blockBuilding, () -> {
|
Draw.draw(Layer.blockBuilding, () -> {
|
||||||
Draw.color(Pal.accent, warmup);
|
Draw.color(Pal.accent, warmup);
|
||||||
|
|
||||||
@@ -420,6 +421,9 @@ public class UnitAssembler extends PayloadBlock{
|
|||||||
Drawf.buildBeam(px, py, spawn.x, spawn.y, plan.unit.hitSize/2f);
|
Drawf.buildBeam(px, py, spawn.x, spawn.y, plan.unit.hitSize/2f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//fill square in middle
|
||||||
|
Fill.square(spawn.x, spawn.y, plan.unit.hitSize/2f);
|
||||||
|
|
||||||
Draw.reset();
|
Draw.reset();
|
||||||
|
|
||||||
Draw.z(Layer.buildBeam);
|
Draw.z(Layer.buildBeam);
|
||||||
|
|||||||
Reference in New Issue
Block a user