SteamWar/FightSystem
Archiviert
13
1

Fix rotated side

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2024-01-28 22:37:35 +01:00
Ursprung dcfe141beb
Commit f130af5465
4 geänderte Dateien mit 37 neuen und 40 gelöschten Zeilen

Datei anzeigen

@ -151,12 +151,12 @@ public abstract class AI {
public Material getBlock(Vector pos) {
queue.add(new Action(1));
return translate(pos, true).getBlock().getType();
return translate(pos).getBlock().getType();
}
public BlockData getBlockData(Vector pos) {
queue.add(new Action(1));
return translate(pos, true).getBlock().getBlockData();
return translate(pos).getBlock().getBlockData();
}
public void setTNT(Vector pos) {
@ -166,7 +166,7 @@ public abstract class AI {
if(FightState.getFightState() != FightState.RUNNING)
return;
Location location = translate(pos, true);
Location location = translate(pos);
if(interactionDistanceViolation(location)) {
chat("InteractionDistanceViolation: setTNT");
return;
@ -183,7 +183,7 @@ public abstract class AI {
queue.add(new Action(1) {
@Override
public void run() {
Location location = translate(pos, true);
Location location = translate(pos);
if(interactionDistanceViolation(location)) {
chat("InteractionDistanceViolation: interact");
return;
@ -198,7 +198,7 @@ public abstract class AI {
queue.add(new Action(1) {
@Override
public void run() {
Location location = translate(pos, true);
Location location = translate(pos);
if (interactionDistanceViolation(location))
return;
Block block = location.getBlock();
@ -225,7 +225,7 @@ public abstract class AI {
return;
}
Location target = translate(pos, false);
Location target = translate(pos);
if(Math.abs(location.getX() - target.getX()) > 1.0 || Math.abs(location.getY() - target.getY()) > 1.5 || Math.abs(location.getZ() - target.getZ()) > 1.0) {
FightSystem.getPlugin().getLogger().log(Level.INFO, () -> entity.getName() + ": Overdistance movement " + location.toVector() + " " + target.toVector());
return;
@ -315,7 +315,7 @@ public abstract class AI {
queue.poll().run();
}
public Location translate(Vector pos, boolean blockPos) {
public Location translate(Vector pos) {
Region extend = team.getExtendRegion();
if(Fight.getUnrotated() == team)
return new Location(
@ -327,9 +327,9 @@ public abstract class AI {
else
return new Location(
Config.world,
extend.getMaxX() - pos.getX() - (blockPos ? 1 : 0),
extend.getMaxX() - pos.getX(),
pos.getY() + team.getSchemRegion().getMinY(),
extend.getMaxZ() - pos.getZ() - (blockPos ? 1 : 0)
extend.getMaxZ() - pos.getZ()
);
}

Datei anzeigen

@ -39,6 +39,8 @@ import java.util.function.Supplier;
public class LixfelAI extends AI {
private static final Vector CENTER_BLOCK = new Vector(0.5, 0.5, 0.5);
private final Random random = new Random();
private List<Supplier<PlanResult>> plans = new ArrayList<>();
@ -47,7 +49,8 @@ public class LixfelAI extends AI {
public LixfelAI(FightTeam team) {
super(team, SteamwarUser.get("Lixfel.AI"));
//getEntity().setGlowing(true);
getEntity().setGlowing(true);
//TODO AI Replay
}
@Override
@ -66,15 +69,15 @@ public class LixfelAI extends AI {
plans.add(movementEmergency);
plans.add(new ReadyPlan());
plans.add(new TimedInteraction(200.0, -1, new Vector(25, 15, 25)));
plans.add(new TimedInteraction(210.0, 420, new Vector(21, 15, 24)));
plans.add(new TimedInteraction(200.0, -1, new Vector(25.5, 15.5, 25.5)));
plans.add(new TimedInteraction(210.0, 420, new Vector(21.5, 15.5, 24.5)));
List<Cannon> cannons = new ArrayList<>(Arrays.asList(
new Cannon(new Vector(11,25,11), 10,23,14, 12,23,14, 10,23,12, 12,23,12, 12,24,15, 10,24,14, 12,23,15, 12,24,14, 11,24,12, 10,24,15, 12,24,12, 10,23,15, 10,24,12),
new Cannon(new Vector(39,25,11), 38,24,15, 38,23,12, 40,23,14, 40,24,12, 40,23,15, 40,24,14, 39,24,12, 38,23,14, 40,24,15, 40,23,12, 38,23,15, 38,24,12, 38,24,14),
new Cannon(new Vector(12,18,11), 13,17,15, 13,17,16, 13,18,16, 13,18,14, 14,18,14, 14,17,15, 14,17,16, 14,18,16, 13,17,14, 14,17,14, 13,18,15, 14,18,15),
new Cannon(new Vector(38,18,11), 37,18,14, 36,18,14, 36,17,15, 37,17,15, 37,18,15, 36,18,15, 36,17,14, 37,17,14, 36,17,16, 37,17,16, 36,18,16, 37,18,16),
new Cannon(new Vector(9,9,16), 10,11,17, 10,8,19, 10,8,17, 11,8,19, 11,8,15, 10,8,15, 12,8,15, 10,10,15, 12,7,19, 11,10,15, 12,8,19, 12,7,15, 11,7,15, 10,9,17, 11,9,19, 12,9,19, 10,9,19, 10,7,17, 11,7,19, 10,7,15, 10,7,19, 10,10,17, 12,9,15, 10,9,15, 11,9,15, 12,10,19, 11,10,19, 12,10,15, 10,6,17, 10,10,19),
new Cannon(new Vector(11.5,25.5,11.5), 10,23,14, 12,23,14, 10,23,12, 12,23,12, 12,24,15, 10,24,14, 12,23,15, 12,24,14, 11,24,12, 10,24,15, 12,24,12, 10,23,15, 10,24,12),
new Cannon(new Vector(39.5,25.5,11.5), 38,24,15, 38,23,12, 40,23,14, 40,24,12, 40,23,15, 40,24,14, 39,24,12, 38,23,14, 40,24,15, 40,23,12, 38,23,15, 38,24,12, 38,24,14),
new Cannon(new Vector(12.5,18.5,11.5), 13,17,15, 13,17,16, 13,18,16, 13,18,14, 14,18,14, 14,17,15, 14,17,16, 14,18,16, 13,17,14, 14,17,14, 13,18,15, 14,18,15),
new Cannon(new Vector(38.5,18.5,11.5), 37,18,14, 36,18,14, 36,17,15, 37,17,15, 37,18,15, 36,18,15, 36,17,14, 37,17,14, 36,17,16, 37,17,16, 36,18,16, 37,18,16),
new Cannon(new Vector(9.5,9.5,16.5), 10,11,17, 10,8,19, 10,8,17, 11,8,19, 11,8,15, 10,8,15, 12,8,15, 10,10,15, 12,7,19, 11,10,15, 12,8,19, 12,7,15, 11,7,15, 10,9,17, 11,9,19, 12,9,19, 10,9,19, 10,7,17, 11,7,19, 10,7,15, 10,7,19, 10,10,17, 12,9,15, 10,9,15, 11,9,15, 12,10,19, 11,10,19, 12,10,15, 10,6,17, 10,10,19),
new Cannon(null, 23,5,9, 23,6,9, 23,7,9, 23,8,9),
new Cannon(null, 27,5,9, 27,6,9, 27,7,9, 27,8,9)
));
@ -103,7 +106,7 @@ public class LixfelAI extends AI {
});
for(Vector water : waterSources) {
cannons.stream().filter(cannon -> cannon.getTNTMinY() >= water.getBlockY()).min(Comparator.comparingDouble(c -> c.waterDistance(water))).ifPresent(cannon -> cannon.addWater(water));
cannons.stream().filter(cannon -> cannon.getTNTMinY() >= water.getBlockY()).min(Comparator.comparingDouble(c -> c.waterDistance(water))).ifPresent(cannon -> cannon.addWater(water.add(CENTER_BLOCK)));
}
}
@ -184,7 +187,7 @@ public class LixfelAI extends AI {
this.activator = activator;
for(int i = 0; i < tntpos.length; i+=3) {
tnt.put(new Vector(tntpos[i], tntpos[i+1], tntpos[i+2]), false);
tnt.put(new Vector(tntpos[i], tntpos[i+1], tntpos[i+2]).add(CENTER_BLOCK), false);
}
minY = tnt.keySet().stream().min(Comparator.comparingInt(Vector::getBlockY)).orElse(new Vector()).getBlockY();

Datei anzeigen

@ -38,6 +38,8 @@ import java.util.stream.Collectors;
public class LixfelPathplanner {
private static final double INTERACTION_RANGE = AI.INTERACTION_RANGE - 0.05;
private static double blockHeight(Clipboard clipboard, BlockVector3 vector) {
BlockData data = BukkitAdapter.adapt(clipboard.getFullBlock(vector));
Material material = data.getMaterial();
@ -81,7 +83,7 @@ public class LixfelPathplanner {
private final AI ai;
private final BlockVector3 diff;
private final Set<Vector> ladders = new HashSet<>();
private final Map<Vector, Vector[]> neighbours = new HashMap<>();
private final Map<Vector, List<Vector>> neighbours = new HashMap<>();
public LixfelPathplanner(AI ai, Clipboard clipboard) {
this.ai = ai;
@ -121,7 +123,7 @@ public class LixfelPathplanner {
});
for(Vector vector : walkable) {
neighbours.put(vector, walkable.stream().filter(neighbour -> neighbouring(neighbour, vector)).filter(neighbour -> neighbour != vector).toArray(Vector[]::new));
neighbours.put(vector, walkable.stream().filter(neighbour -> neighbouring(neighbour, vector)).filter(neighbour -> neighbour != vector).collect(Collectors.toList()));
}
}
@ -134,34 +136,27 @@ public class LixfelPathplanner {
}
public void addPosition(Vector vector) {
Vector[] n = neighbours.keySet().stream().filter(neighbour -> neighbouring(neighbour, vector)).toArray(Vector[]::new);
List<Vector> n = neighbours.keySet().stream().filter(neighbour -> neighbouring(neighbour, vector)).collect(Collectors.toList());
neighbours.put(vector, n);
for(Vector neighbour : n) {
neighbours.computeIfPresent(neighbour, (neighBour, array) -> {
array = Arrays.copyOf(array, array.length+1);
array[array.length-1] = vector;
return array;
neighbours.computeIfPresent(neighbour, (neighBour, list) -> {
list.add(vector);
return list;
});
}
}
public void removePosition(Vector vector) {
ladders.remove(vector);
Vector[] n = neighbours.remove(vector);
List<Vector> n = neighbours.remove(vector);
if(n == null)
return;
for(Vector neighbour : n) {
neighbours.computeIfPresent(neighbour, (neighBour, array) -> {
for(int i = 0; i < array.length; i++) {
if(array[i] == vector) {
Vector[] newArray = Arrays.copyOf(array, array.length-1);
System.arraycopy(array, i+1, newArray, i, newArray.length-i);
return newArray;
}
}
throw new IllegalStateException();
neighbours.computeIfPresent(neighbour, (neighBour, list) -> {
list.remove(vector);
return list;
});
}
}
@ -173,11 +168,11 @@ public class LixfelPathplanner {
public PlanResult inRangeAndTime(double rating, int time, Vector target, Supplier<PlanResult> plan) {
Vector position = ai.getPosition();
double eyeHeight = ai.getEntity().getEyeHeight();
boolean inRange = new Vector(0, eyeHeight, 0).add(position).distance(target) <= AI.INTERACTION_RANGE;
boolean inRange = new Vector(0, eyeHeight, 0).add(position).distance(target) <= INTERACTION_RANGE;
if(inRange)
return time <= 0 ? plan.get() : PlanResult.EMPTY;
List<Vector> path = new ArrayList<>(planToRange(position, new Vector(0, -eyeHeight, 0).add(target), 5.0));
List<Vector> path = new ArrayList<>(planToRange(position, new Vector(0, -eyeHeight, 0).add(target), INTERACTION_RANGE));
if(path.isEmpty() || time > path.size()*AI.MOVEMENT_DELAY)
return PlanResult.EMPTY;
@ -211,7 +206,7 @@ public class LixfelPathplanner {
while(!checking.isEmpty()) {
Set<Vector> toCheck = new HashSet<>();
for(Vector current : checking) {
Vector firstStep = Arrays.stream(neighbours.get(current))
Vector firstStep = neighbours.get(current).stream()
.filter(vector -> !approach.containsKey(vector))
.filter(next -> {
approach.put(next, current);

Datei anzeigen

@ -36,7 +36,6 @@ public class KitCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
AI.printPos();
if(!(sender instanceof Player)) {
return false;
}