Improved power node link preview check

This commit is contained in:
Anuken 2021-02-27 10:16:54 -05:00
parent 5037c4e00e
commit 44d10a355e
3 changed files with 20 additions and 2 deletions

View File

@ -494,7 +494,7 @@ public class DesktopInput extends InputHandler{
}else if(selected != null){
//only begin shooting if there's no cursor event
if(!tryTapPlayer(Core.input.mouseWorld().x, Core.input.mouseWorld().y) && !tileTapped(selected.build) && !player.unit().activelyBuilding() && !droppingItem
&& !((!settings.getBool("doubletapmine") || selected == prevSelected && Time.timeSinceMillis(selectMillis) < 500) && tryBeginMine(selected)) && !Core.scene.hasKeyboard()){
&& !((!settings.getBool("doubletapmine") || (selected == prevSelected && Time.timeSinceMillis(selectMillis) < 500)) && tryBeginMine(selected)) && !Core.scene.hasKeyboard()){
player.shooting = shouldShoot;
}
}else if(!Core.scene.hasKeyboard()){ //if it's out of bounds, shooting is just fine

View File

@ -491,6 +491,11 @@ public class Tile implements Position, QuadTreeObject, Displayable{
return block.solid && block.fillsTile && !block.synthetic() ? data : 0;
}
/** @return true if these tiles are right next to eacho ther. */
public boolean adjacentTo(Tile tile){
return relativeTo(tile) != -1;
}
protected void preChanged(){
if(build != null){
//only call removed() for the center block - this only gets called once.

View File

@ -196,10 +196,23 @@ public class PowerNode extends PowerBlock{
Boolf<Building> valid = other -> other != null && other.tile() != tile && other.power != null &&
(other.block.outputsPower || other.block.consumesPower || other.block instanceof PowerNode) &&
overlaps(tile.x * tilesize + offset, tile.y * tilesize + offset, other.tile(), laserRange * tilesize) && other.team == player.team()
&& !other.proximity.contains(e -> e.tile == tile) && !graphs.contains(other.power.graph);
&& !graphs.contains(other.power.graph) &&
!Structs.contains(Edges.getEdges(size), p -> { //do not link to adjacent buildings
var t = world.tile(tile.x + p.x, tile.y + p.y);
return t != null && t.build == other;
});
tempTileEnts.clear();
graphs.clear();
//add conducting graphs to prevent double link
for(var p : Edges.getEdges(size)){
Tile other = tile.nearby(p);
if(other != null && other.team() == player.team() && other.build != null && other.build.power != null){
graphs.add(other.build.power.graph);
}
}
if(tile.build != null && tile.build.power != null){
graphs.add(tile.build.power.graph);
}