diff --git a/core/src/io/anuke/mindustry/content/Recipes.java b/core/src/io/anuke/mindustry/content/Recipes.java index 92d447acaf..94c07d684c 100644 --- a/core/src/io/anuke/mindustry/content/Recipes.java +++ b/core/src/io/anuke/mindustry/content/Recipes.java @@ -139,7 +139,6 @@ public class Recipes implements ContentList{ new Recipe(units, UnitBlocks.monsoonPad, new ItemStack(Items.plastanium, 80), new ItemStack(Items.titanium, 100), new ItemStack(Items.lead, 130), new ItemStack(Items.silicon, 220)).setMode(GameMode.noWaves); new Recipe(units, UnitBlocks.repairPoint, new ItemStack(Items.lead, 30), new ItemStack(Items.tungsten, 30), new ItemStack(Items.silicon, 30)); - new Recipe(units, UnitBlocks.resupplyPoint, new ItemStack(Items.lead, 30), new ItemStack(Items.tungsten, 30), new ItemStack(Items.silicon, 30)); new Recipe(units, UnitBlocks.commandCenter, new ItemStack(Items.lead, 100), new ItemStack(Items.carbide, 100), new ItemStack(Items.silicon, 200)).setMode(GameMode.noWaves); //LIQUIDS diff --git a/core/src/io/anuke/mindustry/content/Weapons.java b/core/src/io/anuke/mindustry/content/Weapons.java index 934b05ea69..7909578967 100644 --- a/core/src/io/anuke/mindustry/content/Weapons.java +++ b/core/src/io/anuke/mindustry/content/Weapons.java @@ -19,7 +19,7 @@ public class Weapons implements ContentList{ reload = 15f; roundrobin = true; ejectEffect = ShootFx.shellEjectSmall; - setAmmo(AmmoTypes.bulletLead); + ammo = AmmoTypes.bulletLead; }}; missiles = new Weapon("missiles"){{ @@ -30,7 +30,7 @@ public class Weapons implements ContentList{ roundrobin = false; roundrobin = true; ejectEffect = Fx.none; - setAmmo(AmmoTypes.weaponMissile); + ammo = AmmoTypes.weaponMissile; }}; chainBlaster = new Weapon("chain-blaster"){{ @@ -38,7 +38,7 @@ public class Weapons implements ContentList{ reload = 28f; roundrobin = true; ejectEffect = ShootFx.shellEjectSmall; - setAmmo(AmmoTypes.bulletLead, AmmoTypes.bulletCarbide, AmmoTypes.bulletTungsten, AmmoTypes.bulletSilicon, AmmoTypes.bulletThorium); + ammo = AmmoTypes.bulletLead; }}; shockgun = new Weapon("shockgun"){{ @@ -50,7 +50,7 @@ public class Weapons implements ContentList{ recoil = 2f; velocityRnd = 0.7f; ejectEffect = ShootFx.shellEjectSmall; - setAmmo(AmmoTypes.shotgunTungsten); + ammo = AmmoTypes.shotgunTungsten; }}; flakgun = new Weapon("flakgun"){{ @@ -62,7 +62,7 @@ public class Weapons implements ContentList{ recoil = 3f; velocityRnd = 0.1f; ejectEffect = ShootFx.shellEjectMedium; - setAmmo(AmmoTypes.shellCarbide); + ammo = AmmoTypes.shellCarbide; }}; flamethrower = new Weapon("flamethrower"){{ @@ -71,7 +71,7 @@ public class Weapons implements ContentList{ roundrobin = true; recoil = 1f; ejectEffect = Fx.none; - setAmmo(AmmoTypes.flamerThermite); + ammo = AmmoTypes.flamerThermite; }}; sapper = new Weapon("sapper"){{ @@ -79,7 +79,7 @@ public class Weapons implements ContentList{ reload = 12f; roundrobin = true; ejectEffect = ShootFx.shellEjectSmall; - setAmmo(AmmoTypes.bulletCarbide); + ammo = AmmoTypes.bulletCarbide; }}; swarmer = new Weapon("swarmer"){{ @@ -87,7 +87,7 @@ public class Weapons implements ContentList{ reload = 10f; roundrobin = true; ejectEffect = ShootFx.shellEjectSmall; - setAmmo(AmmoTypes.bulletPyratite); + ammo = AmmoTypes.bulletPyratite; }}; bomber = new Weapon("bomber"){{ @@ -98,7 +98,7 @@ public class Weapons implements ContentList{ ejectEffect = Fx.none; velocityRnd = 1f; inaccuracy = 40f; - setAmmo(AmmoTypes.bombExplosive, AmmoTypes.bombIncendiary, AmmoTypes.bombOil); + ammo = AmmoTypes.bombExplosive; }}; } diff --git a/core/src/io/anuke/mindustry/content/blocks/UnitBlocks.java b/core/src/io/anuke/mindustry/content/blocks/UnitBlocks.java index 2159d0ab48..179b2b4642 100644 --- a/core/src/io/anuke/mindustry/content/blocks/UnitBlocks.java +++ b/core/src/io/anuke/mindustry/content/blocks/UnitBlocks.java @@ -8,7 +8,7 @@ import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.blocks.units.*; public class UnitBlocks extends BlockList implements ContentList{ - public static Block resupplyPoint, repairPoint, dronePad, + public static Block repairPoint, dronePad, fabricatorPad, interceptorPad, monsoonPad, daggerPad, titanPad, dropPoint, reconstructor, overdriveProjector, shieldProjector, commandCenter; @@ -64,11 +64,6 @@ public class UnitBlocks extends BlockList implements ContentList{ consumes.items(new ItemStack[]{new ItemStack(Items.silicon, 20), new ItemStack(Items.thorium, 30)}); }}; - resupplyPoint = new ResupplyPoint("resupply-point"){{ - shadow = "shadow-round-1"; - itemCapacity = 30; - }}; - dropPoint = new DropPoint("drop-point"){{ shadow = "shadow-round-1"; itemCapacity = 40; diff --git a/core/src/io/anuke/mindustry/entities/Player.java b/core/src/io/anuke/mindustry/entities/Player.java index 8f850da16f..2d6ad754e1 100644 --- a/core/src/io/anuke/mindustry/entities/Player.java +++ b/core/src/io/anuke/mindustry/entities/Player.java @@ -137,11 +137,6 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra return mech.itemCapacity; } - @Override - public int getAmmoCapacity(){ - return mech.ammoCapacity; - } - @Override public void interpolate(){ super.interpolate(); @@ -195,21 +190,11 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra return mech.armor; } - @Override - public boolean acceptsAmmo(Item item){ - return mech.weapon.getAmmoType(item) != null && inventory.canAcceptAmmo(mech.weapon.getAmmoType(item)); - } - @Override public void added(){ baseRotation = 90f; } - @Override - public void addAmmo(Item item){ - inventory.addAmmo(mech.weapon.getAmmoType(item)); - } - @Override public float getMass(){ return mech.mass; @@ -622,20 +607,20 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra y += Mathf.cos(Timers.time() + id * 999, 25f, 0.08f); //update shooting if not building, not mining and there's ammo left - if(!isBuilding() && inventory.hasAmmo() && getMineTile() == null){ + if(!isBuilding() && getMineTile() == null){ //autofire: mobile only! if(mobile){ if(target == null){ isShooting = false; - target = Units.getClosestTarget(team, x, y, inventory.getAmmoRange()); + target = Units.getClosestTarget(team, x, y, getWeapon().getAmmo().getRange()); }else if(target.isValid()){ //rotate toward and shoot the target rotation = Mathf.slerpDelta(rotation, angleTo(target), 0.2f); Vector2 intercept = - Predict.intercept(x, y, target.getX(), target.getY(), target.getVelocity().x - velocity.x, target.getVelocity().y - velocity.y, inventory.getAmmo().bullet.speed); + Predict.intercept(x, y, target.getX(), target.getY(), target.getVelocity().x - velocity.x, target.getVelocity().y - velocity.y, getWeapon().getAmmo().bullet.speed); pointerX = intercept.x; pointerY = intercept.y; @@ -679,7 +664,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra } public boolean isShooting(){ - return isShooting && inventory.hasAmmo() && (!isBoosting || mech.flying); + return isShooting && (!isBoosting || mech.flying); } public void updateRespawning(){ diff --git a/core/src/io/anuke/mindustry/entities/Unit.java b/core/src/io/anuke/mindustry/entities/Unit.java index e234c4936a..7b11948a6d 100644 --- a/core/src/io/anuke/mindustry/entities/Unit.java +++ b/core/src/io/anuke/mindustry/entities/Unit.java @@ -8,8 +8,8 @@ import io.anuke.mindustry.game.Team; import io.anuke.mindustry.game.TeamInfo.TeamData; import io.anuke.mindustry.net.Interpolator; import io.anuke.mindustry.net.Net; -import io.anuke.mindustry.type.Item; import io.anuke.mindustry.type.StatusEffect; +import io.anuke.mindustry.type.Weapon; import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.blocks.Floor; import io.anuke.ucore.core.Effects; @@ -300,10 +300,6 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ } } - public float getAmmoFraction(){ - return inventory.totalAmmo() / (float) inventory.ammoCapacity(); - } - public void drawUnder(){ } @@ -328,16 +324,12 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ public abstract TextureRegion getIconRegion(); + public abstract Weapon getWeapon(); + public abstract int getItemCapacity(); - public abstract int getAmmoCapacity(); - public abstract float getArmor(); - public abstract boolean acceptsAmmo(Item item); - - public abstract void addAmmo(Item item); - public abstract float getMass(); public abstract boolean isFlying(); diff --git a/core/src/io/anuke/mindustry/entities/UnitInventory.java b/core/src/io/anuke/mindustry/entities/UnitInventory.java index 0ebfcb27f9..834f0b8779 100644 --- a/core/src/io/anuke/mindustry/entities/UnitInventory.java +++ b/core/src/io/anuke/mindustry/entities/UnitInventory.java @@ -1,10 +1,7 @@ package io.anuke.mindustry.entities; -import com.badlogic.gdx.utils.Array; import io.anuke.mindustry.content.Items; import io.anuke.mindustry.entities.traits.Saveable; -import io.anuke.mindustry.type.AmmoEntry; -import io.anuke.mindustry.type.AmmoType; import io.anuke.mindustry.type.Item; import io.anuke.mindustry.type.ItemStack; @@ -14,8 +11,6 @@ import java.io.IOException; public class UnitInventory implements Saveable{ private final Unit unit; - private Array ammos = new Array<>(); - private int totalAmmo; private ItemStack item = new ItemStack(Items.stone, 0); public UnitInventory(Unit unit){ @@ -30,90 +25,19 @@ public class UnitInventory implements Saveable{ public void writeSave(DataOutput stream) throws IOException{ stream.writeShort(item.amount); stream.writeByte(item.item.id); - stream.writeShort(totalAmmo); - stream.writeByte(ammos.size); - for(int i = 0; i < ammos.size; i++){ - stream.writeByte(ammos.get(i).type.id); - stream.writeShort(ammos.get(i).amount); - } } @Override public void readSave(DataInput stream) throws IOException{ short iamount = stream.readShort(); byte iid = stream.readByte(); - this.totalAmmo = stream.readShort(); - byte ammoa = stream.readByte(); - for(int i = 0; i < ammoa; i++){ - byte aid = stream.readByte(); - int am = stream.readShort(); - ammos.add(new AmmoEntry(AmmoType.getByID(aid), am)); - } item.item = Item.getByID(iid); item.amount = iamount; } - /** - * Returns ammo range, or MAX_VALUE if this inventory has no ammo. - */ - public float getAmmoRange(){ - return hasAmmo() ? getAmmo().getRange() : Float.MAX_VALUE; - } - - public AmmoType getAmmo(){ - return ammos.size == 0 ? null : ammos.peek().type; - } - - public boolean hasAmmo(){ - return totalAmmo > 0; - } - - public void useAmmo(){ - if(unit.isInfiniteAmmo()) return; - AmmoEntry entry = ammos.peek(); - entry.amount--; - if(entry.amount == 0) ammos.pop(); - totalAmmo--; - } - - public int totalAmmo(){ - return totalAmmo; - } - - public int ammoCapacity(){ - return unit.getAmmoCapacity(); - } - - public boolean canAcceptAmmo(AmmoType type){ - return totalAmmo + type.quantityMultiplier <= unit.getAmmoCapacity(); - } - - public void addAmmo(AmmoType type){ - if(type == null) return; - totalAmmo += type.quantityMultiplier; - - //find ammo entry by type - for(int i = ammos.size - 1; i >= 0; i--){ - AmmoEntry entry = ammos.get(i); - - //if found, put it to the right - if(entry.type == type){ - entry.amount += type.quantityMultiplier; - ammos.swap(i, ammos.size - 1); - return; - } - } - - //must not be found - AmmoEntry entry = new AmmoEntry(type, (int) type.quantityMultiplier); - ammos.add(entry); - } - - public void fillAmmo(AmmoType type){ - totalAmmo = ammoCapacity(); - ammos.clear(); - ammos.add(new AmmoEntry(type, ammoCapacity())); + public void clear(){ + item.amount = 0; } public int capacity(){ @@ -140,12 +64,6 @@ public class UnitInventory implements Saveable{ return (!hasItem() && amount <= unit.getItemCapacity()) || (item.item == type && item.amount + amount <= unit.getItemCapacity()); } - public void clear(){ - item.amount = 0; - ammos.clear(); - totalAmmo = 0; - } - public void clearItem(){ item.amount = 0; } diff --git a/core/src/io/anuke/mindustry/entities/Units.java b/core/src/io/anuke/mindustry/entities/Units.java index 1b9fcb27f2..75098b9568 100644 --- a/core/src/io/anuke/mindustry/entities/Units.java +++ b/core/src/io/anuke/mindustry/entities/Units.java @@ -51,7 +51,7 @@ public class Units{ * See {@link #invalidateTarget(TargetTrait, Team, float, float, float)} */ public static boolean invalidateTarget(TargetTrait target, Unit targeter){ - return invalidateTarget(target, targeter.team, targeter.x, targeter.y, targeter.inventory.getAmmoRange()); + return invalidateTarget(target, targeter.team, targeter.x, targeter.y, targeter.getWeapon().getAmmo().getRange()); } /** diff --git a/core/src/io/anuke/mindustry/entities/effect/ItemTransfer.java b/core/src/io/anuke/mindustry/entities/effect/ItemTransfer.java index 27ef69d948..bf23331e32 100644 --- a/core/src/io/anuke/mindustry/entities/effect/ItemTransfer.java +++ b/core/src/io/anuke/mindustry/entities/effect/ItemTransfer.java @@ -34,14 +34,6 @@ public class ItemTransfer extends TimedEntity implements DrawTrait{ public ItemTransfer(){ } - @Remote(called = Loc.server, unreliable = true) - public static void transferAmmo(Item item, float x, float y, Unit to){ - if(to == null) return; - to.addAmmo(item); - create(item, x, y, to, () -> { - }); - } - @Remote(called = Loc.server, unreliable = true) public static void transferItemEffect(Item item, float x, float y, Unit to){ if(to == null) return; diff --git a/core/src/io/anuke/mindustry/entities/units/BaseUnit.java b/core/src/io/anuke/mindustry/entities/units/BaseUnit.java index 8a3b2696b6..562a76128f 100644 --- a/core/src/io/anuke/mindustry/entities/units/BaseUnit.java +++ b/core/src/io/anuke/mindustry/entities/units/BaseUnit.java @@ -19,7 +19,6 @@ import io.anuke.mindustry.game.TeamInfo.TeamData; import io.anuke.mindustry.gen.Call; import io.anuke.mindustry.graphics.Palette; import io.anuke.mindustry.net.Net; -import io.anuke.mindustry.type.Item; import io.anuke.mindustry.type.ItemStack; import io.anuke.mindustry.type.Weapon; import io.anuke.mindustry.world.Tile; @@ -185,7 +184,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{ } public void targetClosest(){ - target = Units.getClosestTarget(team, x, y, inventory.getAmmoRange()); + target = Units.getClosestTarget(team, x, y, getWeapon().getAmmo().getRange()); } public TileEntity getClosestEnemyCore(){ @@ -253,11 +252,6 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{ return type.itemCapacity; } - @Override - public int getAmmoCapacity(){ - return type.ammoCapacity; - } - @Override public boolean isInfiniteAmmo(){ return isWave; @@ -282,16 +276,6 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{ return type.armor; } - @Override - public boolean acceptsAmmo(Item item){ - return getWeapon().getAmmoType(item) != null && inventory.canAcceptAmmo(getWeapon().getAmmoType(item)); - } - - @Override - public void addAmmo(Item item){ - inventory.addAmmo(getWeapon().getAmmoType(item)); - } - @Override public float getSize(){ return 8; diff --git a/core/src/io/anuke/mindustry/entities/units/FlyingUnit.java b/core/src/io/anuke/mindustry/entities/units/FlyingUnit.java index e7085f93b6..6dc76ac680 100644 --- a/core/src/io/anuke/mindustry/entities/units/FlyingUnit.java +++ b/core/src/io/anuke/mindustry/entities/units/FlyingUnit.java @@ -28,22 +28,6 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{ protected CarriableTrait carrying; protected final UnitState - resupply = new UnitState(){ - public void entered(){ - target = null; - } - - public void update(){ - if(inventory.totalAmmo() + 10 >= inventory.ammoCapacity()){ - state.set(attack); - }else if(!targetHasFlag(BlockFlag.resupplyPoint)){ - retarget(() -> targetClosestAllyFlag(BlockFlag.resupplyPoint)); - }else{ - circle(20f); - } - } - }, - idle = new UnitState(){ public void update(){ if(!isCommanded()){ @@ -75,9 +59,7 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{ target = null; } - if(!inventory.hasAmmo()){ - state.set(resupply); - }else if(target == null){ + if(target == null){ retarget(() -> { targetClosest(); if(target == null) targetClosestEnemyFlag(BlockFlag.target); @@ -91,10 +73,9 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{ }else{ attack(150f); - if((Mathf.angNear(angleTo(target), rotation, 15f) || !inventory.getAmmo().bullet.keepVelocity) //bombers don't care about rotation - && distanceTo(target) < inventory.getAmmo().getRange()){ - AmmoType ammo = inventory.getAmmo(); - inventory.useAmmo(); + if((Mathf.angNear(angleTo(target), rotation, 15f) || !getWeapon().getAmmo().bullet.keepVelocity) //bombers don't care about rotation + && distanceTo(target) < getWeapon().getAmmo().getRange()){ + AmmoType ammo = getWeapon().getAmmo(); Vector2 to = Predict.intercept(FlyingUnit.this, target, ammo.bullet.speed); diff --git a/core/src/io/anuke/mindustry/entities/units/GroundUnit.java b/core/src/io/anuke/mindustry/entities/units/GroundUnit.java index 9f2027c05c..38bcda1ff3 100644 --- a/core/src/io/anuke/mindustry/entities/units/GroundUnit.java +++ b/core/src/io/anuke/mindustry/entities/units/GroundUnit.java @@ -12,11 +12,9 @@ import io.anuke.mindustry.type.Upgrade; import io.anuke.mindustry.type.Weapon; import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.blocks.Floor; -import io.anuke.mindustry.world.meta.BlockFlag; import io.anuke.ucore.core.Timers; import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.util.Angles; -import io.anuke.ucore.util.Geometry; import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Translator; @@ -35,24 +33,6 @@ public abstract class GroundUnit extends BaseUnit{ public final UnitState - resupply = new UnitState(){ - public void entered(){ - target = null; - } - - public void update(){ - Tile tile = Geometry.findClosest(x, y, world.indexer().getAllied(team, BlockFlag.resupplyPoint)); - - if(tile != null && distanceTo(tile) > 40){ - moveAwayFromCore(); - } - - //TODO move toward resupply point - if(isWave || inventory.totalAmmo() + 10 >= inventory.ammoCapacity()){ - state.set(attack); - } - } - }, attack = new UnitState(){ public void entered(){ target = null; @@ -62,17 +42,15 @@ public abstract class GroundUnit extends BaseUnit{ TileEntity core = getClosestEnemyCore(); float dst = core == null ? 0 : distanceTo(core); - if(core != null && inventory.hasAmmo() && dst < inventory.getAmmo().getRange() / 1.1f){ + if(core != null && dst < getWeapon().getAmmo().getRange() / 1.1f){ target = core; }else{ retarget(() -> targetClosest()); } - if(!inventory.hasAmmo()){ - state.set(resupply); - }else if(target != null){ + if(target != null){ if(core != null){ - if(dst > inventory.getAmmo().getRange() * 0.5f){ + if(dst > getWeapon().getAmmo().getRange() * 0.5f){ moveToCore(); } @@ -80,11 +58,11 @@ public abstract class GroundUnit extends BaseUnit{ moveToCore(); } - if(distanceTo(target) < inventory.getAmmo().getRange()){ + if(distanceTo(target) < getWeapon().getAmmo().getRange()){ rotate(angleTo(target)); if(Mathf.angNear(angleTo(target), rotation, 13f)){ - AmmoType ammo = inventory.getAmmo(); + AmmoType ammo = getWeapon().getAmmo(); Vector2 to = Predict.intercept(GroundUnit.this, target, ammo.bullet.speed); @@ -143,14 +121,14 @@ public abstract class GroundUnit extends BaseUnit{ @Override public UnitState getStartState(){ - return resupply; + return attack; } @Override public void update(){ super.update(); - if(!velocity.isZero(0.0001f) && (target == null || !inventory.hasAmmo() || (inventory.hasAmmo() && distanceTo(target) > inventory.getAmmoRange()))){ + if(!velocity.isZero(0.0001f) && (target == null || (distanceTo(target) > getWeapon().getAmmo().getRange()))){ rotation = Mathf.slerpDelta(rotation, velocity.angle(), 0.2f); } } diff --git a/core/src/io/anuke/mindustry/entities/units/types/Drone.java b/core/src/io/anuke/mindustry/entities/units/types/Drone.java index 2530e50ec2..da5c9ecb53 100644 --- a/core/src/io/anuke/mindustry/entities/units/types/Drone.java +++ b/core/src/io/anuke/mindustry/entities/units/types/Drone.java @@ -391,11 +391,6 @@ public class Drone extends FlyingUnit implements BuilderTrait{ return isBuilding() ? placeDistance * 2f : 30f; } - @Override - public float getAmmoFraction(){ - return inventory.getItem().amount / (float) type.itemCapacity; - } - protected void findItem(){ TileEntity entity = getClosestCore(); if(entity == null){ diff --git a/core/src/io/anuke/mindustry/game/SpawnGroup.java b/core/src/io/anuke/mindustry/game/SpawnGroup.java index 4d8fe850be..6ccd8e5c38 100644 --- a/core/src/io/anuke/mindustry/game/SpawnGroup.java +++ b/core/src/io/anuke/mindustry/game/SpawnGroup.java @@ -114,12 +114,6 @@ public class SpawnGroup{ unit.inventory.addItem(items.item, items.amount); } - if(ammoItem != null){ - unit.inventory.addAmmo(unit.getWeapon().getAmmoType(ammoItem)); - }else{ - unit.inventory.addAmmo(unit.getWeapon().getAmmoType(unit.getWeapon().getAcceptedItems().iterator().next())); - } - return unit; } } diff --git a/core/src/io/anuke/mindustry/graphics/OverlayRenderer.java b/core/src/io/anuke/mindustry/graphics/OverlayRenderer.java index 2b8d7afd71..0127965d68 100644 --- a/core/src/io/anuke/mindustry/graphics/OverlayRenderer.java +++ b/core/src/io/anuke/mindustry/graphics/OverlayRenderer.java @@ -180,9 +180,8 @@ public class OverlayRenderer{ y = (int) (y + 0.0001f); } - drawEncloser(x, y - 9f, 2f); + drawEncloser(x, y - 8f, 1f); drawBar(Palette.healthstats, x, y - 8f, unit.healthf()); - drawBar(Palette.ammo, x, y - 9f, unit.getAmmoFraction()); } void drawBar(Color color, float x, float y, float finion){ diff --git a/core/src/io/anuke/mindustry/maps/generation/FortressGenerator.java b/core/src/io/anuke/mindustry/maps/generation/FortressGenerator.java index 12f21f066f..eeca7a94c5 100644 --- a/core/src/io/anuke/mindustry/maps/generation/FortressGenerator.java +++ b/core/src/io/anuke/mindustry/maps/generation/FortressGenerator.java @@ -15,7 +15,6 @@ import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.blocks.defense.turrets.ItemTurret; import io.anuke.mindustry.world.blocks.defense.turrets.PowerTurret; -import io.anuke.mindustry.world.blocks.units.ResupplyPoint; import io.anuke.ucore.util.Mathf; import static io.anuke.mindustry.Vars.world; @@ -186,7 +185,6 @@ public class FortressGenerator{ } Block fixBlock(Block result){ - if(result == UnitBlocks.resupplyPoint) result = DefenseBlocks.tungstenWall; if(result == UnitBlocks.dronePad) result = DefenseBlocks.tungstenWallLarge; if(result == UnitBlocks.fabricatorPad) result = DefenseBlocks.tungstenWallLarge; return result; @@ -201,8 +199,6 @@ public class FortressGenerator{ ItemTurret turret = (ItemTurret)block; AmmoType[] type = turret.getAmmoTypes(); block.handleStack(type[0].item, block.acceptStack(type[0].item, 1000, tile, null), tile, null); - }else if(block instanceof ResupplyPoint){ - tile.entity.items.add(Items.lead, tile.block().itemCapacity); } } diff --git a/core/src/io/anuke/mindustry/type/Weapon.java b/core/src/io/anuke/mindustry/type/Weapon.java index 623be27e86..e900563bdd 100644 --- a/core/src/io/anuke/mindustry/type/Weapon.java +++ b/core/src/io/anuke/mindustry/type/Weapon.java @@ -1,7 +1,6 @@ package io.anuke.mindustry.type; import com.badlogic.gdx.graphics.g2d.TextureRegion; -import com.badlogic.gdx.utils.OrderedMap; import io.anuke.annotations.Annotations.Loc; import io.anuke.annotations.Annotations.Remote; import io.anuke.mindustry.Vars; @@ -19,64 +18,37 @@ import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Translator; public class Weapon extends Upgrade{ - /** - * minimum cursor distance from player, fixes 'cross-eyed' shooting. - */ + /**minimum cursor distance from player, fixes 'cross-eyed' shooting.*/ protected static float minPlayerDist = 20f; - public TextureRegion equipRegion, region; - /** - * ammo type map. set with setAmmo() - */ - protected OrderedMap ammoMap = new OrderedMap<>(); - /** - * shell ejection effect - */ + /**ammo type map. set with setAmmo()*/ + protected AmmoType ammo; + /**shell ejection effect*/ protected Effect ejectEffect = Fx.none; - /** - * weapon reload in frames - */ + /**weapon reload in frames*/ protected float reload; - /** - * amount of shots per fire - */ + /**amount of shots per fire*/ protected int shots = 1; - /** - * spacing in degrees between multiple shots, if applicable - */ + /**spacing in degrees between multiple shots, if applicable*/ protected float spacing = 12f; - /** - * inaccuracy of degrees of each shot - */ + /**inaccuracy of degrees of each shot*/ protected float inaccuracy = 0f; - /** - * intensity and duration of each shot's screen shake - */ + /**intensity and duration of each shot's screen shake*/ protected float shake = 0f; - /** - * visual weapon knockback. - */ + /**visual weapon knockback.*/ protected float recoil = 1.5f; - /** - * shoot barrel y offset - */ + /**shoot barrel y offset*/ protected float length = 3f; - /** - * shoot barrel x offset. - */ + /**shoot barrel x offset.*/ protected float width = 4f; - /** - * fraction of velocity that is random - */ + /**fraction of velocity that is random*/ protected float velocityRnd = 0f; - /** - * whether to shoot the weapons in different arms one after another, rather than all at once - */ + /**whether to shoot the weapons in different arms one after another, rather than all at once*/ protected boolean roundrobin = false; - /** - * translator for vector calulations - */ + /**translator for vector calulations*/ protected Translator tr = new Translator(); + public TextureRegion equipRegion, region; + protected Weapon(String name){ super(name); } @@ -103,12 +75,9 @@ public class Weapon extends Upgrade{ Weapon weapon = shooter.getWeapon(); Angles.shotgun(weapon.shots, weapon.spacing, rotation, f -> weapon.bullet(shooter, x, y, f + Mathf.range(weapon.inaccuracy))); + AmmoType ammo = weapon.ammo; - AmmoType type = shooter.getInventory().getAmmo(); - - if(type == null) return; - - weapon.tr.trns(rotation + 180f, type.recoil); + weapon.tr.trns(rotation + 180f, ammo.recoil); shooter.getVelocity().add(weapon.tr); @@ -116,8 +85,8 @@ public class Weapon extends Upgrade{ Effects.shake(weapon.shake, weapon.shake, x, y); Effects.effect(weapon.ejectEffect, x, y, rotation * -Mathf.sign(left)); - Effects.effect(type.shootEffect, x + weapon.tr.x, y + weapon.tr.y, rotation, shooter); - Effects.effect(type.smokeEffect, x + weapon.tr.x, y + weapon.tr.y, rotation, shooter); + Effects.effect(ammo.shootEffect, x + weapon.tr.x, y + weapon.tr.y, rotation, shooter); + Effects.effect(ammo.smokeEffect, x + weapon.tr.x, y + weapon.tr.y, rotation, shooter); //reset timer for remote players shooter.getTimer().get(shooter.getShootTimer(left), weapon.reload); @@ -134,13 +103,17 @@ public class Weapon extends Upgrade{ return "weapon"; } + public AmmoType getAmmo(){ + return ammo; + } + public void update(ShooterTrait shooter, float pointerX, float pointerY){ update(shooter, true, pointerX, pointerY); update(shooter, false, pointerX, pointerY); } private void update(ShooterTrait shooter, boolean left, float pointerX, float pointerY){ - if(shooter.getInventory().hasAmmo() && shooter.getTimer().get(shooter.getShootTimer(left), reload)){ + if(shooter.getTimer().get(shooter.getShootTimer(left), reload)){ if(roundrobin){ shooter.getTimer().reset(shooter.getShootTimer(!left), reload / 2f); } @@ -180,29 +153,13 @@ public class Weapon extends Upgrade{ Call.onGenericShootWeapon(p, x, y, angle, left); } } - - p.getInventory().useAmmo(); - } - - public Iterable getAcceptedItems(){ - return ammoMap.orderedKeys(); - } - - public AmmoType getAmmoType(Item item){ - return ammoMap.get(item); - } - - protected void setAmmo(AmmoType... types){ - for(AmmoType type : types){ - ammoMap.put(type.item, type); - } } void bullet(ShooterTrait owner, float x, float y, float angle){ - if(owner == null || !owner.getInventory().hasAmmo()) return; + if(owner == null) return; tr.trns(angle, 3f); - Bullet.create(owner.getInventory().getAmmo().bullet, + Bullet.create(ammo.bullet, owner, owner.getTeam(), x + tr.x, y + tr.y, angle, (1f - velocityRnd) + Mathf.random(velocityRnd)); } } diff --git a/core/src/io/anuke/mindustry/ui/fragments/DebugFragment.java b/core/src/io/anuke/mindustry/ui/fragments/DebugFragment.java index 10aa2d8460..a3461fe929 100644 --- a/core/src/io/anuke/mindustry/ui/fragments/DebugFragment.java +++ b/core/src/io/anuke/mindustry/ui/fragments/DebugFragment.java @@ -145,7 +145,6 @@ public class DebugFragment extends Fragment{ for(UnitType type : UnitType.all()){ dialog.content().addImageButton("white", 40, () -> { BaseUnit unit = type.create(player.getTeam()); - unit.inventory.addAmmo(type.weapon.getAmmoType(type.weapon.getAcceptedItems().iterator().next())); unit.setWave(); unit.set(player.x, player.y); unit.add(); diff --git a/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java b/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java index aa50783fd5..2b02af63b3 100644 --- a/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java +++ b/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java @@ -235,25 +235,6 @@ public class CoreBlock extends StorageBlock{ entity.heat = Mathf.lerpDelta(entity.heat, 0f, 0.1f); } - - if(entity.solid && tile.entity.timer.get(timerSupply, supplyInterval)){ - rect.setSize(supplyRadius * 2).setCenter(tile.drawx(), tile.drawy()); - - Units.getNearby(tile.getTeam(), rect, unit -> { - if(unit.isDead() || unit.distanceTo(tile.drawx(), tile.drawy()) > supplyRadius || unit.getGroup() == null) - return; - - for(int i = 0; i < Item.all().size; i++){ - Item item = Item.getByID(i); - if(tile.entity.items.get(item) > 0 && unit.acceptsAmmo(item)){ - tile.entity.items.remove(item, 1); - unit.addAmmo(item); - Call.transferAmmo(item, tile.drawx(), tile.drawy(), unit); - return; - } - } - }); - } } @Override @@ -261,19 +242,6 @@ public class CoreBlock extends StorageBlock{ return new CoreEntity(); } - /* - @Remote(called = Loc.server) - public static void onCoreUnitSet(Tile tile, Unit player){ - CoreEntity entity = tile.entity(); - entity.currentUnit = player; - entity.progress = 0f; - player.set(tile.drawx(), tile.drawy()); - - if(player instanceof Player){ - ((Player) player).setRespawning(true); - } - } - */ public class CoreEntity extends TileEntity implements SpawnerTrait{ public Unit currentUnit; int droneID = -1; diff --git a/core/src/io/anuke/mindustry/world/blocks/units/ResupplyPoint.java b/core/src/io/anuke/mindustry/world/blocks/units/ResupplyPoint.java deleted file mode 100644 index 6f0c5a6281..0000000000 --- a/core/src/io/anuke/mindustry/world/blocks/units/ResupplyPoint.java +++ /dev/null @@ -1,144 +0,0 @@ -package io.anuke.mindustry.world.blocks.units; - -import com.badlogic.gdx.math.Rectangle; -import com.badlogic.gdx.math.Vector2; -import io.anuke.mindustry.entities.TileEntity; -import io.anuke.mindustry.entities.Unit; -import io.anuke.mindustry.entities.Units; -import io.anuke.mindustry.graphics.Layer; -import io.anuke.mindustry.graphics.Palette; -import io.anuke.mindustry.type.Item; -import io.anuke.mindustry.world.Block; -import io.anuke.mindustry.world.Tile; -import io.anuke.mindustry.world.meta.BlockFlag; -import io.anuke.ucore.core.Timers; -import io.anuke.ucore.graphics.Draw; -import io.anuke.ucore.graphics.Lines; -import io.anuke.ucore.graphics.Shapes; -import io.anuke.ucore.util.Angles; -import io.anuke.ucore.util.EnumSet; -import io.anuke.ucore.util.Mathf; - -public class ResupplyPoint extends Block{ - private static Rectangle rect = new Rectangle(); - - protected int timerSupply = timers++; - protected int timerTarget = timers++; - - protected float supplyRadius = 50f; - protected float supplyInterval = 10f; - - public ResupplyPoint(String name){ - super(name); - update = true; - solid = true; - flags = EnumSet.of(BlockFlag.resupplyPoint); - layer = Layer.laser; - hasItems = true; - hasPower = true; - powerCapacity = 20f; - - consumes.power(0.02f); - } - - @Override - public void drawSelect(Tile tile){ - Draw.color(Palette.accent); - Lines.dashCircle(tile.drawx(), tile.drawy(), supplyRadius); - Draw.color(); - } - - @Override - public void drawLayer(Tile tile){ - ResupplyPointEntity entity = tile.entity(); - - if(entity.strength > 0f){ - float ang = entity.angleTo(entity.lastx, entity.lasty); - float len = 5f; - float x1 = tile.drawx() + Angles.trnsx(ang, len), y1 = tile.drawy() + Angles.trnsy(ang, len); - float dstTo = Vector2.dst(x1, y1, entity.lastx, entity.lasty); - float space = 4f; - - float xf = entity.lastx - x1, yf = entity.lasty - y1; - - Shapes.laser("transfer", "transfer-end", - x1, y1, entity.lastx, entity.lasty, entity.strength); - - Draw.color(Palette.accent); - for(int i = 0; i < dstTo / space - 1; i++){ - float fract = (i * space) / dstTo + ((Timers.time() / 90f) % (space / dstTo)); - Draw.alpha(Mathf.clamp(fract * 1.5f)); - Draw.rect("transfer-arrow", x1 + fract * xf, y1 + fract * yf, - 8, 8 * entity.strength, ang); - } - - Draw.color(); - - } - } - - @Override - public void update(Tile tile){ - ResupplyPointEntity entity = tile.entity(); - - if(!validTarget(entity, entity.target) || entity.target.distanceTo(tile) > supplyRadius){ - entity.target = null; - }else if(entity.target != null && entity.strength > 0.5f){ - - if(entity.timer.get(timerSupply, supplyInterval)){ - for(int i = 0; i < Item.all().size; i++){ - Item item = Item.getByID(i); - if(tile.entity.items.has(item) && entity.target.acceptsAmmo(item)){ - tile.entity.items.remove(item, 1); - entity.target.addAmmo(item); - break; - } - } - } - - entity.rotation = Mathf.slerpDelta(entity.rotation, entity.angleTo(entity.target), 0.5f); - } - - if(entity.target != null && entity.cons.valid()){ - entity.lastx = entity.target.x; - entity.lasty = entity.target.y; - entity.strength = Mathf.lerpDelta(entity.strength, 1f, 0.08f * Timers.delta()); - }else{ - entity.strength = Mathf.lerpDelta(entity.strength, 0f, 0.08f * Timers.delta()); - } - - if(entity.timer.get(timerTarget, 20)){ - rect.setSize(supplyRadius * 2).setCenter(tile.drawx(), tile.drawy()); - - entity.target = Units.getClosest(tile.getTeam(), tile.drawx(), tile.drawy(), supplyRadius, unit -> validTarget(entity, unit)); - } - } - - @Override - public boolean acceptItem(Item item, Tile tile, Tile source){ - return tile.entity.items.total() < itemCapacity; - } - - @Override - public TileEntity getEntity(){ - return new ResupplyPointEntity(); - } - - boolean validTarget(ResupplyPointEntity entity, Unit unit){ - if(unit == null || unit.inventory.totalAmmo() >= unit.inventory.ammoCapacity() - || unit.isDead()) return false; - - for(int i = 0; i < Item.all().size; i++){ - Item item = Item.getByID(i); - if(entity.items.has(item) && unit.acceptsAmmo(item)){ - return true; - } - } - return false; - } - - public class ResupplyPointEntity extends TileEntity{ - public Unit target; - public float strength, rotation = 90, lastx, lasty; - } -} diff --git a/core/src/io/anuke/mindustry/world/blocks/units/UnitPad.java b/core/src/io/anuke/mindustry/world/blocks/units/UnitPad.java index fe6a617435..3a247e11e2 100644 --- a/core/src/io/anuke/mindustry/world/blocks/units/UnitPad.java +++ b/core/src/io/anuke/mindustry/world/blocks/units/UnitPad.java @@ -13,7 +13,6 @@ import io.anuke.mindustry.gen.Call; import io.anuke.mindustry.graphics.Palette; import io.anuke.mindustry.graphics.Shaders; import io.anuke.mindustry.net.Net; -import io.anuke.mindustry.type.AmmoType; import io.anuke.mindustry.type.Item; import io.anuke.mindustry.type.ItemStack; import io.anuke.mindustry.world.BarType; @@ -74,10 +73,6 @@ public class UnitPad extends Block{ unit.set(tile.drawx(), tile.drawy()); unit.add(); unit.getVelocity().y = factory.launchVelocity; - - //fill inventory with 1st ammo - AmmoType type = unit.getWeapon().getAmmoType(unit.getWeapon().getAcceptedItems().iterator().next()); - unit.inventory.fillAmmo(type); } }