From 1682e3b9968bf088ca8f812200b06252ce1654ad Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 24 Sep 2020 14:26:24 -0400 Subject: [PATCH] Fixed #2714 --- core/src/mindustry/ai/types/GroundAI.java | 1 - core/src/mindustry/content/Blocks.java | 4 +- core/src/mindustry/content/UnitTypes.java | 1 + core/src/mindustry/entities/PhysicsWorld.java | 48 +++++++++++++++++++ .../mindustry/graphics/g3d/MeshBuilder.java | 5 +- 5 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 core/src/mindustry/entities/PhysicsWorld.java diff --git a/core/src/mindustry/ai/types/GroundAI.java b/core/src/mindustry/ai/types/GroundAI.java index 88fa3fc51c..20f10c9cb0 100644 --- a/core/src/mindustry/ai/types/GroundAI.java +++ b/core/src/mindustry/ai/types/GroundAI.java @@ -51,7 +51,6 @@ public class GroundAI extends AIController{ if(!Units.invalidateTarget(target, unit, unit.range()) && unit.type().rotateShooting){ if(unit.type().hasWeapons()){ - //TODO certain units should not look at the target, e.g. ships unit.lookAt(Predict.intercept(unit, target, unit.type().weapons.first().bullet.speed)); } }else if(unit.moving()){ diff --git a/core/src/mindustry/content/Blocks.java b/core/src/mindustry/content/Blocks.java index 498bed9295..d1333c8a9a 100644 --- a/core/src/mindustry/content/Blocks.java +++ b/core/src/mindustry/content/Blocks.java @@ -1148,7 +1148,7 @@ public class Blocks implements ContentList{ requirements(Category.power, with(Items.copper, 35, Items.graphite, 25, Items.lead, 40, Items.silicon, 30)); powerProduction = 5.5f; itemDuration = 90f; - consumes.liquid(Liquids.water, 0.09f); + consumes.liquid(Liquids.water, 0.1f); hasLiquids = true; size = 2; }}; @@ -1268,7 +1268,7 @@ public class Blocks implements ContentList{ rotateSpeed = 1.4f; attribute = Attribute.water; - consumes.power(1.25f); + consumes.power(1.5f); }}; cultivator = new Cultivator("cultivator"){{ diff --git a/core/src/mindustry/content/UnitTypes.java b/core/src/mindustry/content/UnitTypes.java index 8e2a5f0734..cc377c833b 100644 --- a/core/src/mindustry/content/UnitTypes.java +++ b/core/src/mindustry/content/UnitTypes.java @@ -156,6 +156,7 @@ public class UnitTypes implements ContentList{ mechStepParticles = true; mechStepShake = 0.15f; + singleTarget = true; weapons.add( new Weapon("scepter-weapon"){{ diff --git a/core/src/mindustry/entities/PhysicsWorld.java b/core/src/mindustry/entities/PhysicsWorld.java new file mode 100644 index 0000000000..0dc918f7a2 --- /dev/null +++ b/core/src/mindustry/entities/PhysicsWorld.java @@ -0,0 +1,48 @@ +package mindustry.entities; + +import arc.math.geom.*; +import arc.math.geom.QuadTree.*; +import arc.struct.*; + +public class PhysicsWorld{ + private QuadTree tree; + private Seq bodies = new Seq<>(false, 16, PhysicsBody.class); + private Rect rect = new Rect(); + + public PhysicsWorld(Rect bounds){ + tree = new QuadTree<>(new Rect(bounds)); + } + + public void add(PhysicsBody body){ + bodies.add(body); + } + + public void remove(PhysicsBody body){ + bodies.remove(body); + } + + public void update(){ + tree.clear(); + for(int i = 0; i < bodies.size; i++){ + tree.insert(bodies.items[i]); + } + + for(int i = 0; i < bodies.size; i++){ + PhysicsBody body = bodies.items[i]; + body.hitbox(rect); + tree.intersect(rect, other -> { + + }); + } + } + + public static class PhysicsBody implements QuadTreeObject{ + public float x, y, xv, yv, radius, mass; + public int flag = 0; + + @Override + public void hitbox(Rect out){ + out.setCentered(x, y, radius * 2, radius * 2); + } + } +} diff --git a/core/src/mindustry/graphics/g3d/MeshBuilder.java b/core/src/mindustry/graphics/g3d/MeshBuilder.java index 2342c469c6..dc26cec9f5 100644 --- a/core/src/mindustry/graphics/g3d/MeshBuilder.java +++ b/core/src/mindustry/graphics/g3d/MeshBuilder.java @@ -4,11 +4,10 @@ import arc.graphics.*; import arc.graphics.VertexAttributes.*; import arc.graphics.gl.*; import arc.math.geom.*; -import arc.util.*; import mindustry.graphics.g3d.PlanetGrid.*; public class MeshBuilder{ - private static final Vec3 v1 = new Vec3(), v2 = new Vec3(), v3 = new Vec3(); + private static final Vec3 v1 = new Vec3(), v2 = new Vec3(), v3 = new Vec3(), v4 = new Vec3(); private static final float[] floats = new float[3 + 3 + 1]; private static Mesh mesh; @@ -111,7 +110,7 @@ public class MeshBuilder{ } private static Vec3 normal(Vec3 v1, Vec3 v2, Vec3 v3){ - return Tmp.v32.set(v2).sub(v1).crs(v3.x - v1.x, v3.y - v1.y, v3.z - v1.z).nor(); + return v4.set(v2).sub(v1).crs(v3.x - v1.x, v3.y - v1.y, v3.z - v1.z).nor(); } private static void verts(Vec3 a, Vec3 b, Vec3 c, Vec3 normal, Color color){