Bugfixes, cleanup, optimization

This commit is contained in:
Anuken
2018-06-02 21:45:07 -04:00
parent ae6b4211b9
commit 9555b10b97
47 changed files with 369 additions and 299 deletions
@@ -173,7 +173,7 @@ public interface BlockBuilder {
unit.rotation = Mathf.slerpDelta(unit.rotation, unit.angleTo(tile.worldx(), tile.worldy()), 0.4f);
if(unit.inventory.canAcceptItem(item) &&
Mathf.chance(Timers.delta() * 0.05 / item.hardness)){
Mathf.chance(Timers.delta() * (0.06 - item.hardness * 0.01))){
ItemTransfer.create(item,
tile.worldx() + Mathf.range(tilesize/2f),
tile.worldy() + Mathf.range(tilesize/2f),
@@ -465,8 +465,8 @@ public class Player extends Unit implements BlockBuilder {
rotation = Mathf.slerpDelta(rotation, velocity.angle(), velocity.len()/10f);
}
//update shooting if not building and there's ammo left
if(!isBuilding() && inventory.hasAmmo()){
//update shooting if not building, not mining and there's ammo left
if(!isBuilding() && inventory.hasAmmo() && getMineTile() == null){
//autofire: mobile only!
if(mobile) {
@@ -19,13 +19,11 @@ public class Predict {
* @return the intercept location*/
public static Vector2 intercept(float srcx, float srcy, float dstx, float dsty, float dstvx, float dstvy, float v) {
float tx = dstx - srcx,
ty = dsty - srcy,
tvx = dstvx,
tvy = dstvy;
ty = dsty - srcy;
// Get quadratic equation components
float a = tvx*tvx + tvy*tvy - v*v;
float b = 2 * (tvx * tx + tvy * ty);
float a = dstvx * dstvx + dstvy * dstvy - v*v;
float b = 2 * (dstvx * tx + dstvy * ty);
float c = tx*tx + ty*ty;
// Solve quadratic
@@ -132,6 +132,10 @@ public class UnitInventory {
totalAmmo = 0;
}
public void clearItem(){
item = null;
}
public boolean hasItem(){
return item != null;
}
@@ -28,16 +28,13 @@ public class Units {
* @param range The maximum distance from the target X/Y the targeter can be for it to be valid
* @return whether the target is invalid
*/
public static boolean invalidateTarget(Targetable target, Team team, float x, float y, float range){
if(target == null){
public static boolean invalidateTarget(Targetable target, Team team, float x, float y, float range) {
if (target == null) {
return false;
}
if(range != Float.MAX_VALUE && target.distanceTo(x, y) > range){
return false;
}
return (!(range != Float.MAX_VALUE) || !(target.distanceTo(x, y) > range)) && (target.getTeam() == team || !target.isValid());
return target.getTeam() == team || !target.isValid();
}
/**See {@link #invalidateTarget(Targetable, Team, float, float, float)}*/
@@ -100,7 +100,7 @@ public abstract class UnitType {
public abstract void behavior(BaseUnit unit);
public void updateTargeting(BaseUnit unit){
if(unit.target == null || (unit.target instanceof Unit && (((Unit)unit.target).isDead() || ((Unit)unit.target).team == unit.team))
if(unit.target == null || (unit.target instanceof Unit && (unit.target.isDead() || ((Unit)unit.target).team == unit.team))
|| (unit.target instanceof TileEntity && ((TileEntity) unit.target).tile.entity == null)){
unit.target = null;
}