Cleanup
This commit is contained in:
@@ -17,12 +17,16 @@ import static mindustry.Vars.net;
|
|||||||
public class Weapons{
|
public class Weapons{
|
||||||
private static final int[] one = {1};
|
private static final int[] one = {1};
|
||||||
|
|
||||||
private WeaponMount[] mounts;
|
private WeaponMount[] mounts = {};
|
||||||
private UnitDef lastDef;
|
|
||||||
|
public void init(Unit unit){
|
||||||
|
mounts = new WeaponMount[unit.type().weapons.size];
|
||||||
|
for(int i = 0; i < mounts.length; i++){
|
||||||
|
mounts[i] = new WeaponMount(unit.type().weapons.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void update(Unit unit){
|
public void update(Unit unit){
|
||||||
check(unit);
|
|
||||||
|
|
||||||
for(WeaponMount mount : mounts){
|
for(WeaponMount mount : mounts){
|
||||||
Weapon weapon = mount.weapon;
|
Weapon weapon = mount.weapon;
|
||||||
|
|
||||||
@@ -33,8 +37,6 @@ public class Weapons{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void draw(Unit unit){
|
public void draw(Unit unit){
|
||||||
check(unit);
|
|
||||||
|
|
||||||
for(WeaponMount mount : mounts){
|
for(WeaponMount mount : mounts){
|
||||||
Weapon weapon = mount.weapon;
|
Weapon weapon = mount.weapon;
|
||||||
|
|
||||||
@@ -55,17 +57,6 @@ public class Weapons{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//region weapon code
|
//region weapon code
|
||||||
|
|
||||||
@Remote(targets = Loc.server, called = Loc.both, unreliable = true)
|
@Remote(targets = Loc.server, called = Loc.both, unreliable = true)
|
||||||
@@ -180,6 +171,8 @@ public class Weapons{
|
|||||||
float rotation;
|
float rotation;
|
||||||
/** weapon associated with this mount */
|
/** weapon associated with this mount */
|
||||||
Weapon weapon;
|
Weapon weapon;
|
||||||
|
/** aiming position in world coordinates */
|
||||||
|
float aimX, aimY;
|
||||||
|
|
||||||
public WeaponMount(Weapon weapon){
|
public WeaponMount(Weapon weapon){
|
||||||
this.weapon = weapon;
|
this.weapon = weapon;
|
||||||
|
|||||||
@@ -42,12 +42,29 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
|||||||
public float rotation;
|
public float rotation;
|
||||||
|
|
||||||
protected final Interpolator interpolator = new Interpolator();
|
protected final Interpolator interpolator = new Interpolator();
|
||||||
|
/** status effects */
|
||||||
protected final Statuses status = new Statuses();
|
protected final Statuses status = new Statuses();
|
||||||
|
/** current item held */
|
||||||
protected final ItemStack item = new ItemStack(content.item(0), 0);
|
protected final ItemStack item = new ItemStack(content.item(0), 0);
|
||||||
|
/** holds weapon aiming positions and angles */
|
||||||
protected final Weapons weapons = new Weapons();
|
protected final Weapons weapons = new Weapons();
|
||||||
|
|
||||||
|
/** team; can be changed at any time */
|
||||||
protected Team team = Team.sharded;
|
protected Team team = Team.sharded;
|
||||||
|
/** timers for drowning and getting hit */
|
||||||
protected float drownTime, hitTime;
|
protected float drownTime, hitTime;
|
||||||
|
/** this unit's type; do not change internally without calling setType(...) */
|
||||||
|
protected UnitDef type;
|
||||||
|
|
||||||
|
public void setType(UnitDef type){
|
||||||
|
this.type = type;
|
||||||
|
clampHealth();
|
||||||
|
weapons.init(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnitDef type(){
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean collidesGrid(int x, int y){
|
public boolean collidesGrid(int x, int y){
|
||||||
@@ -137,18 +154,18 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void hitbox(Rect rect){
|
public void hitbox(Rect rect){
|
||||||
rect.setSize(type().hitsize).setCenter(x, y);
|
rect.setSize(type.hitsize).setCenter(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void hitboxTile(Rect rect){
|
public void hitboxTile(Rect rect){
|
||||||
rect.setSize(type().hitsizeTile).setCenter(x, y);
|
rect.setSize(type.hitsizeTile).setCenter(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float drag(){
|
public float drag(){
|
||||||
return type().drag;
|
return type.drag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -181,8 +198,6 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
|||||||
this.rotation = rotation;
|
this.rotation = rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract UnitDef type();
|
|
||||||
|
|
||||||
public void writeSave(DataOutput stream, boolean net) throws IOException{
|
public void writeSave(DataOutput stream, boolean net) throws IOException{
|
||||||
if(item.item == null) item.item = Items.copper;
|
if(item.item == null) item.item = Items.copper;
|
||||||
|
|
||||||
@@ -210,7 +225,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isImmune(StatusEffect effect){
|
public boolean isImmune(StatusEffect effect){
|
||||||
return type().immunities.contains(effect);
|
return type.immunities.contains(effect);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOutOfBounds(){
|
public boolean isOutOfBounds(){
|
||||||
@@ -411,8 +426,8 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void drawLight(){
|
public void drawLight(){
|
||||||
if(type().lightRadius > 0){
|
if(type.lightRadius > 0){
|
||||||
renderer.lights.add(x, y, type().lightRadius, type().lightColor, 0.6f);
|
renderer.lights.add(x, y, type.lightRadius, type.lightColor, 0.6f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -471,15 +486,15 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
|||||||
public abstract TextureRegion getIconRegion();
|
public abstract TextureRegion getIconRegion();
|
||||||
|
|
||||||
public final int getItemCapacity(){
|
public final int getItemCapacity(){
|
||||||
return type().itemCapacity;
|
return type.itemCapacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float mass(){
|
public float mass(){
|
||||||
return type().mass;
|
return type.mass;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFlying(){
|
public boolean isFlying(){
|
||||||
return type().flying;
|
return type.flying;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
org.gradle.daemon=true
|
org.gradle.daemon=true
|
||||||
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
||||||
archash=94aea8c1999b603635b690635488219cea8c6e33
|
archash=8c289d62c50d23dbd58872e65f0d0cf4731a7e91
|
||||||
|
|||||||
Reference in New Issue
Block a user