mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-03-10 04:40:10 +07:00
New flying unit targeting system
This commit is contained in:
parent
373d004752
commit
f77c32cbb2
@ -33,16 +33,24 @@ public class FlyingAI extends AIController{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Teamc findTarget(float x, float y, float range, boolean air, boolean ground){
|
protected Teamc findTarget(float x, float y, float range, boolean air, boolean ground){
|
||||||
Teamc result = target(x, y, range, air, ground);
|
var result = findMainTarget(x, y, range, air, ground);
|
||||||
if(result != null) return result;
|
|
||||||
|
|
||||||
if(ground) result = targetFlag(x, y, BlockFlag.generator, true);
|
//if the main target is in range, use it, otherwise target whatever is closest
|
||||||
if(result != null) return result;
|
return checkTarget(result, x, y, range) ? target(x, y, range, air, ground) : result;
|
||||||
|
}
|
||||||
|
|
||||||
if(ground) result = targetFlag(x, y, BlockFlag.core, true);
|
@Override
|
||||||
if(result != null) return result;
|
protected Teamc findMainTarget(float x, float y, float range, boolean air, boolean ground){
|
||||||
|
for(var flag : unit.team.isAI() ? unit.type.targetFlags : unit.type.playerTargetFlags){
|
||||||
return null;
|
if(flag == null){
|
||||||
|
Teamc result = target(x, y, range, air, ground);
|
||||||
|
if(result != null) return result;
|
||||||
|
}else if(ground){
|
||||||
|
Teamc result = targetFlag(x, y, flag, true);
|
||||||
|
if(result != null) return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return targetFlag(x, y, BlockFlag.core, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void attack(float circleLength){
|
protected void attack(float circleLength){
|
||||||
|
@ -928,6 +928,7 @@ public class UnitTypes implements ContentList{
|
|||||||
engineOffset = 5.5f;
|
engineOffset = 5.5f;
|
||||||
range = 140f;
|
range = 140f;
|
||||||
targetAir = false;
|
targetAir = false;
|
||||||
|
targetFlags = new BlockFlag[]{BlockFlag.generator, null};
|
||||||
commandLimit = 4;
|
commandLimit = 4;
|
||||||
circleTarget = true;
|
circleTarget = true;
|
||||||
hitSize = 7;
|
hitSize = 7;
|
||||||
@ -961,7 +962,7 @@ public class UnitTypes implements ContentList{
|
|||||||
range = 140f;
|
range = 140f;
|
||||||
faceTarget = false;
|
faceTarget = false;
|
||||||
armor = 3f;
|
armor = 3f;
|
||||||
targetFlag = BlockFlag.factory;
|
targetFlags = new BlockFlag[]{BlockFlag.factory, null};
|
||||||
commandLimit = 5;
|
commandLimit = 5;
|
||||||
circleTarget = true;
|
circleTarget = true;
|
||||||
|
|
||||||
@ -999,6 +1000,7 @@ public class UnitTypes implements ContentList{
|
|||||||
lowAltitude = true;
|
lowAltitude = true;
|
||||||
armor = 5f;
|
armor = 5f;
|
||||||
|
|
||||||
|
targetFlags = new BlockFlag[]{BlockFlag.launchPad, BlockFlag.storage, BlockFlag.battery, null};
|
||||||
engineOffset = 12f;
|
engineOffset = 12f;
|
||||||
engineSize = 3f;
|
engineSize = 3f;
|
||||||
|
|
||||||
@ -1045,7 +1047,7 @@ public class UnitTypes implements ContentList{
|
|||||||
engineOffset = 21;
|
engineOffset = 21;
|
||||||
engineSize = 5.3f;
|
engineSize = 5.3f;
|
||||||
hitSize = 46f;
|
hitSize = 46f;
|
||||||
targetFlag = BlockFlag.battery;
|
targetFlags = new BlockFlag[]{BlockFlag.generator, BlockFlag.core, null};
|
||||||
|
|
||||||
BulletType missiles = new MissileBulletType(2.7f, 14){{
|
BulletType missiles = new MissileBulletType(2.7f, 14){{
|
||||||
width = 8f;
|
width = 8f;
|
||||||
@ -1120,7 +1122,7 @@ public class UnitTypes implements ContentList{
|
|||||||
hitSize = 58f;
|
hitSize = 58f;
|
||||||
destructibleWreck = false;
|
destructibleWreck = false;
|
||||||
armor = 13f;
|
armor = 13f;
|
||||||
targetFlag = BlockFlag.reactor;
|
targetFlags = new BlockFlag[]{BlockFlag.reactor, BlockFlag.core, null};
|
||||||
|
|
||||||
BulletType fragBullet = new FlakBulletType(4f, 5){{
|
BulletType fragBullet = new FlakBulletType(4f, 5){{
|
||||||
shootEffect = Fx.shootBig;
|
shootEffect = Fx.shootBig;
|
||||||
@ -1333,7 +1335,7 @@ public class UnitTypes implements ContentList{
|
|||||||
buildBeamOffset = 23;
|
buildBeamOffset = 23;
|
||||||
range = 140f;
|
range = 140f;
|
||||||
targetAir = false;
|
targetAir = false;
|
||||||
targetFlag = BlockFlag.battery;
|
targetFlags = new BlockFlag[]{BlockFlag.battery, BlockFlag.factory, null};
|
||||||
|
|
||||||
ammoType = AmmoTypes.powerHigh;
|
ammoType = AmmoTypes.powerHigh;
|
||||||
|
|
||||||
|
@ -79,7 +79,6 @@ public class AIController implements UnitController{
|
|||||||
return Units.invalidateTarget(target, unit.team, unit.x, unit.y);
|
return Units.invalidateTarget(target, unit.team, unit.x, unit.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void pathfind(int pathTarget){
|
protected void pathfind(int pathTarget){
|
||||||
int costType = unit.pathType();
|
int costType = unit.pathType();
|
||||||
|
|
||||||
@ -97,7 +96,7 @@ public class AIController implements UnitController{
|
|||||||
boolean ret = retarget();
|
boolean ret = retarget();
|
||||||
|
|
||||||
if(ret){
|
if(ret){
|
||||||
target = findTarget(unit.x, unit.y, unit.range(), unit.type.targetAir, unit.type.targetGround);
|
target = findMainTarget(unit.x, unit.y, unit.range(), unit.type.targetAir, unit.type.targetGround);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(invalid(target)){
|
if(invalid(target)){
|
||||||
@ -167,6 +166,10 @@ public class AIController implements UnitController{
|
|||||||
return timer.get(timerTarget, target == null ? 40 : 90);
|
return timer.get(timerTarget, target == null ? 40 : 90);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Teamc findMainTarget(float x, float y, float range, boolean air, boolean ground){
|
||||||
|
return findTarget(x, y, range, air, ground);
|
||||||
|
}
|
||||||
|
|
||||||
protected Teamc findTarget(float x, float y, float range, boolean air, boolean ground){
|
protected Teamc findTarget(float x, float y, float range, boolean air, boolean ground){
|
||||||
return target(x, y, range, air, ground);
|
return target(x, y, range, air, ground);
|
||||||
}
|
}
|
||||||
|
@ -96,6 +96,11 @@ public class Team implements Comparable<Team>{
|
|||||||
return state.teams.isActive(this);
|
return state.teams.isActive(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return whether this team is solely comprised of AI, with no players. */
|
||||||
|
public boolean isAI(){
|
||||||
|
return state.rules.waves && this == state.rules.waveTeam;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isEnemy(Team other){
|
public boolean isEnemy(Team other){
|
||||||
return this != other;
|
return this != other;
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,10 @@ public class UnitType extends UnlockableContent{
|
|||||||
public Effect fallThrusterEffect = Fx.fallSmoke;
|
public Effect fallThrusterEffect = Fx.fallSmoke;
|
||||||
public Effect deathExplosionEffect = Fx.dynamicExplosion;
|
public Effect deathExplosionEffect = Fx.dynamicExplosion;
|
||||||
public Seq<Ability> abilities = new Seq<>();
|
public Seq<Ability> abilities = new Seq<>();
|
||||||
public BlockFlag targetFlag = BlockFlag.generator;
|
/** Flags to target based on priority. Null indicates that the closest target should be found. The closest enemy core is used as a fallback. */
|
||||||
|
public BlockFlag[] targetFlags = {null};
|
||||||
|
/** targetFlags, as an override for "non-AI" teams. By default, units of this type will rush the core. */
|
||||||
|
public BlockFlag[] playerTargetFlags = {BlockFlag.core, null};
|
||||||
|
|
||||||
public Color outlineColor = Pal.darkerMetal;
|
public Color outlineColor = Pal.darkerMetal;
|
||||||
public int outlineRadius = 3;
|
public int outlineRadius = 3;
|
||||||
|
Loading…
Reference in New Issue
Block a user