Fixed some AI quirks, re-added debug blocks, fixed cultivator

This commit is contained in:
Anuken
2018-06-23 15:11:13 -04:00
parent 8f2aae6065
commit 0267ad574f
11 changed files with 86 additions and 22 deletions
@@ -464,9 +464,10 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
if(ui.chatfrag.chatOpen()) return;
float speed = isBoosting ? mech.boostSpeed : mech.speed;
float carrySlowdown = 0.3f;
//fraction of speed when at max load
float carrySlowdown = 0.7f;
speed *= ((1f-carrySlowdown) + (inventory.hasItem() ? (float)inventory.getItem().amount/inventory.capacity(): 1f) * carrySlowdown);
speed *= ((inventory.hasItem() ? Mathf.lerp(1f, carrySlowdown, (float)inventory.getItem().amount/inventory.capacity()) : 1f));
if(mech.flying){
//prevent strafing backwards, have a penalty for doing so
@@ -1,8 +1,11 @@
package io.anuke.mindustry.entities.units;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ObjectSet;
import io.anuke.annotations.Annotations.Loc;
import io.anuke.annotations.Annotations.Remote;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.content.fx.ExplosionFx;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.entities.Unit;
@@ -11,6 +14,7 @@ import io.anuke.mindustry.entities.bullet.Bullet;
import io.anuke.mindustry.entities.effect.ScorchDecal;
import io.anuke.mindustry.entities.traits.TargetTrait;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.game.TeamInfo.TeamData;
import io.anuke.mindustry.gen.CallEntity;
import io.anuke.mindustry.net.In;
import io.anuke.mindustry.net.Net;
@@ -39,6 +43,8 @@ public abstract class BaseUnit extends Unit{
protected static final int timerTarget = timerIndex++;
protected static final int timerReload = timerIndex++;
protected static final Array<Tile> nearbyCores = new Array<>();
protected UnitType type;
protected Timer timer = new Timer(5);
protected StateMachine state = new StateMachine();
@@ -94,7 +100,7 @@ public abstract class BaseUnit extends Unit{
}
public void updateTargeting(){
if(target == null || (target instanceof Unit && (target.isDead() || ((Unit)target).getTeam() == team))
if(target == null || (target instanceof Unit && (target.isDead() || target.getTeam() == team))
|| (target instanceof TileEntity && ((TileEntity) target).tile.entity == null)){
target = null;
}
@@ -124,6 +130,20 @@ public abstract class BaseUnit extends Unit{
target = Units.getClosestTarget(team, x, y, inventory.getAmmoRange());
}
public TileEntity getClosestEnemyCore(){
if(Vars.state.teams.has(team)){
ObjectSet<TeamData> datas = Vars.state.teams.enemyDataOf(team);
for(TeamData data : datas){
Tile tile = Geometry.findClosest(x, y, data.cores);
if(tile != null){
return tile.entity;
}
}
}
return null;
}
public UnitState getStartState(){
return null;
}
@@ -1,5 +1,7 @@
package io.anuke.mindustry.entities.units;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.entities.Predict;
import io.anuke.mindustry.entities.Units;
import io.anuke.mindustry.entities.traits.CarriableTrait;
import io.anuke.mindustry.entities.traits.CarryTrait;
@@ -12,7 +14,10 @@ import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.meta.BlockFlag;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.*;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Translator;
import static io.anuke.mindustry.Vars.world;
@@ -237,7 +242,9 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
AmmoType ammo = inventory.getAmmo();
inventory.useAmmo();
shoot(ammo, Angles.moveToward(rotation, angleTo(target), maxAim));
Vector2 to = Predict.intercept(FlyingUnit.this, target, ammo.bullet.speed);
shoot(ammo, Angles.moveToward(rotation, angleTo(to.x, to.y), maxAim));
}
}
}
@@ -1,7 +1,10 @@
package io.anuke.mindustry.entities.units;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.Predict;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.entities.Units;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.type.AmmoType;
@@ -10,7 +13,10 @@ import io.anuke.mindustry.world.blocks.Floor;
import io.anuke.mindustry.world.meta.BlockFlag;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.*;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Translator;
import static io.anuke.mindustry.Vars.world;
@@ -53,7 +59,7 @@ public abstract class GroundUnit extends BaseUnit {
public void update() {
super.update();
if(!velocity.isZero(0.001f) && (target == null || (inventory.hasAmmo() && distanceTo(target) <= inventory.getAmmoRange()))){
if(!velocity.isZero(0.001f) && (target == null || !inventory.hasAmmo() || (inventory.hasAmmo() && distanceTo(target) > inventory.getAmmoRange()))){
rotation = Mathf.slerpDelta(rotation, velocity.angle(), 0.2f);
}
}
@@ -161,14 +167,27 @@ public abstract class GroundUnit extends BaseUnit {
}
public void update() {
retarget(() -> targetClosest());
TileEntity core = getClosestEnemyCore();
float dst = core == null ? 0 :distanceTo(core);
if(core != null && dst < inventory.getAmmo().getRange()){
target = core;
}else {
retarget(() -> targetClosest());
}
if(!inventory.hasAmmo()) {
state.set(resupply);
}else if(target != null){
if(distanceTo(target) > inventory.getAmmo().getRange() * 0.7f){
moveToCore();
if(core != null){
if(dst > inventory.getAmmo().getRange() * 0.7f){
moveToCore();
}
rotate(angleTo(target));
}else{
moveToCore();
rotate(angleTo(target));
}
@@ -178,7 +197,9 @@ public abstract class GroundUnit extends BaseUnit {
inventory.useAmmo();
rotate(angleTo(target));
shoot(ammo, Angles.moveToward(rotation, angleTo(target), maxAim));
Vector2 to = Predict.intercept(GroundUnit.this, target, ammo.bullet.speed);
shoot(ammo, Angles.moveToward(rotation, angleTo(to.x, to.y), maxAim));
}
}else{
moveToCore();