Correct quell AI

This commit is contained in:
Anuken
2022-01-29 13:44:38 -05:00
parent 77dc453e75
commit fdfc43ce72
6 changed files with 78 additions and 7 deletions

View File

@@ -0,0 +1,62 @@
package mindustry.ai.types;
import arc.math.*;
import arc.util.*;
import mindustry.*;
import mindustry.entities.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
/** AI/wave team only! This is used for wave support flyers. */
public class FlyingFollowAI extends FlyingAI{
public Teamc following;
@Override
public void updateMovement(){
unloadPayloads();
if(following != null){
moveTo(following, (following instanceof Sized s ? s.hitSize()/2f * 1.1f : 0f) + unit.hitSize/2f + 15f, 50f);
}else if(target != null && unit.hasWeapons()){
moveTo(target, 80f);
}
if(shouldFaceTarget()){
unit.lookAt(target);
Log.info("lookAt target = @", target);
}else if(following != null){
unit.lookAt(following);
}
if(timer.get(timerTarget3, 30f)){
following = Units.closest(unit.team, unit.x, unit.y, Math.max(unit.type.range, 400f), u -> !u.dead() && u.type != unit.type, (u, tx, ty) -> -u.maxHealth + Mathf.dst2(u.x, u.y, tx, ty) / 6400f);
}
}
public boolean shouldFaceTarget(){
return target != null && (following == null || unit.within(target, unit.range()));
}
@Override
public void updateVisuals(){
if(unit.isFlying()){
unit.wobble();
if(!shouldFaceTarget()){
unit.lookAt(unit.prefRotation());
}
}
}
@Override
public AIController fallback(){
return new FlyingAI();
}
@Override
public boolean useFallback(){
//only AI teams use this controller
return Vars.state.rules.pvp || Vars.state.rules.waveTeam != unit.team;
}
}

View File

@@ -2603,6 +2603,7 @@ public class UnitTypes{
//region erekir - flying
quell = new UnitType("quell"){{
defaultController = FlyingFollowAI::new;
envDisabled = 0;
outlineColor = Pal.darkOutline;
@@ -2639,6 +2640,8 @@ public class UnitTypes{
shootEffect = Fx.shootBig;
smokeEffect = Fx.shootBigSmoke2;
shake = 1f;
speed = 0f;
keepVelocity = false;
}};
unitSpawned = new MissileUnitType("quell-missile"){{

View File

@@ -125,6 +125,7 @@ public class AIController implements UnitController{
for(var mount : unit.mounts){
Weapon weapon = mount.weapon;
float wrange = weapon.range();
//let uncontrollable weapons do their own thing
if(!weapon.controllable) continue;
@@ -136,10 +137,10 @@ public class AIController implements UnitController{
mount.target = target;
}else{
if(ret){
mount.target = findTarget(mountX, mountY, weapon.bullet.range(), weapon.bullet.collidesAir, weapon.bullet.collidesGround);
mount.target = findTarget(mountX, mountY, wrange, weapon.bullet.collidesAir, weapon.bullet.collidesGround);
}
if(checkTarget(mount.target, mountX, mountY, weapon.bullet.range())){
if(checkTarget(mount.target, mountX, mountY, wrange)){
mount.target = null;
}
}
@@ -147,7 +148,7 @@ public class AIController implements UnitController{
boolean shoot = false;
if(mount.target != null){
shoot = mount.target.within(mountX, mountY, weapon.bullet.range() + (mount.target instanceof Sized s ? s.hitSize()/2f : 0f)) && shouldShoot();
shoot = mount.target.within(mountX, mountY, wrange + (mount.target instanceof Sized s ? s.hitSize()/2f : 0f)) && shouldShoot();
Vec2 to = Predict.intercept(unit, mount.target, weapon.bullet.speed);
mount.aimX = to.x;

View File

@@ -17,7 +17,6 @@ import mindustry.world.meta.*;
import static mindustry.Vars.*;
public class ErekirPlanetGenerator extends PlanetGenerator{
//public float scl = 2f;
public float heightScl = 0.9f, octaves = 8, persistence = 0.7f, heightPow = 3f, heightMult = 1.6f;
//TODO inline/remove
@@ -407,6 +406,8 @@ public class ErekirPlanetGenerator extends PlanetGenerator{
//it is very hot
state.rules.attributes.set(Attribute.heat, 0.8f);
state.rules.environment = sector.planet.defaultEnv;
//TODO remove slag and arkycite around core.
Schematics.placeLaunchLoadout(spawnX, spawnY);
//all sectors are wave sectors

View File

@@ -417,8 +417,8 @@ public class UnitType extends UnlockableContent{
if(range < 0){
range = Float.MAX_VALUE;
for(Weapon weapon : weapons){
range = Math.min(range, weapon.bullet.range() - margin);
maxRange = Math.max(maxRange, weapon.bullet.range() - margin);
range = Math.min(range, weapon.range() - margin);
maxRange = Math.max(maxRange, weapon.range() - margin);
}
}
@@ -426,7 +426,7 @@ public class UnitType extends UnlockableContent{
maxRange = Math.max(0f, range);
for(Weapon weapon : weapons){
maxRange = Math.max(maxRange, weapon.bullet.range() - margin);
maxRange = Math.max(maxRange, weapon.range() - margin);
}
}

View File

@@ -216,6 +216,10 @@ public class Weapon implements Cloneable{
Draw.z(z);
}
public float range(){
return unitSpawned != null ? unitSpawned.lifetime * unitSpawned.speed : bullet.range();
}
public void update(Unit unit, WeaponMount mount){
boolean can = unit.canShoot();
float lastReload = mount.reload;