Removed Mech/UnitType
This commit is contained in:
@@ -1,4 +1,69 @@
|
||||
package mindustry.entities;
|
||||
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
public class Weapons{
|
||||
private static final int[] one = {1};
|
||||
|
||||
private WeaponMount[] mounts;
|
||||
private UnitDef lastDef;
|
||||
|
||||
public void update(Unit unit){
|
||||
check(unit);
|
||||
|
||||
for(WeaponMount mount : mounts){
|
||||
Weapon weapon = mount.weapon;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Unit unit){
|
||||
check(unit);
|
||||
|
||||
for(WeaponMount mount : mounts){
|
||||
Weapon weapon = mount.weapon;
|
||||
|
||||
for(int i : (weapon.mirror ? Mathf.signs : one)){
|
||||
i *= Mathf.sign(weapon.flipped);
|
||||
|
||||
float rotation = unit.rotation - 90 + (weapon.rotate ? mount.rotation : 0);
|
||||
float trY = weapon.length - mount.reload / weapon.reload * weapon.recoil;
|
||||
float width = i > 0 ? -weapon.region.getWidth() : weapon.region.getWidth();
|
||||
|
||||
Draw.rect(weapon.region,
|
||||
unit.x + Angles.trnsx(rotation, weapon.width * i, trY),
|
||||
unit.y + Angles.trnsy(rotation, weapon.width * i, trY),
|
||||
width * Draw.scl,
|
||||
weapon.region.getHeight() * Draw.scl,
|
||||
rotation - 90);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//check mount validity
|
||||
private void check(Unit unit){
|
||||
if(mounts == null || mounts.length != unit.type().weapons.size || lastDef != unit.type()){
|
||||
mounts = new WeaponMount[unit.type().weapons.size];
|
||||
for(int i = 0; i < mounts.length; i++){
|
||||
mounts[i] = new WeaponMount(unit.type().weapons.get(i));
|
||||
}
|
||||
lastDef = unit.type();
|
||||
}
|
||||
}
|
||||
|
||||
private static class WeaponMount{
|
||||
/** reload in frames; 0 means ready to fire */
|
||||
float reload;
|
||||
/** rotation relative to the unit this mount is on */
|
||||
float rotation;
|
||||
/** weapon associated with this mount */
|
||||
Weapon weapon;
|
||||
|
||||
public WeaponMount(Weapon weapon){
|
||||
this.weapon = weapon;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
||||
protected static final int timerTarget2 = timerIndex++;
|
||||
|
||||
protected boolean loaded;
|
||||
protected UnitType type;
|
||||
protected UnitDef type;
|
||||
protected Interval timer = new Interval(5);
|
||||
protected StateMachine state = new StateMachine();
|
||||
protected TargetTrait target;
|
||||
@@ -112,7 +112,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
||||
}
|
||||
|
||||
/** Initialize the type and team of this unit. Only call once! */
|
||||
public void init(UnitType type, Team team){
|
||||
public void init(UnitDef type, Team team){
|
||||
if(this.type != null) throw new RuntimeException("This unit is already initialized!");
|
||||
|
||||
this.type = type;
|
||||
@@ -124,16 +124,12 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
||||
return true;
|
||||
}
|
||||
|
||||
public UnitType getType(){
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setSpawner(Tile tile){
|
||||
this.spawner = tile.pos();
|
||||
}
|
||||
|
||||
public void rotate(float angle){
|
||||
rotation = Mathf.slerpDelta(rotation, angle, type.rotatespeed);
|
||||
rotation = Mathf.slerpDelta(rotation, angle, type.rotateSpeed);
|
||||
}
|
||||
|
||||
public boolean targetHasFlag(BlockFlag flag){
|
||||
@@ -172,7 +168,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
||||
}
|
||||
|
||||
public void targetClosest(){
|
||||
TargetTrait newTarget = Units.closestTarget(team, x, y, Math.max(getWeapon().bullet.range(), type.range), u -> type.targetAir || !u.isFlying());
|
||||
TargetTrait newTarget = Units.closestTarget(team, x, y, type.range, u -> type.targetAir || !u.isFlying());
|
||||
if(newTarget != null){
|
||||
target = newTarget;
|
||||
}
|
||||
|
||||
@@ -36,9 +36,6 @@ import static mindustry.Vars.*;
|
||||
public class Player extends Unit implements BuilderMinerTrait, ShooterTrait{
|
||||
public static final int timerSync = 2;
|
||||
public static final int timerAbility = 3;
|
||||
public static final int timerTransfer = 4;
|
||||
private static final int timerShootLeft = 0;
|
||||
private static final int timerShootRight = 1;
|
||||
private static final float liftoffBoost = 0.2f;
|
||||
|
||||
private static final Rect rect = new Rect();
|
||||
@@ -54,7 +51,7 @@ public class Player extends Unit implements BuilderMinerTrait, ShooterTrait{
|
||||
public float boostHeat, shootHeat, destructTime;
|
||||
public boolean achievedFlight;
|
||||
public Color color = new Color();
|
||||
public Mech mech = Mechs.starter;
|
||||
public UnitDef mech = Mechs.starter;
|
||||
public SpawnerTrait spawner, lastSpawner;
|
||||
public int respawns;
|
||||
|
||||
@@ -118,6 +115,16 @@ public class Player extends Unit implements BuilderMinerTrait, ShooterTrait{
|
||||
return TypeIDs.player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitDef type(){
|
||||
return mech;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Weapons getWeapons(){
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move(float x, float y){
|
||||
if(!mech.flying){
|
||||
@@ -172,7 +179,7 @@ public class Player extends Unit implements BuilderMinerTrait, ShooterTrait{
|
||||
|
||||
@Override
|
||||
public boolean canMine(Item item){
|
||||
return item.hardness <= mech.drillPower;
|
||||
return item.hardness <= mech.drillTier;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -298,18 +305,7 @@ public class Player extends Unit implements BuilderMinerTrait, ShooterTrait{
|
||||
Draw.rect(mech.region, x, y, rotation - 90);
|
||||
|
||||
mech.draw(this);
|
||||
|
||||
for(int i : Mathf.signs){
|
||||
float tra = rotation - 90, trY = -mech.weapon.getRecoil(this, i > 0) + mech.weaponOffsetY;
|
||||
float w = i > 0 ? -mech.weapon.region.getWidth() : mech.weapon.region.getWidth();
|
||||
Draw.rect(mech.weapon.region,
|
||||
x + Angles.trnsx(tra, (mech.weaponOffsetX + mech.spreadX(this)) * i, trY),
|
||||
y + Angles.trnsy(tra, (mech.weaponOffsetX + mech.spreadX(this)) * i, trY),
|
||||
w * Draw.scl,
|
||||
mech.weapon.region.getHeight() * Draw.scl,
|
||||
rotation - 90);
|
||||
}
|
||||
|
||||
weapons.draw(this);
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
@@ -495,9 +491,6 @@ public class Player extends Unit implements BuilderMinerTrait, ShooterTrait{
|
||||
|
||||
if(boostHeat <= liftoffBoost + 0.05f && achievedFlight && !mech.flying){
|
||||
if(tile != null){
|
||||
if(mech.shake > 1f){
|
||||
Effects.shake(mech.shake, mech.shake, this);
|
||||
}
|
||||
Effects.effect(Fx.unitLand, tile.floor().color, x, y, tile.floor().isLiquid ? 1f : 0.5f);
|
||||
}
|
||||
mech.onLand(this);
|
||||
@@ -585,7 +578,7 @@ public class Player extends Unit implements BuilderMinerTrait, ShooterTrait{
|
||||
|
||||
if(canMove){
|
||||
float baseLerp = mech.getRotationAlpha(this);
|
||||
if(!isShooting() || !mech.turnCursor){
|
||||
if(!isShooting() || !mech.faceTarget){
|
||||
if(!movement.isZero()){
|
||||
rotation = Mathf.slerpDelta(rotation, mech.flying ? velocity.angle() : movement.angle(), 0.13f * baseLerp);
|
||||
}
|
||||
@@ -598,18 +591,19 @@ public class Player extends Unit implements BuilderMinerTrait, ShooterTrait{
|
||||
|
||||
protected void updateShooting(){
|
||||
if(!state.isEditor() && isShooting() && mech.canShoot(this)){
|
||||
if(!mech.turnCursor){
|
||||
weapons.update(this);
|
||||
//if(!mech.turnCursor){
|
||||
//shoot forward ignoring cursor
|
||||
mech.weapon.update(this, x + Angles.trnsx(rotation, mech.weapon.targetDistance), y + Angles.trnsy(rotation, mech.weapon.targetDistance));
|
||||
}else{
|
||||
mech.weapon.update(this, pointerX, pointerY);
|
||||
}
|
||||
//mech.weapon.update(this, x + Angles.trnsx(rotation, mech.weapon.targetDistance), y + Angles.trnsy(rotation, mech.weapon.targetDistance));
|
||||
//}else{
|
||||
//mech.weapon.update(this, pointerX, pointerY);
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateTouch(){
|
||||
if(Units.invalidateTarget(target, this) &&
|
||||
!(target instanceof TileEntity && ((TileEntity)target).damaged() && target.isValid() && target.getTeam() == team && mech.canHeal && dst(target) < getWeapon().bullet.range() && !(((TileEntity)target).block instanceof BuildBlock))){
|
||||
!(target instanceof TileEntity && ((TileEntity)target).damaged() && target.isValid() && target.getTeam() == team && mech.canHeal && dst(target) < mech.range && !(((TileEntity)target).block instanceof BuildBlock))){
|
||||
target = null;
|
||||
}
|
||||
|
||||
@@ -685,11 +679,11 @@ public class Player extends Unit implements BuilderMinerTrait, ShooterTrait{
|
||||
if(target == null){
|
||||
isShooting = false;
|
||||
if(Core.settings.getBool("autotarget")){
|
||||
target = Units.closestTarget(team, x, y, getWeapon().bullet.range(), u -> u.getTeam() != Team.derelict, u -> u.getTeam() != Team.derelict);
|
||||
target = Units.closestTarget(team, x, y, mech.range, u -> u.getTeam() != Team.derelict, u -> u.getTeam() != Team.derelict);
|
||||
|
||||
if(mech.canHeal && target == null){
|
||||
target = Geometry.findClosest(x, y, indexer.getDamaged(Team.sharded));
|
||||
if(target != null && dst(target) > getWeapon().bullet.range()){
|
||||
if(target != null && dst(target) > mech.range){
|
||||
target = null;
|
||||
}else if(target != null){
|
||||
target = ((Tile)target).entity;
|
||||
@@ -700,9 +694,9 @@ public class Player extends Unit implements BuilderMinerTrait, ShooterTrait{
|
||||
setMineTile(null);
|
||||
}
|
||||
}
|
||||
}else if(target.isValid() || (target instanceof TileEntity && ((TileEntity)target).damaged() && target.getTeam() == team && mech.canHeal && dst(target) < getWeapon().bullet.range())){
|
||||
}else if(target.isValid() || (target instanceof TileEntity && ((TileEntity)target).damaged() && target.getTeam() == team && mech.canHeal && dst(target) < mech.range)){
|
||||
//rotate toward and shoot the target
|
||||
if(mech.turnCursor){
|
||||
if(mech.faceTarget){
|
||||
rotation = Mathf.slerpDelta(rotation, angleTo(target), 0.2f);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
protected final Interpolator interpolator = new Interpolator();
|
||||
protected final Statuses status = new Statuses();
|
||||
protected final ItemStack item = new ItemStack(content.item(0), 0);
|
||||
protected final Weapons weapons = new Weapons();
|
||||
|
||||
protected Team team = Team.sharded;
|
||||
protected float drownTime, hitTime;
|
||||
@@ -136,18 +137,18 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
|
||||
@Override
|
||||
public void hitbox(Rect rect){
|
||||
rect.setSize(def().hitsize).setCenter(x, y);
|
||||
rect.setSize(type().hitsize).setCenter(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hitboxTile(Rect rect){
|
||||
rect.setSize(def().hitsizeTile).setCenter(x, y);
|
||||
rect.setSize(type().hitsizeTile).setCenter(x, y);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public float drag(){
|
||||
return def().drag;
|
||||
return type().drag;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -180,7 +181,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
public abstract UnitDef def();
|
||||
public abstract UnitDef type();
|
||||
|
||||
public void writeSave(DataOutput stream, boolean net) throws IOException{
|
||||
if(item.item == null) item.item = Items.copper;
|
||||
@@ -209,7 +210,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
}
|
||||
|
||||
public boolean isImmune(StatusEffect effect){
|
||||
return def().immunities.contains(effect);
|
||||
return type().immunities.contains(effect);
|
||||
}
|
||||
|
||||
public boolean isOutOfBounds(){
|
||||
@@ -410,8 +411,8 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
}
|
||||
|
||||
public void drawLight(){
|
||||
if(def().lightRadius > 0){
|
||||
renderer.lights.add(x, y, def().lightRadius, def().lightColor, 0.6f);
|
||||
if(type().lightRadius > 0){
|
||||
renderer.lights.add(x, y, type().lightRadius, type().lightColor, 0.6f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -470,15 +471,15 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
public abstract TextureRegion getIconRegion();
|
||||
|
||||
public final int getItemCapacity(){
|
||||
return def().itemCapacity;
|
||||
return type().itemCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float mass(){
|
||||
return def().mass;
|
||||
return type().mass;
|
||||
}
|
||||
|
||||
public boolean isFlying(){
|
||||
return def().flying;
|
||||
return type().flying;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,11 +120,6 @@ public class GroundUnit extends BaseUnit{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Weapon getWeapon(){
|
||||
return type.weapon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
Draw.mixcol(Color.white, hitTime / hitDuration);
|
||||
|
||||
Reference in New Issue
Block a user