Merge branch 'master' of https://github.com/Anuken/Mindustry into new-pathfinding

This commit is contained in:
Anuken
2024-04-15 13:08:48 -04:00
235 changed files with 10974 additions and 3792 deletions

View File

@@ -12,14 +12,12 @@ import mindustry.async.*;
import mindustry.content.*;
import mindustry.core.*;
import mindustry.gen.*;
import mindustry.world.blocks.environment.*;
public class UnitGroup{
public Seq<Unit> units = new Seq<>();
public int collisionLayer;
public volatile float[] positions, originalPositions;
public volatile boolean valid;
public float minSpeed = 999999f;
public void calculateFormation(Vec2 dest, int collisionLayer){
this.collisionLayer = collisionLayer;
@@ -33,20 +31,15 @@ public class UnitGroup{
cy /= units.size;
positions = new float[units.size * 2];
//all positions are relative to the center
for(int i = 0; i < units.size; i ++){
Unit unit = units.get(i);
positions[i * 2] = unit.x - cx;
positions[i * 2 + 1] = unit.y - cy;
unit.command().groupIndex = i;
//don't factor in the floor speed multiplier
Floor on = unit.isFlying() ? Blocks.air.asFloor() : unit.floorOn();
minSpeed = Math.min(unit.speed() / on.speedMultiplier, minSpeed);
}
if(Float.isInfinite(minSpeed) || Float.isNaN(minSpeed)) minSpeed = 999999f;
//run on new thread to prevent stutter
Vars.mainExecutor.submit(() -> {
//unused space between circles that needs to be reached for compression to end

View File

@@ -30,6 +30,8 @@ public class CommandAI extends AIController{
public int groupIndex = 0;
/** All encountered unreachable buildings of this AI. Why a sequence? Because contains() is very rarely called on it. */
public IntSeq unreachableBuildings = new IntSeq(8);
/** ID of unit read as target. This is set up after reading. Do not access! */
public int readAttackTarget = -1;
protected boolean stopAtTarget, stopWhenInRange;
protected Vec2 lastTargetPos;
@@ -214,7 +216,7 @@ public class CommandAI extends AIController{
}
//TODO: should the unit stop when it finds a target?
if(stance == UnitStance.patrol && target != null && unit.within(target, unit.type.range - 2f)){
if(stance == UnitStance.patrol && target != null && unit.within(target, unit.type.range - 2f) && !unit.type.circleTarget){
move = false;
}
@@ -285,7 +287,7 @@ public class CommandAI extends AIController{
attackTarget = null;
}
if(unit.isFlying() && move){
if(unit.isFlying() && move && (attackTarget == null || !unit.within(attackTarget, unit.type.range))){
unit.lookAt(vecMovePos);
}else{
faceTarget();
@@ -351,8 +353,11 @@ public class CommandAI extends AIController{
}
@Override
public float prefSpeed(){
return group == null ? super.prefSpeed() : Math.min(group.minSpeed, unit.speed());
public void afterRead(Unit unit){
if(readAttackTarget != -1){
attackTarget = Groups.unit.getByID(readAttackTarget);
readAttackTarget = -1;
}
}
@Override

View File

@@ -2,6 +2,8 @@ package mindustry.ai.types;
import arc.math.*;
import arc.util.*;
import mindustry.*;
import mindustry.entities.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
@@ -29,6 +31,11 @@ public class MissileAI extends AIController{
}
}
@Override
public Teamc target(float x, float y, float range, boolean air, boolean ground){
return Units.closestTarget(unit.team, x, y, range, u -> u.checkTarget(air, ground), t -> ground && (!t.block.underBullets || (shooter != null && t == Vars.world.buildWorld(shooter.aimX, shooter.aimY))));
}
@Override
public boolean retarget(){
//more frequent retarget due to high speed. TODO won't this lag?