This commit is contained in:
Anuken
2018-08-18 13:06:54 -04:00
31 changed files with 662 additions and 1104 deletions
@@ -129,11 +129,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();
@@ -187,21 +182,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;
@@ -273,6 +258,23 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
Draw.rect(mech.iconRegion, x , y, rotation - 90);
}
@Override
public void drawAll(){
boolean snap = snapCamera && isLocal;
float px = x, py = y;
if(snap){
x = (int) (x + 0.0001f);
y = (int) (y + 0.0001f);
}
super.drawAll();
x = px;
y = py;
}
@Override
public void draw(){
if((debug && (!showPlayer || !showUI)) || dead) return;
@@ -284,15 +286,6 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
boostHeat = Mathf.lerpDelta(boostHeat, isBoosting && ((!movement.isZero() && moved) || !isLocal) ? 1f : 0f, 0.08f);
boolean snap = snapCamera && isLocal;
float px = x, py = y;
if(snap){
x = (int) (x + 0.0001f);
y = (int) (y + 0.0001f);
}
float ft = Mathf.sin(walktime, 6f, 2f) * (1f - boostHeat);
Floor floor = getFloorOn();
@@ -351,9 +344,6 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
}
Draw.alpha(1f);
x = px;
y = py;
}
@Override
@@ -620,20 +610,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;
@@ -677,7 +667,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(){
+22 -15
View File
@@ -1,5 +1,6 @@
package io.anuke.mindustry.entities;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.content.blocks.Blocks;
@@ -8,8 +9,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;
@@ -294,16 +295,30 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
}
}
public float getAmmoFraction(){
return inventory.totalAmmo() / (float) inventory.ammoCapacity();
}
public void drawUnder(){
}
public void drawOver(){
}
public void drawStats(){
Draw.color(Color.BLACK, team.color, healthf() + Mathf.absin(Timers.time(), 1f+healthf()*5f, 1f - healthf()));
Draw.alpha(hitTime);
Draw.rect(getPowerCellRegion(), x, y, rotation - 90);
Draw.color();
}
public TextureRegion getPowerCellRegion(){
return Draw.region("power-cell");
}
public void drawAll(){
if(!isDead()){
draw();
drawStats();
}
}
public void drawShadow(){
Draw.rect(getIconRegion(), x , y, rotation - 90);
}
@@ -312,26 +327,18 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
Fill.circle(x, y, getViewDistance());
}
public boolean isInfiniteAmmo(){
return false;
}
public float getViewDistance(){
return 135f;
}
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();
@@ -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<AmmoEntry> 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;
}
@@ -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());
}
/**
@@ -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;
@@ -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,16 +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;
}
@Override
public void interpolate(){
super.interpolate();
@@ -282,16 +271,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;
@@ -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);
@@ -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);
}
}
@@ -395,11 +395,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){