mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-30 22:49:06 +07:00
Made core drone pick up dropped items
This commit is contained in:
@ -127,7 +127,7 @@ public class UnitInventory implements Saveable{
|
||||
}
|
||||
|
||||
public boolean canAcceptItem(Item type, int amount){
|
||||
return !hasItem() || (item.item == type && item.amount + amount <= unit.getItemCapacity());
|
||||
return (!hasItem() && amount <= unit.getItemCapacity()) || (item.item == type && item.amount + amount <= unit.getItemCapacity());
|
||||
}
|
||||
|
||||
public void clear(){
|
||||
|
@ -8,8 +8,11 @@ import io.anuke.annotations.Annotations.Loc;
|
||||
import io.anuke.annotations.Annotations.Remote;
|
||||
import io.anuke.mindustry.content.fx.UnitFx;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.entities.traits.SaveTrait;
|
||||
import io.anuke.mindustry.entities.traits.SyncTrait;
|
||||
import io.anuke.mindustry.entities.traits.TargetTrait;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.gen.CallEntity;
|
||||
import io.anuke.mindustry.net.In;
|
||||
import io.anuke.mindustry.net.Interpolator;
|
||||
@ -33,7 +36,7 @@ import java.io.IOException;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class ItemDrop extends SolidEntity implements SaveTrait, SyncTrait, DrawTrait, VelocityTrait, TimeTrait, Poolable {
|
||||
public class ItemDrop extends SolidEntity implements SaveTrait, SyncTrait, DrawTrait, VelocityTrait, TimeTrait, TargetTrait, Poolable {
|
||||
public static int typeID = -1;
|
||||
|
||||
private static final float sinkLifetime = 80f;
|
||||
@ -77,6 +80,24 @@ public class ItemDrop extends SolidEntity implements SaveTrait, SyncTrait, DrawT
|
||||
hitboxTile.setSize(5f);
|
||||
}
|
||||
|
||||
public Item getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public int getAmount(){
|
||||
return amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDead() {
|
||||
return !isAdded();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Team getTeam() {
|
||||
return Team.none;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTypeID() {
|
||||
return typeID;
|
||||
@ -109,7 +130,7 @@ public class ItemDrop extends SolidEntity implements SaveTrait, SyncTrait, DrawT
|
||||
|
||||
@Override
|
||||
public void collision(SolidTrait other, float x, float y) {
|
||||
Player player = (Player)other;
|
||||
Unit player = (Unit)other;
|
||||
if(player.inventory.canAcceptItem(item, 1)){
|
||||
int used = Math.min(amount, player.inventory.capacity() - player.inventory.getItem().amount);
|
||||
player.inventory.addItem(item, used);
|
||||
|
@ -6,6 +6,7 @@ import com.badlogic.gdx.utils.Queue;
|
||||
import io.anuke.mindustry.content.Items;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.Units;
|
||||
import io.anuke.mindustry.entities.effect.ItemDrop;
|
||||
import io.anuke.mindustry.entities.traits.BuilderTrait;
|
||||
import io.anuke.mindustry.entities.units.BaseUnit;
|
||||
import io.anuke.mindustry.entities.units.FlyingUnit;
|
||||
@ -24,12 +25,15 @@ import io.anuke.mindustry.world.meta.BlockFlag;
|
||||
import io.anuke.ucore.core.Events;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.entities.EntityGroup;
|
||||
import io.anuke.ucore.entities.EntityPhysics;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.graphics.Shapes;
|
||||
import io.anuke.ucore.util.*;
|
||||
import io.anuke.ucore.util.Angles;
|
||||
import io.anuke.ucore.util.Geometry;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.ThreadQueue;
|
||||
|
||||
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 {
|
||||
public static int typeID = -1;
|
||||
@ -181,6 +185,23 @@ public class Drone extends FlyingUnit implements BuilderTrait {
|
||||
targetItem = Mathf.findMin(toMine, (a, b) -> -Integer.compare(entity.items.getItem(a), entity.items.getItem(b)));
|
||||
}
|
||||
|
||||
protected boolean findItemDrop(){
|
||||
TileEntity core = getClosestCore();
|
||||
|
||||
if(core == null) return false;
|
||||
|
||||
//find nearby dropped items to pick up if applicable
|
||||
ItemDrop drop = EntityPhysics.getClosest(itemGroup, x, y, 60f,
|
||||
item -> core.tile.block().acceptStack(item.getItem(), item.getAmount(), core.tile, Drone.this) == item.getAmount() &&
|
||||
inventory.canAcceptItem(item.getItem(), 1));
|
||||
if(drop != null){
|
||||
setState(pickup);
|
||||
target = drop;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public final UnitState
|
||||
|
||||
build = new UnitState(){
|
||||
@ -256,6 +277,10 @@ public class Drone extends FlyingUnit implements BuilderTrait {
|
||||
}
|
||||
|
||||
public void update() {
|
||||
TileEntity entity = getClosestCore();
|
||||
|
||||
if(entity == null) return;
|
||||
|
||||
if(targetItem == null) {
|
||||
findItem();
|
||||
}
|
||||
@ -270,6 +295,10 @@ public class Drone extends FlyingUnit implements BuilderTrait {
|
||||
}
|
||||
|
||||
retarget(() -> {
|
||||
if(findItemDrop()){
|
||||
return;
|
||||
}
|
||||
|
||||
if(getMineTile() == null){
|
||||
findItem();
|
||||
}
|
||||
@ -279,7 +308,7 @@ public class Drone extends FlyingUnit implements BuilderTrait {
|
||||
target = world.indexer().findClosestOre(x, y, targetItem);
|
||||
});
|
||||
|
||||
if(target != null) {
|
||||
if(target instanceof Tile) {
|
||||
moveTo(type.range/1.5f);
|
||||
|
||||
if (distanceTo(target) < type.range) {
|
||||
@ -293,6 +322,33 @@ public class Drone extends FlyingUnit implements BuilderTrait {
|
||||
setMineTile(null);
|
||||
}
|
||||
},
|
||||
pickup = new UnitState() {
|
||||
public void entered() {
|
||||
target = null;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
ItemDrop item = (ItemDrop)target;
|
||||
|
||||
if(inventory.isFull() || !inventory.canAcceptItem(item.getItem(), 1)){
|
||||
setState(drop);
|
||||
return;
|
||||
}
|
||||
|
||||
if(distanceTo(item) < 4){
|
||||
item.collision(Drone.this, x, y);
|
||||
}
|
||||
|
||||
//item has been picked up
|
||||
if(item.getAmount() == 0){
|
||||
if(!findItemDrop()){
|
||||
setState(drop);
|
||||
}
|
||||
}
|
||||
|
||||
moveTo(0f);
|
||||
}
|
||||
},
|
||||
drop = new UnitState() {
|
||||
public void entered() {
|
||||
target = null;
|
||||
|
@ -44,7 +44,7 @@ public class FogRenderer implements Disposable{
|
||||
for (int y = 0; y < world.height(); y++) {
|
||||
Tile tile = world.tile(x, y);
|
||||
|
||||
if(tile.getTeam() == players[0].getTeam() && tile.block().viewRange > 0){
|
||||
if(tile.getTeam() == players[0].getTeam() && tile.block().synthetic() && tile.block().viewRange > 0){
|
||||
changeQueue.add(tile);
|
||||
}
|
||||
}
|
||||
@ -52,7 +52,7 @@ public class FogRenderer implements Disposable{
|
||||
});
|
||||
|
||||
Events.on(TileChangeEvent.class, tile -> threads.runGraphics(() -> {
|
||||
if(tile.getTeam() == players[0].getTeam() && tile.block().viewRange > 0){
|
||||
if(tile.getTeam() == players[0].getTeam() && tile.block().synthetic() && tile.block().viewRange > 0){
|
||||
changeQueue.add(tile);
|
||||
}
|
||||
}));
|
||||
@ -106,7 +106,6 @@ public class FogRenderer implements Disposable{
|
||||
buffer.end();
|
||||
|
||||
region.setTexture(buffer.getColorBufferTexture());
|
||||
//region.setRegion(0, 0, 1, 1);
|
||||
region.setRegion(u, v2, u2, v);
|
||||
|
||||
Core.batch.setProjectionMatrix(Core.camera.combined);
|
||||
@ -114,7 +113,6 @@ public class FogRenderer implements Disposable{
|
||||
renderer.pixelSurface.getBuffer().begin();
|
||||
Graphics.begin();
|
||||
|
||||
// Core.batch.draw(buffer.getColorBufferTexture(), px + 50, py, 200, 200 * world.height()/(float)world.width());
|
||||
Core.batch.draw(region, px, py, vw, vh);
|
||||
|
||||
Graphics.end();
|
||||
|
@ -121,7 +121,7 @@ public class Block extends BaseBlock implements UnlockableContent{
|
||||
/**The color of this block when displayed on the minimap or map preview.*/
|
||||
public Color minimapColor = Color.CLEAR;
|
||||
/**View range of this block type. Use a value < 0 to disable.*/
|
||||
public float viewRange = -1;
|
||||
public float viewRange = 10;
|
||||
|
||||
public Block(String name) {
|
||||
this.name = name;
|
||||
@ -354,10 +354,10 @@ public class Block extends BaseBlock implements UnlockableContent{
|
||||
if(icon == null) {
|
||||
if (Draw.hasRegion(name + "-icon")) {
|
||||
icon = new TextureRegion[]{Draw.region(name + "-icon")};
|
||||
} else if (Draw.hasRegion(name)){
|
||||
icon = new TextureRegion[]{Draw.region(name)};
|
||||
} else if (Draw.hasRegion(name + "1")) {
|
||||
icon = new TextureRegion[]{Draw.region(name + "1")};
|
||||
} else if (Draw.hasRegion(name)){
|
||||
icon = new TextureRegion[]{Draw.region(name)};
|
||||
icon = new TextureRegion[]{Draw.region(name + "1")};
|
||||
}else{
|
||||
icon = new TextureRegion[]{};
|
||||
}
|
||||
|
Reference in New Issue
Block a user