From 1327a2bef4b61bab7f46bfee1bca37ab4fd6b625 Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 15 Sep 2020 10:39:45 -0400 Subject: [PATCH] Mega repair AI --- core/src/mindustry/Vars.java | 3 +- core/src/mindustry/ai/types/FlyingAI.java | 8 ----- core/src/mindustry/ai/types/MinerAI.java | 8 ----- core/src/mindustry/ai/types/RepairAI.java | 32 +++++++++++++++++++ core/src/mindustry/content/UnitTypes.java | 1 + .../entities/units/AIController.java | 13 +++++++- .../world/blocks/logic/LogicBlock.java | 1 - 7 files changed, 46 insertions(+), 20 deletions(-) create mode 100644 core/src/mindustry/ai/types/RepairAI.java diff --git a/core/src/mindustry/Vars.java b/core/src/mindustry/Vars.java index 10403cefb8..34ad2f6daa 100644 --- a/core/src/mindustry/Vars.java +++ b/core/src/mindustry/Vars.java @@ -214,8 +214,7 @@ public class Vars implements Loadable{ if(loadLocales){ //load locales - String[] - stra = Core.files.internal("locales").readString().split("\n"); + String[] stra = Core.files.internal("locales").readString().split("\n"); locales = new Locale[stra.length]; for(int i = 0; i < locales.length; i++){ String code = stra[i]; diff --git a/core/src/mindustry/ai/types/FlyingAI.java b/core/src/mindustry/ai/types/FlyingAI.java index 6f4eae425f..64fb8b44cd 100644 --- a/core/src/mindustry/ai/types/FlyingAI.java +++ b/core/src/mindustry/ai/types/FlyingAI.java @@ -12,14 +12,6 @@ public class FlyingAI extends AIController{ @Override public void updateMovement(){ - if(unit.moving()){ - unit.lookAt(unit.vel.angle()); - } - - if(unit.isFlying()){ - unit.wobble(); - } - if(target != null && unit.hasWeapons() && command() == UnitCommand.attack){ if(unit.type().weapons.first().rotate){ moveTo(target, unit.range() * 0.8f); diff --git a/core/src/mindustry/ai/types/MinerAI.java b/core/src/mindustry/ai/types/MinerAI.java index 120c4d05f8..f635c9e543 100644 --- a/core/src/mindustry/ai/types/MinerAI.java +++ b/core/src/mindustry/ai/types/MinerAI.java @@ -15,14 +15,6 @@ public class MinerAI extends AIController{ @Override protected void updateMovement(){ - if(unit.moving()){ - unit.lookAt(unit.vel.angle()); - } - - if(unit.isFlying()){ - unit.wobble(); - } - Building core = unit.closestCore(); if(!(unit instanceof Minerc) || core == null) return; diff --git a/core/src/mindustry/ai/types/RepairAI.java b/core/src/mindustry/ai/types/RepairAI.java new file mode 100644 index 0000000000..a90eba3e56 --- /dev/null +++ b/core/src/mindustry/ai/types/RepairAI.java @@ -0,0 +1,32 @@ +package mindustry.ai.types; + +import mindustry.entities.*; +import mindustry.entities.units.*; +import mindustry.world.blocks.ConstructBlock.*; + +//note that repair AI doesn't attack anything even if it theoretically can +public class RepairAI extends AIController{ + + @Override + protected void updateMovement(){ + boolean shoot = false; + + if(target != null){ + if(!target.within(unit, unit.type().range)){ + moveTo(target, unit.type().range * 0.9f); + }else{ + unit.aim(target); + shoot = true; + } + } + + unit.controlWeapons(shoot); + } + + @Override + protected void updateTargeting(){ + target = Units.findDamagedTile(unit.team, unit.x, unit.y); + + if(target instanceof ConstructBuild) target = null; + } +} diff --git a/core/src/mindustry/content/UnitTypes.java b/core/src/mindustry/content/UnitTypes.java index 7622e31b35..1a570948bc 100644 --- a/core/src/mindustry/content/UnitTypes.java +++ b/core/src/mindustry/content/UnitTypes.java @@ -1029,6 +1029,7 @@ public class UnitTypes implements ContentList{ }}; mega = new UnitType("mega"){{ + defaultController = RepairAI::new; mineTier = 2; health = 500; diff --git a/core/src/mindustry/entities/units/AIController.java b/core/src/mindustry/entities/units/AIController.java index 98f20b45f7..9bca34d271 100644 --- a/core/src/mindustry/entities/units/AIController.java +++ b/core/src/mindustry/entities/units/AIController.java @@ -33,6 +33,7 @@ public class AIController implements UnitController{ @Override public void updateUnit(){ + updateVisuals(); updateTargeting(); updateMovement(); } @@ -41,13 +42,23 @@ public class AIController implements UnitController{ return unit.team.data().command; } + protected void updateVisuals(){ + + if(unit.isFlying()){ + unit.wobble(); + + if(unit.moving()){ + unit.lookAt(unit.vel.angle()); + } + } + } + protected void updateMovement(){ } protected void updateTargeting(){ if(unit.hasWeapons()){ - updateWeapons(); } } diff --git a/core/src/mindustry/world/blocks/logic/LogicBlock.java b/core/src/mindustry/world/blocks/logic/LogicBlock.java index e79a0ad6ce..24dcaa4b7e 100644 --- a/core/src/mindustry/world/blocks/logic/LogicBlock.java +++ b/core/src/mindustry/world/blocks/logic/LogicBlock.java @@ -34,7 +34,6 @@ public class LogicBlock extends Block{ update = true; solid = true; configurable = true; - sync = true; config(byte[].class, (LogicBuild build, byte[] data) -> build.readCompressed(data, true));