prefRotation for units
This commit is contained in:
@@ -23,7 +23,6 @@ public class SoundLoop{
|
|||||||
if(id < 0){
|
if(id < 0){
|
||||||
if(play){
|
if(play){
|
||||||
id = sound.loop(sound.calcVolume(x, y) * volume * baseVolume, 1f, sound.calcPan(x, y));
|
id = sound.loop(sound.calcVolume(x, y) * volume * baseVolume, 1f, sound.calcPan(x, y));
|
||||||
Log.info("playing, id = @", id);
|
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
//fade the sound in or out
|
//fade the sound in or out
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ abstract class BuilderComp implements Unitc{
|
|||||||
|
|
||||||
@Import float x, y, rotation;
|
@Import float x, y, rotation;
|
||||||
|
|
||||||
@SyncLocal Queue<BuildPlan> plans = new Queue<>();
|
@SyncLocal Queue<BuildPlan> plans = new Queue<>(1);
|
||||||
@SyncLocal transient boolean updateBuilding = true;
|
@SyncLocal transient boolean updateBuilding = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -35,7 +35,6 @@ abstract class BuilderComp implements Unitc{
|
|||||||
if(!updateBuilding) return;
|
if(!updateBuilding) return;
|
||||||
|
|
||||||
float finalPlaceDst = state.rules.infiniteResources ? Float.MAX_VALUE : buildingRange;
|
float finalPlaceDst = state.rules.infiniteResources ? Float.MAX_VALUE : buildingRange;
|
||||||
|
|
||||||
boolean infinite = state.rules.infiniteResources || team().rules().infiniteResources;
|
boolean infinite = state.rules.infiniteResources || team().rules().infiniteResources;
|
||||||
|
|
||||||
Iterator<BuildPlan> it = plans.iterator();
|
Iterator<BuildPlan> it = plans.iterator();
|
||||||
@@ -69,10 +68,6 @@ abstract class BuilderComp implements Unitc{
|
|||||||
|
|
||||||
Tile tile = world.tile(current.x, current.y);
|
Tile tile = world.tile(current.x, current.y);
|
||||||
|
|
||||||
if(within(tile, finalPlaceDst)){
|
|
||||||
lookAt(angleTo(tile));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!(tile.block() instanceof ConstructBlock)){
|
if(!(tile.block() instanceof ConstructBlock)){
|
||||||
if(!current.initialized && !current.breaking && Build.validPlace(current.block, team(), current.x, current.y, current.rotation)){
|
if(!current.initialized && !current.breaking && Build.validPlace(current.block, team(), current.x, current.y, current.rotation)){
|
||||||
boolean hasAll = infinite || !Structs.contains(current.block.requirements, i -> core != null && !core.items.has(i.item));
|
boolean hasAll = infinite || !Structs.contains(current.block.requirements, i -> core != null && !core.items.has(i.item));
|
||||||
@@ -188,6 +183,10 @@ abstract class BuilderComp implements Unitc{
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean activelyBuilding(){
|
boolean activelyBuilding(){
|
||||||
|
//not actively building when not near the build plan
|
||||||
|
if(isBuilding() && !within(buildPlan(), state.rules.infiniteResources ? Float.MAX_VALUE : buildingRange)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return isBuilding() && updateBuilding;
|
return isBuilding() && updateBuilding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,6 @@ abstract class MinerComp implements Itemsc, Posc, Teamc, Rotc, Drawc, Unitc{
|
|||||||
mineTimer = 0f;
|
mineTimer = 0f;
|
||||||
}else if(mining()){
|
}else if(mining()){
|
||||||
Item item = mineTile.drop();
|
Item item = mineTile.drop();
|
||||||
lookAt(angleTo(mineTile.worldx(), mineTile.worldy()));
|
|
||||||
mineTimer += Time.delta *type.mineSpeed;
|
mineTimer += Time.delta *type.mineSpeed;
|
||||||
|
|
||||||
if(Mathf.chance(0.06 * Time.delta)){
|
if(Mathf.chance(0.06 * Time.delta)){
|
||||||
|
|||||||
@@ -79,6 +79,17 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
|
|||||||
controlling().each(cons);
|
controlling().each(cons);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return where the unit wants to look at. */
|
||||||
|
public float prefRotation(){
|
||||||
|
if(this instanceof Builderc builder && builder.activelyBuilding()){
|
||||||
|
return angleTo(builder.buildPlan());
|
||||||
|
}else if(this instanceof Minerc miner && miner.mineTile() != null){
|
||||||
|
return angleTo(miner.mineTile());
|
||||||
|
}else{
|
||||||
|
return vel().angle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float range(){
|
public float range(){
|
||||||
return type.range;
|
return type.range;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import mindustry.world.*;
|
|||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
/** Class for storing build requests. Can be either a place or remove request. */
|
/** Class for storing build requests. Can be either a place or remove request. */
|
||||||
public class BuildPlan{
|
public class BuildPlan implements Position{
|
||||||
/** Position and rotation of this request. */
|
/** Position and rotation of this request. */
|
||||||
public int x, y, rotation;
|
public int x, y, rotation;
|
||||||
/** Block being placed. If null, this is a breaking request.*/
|
/** Block being placed. If null, this is a breaking request.*/
|
||||||
@@ -127,11 +127,11 @@ public class BuildPlan{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public float drawx(){
|
public float drawx(){
|
||||||
return x*tilesize + block.offset;
|
return x*tilesize + (block == null ? 0 : block.offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float drawy(){
|
public float drawy(){
|
||||||
return y*tilesize + block.offset;
|
return y*tilesize + (block == null ? 0 : block.offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable Tile tile(){
|
public @Nullable Tile tile(){
|
||||||
@@ -142,6 +142,16 @@ public class BuildPlan{
|
|||||||
return world.build(x, y);
|
return world.build(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getX(){
|
||||||
|
return drawx();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getY(){
|
||||||
|
return drawy();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(){
|
public String toString(){
|
||||||
return "BuildRequest{" +
|
return "BuildRequest{" +
|
||||||
|
|||||||
Reference in New Issue
Block a user