From 0267ad574f5a092c6d05edbe59ed8013b94c15d1 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sat, 23 Jun 2018 15:11:13 -0400 Subject: [PATCH] Fixed some AI quirks, re-added debug blocks, fixed cultivator --- .../io/anuke/mindustry/content/Recipes.java | 5 +-- .../io/anuke/mindustry/entities/Player.java | 5 +-- .../mindustry/entities/units/BaseUnit.java | 22 ++++++++++++- .../mindustry/entities/units/FlyingUnit.java | 11 +++++-- .../mindustry/entities/units/GroundUnit.java | 33 +++++++++++++++---- .../ui/fragments/BlocksFragment.java | 8 +++-- core/src/io/anuke/mindustry/world/Build.java | 3 +- .../blocks/defense/turrets/ItemTurret.java | 2 +- .../world/blocks/distribution/Conveyor.java | 4 +-- .../world/blocks/production/Cultivator.java | 6 ++++ .../world/blocks/production/Drill.java | 9 +++-- 11 files changed, 86 insertions(+), 22 deletions(-) diff --git a/core/src/io/anuke/mindustry/content/Recipes.java b/core/src/io/anuke/mindustry/content/Recipes.java index 1de33adebf..2578b4b04e 100644 --- a/core/src/io/anuke/mindustry/content/Recipes.java +++ b/core/src/io/anuke/mindustry/content/Recipes.java @@ -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)); diff --git a/core/src/io/anuke/mindustry/entities/Player.java b/core/src/io/anuke/mindustry/entities/Player.java index 1912c3c878..a2a63a3212 100644 --- a/core/src/io/anuke/mindustry/entities/Player.java +++ b/core/src/io/anuke/mindustry/entities/Player.java @@ -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 diff --git a/core/src/io/anuke/mindustry/entities/units/BaseUnit.java b/core/src/io/anuke/mindustry/entities/units/BaseUnit.java index e46b208750..77bad39ce0 100644 --- a/core/src/io/anuke/mindustry/entities/units/BaseUnit.java +++ b/core/src/io/anuke/mindustry/entities/units/BaseUnit.java @@ -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 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 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; } diff --git a/core/src/io/anuke/mindustry/entities/units/FlyingUnit.java b/core/src/io/anuke/mindustry/entities/units/FlyingUnit.java index 59c8db0007..bf20a3ca01 100644 --- a/core/src/io/anuke/mindustry/entities/units/FlyingUnit.java +++ b/core/src/io/anuke/mindustry/entities/units/FlyingUnit.java @@ -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)); } } } diff --git a/core/src/io/anuke/mindustry/entities/units/GroundUnit.java b/core/src/io/anuke/mindustry/entities/units/GroundUnit.java index 2fa29f9122..afbcda8b85 100644 --- a/core/src/io/anuke/mindustry/entities/units/GroundUnit.java +++ b/core/src/io/anuke/mindustry/entities/units/GroundUnit.java @@ -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(); diff --git a/core/src/io/anuke/mindustry/ui/fragments/BlocksFragment.java b/core/src/io/anuke/mindustry/ui/fragments/BlocksFragment.java index 2bf7378791..6dbb414c20 100644 --- a/core/src/io/anuke/mindustry/ui/fragments/BlocksFragment.java +++ b/core/src/io/anuke/mindustry/ui/fragments/BlocksFragment.java @@ -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 + ""; diff --git a/core/src/io/anuke/mindustry/world/Build.java b/core/src/io/anuke/mindustry/world/Build.java index 2bbb408d1e..ba4476af8a 100644 --- a/core/src/io/anuke/mindustry/world/Build.java +++ b/core/src/io/anuke/mindustry/world/Build.java @@ -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; } diff --git a/core/src/io/anuke/mindustry/world/blocks/defense/turrets/ItemTurret.java b/core/src/io/anuke/mindustry/world/blocks/defense/turrets/ItemTurret.java index eeb5b8dfa5..8b8955d539 100644 --- a/core/src/io/anuke/mindustry/world/blocks/defense/turrets/ItemTurret.java +++ b/core/src/io/anuke/mindustry/world/blocks/defense/turrets/ItemTurret.java @@ -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 ammoMap = new ObjectMap<>(); diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/Conveyor.java b/core/src/io/anuke/mindustry/world/blocks/distribution/Conveyor.java index 5f075dc5e5..522a327f04 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/Conveyor.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/Conveyor.java @@ -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); } diff --git a/core/src/io/anuke/mindustry/world/blocks/production/Cultivator.java b/core/src/io/anuke/mindustry/world/blocks/production/Cultivator.java index 3fd489f7d9..248aca5b43 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/Cultivator.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/Cultivator.java @@ -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; diff --git a/core/src/io/anuke/mindustry/world/blocks/production/Drill.java b/core/src/io/anuke/mindustry/world/blocks/production/Drill.java index 7c1b733c4b..f307b659cc 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/Drill.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/Drill.java @@ -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; }