Partial 7.0 merge - API preview
This commit is contained in:
@@ -6,6 +6,7 @@ import mindustry.ctype.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.net.*;
|
||||
import mindustry.net.Packets.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
@@ -242,11 +243,31 @@ public class EventType{
|
||||
}
|
||||
}
|
||||
|
||||
public static class TileChangeEvent{
|
||||
public final Tile tile;
|
||||
/**
|
||||
* Called *before* a tile has changed.
|
||||
* WARNING! This event is special: its instance is reused! Do not cache or use with a timer.
|
||||
* Do not modify any tiles inside listeners that use this tile.
|
||||
* */
|
||||
public static class TilePreChangeEvent{
|
||||
public Tile tile;
|
||||
|
||||
public TileChangeEvent(Tile tile){
|
||||
public TilePreChangeEvent set(Tile tile){
|
||||
this.tile = tile;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called *after* a tile has changed.
|
||||
* WARNING! This event is special: its instance is reused! Do not cache or use with a timer.
|
||||
* Do not modify any tiles inside listeners that use this tile.
|
||||
* */
|
||||
public static class TileChangeEvent{
|
||||
public Tile tile;
|
||||
|
||||
public TileChangeEvent set(Tile tile){
|
||||
this.tile = tile;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -392,6 +413,17 @@ public class EventType{
|
||||
}
|
||||
}
|
||||
|
||||
/** Called when a player sends a connection packet. */
|
||||
public static class ConnectPacketEvent{
|
||||
public final NetConnection connection;
|
||||
public final ConnectPacket packet;
|
||||
|
||||
public ConnectPacketEvent(NetConnection connection, ConnectPacket packet){
|
||||
this.connection = connection;
|
||||
this.packet = packet;
|
||||
}
|
||||
}
|
||||
|
||||
/** Called after connecting; when a player receives world data and is ready to play.*/
|
||||
public static class PlayerJoin{
|
||||
public final Player player;
|
||||
|
||||
@@ -2,6 +2,7 @@ package mindustry.game;
|
||||
|
||||
import arc.*;
|
||||
import arc.func.*;
|
||||
import arc.util.*;
|
||||
import mindustry.maps.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
@@ -22,7 +23,7 @@ public enum Gamemode{
|
||||
rules.waves = true;
|
||||
rules.waveTimer = true;
|
||||
|
||||
rules.waveSpacing /= 2f;
|
||||
rules.waveSpacing = 60f * Time.toMinutes;
|
||||
rules.teams.get(rules.waveTeam).infiniteResources = true;
|
||||
}, map -> map.teams.contains(state.rules.waveTeam.id)),
|
||||
pvp(rules -> {
|
||||
|
||||
@@ -10,6 +10,8 @@ import mindustry.io.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.type.Weather.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
/**
|
||||
* Defines current rules on how the game should function.
|
||||
@@ -34,6 +36,8 @@ public class Rules{
|
||||
public boolean editor = false;
|
||||
/** Whether a gameover can happen at all. Set this to false to implement custom gameover conditions. */
|
||||
public boolean canGameOver = true;
|
||||
/** Whether cores change teams when they are destroyed. */
|
||||
public boolean coreCapture = false;
|
||||
/** Whether reactors can explode and damage other blocks. */
|
||||
public boolean reactorExplosions = true;
|
||||
/** Whether schematics are allowed. */
|
||||
@@ -72,6 +76,10 @@ public class Rules{
|
||||
public int winWave = 0;
|
||||
/** Base unit cap. Can still be increased by blocks. */
|
||||
public int unitCap = 0;
|
||||
/** Environmental flags that dictate visuals & how blocks function. */
|
||||
public int environment = Env.terrestrial | Env.spores | Env.groundOil | Env.groundWater;
|
||||
/** Attributes of the environment. */
|
||||
public Attributes attributes = new Attributes();
|
||||
/** Sector for saves that have them. */
|
||||
public @Nullable Sector sector;
|
||||
/** Spawn layout. */
|
||||
|
||||
@@ -214,7 +214,7 @@ public class Saves{
|
||||
}
|
||||
previewExecutor.submit(() -> {
|
||||
try{
|
||||
previewFile().writePNG(renderer.minimap.getPixmap());
|
||||
previewFile().writePng(renderer.minimap.getPixmap());
|
||||
requestedPreview = false;
|
||||
}catch(Throwable t){
|
||||
Log.err(t);
|
||||
|
||||
@@ -15,6 +15,9 @@ import static mindustry.Vars.*;
|
||||
|
||||
public class Schematic implements Publishable, Comparable<Schematic>{
|
||||
public final Seq<Stile> tiles;
|
||||
/** These are used for the schematic tag UI. */
|
||||
public Seq<String> labels = new Seq<>();
|
||||
/** Internal meta tags. */
|
||||
public StringMap tags;
|
||||
public int width, height;
|
||||
public @Nullable Fi file;
|
||||
@@ -29,7 +32,7 @@ public class Schematic implements Publishable, Comparable<Schematic>{
|
||||
}
|
||||
|
||||
public float powerProduction(){
|
||||
return tiles.sumf(s -> s.block instanceof PowerGenerator ? ((PowerGenerator)s.block).powerProduction : 0f);
|
||||
return tiles.sumf(s -> s.block instanceof PowerGenerator p ? p.powerProduction : 0f);
|
||||
}
|
||||
|
||||
public float powerConsumption(){
|
||||
|
||||
@@ -26,7 +26,6 @@ import mindustry.input.*;
|
||||
import mindustry.input.Placement.*;
|
||||
import mindustry.io.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.*;
|
||||
import mindustry.world.blocks.ConstructBlock.*;
|
||||
import mindustry.world.blocks.distribution.*;
|
||||
import mindustry.world.blocks.legacy.*;
|
||||
@@ -128,8 +127,6 @@ public class Schematics implements Loadable{
|
||||
Log.err(e);
|
||||
ui.showException(e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private @Nullable Schematic loadFile(Fi file){
|
||||
@@ -173,7 +170,7 @@ public class Schematics implements Loadable{
|
||||
Draw.flush();
|
||||
buffer.begin();
|
||||
Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, buffer.getWidth(), buffer.getHeight());
|
||||
file.writePNG(pixmap);
|
||||
file.writePng(pixmap);
|
||||
buffer.end();
|
||||
}
|
||||
|
||||
@@ -349,7 +346,7 @@ public class Schematics implements Loadable{
|
||||
for(int cx = x; cx <= x2; cx++){
|
||||
for(int cy = y; cy <= y2; cy++){
|
||||
Building linked = world.build(cx, cy);
|
||||
Block realBlock = linked == null ? null : linked instanceof ConstructBuild cons ? cons.cblock : linked.block;
|
||||
Block realBlock = linked == null ? null : linked instanceof ConstructBuild cons ? cons.current : linked.block;
|
||||
|
||||
if(linked != null && realBlock != null && (realBlock.isVisible() || realBlock instanceof CoreBlock)){
|
||||
int top = realBlock.size/2;
|
||||
@@ -378,7 +375,7 @@ public class Schematics implements Loadable{
|
||||
for(int cx = ox; cx <= ox2; cx++){
|
||||
for(int cy = oy; cy <= oy2; cy++){
|
||||
Building tile = world.build(cx, cy);
|
||||
Block realBlock = tile == null ? null : tile instanceof ConstructBuild cons ? cons.cblock : tile.block;
|
||||
Block realBlock = tile == null ? null : tile instanceof ConstructBuild cons ? cons.current : tile.block;
|
||||
|
||||
if(tile != null && !counted.contains(tile.pos()) && realBlock != null
|
||||
&& (realBlock.isVisible() || realBlock instanceof CoreBlock)){
|
||||
@@ -424,7 +421,7 @@ public class Schematics implements Loadable{
|
||||
Seq<Tile> seq = new Seq<>();
|
||||
if(coreTile == null) throw new IllegalArgumentException("Loadout schematic has no core tile!");
|
||||
int ox = x - coreTile.x, oy = y - coreTile.y;
|
||||
schem.tiles.each(st -> {
|
||||
schem.tiles.copy().sort(s -> -s.block.schematicPriority).each(st -> {
|
||||
Tile tile = world.tile(st.x + ox, st.y + oy);
|
||||
if(tile == null) return;
|
||||
|
||||
@@ -498,11 +495,19 @@ public class Schematics implements Loadable{
|
||||
short width = stream.readShort(), height = stream.readShort();
|
||||
|
||||
StringMap map = new StringMap();
|
||||
byte tags = stream.readByte();
|
||||
int tags = stream.readUnsignedByte();
|
||||
for(int i = 0; i < tags; i++){
|
||||
map.put(stream.readUTF(), stream.readUTF());
|
||||
}
|
||||
|
||||
String[] labels = null;
|
||||
|
||||
//try to read the categories, but skip if it fails
|
||||
try{
|
||||
labels = JsonIO.read(String[].class, map.get("labels", "[]"));
|
||||
}catch(Exception ignored){
|
||||
}
|
||||
|
||||
IntMap<Block> blocks = new IntMap<>();
|
||||
byte length = stream.readByte();
|
||||
for(int i = 0; i < length; i++){
|
||||
@@ -523,7 +528,9 @@ public class Schematics implements Loadable{
|
||||
}
|
||||
}
|
||||
|
||||
return new Schematic(tiles, map, width, height);
|
||||
Schematic out = new Schematic(tiles, map, width, height);
|
||||
if(labels != null) out.labels.addAll(labels);
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -540,6 +547,8 @@ public class Schematics implements Loadable{
|
||||
stream.writeShort(schematic.width);
|
||||
stream.writeShort(schematic.height);
|
||||
|
||||
schematic.tags.put("labels", JsonIO.write(schematic.labels.toArray(String.class)));
|
||||
|
||||
stream.writeByte(schematic.tags.size);
|
||||
for(ObjectMap.Entry<String, String> e : schematic.tags.entries()){
|
||||
stream.writeUTF(e.key);
|
||||
|
||||
@@ -9,6 +9,7 @@ import mindustry.maps.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.storage.CoreBlock.*;
|
||||
import mindustry.world.meta.*;
|
||||
import mindustry.world.modules.*;
|
||||
|
||||
import java.util.*;
|
||||
@@ -69,6 +70,8 @@ public class SectorInfo{
|
||||
public @Nullable String name;
|
||||
/** Displayed icon. */
|
||||
public @Nullable String icon;
|
||||
/** Displayed icon, as content. */
|
||||
public @Nullable UnlockableContent contentIcon;
|
||||
/** Version of generated waves. When it doesn't match, new waves are generated. */
|
||||
public int waveVersion = -1;
|
||||
/** Whether this sector was indicated to the player or not. */
|
||||
@@ -191,6 +194,13 @@ public class SectorInfo{
|
||||
stat.mean = Math.min(stat.mean, rawProduction.get(item, ExportStat::new).mean);
|
||||
});
|
||||
|
||||
var pads = indexer.getAllied(state.rules.defaultTeam, BlockFlag.launchPad);
|
||||
|
||||
//disable export when launch pads are disabled, or there aren't any active ones
|
||||
if(pads.size() == 0 || !Seq.with(pads).contains(t -> t.build.consValid())){
|
||||
export.clear();
|
||||
}
|
||||
|
||||
if(state.rules.sector != null){
|
||||
state.rules.sector.saveInfo();
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ public class Teams{
|
||||
public Seq<TeamData> active = new Seq<>();
|
||||
/** Teams with block or unit presence. */
|
||||
public Seq<TeamData> present = new Seq<>(TeamData.class);
|
||||
/** Current boss unit. */
|
||||
public @Nullable Unit boss;
|
||||
/** Current boss units. */
|
||||
public Seq<Unit> bosses = new Seq<>();
|
||||
|
||||
public Teams(){
|
||||
active.add(get(Team.crux));
|
||||
@@ -117,7 +117,6 @@ public class Teams{
|
||||
if(data.active() && !active.contains(data)){
|
||||
active.add(data);
|
||||
updateEnemies();
|
||||
indexer.updateTeamIndex(data.team);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +144,7 @@ public class Teams{
|
||||
|
||||
public void updateTeamStats(){
|
||||
present.clear();
|
||||
boss = null;
|
||||
bosses.clear();
|
||||
|
||||
for(Team team : Team.all){
|
||||
TeamData data = team.data();
|
||||
@@ -172,16 +171,17 @@ public class Teams{
|
||||
}
|
||||
|
||||
//update presence flag.
|
||||
Groups.build.each( b -> b.team.data().presentFlag = true);
|
||||
Groups.build.each(b -> b.team.data().presentFlag = true);
|
||||
|
||||
for(Unit unit : Groups.unit){
|
||||
if(unit.type == null) continue;
|
||||
TeamData data = unit.team.data();
|
||||
data.tree().insert(unit);
|
||||
data.units.add(unit);
|
||||
data.presentFlag = true;
|
||||
|
||||
if(unit.team == state.rules.waveTeam && unit.isBoss()){
|
||||
boss = unit;
|
||||
bosses.add(unit);
|
||||
}
|
||||
|
||||
if(data.unitsByType == null || data.unitsByType.length <= unit.type.id){
|
||||
@@ -241,12 +241,17 @@ public class Teams{
|
||||
/** Target items to mine. */
|
||||
public Seq<Item> mineItems = Seq.with(Items.copper, Items.lead, Items.titanium, Items.thorium);
|
||||
|
||||
/** Quadtree for all buildings of this team. Null if not active. */
|
||||
@Nullable
|
||||
public QuadTree<Building> buildings;
|
||||
/** Current unit cap. Do not modify externally. */
|
||||
public int unitCap;
|
||||
/** Total unit count. */
|
||||
public int unitCount;
|
||||
/** Counts for each type of unit. Do not access directly. */
|
||||
@Nullable
|
||||
public int[] typeCounts;
|
||||
/** Quadtree for units of this type. Do not access directly. */
|
||||
/** Quadtree for units of this team. Do not access directly. */
|
||||
@Nullable
|
||||
public QuadTree<Unit> tree;
|
||||
/** Units of this team. Updated each frame. */
|
||||
@@ -328,5 +333,16 @@ public class Teams{
|
||||
this.block = block;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return "BlockPlan{" +
|
||||
"x=" + x +
|
||||
", y=" + y +
|
||||
", rotation=" + rotation +
|
||||
", block=" + block +
|
||||
", config=" + config +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import arc.util.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.game.SectorInfo.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.maps.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.blocks.storage.*;
|
||||
@@ -236,6 +237,10 @@ public class Universe{
|
||||
state.rules.winWave = waveMax;
|
||||
state.rules.waves = true;
|
||||
state.rules.attackMode = false;
|
||||
//update rules in multiplayer
|
||||
if(net.server()){
|
||||
Call.setRules(state.rules);
|
||||
}
|
||||
}else{
|
||||
sector.info.winWave = waveMax;
|
||||
sector.info.waves = true;
|
||||
|
||||
Reference in New Issue
Block a user