Fixed drones being useless
This commit is contained in:
@@ -35,6 +35,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
||||
protected static int timerIndex = 0;
|
||||
|
||||
protected static final int timerTarget = timerIndex++;
|
||||
protected static final int timerTarget2 = timerIndex++;
|
||||
protected static final int timerShootLeft = timerIndex++;
|
||||
protected static final int timerShootRight = timerIndex++;
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@ import io.anuke.mindustry.entities.type.*;
|
||||
import io.anuke.mindustry.entities.units.UnitState;
|
||||
import io.anuke.mindustry.game.EventType.BuildSelectEvent;
|
||||
import io.anuke.mindustry.gen.Call;
|
||||
import io.anuke.mindustry.type.*;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.ItemType;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.BuildBlock;
|
||||
import io.anuke.mindustry.world.blocks.BuildBlock.BuildEntity;
|
||||
@@ -21,10 +22,11 @@ import io.anuke.mindustry.world.meta.BlockFlag;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.unitGroups;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Drone extends FlyingUnit implements BuilderTrait{
|
||||
|
||||
|
||||
protected Item targetItem;
|
||||
protected Tile mineTile;
|
||||
protected Queue<BuildRequest> placeQueue = new Queue<>();
|
||||
@@ -51,24 +53,12 @@ public class Drone extends FlyingUnit implements BuilderTrait{
|
||||
|
||||
if(core == null) return;
|
||||
|
||||
if((entity.progress() < 1f || entity.progress() > 0f) && entity.block instanceof BuildBlock){ //building is valid
|
||||
if((entity.progress < 1f || entity.progress > 0f) && entity.tile.block() instanceof BuildBlock){ //building is valid
|
||||
if(!isBuilding() && dst(target) < placeDistance * 0.9f){ //within distance, begin placing
|
||||
if(isBreaking){
|
||||
getPlaceQueue().addLast(new BuildRequest(entity.tile.x, entity.tile.y));
|
||||
}else{
|
||||
getPlaceQueue().addLast(new BuildRequest(entity.tile.x, entity.tile.y, entity.tile.getRotation(), entity.block));
|
||||
}
|
||||
}
|
||||
|
||||
//if it's missing requirements, try and mine them
|
||||
if(entity.block != null){
|
||||
for(ItemStack stack : entity.block.buildRequirements){
|
||||
if(!core.items.has(stack.item, stack.amount) && type.toMine.contains(stack.item)){
|
||||
targetItem = stack.item;
|
||||
getPlaceQueue().clear();
|
||||
setState(mine);
|
||||
return;
|
||||
}
|
||||
getPlaceQueue().addLast(new BuildRequest(entity.tile.x, entity.tile.y, entity.tile.getRotation(), entity.cblock));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,7 +212,6 @@ public class Drone extends FlyingUnit implements BuilderTrait{
|
||||
EntityGroup<BaseUnit> group = unitGroups[event.team.ordinal()];
|
||||
|
||||
if(!(event.builder instanceof Player) || !(event.tile.entity instanceof BuildEntity)) return;
|
||||
BuildEntity entity = event.tile.entity();
|
||||
|
||||
for(BaseUnit unit : group.all()){
|
||||
if(unit instanceof Drone){
|
||||
@@ -235,23 +224,11 @@ public class Drone extends FlyingUnit implements BuilderTrait{
|
||||
drone.setState(drone.repair);
|
||||
}
|
||||
}
|
||||
|
||||
drone.notifyPlaced(entity, event.breaking);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void notifyPlaced(BuildEntity entity, boolean isBreaking){
|
||||
float dist = Math.min(entity.dst(x, y) - placeDistance, 0);
|
||||
|
||||
if(!state.is(build) && dist / type.maxVelocity < entity.buildCost * 0.9f){
|
||||
target = entity;
|
||||
this.isBreaking = isBreaking;
|
||||
setState(build);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMine(Item item){
|
||||
return type.toMine.contains(item);
|
||||
@@ -290,6 +267,25 @@ public class Drone extends FlyingUnit implements BuilderTrait{
|
||||
target = null;
|
||||
}
|
||||
|
||||
if(!state.is(build) && timer.get(timerTarget2, 15)){
|
||||
for(Player player : playerGroup.all()){
|
||||
if(player.getTeam() == team && player.getCurrentRequest() != null){
|
||||
BuildRequest req = player.getCurrentRequest();
|
||||
Tile tile = world.tile(req.x, req.y);
|
||||
if(tile != null && tile.entity instanceof BuildEntity){
|
||||
BuildEntity b = tile.entity();
|
||||
float dist = Math.min(b.dst(x, y) - placeDistance, 0);
|
||||
if(dist / type.maxVelocity < b.buildCost * 0.9f){
|
||||
target = b;
|
||||
this.isBreaking = req.breaking;
|
||||
setState(build);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateBuilding();
|
||||
}
|
||||
|
||||
@@ -330,7 +326,7 @@ public class Drone extends FlyingUnit implements BuilderTrait{
|
||||
if(entity == null){
|
||||
return;
|
||||
}
|
||||
targetItem = Structs.findMin(type.toMine, (a, b) -> -Integer.compare(entity.items.get(a), entity.items.get(b)));
|
||||
targetItem = Structs.findMin(type.toMine, world.indexer::hasOre, (a, b) -> -Integer.compare(entity.items.get(a), entity.items.get(b)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user