Merge branch 'master' of https://github.com/Anuken/Mindustry into 7.0-features

This commit is contained in:
Anuken
2021-10-12 12:36:20 -04:00
80 changed files with 2247 additions and 187 deletions

View File

@@ -132,6 +132,8 @@ public class Vars implements Loadable{
Color.valueOf("4b5ef1"),
Color.valueOf("2cabfe"),
};
/** maximum TCP packet size */
public static final int maxTcpSize = 900;
/** default server port */
public static final int port = 6567;
/** multicast discovery port.*/
@@ -199,6 +201,8 @@ public class Vars implements Loadable{
public static final String saveExtension = "msav";
/** schematic file extension */
public static final String schematicExtension = "msch";
/** path to the java executable */
public static String javaPath;
/** list of all locales that can be switched to */
public static Locale[] locales;
@@ -293,6 +297,10 @@ public class Vars implements Loadable{
pathfinder = new Pathfinder();
bases = new BaseRegistry();
constants = new GlobalConstants();
javaPath =
new Fi(OS.prop("java.home")).child("bin/java").exists() ? new Fi(OS.prop("java.home")).child("bin/java").absolutePath() :
Core.files.local("jre/bin/java").exists() ? Core.files.local("jre/bin/java").absolutePath() :
"java";
state = new GameState();

View File

@@ -28,11 +28,11 @@ public class StatusEffects implements ContentList{
init(() -> {
opposite(wet, freezing);
affinity(tarred, ((unit, result, time) -> {
affinity(tarred, (unit, result, time) -> {
unit.damagePierce(transitionDamage);
Fx.burning.at(unit.x + Mathf.range(unit.bounds() / 2f), unit.y + Mathf.range(unit.bounds() / 2f));
result.set(burning, Math.min(time + result.time, 300f));
}));
});
});
}};
@@ -46,9 +46,9 @@ public class StatusEffects implements ContentList{
init(() -> {
opposite(melting, burning);
affinity(blasted, ((unit, result, time) -> {
affinity(blasted, (unit, result, time) -> {
unit.damagePierce(transitionDamage);
}));
});
});
}};

View File

@@ -187,15 +187,15 @@ public class NetClient implements ApplicationListener{
effect(effect, x, y, rotation, color);
}
//called on all clients
@Remote(targets = Loc.server, variants = Variant.both)
public static void sendMessage(String message, String sender, Player playersender){
public static void sendMessage(String message, @Nullable String unformatted, @Nullable Player playersender){
if(Vars.ui != null){
Vars.ui.chatfrag.addMessage(message, sender);
Vars.ui.chatfrag.addMessage(message);
}
if(playersender != null){
playersender.lastText(message);
//display raw unformatted text above player head
if(playersender != null && unformatted != null){
playersender.lastText(unformatted);
playersender.textFadeTime(1f);
}
}
@@ -204,7 +204,7 @@ public class NetClient implements ApplicationListener{
@Remote(called = Loc.server, targets = Loc.server)
public static void sendMessage(String message){
if(Vars.ui != null){
Vars.ui.chatfrag.addMessage(message, null);
Vars.ui.chatfrag.addMessage(message);
}
}
@@ -240,7 +240,7 @@ public class NetClient implements ApplicationListener{
//special case; graphical server needs to see its message
if(!headless){
sendMessage(message, colorizeName(player.id, player.name), player);
sendMessage(netServer.chatFormatter.format(player, message), message, player);
}
//server console logging
@@ -248,7 +248,7 @@ public class NetClient implements ApplicationListener{
//invoke event for all clients but also locally
//this is required so other clients get the correct name even if they don't know who's sending it yet
Call.sendMessage(message, colorizeName(player.id(), player.name), player);
Call.sendMessage(netServer.chatFormatter.format(player, message), message, player);
}else{
//a command was sent, now get the output
@@ -284,12 +284,6 @@ public class NetClient implements ApplicationListener{
}
}
public static String colorizeName(int id, String name){
Player player = Groups.player.getByID(id);
if(name == null || player == null) return null;
return "[#" + player.color().toString().toUpperCase() + "]" + name;
}
@Remote(called = Loc.client, variants = Variant.one)
public static void connect(String ip, int port){
if(!steam && ip.startsWith("steam:")) return;

View File

@@ -64,6 +64,8 @@ public class NetServer implements ApplicationListener{
return state.rules.defaultTeam;
};
/** Converts a message + NULLABLE player sender into a single string. Override for custom prefixes/suffixes. */
public ChatFormatter chatFormatter = (player, message) -> player == null ? message : "[coral][[" + player.coloredName() + "[coral]]:[white] " + message;
private boolean closing = false;
private Interval timer = new Interval();
@@ -293,20 +295,22 @@ public class NetServer implements ApplicationListener{
clientCommands.<Player>register("t", "<message...>", "Send a message only to your teammates.", (args, player) -> {
String message = admins.filterMessage(player, args[0]);
if(message != null){
Groups.player.each(p -> p.team() == player.team(), o -> o.sendMessage(message, player, "[#" + player.team().color.toString() + "]<T>" + NetClient.colorizeName(player.id(), player.name)));
String raw = "[#" + player.team().color.toString() + "]<T> " + chatFormatter.format(player, message);
Groups.player.each(p -> p.team() == player.team(), o -> o.sendMessage(raw, player, message));
}
});
clientCommands.<Player>register("a", "<message...>", "Send a message only to admins.", (args, player) -> {
if(!player.admin){
player.sendMessage("[scarlet]You must be admin to use this command.");
player.sendMessage("[scarlet]You must be an admin to use this command.");
return;
}
Groups.player.each(Player::admin, a -> a.sendMessage(args[0], player, "[#" + Pal.adminChat.toString() + "]<A>" + NetClient.colorizeName(player.id, player.name)));
String raw = "[#" + Pal.adminChat.toString() + "]<A> " + chatFormatter.format(player, args[0]);
Groups.player.each(Player::admin, a -> a.sendMessage(raw, player, args[0]));
});
//duration of a a kick in seconds
//duration of a kick in seconds
int kickDuration = 60 * 60;
//voting round duration in seconds
float voteDuration = 0.5f * 60;
@@ -981,4 +985,9 @@ public class NetServer implements ApplicationListener{
public interface TeamAssigner{
Team assign(Player player, Iterable<Player> players);
}
public interface ChatFormatter{
/** @return text to be placed before player name */
String format(@Nullable Player player, String message);
}
}

View File

@@ -314,6 +314,7 @@ public class Renderer implements ApplicationListener{
Draw.draw(Layer.overlayUI, overlays::drawTop);
Draw.draw(Layer.space, this::drawLanding);
Events.fire(Trigger.drawOver);
blocks.drawBlocks();
Groups.draw.draw(Drawc::draw);

View File

@@ -108,7 +108,7 @@ public class Damage{
furthest = null;
boolean found = world.raycast(b.tileX(), b.tileY(), World.toTile(b.x + Tmp.v1.x), World.toTile(b.y + Tmp.v1.y),
(x, y) -> (furthest = world.tile(x, y)) != null && furthest.team() != b.team && furthest.block().absorbLasers);
(x, y) -> (furthest = world.tile(x, y)) != null && furthest.team() != b.team && (furthest.build != null && furthest.build.absorbLasers()));
return found && furthest != null ? Math.max(6f, b.dst(furthest.worldx(), furthest.worldy())) : length;
}

View File

@@ -53,7 +53,7 @@ public class Lightning{
world.raycastEach(World.toTile(from.getX()), World.toTile(from.getY()), World.toTile(to.getX()), World.toTile(to.getY()), (wx, wy) -> {
Tile tile = world.tile(wx, wy);
if(tile != null && tile.block().insulated && tile.team() != team){
if(tile != null && (tile.build != null && tile.build.isInsulated()) && tile.team() != team){
bhit = true;
//snap it instead of removing
lines.get(lines.size - 1).set(wx * tilesize, wy * tilesize);

View File

@@ -1241,6 +1241,14 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
return amount;
}
public boolean absorbLasers(){
return block.absorbLasers;
}
public boolean isInsulated(){
return block.insulated;
}
public boolean collide(Bullet other){
return true;
}

View File

@@ -9,7 +9,6 @@ import arc.util.*;
import arc.util.pooling.*;
import mindustry.annotations.Annotations.*;
import mindustry.content.*;
import mindustry.core.*;
import mindustry.entities.units.*;
import mindustry.game.EventType.*;
import mindustry.game.*;
@@ -310,10 +309,15 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra
Draw.z(z);
}
/** @return name with a markup color prefix */
String coloredName(){
return "[#" + color.toString().toUpperCase() + "]" + name;
}
void sendMessage(String text){
if(isLocal()){
if(ui != null){
ui.chatfrag.addMessage(text, null);
ui.chatfrag.addMessage(text);
}
}else{
Call.sendMessage(con, text, null, null);
@@ -321,16 +325,16 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra
}
void sendMessage(String text, Player from){
sendMessage(text, from, NetClient.colorizeName(from.id(), from.name));
sendMessage(text, from, null);
}
void sendMessage(String text, Player from, String fromName){
void sendMessage(String text, Player from, String unformatted){
if(isLocal()){
if(ui != null){
ui.chatfrag.addMessage(text, fromName);
ui.chatfrag.addMessage(text);
}
}else{
Call.sendMessage(con, text, fromName, from);
Call.sendMessage(con, text, unformatted, from);
}
}

View File

@@ -88,7 +88,7 @@ abstract class WaterMoveComp implements Posc, Velc, Hitboxc, Flyingc, Unitc{
@Replace
public float floorSpeedMultiplier(){
Floor on = isFlying() ? Blocks.air.asFloor() : floorOn();
return (on.isDeep() ? 1.3f : 1f) * speedMultiplier;
return (on.shallow ? 1f : 1.3f) * speedMultiplier;
}
public boolean onLiquid(){

View File

@@ -33,6 +33,7 @@ public class EventType{
socketConfigChanged,
update,
draw,
drawOver,
preDraw,
postDraw,
uiDrawBegin,
@@ -50,6 +51,7 @@ public class EventType{
public static class ResizeEvent{}
public static class MapMakeEvent{}
public static class MapPublishEvent{}
public static class SaveWriteEvent{}
public static class SaveLoadEvent{}
public static class ClientCreateEvent{}
public static class ServerLoadEvent{}
@@ -503,7 +505,7 @@ public class EventType{
this.player = player;
}
}
public static class PlayerBanEvent{
@Nullable
public final Player player;
@@ -514,7 +516,7 @@ public class EventType{
this.uuid = uuid;
}
}
public static class PlayerUnbanEvent{
@Nullable
public final Player player;
@@ -525,7 +527,7 @@ public class EventType{
this.uuid = uuid;
}
}
public static class PlayerIpBanEvent{
public final String ip;
@@ -533,7 +535,7 @@ public class EventType{
this.ip = ip;
}
}
public static class PlayerIpUnbanEvent{
public final String ip;
@@ -541,6 +543,5 @@ public class EventType{
this.ip = ip;
}
}
}
}

View File

@@ -113,12 +113,15 @@ public class SaveIO{
public static void write(OutputStream os, StringMap tags){
try(DataOutputStream stream = new DataOutputStream(os)){
Events.fire(new SaveWriteEvent());
SaveVersion ver = getVersion();
stream.write(header);
stream.writeInt(getVersion().version);
stream.writeInt(ver.version);
if(tags == null){
getVersion().write(stream);
ver.write(stream);
}else{
getVersion().write(stream, tags);
ver.write(stream, tags);
}
}catch(Throwable e){
throw new RuntimeException(e);

View File

@@ -327,7 +327,7 @@ public class SerpuloPlanetGenerator extends PlanetGenerator{
}
}
boolean naval = (float)waters / total >= 0.15f;
boolean naval = (float)waters / total >= 0.19f;
//create water pathway if the map is flooded
if(naval){
@@ -345,11 +345,11 @@ public class SerpuloPlanetGenerator extends PlanetGenerator{
Vec3 v = sector.rect.project(x, y);
float rr = Simplex.noise2d(sector.id, (float)2, 0.6f, 1f / 7f, x, y) * 0.1f;
float value = Ridged.noise3d(2, v.x, v.y, v.z, 1, 1f / 53f) + rr - rawHeight(v) * 0f;
float value = Ridged.noise3d(2, v.x, v.y, v.z, 1, 1f / 55f) + rr - rawHeight(v) * 0f;
float rrscl = rr * 44 - 2;
if(value > 0.12f && !Mathf.within(x, y, fspawn.x, fspawn.y, 12 + rrscl)){
boolean deep = value > 0.12f + 0.1f && !Mathf.within(x, y, fspawn.x, fspawn.y, 15 + rrscl);
if(value > 0.17f && !Mathf.within(x, y, fspawn.x, fspawn.y, 12 + rrscl)){
boolean deep = value > 0.17f + 0.1f && !Mathf.within(x, y, fspawn.x, fspawn.y, 15 + rrscl);
boolean spore = floor != Blocks.sand && floor != Blocks.salt;
//do not place rivers on ice, they're frozen
//ignore pre-existing liquids
@@ -407,7 +407,7 @@ public class SerpuloPlanetGenerator extends PlanetGenerator{
}
}
floor = floor == Blocks.water ? Blocks.deepwater : Blocks.deepTaintedWater;
floor = floor == Blocks.water ? Blocks.deepwater : Blocks.taintedWater;
}
});
}

View File

@@ -107,8 +107,8 @@ public class BeControl{
download(updateUrl, file, i -> length[0] = i, v -> progress[0] = v, () -> cancel[0], () -> {
try{
Runtime.getRuntime().exec(OS.isMac ?
new String[]{"java", "-XstartOnFirstThread", "-DlastBuild=" + Version.build, "-Dberestart", "-Dbecopy=" + fileDest.absolutePath(), "-jar", file.absolutePath()} :
new String[]{"java", "-DlastBuild=" + Version.build, "-Dberestart", "-Dbecopy=" + fileDest.absolutePath(), "-jar", file.absolutePath()}
new String[]{javaPath, "-XstartOnFirstThread", "-DlastBuild=" + Version.build, "-Dberestart", "-Dbecopy=" + fileDest.absolutePath(), "-jar", file.absolutePath()} :
new String[]{javaPath, "-DlastBuild=" + Version.build, "-Dberestart", "-Dbecopy=" + fileDest.absolutePath(), "-jar", file.absolutePath()}
);
System.exit(0);
}catch(IOException e){

View File

@@ -90,7 +90,7 @@ public abstract class NetConnection{
cid = begin.id;
while(stream.stream.available() > 0){
byte[] bytes = new byte[Math.min(512, stream.stream.available())];
byte[] bytes = new byte[Math.min(maxTcpSize, stream.stream.available())];
stream.stream.read(bytes);
StreamChunk chunk = new StreamChunk();

View File

@@ -200,7 +200,7 @@ public class Weapon implements Cloneable{
boolean can = unit.canShoot();
float lastReload = mount.reload;
mount.reload = Math.max(mount.reload - Time.delta * unit.reloadMultiplier, 0);
mount.recoil = Math.max(mount.recoil - (Time.delta * recoil * unit.reloadMultiplier) / recoilTime, 0);
mount.recoil = Mathf.approachDelta(mount.recoil, 0, (Math.abs(recoil) * unit.reloadMultiplier) / recoilTime);
//rotate if applicable
if(rotate && (mount.rotate || mount.shoot) && can){

View File

@@ -138,8 +138,10 @@ public class Bar extends Element{
GlyphLayout lay = Pools.obtain(GlyphLayout.class, GlyphLayout::new);
lay.setText(font, name);
font.setColor(1f, 1f, 1f, parentAlpha);
font.draw(name, x + width / 2f - lay.width / 2f, y + height / 2f + lay.height / 2f + 1);
font.setColor(1f, 1f, 1f, 1f);
font.getCache().clear();
font.getCache().addText(name, x + width / 2f - lay.width / 2f, y + height / 2f + lay.height / 2f + 1);
font.getCache().draw(parentAlpha);
Pools.free(lay);
}

View File

@@ -37,6 +37,7 @@ public class Minimap extends Table{
Draw.rect(renderer.minimap.getRegion(), x + width / 2f, y + height / 2f, width, height);
if(renderer.minimap.getTexture() != null){
Draw.alpha(parentAlpha);
renderer.minimap.drawEntities(x, y, width, height, 0.75f, false);
}

View File

@@ -23,7 +23,7 @@ import static mindustry.Vars.*;
public class ChatFragment extends Table{
private static final int messagesShown = 10;
private Seq<ChatMessage> messages = new Seq<>();
private Seq<String> messages = new Seq<>();
private float fadetime;
private boolean shown = false;
private TextField chatfield;
@@ -144,13 +144,13 @@ public class ChatFragment extends Table{
float theight = offsety + spacing + getMarginBottom() + scene.marginBottom;
for(int i = scrollPos; i < messages.size && i < messagesShown + scrollPos && (i < fadetime || shown); i++){
layout.setText(font, messages.get(i).formattedMessage, Color.white, textWidth, Align.bottomLeft, true);
layout.setText(font, messages.get(i), Color.white, textWidth, Align.bottomLeft, true);
theight += layout.height + textspacing;
if(i - scrollPos == 0) theight -= textspacing + 1;
font.getCache().clear();
font.getCache().setColor(Color.white);
font.getCache().addText(messages.get(i).formattedMessage, fontoffsetx + offsetx, offsety + theight, textWidth, Align.bottomLeft, true);
font.getCache().addText(messages.get(i), fontoffsetx + offsetx, offsety + theight, textWidth, Align.bottomLeft, true);
if(!shown && fadetime - i < 1f && fadetime - i >= 0f){
font.getCache().setAlphas((fadetime - i) * opacity);
@@ -257,9 +257,9 @@ public class ChatFragment extends Table{
return shown;
}
public void addMessage(String message, String sender){
if(sender == null && message == null) return;
messages.insert(0, new ChatMessage(message, sender));
public void addMessage(String message){
if(message == null) return;
messages.insert(0, message);
fadetime += 1f;
fadetime = Math.min(fadetime, messagesShown) + 1f;
@@ -267,22 +267,6 @@ public class ChatFragment extends Table{
if(scrollPos > 0) scrollPos++;
}
private static class ChatMessage{
public final String sender;
public final String message;
public final String formattedMessage;
public ChatMessage(String message, String sender){
this.message = message;
this.sender = sender;
if(sender == null){ //no sender, this is a server message?
formattedMessage = message == null ? "" : message;
}else{
formattedMessage = "[coral][[" + sender + "[coral]]:[white] " + message;
}
}
}
private enum ChatMode{
normal(""),
team("/t"),

View File

@@ -667,7 +667,7 @@ public class HudFragment extends Fragment{
float stroke = width * 0.35f;
float bh = height/2f;
Draw.color(color);
Draw.color(color, parentAlpha);
float f1 = Math.min(fract * 2f, 1f), f2 = (fract - 0.5f) * 2f;
@@ -703,10 +703,10 @@ public class HudFragment extends Fragment{
new Element(){
@Override
public void draw(){
Draw.color(Pal.darkerGray);
Draw.color(Pal.darkerGray, parentAlpha);
Fill.poly(x + width/2f, y + height/2f, 6, height / Mathf.sqrt3);
Draw.reset();
Drawf.shadow(x + width/2f, y + height/2f, height * 1.13f);
Drawf.shadow(x + width/2f, y + height/2f, height * 1.13f, parentAlpha);
}
},
new Table(t -> {

View File

@@ -10,6 +10,7 @@ import arc.util.*;
import arc.util.io.*;
import mindustry.annotations.Annotations.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.logic.*;
@@ -31,13 +32,16 @@ public class ForceProjector extends Block{
public float cooldownNormal = 1.75f;
public float cooldownLiquid = 1.5f;
public float cooldownBrokenBase = 0.35f;
public Effect absorbEffect = Fx.absorb;
public Effect shieldBreakEffect = Fx.shieldBreak;
public @Load("@-top") TextureRegion topRegion;
static ForceBuild paramEntity;
static Effect paramEffect;
static final Cons<Bullet> shieldConsumer = trait -> {
if(trait.team != paramEntity.team && trait.type.absorbable && Intersector.isInsideHexagon(paramEntity.x, paramEntity.y, paramEntity.realRadius() * 2f, trait.x(), trait.y())){
trait.absorb();
Fx.absorb.at(trait);
paramEffect.at(trait);
paramEntity.hit = 1f;
paramEntity.buildup += trait.damage();
}
@@ -154,7 +158,7 @@ public class ForceProjector extends Block{
if(buildup >= shieldHealth + phaseShieldBoost * phaseHeat && !broken){
broken = true;
buildup = shieldHealth;
Fx.shieldBreak.at(x, y, realRadius(), team.color);
shieldBreakEffect.at(x, y, realRadius(), team.color);
}
if(hit > 0f){
@@ -165,6 +169,7 @@ public class ForceProjector extends Block{
if(realRadius > 0 && !broken){
paramEntity = this;
paramEffect = absorbEffect;
Groups.bullet.intersect(x - realRadius, y - realRadius, realRadius * 2f, realRadius * 2f, shieldConsumer);
}
}

View File

@@ -69,13 +69,8 @@ public class OverflowGate extends Block{
}else if(bc && !ac){
to = b;
}else{
if(rotation == 0){
to = a;
if(flip) rotation =1;
}else{
to = b;
if(flip) rotation = 0;
}
to = (rotation & (1 << from)) == 0 ? a : b;
if(flip) rotation ^= (1 << from);
}
}

View File

@@ -114,13 +114,8 @@ public class Sorter extends Block{
}else if(!bc){
return null;
}else{
if(rotation == 0){
to = a;
if(flip) this.rotation = (byte)1;
}else{
to = b;
if(flip) this.rotation = (byte)0;
}
to = (rotation & (1 << dir)) == 0 ? a : b;
if(flip) rotation ^= (1 << dir);
}
}

View File

@@ -349,7 +349,7 @@ public class PowerNode extends PowerBlock{
public static boolean insulated(int x, int y, int x2, int y2){
return world.raycast(x, y, x2, y2, (wx, wy) -> {
Building tile = world.build(wx, wy);
return tile != null && tile.block.insulated;
return tile != null && tile.isInsulated();
});
}