Fixed units pathfinding to nonexistent cores
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package io.anuke.mindustry.ai;
|
package io.anuke.mindustry.ai;
|
||||||
|
|
||||||
import com.badlogic.gdx.math.GridPoint2;
|
import com.badlogic.gdx.math.GridPoint2;
|
||||||
import com.badlogic.gdx.utils.Array;
|
|
||||||
import com.badlogic.gdx.utils.IntArray;
|
import com.badlogic.gdx.utils.IntArray;
|
||||||
import com.badlogic.gdx.utils.Queue;
|
import com.badlogic.gdx.utils.Queue;
|
||||||
import com.badlogic.gdx.utils.TimeUtils;
|
import com.badlogic.gdx.utils.TimeUtils;
|
||||||
@@ -31,7 +30,7 @@ public class Pathfinder{
|
|||||||
|
|
||||||
for(Team team : Team.all){
|
for(Team team : Team.all){
|
||||||
TeamData data = state.teams.get(team);
|
TeamData data = state.teams.get(team);
|
||||||
if(state.teams.isActive(team) && data.team != event.tile.getTeam() && paths[data.team.ordinal()].weights[event.tile.x][event.tile.y] >= Float.MAX_VALUE){
|
if(state.teams.isActive(team) && data.team != event.tile.getTeam()){
|
||||||
update(event.tile, data.team);
|
update(event.tile, data.team);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -87,28 +86,28 @@ public class Pathfinder{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean passable(Tile tile, Team team){
|
private boolean passable(Tile tile, Team team){
|
||||||
return (!tile.solid())
|
return (!tile.solid()) || (tile.breakable() && (tile.target().getTeam() != team));
|
||||||
|| (tile.breakable() && (tile.target().getTeam() != team));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**Clears the frontier, increments the search and sets up all flow sources.
|
||||||
|
* This only occurs for active teams.*/
|
||||||
private void update(Tile tile, Team team){
|
private void update(Tile tile, Team team){
|
||||||
|
//make sure team exists
|
||||||
if(paths[team.ordinal()] != null){
|
if(paths[team.ordinal()] != null){
|
||||||
PathData path = paths[team.ordinal()];
|
PathData path = paths[team.ordinal()];
|
||||||
|
|
||||||
|
//impassable tiles have a weight of float.max
|
||||||
if(!passable(tile, team)){
|
if(!passable(tile, team)){
|
||||||
path.weights[tile.x][tile.y] = Float.MAX_VALUE;
|
path.weights[tile.x][tile.y] = Float.MAX_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//increment search, clear frontier
|
||||||
path.search++;
|
path.search++;
|
||||||
|
path.frontier.clear();
|
||||||
if(path.lastSearchTime + 1000 / 60 * 3 > TimeUtils.millis()){
|
|
||||||
path.frontier.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
path.lastSearchTime = TimeUtils.millis();
|
path.lastSearchTime = TimeUtils.millis();
|
||||||
|
|
||||||
Array<Tile> set = world.indexer.getEnemy(team, BlockFlag.target);
|
//add all targets to the frontier
|
||||||
for(Tile other : set){
|
for(Tile other : world.indexer.getEnemy(team, BlockFlag.target)){
|
||||||
path.weights[other.x][other.y] = 0;
|
path.weights[other.x][other.y] = 0;
|
||||||
path.searches[other.x][other.y] = path.search;
|
path.searches[other.x][other.y] = path.search;
|
||||||
path.frontier.addFirst(other);
|
path.frontier.addFirst(other);
|
||||||
|
|||||||
@@ -398,6 +398,11 @@ public class NetClient extends Module{
|
|||||||
Net.disconnect();
|
Net.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**When set, any disconnects will be ignored and no dialogs will be shown.*/
|
||||||
|
public void setQuiet(){
|
||||||
|
quiet = true;
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void addRemovedEntity(int id){
|
public synchronized void addRemovedEntity(int id){
|
||||||
removed.add(id);
|
removed.add(id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -418,6 +418,7 @@ public class NetServer extends Module{
|
|||||||
@Remote(called = Loc.both)
|
@Remote(called = Loc.both)
|
||||||
public static void onGameOver(Team winner){
|
public static void onGameOver(Team winner){
|
||||||
threads.runGraphics(() -> ui.restart.show(winner));
|
threads.runGraphics(() -> ui.restart.show(winner));
|
||||||
|
netClient.setQuiet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isWaitingForPlayers(){
|
public boolean isWaitingForPlayers(){
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ public class EventType{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**Called when block building begins. The tile's block will nearly always be a BuildBlock.*/
|
||||||
public static class BlockBuildEvent implements Event{
|
public static class BlockBuildEvent implements Event{
|
||||||
public final Tile tile;
|
public final Tile tile;
|
||||||
public final Team team;
|
public final Team team;
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class CustomGameDialog extends FloatingDialog{
|
|||||||
if(mode.hidden) continue;
|
if(mode.hidden) continue;
|
||||||
|
|
||||||
modes.addButton("$mode." + mode.name() + ".name", "toggle", () -> state.mode = mode)
|
modes.addButton("$mode." + mode.name() + ".name", "toggle", () -> state.mode = mode)
|
||||||
.update(b -> b.setChecked(state.mode == mode)).group(group).size(125f, 54f).padBottom(-5);
|
.update(b -> b.setChecked(state.mode == mode)).group(group).size(140f, 54f).padBottom(-5);
|
||||||
if(i++ % 2 == 1) modes.row();
|
if(i++ % 2 == 1) modes.row();
|
||||||
}
|
}
|
||||||
selmode.add(modes);
|
selmode.add(modes);
|
||||||
@@ -73,9 +73,8 @@ public class CustomGameDialog extends FloatingDialog{
|
|||||||
state.difficulty = (ds[Mathf.mod(state.difficulty.ordinal() - 1, ds.length)]);
|
state.difficulty = (ds[Mathf.mod(state.difficulty.ordinal() - 1, ds.length)]);
|
||||||
}).width(s);
|
}).width(s);
|
||||||
|
|
||||||
sdif.addButton("", () -> {
|
sdif.addButton("", () -> {})
|
||||||
|
.update(t -> {
|
||||||
}).update(t -> {
|
|
||||||
t.setText(state.difficulty.toString());
|
t.setText(state.difficulty.toString());
|
||||||
t.setTouchable(Touchable.disabled);
|
t.setTouchable(Touchable.disabled);
|
||||||
}).width(180f);
|
}).width(180f);
|
||||||
|
|||||||
Reference in New Issue
Block a user