Partial impl of #2923
This commit is contained in:
@@ -6,10 +6,14 @@ import mindustry.entities.units.*;
|
|||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.world.meta.*;
|
import mindustry.world.meta.*;
|
||||||
|
|
||||||
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
public class DefenderAI extends AIController{
|
public class DefenderAI extends AIController{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateMovement(){
|
public void updateMovement(){
|
||||||
|
unloadPayloads();
|
||||||
|
|
||||||
if(target != null){
|
if(target != null){
|
||||||
moveTo(target, (target instanceof Sized s ? s.hitSize()/2f * 1.1f : 0f) + unit.hitSize/2f + 15f, 50f);
|
moveTo(target, (target instanceof Sized s ? s.hitSize()/2f * 1.1f : 0f) + unit.hitSize/2f + 15f, 50f);
|
||||||
unit.lookAt(target);
|
unit.lookAt(target);
|
||||||
@@ -23,6 +27,7 @@ public class DefenderAI 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){
|
||||||
|
|
||||||
//find unit to follow if not in rally mode
|
//find unit to follow if not in rally mode
|
||||||
if(command() != UnitCommand.rally){
|
if(command() != UnitCommand.rally){
|
||||||
//Sort by max health and closer target.
|
//Sort by max health and closer target.
|
||||||
@@ -34,6 +39,14 @@ public class DefenderAI extends AIController{
|
|||||||
var block = targetFlag(unit.x, unit.y, BlockFlag.rally, false);
|
var block = targetFlag(unit.x, unit.y, BlockFlag.rally, false);
|
||||||
if(block != null) return block;
|
if(block != null) return block;
|
||||||
//return core if found
|
//return core if found
|
||||||
return unit.closestCore();
|
var core = unit.closestCore();
|
||||||
|
if(core != null) return core;
|
||||||
|
|
||||||
|
//for enemies, target the enemy core.
|
||||||
|
if(state.rules.waves && unit.team == state.rules.waveTeam){
|
||||||
|
return unit.closestEnemyCore();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ public class FlyingAI extends AIController{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateMovement(){
|
public void updateMovement(){
|
||||||
|
unloadPayloads();
|
||||||
|
|
||||||
if(target != null && unit.hasWeapons() && command() == UnitCommand.attack){
|
if(target != null && unit.hasWeapons() && command() == UnitCommand.attack){
|
||||||
if(!unit.type.circleTarget){
|
if(!unit.type.circleTarget){
|
||||||
moveTo(target, unit.type.range * 0.8f);
|
moveTo(target, unit.type.range * 0.8f);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import mindustry.entities.*;
|
|||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
import mindustry.world.*;
|
import mindustry.world.*;
|
||||||
|
import mindustry.world.blocks.payloads.*;
|
||||||
import mindustry.world.meta.*;
|
import mindustry.world.meta.*;
|
||||||
|
|
||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
@@ -178,6 +179,14 @@ public class AIController implements UnitController{
|
|||||||
return Geometry.findClosest(unit.x, unit.y, Vars.spawner.getSpawns());
|
return Geometry.findClosest(unit.x, unit.y, Vars.spawner.getSpawns());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void unloadPayloads(){
|
||||||
|
if(unit instanceof Payloadc pay && pay.hasPayload() && target instanceof Building && pay.payloads().peek() instanceof UnitPayload){
|
||||||
|
if(target.within(unit, Math.max(unit.type().range + 1f, 75f))){
|
||||||
|
pay.dropLastPayload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void circle(Position target, float circleLength){
|
protected void circle(Position target, float circleLength){
|
||||||
circle(target, circleLength, unit.speed());
|
circle(target, circleLength, unit.speed());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package mindustry.game;
|
package mindustry.game;
|
||||||
|
|
||||||
|
import arc.struct.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
import arc.util.serialization.*;
|
import arc.util.serialization.*;
|
||||||
import arc.util.serialization.Json.*;
|
import arc.util.serialization.Json.*;
|
||||||
@@ -39,12 +40,12 @@ public class SpawnGroup implements JsonSerializable{
|
|||||||
public float shieldScaling = 0f;
|
public float shieldScaling = 0f;
|
||||||
/** Amount of enemies spawned initially, with no scaling */
|
/** Amount of enemies spawned initially, with no scaling */
|
||||||
public int unitAmount = 1;
|
public int unitAmount = 1;
|
||||||
|
/** Seq of payloads that this unit will spawn with. */
|
||||||
|
public @Nullable Seq<UnitType> payloads;
|
||||||
/** Status effect applied to the spawned unit. Null to disable. */
|
/** Status effect applied to the spawned unit. Null to disable. */
|
||||||
@Nullable
|
public @Nullable StatusEffect effect;
|
||||||
public StatusEffect effect;
|
|
||||||
/** Items this unit spawns with. Null to disable. */
|
/** Items this unit spawns with. Null to disable. */
|
||||||
@Nullable
|
public @Nullable ItemStack items;
|
||||||
public ItemStack items;
|
|
||||||
|
|
||||||
public SpawnGroup(UnitType type){
|
public SpawnGroup(UnitType type){
|
||||||
this.type = type;
|
this.type = type;
|
||||||
@@ -85,6 +86,15 @@ public class SpawnGroup implements JsonSerializable{
|
|||||||
|
|
||||||
unit.shield = getShield(wave);
|
unit.shield = getShield(wave);
|
||||||
|
|
||||||
|
//load up spawn payloads
|
||||||
|
if(payloads != null && unit instanceof Payloadc pay){
|
||||||
|
for(var type : payloads){
|
||||||
|
if(type == null) continue;
|
||||||
|
Unit payload = type.create(unit.team);
|
||||||
|
pay.pickup(payload);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return unit;
|
return unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,6 +111,9 @@ public class SpawnGroup implements JsonSerializable{
|
|||||||
if(shieldScaling != 0) json.writeValue("shieldScaling", shieldScaling);
|
if(shieldScaling != 0) json.writeValue("shieldScaling", shieldScaling);
|
||||||
if(unitAmount != 1) json.writeValue("amount", unitAmount);
|
if(unitAmount != 1) json.writeValue("amount", unitAmount);
|
||||||
if(effect != null) json.writeValue("effect", effect.name);
|
if(effect != null) json.writeValue("effect", effect.name);
|
||||||
|
if(payloads != null && payloads.size > 0){
|
||||||
|
json.writeValue("payloads", payloads.map(u -> u.name).toArray(String.class));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -117,6 +130,9 @@ public class SpawnGroup implements JsonSerializable{
|
|||||||
shields = data.getFloat("shields", 0);
|
shields = data.getFloat("shields", 0);
|
||||||
shieldScaling = data.getFloat("shieldScaling", 0);
|
shieldScaling = data.getFloat("shieldScaling", 0);
|
||||||
unitAmount = data.getInt("amount", 1);
|
unitAmount = data.getInt("amount", 1);
|
||||||
|
if(data.has("payloads")){
|
||||||
|
payloads = Seq.with(json.readValue(String[].class, data.get("payloads"))).map(s -> content.getByName(ContentType.unit, s));
|
||||||
|
}
|
||||||
|
|
||||||
//old boss effect ID
|
//old boss effect ID
|
||||||
if(data.has("effect") && data.get("effect").isNumber() && data.getInt("effect", -1) == 8){
|
if(data.has("effect") && data.get("effect").isNumber() && data.getInt("effect", -1) == 8){
|
||||||
|
|||||||
Reference in New Issue
Block a user