Building cleanup
This commit is contained in:
@@ -117,24 +117,29 @@ abstract class BuilderComp implements Posc, Teamc, Rotc{
|
|||||||
current.progress = entity.progress;
|
current.progress = entity.progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Draw all current build requests. Does not draw the beam effect, only the positions. */
|
/** Draw all current build plans. Does not draw the beam effect, only the positions. */
|
||||||
void drawBuildRequests(){
|
void drawBuildPlans(){
|
||||||
|
|
||||||
for(BuildPlan request : plans){
|
for(BuildPlan request : plans){
|
||||||
if(request.progress > 0.01f || (buildPlan() == request && request.initialized && (dst(request.x * tilesize, request.y * tilesize) <= buildingRange || state.isEditor()))) continue;
|
if(request.progress > 0.01f || (buildPlan() == request && request.initialized && (within(request.x * tilesize, request.y * tilesize, buildingRange) || state.isEditor()))) continue;
|
||||||
|
|
||||||
request.animScale = 1f;
|
drawPlan(request, 1f);
|
||||||
if(request.breaking){
|
|
||||||
control.input.drawBreaking(request);
|
|
||||||
}else{
|
|
||||||
request.block.drawRequest(request, control.input.allRequests(),
|
|
||||||
Build.validPlace(request.block, team, request.x, request.y, request.rotation) || control.input.requestMatches(request));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Draw.reset();
|
Draw.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void drawPlan(BuildPlan request, float alpha){
|
||||||
|
request.animScale = 1f;
|
||||||
|
if(request.breaking){
|
||||||
|
control.input.drawBreaking(request);
|
||||||
|
}else{
|
||||||
|
request.block.drawPlan(request, control.input.allRequests(),
|
||||||
|
Build.validPlace(request.block, team, request.x, request.y, request.rotation) || control.input.requestMatches(request),
|
||||||
|
alpha);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** @return whether this request should be skipped, in favor of the next one. */
|
/** @return whether this request should be skipped, in favor of the next one. */
|
||||||
boolean shouldSkip(BuildPlan request, @Nullable Building core){
|
boolean shouldSkip(BuildPlan request, @Nullable Building core){
|
||||||
//requests that you have at least *started* are considered
|
//requests that you have at least *started* are considered
|
||||||
@@ -193,8 +198,10 @@ abstract class BuilderComp implements Posc, Teamc, Rotc{
|
|||||||
|
|
||||||
boolean activelyBuilding(){
|
boolean activelyBuilding(){
|
||||||
//not actively building when not near the build plan
|
//not actively building when not near the build plan
|
||||||
if(isBuilding() && !within(buildPlan(), state.rules.infiniteResources ? Float.MAX_VALUE : buildingRange)){
|
if(isBuilding()){
|
||||||
return false;
|
if(!within(buildPlan(), state.rules.infiniteResources ? Float.MAX_VALUE : buildingRange)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return isBuilding() && updateBuilding;
|
return isBuilding() && updateBuilding;
|
||||||
}
|
}
|
||||||
@@ -206,19 +213,26 @@ abstract class BuilderComp implements Posc, Teamc, Rotc{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void draw(){
|
public void draw(){
|
||||||
if(!isBuilding() || !updateBuilding || !canBuild()) return;
|
if(!activelyBuilding()) return;
|
||||||
|
|
||||||
//TODO check correctness
|
//TODO check correctness
|
||||||
Draw.z(Layer.flyingUnit);
|
Draw.z(Layer.flyingUnit);
|
||||||
|
|
||||||
BuildPlan plan = buildPlan();
|
BuildPlan plan = buildPlan();
|
||||||
Tile tile = world.tile(plan.x, plan.y);
|
Tile tile = world.tile(plan.x, plan.y);
|
||||||
|
var core = team.core();
|
||||||
|
|
||||||
if(tile == null || (!within(tile, buildingRange) && !state.isEditor())){
|
if(tile == null || (!within(tile, buildingRange) && !state.isEditor())){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//draw remote plans.
|
||||||
|
if(core != null && !isLocal() && !(tile.block() instanceof ConstructBlock)){
|
||||||
|
Draw.z(Layer.plans - 1f);
|
||||||
|
drawPlan(plan, 0.5f);
|
||||||
|
Draw.z(Layer.flyingUnit);
|
||||||
|
}
|
||||||
|
|
||||||
int size = plan.breaking ? tile.block().size : plan.block.size;
|
int size = plan.breaking ? tile.block().size : plan.block.size;
|
||||||
float tx = plan.drawx(), ty = plan.drawy();
|
float tx = plan.drawx(), ty = plan.drawy();
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class OverlayRenderer{
|
|||||||
if(player.dead()) return;
|
if(player.dead()) return;
|
||||||
|
|
||||||
if(player.isBuilder()){
|
if(player.isBuilder()){
|
||||||
player.unit().drawBuildRequests();
|
player.unit().drawBuildPlans();
|
||||||
}
|
}
|
||||||
|
|
||||||
input.drawBottom();
|
input.drawBottom();
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ public class DesktopInput extends InputHandler{
|
|||||||
drawArrow(sreq.block, sreq.x, sreq.y, sreq.rotation, valid);
|
drawArrow(sreq.block, sreq.x, sreq.y, sreq.rotation, valid);
|
||||||
}
|
}
|
||||||
|
|
||||||
sreq.block.drawRequest(sreq, allRequests(), valid);
|
sreq.block.drawPlan(sreq, allRequests(), valid);
|
||||||
|
|
||||||
drawSelected(sreq.x, sreq.y, sreq.block, getRequest(sreq.x, sreq.y, sreq.block.size, sreq) != null ? Pal.remove : Pal.accent);
|
drawSelected(sreq.x, sreq.y, sreq.block, getRequest(sreq.x, sreq.y, sreq.block.size, sreq) != null ? Pal.remove : Pal.accent);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -759,14 +759,14 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void drawRequest(BuildPlan request){
|
protected void drawRequest(BuildPlan request){
|
||||||
request.block.drawRequest(request, allRequests(), validPlace(request.x, request.y, request.block, request.rotation));
|
request.block.drawPlan(request, allRequests(), validPlace(request.x, request.y, request.block, request.rotation));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Draws a placement icon for a specific block. */
|
/** Draws a placement icon for a specific block. */
|
||||||
protected void drawRequest(int x, int y, Block block, int rotation){
|
protected void drawRequest(int x, int y, Block block, int rotation){
|
||||||
brequest.set(x, y, rotation, block);
|
brequest.set(x, y, rotation, block);
|
||||||
brequest.animScale = 1f;
|
brequest.animScale = 1f;
|
||||||
block.drawRequest(brequest, allRequests(), validPlace(x, y, block, rotation));
|
block.drawPlan(brequest, allRequests(), validPlace(x, y, block, rotation));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Remove everything from the queue in a selection. */
|
/** Remove everything from the queue in a selection. */
|
||||||
@@ -1048,7 +1048,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
|
|
||||||
public boolean canShoot(){
|
public boolean canShoot(){
|
||||||
return block == null && !onConfigurable() && !isDroppingItem() && !player.unit().activelyBuilding() &&
|
return block == null && !onConfigurable() && !isDroppingItem() && !player.unit().activelyBuilding() &&
|
||||||
!(player.unit() instanceof Mechc && player.unit().isFlying());
|
!(player.unit() instanceof Mechc && player.unit().isFlying()) && !player.unit().mining();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onConfigurable(){
|
public boolean onConfigurable(){
|
||||||
|
|||||||
@@ -292,7 +292,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
|||||||
if(request.breaking){
|
if(request.breaking){
|
||||||
drawSelected(request.x, request.y, tile.block(), Pal.remove);
|
drawSelected(request.x, request.y, tile.block(), Pal.remove);
|
||||||
}else{
|
}else{
|
||||||
request.block.drawRequest(request, allRequests(), true);
|
request.block.drawPlan(request, allRequests(), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,7 +311,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
|||||||
if(i == lineRequests.size - 1 && request.block.rotate){
|
if(i == lineRequests.size - 1 && request.block.rotate){
|
||||||
drawArrow(block, request.x, request.y, request.rotation);
|
drawArrow(block, request.x, request.y, request.rotation);
|
||||||
}
|
}
|
||||||
request.block.drawRequest(request, allRequests(), validPlace(request.x, request.y, request.block, request.rotation) && getRequest(request.x, request.y, request.block.size, null) == null);
|
request.block.drawPlan(request, allRequests(), validPlace(request.x, request.y, request.block, request.rotation) && getRequest(request.x, request.y, request.block.size, null) == null);
|
||||||
drawSelected(request.x, request.y, request.block, Pal.accent);
|
drawSelected(request.x, request.y, request.block, Pal.accent);
|
||||||
}
|
}
|
||||||
}else if(mode == breaking){
|
}else if(mode == breaking){
|
||||||
@@ -391,7 +391,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
|||||||
if(request.breaking){
|
if(request.breaking){
|
||||||
drawSelected(request.x, request.y, request.tile().block(), Pal.remove);
|
drawSelected(request.x, request.y, request.tile().block(), Pal.remove);
|
||||||
}else{
|
}else{
|
||||||
request.block.drawRequest(request, allRequests(), validPlace(request.x, request.y, request.block, request.rotation));
|
request.block.drawPlan(request, allRequests(), validPlace(request.x, request.y, request.block, request.rotation));
|
||||||
drawSelected(request.x, request.y, request.block, Pal.accent);
|
drawSelected(request.x, request.y, request.block, Pal.accent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -736,6 +736,10 @@ public class MobileInput extends InputHandler implements GestureListener{
|
|||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(player.shooting && (player.unit().activelyBuilding() || player.unit().mining())){
|
||||||
|
player.shooting = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void autoPan(){
|
protected void autoPan(){
|
||||||
@@ -913,7 +917,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//update shooting if not building + not mining
|
//update shooting if not building + not mining
|
||||||
if(!player.unit().isBuilding() && player.unit().mineTile == null){
|
if(!player.unit().activelyBuilding() && player.unit().mineTile == null){
|
||||||
|
|
||||||
//autofire targeting
|
//autofire targeting
|
||||||
if(manualShooting){
|
if(manualShooting){
|
||||||
|
|||||||
@@ -393,10 +393,14 @@ public class Block extends UnlockableContent{
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawRequest(BuildPlan req, Eachable<BuildPlan> list, boolean valid){
|
public void drawPlan(BuildPlan req, Eachable<BuildPlan> list, boolean valid){
|
||||||
|
drawPlan(req, list, valid, 1f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawPlan(BuildPlan req, Eachable<BuildPlan> list, boolean valid, float alpha){
|
||||||
Draw.reset();
|
Draw.reset();
|
||||||
Draw.mixcol(!valid ? Pal.breakInvalid : Color.white, (!valid ? 0.4f : 0.24f) + Mathf.absin(Time.globalTime, 6f, 0.28f));
|
Draw.mixcol(!valid ? Pal.breakInvalid : Color.white, (!valid ? 0.4f : 0.24f) + Mathf.absin(Time.globalTime, 6f, 0.28f));
|
||||||
Draw.alpha(1f);
|
Draw.alpha(alpha);
|
||||||
float prevScale = Draw.scl;
|
float prevScale = Draw.scl;
|
||||||
Draw.scl *= req.animScale;
|
Draw.scl *= req.animScale;
|
||||||
drawRequestRegion(req, list);
|
drawRequestRegion(req, list);
|
||||||
|
|||||||
Reference in New Issue
Block a user