Merge branch 'master' into schematic

This commit is contained in:
J-VdS
2020-09-23 16:29:41 +02:00
committed by GitHub
563 changed files with 30174 additions and 22699 deletions
+2 -2
View File
@@ -163,14 +163,14 @@ public class DefaultWaves{
spacing = 3;
}},
new SpawnGroup(UnitTypes.vestige){{
new SpawnGroup(UnitTypes.scepter){{
begin = 41;
unitAmount = 1;
unitScaling = 1;
spacing = 30;
}},
new SpawnGroup(UnitTypes.cataclyst){{
new SpawnGroup(UnitTypes.reign){{
begin = 81;
unitAmount = 1;
unitScaling = 1;
+5 -4
View File
@@ -170,11 +170,10 @@ public class EventType{
}
}
/** Called from the logic thread. Do not access graphics here! */
public static class BuildinghangeEvent{
public static class TileChangeEvent{
public final Tile tile;
public BuildinghangeEvent(Tile tile){
public TileChangeEvent(Tile tile){
this.tile = tile;
}
}
@@ -225,12 +224,14 @@ public class EventType{
public final Team team;
public final @Nullable Unit unit;
public final boolean breaking;
public final @Nullable Object config;
public BlockBuildEndEvent(Tile tile, @Nullable Unit unit, Team team, boolean breaking){
public BlockBuildEndEvent(Tile tile, @Nullable Unit unit, Team team, boolean breaking, @Nullable Object config){
this.tile = tile;
this.team = team;
this.unit = unit;
this.breaking = breaking;
this.config = config;
}
}
-3
View File
@@ -91,9 +91,6 @@ public class Rules{
public boolean enemyLights = true;
/** Ambient light color, used when lighting is enabled. */
public Color ambientLight = new Color(0.01f, 0.01f, 0.04f, 0.99f);
/** Multiplier for solar panel power output.
negative = use ambient light if lighting is enabled. */
public float solarPowerMultiplier = -1f;
/** team of the player by default */
public Team defaultTeam = Team.sharded;
/** team of the enemy in waves/sectors */
+11 -9
View File
@@ -61,6 +61,9 @@ public class Saves{
//automatically assign sector save slots
for(SaveSlot slot : saves){
if(slot.getSector() != null){
if(slot.getSector().save != null){
Log.warn("Sector @ has two corresponding saves: @ and @", slot.getSector(), slot.getSector().save.file, slot.file);
}
slot.getSector().save = slot;
}
}
@@ -75,7 +78,6 @@ public class Saves{
}
public void update(){
SaveSlot current = this.current;
if(current != null && state.isGame()
&& !(state.isPaused() && Core.scene.hasDialog())){
@@ -90,14 +92,13 @@ public class Saves{
if(time > Core.settings.getInt("saveinterval") * 60){
saving = true;
Time.runTask(2f, () -> {
try{
current.save();
}catch(Throwable e){
e.printStackTrace();
}
saving = false;
});
try{
current.save();
}catch(Throwable e){
e.printStackTrace();
}
Time.runTask(3f, () -> saving = false);
time = 0;
}
@@ -128,6 +129,7 @@ public class Saves{
sector.save.setName(sector.save.file.nameWithoutExtension());
saves.add(sector.save);
}
sector.save.setAutosave(true);
sector.save.save();
lastSectorSave = sector.save;
Core.settings.put("last-sector-save", sector.save.getName());
+5 -14
View File
@@ -2,9 +2,7 @@ package mindustry.game;
import arc.files.*;
import arc.struct.*;
import arc.struct.IntIntMap.*;
import arc.util.ArcAnnotate.*;
import mindustry.*;
import mindustry.content.*;
import mindustry.mod.Mods.*;
import mindustry.type.*;
@@ -12,7 +10,6 @@ import mindustry.world.*;
import mindustry.world.blocks.power.*;
import mindustry.world.blocks.storage.*;
import mindustry.world.consumers.*;
import mindustry.world.meta.*;
import static mindustry.Vars.*;
@@ -39,22 +36,16 @@ public class Schematic implements Publishable, Comparable<Schematic>{
return tiles.sumf(s -> s.block.consumes.has(ConsumeType.power) ? s.block.consumes.getPower().usage : 0f);
}
public Seq<ItemStack> requirements(){
IntIntMap amounts = new IntIntMap();
public ItemSeq requirements(){
ItemSeq requirements = new ItemSeq();
tiles.each(t -> {
if(t.block.buildVisibility == BuildVisibility.hidden) return;
for(ItemStack stack : t.block.requirements){
amounts.increment(stack.item.id, stack.amount);
requirements.add(stack.item, stack.amount);
}
});
Seq<ItemStack> stacks = new Seq<>();
for(Entry ent : amounts.entries()){
stacks.add(new ItemStack(Vars.content.item(ent.key), ent.value));
}
stacks.sort();
return stacks;
return requirements;
}
public boolean hasCore(){
+12 -10
View File
@@ -28,6 +28,7 @@ import mindustry.io.*;
import mindustry.world.*;
import mindustry.world.blocks.*;
import mindustry.world.blocks.distribution.*;
import mindustry.world.blocks.legacy.*;
import mindustry.world.blocks.power.*;
import mindustry.world.blocks.production.*;
import mindustry.world.blocks.sandbox.*;
@@ -247,7 +248,7 @@ public class Schematics implements Loadable{
Draw.rect(Tmp.tr1, buffer.getWidth()/2f, buffer.getHeight()/2f, buffer.getWidth(), -buffer.getHeight());
Draw.color();
Seq<BuildPlan> requests = schematic.tiles.map(t -> new BuildPlan(t.x, t.y, t.rotation, t.block).configure(t.config));
Seq<BuildPlan> requests = schematic.tiles.map(t -> new BuildPlan(t.x, t.y, t.rotation, t.block, t.config));
Draw.flush();
//scale each request to fit schematic
@@ -278,7 +279,7 @@ public class Schematics implements Loadable{
/** Creates an array of build requests from a schematic's data, centered on the provided x+y coordinates. */
public Seq<BuildPlan> toRequests(Schematic schem, int x, int y){
return schem.tiles.map(t -> new BuildPlan(t.x + x - schem.width/2, t.y + y - schem.height/2, t.rotation, t.block).original(t.x, t.y, schem.width, schem.height).configure(t.config))
return schem.tiles.map(t -> new BuildPlan(t.x + x - schem.width/2, t.y + y - schem.height/2, t.rotation, t.block, t.config).original(t.x, t.y, schem.width, schem.height))
.removeAll(s -> !s.block.isVisible() || !s.block.unlockedNow());
}
@@ -346,9 +347,9 @@ public class Schematics implements Loadable{
for(int cy = y; cy <= y2; cy++){
Building linked = world.build(cx, cy);
if(linked != null &&linked.block().isVisible() && !(linked.block() instanceof BuildBlock)){
int top = linked.block().size/2;
int bot = linked.block().size % 2 == 1 ? -linked.block().size/2 : -(linked.block().size - 1)/2;
if(linked != null && linked.block.isVisible() && !(linked.block instanceof ConstructBlock)){
int top = linked.block.size/2;
int bot = linked.block.size % 2 == 1 ? -linked.block.size/2 : -(linked.block.size - 1)/2;
minx = Math.min(linked.tileX() + bot, minx);
miny = Math.min(linked.tileY() + bot, miny);
maxx = Math.max(linked.tileX() + top, maxx);
@@ -374,11 +375,11 @@ public class Schematics implements Loadable{
for(int cy = oy; cy <= oy2; cy++){
Building tile = world.build(cx, cy);
if(tile != null && !counted.contains(tile.pos()) && !(tile.block() instanceof BuildBlock)
&& (tile.block().isVisible() || (tile.block() instanceof CoreBlock))){
if(tile != null && !counted.contains(tile.pos()) && !(tile.block instanceof ConstructBlock)
&& (tile.block.isVisible() || (tile.block instanceof CoreBlock))){
Object config = tile.config();
tiles.add(new Stile(tile.block(), tile.tileX() + offsetX, tile.tileY() + offsetY, config, (byte)tile.rotation));
tiles.add(new Stile(tile.block, tile.tileX() + offsetX, tile.tileY() + offsetY, config, (byte)tile.rotation));
counted.add(tile.pos());
}
}
@@ -486,8 +487,9 @@ public class Schematics implements Loadable{
IntMap<Block> blocks = new IntMap<>();
byte length = stream.readByte();
for(int i = 0; i < length; i++){
Block block = Vars.content.getByName(ContentType.block, stream.readUTF());
blocks.put(i, block == null ? Blocks.air : block);
String name = stream.readUTF();
Block block = Vars.content.getByName(ContentType.block, SaveFileReader.fallback.get(name, name));
blocks.put(i, block == null || block instanceof LegacyBlock ? Blocks.air : block);
}
int total = stream.readInt();
+7 -6
View File
@@ -2,9 +2,10 @@ package mindustry.game;
import arc.math.*;
import arc.struct.*;
import arc.util.*;
import arc.util.ArcAnnotate.*;
import arc.util.*;
import mindustry.content.*;
import mindustry.ctype.*;
import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.blocks.storage.CoreBlock.*;
@@ -32,6 +33,8 @@ public class SectorInfo{
public boolean hasCore = true;
/** Sector that was launched from. */
public @Nullable Sector origin;
/** Resources known to occur at this sector. */
public Seq<UnlockableContent> resources = new Seq<>();
/** Time spent at this sector. Do not use unless you know what you're doing. */
public transient float internalTimeSpent;
@@ -84,12 +87,10 @@ public class SectorInfo{
/** Update averages of various stats, updates some special sector logic.
* Called every frame. */
public void update(){
internalTimeSpent += Time.delta;
//updating in multiplayer as a client doesn't make sense
if(net.client()) return;
//time spent exceeds turn duration!
if(internalTimeSpent >= turnDuration && internalTimeSpent - Time.delta < turnDuration){
universe.displayTimeEnd();
}
internalTimeSpent += Time.delta;
//create last stored core items
if(lastCoreItems == null){
+1 -1
View File
@@ -39,7 +39,7 @@ public class Stats{
//weigh used fractions
float frac = 0f;
Seq<Item> obtainable = Seq.select(zone.data.resources, i -> i instanceof Item).as();
Seq<Item> obtainable = zone.save == null ? new Seq<>() : zone.save.meta.secinfo.resources.select(i -> i instanceof Item).as();
for(Item item : obtainable){
frac += Mathf.clamp((float)itemsDelivered.get(item, 0) / capacity) / (float)obtainable.size;
}
+1 -1
View File
@@ -250,7 +250,7 @@ public class Tutorial{
Building core = state.teams.playerCores().first();
for(int i = 0; i < blocksToBreak; i++){
if(world.tile(core.tile().x + blockOffset, core.tile().y + i).block() == Blocks.scrapWall){
if(world.tile(core.tile.x + blockOffset, core.tile.y + i).block() == Blocks.scrapWall){
return false;
}
}
+45 -22
View File
@@ -14,12 +14,13 @@ import static mindustry.Vars.*;
/** Updates and handles state of the campaign universe. Has no relevance to other gamemodes. */
public class Universe{
private long seconds;
private int seconds;
private int netSeconds;
private float secondCounter;
private int turn;
private Schematic lastLoadout;
private Seq<ItemStack> lastLaunchResources = new Seq<>();
private ItemSeq lastLaunchResources = new ItemSeq();
public Universe(){
load();
@@ -55,23 +56,40 @@ public class Universe{
public void displayTimeEnd(){
if(!headless){
state.set(State.paused);
//check if any sectors are under attack to display this
Seq<Sector> attacked = state.getSector().planet.sectors.select(s -> s.hasWaves() && s.hasBase() && !s.isBeingPlayed() && s.getSecondsPassed() > 1);
ui.announce("Next turn incoming.");
if(attacked.any()){
state.set(State.paused);
//TODO localize
String text = attacked.size > 1 ? attacked.size + " sectors attacked." : "Sector " + attacked.first().id + " under attack.";
ui.hudfrag.sectorText = text;
ui.hudfrag.attackedSectors = attacked;
ui.announce(text);
}else{
//autorun next turn
universe.runTurn();
}
}
}
/** Update planet rotations, global time and relevant state. */
public void update(){
secondCounter += Time.delta / 60f;
if(secondCounter >= 1){
seconds += (int)secondCounter;
secondCounter %= 1f;
//only update time when not in multiplayer
if(!net.client()){
secondCounter += Time.delta / 60f;
//save every few seconds
if(seconds % 10 == 1){
save();
if(secondCounter >= 1){
seconds += (int)secondCounter;
secondCounter %= 1f;
//save every few seconds
if(seconds % 10 == 1){
save();
}
}
}
@@ -86,14 +104,14 @@ public class Universe{
}
}
public Seq<ItemStack> getLaunchResources(){
lastLaunchResources = Core.settings.getJson("launch-resources", Seq.class, ItemStack.class, Seq::new);
public ItemSeq getLaunchResources(){
lastLaunchResources = Core.settings.getJson("launch-resources-seq", ItemSeq.class, ItemSeq::new);
return lastLaunchResources;
}
public void updateLaunchResources(Seq<ItemStack> stacks){
public void updateLaunchResources(ItemSeq stacks){
this.lastLaunchResources = stacks;
Core.settings.putJson("launch-resources", ItemStack.class, lastLaunchResources);
Core.settings.putJson("launch-resources-seq", lastLaunchResources);
}
/** Updates selected loadout for future deployment. */
@@ -178,25 +196,30 @@ public class Universe{
return count;
}
public float secondsMod(float mod, float scale){
return (seconds / scale) % mod;
public void updateNetSeconds(int value){
netSeconds = value;
}
public long seconds(){
return seconds;
public float secondsMod(float mod, float scale){
return (seconds() / scale) % mod;
}
public int seconds(){
//use networked seconds when playing as client
return net.client() ? netSeconds : seconds;
}
public float secondsf(){
return seconds + secondCounter;
return seconds() + secondCounter;
}
private void save(){
Core.settings.put("utime", seconds);
Core.settings.put("utimei", seconds);
Core.settings.put("turn", turn);
}
private void load(){
seconds = Core.settings.getLong("utime");
seconds = Core.settings.getInt("utimei");
turn = Core.settings.getInt("turn");
}