Make its movement a bit more robotic
Far from smooth, but its better than a mass suicide orgy.
This commit is contained in:
@@ -21,7 +21,6 @@ import static mindustry.Vars.*;
|
|||||||
public class CraterUnit extends GroundUnit{
|
public class CraterUnit extends GroundUnit{
|
||||||
private final Effect io = Fx.plasticburn; // effect to play when poofing in and out of existence
|
private final Effect io = Fx.plasticburn; // effect to play when poofing in and out of existence
|
||||||
private int inactivity = 0;
|
private int inactivity = 0;
|
||||||
private CraterUnit crater = this;
|
|
||||||
|
|
||||||
private final UnitState
|
private final UnitState
|
||||||
|
|
||||||
@@ -35,26 +34,22 @@ public class CraterUnit extends GroundUnit{
|
|||||||
public void update(){
|
public void update(){
|
||||||
|
|
||||||
// switch to unload when on an end tile
|
// switch to unload when on an end tile
|
||||||
if(dst(on()) < 2.5f && on(Track.end)){
|
if(dst(on()) < 1.5f && on(Track.end)){
|
||||||
state.set(unload);
|
state.set(unload);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// compute a destination
|
||||||
Tile target = on().front();
|
Tile target = on().front();
|
||||||
|
if(!dibs(target)) target = on();
|
||||||
|
|
||||||
if(!Track.dibs.containsKey(target)){
|
if(dst(target) > 1f){ // move to target...
|
||||||
Track.dibs.put(target, crater);
|
velocity.add(vec.trnsExact(angleTo(target), type.speed * Time.delta()));
|
||||||
if(Track.dibs.get(on()) == crater) Track.dibs.remove(on());
|
}else{ // ...but snap on its center
|
||||||
|
set(target.drawx(), target.drawy()); // fixme: make movement more majestically
|
||||||
}
|
}
|
||||||
if(Track.dibs.get(target) != crater) target = on();
|
|
||||||
|
|
||||||
// move in the direction/rotation of the block its currently on
|
rotation = Mathf.slerpDelta(rotation, angleTo(on().front()), type.rotatespeed);
|
||||||
velocity.add(vec.trnsExact(angleTo(target), type.speed * Time.delta()));
|
|
||||||
rotation = Mathf.slerpDelta(rotation, baseRotation, type.rotatespeed);
|
|
||||||
|
|
||||||
// if(dst(on()) < 0.5f && on() != target){
|
|
||||||
// velocity.snap();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
unload = new UnitState(){
|
unload = new UnitState(){
|
||||||
@@ -75,6 +70,31 @@ public class CraterUnit extends GroundUnit{
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ensures (well, tries to make sure) that each crater has one tile to itself
|
||||||
|
private boolean dibs(Tile tile){
|
||||||
|
if(!tile.block().compressable) return false;
|
||||||
|
|
||||||
|
// invalidate existing dibs
|
||||||
|
if(Track.dibs.containsKey(tile)){
|
||||||
|
if(Track.dibs.get(tile).isDead() || Track.dibs.get(tile).dst(tile) > tilesize) Track.dibs.remove(tile);
|
||||||
|
}
|
||||||
|
|
||||||
|
// instantly claim unclaimed tiles
|
||||||
|
if(!Track.dibs.containsKey(tile)){
|
||||||
|
Track.dibs.remove(on());
|
||||||
|
Track.dibs.put(tile, this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// tile is claimed by current unit
|
||||||
|
if(Track.dibs.get(tile) == this){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// various reasons
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UnitState getStartState(){
|
public UnitState getStartState(){
|
||||||
return load;
|
return load;
|
||||||
|
|||||||
@@ -122,6 +122,6 @@ public class CompressedConveyor extends ArmoredConveyor{
|
|||||||
this.check = check;
|
this.check = check;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ObjectMap<Tile, CraterUnit> dibs = new ObjectMap<>();
|
public static ObjectMap<Tile, CraterUnit> dibs = new ObjectMap<>(); // fixme: race conditions on world load
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user