Implemented Fortress unit / Made artillery ignore air

This commit is contained in:
Anuken
2018-10-01 09:51:12 -04:00
parent d5d90bde9a
commit d2ce051c4a
28 changed files with 680 additions and 618 deletions
@@ -13,6 +13,7 @@ public class ArtilleryBulletType extends BasicBulletType{
super(speed, damage, bulletSprite);
collidesTiles = false;
collides = false;
collidesAir = false;
hitShake = 1f;
}
@@ -12,5 +12,6 @@ public class BombBulletType extends BasicBulletType{
lifetime = 30f;
drag = 0.05f;
keepVelocity = false;
collidesAir = false;
}
}
@@ -180,7 +180,7 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncT
@Override
public boolean collides(SolidTrait other){
return type.collides && super.collides(other) && !supressCollision;
return type.collides && super.collides(other) && !supressCollision && !(other instanceof Unit && ((Unit) other).isFlying() && !type.collidesAir);
}
@Override
@@ -37,6 +37,8 @@ public abstract class BulletType extends Content implements BaseBulletType<Bulle
public boolean collidesTiles = true;
/**Whether this bullet type collides with tiles that are of the same team.*/
public boolean collidesTeam = false;
/**Whether this bullet type collides with air units.*/
public boolean collidesAir = true;
/**Whether this bullet types collides with anything at all.*/
public boolean collides = true;
/**Whether velocity is inherited from the shooter.*/
@@ -190,7 +190,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
}
public void targetClosest(){
target = Units.getClosestTarget(team, x, y, getWeapon().getAmmo().getRange());
target = Units.getClosestTarget(team, x, y, getWeapon().getAmmo().getRange(), u -> type.targetAir || !u.isFlying());
}
public TileEntity getClosestEnemyCore(){
@@ -60,13 +60,7 @@ public abstract class GroundUnit extends BaseUnit{
if(distanceTo(target) > 400f){
moveAwayFromCore();
}else{
vec.trns(baseRotation, type.speed);
velocity.add(vec.x, vec.y);
vec.trns(baseRotation, type.hitsizeTile);
Tile tile = world.tileWorld(x + vec.x, y + vec.y);
if((tile == null || tile.solid() || tile.floor().drownTime > 0) || stuckTime > 10f){
baseRotation += Mathf.sign(id % 2 - 0.5f) * Timers.delta() * 3f;
}
patrol();
}
}
}
@@ -128,7 +122,11 @@ public abstract class GroundUnit extends BaseUnit{
stuckTime = !vec.set(x, y).sub(lastPosition().x, lastPosition().y).isZero(0.0001f) ? 0f : stuckTime + Timers.delta();
if(!velocity.isZero(0.0001f) && (Units.invalidateTarget(target, this) || (distanceTo(target) > getWeapon().getAmmo().getRange()))){
rotation = Mathf.slerpDelta(rotation, velocity.angle(), 0.2f);
rotation = Mathf.slerpDelta(rotation, velocity.angle(), type.rotatespeed);
}
if(stuckTime < 1f){
walkTime += Timers.delta();
}
}
@@ -145,9 +143,7 @@ public abstract class GroundUnit extends BaseUnit{
public void draw(){
Draw.alpha(hitTime / hitDuration);
float walktime = walkTime;
float ft = Mathf.sin(walktime, 6f, 2f);
float ft = Mathf.sin(walkTime * type.speed*5f, 6f, 2f);
Floor floor = getFloorOn();
@@ -241,6 +237,16 @@ public abstract class GroundUnit extends BaseUnit{
super.readSave(stream);
}
protected void patrol(){
vec.trns(baseRotation, type.speed);
velocity.add(vec.x, vec.y);
vec.trns(baseRotation, type.hitsizeTile);
Tile tile = world.tileWorld(x + vec.x, y + vec.y);
if((tile == null || tile.solid() || tile.floor().drownTime > 0) || stuckTime > 10f){
baseRotation += Mathf.sign(id % 2 - 0.5f) * Timers.delta() * 3f;
}
}
protected void circle(float circleLength){
if(target == null) return;
@@ -265,7 +271,6 @@ public abstract class GroundUnit extends BaseUnit{
vec.trns(baseRotation, type.speed);
baseRotation = Mathf.slerpDelta(baseRotation, angleTo(targetTile), 0.05f);
walkTime += Timers.delta();
velocity.add(vec);
}
@@ -290,7 +295,6 @@ public abstract class GroundUnit extends BaseUnit{
vec.trns(baseRotation, type.speed);
baseRotation = Mathf.slerpDelta(baseRotation, angleTo(targetTile), 0.05f);
walkTime += Timers.delta();
velocity.add(vec);
}
}
@@ -30,10 +30,11 @@ public class UnitType extends UnlockableContent{
public float hitsizeTile = 4f;
public float speed = 0.4f;
public float range = 160;
public float rotatespeed = 0.1f;
public float rotatespeed = 0.2f;
public float baseRotateSpeed = 0.1f;
public float mass = 1f;
public boolean isFlying;
public boolean targetAir = true;
public float drag = 0.1f;
public float maxVelocity = 5f;
public float retreatPercent = 0.2f;
@@ -1,6 +1,21 @@
package io.anuke.mindustry.entities.units.types;
import io.anuke.mindustry.entities.Units;
import io.anuke.mindustry.entities.units.GroundUnit;
public class Fortress extends GroundUnit{
@Override
protected void patrol(){
if(Units.invalidateTarget(target, this)){
super.patrol();
}
}
@Override
protected void moveToCore(){
if(Units.invalidateTarget(target, this)){
super.moveToCore();
}
}
}