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

View File

@@ -47,8 +47,8 @@ public class Recipes implements ContentList{
//CRAFTING
//smelting
new Recipe(crafting, CraftingBlocks.smelter, new ItemStack(Items.tungsten, 40));
new Recipe(crafting, CraftingBlocks.arcsmelter, new ItemStack(Items.tungsten, 60), new ItemStack(Items.carbide, 60), new ItemStack(Items.lead, 50));
new Recipe(crafting, CraftingBlocks.smelter, new ItemStack(Items.tungsten, 60));
new Recipe(crafting, CraftingBlocks.arcsmelter, new ItemStack(Items.tungsten, 90), new ItemStack(Items.carbide, 60), new ItemStack(Items.lead, 50));
new Recipe(crafting, CraftingBlocks.siliconsmelter, new ItemStack(Items.tungsten, 60), new ItemStack(Items.lead, 50));
//misc
@@ -57,6 +57,7 @@ public class Recipes implements ContentList{
new Recipe(crafting, CraftingBlocks.blastMixer, new ItemStack(Items.tungsten, 60), new ItemStack(Items.lead, 60), new ItemStack(Items.carbide, 40));
//processing
new Recipe(crafting, CraftingBlocks.biomatterCompressor, new ItemStack(Items.lead, 70), new ItemStack(Items.silicon, 60));
new Recipe(crafting, CraftingBlocks.separator, new ItemStack(Items.tungsten, 60), new ItemStack(Items.carbide, 50));
new Recipe(crafting, CraftingBlocks.centrifuge, new ItemStack(Items.tungsten, 130), new ItemStack(Items.carbide, 130), new ItemStack(Items.silicon, 30), new ItemStack(Items.titanium, 40));

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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));
}
}
}

View File

@@ -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();

View File

@@ -179,6 +179,8 @@ public class BlocksFragment implements Fragment{
//add actual recipes
for (Recipe r : recipes) {
if(r.debugOnly && !debug) continue;
ImageButton image = new ImageButton(new TextureRegion(), "select");
TextureRegion[] regions = r.result.getCompactIcon();
@@ -343,11 +345,11 @@ public class BlocksFragment implements Fragment{
}
String format(int number){
if(number > 1000000) {
if(number >= 1000000) {
return Strings.toFixed(number/1000000f, 1) + "[gray]mil[]";
}else if(number > 10000){
}else if(number >= 10000){
return number/1000 + "[gray]k[]";
}else if(number > 1000){
}else if(number >= 1000){
return Strings.toFixed(number/1000f, 1) + "[gray]k[]";
}else{
return number + "";

View File

@@ -17,6 +17,7 @@ import io.anuke.mindustry.world.blocks.BuildBlock;
import io.anuke.mindustry.world.blocks.BuildBlock.BuildEntity;
import io.anuke.ucore.entities.Entities;
import static io.anuke.mindustry.Vars.debug;
import static io.anuke.mindustry.Vars.tilesize;
import static io.anuke.mindustry.Vars.world;
@@ -147,7 +148,7 @@ public class Build {
public static boolean validPlace(Team team, int x, int y, Block type, int rotation) {
Recipe recipe = Recipe.getByResult(type);
if (recipe == null) {
if (recipe == null || (recipe.debugOnly && !debug)) {
return false;
}

View File

@@ -10,7 +10,7 @@ import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.meta.BlockBar;
public class ItemTurret extends CooledTurret {
protected int maxAmmo = 100;
protected int maxAmmo = 50;
protected AmmoType[] ammoTypes;
protected ObjectMap<Item, AmmoType> ammoMap = new ObjectMap<>();

View File

@@ -192,8 +192,8 @@ public class Conveyor extends Block{
}
}
if(entity.minitem <= 0.0001f){
entity.clogHeat = Mathf.lerpDelta(entity.clogHeat, 1f, 0.05f);
if(entity.minitem < itemSpace){
entity.clogHeat = Mathf.lerpDelta(entity.clogHeat, 1f, 0.02f);
}else{
entity.clogHeat = Mathf.lerpDelta(entity.clogHeat, 0f, 1f);
}

View File

@@ -2,6 +2,7 @@ package io.anuke.mindustry.world.blocks.production;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.mindustry.content.Items;
import io.anuke.mindustry.content.blocks.Blocks;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.content.fx.Fx;
@@ -84,6 +85,11 @@ public class Cultivator extends Drill {
return tile.floor() == Blocks.grass;
}
@Override
public Item getDrop(Tile tile) {
return Items.biomatter;
}
public static class CultivatorEntity extends DrillEntity{
public float warmup;

View File

@@ -119,8 +119,9 @@ public class Drill extends Block{
for(Tile other : tile.getLinkedTiles(tempTiles)){
if(isValid(other)){
toAdd.add(other.floor().drops.item);
totalHardness += other.floor().drops.item.hardness;
Item drop = getDrop(other);
toAdd.add(drop);
totalHardness += drop.hardness;
multiplier += 1f;
}
}
@@ -196,6 +197,10 @@ public class Drill extends Block{
return new DrillEntity();
}
public Item getDrop(Tile tile){
return tile.floor().drops.item;
}
protected boolean isValid(Tile tile){
return tile.floor().drops != null && tile.floor().drops.item.hardness <= tier;
}