Fixed drones being useless
This commit is contained in:
@@ -34,6 +34,8 @@ public class BlockIndexer{
|
|||||||
private Bits[] structQuadrants;
|
private Bits[] structQuadrants;
|
||||||
/** Stores all damaged tile entities by team. */
|
/** Stores all damaged tile entities by team. */
|
||||||
private ObjectSet<Tile>[] damagedTiles = new ObjectSet[Team.all.length];
|
private ObjectSet<Tile>[] damagedTiles = new ObjectSet[Team.all.length];
|
||||||
|
/**All ores available on this map.*/
|
||||||
|
private ObjectSet<Item> allOres = new ObjectSet<>();
|
||||||
|
|
||||||
/** Maps teams to a map of flagged tiles by type. */
|
/** Maps teams to a map of flagged tiles by type. */
|
||||||
private ObjectSet<Tile>[][] flagMap = new ObjectSet[Team.all.length][BlockFlag.all.length];
|
private ObjectSet<Tile>[][] flagMap = new ObjectSet[Team.all.length][BlockFlag.all.length];
|
||||||
@@ -67,6 +69,7 @@ public class BlockIndexer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
typeMap.clear();
|
typeMap.clear();
|
||||||
|
allOres.clear();
|
||||||
ores = null;
|
ores = null;
|
||||||
|
|
||||||
//create bitset for each team type that contains each quadrant
|
//create bitset for each team type that contains each quadrant
|
||||||
@@ -84,6 +87,8 @@ public class BlockIndexer{
|
|||||||
if(tile.entity != null && tile.entity.damaged()){
|
if(tile.entity != null && tile.entity.damaged()){
|
||||||
notifyTileDamaged(tile.entity);
|
notifyTileDamaged(tile.entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(tile.drop() != null) allOres.add(tile.drop());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,6 +106,11 @@ public class BlockIndexer{
|
|||||||
return flagMap[team.ordinal()];
|
return flagMap[team.ordinal()];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return whether this item is present on this map.*/
|
||||||
|
public boolean hasOre(Item item){
|
||||||
|
return allOres.contains(item);
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns all damaged tiles by team. */
|
/** Returns all damaged tiles by team. */
|
||||||
public ObjectSet<Tile> getDamaged(Team team){
|
public ObjectSet<Tile> getDamaged(Team team){
|
||||||
returnArray.clear();
|
returnArray.clear();
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
|||||||
protected static int timerIndex = 0;
|
protected static int timerIndex = 0;
|
||||||
|
|
||||||
protected static final int timerTarget = timerIndex++;
|
protected static final int timerTarget = timerIndex++;
|
||||||
|
protected static final int timerTarget2 = timerIndex++;
|
||||||
protected static final int timerShootLeft = timerIndex++;
|
protected static final int timerShootLeft = timerIndex++;
|
||||||
protected static final int timerShootRight = 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.entities.units.UnitState;
|
||||||
import io.anuke.mindustry.game.EventType.BuildSelectEvent;
|
import io.anuke.mindustry.game.EventType.BuildSelectEvent;
|
||||||
import io.anuke.mindustry.gen.Call;
|
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.Tile;
|
||||||
import io.anuke.mindustry.world.blocks.BuildBlock;
|
import io.anuke.mindustry.world.blocks.BuildBlock;
|
||||||
import io.anuke.mindustry.world.blocks.BuildBlock.BuildEntity;
|
import io.anuke.mindustry.world.blocks.BuildBlock.BuildEntity;
|
||||||
@@ -21,10 +22,11 @@ import io.anuke.mindustry.world.meta.BlockFlag;
|
|||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.unitGroups;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
import static io.anuke.mindustry.Vars.world;
|
|
||||||
|
|
||||||
public class Drone extends FlyingUnit implements BuilderTrait{
|
public class Drone extends FlyingUnit implements BuilderTrait{
|
||||||
|
|
||||||
|
|
||||||
protected Item targetItem;
|
protected Item targetItem;
|
||||||
protected Tile mineTile;
|
protected Tile mineTile;
|
||||||
protected Queue<BuildRequest> placeQueue = new Queue<>();
|
protected Queue<BuildRequest> placeQueue = new Queue<>();
|
||||||
@@ -51,24 +53,12 @@ public class Drone extends FlyingUnit implements BuilderTrait{
|
|||||||
|
|
||||||
if(core == null) return;
|
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(!isBuilding() && dst(target) < placeDistance * 0.9f){ //within distance, begin placing
|
||||||
if(isBreaking){
|
if(isBreaking){
|
||||||
getPlaceQueue().addLast(new BuildRequest(entity.tile.x, entity.tile.y));
|
getPlaceQueue().addLast(new BuildRequest(entity.tile.x, entity.tile.y));
|
||||||
}else{
|
}else{
|
||||||
getPlaceQueue().addLast(new BuildRequest(entity.tile.x, entity.tile.y, entity.tile.getRotation(), entity.block));
|
getPlaceQueue().addLast(new BuildRequest(entity.tile.x, entity.tile.y, entity.tile.getRotation(), entity.cblock));
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,7 +212,6 @@ public class Drone extends FlyingUnit implements BuilderTrait{
|
|||||||
EntityGroup<BaseUnit> group = unitGroups[event.team.ordinal()];
|
EntityGroup<BaseUnit> group = unitGroups[event.team.ordinal()];
|
||||||
|
|
||||||
if(!(event.builder instanceof Player) || !(event.tile.entity instanceof BuildEntity)) return;
|
if(!(event.builder instanceof Player) || !(event.tile.entity instanceof BuildEntity)) return;
|
||||||
BuildEntity entity = event.tile.entity();
|
|
||||||
|
|
||||||
for(BaseUnit unit : group.all()){
|
for(BaseUnit unit : group.all()){
|
||||||
if(unit instanceof Drone){
|
if(unit instanceof Drone){
|
||||||
@@ -235,23 +224,11 @@ public class Drone extends FlyingUnit implements BuilderTrait{
|
|||||||
drone.setState(drone.repair);
|
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
|
@Override
|
||||||
public boolean canMine(Item item){
|
public boolean canMine(Item item){
|
||||||
return type.toMine.contains(item);
|
return type.toMine.contains(item);
|
||||||
@@ -290,6 +267,25 @@ public class Drone extends FlyingUnit implements BuilderTrait{
|
|||||||
target = null;
|
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();
|
updateBuilding();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -330,7 +326,7 @@ public class Drone extends FlyingUnit implements BuilderTrait{
|
|||||||
if(entity == null){
|
if(entity == null){
|
||||||
return;
|
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
|
@Override
|
||||||
|
|||||||
@@ -383,6 +383,9 @@ public class Tile implements Position, TargetTrait{
|
|||||||
for(int i = 0; i < 8; i++){
|
for(int i = 0; i < 8; i++){
|
||||||
Point2 point = Geometry.d8[i];
|
Point2 point = Geometry.d8[i];
|
||||||
Tile tile = world.tile(x + point.x, y + point.y);
|
Tile tile = world.tile(x + point.x, y + point.y);
|
||||||
|
if(tile != null && tile.floor.isLiquid){
|
||||||
|
cost += 3;
|
||||||
|
}
|
||||||
if(tile != null && tile.solid()){
|
if(tile != null && tile.solid()){
|
||||||
occluded = true;
|
occluded = true;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -76,19 +76,19 @@ public class BuildBlock extends Block{
|
|||||||
@Override
|
@Override
|
||||||
public String getDisplayName(Tile tile){
|
public String getDisplayName(Tile tile){
|
||||||
BuildEntity entity = tile.entity();
|
BuildEntity entity = tile.entity();
|
||||||
return Core.bundle.format("block.constructing", entity.block == null ? entity.previous.localizedName : entity.block.localizedName);
|
return Core.bundle.format("block.constructing", entity.cblock == null ? entity.previous.localizedName : entity.cblock.localizedName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TextureRegion getDisplayIcon(Tile tile){
|
public TextureRegion getDisplayIcon(Tile tile){
|
||||||
BuildEntity entity = tile.entity();
|
BuildEntity entity = tile.entity();
|
||||||
return (entity.block == null ? entity.previous : entity.block).icon(Icon.full);
|
return (entity.cblock == null ? entity.previous : entity.cblock).icon(Icon.full);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSolidFor(Tile tile){
|
public boolean isSolidFor(Tile tile){
|
||||||
BuildEntity entity = tile.entity();
|
BuildEntity entity = tile.entity();
|
||||||
return entity == null || (entity.block != null && entity.block.solid) || entity.previous == null || entity.previous.solid;
|
return entity == null || (entity.cblock != null && entity.cblock.solid) || entity.previous == null || entity.previous.solid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -101,9 +101,9 @@ public class BuildBlock extends Block{
|
|||||||
BuildEntity entity = tile.entity();
|
BuildEntity entity = tile.entity();
|
||||||
|
|
||||||
//if the target is constructible, begin constructing
|
//if the target is constructible, begin constructing
|
||||||
if(entity.block != null){
|
if(entity.cblock != null){
|
||||||
player.clearBuilding();
|
player.clearBuilding();
|
||||||
player.addBuildRequest(new BuildRequest(tile.x, tile.y, tile.getRotation(), entity.block));
|
player.addBuildRequest(new BuildRequest(tile.x, tile.y, tile.getRotation(), entity.cblock));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +121,7 @@ public class BuildBlock extends Block{
|
|||||||
BuildEntity entity = tile.entity();
|
BuildEntity entity = tile.entity();
|
||||||
|
|
||||||
//When breaking, don't draw the previous block... since it's the thing you were breaking
|
//When breaking, don't draw the previous block... since it's the thing you were breaking
|
||||||
if(entity.block != null && entity.previous == entity.block){
|
if(entity.cblock != null && entity.previous == entity.cblock){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +139,7 @@ public class BuildBlock extends Block{
|
|||||||
|
|
||||||
Shaders.blockbuild.color = Pal.accent;
|
Shaders.blockbuild.color = Pal.accent;
|
||||||
|
|
||||||
Block target = entity.block == null ? entity.previous : entity.block;
|
Block target = entity.cblock == null ? entity.previous : entity.cblock;
|
||||||
|
|
||||||
if(target == null) return;
|
if(target == null) return;
|
||||||
|
|
||||||
@@ -162,7 +162,7 @@ public class BuildBlock extends Block{
|
|||||||
* The recipe of the block that is being constructed.
|
* The recipe of the block that is being constructed.
|
||||||
* If there is no recipe for this block, as is the case with rocks, 'previous' is used.
|
* If there is no recipe for this block, as is the case with rocks, 'previous' is used.
|
||||||
*/
|
*/
|
||||||
public Block block;
|
public Block cblock;
|
||||||
|
|
||||||
public float progress = 0;
|
public float progress = 0;
|
||||||
public float buildCost;
|
public float buildCost;
|
||||||
@@ -177,15 +177,15 @@ public class BuildBlock extends Block{
|
|||||||
private float[] totalAccumulator;
|
private float[] totalAccumulator;
|
||||||
|
|
||||||
public void construct(Unit builder, TileEntity core, float amount){
|
public void construct(Unit builder, TileEntity core, float amount){
|
||||||
if(block == null){
|
if(cblock == null){
|
||||||
kill();
|
kill();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
float maxProgress = checkRequired(core.items, amount, false);
|
float maxProgress = checkRequired(core.items, amount, false);
|
||||||
|
|
||||||
for(int i = 0; i < block.buildRequirements.length; i++){
|
for(int i = 0; i < cblock.buildRequirements.length; i++){
|
||||||
int reqamount = Math.round(state.rules.buildCostMultiplier * block.buildRequirements[i].amount);
|
int reqamount = Math.round(state.rules.buildCostMultiplier * cblock.buildRequirements[i].amount);
|
||||||
accumulator[i] += Math.min(reqamount * maxProgress, reqamount - totalAccumulator[i] + 0.00001f); //add min amount progressed to the accumulator
|
accumulator[i] += Math.min(reqamount * maxProgress, reqamount - totalAccumulator[i] + 0.00001f); //add min amount progressed to the accumulator
|
||||||
totalAccumulator[i] = Math.min(totalAccumulator[i] + reqamount * maxProgress, reqamount);
|
totalAccumulator[i] = Math.min(totalAccumulator[i] + reqamount * maxProgress, reqamount);
|
||||||
}
|
}
|
||||||
@@ -199,15 +199,15 @@ public class BuildBlock extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(progress >= 1f || state.rules.infiniteResources){
|
if(progress >= 1f || state.rules.infiniteResources){
|
||||||
Call.onConstructFinish(tile, block, builderID, tile.getRotation(), builder.getTeam());
|
Call.onConstructFinish(tile, cblock, builderID, tile.getRotation(), builder.getTeam());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deconstruct(Unit builder, TileEntity core, float amount){
|
public void deconstruct(Unit builder, TileEntity core, float amount){
|
||||||
float deconstructMultiplier = 0.5f;
|
float deconstructMultiplier = 0.5f;
|
||||||
|
|
||||||
if(block != null){
|
if(cblock != null){
|
||||||
ItemStack[] requirements = block.buildRequirements;
|
ItemStack[] requirements = cblock.buildRequirements;
|
||||||
if(requirements.length != accumulator.length || totalAccumulator.length != requirements.length){
|
if(requirements.length != accumulator.length || totalAccumulator.length != requirements.length){
|
||||||
setDeconstruct(previous);
|
setDeconstruct(previous);
|
||||||
}
|
}
|
||||||
@@ -231,22 +231,22 @@ public class BuildBlock extends Block{
|
|||||||
progress = Mathf.clamp(progress - amount);
|
progress = Mathf.clamp(progress - amount);
|
||||||
|
|
||||||
if(progress <= 0 || state.rules.infiniteResources){
|
if(progress <= 0 || state.rules.infiniteResources){
|
||||||
Call.onDeconstructFinish(tile, this.block == null ? previous : this.block);
|
Call.onDeconstructFinish(tile, this.cblock == null ? previous : this.cblock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private float checkRequired(ItemModule inventory, float amount, boolean remove){
|
private float checkRequired(ItemModule inventory, float amount, boolean remove){
|
||||||
float maxProgress = amount;
|
float maxProgress = amount;
|
||||||
|
|
||||||
for(int i = 0; i < block.buildRequirements.length; i++){
|
for(int i = 0; i < cblock.buildRequirements.length; i++){
|
||||||
int sclamount = Math.round(state.rules.buildCostMultiplier * block.buildRequirements[i].amount);
|
int sclamount = Math.round(state.rules.buildCostMultiplier * cblock.buildRequirements[i].amount);
|
||||||
int required = (int)(accumulator[i]); //calculate items that are required now
|
int required = (int)(accumulator[i]); //calculate items that are required now
|
||||||
|
|
||||||
if(inventory.get(block.buildRequirements[i].item) == 0 && sclamount != 0){
|
if(inventory.get(cblock.buildRequirements[i].item) == 0 && sclamount != 0){
|
||||||
maxProgress = 0f;
|
maxProgress = 0f;
|
||||||
}else if(required > 0){ //if this amount is positive...
|
}else if(required > 0){ //if this amount is positive...
|
||||||
//calculate how many items it can actually use
|
//calculate how many items it can actually use
|
||||||
int maxUse = Math.min(required, inventory.get(block.buildRequirements[i].item));
|
int maxUse = Math.min(required, inventory.get(cblock.buildRequirements[i].item));
|
||||||
//get this as a fraction
|
//get this as a fraction
|
||||||
float fraction = maxUse / (float)required;
|
float fraction = maxUse / (float)required;
|
||||||
|
|
||||||
@@ -257,7 +257,7 @@ public class BuildBlock extends Block{
|
|||||||
|
|
||||||
//remove stuff that is actually used
|
//remove stuff that is actually used
|
||||||
if(remove){
|
if(remove){
|
||||||
inventory.remove(block.buildRequirements[i].item, maxUse);
|
inventory.remove(cblock.buildRequirements[i].item, maxUse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//else, no items are required yet, so just keep going
|
//else, no items are required yet, so just keep going
|
||||||
@@ -271,7 +271,7 @@ public class BuildBlock extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setConstruct(Block previous, Block block){
|
public void setConstruct(Block previous, Block block){
|
||||||
this.block = block;
|
this.cblock = block;
|
||||||
this.previous = previous;
|
this.previous = previous;
|
||||||
this.accumulator = new float[block.buildRequirements.length];
|
this.accumulator = new float[block.buildRequirements.length];
|
||||||
this.totalAccumulator = new float[block.buildRequirements.length];
|
this.totalAccumulator = new float[block.buildRequirements.length];
|
||||||
@@ -282,7 +282,7 @@ public class BuildBlock extends Block{
|
|||||||
this.previous = previous;
|
this.previous = previous;
|
||||||
this.progress = 1f;
|
this.progress = 1f;
|
||||||
if(previous.buildCost >= 0.01f){
|
if(previous.buildCost >= 0.01f){
|
||||||
this.block = previous;
|
this.cblock = previous;
|
||||||
this.accumulator = new float[previous.buildRequirements.length];
|
this.accumulator = new float[previous.buildRequirements.length];
|
||||||
this.totalAccumulator = new float[previous.buildRequirements.length];
|
this.totalAccumulator = new float[previous.buildRequirements.length];
|
||||||
this.buildCost = previous.buildCost * state.rules.buildCostMultiplier;
|
this.buildCost = previous.buildCost * state.rules.buildCostMultiplier;
|
||||||
@@ -295,7 +295,7 @@ public class BuildBlock extends Block{
|
|||||||
public void write(DataOutput stream) throws IOException{
|
public void write(DataOutput stream) throws IOException{
|
||||||
stream.writeFloat(progress);
|
stream.writeFloat(progress);
|
||||||
stream.writeShort(previous == null ? -1 : previous.id);
|
stream.writeShort(previous == null ? -1 : previous.id);
|
||||||
stream.writeShort(block == null ? -1 : block.id);
|
stream.writeShort(cblock == null ? -1 : cblock.id);
|
||||||
|
|
||||||
if(accumulator == null){
|
if(accumulator == null){
|
||||||
stream.writeByte(-1);
|
stream.writeByte(-1);
|
||||||
@@ -325,10 +325,10 @@ public class BuildBlock extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(pid != -1) previous = content.block(pid);
|
if(pid != -1) previous = content.block(pid);
|
||||||
if(rid != -1) block = content.block(rid);
|
if(rid != -1) cblock = content.block(rid);
|
||||||
|
|
||||||
if(block != null){
|
if(cblock != null){
|
||||||
buildCost = block.buildCost * state.rules.buildCostMultiplier;
|
buildCost = cblock.buildCost * state.rules.buildCostMultiplier;
|
||||||
}else{
|
}else{
|
||||||
buildCost = 20f;
|
buildCost = 20f;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user