Full BuildTower impl
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 484 B After Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 907 B After Width: | Height: | Size: 1.7 KiB |
@@ -415,3 +415,4 @@
|
|||||||
63293=beam-node|block-beam-node-ui
|
63293=beam-node|block-beam-node-ui
|
||||||
63292=spark|unit-spark-ui
|
63292=spark|unit-spark-ui
|
||||||
63291=beam-tower|block-beam-tower-ui
|
63291=beam-tower|block-beam-tower-ui
|
||||||
|
63290=build-tower|block-build-tower-ui
|
||||||
|
|||||||
Binary file not shown.
@@ -1160,10 +1160,12 @@ public class Blocks implements ContentList{
|
|||||||
|
|
||||||
buildTower = new BuildTurret("build-tower"){{
|
buildTower = new BuildTurret("build-tower"){{
|
||||||
requirements(Category.effect, with(Items.graphite, 40, Items.beryllium, 50));
|
requirements(Category.effect, with(Items.graphite, 40, Items.beryllium, 50));
|
||||||
consumes.power(0.2f);
|
outlineColor = Pal.darkOutline;
|
||||||
range = 200f;
|
consumes.power(1.5f);
|
||||||
|
range = 120f;
|
||||||
size = 3;
|
size = 3;
|
||||||
health = 80;
|
health = 80;
|
||||||
|
buildSpeed = 1.5f;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
@@ -2209,7 +2211,7 @@ public class Blocks implements ContentList{
|
|||||||
);
|
);
|
||||||
|
|
||||||
shootLength = 0f;
|
shootLength = 0f;
|
||||||
outlineColor = Color.valueOf("2d2f39");
|
outlineColor = Pal.darkOutline;
|
||||||
size = 2;
|
size = 2;
|
||||||
envEnabled |= Env.space;
|
envEnabled |= Env.space;
|
||||||
basePrefix = "reinforced";
|
basePrefix = "reinforced";
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import arc.graphics.*;
|
|||||||
public class Pal{
|
public class Pal{
|
||||||
public static Color
|
public static Color
|
||||||
|
|
||||||
|
darkOutline = Color.valueOf("2d2f39"),
|
||||||
thoriumPink = Color.valueOf("f9a3c7"),
|
thoriumPink = Color.valueOf("f9a3c7"),
|
||||||
coalBlack = Color.valueOf("272727"),
|
coalBlack = Color.valueOf("272727"),
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import arc.struct.*;
|
|||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
import arc.util.io.*;
|
import arc.util.io.*;
|
||||||
import mindustry.annotations.Annotations.*;
|
import mindustry.annotations.Annotations.*;
|
||||||
|
import mindustry.entities.*;
|
||||||
import mindustry.entities.units.*;
|
import mindustry.entities.units.*;
|
||||||
import mindustry.game.Teams.*;
|
import mindustry.game.Teams.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
@@ -12,6 +13,7 @@ import mindustry.graphics.*;
|
|||||||
import mindustry.io.*;
|
import mindustry.io.*;
|
||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
import mindustry.world.*;
|
import mindustry.world.*;
|
||||||
|
import mindustry.world.blocks.ConstructBlock.*;
|
||||||
import mindustry.world.blocks.*;
|
import mindustry.world.blocks.*;
|
||||||
import mindustry.world.blocks.defense.turrets.*;
|
import mindustry.world.blocks.defense.turrets.*;
|
||||||
import mindustry.world.meta.*;
|
import mindustry.world.meta.*;
|
||||||
@@ -19,11 +21,12 @@ import mindustry.world.meta.*;
|
|||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
public class BuildTurret extends BaseTurret{
|
public class BuildTurret extends BaseTurret{
|
||||||
public final int timerTarget = timers++;
|
public final int timerTarget = timers++, timerTarget2 = timers++;
|
||||||
public int targetInterval = 20;
|
public int targetInterval = 60;
|
||||||
|
|
||||||
public @Load(value = "@-base", fallback = "block-@size") TextureRegion baseRegion;
|
public @Load(value = "@-base", fallback = "block-@size") TextureRegion baseRegion;
|
||||||
public float buildSpeed = 1f;
|
public float buildSpeed = 1f;
|
||||||
|
public float buildBeamOffset = 4.1f;
|
||||||
//created in init()
|
//created in init()
|
||||||
public @Nullable UnitType unitType;
|
public @Nullable UnitType unitType;
|
||||||
public float elevation = -1f;
|
public float elevation = -1f;
|
||||||
@@ -46,17 +49,29 @@ public class BuildTurret extends BaseTurret{
|
|||||||
speed = 0f;
|
speed = 0f;
|
||||||
hitSize = 0f;
|
hitSize = 0f;
|
||||||
health = 1;
|
health = 1;
|
||||||
rotateSpeed = BuildTurret.this.rotateSpeed;
|
|
||||||
itemCapacity = 0;
|
itemCapacity = 0;
|
||||||
commandLimit = 0;
|
commandLimit = 0;
|
||||||
|
rotateSpeed = BuildTurret.this.rotateSpeed;
|
||||||
|
buildBeamOffset = BuildTurret.this.buildBeamOffset;
|
||||||
constructor = BlockUnitUnit::create;
|
constructor = BlockUnitUnit::create;
|
||||||
buildRange = BuildTurret.this.range;
|
buildRange = BuildTurret.this.range;
|
||||||
buildSpeed = BuildTurret.this.buildSpeed;
|
buildSpeed = BuildTurret.this.buildSpeed;
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TextureRegion[] icons(){
|
||||||
|
return new TextureRegion[]{baseRegion, region};
|
||||||
|
}
|
||||||
|
|
||||||
public class BuildTurretBuild extends BaseTurretBuild implements ControlBlock{
|
public class BuildTurretBuild extends BaseTurretBuild implements ControlBlock{
|
||||||
public BlockUnitc unit = (BlockUnitc)unitType.create(team);
|
public BlockUnitc unit = (BlockUnitc)unitType.create(team);
|
||||||
|
public @Nullable Unit following;
|
||||||
|
public @Nullable BlockPlan lastPlan;
|
||||||
|
|
||||||
|
{
|
||||||
|
unit.rotation(90f);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canControl(){
|
public boolean canControl(){
|
||||||
@@ -83,32 +98,101 @@ public class BuildTurret extends BaseTurret{
|
|||||||
unit.lookAt(angleTo(unit.buildPlan()));
|
unit.lookAt(angleTo(unit.buildPlan()));
|
||||||
}
|
}
|
||||||
|
|
||||||
//at 0 build speed the unit thinks it can't build, so make it >0
|
unit.buildSpeedMultiplier(efficiency() * timeScale);
|
||||||
unit.buildSpeedMultiplier(Math.max(efficiency() * timeScale, 0.000001f));
|
|
||||||
|
|
||||||
if(!isControlled()){
|
if(!isControlled()){
|
||||||
unit.updateBuilding(true);
|
unit.updateBuilding(true);
|
||||||
|
|
||||||
if(unit.buildPlan() == null && timer(timerTarget, targetInterval)){
|
if(following != null){
|
||||||
|
//validate follower
|
||||||
|
if(!following.isValid() || !following.activelyBuilding()){
|
||||||
|
following = null;
|
||||||
|
unit.plans().clear();
|
||||||
|
}else{
|
||||||
|
//set to follower's first build plan, whatever that is
|
||||||
|
unit.plans().clear();
|
||||||
|
unit.plans().addFirst(following.buildPlan());
|
||||||
|
lastPlan = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}else if(unit.buildPlan() == null && timer(timerTarget, targetInterval)){ //search for new stuff
|
||||||
Queue<BlockPlan> blocks = team.data().blocks;
|
Queue<BlockPlan> blocks = team.data().blocks;
|
||||||
for(int i = 0; i < blocks.size; i++){
|
for(int i = 0; i < blocks.size; i++){
|
||||||
var block = blocks.get(i);
|
var block = blocks.get(i);
|
||||||
if(within(block.x * tilesize, block.y * tilesize, range)){
|
if(within(block.x * tilesize, block.y * tilesize, range)){
|
||||||
if(Build.validPlace(content.block(block.block), unit.team(), block.x, block.y, block.rotation)){
|
var btype = content.block(block.block);
|
||||||
|
|
||||||
|
if(Build.validPlace(btype, unit.team(), block.x, block.y, block.rotation) && team.items().has(btype.requirements, state.rules.buildCostMultiplier)){
|
||||||
unit.addBuild(new BuildPlan(block.x, block.y, block.rotation, content.block(block.block), block.config));
|
unit.addBuild(new BuildPlan(block.x, block.y, block.rotation, content.block(block.block), block.config));
|
||||||
//shift build plan to tail so next unit builds something else
|
//shift build plan to tail so next unit builds something else
|
||||||
blocks.addLast(blocks.removeIndex(i));
|
blocks.addLast(blocks.removeIndex(i));
|
||||||
|
lastPlan = block;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//still not building, find someone to mimic
|
||||||
|
if(unit.buildPlan() == null){
|
||||||
|
following = null;
|
||||||
|
Units.nearby(team, x, y, range, u -> {
|
||||||
|
if(following != null) return;
|
||||||
|
|
||||||
|
if(u.canBuild() && u.activelyBuilding()){
|
||||||
|
BuildPlan plan = u.buildPlan();
|
||||||
|
|
||||||
|
Building build = world.build(plan.x, plan.y);
|
||||||
|
if(build instanceof ConstructBuild && within(build, range)){
|
||||||
|
following = u;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}else if(unit.buildPlan() != null){ //validate building
|
||||||
|
BuildPlan req = unit.buildPlan();
|
||||||
|
|
||||||
|
//clear break plan if another player is breaking something
|
||||||
|
if(!req.breaking && timer.get(timerTarget2, 40f)){
|
||||||
|
for(Player player : Groups.player){
|
||||||
|
if(player.isBuilder() && player.unit().activelyBuilding() && player.unit().buildPlan().samePos(req) && player.unit().buildPlan().breaking){
|
||||||
|
unit.plans().removeFirst();
|
||||||
|
//remove from list of plans
|
||||||
|
team.data().blocks.remove(p -> p.x == req.x && p.y == req.y);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean valid =
|
||||||
|
!(lastPlan != null && lastPlan.removed) &&
|
||||||
|
((req.tile() != null && req.tile().build instanceof ConstructBuild cons && cons.current == req.block) ||
|
||||||
|
(req.breaking ?
|
||||||
|
Build.validBreak(unit.team(), req.x, req.y) :
|
||||||
|
Build.validPlace(req.block, unit.team(), req.x, req.y, req.rotation)));
|
||||||
|
|
||||||
|
if(!valid){
|
||||||
|
//discard invalid request
|
||||||
|
unit.plans().removeFirst();
|
||||||
|
lastPlan = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{ //is being controlled, forget everything
|
||||||
|
following = null;
|
||||||
|
lastPlan = null;
|
||||||
|
}
|
||||||
|
|
||||||
//please do not commit suicide
|
//please do not commit suicide
|
||||||
unit.plans().remove(b -> b.build() == this);
|
unit.plans().remove(b -> b.build() == this);
|
||||||
|
|
||||||
unit.updateBuildLogic();
|
unit.updateBuildLogic();
|
||||||
|
|
||||||
|
//at 0 build speed the unit thinks it can't build, so make it >0 after updating
|
||||||
|
unit.buildSpeedMultiplier(Math.max(unit.buildSpeedMultiplier(), 0.00001f));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldConsume(){
|
||||||
|
return super.shouldConsume() && unit.activelyBuilding();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user