Merge branch 'master' into crater

This commit is contained in:
Patrick 'Quezler' Mounier
2019-12-30 10:55:06 +01:00
48 changed files with 912 additions and 512 deletions

View File

@@ -5,11 +5,11 @@ import arc.func.*;
import arc.math.*;
import arc.math.geom.*;
import arc.struct.*;
import arc.util.*;
import mindustry.content.*;
import mindustry.entities.type.*;
import mindustry.game.EventType.*;
import mindustry.game.*;
import mindustry.game.Teams.*;
import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.blocks.*;
@@ -34,6 +34,8 @@ public class BlockIndexer{
private ObjectSet<Tile>[] damagedTiles = new ObjectSet[Team.all().length];
/**All ores available on this map.*/
private ObjectSet<Item> allOres = new ObjectSet<>();
/**Stores teams that are present here as tiles.*/
private ObjectSet<Team> activeTeams = new ObjectSet<>();
/** Maps teams to a map of flagged tiles by type. */
private ObjectSet<Tile>[][] flagMap = new ObjectSet[Team.all().length][BlockFlag.all.length];
@@ -104,10 +106,11 @@ public class BlockIndexer{
}
private GridBits structQuadrant(Team t){
if(structQuadrants[t.id] == null){
structQuadrants[t.id] = new GridBits(Mathf.ceil(world.width() / (float)quadrantSize), Mathf.ceil(world.height() / (float)quadrantSize));
int id = Pack.u(t.id);
if(structQuadrants[id] == null){
structQuadrants[id] = new GridBits(Mathf.ceil(world.width() / (float)quadrantSize), Mathf.ceil(world.height() / (float)quadrantSize));
}
return structQuadrants[t.id];
return structQuadrants[id];
}
/** Updates all the structure quadrants for a newly activated team. */
@@ -184,6 +187,19 @@ public class BlockIndexer{
set.add(entity.tile);
}
public TileEntity findEnemyTile(Team team, float x, float y, float range, Boolf<Tile> pred){
for(Team enemy : activeTeams){
if(!team.isEnemy(enemy)) continue;
TileEntity entity = indexer.findTile(enemy, x, y, range, pred, true);
if(entity != null){
return entity;
}
}
return null;
}
public TileEntity findTile(Team team, float x, float y, float range, Boolf<Tile> pred){
return findTile(team, x, y, range, pred, false);
}
@@ -209,7 +225,7 @@ public class BlockIndexer{
TileEntity e = other.entity;
float ndst = Mathf.dst(x, y, e.x, e.y);
if(ndst < range && (closest == null || ndst < dst || (usePriority && closest.block.priority.ordinal() < e.block.priority.ordinal()))){
if(ndst < range && (closest == null || ndst < dst || (usePriority && closest.block.priority.ordinal() <= e.block.priority.ordinal()))){
dst = ndst;
closest = e;
}
@@ -263,6 +279,7 @@ public class BlockIndexer{
}
typeMap.put(tile.pos(), new TileIndex(tile.block().flags, tile.getTeam()));
}
activeTeams.add(tile.getTeam());
if(ores == null) return;
@@ -301,13 +318,12 @@ public class BlockIndexer{
//this quadrant is now 'dirty', re-scan the whole thing
int quadrantX = tile.x / quadrantSize;
int quadrantY = tile.y / quadrantSize;
int index = quadrantX + quadrantY * quadWidth();
for(TeamData data : state.teams.getActive()){
GridBits bits = structQuadrant(data.team);
for(Team team : activeTeams){
GridBits bits = structQuadrant(team);
//fast-set this quadrant to 'occupied' if the tile just placed is already of this team
if(tile.getTeam() == data.team && tile.entity != null && tile.block().targetable){
if(tile.getTeam() == team && tile.entity != null && tile.block().targetable){
bits.set(quadrantX, quadrantY);
continue; //no need to process futher
}
@@ -319,7 +335,7 @@ public class BlockIndexer{
for(int y = quadrantY * quadrantSize; y < world.height() && y < (quadrantY + 1) * quadrantSize; y++){
Tile result = world.ltile(x, y);
//when a targetable block is found, mark this quadrant as occupied and stop searching
if(result.entity != null && result.getTeam() == data.team){
if(result.entity != null && result.getTeam() == team){
bits.set(quadrantX, quadrantY);
break outer;
}

View File

@@ -456,7 +456,7 @@ public class Control implements ApplicationListener, Loadable{
state.set(state.is(State.playing) ? State.paused : State.playing);
}
if(Core.input.keyTap(Binding.menu) && !ui.restart.isShown()){
if(Core.input.keyTap(Binding.menu) && !ui.restart.isShown() && !ui.minimapfrag.shown()){
if(ui.chatfrag.shown()){
ui.chatfrag.hide();
}else if(!ui.paused.isShown() && !scene.hasDialog()){

View File

@@ -261,7 +261,7 @@ public class Logic implements ApplicationListener{
}
}
if(!net.client() && !world.isInvalidMap() && !state.isEditor() && !state.rules.canGameOver){
if(!net.client() && !world.isInvalidMap() && !state.isEditor() && state.rules.canGameOver){
checkGameOver();
}
}

View File

@@ -123,12 +123,14 @@ public class Renderer implements ApplicationListener{
if(player.isDead()){
TileEntity core = player.getClosestCore();
if(core != null && player.spawner == null){
camera.position.lerpDelta(core.x, core.y, 0.08f);
}else if(core != null){
camera.position.lerpDelta(position, 0.08f);
if(core != null){
if(player.spawner == null){
camera.position.lerpDelta(core.x, core.y, 0.08f);
}else{
camera.position.lerpDelta(position, 0.08f);
}
}
}else if(control.input instanceof DesktopInput){
}else if(control.input instanceof DesktopInput && !state.isPaused()){
camera.position.lerpDelta(position, 0.08f);
}

View File

@@ -43,6 +43,7 @@ public class UI implements ApplicationListener, Loadable{
public HudFragment hudfrag;
public ChatFragment chatfrag;
public ScriptConsoleFragment scriptfrag;
public MinimapFragment minimapfrag;
public PlayerListFragment listfrag;
public LoadingFragment loadfrag;
@@ -68,7 +69,7 @@ public class UI implements ApplicationListener, Loadable{
public ContentInfoDialog content;
public DeployDialog deploy;
public TechTreeDialog tech;
public MinimapDialog minimap;
//public MinimapDialog minimap;
public SchematicsDialog schematics;
public ModsDialog mods;
public ColorPicker picker;
@@ -210,6 +211,7 @@ public class UI implements ApplicationListener, Loadable{
menufrag = new MenuFragment();
hudfrag = new HudFragment();
chatfrag = new ChatFragment();
minimapfrag = new MinimapFragment();
listfrag = new PlayerListFragment();
loadfrag = new LoadingFragment();
scriptfrag = new ScriptConsoleFragment();
@@ -235,7 +237,6 @@ public class UI implements ApplicationListener, Loadable{
content = new ContentInfoDialog();
deploy = new DeployDialog();
tech = new TechTreeDialog();
minimap = new MinimapDialog();
mods = new ModsDialog();
schematics = new SchematicsDialog();
@@ -254,6 +255,7 @@ public class UI implements ApplicationListener, Loadable{
hudfrag.build(hudGroup);
menufrag.build(menuGroup);
chatfrag.container().build(hudGroup);
minimapfrag.build(hudGroup);
listfrag.build(hudGroup);
scriptfrag.container().build(hudGroup);
loadfrag.build(group);

View File

@@ -83,13 +83,7 @@ public class Units{
public static TileEntity findEnemyTile(Team team, float x, float y, float range, Boolf<Tile> pred){
if(team == Team.derelict) return null;
for(Team enemy : team.enemies()){
TileEntity entity = indexer.findTile(enemy, x, y, range, pred, true);
if(entity != null){
return entity;
}
}
return null;
return indexer.findEnemyTile(team, x, y, range, pred);
}
/** Returns the closest target enemy. First, units are checked, then tile entities. */

View File

@@ -568,6 +568,7 @@ public class Player extends Unit implements BuilderMinerTrait, ShooterTrait{
protected void updateKeyboard(){
Tile tile = world.tileWorld(x, y);
boolean canMove = !Core.scene.hasKeyboard() || ui.minimapfrag.shown();
isBoosting = Core.input.keyDown(Binding.dash) && !mech.flying;
@@ -594,8 +595,8 @@ public class Player extends Unit implements BuilderMinerTrait, ShooterTrait{
}
if(Core.input.keyDown(Binding.mouse_move)){
movement.x += Mathf.clamp((Core.input.mouseX() - Core.graphics.getWidth() / 2) * 0.005f, -1, 1) * speed;
movement.y += Mathf.clamp((Core.input.mouseY() - Core.graphics.getHeight() / 2) * 0.005f, -1, 1) * speed;
movement.x += Mathf.clamp((Core.input.mouseX() - Core.graphics.getWidth() / 2f) * 0.005f, -1, 1) * speed;
movement.y += Mathf.clamp((Core.input.mouseY() - Core.graphics.getHeight() / 2f) * 0.005f, -1, 1) * speed;
}
Vec2 vec = Core.input.mouseWorld(control.input.getMouseX(), control.input.getMouseY());
@@ -605,7 +606,7 @@ public class Player extends Unit implements BuilderMinerTrait, ShooterTrait{
movement.limit(speed).scl(Time.delta());
if(!Core.scene.hasKeyboard()){
if(canMove){
velocity.add(movement.x, movement.y);
}else{
isShooting = false;
@@ -614,7 +615,7 @@ public class Player extends Unit implements BuilderMinerTrait, ShooterTrait{
updateVelocityStatus();
moved = dst(prex, prey) > 0.001f;
if(!Core.scene.hasKeyboard()){
if(canMove){
float baseLerp = mech.getRotationAlpha(this);
if(!isShooting() || !mech.turnCursor){
if(!movement.isZero()){

View File

@@ -30,7 +30,7 @@ public class Team implements Comparable<Team>{
blue = new Team(5, "blue", Color.royal.cpy());
static{
Mathf.random.setSeed(7);
Mathf.random.setSeed(8);
//create the whole 256 placeholder teams
for(int i = 6; i < all.length; i++){
new Team(i, "team#" + i, Color.HSVtoRGB(360f * Mathf.random(), 100f * Mathf.random(0.6f, 1f), 100f * Mathf.random(0.8f, 1f), 1f));

View File

@@ -9,6 +9,7 @@ import arc.math.*;
import arc.math.geom.*;
import arc.scene.ui.layout.*;
import arc.util.*;
import arc.util.ArcAnnotate.*;
import arc.util.pooling.*;
import mindustry.entities.*;
import mindustry.entities.type.*;
@@ -42,7 +43,7 @@ public class MinimapRenderer implements Disposable{
return pixmap;
}
public Texture getTexture(){
public @Nullable Texture getTexture(){
return texture;
}
@@ -70,8 +71,13 @@ public class MinimapRenderer implements Disposable{
region = new TextureRegion(texture);
}
public void drawEntities(float x, float y, float w, float h, boolean withLabels){
updateUnitArray();
public void drawEntities(float x, float y, float w, float h, float scaling, boolean withLabels){
if(!withLabels){
updateUnitArray();
}else{
units.clear();
Units.all(units::add);
}
float sz = baseSize * zoom;
float dx = (Core.camera.position.x / tilesize);
@@ -83,8 +89,13 @@ public class MinimapRenderer implements Disposable{
for(Unit unit : units){
if(unit.isDead()) continue;
float rx = (unit.x - rect.x) / rect.width * w;
float ry = (unit.y - rect.y) / rect.width * h;
float rx = !withLabels ? (unit.x - rect.x) / rect.width * w : unit.x / (world.width() * tilesize) * w;
float ry = !withLabels ? (unit.y - rect.y) / rect.width * h : unit.y / (world.height() * tilesize) * h;
Draw.mixcol(unit.getTeam().color, 1f);
float scale = Scl.scl(1f) / 2f * scaling * 32f;
Draw.rect(unit.getIconRegion(), x + rx, y + ry, scale, scale, unit.rotation - 90);
Draw.reset();
if(withLabels && unit instanceof Player){
Player pl = (Player) unit;
@@ -93,19 +104,16 @@ public class MinimapRenderer implements Disposable{
drawLabel(x + rx, y + ry, pl.name, unit.getTeam().color);
}
}
Draw.color(unit.getTeam().color);
Fill.rect(x + rx, y + ry, Scl.scl(baseSize / 2f), Scl.scl(baseSize / 2f));
}
Draw.color();
Draw.reset();
}
public void drawEntities(float x, float y, float w, float h){
drawEntities(x, y, w, h, true);
drawEntities(x, y, w, h, 1f, true);
}
public TextureRegion getRegion(){
public @Nullable TextureRegion getRegion(){
if(texture == null) return null;
float sz = Mathf.clamp(baseSize * zoom, baseSize, Math.min(world.width(), world.height()));

View File

@@ -96,7 +96,7 @@ public class OverlayRenderer{
if(buildFadeTime > 0.005f){
state.teams.eachEnemyCore(player.getTeam(), core -> {
float dst = core.dst(player);
if(dst < state.rules.enemyCoreBuildRadius * 1.5f){
if(dst < state.rules.enemyCoreBuildRadius * 2.2f){
Draw.color(Color.darkGray);
Lines.circle(core.x, core.y - 2, state.rules.enemyCoreBuildRadius);
Draw.color(Pal.accent, core.getTeam().color, 0.5f + Mathf.absin(Time.time(), 10f, 0.5f));

View File

@@ -136,22 +136,23 @@ public class DesktopInput extends InputHandler{
ui.listfrag.toggle();
}
if(player.getClosestCore() == null && !ui.chatfrag.shown()){
if(((player.getClosestCore() == null && player.isDead()) || state.isPaused()) && !ui.chatfrag.shown()){
//move camera around
float camSpeed = 6f;
float camSpeed = !Core.input.keyDown(Binding.dash) ? 3f : 8f;
Core.camera.position.add(Tmp.v1.setZero().add(Core.input.axis(Binding.move_x), Core.input.axis(Binding.move_y)).nor().scl(Time.delta() * camSpeed));
if(Core.input.keyDown(Binding.mouse_move)){
Core.camera.position.x += Mathf.clamp((Core.input.mouseX() - Core.graphics.getWidth() / 2f) * 0.005f, -1, 1) * camSpeed;
Core.camera.position.y += Mathf.clamp((Core.input.mouseY() - Core.graphics.getHeight() / 2f) * 0.005f, -1, 1) * camSpeed;
}
}
if(Core.input.keyRelease(Binding.select)){
player.isShooting = false;
}
if(!state.is(State.menu) && Core.input.keyTap(Binding.minimap) && (scene.getKeyboardFocus() == ui.minimap || !scene.hasDialog()) && !Core.scene.hasKeyboard() && !(scene.getKeyboardFocus() instanceof TextField)){
if(!ui.minimap.isShown()){
ui.minimap.show();
}else{
ui.minimap.hide();
}
if(!state.is(State.menu) && Core.input.keyTap(Binding.minimap) && !scene.hasDialog() && !(scene.getKeyboardFocus() instanceof TextField)){
ui.minimapfrag.toggle();
}
if(state.is(State.menu) || Core.scene.hasDialog()) return;

View File

@@ -36,7 +36,7 @@ public class Minimap extends Table{
Draw.rect(renderer.minimap.getRegion(), x + width / 2f, y + height / 2f, width, height);
if(renderer.minimap.getTexture() != null){
renderer.minimap.drawEntities(x, y, width, height, false);
renderer.minimap.drawEntities(x, y, width, height, 0.75f, false);
}
}
}).size(140f);
@@ -83,7 +83,7 @@ public class Minimap extends Table{
@Override
public void clicked(InputEvent event, float x, float y){
ui.minimap.show();
ui.minimapfrag.toggle();
}
});

View File

@@ -0,0 +1,114 @@
package mindustry.ui.fragments;
import arc.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.input.*;
import arc.math.*;
import arc.scene.*;
import arc.scene.event.*;
import arc.scene.ui.layout.*;
import mindustry.gen.*;
import mindustry.input.*;
import mindustry.ui.*;
import static mindustry.Vars.*;
public class MinimapFragment extends Fragment{
private boolean shown;
private float panx, pany, zoom = 1f, lastZoom = -1;
private float baseSize = Scl.scl(5f);
private Element elem;
@Override
public void build(Group parent){
elem = parent.fill((x, y, w, h) -> {
w = Core.graphics.getWidth();
h = Core.graphics.getHeight();
float size = baseSize * zoom * world.width();
Draw.color(Color.black);
Fill.crect(x, y, w, h);
if(renderer.minimap.getTexture() != null){
Draw.color();
float ratio = (float)renderer.minimap.getTexture().getHeight() / renderer.minimap.getTexture().getWidth();
TextureRegion reg = Draw.wrap(renderer.minimap.getTexture());
Draw.rect(reg, w/2f + panx*zoom, h/2f + pany*zoom, size, size * ratio);
renderer.minimap.drawEntities(w/2f + panx*zoom - size/2f, h/2f + pany*zoom - size/2f * ratio, size, size * ratio, zoom, true);
}
Draw.reset();
});
elem.visible(() -> shown);
elem.update(() -> {
elem.requestKeyboard();
elem.requestScroll();
elem.setFillParent(true);
elem.setBounds(0, 0, Core.graphics.getWidth(), Core.graphics.getHeight());
if(Core.input.keyTap(Binding.menu)){
shown = false;
}
});
elem.touchable(Touchable.enabled);
elem.addListener(new ElementGestureListener(){
@Override
public void zoom(InputEvent event, float initialDistance, float distance){
if(lastZoom < 0){
lastZoom = zoom;
}
zoom = Mathf.clamp(distance / initialDistance * lastZoom, 0.25f, 10f);
}
@Override
public void pan(InputEvent event, float x, float y, float deltaX, float deltaY){
panx += deltaX / zoom;
pany += deltaY / zoom;
}
@Override
public void touchDown(InputEvent event, float x, float y, int pointer, KeyCode button){
super.touchDown(event, x, y, pointer, button);
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, KeyCode button){
lastZoom = zoom;
}
});
elem.addListener(new InputListener(){
@Override
public boolean scrolled(InputEvent event, float x, float y, float amountX, float amountY){
zoom = Mathf.clamp(zoom - amountY / 10f * zoom, 0.25f, 10f);
return true;
}
});
parent.fill(t -> {
t.setFillParent(true);
t.visible(() -> shown);
t.update(() -> t.setBounds(0, 0, Core.graphics.getWidth(), Core.graphics.getHeight()));
t.add("$minimap").style(Styles.outlineLabel).pad(10f);
t.row();
t.add().growY();
t.row();
t.addImageTextButton("$back", Icon.backSmall, () -> shown = false).size(220f, 60f).pad(10f);
});
}
public boolean shown(){
return shown;
}
public void toggle(){
shown = !shown;
}
}

View File

@@ -130,7 +130,7 @@ public class PlayerListFragment extends Fragment{
t.addImageButton(Icon.zoomSmall, Styles.clearPartiali, () -> Call.onAdminRequest(user, AdminAction.trace));
}).padRight(12).size(bs + 10f, bs);
}else if((!user.isLocal && !user.isAdmin) && net.client() && playerGroup.size() >= 3){ //votekick
}else if((!user.isLocal && !user.isAdmin) && net.client() && playerGroup.size() >= 3 && player.getTeam() != user.getTeam()){ //votekick
button.add().growY();
button.addImageButton(Icon.banSmall, Styles.clearPartiali,

View File

@@ -53,7 +53,7 @@ public class ScriptConsoleFragment extends Table{
clearChatInput();
}
return shown;
return shown && Vars.net.active();
});
update(() -> {

View File

@@ -5,6 +5,7 @@ import arc.math.*;
import mindustry.entities.type.*;
import mindustry.graphics.*;
import mindustry.type.*;
import mindustry.ui.*;
import mindustry.world.*;
import static mindustry.Vars.net;
@@ -20,7 +21,7 @@ public class RespawnBlock{
Draw.reset();
if(player != null){
TextureRegion region = player.getIconRegion();
TextureRegion region = to.icon(Cicon.full);
Draw.color(0f, 0f, 0f, 0.4f * progress);
Draw.rect("circle-shadow", tile.drawx(), tile.drawy(), region.getWidth() / 3f, region.getWidth() / 3f);

View File

@@ -81,11 +81,11 @@ public class OverflowGate extends Block{
if(to == null) return null;
Tile edge = Edges.getFacingEdge(tile, to);
if(!to.block().acceptItem(item, to, edge) || (to.block() instanceof OverflowGate)){
if(!to.block().acceptItem(item, to, edge) || to.getTeam() != tile.getTeam() || (to.block() instanceof OverflowGate)){
Tile a = tile.getNearby(Mathf.mod(from - 1, 4));
Tile b = tile.getNearby(Mathf.mod(from + 1, 4));
boolean ac = a != null && a.block().acceptItem(item, a, edge) && !(a.block() instanceof OverflowGate);
boolean bc = b != null && b.block().acceptItem(item, b, edge) && !(b.block() instanceof OverflowGate);
boolean ac = a != null && a.block().acceptItem(item, a, edge) && !(a.block() instanceof OverflowGate) && a.getTeam() == tile.getTeam();
boolean bc = b != null && b.block().acceptItem(item, b, edge) && !(b.block() instanceof OverflowGate) && b.getTeam() == tile.getTeam();
if(!ac && !bc){
return null;

View File

@@ -151,7 +151,7 @@ public class CoreBlock extends StorageBlock{
@Override
public void removed(Tile tile){
CoreEntity entity = tile.ent();
int total = tile.entity.proximity().count(e -> e.entity.items == tile.entity.items);
int total = tile.entity.proximity().count(e -> e.entity != null && e.entity.items != null && e.entity.items == tile.entity.items);
float fract = 1f / total / state.teams.cores(tile.getTeam()).size;
tile.entity.proximity().each(e -> isContainer(e) && e.entity.items == tile.entity.items, t -> {

View File

@@ -112,7 +112,7 @@ public class MechPad extends Block{
MechFactoryEntity entity = tile.ent();
if(entity.player != null){
RespawnBlock.drawRespawn(tile, entity.heat, entity.progress, entity.time, entity.player, (!entity.sameMech && entity.player.mech == mech ? mech : Mechs.starter));
RespawnBlock.drawRespawn(tile, entity.heat, entity.progress, entity.time, entity.player, (!entity.sameMech && entity.player.mech == mech ? Mechs.starter : mech));
}
}