diff --git a/core/src/mindustry/async/TeamIndexProcess.java b/core/src/mindustry/async/TeamIndexProcess.java index 2be6415659..e691c50ee6 100644 --- a/core/src/mindustry/async/TeamIndexProcess.java +++ b/core/src/mindustry/async/TeamIndexProcess.java @@ -1,16 +1,15 @@ package mindustry.async; import arc.math.geom.*; -import arc.struct.*; import mindustry.*; import mindustry.game.*; -import mindustry.game.Teams.*; import mindustry.gen.*; +import java.util.*; + /** Creates quadtrees per unit team. */ public class TeamIndexProcess implements AsyncProcess{ private QuadTree[] trees = new QuadTree[Team.all().length]; - private Array active = new Array<>(); private int[] counts = new int[Team.all().length]; public QuadTree tree(Team team){ @@ -29,28 +28,20 @@ public class TeamIndexProcess implements AsyncProcess{ @Override public void reset(){ - active.clear(); counts = new int[Team.all().length]; trees = new QuadTree[Team.all().length]; } @Override public void begin(){ - for(TeamData data : Vars.state.teams.getActive()){ - if(!active.contains(data.team)){ - active.add(data.team); - } - } - for(Team team : active){ + for(Team team : Team.all()){ if(trees[team.uid] != null){ trees[team.uid].clear(); } } - for(Team team : active){ - counts[team.id] = 0; - } + Arrays.fill(counts, 0); for(Unitc unit : Groups.unit){ tree(unit.team()).insert(unit); diff --git a/core/src/mindustry/content/Bullets.java b/core/src/mindustry/content/Bullets.java index 01bacd44a5..449a40d027 100644 --- a/core/src/mindustry/content/Bullets.java +++ b/core/src/mindustry/content/Bullets.java @@ -439,7 +439,7 @@ public class Bullets implements ContentList{ } }; - basicFlame = new BulletType(3f, 6f){ + basicFlame = new BulletType(3f, 30f){ { ammoMultiplier = 3f; hitSize = 7f; @@ -464,7 +464,7 @@ public class Bullets implements ContentList{ } }; - pyraFlame = new BulletType(3.3f, 9f){ + pyraFlame = new BulletType(3.3f, 45f){ { ammoMultiplier = 4f; hitSize = 7f; diff --git a/core/src/mindustry/entities/def/BulletComp.java b/core/src/mindustry/entities/def/BulletComp.java index be06eb186f..f2f7ffacfc 100644 --- a/core/src/mindustry/entities/def/BulletComp.java +++ b/core/src/mindustry/entities/def/BulletComp.java @@ -4,6 +4,7 @@ import arc.func.*; import arc.graphics.g2d.*; import arc.math.*; import arc.math.geom.*; +import arc.struct.*; import arc.util.*; import mindustry.annotations.Annotations.*; import mindustry.entities.bullet.*; @@ -18,6 +19,7 @@ import static mindustry.Vars.*; abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Drawc, Shielderc, Ownerc, Velc, Bulletc, Timerc{ @Import Team team; + IntArray collided = new IntArray(6); Object data; BulletType type; float damage; @@ -42,6 +44,7 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw @Override public void remove(){ type.despawned(this); + collided.clear(); } @Override @@ -72,7 +75,8 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw @Override public boolean collides(Hitboxc other){ return type.collides && (other instanceof Teamc && ((Teamc)other).team() != team()) - && !(other instanceof Flyingc && ((((Flyingc)other).isFlying() && !type.collidesAir) || (((Flyingc)other).isGrounded() && !type.collidesGround))); + && !(other instanceof Flyingc && ((((Flyingc)other).isFlying() && !type.collidesAir) || (((Flyingc)other).isGrounded() && !type.collidesGround))) + && !(type.pierce && collided.contains(other.id())); //prevent multiple collisions } @MethodPriority(100) @@ -92,7 +96,11 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw } //must be last. - if(!type.pierce) remove(); + if(!type.pierce){ + remove(); + }else{ + collided.add(other.id()); + } } @Override diff --git a/core/src/mindustry/entities/def/TileComp.java b/core/src/mindustry/entities/def/TileComp.java index 86db58b602..fff63dcf18 100644 --- a/core/src/mindustry/entities/def/TileComp.java +++ b/core/src/mindustry/entities/def/TileComp.java @@ -185,6 +185,10 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree return relativeTo(tile.x, tile.y); } + public byte relativeTo(Tilec tile){ + return relativeTo(tile.tile()); + } + public byte relativeTo(int cx, int cy){ return tile.absoluteRelativeTo(cx, cy); } diff --git a/core/src/mindustry/game/Universe.java b/core/src/mindustry/game/Universe.java index 9d2fc1879f..06537564c6 100644 --- a/core/src/mindustry/game/Universe.java +++ b/core/src/mindustry/game/Universe.java @@ -4,6 +4,7 @@ import arc.*; import arc.math.*; import arc.struct.ObjectFloatMap.*; import arc.util.*; +import mindustry.*; import mindustry.content.*; import mindustry.io.*; import mindustry.type.*; @@ -70,26 +71,37 @@ public class Universe{ } } - private void onTurn(){ - //TODO run waves on hostile sectors, damage them + public int[] getTotalExports(){ + int[] exports = new int[Vars.content.items().size]; - //calculate passive items for(Planet planet : content.planets()){ for(Sector sector : planet.sectors){ - //make sure this is a different sector - if(sector.hasSave() && sector != state.rules.sector){ + + //ignore the current sector if the player is in it right now + if(sector.hasSave() && (state.isMenu() || sector != state.rules.sector)){ SaveMeta meta = sector.save.meta; for(Entry entry : meta.exportRates){ //total is calculated by items/sec (value) * turn duration in seconds int total = (int)(entry.value * turnDuration / 60f); - //add the items to global data - data.addItem(entry.key, total); + exports[entry.key.id] += total; } } } } + + return exports; + } + + private void onTurn(){ + //TODO run waves on hostile sectors, damage them + + //calculate passive item generation + int[] exports = getTotalExports(); + for(int i = 0; i < exports.length; i++){ + data.addItem(content.item(i), exports[i]); + } } public float secondsMod(float mod, float scale){ diff --git a/core/src/mindustry/ui/dialogs/PlanetDialog.java b/core/src/mindustry/ui/dialogs/PlanetDialog.java index fd1ba15134..55ee0b4441 100644 --- a/core/src/mindustry/ui/dialogs/PlanetDialog.java +++ b/core/src/mindustry/ui/dialogs/PlanetDialog.java @@ -33,7 +33,7 @@ public class PlanetDialog extends FloatingDialog{ borderColor = Pal.accent.cpy().a(0.3f), shadowColor = new Color(0, 0, 0, 0.7f); private static final float camLength = 4f; - float outlineRad = 1.16f; + private static final float outlineRad = 1.16f; //the base planet that's being rendered private final Planet solarSystem = Planets.sun; @@ -44,7 +44,9 @@ public class PlanetDialog extends FloatingDialog{ private final PlaneBatch3D projector = new PlaneBatch3D(); private final Mat3D mat = new Mat3D(); private final Vec3 camRelative = new Vec3(); + private final ResourcesDialog resources = new ResourcesDialog(); + private float zoom = 1f, smoothZoom = 1f; private Bloom bloom; private Planet planet = Planets.starter; private @Nullable Sector selected, hovered; @@ -73,18 +75,17 @@ public class PlanetDialog extends FloatingDialog{ Events.on(ResizeEvent.class, e -> makeBloom()); - - buttons.defaults().size(220f, 64f).pad(0f); - TextButtonStyle style = Styles.cleart; float bmargin = 6f; - //TODO names - //buttons.button("$back", Icon.left, style, this::hide).margin(bmargin); - //buttons.addImageTextButton("Tech", Icon.tree, style, () -> ui.tech.show()).margin(bmargin); - //buttons.addImageTextButton("Launch", Icon.upOpen, style, this::hide).margin(bmargin); - //buttons.addImageTextButton("Database", Icon.book, style, () -> ui.database.show()).margin(bmargin); - //buttons.addImageTextButton("Resources", Icon.file, style, this::hide).margin(bmargin); + getCell(buttons).padBottom(-4); + buttons.background(Styles.black).defaults().growX().height(64f).pad(0); + + //TODO + buttons.button("$back", Icon.left, style, this::hide).margin(bmargin); + buttons.button("Research", Icon.tree, style, () -> ui.tech.show()).margin(bmargin); + //buttons.button("Database", Icon.book, style, () -> ui.database.show()).margin(bmargin); + buttons.button("Resources", Icon.file, style, resources::show).margin(bmargin); cam.fov = 60f; @@ -108,6 +109,10 @@ public class PlanetDialog extends FloatingDialog{ camRelative.rotate(Tmp.v31.set(cam.up).rotate(cam.direction, 90), amount); }); + scrolled(value -> { + zoom = Mathf.clamp(zoom + value / 10f, 0.5f, 2f); + }); + update(() -> { if(planet.isLandable()){ hovered = planet.getSector(cam.getMouseRay(), outlineRad); @@ -115,7 +120,7 @@ public class PlanetDialog extends FloatingDialog{ hovered = selected = null; } - + smoothZoom = Mathf.lerpDelta(smoothZoom, zoom, 0.4f); }); addListener(new ElementGestureListener(){ @@ -166,7 +171,7 @@ public class PlanetDialog extends FloatingDialog{ cam.up.set(Vec3.Y); cam.resize(Core.graphics.getWidth(), Core.graphics.getHeight()); - camRelative.setLength(planet.radius * camLength); + camRelative.setLength(planet.radius * camLength + (smoothZoom-1f) * planet.radius * 2); cam.position.set(planet.position).add(camRelative); cam.lookAt(planet.position); cam.update(); @@ -372,8 +377,6 @@ public class PlanetDialog extends FloatingDialog{ }); } - - stable.row(); stable.button("Launch", Styles.transt, () -> { diff --git a/core/src/mindustry/ui/dialogs/ResourcesDialog.java b/core/src/mindustry/ui/dialogs/ResourcesDialog.java new file mode 100644 index 0000000000..51b07e5be7 --- /dev/null +++ b/core/src/mindustry/ui/dialogs/ResourcesDialog.java @@ -0,0 +1,41 @@ +package mindustry.ui.dialogs; + +import arc.graphics.*; +import mindustry.gen.*; +import mindustry.type.*; +import mindustry.ui.*; + +import static mindustry.Vars.*; + +public class ResourcesDialog extends FloatingDialog{ + + public ResourcesDialog(){ + super("//TODO resources"); + shown(this::setup); + addCloseButton(); + } + + void setup(){ + cont.clear(); + + cont.table(Tex.button, t -> { + t.left(); + t.margin(10f); + int[] exports = universe.getTotalExports(); + for(Item item : content.items()){ + if(exports[item.id] > 0 || data.getItem(item) > 0){ + t.image(item.icon(Cicon.small)).padRight(4); + t.add(ui.formatAmount(data.getItem(item))).color(Color.lightGray); + if(exports[item.id] > 0){ + t.add("+ [accent]" + ui.formatAmount(exports[item.id]) + " [lightgray]/T"); + }else{ + t.add(); + } + t.row(); + } + } + }); + + + } +} diff --git a/core/src/mindustry/world/blocks/distribution/ItemBridge.java b/core/src/mindustry/world/blocks/distribution/ItemBridge.java index 7ca39a2e37..43b8a630df 100644 --- a/core/src/mindustry/world/blocks/distribution/ItemBridge.java +++ b/core/src/mindustry/world/blocks/distribution/ItemBridge.java @@ -275,8 +275,8 @@ public class ItemBridge extends Block{ Tile other = world.tile(link); if(linkValid(tile, other)){ - int rel = relativeTo(other.x, other.y); - int rel2 = relativeTo(source.tileX(), source.tileY()); + int rel = relativeTo(other); + int rel2 = relativeTo(Edges.getFacingEdge(source.tile(), tile)); if(rel == rel2) return false; }else{