Added basic ground AI
This commit is contained in:
@@ -36,10 +36,6 @@ abstract class FlyingComp implements Posc, Velc, Healthc, Hitboxc{
|
||||
y += Mathf.cos(Time.time() + id() * 99, 25f, 0.05f) * Time.delta() * elevation;
|
||||
}
|
||||
|
||||
void moveAt(Vec2 vector){
|
||||
moveAt(vector, 1f);
|
||||
}
|
||||
|
||||
void moveAt(Vec2 vector, float acceleration){
|
||||
Vec2 t = Tmp.v3.set(vector).scl(floorSpeedMultiplier()); //target vector
|
||||
Tmp.v1.set(t).sub(vel).limit(acceleration * vector.len()); //delta vector
|
||||
|
||||
@@ -13,8 +13,11 @@ abstract class TeamComp implements Posc{
|
||||
|
||||
Team team = Team.derelict;
|
||||
|
||||
public @Nullable
|
||||
Tilec closestCore(){
|
||||
public @Nullable Tilec closestCore(){
|
||||
return state.teams.closestCore(x, y, team);
|
||||
}
|
||||
|
||||
public @Nullable Tilec closestEnemyCore(){
|
||||
return state.teams.closestEnemyCore(x, y, team);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,15 @@ abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitbox
|
||||
private UnitController controller;
|
||||
private UnitType type;
|
||||
|
||||
public void moveAt(Vec2 vector){
|
||||
moveAt(vector, type.accel);
|
||||
}
|
||||
|
||||
public void aimLook(Position pos){
|
||||
aim(pos);
|
||||
lookAt(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float clipSize(){
|
||||
return type.region.getWidth() * 2f;
|
||||
|
||||
@@ -21,11 +21,14 @@ abstract class WeaponsComp implements Teamc, Posc, Rotc{
|
||||
|
||||
/** weapon mount array, never null */
|
||||
@ReadOnly WeaponMount[] mounts = {};
|
||||
@ReadOnly float range;
|
||||
|
||||
void setupWeapons(UnitType def){
|
||||
mounts = new WeaponMount[def.weapons.size];
|
||||
range = 0f;
|
||||
for(int i = 0; i < mounts.length; i++){
|
||||
mounts[i] = new WeaponMount(def.weapons.get(i));
|
||||
range = Math.max(range, def.weapons.get(i).bullet.range());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,43 @@
|
||||
package mindustry.entities.units;
|
||||
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.gen.*;
|
||||
|
||||
public class AIController implements UnitController{
|
||||
protected Unitc unit;
|
||||
protected static final Vec2 vec = new Vec2();
|
||||
protected static final int timerTarget = 0;
|
||||
|
||||
float rot = Mathf.random(360f);
|
||||
protected Unitc unit;
|
||||
protected Teamc target;
|
||||
protected Interval timer = new Interval(4);
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
targeting();
|
||||
behavior();
|
||||
}
|
||||
|
||||
protected boolean retarget(){
|
||||
return timer.get(timerTarget, 20);
|
||||
}
|
||||
|
||||
protected void targetClosest(){
|
||||
Teamc newTarget = Units.closestTarget(unit.team(), unit.x(), unit.y(), Math.max(unit.range(), unit.type().range), u -> unit.type().targetAir || !u.isFlying());
|
||||
if(newTarget != null){
|
||||
target = newTarget;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void targeting(){
|
||||
|
||||
}
|
||||
|
||||
public void behavior(){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unit(Unitc unit){
|
||||
@@ -17,15 +48,4 @@ public class AIController implements UnitController{
|
||||
public Unitc unit(){
|
||||
return unit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
//TODO implement
|
||||
//rot += Mathf.range(3f) * Time.delta();
|
||||
|
||||
//unit.moveAt(Tmp.v1.trns(rot, unit.type().speed));
|
||||
//if(!unit.vel().isZero()){
|
||||
// unit.lookAt(unit.vel().angle());
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user