Removed Mech/UnitType
This commit is contained in:
@@ -18,9 +18,9 @@ import mindustry.type.*;
|
||||
import static mindustry.Vars.indexer;
|
||||
|
||||
public class Mechs implements ContentList{
|
||||
public static Mech vanguard, alpha, delta, tau, omega, dart, javelin, trident, glaive;
|
||||
public static UnitDef vanguard, alpha, delta, tau, omega, dart, javelin, trident, glaive;
|
||||
|
||||
public static Mech starter;
|
||||
public static UnitDef starter;
|
||||
|
||||
@Override
|
||||
public void load(){
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -14,7 +14,6 @@ import arc.util.noise.RidgedPerlin;
|
||||
import arc.util.noise.Simplex;
|
||||
import mindustry.content.Blocks;
|
||||
import mindustry.content.UnitTypes;
|
||||
import mindustry.type.UnitType;
|
||||
import mindustry.ui.Cicon;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.Floor;
|
||||
|
||||
@@ -232,13 +232,13 @@ public class TypeIO{
|
||||
return Effects.getEffect(buffer.getShort());
|
||||
}
|
||||
|
||||
@WriteClass(UnitType.class)
|
||||
public static void writeUnitType(ByteBuffer buffer, UnitType effect){
|
||||
@WriteClass(UnitDef.class)
|
||||
public static void writeUnitType(ByteBuffer buffer, UnitDef effect){
|
||||
buffer.putShort(effect.id);
|
||||
}
|
||||
|
||||
@ReadClass(UnitType.class)
|
||||
public static UnitType readUnitType(ByteBuffer buffer){
|
||||
@ReadClass(UnitDef.class)
|
||||
public static UnitDef readUnitType(ByteBuffer buffer){
|
||||
return content.getByID(ContentType.unit, buffer.getShort());
|
||||
}
|
||||
|
||||
@@ -252,16 +252,6 @@ public class TypeIO{
|
||||
return new Color(buffer.getInt());
|
||||
}
|
||||
|
||||
@WriteClass(Mech.class)
|
||||
public static void writeMech(ByteBuffer buffer, Mech mech){
|
||||
buffer.put((byte)mech.id);
|
||||
}
|
||||
|
||||
@ReadClass(Mech.class)
|
||||
public static Mech readMech(ByteBuffer buffer){
|
||||
return content.getByID(ContentType.mech, buffer.get());
|
||||
}
|
||||
|
||||
@WriteClass(Liquid.class)
|
||||
public static void writeLiquid(ByteBuffer buffer, Liquid liquid){
|
||||
buffer.putShort(liquid == null ? -1 : liquid.id);
|
||||
|
||||
@@ -1,139 +0,0 @@
|
||||
package mindustry.type;
|
||||
|
||||
import arc.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.ui.*;
|
||||
|
||||
public class Mech extends UnitDef{
|
||||
/*
|
||||
public boolean flying;
|
||||
public float speed = 1.1f;
|
||||
public float maxSpeed = 10f;
|
||||
public float boostSpeed = 0.75f;
|
||||
public float drag = 0.4f;
|
||||
public float mass = 1f;
|
||||
public float shake = 0f;
|
||||
public float health = 200f;
|
||||
|
||||
public float hitsize = 6f;
|
||||
public float cellTrnsY = 0f;
|
||||
public float mineSpeed = 1f;
|
||||
public int drillPower = -1;
|
||||
public float buildPower = 1f;
|
||||
public Color engineColor = Pal.boostTo;
|
||||
public int itemCapacity = 30;
|
||||
public boolean turnCursor = true;
|
||||
public boolean canHeal = false;
|
||||
public float compoundSpeed, compoundSpeedBoost;
|
||||
|
||||
/** draw the health and team indicator
|
||||
public boolean drawCell = true;
|
||||
/** draw the items on its back
|
||||
public boolean drawItems = true;
|
||||
/** draw the engine light if it's flying/boosting
|
||||
public boolean drawLight = true;
|
||||
|
||||
public float weaponOffsetX, weaponOffsetY, engineOffset = 5f, engineSize = 2.5f;*/
|
||||
public @NonNull Weapon weapon;
|
||||
|
||||
public TextureRegion baseRegion, legRegion, region;
|
||||
|
||||
public Mech(String name, boolean flying){
|
||||
super(name);
|
||||
this.flying = flying;
|
||||
}
|
||||
|
||||
public Mech(String name){
|
||||
this(name, false);
|
||||
}
|
||||
|
||||
public void update(Player player){
|
||||
}
|
||||
|
||||
public void draw(Player player){
|
||||
}
|
||||
|
||||
public void drawStats(Player player){
|
||||
if(drawCell){
|
||||
float health = player.healthf();
|
||||
Draw.color(Color.black, player.getTeam().color, health + Mathf.absin(Time.time(), health * 5f, 1f - health));
|
||||
Draw.rect(player.getPowerCellRegion(),
|
||||
player.x + Angles.trnsx(player.rotation, cellOffsetY, cellOffsetX),
|
||||
player.y + Angles.trnsy(player.rotation, cellOffsetY, cellOffsetX),
|
||||
player.rotation - 90);
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
if(drawItems){
|
||||
player.drawBackItems();
|
||||
}
|
||||
}
|
||||
|
||||
public float getExtraArmor(Player player){
|
||||
return 0f;
|
||||
}
|
||||
|
||||
public float spreadX(Player player){
|
||||
return 0f;
|
||||
}
|
||||
|
||||
public float getRotationAlpha(Player player){
|
||||
return 1f;
|
||||
}
|
||||
|
||||
public boolean canShoot(Player player){
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onLand(Player player){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
super.init();
|
||||
|
||||
for(int i = 0; i < 500; i++){
|
||||
compoundSpeed *= (1f - drag);
|
||||
compoundSpeed += speed;
|
||||
}
|
||||
|
||||
for(int i = 0; i < 500; i++){
|
||||
compoundSpeedBoost *= (1f - drag);
|
||||
compoundSpeedBoost += boostSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayInfo(Table table){
|
||||
ContentDisplay.displayMech(table, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContentType getContentType(){
|
||||
return ContentType.mech;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(){
|
||||
weapon.load();
|
||||
if(!flying){
|
||||
legRegion = Core.atlas.find(name + "-leg");
|
||||
baseRegion = Core.atlas.find(name + "-base");
|
||||
}
|
||||
|
||||
region = Core.atlas.find(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return localizedName;
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,36 @@
|
||||
package mindustry.type;
|
||||
|
||||
import arc.*;
|
||||
import arc.audio.*;
|
||||
import arc.func.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.entities.type.base.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.ui.*;
|
||||
|
||||
//TODO change to UnitType or Shell or something
|
||||
public class UnitDef extends UnlockableContent{
|
||||
//TODO implement
|
||||
public @NonNull Prov<? extends BaseUnit> constructor = () -> this.flying ? new FlyingUnit() : new GroundUnit();
|
||||
public TypeID typeID;
|
||||
|
||||
public abstract class UnitDef extends UnlockableContent{
|
||||
public boolean flying;
|
||||
public float speed = 1.1f, boostSpeed = 0.75f;
|
||||
public float drag = 0.4f, mass = 1f;
|
||||
public float health = 200f;
|
||||
public float speed = 1.1f, boostSpeed = 0.75f, rotateSpeed = 0.2f, baseRotateSpeed = 0.1f;
|
||||
public float drag = 0.3f, mass = 1f, accel = 0.1f;
|
||||
public float health = 200f, range = -1;
|
||||
public boolean targetAir = false, targetGround = false;
|
||||
public boolean faceTarget = true; //equivalent to turnCursor
|
||||
|
||||
public int itemCapacity = 30;
|
||||
public int drillTier = -1;
|
||||
@@ -30,8 +49,94 @@ public abstract class UnitDef extends UnlockableContent{
|
||||
public Sound deathSound = Sounds.bang;
|
||||
|
||||
public Array<Weapon> weapons = new Array<>();
|
||||
public TextureRegion baseRegion, legRegion, region;
|
||||
|
||||
public UnitDef(String name){
|
||||
super(name);
|
||||
|
||||
//TODO replace with the sane constructor
|
||||
typeID = new TypeID(name, constructor);
|
||||
}
|
||||
|
||||
public BaseUnit create(Team team){
|
||||
BaseUnit unit = constructor.get();
|
||||
unit.init(this, team);
|
||||
return unit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayInfo(Table table){
|
||||
ContentDisplay.displayUnit(table, this);
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void init(){
|
||||
//set up default range
|
||||
if(range < 0){
|
||||
for(Weapon weapon : weapons){
|
||||
range = Math.max(range, weapon.bullet.range());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void load(){
|
||||
weapons.each(Weapon::load);
|
||||
region = Core.atlas.find(name);
|
||||
legRegion = Core.atlas.find(name + "-leg");
|
||||
baseRegion = Core.atlas.find(name + "-base");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContentType getContentType(){
|
||||
return ContentType.unit;
|
||||
}
|
||||
|
||||
//TODO remove methods below!
|
||||
|
||||
public void update(Unit player){
|
||||
}
|
||||
|
||||
public void draw(Unit player){
|
||||
}
|
||||
|
||||
public void drawStats(Unit player){
|
||||
if(drawCell){
|
||||
float health = player.healthf();
|
||||
Draw.color(Color.black, player.getTeam().color, health + Mathf.absin(Time.time(), health * 5f, 1f - health));
|
||||
Draw.rect(player.getPowerCellRegion(),
|
||||
player.x + Angles.trnsx(player.rotation, cellOffsetY, cellOffsetX),
|
||||
player.y + Angles.trnsy(player.rotation, cellOffsetY, cellOffsetX),
|
||||
player.rotation - 90);
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
if(drawItems){
|
||||
//player.drawBackItems(0f, true);
|
||||
}
|
||||
}
|
||||
|
||||
public float getExtraArmor(Unit player){
|
||||
return 0f;
|
||||
}
|
||||
|
||||
//TODO remove
|
||||
public float spreadX(Unit player){
|
||||
return 0f;
|
||||
}
|
||||
|
||||
//TODO remove
|
||||
public float getRotationAlpha(Unit player){
|
||||
return 1f;
|
||||
}
|
||||
|
||||
public boolean canShoot(Unit player){
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onLand(Unit player){
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
package mindustry.type;
|
||||
|
||||
import arc.*;
|
||||
import arc.audio.*;
|
||||
import arc.func.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.ui.*;
|
||||
|
||||
public class UnitType extends UnitDef{
|
||||
public @NonNull TypeID typeID;
|
||||
public @NonNull Prov<? extends BaseUnit> constructor;
|
||||
|
||||
/*
|
||||
public float health = 60;
|
||||
public float hitsize = 7f;
|
||||
public float hitsizeTile = 4f;
|
||||
public float speed = 0.4f;
|
||||
public float range = 0, attackLength = 150f;
|
||||
public float rotatespeed = 0.2f;
|
||||
public float baseRotateSpeed = 0.1f;
|
||||
public float shootCone = 15f;
|
||||
public float mass = 1f;
|
||||
public boolean flying;
|
||||
public boolean targetAir = true;
|
||||
public boolean rotateWeapon = false;
|
||||
public float drag = 0.1f;
|
||||
public float maxVelocity = 5f;
|
||||
public float retreatPercent = 0.6f;
|
||||
public int itemCapacity = 30;
|
||||
public ObjectSet<Item> toMine = ObjectSet.with(Items.lead, Items.copper);
|
||||
public float buildPower = 0.3f, minePower = 0.7f;
|
||||
public @NonNull Weapon weapon;
|
||||
public float weaponOffsetY, engineOffset = 6f, engineSize = 2f;
|
||||
public ObjectSet<StatusEffect> immunities = new ObjectSet<>();
|
||||
public Sound deathSound = Sounds.bang;*/
|
||||
|
||||
public TextureRegion legRegion, baseRegion, region;
|
||||
|
||||
public <T extends BaseUnit> UnitType(String name, Prov<T> mainConstructor){
|
||||
this(name);
|
||||
create(mainConstructor);
|
||||
}
|
||||
|
||||
public UnitType(String name){
|
||||
super(name);
|
||||
}
|
||||
|
||||
public <T extends BaseUnit> void create(Prov<T> mainConstructor){
|
||||
this.constructor = mainConstructor;
|
||||
this.description = Core.bundle.getOrNull("unit." + name + ".description");
|
||||
this.typeID = new TypeID(name, mainConstructor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayInfo(Table table){
|
||||
ContentDisplay.displayUnit(table, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(){
|
||||
weapon.load();
|
||||
region = Core.atlas.find(name);
|
||||
legRegion = Core.atlas.find(name + "-leg");
|
||||
baseRegion = Core.atlas.find(name + "-base");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContentType getContentType(){
|
||||
return ContentType.unit;
|
||||
}
|
||||
|
||||
public BaseUnit create(Team team){
|
||||
BaseUnit unit = constructor.get();
|
||||
unit.init(this, team);
|
||||
return unit;
|
||||
}
|
||||
}
|
||||
@@ -24,11 +24,21 @@ public class Weapon{
|
||||
|
||||
/** minimum cursor distance from player, fixes 'cross-eyed' shooting. */
|
||||
protected static float minPlayerDist = 20f;
|
||||
//temporary only
|
||||
protected static int sequenceNum = 0;
|
||||
|
||||
/** bullet shot */
|
||||
public @NonNull BulletType bullet;
|
||||
/** shell ejection effect */
|
||||
public Effect ejectEffect = Fx.none;
|
||||
/** whether to mirror the weapon (draw two of them, which is the default) */
|
||||
public boolean mirror = true;
|
||||
/** whether to flip the weapon's position/side on the ship (only valid when mirror is false) */
|
||||
public boolean flipped = false;
|
||||
/** whether to shoot the weapons in different arms one after another, rather than all at once; only valid when mirror = true */
|
||||
public boolean alternate = false;
|
||||
/** whether to rotate toward the target independently of unit */
|
||||
public boolean rotate = false;
|
||||
/** weapon reload in frames */
|
||||
public float reload;
|
||||
/** amount of shots per fire */
|
||||
@@ -47,8 +57,6 @@ public class Weapon{
|
||||
public float width = 4f;
|
||||
/** fraction of velocity that is random */
|
||||
public float velocityRnd = 0f;
|
||||
/** whether to shoot the weapons in different arms one after another, rather than all at once */
|
||||
public boolean alternate = false;
|
||||
/** randomization of shot length */
|
||||
public float lengthRand = 0f;
|
||||
/** delay in ticks between shots */
|
||||
@@ -57,9 +65,9 @@ public class Weapon{
|
||||
public boolean ignoreRotation = false;
|
||||
/** if turnCursor is false for a mech, how far away will the weapon target. */
|
||||
public float targetDistance = 1f;
|
||||
|
||||
/** sound used for shooting */
|
||||
public Sound shootSound = Sounds.pew;
|
||||
|
||||
/** displayed region (autoloaded) */
|
||||
public TextureRegion region;
|
||||
|
||||
protected Weapon(String name){
|
||||
@@ -154,10 +162,6 @@ public class Weapon{
|
||||
}
|
||||
}
|
||||
|
||||
public float getRecoil(ShooterTrait player, boolean left){
|
||||
return (1f - Mathf.clamp(player.getTimer().getTime(player.getShootTimer(left)) / reload)) * recoil;
|
||||
}
|
||||
|
||||
public void shoot(ShooterTrait p, float x, float y, float angle, boolean left){
|
||||
if(net.client()){
|
||||
//call it directly, don't invoke on server
|
||||
|
||||
@@ -131,6 +131,8 @@ public class ContentDisplay{
|
||||
table.row();
|
||||
}
|
||||
|
||||
//TODO implement later
|
||||
/*
|
||||
public static void displayMech(Table table, Mech mech){
|
||||
table.table(title -> {
|
||||
title.addImage(mech.icon(Cicon.xlarge)).size(8 * 6);
|
||||
@@ -177,9 +179,9 @@ public class ContentDisplay{
|
||||
table.add(Core.bundle.format("mech.minepower", mech.drillPower));
|
||||
table.row();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
public static void displayUnit(Table table, UnitType unit){
|
||||
public static void displayUnit(Table table, UnitDef unit){
|
||||
table.table(title -> {
|
||||
title.addImage(unit.icon(Cicon.xlarge)).size(8 * 6);
|
||||
title.add("[accent]" + unit.localizedName).padLeft(5);
|
||||
|
||||
Reference in New Issue
Block a user