From b81145990c2232dde3c4d90da54da06baaf028e5 Mon Sep 17 00:00:00 2001 From: Ilya246 <57039557+Ilya246@users.noreply.github.com> Date: Sat, 27 Mar 2021 17:49:04 +0400 Subject: [PATCH] Add files via upload --- src/crawler_arena/ReinforcementAI.java | 67 ++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/crawler_arena/ReinforcementAI.java diff --git a/src/crawler_arena/ReinforcementAI.java b/src/crawler_arena/ReinforcementAI.java new file mode 100644 index 0000000..d87a16d --- /dev/null +++ b/src/crawler_arena/ReinforcementAI.java @@ -0,0 +1,67 @@ +package ReinforcementAI; + +import arc.math.geom.*; +import mindustry.*; +import mindustry.ai.*; +import mindustry.entities.*; +import mindustry.entities.units.*; +import mindustry.gen.*; +import mindustry.world.*; +import mindustry.world.blocks.distribution.*; +import mindustry.world.blocks.liquid.*; +import mindustry.world.meta.*; +import mindustry.ai.types.*; +import mindustry.ai.Pathfinder; +import arc.*; +import arc.func.*; +import arc.struct.*; +import arc.util.*; +import arc.util.async.*; +import arc.math.Mathf; +import mindustry.content.*; +import mindustry.core.*; +import mindustry.game.*; +import mindustry.world.meta.*; + +import static mindustry.Vars.*; + +public class ReinforcementAI extends GroundAI{ + static boolean blockedByBlock; + + @Override + public void updateUnit(){ + + if(Units.invalidateTarget(target, unit.team, unit.x, unit.y, Float.MAX_VALUE)){ + target = null; + } + + if(retarget()){ + target = target(unit.x, unit.y, unit.range(), unit.type.targetAir, unit.type.targetGround); + } + + Building core = unit.closestEnemyCore(); + + boolean rotate = false, shoot = false, moveToTarget = false; + + if(!Units.invalidateTarget(target, unit, unit.range()) && unit.hasWeapons()){ + rotate = true; + shoot = unit.within(target, unit.type.weapons.first().bullet.range() + + (target instanceof Building ? 1.5f * Vars.tilesize / 2f : ((Hitboxc)target).hitSize() / 2f)); + + if(unit.type.hasWeapons()){ + unit.aimLook(Predict.intercept(unit, target, unit.type.weapons.first().bullet.speed)); + }; + }; + if(Math.abs(unit.x - world.width() * 4) > 120){ + unit.moveAt(new Vec2().trns(Mathf.atan2(world.width() * 4 - unit.x, world.height() * 4 - unit.y), unit.speed())); + }; + if(unit.moving()) unit.lookAt(unit.vel().angle()); + unit.controlWeapons(rotate, shoot); + } + + @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 instanceof Conveyor || t.block instanceof Conduit)); //do not target conveyors/conduits + } +}