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
arkyid=37
atrax=38
block=1
cix=2
draug=3
@ -34,6 +35,7 @@ pulsar=34
quasar=32
risse=33
spirit=27
spiroct=39
tau=17
trident=18
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));
plans = new UnitPlan[]{
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)),
};
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;
//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)
public static @EntityDef({Unitc.class}) UnitType flare, eclipse, horizon, zenith, antumbra;
@ -269,6 +272,10 @@ public class UnitTypes implements ContentList{
hovering = true;
armor = 3f;
allowLegStep = true;
visualElevation = 0.2f;
groundLayer = Layer.legUnit - 1f;
weapons.add(new Weapon("eruption"){{
shootY = 3f;
reload = 10f;
@ -303,6 +310,12 @@ public class UnitTypes implements ContentList{
hovering = true;
armor = 3f;
buildSpeed = 0.75f;
allowLegStep = true;
visualElevation = 0.3f;
groundLayer = Layer.legUnit;
weapons.add(new Weapon("spiroct-weapon"){{
shootY = 4f;
reload = 15f;
@ -315,6 +328,7 @@ public class UnitTypes implements ContentList{
y = -1.5f;
bullet = new SapBulletType(){{
sapStrength = 0.3f;
length = 75f;
damage = 15;
shootEffect = Fx.shootSmall;
@ -333,8 +347,9 @@ public class UnitTypes implements ContentList{
y = 3f;
bullet = new SapBulletType(){{
sapStrength = 0.65f;
length = 40f;
damage = 10;
damage = 12;
shootEffect = Fx.shootSmall;
hitColor = color = Color.valueOf("bf92f9");
despawnEffect = Fx.none;
@ -350,7 +365,6 @@ public class UnitTypes implements ContentList{
speed = 0.5f;
hitsize = 9f;
health = 140;
baseElevation = 0.51f;
legCount = 6;
legMoveSpace = 1f;

View File

@ -24,6 +24,12 @@ public class EntityCollisions{
//entity collisions
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){
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){
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){
Tile tile = world.tile(x, y);
return tile != null && tile.solid();
return tile == null || tile.solid();
}
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);
}
}
}

View File

@ -12,8 +12,10 @@ import mindustry.graphics.*;
import mindustry.type.*;
import mindustry.world.blocks.environment.*;
import static mindustry.Vars.*;
@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 UnitType type;
@ -22,6 +24,12 @@ abstract class LegsComp implements Posc, Rotc, Hitboxc, Flyingc, Unitc, Elevatio
transient float moveSpace;
transient float baseRotation;
@Replace
@Override
public void move(float cx, float cy){
collisions.moveCheck(this, cx, cy, !type.allowLegStep ? EntityCollisions::solid : EntityCollisions::legsSolid);
}
@Override
public void update(){
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.maxHealth = type.health;
this.drag = type.drag;
this.elevation = type.flying ? 1f : type.baseElevation;
this.elevation = type.flying ? 1f : 0;
this.armor = type.armor;
this.hitSize = type.hitsize;
this.hovering = type.hovering;
@ -214,17 +214,12 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
Tile tile = tileOn();
Floor floor = floorOn();
if(tile != null && isGrounded()){
if(tile != null && isGrounded() && !type.hovering){
//unit block update
if(tile.build != null){
tile.build.unitOn(base());
}
//kill when stuck in wall
if(tile.solid()){
kill();
}
//apply damage
if(floor.damageTaken > 0f){
damageContinuous(floor.damageTaken);

View File

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

View File

@ -38,6 +38,9 @@ public class Layer{
//power lines
power = 70,
//certain multi-legged units
legUnit = 75f,
//darkness over block clusters
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 canBoost = false;
public boolean destructibleWreck = true;
public float groundLayer = Layer.groundUnit;
public float sway = 1f;
public int payloadCapacity = 1;
public int commandLimit = 24;
public float baseElevation = 0f;
public float visualElevation = -1f;
public float deathShake = 2f;
public boolean allowLegStep = false;
public boolean hovering = false;
public Effect fallEffect = Fx.fallSmoke;
public Effect fallThrusterEffect = Fx.fallSmoke;
public Seq<mindustry.entities.abilities.Ability> abilities = new Seq<>();
public Seq<Ability> abilities = new Seq<>();
//TODO document
public int legCount = 4, legGroupSize = 2;
@ -215,7 +217,7 @@ public class UnitType extends UnlockableContent{
public void draw(Unit unit){
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())){
drawControl(unit);
@ -297,7 +299,8 @@ public class UnitType extends UnlockableContent{
public void drawShadow(Unit unit){
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();
}
@ -444,8 +447,8 @@ public class UnitType extends UnlockableContent{
Tmp.v1.set(leg.base).sub(leg.joint).inv().setLength(legExtension);
if(leg.moving && baseElevation > 0){
float scl = baseElevation;
if(leg.moving && visualElevation > 0){
float scl = visualElevation;
float elev = Mathf.slope(1f - leg.stage) * scl;
Draw.color(shadowColor);
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;
}
public int staticDarkness(){
return block.solid && block.fillsTile && !block.synthetic() ? rotation : 0;
}
public void updateOcclusion(){
cost = 1;
boolean occluded = false;