mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-27 16:09:57 +07:00
Cleanup
This commit is contained in:
parent
6f3c771d73
commit
432a40c656
@ -17,12 +17,16 @@ import static mindustry.Vars.net;
|
||||
public class Weapons{
|
||||
private static final int[] one = {1};
|
||||
|
||||
private WeaponMount[] mounts;
|
||||
private UnitDef lastDef;
|
||||
private WeaponMount[] mounts = {};
|
||||
|
||||
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){
|
||||
check(unit);
|
||||
|
||||
for(WeaponMount mount : mounts){
|
||||
Weapon weapon = mount.weapon;
|
||||
|
||||
@ -33,8 +37,6 @@ public class Weapons{
|
||||
}
|
||||
|
||||
public void draw(Unit unit){
|
||||
check(unit);
|
||||
|
||||
for(WeaponMount mount : mounts){
|
||||
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
|
||||
|
||||
@Remote(targets = Loc.server, called = Loc.both, unreliable = true)
|
||||
@ -180,6 +171,8 @@ public class Weapons{
|
||||
float rotation;
|
||||
/** weapon associated with this mount */
|
||||
Weapon weapon;
|
||||
/** aiming position in world coordinates */
|
||||
float aimX, aimY;
|
||||
|
||||
public WeaponMount(Weapon weapon){
|
||||
this.weapon = weapon;
|
||||
|
@ -42,12 +42,29 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
public float rotation;
|
||||
|
||||
protected final Interpolator interpolator = new Interpolator();
|
||||
/** status effects */
|
||||
protected final Statuses status = new Statuses();
|
||||
/** current item held */
|
||||
protected final ItemStack item = new ItemStack(content.item(0), 0);
|
||||
/** holds weapon aiming positions and angles */
|
||||
protected final Weapons weapons = new Weapons();
|
||||
|
||||
/** team; can be changed at any time */
|
||||
protected Team team = Team.sharded;
|
||||
/** timers for drowning and getting hit */
|
||||
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
|
||||
public boolean collidesGrid(int x, int y){
|
||||
@ -137,18 +154,18 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
|
||||
@Override
|
||||
public void hitbox(Rect rect){
|
||||
rect.setSize(type().hitsize).setCenter(x, y);
|
||||
rect.setSize(type.hitsize).setCenter(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hitboxTile(Rect rect){
|
||||
rect.setSize(type().hitsizeTile).setCenter(x, y);
|
||||
rect.setSize(type.hitsizeTile).setCenter(x, y);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public float drag(){
|
||||
return type().drag;
|
||||
return type.drag;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -181,8 +198,6 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
public abstract UnitDef type();
|
||||
|
||||
public void writeSave(DataOutput stream, boolean net) throws IOException{
|
||||
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){
|
||||
return type().immunities.contains(effect);
|
||||
return type.immunities.contains(effect);
|
||||
}
|
||||
|
||||
public boolean isOutOfBounds(){
|
||||
@ -411,8 +426,8 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
}
|
||||
|
||||
public void drawLight(){
|
||||
if(type().lightRadius > 0){
|
||||
renderer.lights.add(x, y, type().lightRadius, type().lightColor, 0.6f);
|
||||
if(type.lightRadius > 0){
|
||||
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 final int getItemCapacity(){
|
||||
return type().itemCapacity;
|
||||
return type.itemCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float mass(){
|
||||
return type().mass;
|
||||
return type.mass;
|
||||
}
|
||||
|
||||
public boolean isFlying(){
|
||||
return type().flying;
|
||||
return type.flying;
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
org.gradle.daemon=true
|
||||
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
||||
archash=94aea8c1999b603635b690635488219cea8c6e33
|
||||
archash=8c289d62c50d23dbd58872e65f0d0cf4731a7e91
|
||||
|
Loading…
Reference in New Issue
Block a user