Leg unit movement fixes

This commit is contained in:
Anuken
2020-07-12 11:34:19 -04:00
parent dad5b186db
commit f5f495b9b8
12 changed files with 63 additions and 23 deletions

View File

@@ -2,6 +2,7 @@
alpha=0 alpha=0
arkyid=37 arkyid=37
atrax=38
block=1 block=1
cix=2 cix=2
draug=3 draug=3
@@ -34,6 +35,7 @@ pulsar=34
quasar=32 quasar=32
risse=33 risse=33
spirit=27 spirit=27
spiroct=39
tau=17 tau=17
trident=18 trident=18
vanguard=19 vanguard=19

View File

@@ -0,0 +1 @@
{fields:[{name:ammo,type:int,size:4},{name:armor,type:float,size:4},{name:controller,type:mindustry.entities.units.UnitController,size:-1},{name:elevation,type:float,size:4},{name:health,type:float,size:4},{name:isShooting,type:boolean,size:1},{name:mounts,type:"mindustry.entities.units.WeaponMount[]",size:-1},{name:plans,type:arc.struct.Queue<mindustry.entities.units.BuildPlan>,size:-1},{name:rotation,type:float,size:4},{name:shield,type:float,size:4},{name:spawnedByCore,type:boolean,size:1},{name:stack,type:mindustry.type.ItemStack,size:-1},{name:statuses,type:arc.struct.Seq<mindustry.entities.units.StatusEntry>,size:-1},{name:team,type:mindustry.game.Team,size:-1},{name:type,type:mindustry.type.UnitType,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]}

View File

@@ -1675,7 +1675,7 @@ public class Blocks implements ContentList{
requirements(Category.units, with(Items.copper, 30, Items.lead, 70)); requirements(Category.units, with(Items.copper, 30, Items.lead, 70));
plans = new UnitPlan[]{ plans = new UnitPlan[]{
new UnitPlan(UnitTypes.dagger, 200f, with(Items.silicon, 10, Items.lead, 10)), new UnitPlan(UnitTypes.dagger, 200f, with(Items.silicon, 10, Items.lead, 10)),
new UnitPlan(UnitTypes.crawler, 200f, with(Items.silicon, 10, Items.blastCompound, 5)), new UnitPlan(UnitTypes.crawler, 200f, with(Items.silicon, 10, Items.blastCompound, 10)),
new UnitPlan(UnitTypes.nova, 200f, with(Items.silicon, 20, Items.lead, 20, Items.titanium, 20)), new UnitPlan(UnitTypes.nova, 200f, with(Items.silicon, 20, Items.lead, 20, Items.titanium, 20)),
}; };
size = 3; size = 3;

View File

@@ -24,7 +24,10 @@ public class UnitTypes implements ContentList{
public static @EntityDef({Unitc.class, Mechc.class, Builderc.class, Minerc.class, Commanderc.class}) UnitType pulsar, quasar; public static @EntityDef({Unitc.class, Mechc.class, Builderc.class, Minerc.class, Commanderc.class}) UnitType pulsar, quasar;
//legs //legs
public static @EntityDef({Unitc.class, Legsc.class}) UnitType arkyid, atrax, spiroct; public static @EntityDef({Unitc.class, Legsc.class}) UnitType atrax;
//legs + building
public static @EntityDef({Unitc.class, Legsc.class, Builderc.class}) UnitType spiroct, arkyid;
//air (no special traits) //air (no special traits)
public static @EntityDef({Unitc.class}) UnitType flare, eclipse, horizon, zenith, antumbra; public static @EntityDef({Unitc.class}) UnitType flare, eclipse, horizon, zenith, antumbra;
@@ -269,6 +272,10 @@ public class UnitTypes implements ContentList{
hovering = true; hovering = true;
armor = 3f; armor = 3f;
allowLegStep = true;
visualElevation = 0.2f;
groundLayer = Layer.legUnit - 1f;
weapons.add(new Weapon("eruption"){{ weapons.add(new Weapon("eruption"){{
shootY = 3f; shootY = 3f;
reload = 10f; reload = 10f;
@@ -303,6 +310,12 @@ public class UnitTypes implements ContentList{
hovering = true; hovering = true;
armor = 3f; armor = 3f;
buildSpeed = 0.75f;
allowLegStep = true;
visualElevation = 0.3f;
groundLayer = Layer.legUnit;
weapons.add(new Weapon("spiroct-weapon"){{ weapons.add(new Weapon("spiroct-weapon"){{
shootY = 4f; shootY = 4f;
reload = 15f; reload = 15f;
@@ -315,6 +328,7 @@ public class UnitTypes implements ContentList{
y = -1.5f; y = -1.5f;
bullet = new SapBulletType(){{ bullet = new SapBulletType(){{
sapStrength = 0.3f;
length = 75f; length = 75f;
damage = 15; damage = 15;
shootEffect = Fx.shootSmall; shootEffect = Fx.shootSmall;
@@ -333,8 +347,9 @@ public class UnitTypes implements ContentList{
y = 3f; y = 3f;
bullet = new SapBulletType(){{ bullet = new SapBulletType(){{
sapStrength = 0.65f;
length = 40f; length = 40f;
damage = 10; damage = 12;
shootEffect = Fx.shootSmall; shootEffect = Fx.shootSmall;
hitColor = color = Color.valueOf("bf92f9"); hitColor = color = Color.valueOf("bf92f9");
despawnEffect = Fx.none; despawnEffect = Fx.none;
@@ -350,7 +365,6 @@ public class UnitTypes implements ContentList{
speed = 0.5f; speed = 0.5f;
hitsize = 9f; hitsize = 9f;
health = 140; health = 140;
baseElevation = 0.51f;
legCount = 6; legCount = 6;
legMoveSpace = 1f; legMoveSpace = 1f;

View File

@@ -24,6 +24,12 @@ public class EntityCollisions{
//entity collisions //entity collisions
private Seq<Hitboxc> arrOut = new Seq<>(); private Seq<Hitboxc> arrOut = new Seq<>();
public void moveCheck(Hitboxc entity, float deltax, float deltay, SolidPred solidCheck){
if(!solidCheck.solid(entity.tileX(), entity.tileY())){
move(entity, deltax, deltay, solidCheck);
}
}
public void move(Hitboxc entity, float deltax, float deltay){ public void move(Hitboxc entity, float deltax, float deltay){
move(entity, deltax, deltay, EntityCollisions::solid); move(entity, deltax, deltay, EntityCollisions::solid);
} }
@@ -119,14 +125,19 @@ public class EntityCollisions{
}); });
} }
public static boolean legsSolid(int x, int y){
Tile tile = world.tile(x, y);
return tile == null || tile.staticDarkness() >= 2;
}
public static boolean waterSolid(int x, int y){ public static boolean waterSolid(int x, int y){
Tile tile = world.tile(x, y); Tile tile = world.tile(x, y);
return tile != null && (tile.solid() || !tile.floor().isLiquid); return tile == null || (tile.solid() || !tile.floor().isLiquid);
} }
public static boolean solid(int x, int y){ public static boolean solid(int x, int y){
Tile tile = world.tile(x, y); Tile tile = world.tile(x, y);
return tile != null && tile.solid(); return tile == null || tile.solid();
} }
private void checkCollide(Hitboxc a, Hitboxc b){ private void checkCollide(Hitboxc a, Hitboxc b){

View File

@@ -19,4 +19,5 @@ abstract class ElevationMoveComp implements Velc, Posc, Flyingc, Hitboxc{
collisions.move(this, cx, cy); collisions.move(this, cx, cy);
} }
} }
} }

View File

@@ -12,8 +12,10 @@ import mindustry.graphics.*;
import mindustry.type.*; import mindustry.type.*;
import mindustry.world.blocks.environment.*; import mindustry.world.blocks.environment.*;
import static mindustry.Vars.*;
@Component @Component
abstract class LegsComp implements Posc, Rotc, Hitboxc, Flyingc, Unitc, ElevationMovec{ abstract class LegsComp implements Posc, Rotc, Hitboxc, Flyingc, Unitc{
@Import float x, y; @Import float x, y;
@Import UnitType type; @Import UnitType type;
@@ -22,6 +24,12 @@ abstract class LegsComp implements Posc, Rotc, Hitboxc, Flyingc, Unitc, Elevatio
transient float moveSpace; transient float moveSpace;
transient float baseRotation; transient float baseRotation;
@Replace
@Override
public void move(float cx, float cy){
collisions.moveCheck(this, cx, cy, !type.allowLegStep ? EntityCollisions::solid : EntityCollisions::legsSolid);
}
@Override @Override
public void update(){ public void update(){
if(Mathf.dst(deltaX(), deltaY()) > 0.001f){ if(Mathf.dst(deltaX(), deltaY()) > 0.001f){

View File

@@ -122,7 +122,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
this.type = type; this.type = type;
this.maxHealth = type.health; this.maxHealth = type.health;
this.drag = type.drag; this.drag = type.drag;
this.elevation = type.flying ? 1f : type.baseElevation; this.elevation = type.flying ? 1f : 0;
this.armor = type.armor; this.armor = type.armor;
this.hitSize = type.hitsize; this.hitSize = type.hitsize;
this.hovering = type.hovering; this.hovering = type.hovering;
@@ -214,17 +214,12 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
Tile tile = tileOn(); Tile tile = tileOn();
Floor floor = floorOn(); Floor floor = floorOn();
if(tile != null && isGrounded()){ if(tile != null && isGrounded() && !type.hovering){
//unit block update //unit block update
if(tile.build != null){ if(tile.build != null){
tile.build.unitOn(base()); tile.build.unitOn(base());
} }
//kill when stuck in wall
if(tile.solid()){
kill();
}
//apply damage //apply damage
if(floor.damageTaken > 0f){ if(floor.damageTaken > 0f){
damageContinuous(floor.damageTaken); damageContinuous(floor.damageTaken);

View File

@@ -17,9 +17,7 @@ abstract class WaterMoveComp implements Posc, Velc, Hitboxc, Flyingc{
@Override @Override
public void move(float cx, float cy){ public void move(float cx, float cy){
if(isGrounded()){ if(isGrounded()){
if(!EntityCollisions.waterSolid(tileX(), tileY())){ collisions.moveCheck(this, cx, cy, EntityCollisions::waterSolid);
collisions.move(this, cx, cy, EntityCollisions::waterSolid);
}
}else{ }else{
x += cx; x += cx;
y += cy; y += cy;

View File

@@ -38,6 +38,9 @@ public class Layer{
//power lines //power lines
power = 70, power = 70,
//certain multi-legged units
legUnit = 75f,
//darkness over block clusters //darkness over block clusters
darkness = 80, darkness = 80,

View File

@@ -43,15 +43,17 @@ public class UnitType extends UnlockableContent{
public boolean faceTarget = true, rotateShooting = true, isCounted = true, lowAltitude = false; public boolean faceTarget = true, rotateShooting = true, isCounted = true, lowAltitude = false;
public boolean canBoost = false; public boolean canBoost = false;
public boolean destructibleWreck = true; public boolean destructibleWreck = true;
public float groundLayer = Layer.groundUnit;
public float sway = 1f; public float sway = 1f;
public int payloadCapacity = 1; public int payloadCapacity = 1;
public int commandLimit = 24; public int commandLimit = 24;
public float baseElevation = 0f; public float visualElevation = -1f;
public float deathShake = 2f; public float deathShake = 2f;
public boolean allowLegStep = false;
public boolean hovering = false; public boolean hovering = false;
public Effect fallEffect = Fx.fallSmoke; public Effect fallEffect = Fx.fallSmoke;
public Effect fallThrusterEffect = Fx.fallSmoke; public Effect fallThrusterEffect = Fx.fallSmoke;
public Seq<mindustry.entities.abilities.Ability> abilities = new Seq<>(); public Seq<Ability> abilities = new Seq<>();
//TODO document //TODO document
public int legCount = 4, legGroupSize = 2; public int legCount = 4, legGroupSize = 2;
@@ -215,7 +217,7 @@ public class UnitType extends UnlockableContent{
public void draw(Unit unit){ public void draw(Unit unit){
Mechc legs = unit instanceof Mechc ? (Mechc)unit : null; Mechc legs = unit instanceof Mechc ? (Mechc)unit : null;
float z = unit.elevation > 0.5f ? (lowAltitude ? Layer.flyingUnitLow : Layer.flyingUnit) : Layer.groundUnit; float z = unit.elevation > 0.5f ? (lowAltitude ? Layer.flyingUnitLow : Layer.flyingUnit) : groundLayer;
if(unit.controller().isBeingControlled(player.unit())){ if(unit.controller().isBeingControlled(player.unit())){
drawControl(unit); drawControl(unit);
@@ -297,7 +299,8 @@ public class UnitType extends UnlockableContent{
public void drawShadow(Unit unit){ public void drawShadow(Unit unit){
Draw.color(shadowColor); Draw.color(shadowColor);
Draw.rect(shadowRegion, unit.x + shadowTX * unit.elevation, unit.y + shadowTY * unit.elevation, unit.rotation - 90); float e = Math.max(unit.elevation, visualElevation);
Draw.rect(shadowRegion, unit.x + shadowTX * e, unit.y + shadowTY * e, unit.rotation - 90);
Draw.color(); Draw.color();
} }
@@ -444,8 +447,8 @@ public class UnitType extends UnlockableContent{
Tmp.v1.set(leg.base).sub(leg.joint).inv().setLength(legExtension); Tmp.v1.set(leg.base).sub(leg.joint).inv().setLength(legExtension);
if(leg.moving && baseElevation > 0){ if(leg.moving && visualElevation > 0){
float scl = baseElevation; float scl = visualElevation;
float elev = Mathf.slope(1f - leg.stage) * scl; float elev = Mathf.slope(1f - leg.stage) * scl;
Draw.color(shadowColor); Draw.color(shadowColor);
Draw.rect(footRegion, leg.base.x + shadowTX * elev, leg.base.y + shadowTY * elev, position.angleTo(leg.base)); Draw.rect(footRegion, leg.base.x + shadowTX * elev, leg.base.y + shadowTY * elev, position.angleTo(leg.base));

View File

@@ -468,6 +468,10 @@ public class Tile implements Position, QuadTreeObject, Displayable{
return overlay == Blocks.air || overlay.itemDrop == null ? floor.itemDrop : overlay.itemDrop; return overlay == Blocks.air || overlay.itemDrop == null ? floor.itemDrop : overlay.itemDrop;
} }
public int staticDarkness(){
return block.solid && block.fillsTile && !block.synthetic() ? rotation : 0;
}
public void updateOcclusion(){ public void updateOcclusion(){
cost = 1; cost = 1;
boolean occluded = false; boolean occluded = false;