Many bugfixes / Support for repairing derelict in selection

This commit is contained in:
Anuken
2024-09-18 16:27:54 -04:00
parent 63e246cc9d
commit e521a56712
8 changed files with 66 additions and 11 deletions
Binary file not shown.
+13 -1
View File
@@ -272,6 +272,13 @@ public class CommandAI extends AIController{
vecOut.set(vecMovePos); vecOut.set(vecMovePos);
}else{ }else{
move = controlPath.getPathPosition(unit, vecMovePos, targetPos, vecOut, noFound) && (!blockingUnit || timeSpentBlocked > maxBlockTime); move = controlPath.getPathPosition(unit, vecMovePos, targetPos, vecOut, noFound) && (!blockingUnit || timeSpentBlocked > maxBlockTime);
//TODO: what to do when there's a target and it can't be reached?
/*
if(noFound[0] && attackTarget != null && attackTarget.within(unit, unit.type.range * 2f)){
move = true;
vecOut.set(targetPos);
}*/
} }
//rare case where unit must be perfectly aligned (happens with 1-tile gaps) //rare case where unit must be perfectly aligned (happens with 1-tile gaps)
@@ -403,6 +410,11 @@ public class CommandAI extends AIController{
} }
} }
@Override
public void removed(Unit unit){
clearCommands();
}
public void commandQueue(Position location){ public void commandQueue(Position location){
if(targetPos == null && attackTarget == null){ if(targetPos == null && attackTarget == null){
if(location instanceof Teamc t){ if(location instanceof Teamc t){
@@ -444,7 +456,7 @@ public class CommandAI extends AIController{
@Override @Override
public Teamc findTarget(float x, float y, float range, boolean air, boolean ground){ public Teamc findTarget(float x, float y, float range, boolean air, boolean ground){
return !nearAttackTarget(x, y, range) ? super.findTarget(x, y, range, air, ground) : attackTarget; return !nearAttackTarget(x, y, range) ? super.findTarget(x, y, range, air, ground) : Units.isHittable(attackTarget, air, ground) ? attackTarget : null;
} }
public boolean nearAttackTarget(float x, float y, float range){ public boolean nearAttackTarget(float x, float y, float range){
+3 -2
View File
@@ -10,6 +10,7 @@ import static mindustry.Vars.*;
import static mindustry.world.meta.BlockFlag.*; import static mindustry.world.meta.BlockFlag.*;
public class FlyingAI extends AIController{ public class FlyingAI extends AIController{
final static Rand rand = new Rand();
final static BlockFlag[] randomTargets = {core, storage, generator, launchPad, factory, repair, battery, reactor, drill}; final static BlockFlag[] randomTargets = {core, storage, generator, launchPad, factory, repair, battery, reactor, drill};
@Override @Override
@@ -72,10 +73,10 @@ public class FlyingAI extends AIController{
if(state.rules.randomWaveAI){ if(state.rules.randomWaveAI){
//when there are no waves, it's just random based on the unit //when there are no waves, it's just random based on the unit
Mathf.rand.setSeed(unit.type.id + (state.rules.waves ? state.wave : unit.id)); rand.setSeed(unit.type.id + (state.rules.waves ? state.wave : unit.id));
//try a few random flags first //try a few random flags first
for(int attempt = 0; attempt < 5; attempt++){ for(int attempt = 0; attempt < 5; attempt++){
Teamc result = targetFlag(x, y, randomTargets[Mathf.rand.random(randomTargets.length - 1)], true); Teamc result = targetFlag(x, y, randomTargets[rand.random(randomTargets.length - 1)], true);
if(result != null) return result; if(result != null) return result;
} }
//try the closest target //try the closest target
+4
View File
@@ -112,6 +112,10 @@ public class Units{
return player == null || tile == null || tile.interactable(player.team()) || state.rules.editor; return player == null || tile == null || tile.interactable(player.team()) || state.rules.editor;
} }
public static boolean isHittable(@Nullable Posc target, boolean air, boolean ground){
return target != null && (target instanceof Buildingc ? ground : (target instanceof Unit u && u.checkTarget(air, ground)));
}
/** /**
* Validates a target. * Validates a target.
* @param target The target to validate * @param target The target to validate
@@ -90,6 +90,8 @@ abstract class PayloadComp implements Posc, Rotc, Hitboxc, Unitc{
} }
void pickup(Unit unit){ void pickup(Unit unit){
if(unit.isAdded()) unit.team.data().updateCount(unit.type, 1);
unit.remove(); unit.remove();
addPayload(new UnitPayload(unit)); addPayload(new UnitPayload(unit));
Fx.unitPickup.at(unit); Fx.unitPickup.at(unit);
+1 -1
View File
@@ -457,7 +457,7 @@ public class DesktopInput extends InputHandler{
cursorType = cursor.build.getCursor(); cursorType = cursor.build.getCursor();
} }
if(cursor.build != null && !state.rules.editor && player.team() != Team.derelict && cursor.build.team == Team.derelict && cursor.build.block.unlockedNow() && Build.validPlace(cursor.block(), player.team(), cursor.build.tileX(), cursor.build.tileY(), cursor.build.rotation)){ if(canRepairDerelict(cursor)){
cursorType = ui.repairCursor; cursorType = ui.repairCursor;
} }
+40 -6
View File
@@ -53,6 +53,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
/** Used for dropping items. */ /** Used for dropping items. */
final static float playerSelectRange = mobile ? 17f : 11f; final static float playerSelectRange = mobile ? 17f : 11f;
final static IntSeq removed = new IntSeq(); final static IntSeq removed = new IntSeq();
final static IntSet intSet = new IntSet();
/** Maximum line length. */ /** Maximum line length. */
final static int maxLength = 100; final static int maxLength = 100;
final static Rect r1 = new Rect(), r2 = new Rect(); final static Rect r1 = new Rect(), r2 = new Rect();
@@ -1383,10 +1384,10 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
Lines.rect(result.x, result.y, result.x2 - result.x, result.y2 - result.y); Lines.rect(result.x, result.y, result.x2 - result.x, result.y2 - result.y);
} }
protected void drawRebuildSelection(int x, int y, int x2, int y2){ protected void drawRebuildSelection(int x1, int y1, int x2, int y2){
drawSelection(x, y, x2, y2, 0, Pal.sapBulletBack, Pal.sapBullet); drawSelection(x1, y1, x2, y2, 0, Pal.sapBulletBack, Pal.sapBullet);
NormalizeDrawResult result = Placement.normalizeDrawArea(Blocks.air, x, y, x2, y2, false, 0, 1f); NormalizeDrawResult result = Placement.normalizeDrawArea(Blocks.air, x1, y1, x2, y2, false, 0, 1f);
Tmp.r1.set(result.x, result.y, result.x2 - result.x, result.y2 - result.y); Tmp.r1.set(result.x, result.y, result.x2 - result.x, result.y2 - result.y);
@@ -1396,6 +1397,20 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
drawSelected(plan.x, plan.y, content.block(plan.block), Pal.sapBullet); drawSelected(plan.x, plan.y, content.block(plan.block), Pal.sapBullet);
} }
} }
NormalizeResult dresult = Placement.normalizeArea(x1, y1, x2, y2, rotation, false, 999999999);
intSet.clear();
for(int x = dresult.x; x <= dresult.x2; x++){
for(int y = dresult.y; y <= dresult.y2; y++){
Tile tile = world.tileBuilding(x, y);
if(tile != null && intSet.add(tile.pos()) && canRepairDerelict(tile)){
drawSelected(tile.x, tile.y, tile.block(), Pal.sapBullet);
}
}
}
} }
protected void drawBreakSelection(int x1, int y1, int x2, int y2){ protected void drawBreakSelection(int x1, int y1, int x2, int y2){
@@ -1684,13 +1699,20 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
} }
boolean tryRepairDerelict(Tile selected){ boolean tryRepairDerelict(Tile selected){
if(selected != null && !state.rules.editor && player.team() != Team.derelict && selected.build != null && selected.build.block.unlockedNow() && selected.build.team == Team.derelict && Build.validPlace(selected.block(), player.team(), selected.build.tileX(), selected.build.tileY(), selected.build.rotation)){ if(selected != null && !state.rules.editor && player.team() != Team.derelict && selected.build != null && selected.build.block.unlockedNow() && selected.build.team == Team.derelict &&
Build.validPlace(selected.block(), player.team(), selected.build.tileX(), selected.build.tileY(), selected.build.rotation)){
player.unit().addBuild(new BuildPlan(selected.build.tileX(), selected.build.tileY(), selected.build.rotation, selected.block(), selected.build.config())); player.unit().addBuild(new BuildPlan(selected.build.tileX(), selected.build.tileY(), selected.build.rotation, selected.block(), selected.build.config()));
return true; return true;
} }
return false; return false;
} }
boolean canRepairDerelict(Tile tile){
return tile != null && tile.build != null && !state.rules.editor && player.team() != Team.derelict && tile.build.team == Team.derelict && tile.build.block.unlockedNow() &&
Build.validPlace(tile.block(), player.team(), tile.build.tileX(), tile.build.tileY(), tile.build.rotation);
}
boolean canMine(Tile tile){ boolean canMine(Tile tile){
return !Core.scene.hasMouse() return !Core.scene.hasMouse()
&& player.unit().validMine(tile) && player.unit().validMine(tile)
@@ -1898,8 +1920,8 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
} }
} }
public void rebuildArea(int x, int y, int x2, int y2){ public void rebuildArea(int x1, int y1, int x2, int y2){
NormalizeResult result = Placement.normalizeArea(x, y, x2, y2, rotation, false, 999999999); NormalizeResult result = Placement.normalizeArea(x1, y1, x2, y2, rotation, false, 999999999);
Tmp.r1.set(result.x * tilesize, result.y * tilesize, (result.x2 - result.x) * tilesize, (result.y2 - result.y) * tilesize); Tmp.r1.set(result.x * tilesize, result.y * tilesize, (result.x2 - result.x) * tilesize, (result.y2 - result.y) * tilesize);
Iterator<BlockPlan> broken = player.team().data().plans.iterator(); Iterator<BlockPlan> broken = player.team().data().plans.iterator();
@@ -1910,6 +1932,18 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
player.unit().addBuild(new BuildPlan(plan.x, plan.y, plan.rotation, content.block(plan.block), plan.config)); player.unit().addBuild(new BuildPlan(plan.x, plan.y, plan.rotation, content.block(plan.block), plan.config));
} }
} }
intSet.clear();
for(int x = result.x; x <= result.x2; x++){
for(int y = result.y; y <= result.y2; y++){
Tile tile = world.tileBuilding(x, y);
if(tile != null && tile.build != null && intSet.add(tile.pos())){
tryRepairDerelict(tile);
}
}
}
} }
public void tryBreakBlock(int x, int y){ public void tryBreakBlock(int x, int y){
+3 -1
View File
@@ -1276,7 +1276,9 @@ public class UnitType extends UnlockableContent implements Senseable{
if(drawCell) drawCell(unit); if(drawCell) drawCell(unit);
drawWeapons(unit); drawWeapons(unit);
if(drawItems) drawItems(unit); if(drawItems) drawItems(unit);
drawLight(unit); if(!isPayload){
drawLight(unit);
}
if(unit.shieldAlpha > 0 && drawShields){ if(unit.shieldAlpha > 0 && drawShields){
drawShield(unit); drawShield(unit);