Merge branch '6.0' of https://github.com/Anuken/Mindustry into object-config
# Conflicts: # core/src/mindustry/entities/traits/BuilderTrait.java # core/src/mindustry/entities/type/TileEntity.java # core/src/mindustry/game/EventType.java # core/src/mindustry/game/Schematics.java # core/src/mindustry/input/InputHandler.java # core/src/mindustry/io/TypeIO.java # core/src/mindustry/world/Block.java # core/src/mindustry/world/blocks/distribution/Sorter.java
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
package mindustry.game;
|
||||
|
||||
import arc.Core;
|
||||
|
||||
/** Presets for time between waves. Currently unused.*/
|
||||
public enum Difficulty{
|
||||
easy(1.4f),
|
||||
normal(1f),
|
||||
hard(0.5f),
|
||||
insane(0.25f);
|
||||
|
||||
/** Multiplier of the time between waves. */
|
||||
public final float waveTime;
|
||||
|
||||
private String value;
|
||||
|
||||
Difficulty(float waveTime){
|
||||
this.waveTime = waveTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
if(value == null){
|
||||
value = Core.bundle.get("setting.difficulty." + name());
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
package mindustry.game;
|
||||
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import mindustry.core.GameState.State;
|
||||
import mindustry.ctype.UnlockableContent;
|
||||
import mindustry.entities.traits.BuilderTrait;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.core.GameState.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.Tile;
|
||||
import mindustry.world.*;
|
||||
|
||||
public class EventType{
|
||||
|
||||
@@ -62,10 +61,10 @@ public class EventType{
|
||||
}
|
||||
|
||||
public static class PlayerChatEvent{
|
||||
public final Player player;
|
||||
public final Playerc player;
|
||||
public final String message;
|
||||
|
||||
public PlayerChatEvent(Player player, String message){
|
||||
public PlayerChatEvent(Playerc player, String message){
|
||||
this.player = player;
|
||||
this.message = message;
|
||||
}
|
||||
@@ -92,6 +91,10 @@ public class EventType{
|
||||
}
|
||||
}
|
||||
|
||||
public static class ClientCreateEvent{
|
||||
|
||||
}
|
||||
|
||||
/** Called when the client game is first loaded. */
|
||||
public static class ClientLoadEvent{
|
||||
|
||||
@@ -144,11 +147,11 @@ public class EventType{
|
||||
/** Called when the player withdraws items from a block. */
|
||||
public static class WithdrawEvent{
|
||||
public final Tile tile;
|
||||
public final Player player;
|
||||
public final Playerc player;
|
||||
public final Item item;
|
||||
public final int amount;
|
||||
|
||||
public WithdrawEvent(Tile tile, Player player, Item item, int amount){
|
||||
public WithdrawEvent(Tile tile, Playerc player, Item item, int amount){
|
||||
this.tile = tile;
|
||||
this.player = player;
|
||||
this.item = item;
|
||||
@@ -159,11 +162,11 @@ public class EventType{
|
||||
/** Called when a player deposits items to a block.*/
|
||||
public static class DepositEvent{
|
||||
public final Tile tile;
|
||||
public final Player player;
|
||||
public final Playerc player;
|
||||
public final Item item;
|
||||
public final int amount;
|
||||
|
||||
public DepositEvent(Tile tile, Player player, Item item, int amount){
|
||||
public DepositEvent(Tile tile, Playerc player, Item item, int amount){
|
||||
this.tile = tile;
|
||||
this.player = player;
|
||||
this.item = item;
|
||||
@@ -174,9 +177,9 @@ public class EventType{
|
||||
/** Called when the player taps a block. */
|
||||
public static class TapEvent{
|
||||
public final Tile tile;
|
||||
public final Player player;
|
||||
public final Playerc player;
|
||||
|
||||
public TapEvent(Tile tile, Player player){
|
||||
public TapEvent(Tile tile, Playerc player){
|
||||
this.tile = tile;
|
||||
this.player = player;
|
||||
}
|
||||
@@ -185,10 +188,10 @@ public class EventType{
|
||||
/** Called when the player sets a specific block. */
|
||||
public static class TapConfigEvent{
|
||||
public final Tile tile;
|
||||
public final Player player;
|
||||
public final Playerc player;
|
||||
public final Object value;
|
||||
|
||||
public TapConfigEvent(Tile tile, Player player, Object value){
|
||||
public TapConfigEvent(Tile tile, Playerc player, Object value){
|
||||
this.tile = tile;
|
||||
this.player = player;
|
||||
this.value = value;
|
||||
@@ -261,14 +264,13 @@ public class EventType{
|
||||
public static class BlockBuildEndEvent{
|
||||
public final Tile tile;
|
||||
public final Team team;
|
||||
public final @Nullable
|
||||
Player player;
|
||||
public final @Nullable Unitc unit;
|
||||
public final boolean breaking;
|
||||
|
||||
public BlockBuildEndEvent(Tile tile, @Nullable Player player, Team team, boolean breaking){
|
||||
public BlockBuildEndEvent(Tile tile, @Nullable Unitc unit, Team team, boolean breaking){
|
||||
this.tile = tile;
|
||||
this.team = team;
|
||||
this.player = player;
|
||||
this.unit = unit;
|
||||
this.breaking = breaking;
|
||||
}
|
||||
}
|
||||
@@ -280,10 +282,10 @@ public class EventType{
|
||||
public static class BuildSelectEvent{
|
||||
public final Tile tile;
|
||||
public final Team team;
|
||||
public final BuilderTrait builder;
|
||||
public final Builderc builder;
|
||||
public final boolean breaking;
|
||||
|
||||
public BuildSelectEvent(Tile tile, Team team, BuilderTrait builder, boolean breaking){
|
||||
public BuildSelectEvent(Tile tile, Team team, Builderc builder, boolean breaking){
|
||||
this.tile = tile;
|
||||
this.team = team;
|
||||
this.builder = builder;
|
||||
@@ -302,17 +304,17 @@ public class EventType{
|
||||
}
|
||||
|
||||
public static class UnitDestroyEvent{
|
||||
public final Unit unit;
|
||||
public final Unitc unit;
|
||||
|
||||
public UnitDestroyEvent(Unit unit){
|
||||
public UnitDestroyEvent(Unitc unit){
|
||||
this.unit = unit;
|
||||
}
|
||||
}
|
||||
|
||||
public static class UnitCreateEvent{
|
||||
public final BaseUnit unit;
|
||||
public final Unitc unit;
|
||||
|
||||
public UnitCreateEvent(BaseUnit unit){
|
||||
public UnitCreateEvent(Unitc unit){
|
||||
this.unit = unit;
|
||||
}
|
||||
}
|
||||
@@ -321,11 +323,12 @@ public class EventType{
|
||||
|
||||
}
|
||||
|
||||
//TODO rename
|
||||
public static class MechChangeEvent{
|
||||
public final Player player;
|
||||
public final Mech mech;
|
||||
public final Playerc player;
|
||||
public final UnitType mech;
|
||||
|
||||
public MechChangeEvent(Player player, Mech mech){
|
||||
public MechChangeEvent(Playerc player, UnitType mech){
|
||||
this.player = player;
|
||||
this.mech = mech;
|
||||
}
|
||||
@@ -333,42 +336,42 @@ public class EventType{
|
||||
|
||||
/** Called after connecting; when a player recieves world data and is ready to play.*/
|
||||
public static class PlayerJoin{
|
||||
public final Player player;
|
||||
public final Playerc player;
|
||||
|
||||
public PlayerJoin(Player player){
|
||||
public PlayerJoin(Playerc player){
|
||||
this.player = player;
|
||||
}
|
||||
}
|
||||
|
||||
/** Called when a player connects, but has not joined the game yet.*/
|
||||
public static class PlayerConnect{
|
||||
public final Player player;
|
||||
public final Playerc player;
|
||||
|
||||
public PlayerConnect(Player player){
|
||||
public PlayerConnect(Playerc player){
|
||||
this.player = player;
|
||||
}
|
||||
}
|
||||
|
||||
public static class PlayerLeave{
|
||||
public final Player player;
|
||||
public final Playerc player;
|
||||
|
||||
public PlayerLeave(Player player){
|
||||
public PlayerLeave(Playerc player){
|
||||
this.player = player;
|
||||
}
|
||||
}
|
||||
|
||||
public static class PlayerBanEvent{
|
||||
public final Player player;
|
||||
public final Playerc player;
|
||||
|
||||
public PlayerBanEvent(Player player){
|
||||
public PlayerBanEvent(Playerc player){
|
||||
this.player = player;
|
||||
}
|
||||
}
|
||||
|
||||
public static class PlayerUnbanEvent{
|
||||
public final Player player;
|
||||
public final Playerc player;
|
||||
|
||||
public PlayerUnbanEvent(Player player){
|
||||
public PlayerUnbanEvent(Playerc player){
|
||||
this.player = player;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package mindustry.game;
|
||||
import arc.*;
|
||||
import arc.struct.*;
|
||||
import arc.files.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.*;
|
||||
import mindustry.content.*;
|
||||
@@ -19,6 +20,8 @@ import static mindustry.Vars.*;
|
||||
public class GlobalData{
|
||||
private ObjectMap<ContentType, ObjectSet<String>> unlocked = new ObjectMap<>();
|
||||
private ObjectIntMap<Item> items = new ObjectIntMap<>();
|
||||
private Array<Satellite> satellites = new Array<>();
|
||||
private ObjectMap<String, MapRegion> regions = new ObjectMap<>();
|
||||
private boolean modified;
|
||||
|
||||
public GlobalData(){
|
||||
@@ -35,6 +38,10 @@ public class GlobalData{
|
||||
});
|
||||
}
|
||||
|
||||
public @Nullable MapRegion getRegion(String name){
|
||||
return regions.get(name);
|
||||
}
|
||||
|
||||
public void exportData(Fi file) throws IOException{
|
||||
Array<Fi> files = new Array<>();
|
||||
files.add(Core.settings.getSettingsFile());
|
||||
@@ -49,7 +56,7 @@ public class GlobalData{
|
||||
for(Fi add : files){
|
||||
if(add.isDirectory()) continue;
|
||||
zos.putNextEntry(new ZipEntry(add.path().substring(base.length())));
|
||||
Streams.copyStream(add.read(), zos);
|
||||
Streams.copy(add.read(), zos);
|
||||
zos.closeEntry();
|
||||
}
|
||||
|
||||
|
||||
12
core/src/mindustry/game/MapRegion.java
Normal file
12
core/src/mindustry/game/MapRegion.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package mindustry.game;
|
||||
|
||||
/** Defines a special map that can be visited, loaded, and saved. */
|
||||
public abstract class MapRegion{
|
||||
|
||||
/** Name of the region. Used for lookup and save names. */
|
||||
public abstract String name();
|
||||
|
||||
public void load(){
|
||||
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,7 @@ public class MusicControl{
|
||||
public void update(){
|
||||
if(state.is(State.menu)){
|
||||
silenced = false;
|
||||
if(ui.deploy.isShown()){
|
||||
if(ui.planet.isShown()){
|
||||
play(Musics.launch);
|
||||
}else if(ui.editor.isShown()){
|
||||
play(Musics.editor);
|
||||
@@ -83,7 +83,7 @@ public class MusicControl{
|
||||
|
||||
/** Whether to play dark music.*/
|
||||
private boolean isDark(){
|
||||
if(state.teams.get(player.getTeam()).hasCore() && state.teams.get(player.getTeam()).core().healthf() < 0.85f){
|
||||
if(state.teams.get(player.team()).hasCore() && state.teams.get(player.team()).core().healthf() < 0.85f){
|
||||
//core damaged -> dark
|
||||
return true;
|
||||
}
|
||||
@@ -100,6 +100,8 @@ public class MusicControl{
|
||||
/** Plays and fades in a music track. This must be called every frame.
|
||||
* If something is already playing, fades out that track and fades in this new music.*/
|
||||
private void play(@Nullable Music music){
|
||||
if(!shouldPlay()) return;
|
||||
|
||||
//update volume of current track
|
||||
if(current != null){
|
||||
current.setVolume(fade * Core.settings.getInt("musicvol") / 100f);
|
||||
@@ -143,7 +145,7 @@ public class MusicControl{
|
||||
|
||||
/** Plays a music track once and only once. If something is already playing, does nothing.*/
|
||||
private void playOnce(Music music){
|
||||
if(current != null || music == null) return; //do not interrupt already-playing tracks
|
||||
if(current != null || music == null || !shouldPlay()) return; //do not interrupt already-playing tracks
|
||||
|
||||
//save last random track played to prevent duplicates
|
||||
lastRandomPlayed = music;
|
||||
@@ -162,6 +164,10 @@ public class MusicControl{
|
||||
current.play();
|
||||
}
|
||||
|
||||
private boolean shouldPlay(){
|
||||
return Core.settings.getInt("musicvol") > 0;
|
||||
}
|
||||
|
||||
/** Fades out the current track, unless it has already been silenced. */
|
||||
private void silence(){
|
||||
play(null);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package mindustry.game;
|
||||
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import arc.struct.*;
|
||||
import arc.graphics.*;
|
||||
@@ -56,8 +57,10 @@ public class Rules{
|
||||
public float bossWaveMultiplier = 3f;
|
||||
/** How many times longer a launch wave takes. */
|
||||
public float launchWaveMultiplier = 2f;
|
||||
/** Zone for saves that have them.*/
|
||||
public Zone zone;
|
||||
/** Sector for saves that have them.*/
|
||||
public @Nullable Sector sector;
|
||||
/** Region that save is on. Indicates campaign. */
|
||||
public @Nullable MapRegion region;
|
||||
/** Spawn layout. */
|
||||
public Array<SpawnGroup> spawns = new Array<>();
|
||||
/** Determines if there should be limited respawns. */
|
||||
@@ -74,6 +77,9 @@ public class Rules{
|
||||
public boolean tutorial = false;
|
||||
/** Whether a gameover can happen at all. Set this to false to implement custom gameover conditions. */
|
||||
public boolean canGameOver = true;
|
||||
/** Whether to draw shadows of blocks at map edges and static blocks.
|
||||
* Do not change unless you know exactly what you are doing.*/
|
||||
public boolean drawFog = true;
|
||||
/** Starting items put in cores */
|
||||
public Array<ItemStack> loadout = Array.with(ItemStack.with(Items.copper, 100));
|
||||
/** Blocks that cannot be placed. */
|
||||
@@ -82,6 +88,9 @@ public class Rules{
|
||||
public boolean lighting = false;
|
||||
/** 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 */
|
||||
|
||||
@@ -6,6 +6,7 @@ import arc.struct.*;
|
||||
import arc.files.*;
|
||||
import arc.graphics.*;
|
||||
import arc.util.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.async.*;
|
||||
import mindustry.*;
|
||||
import mindustry.core.GameState.*;
|
||||
@@ -23,11 +24,11 @@ import static mindustry.Vars.*;
|
||||
|
||||
public class Saves{
|
||||
private Array<SaveSlot> saves = new Array<>();
|
||||
private SaveSlot current;
|
||||
private @Nullable SaveSlot current;
|
||||
private @Nullable SaveSlot lastSectorSave;
|
||||
private AsyncExecutor previewExecutor = new AsyncExecutor(1);
|
||||
private boolean saving;
|
||||
private float time;
|
||||
private Fi zoneFile;
|
||||
|
||||
private long totalPlaytime;
|
||||
private long lastTimestamp;
|
||||
@@ -46,7 +47,6 @@ public class Saves{
|
||||
|
||||
public void load(){
|
||||
saves.clear();
|
||||
zoneFile = saveDirectory.child("-1.msav");
|
||||
|
||||
for(Fi file : saveDirectory.list()){
|
||||
if(!file.name().contains("backup") && SaveIO.isSaveValid(file)){
|
||||
@@ -55,9 +55,22 @@ public class Saves{
|
||||
slot.meta = SaveIO.getMeta(file);
|
||||
}
|
||||
}
|
||||
|
||||
lastSectorSave = saves.find(s -> s.isSector() && s.getName().equals(Core.settings.getString("last-sector-save", "<none>")));
|
||||
|
||||
//automatically assign sector save slots
|
||||
for(SaveSlot slot : saves){
|
||||
if(slot.getSector() != null){
|
||||
slot.getSector().save = slot;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SaveSlot getCurrent(){
|
||||
public @Nullable SaveSlot getLastSector(){
|
||||
return lastSectorSave;
|
||||
}
|
||||
|
||||
public @Nullable SaveSlot getCurrent(){
|
||||
return current;
|
||||
}
|
||||
|
||||
@@ -80,7 +93,7 @@ public class Saves{
|
||||
Time.runTask(2f, () -> {
|
||||
try{
|
||||
current.save();
|
||||
}catch(Exception e){
|
||||
}catch(Throwable e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
saving = false;
|
||||
@@ -105,12 +118,19 @@ public class Saves{
|
||||
return saving;
|
||||
}
|
||||
|
||||
public void zoneSave(){
|
||||
SaveSlot slot = new SaveSlot(zoneFile);
|
||||
slot.setName("zone");
|
||||
saves.remove(s -> s.file.equals(zoneFile));
|
||||
saves.add(slot);
|
||||
slot.save();
|
||||
public Fi getSectorFile(Sector sector){
|
||||
return saveDirectory.child("sector-" + sector.planet.name + "-" + sector.id + "." + saveExtension);
|
||||
}
|
||||
|
||||
public void saveSector(Sector sector){
|
||||
if(sector.save == null){
|
||||
sector.save = new SaveSlot(getSectorFile(sector));
|
||||
sector.save.setName(sector.save.file.nameWithoutExtension());
|
||||
saves.add(sector.save);
|
||||
}
|
||||
sector.save.save();
|
||||
lastSectorSave = sector.save;
|
||||
Core.settings.putSave("last-sector-save", sector.save.getName());
|
||||
}
|
||||
|
||||
public SaveSlot addSave(String name){
|
||||
@@ -131,11 +151,6 @@ public class Saves{
|
||||
return slot;
|
||||
}
|
||||
|
||||
public SaveSlot getZoneSlot(){
|
||||
SaveSlot slot = getSaveSlots().find(s -> s.file.equals(zoneFile));
|
||||
return slot == null || slot.getZone() == null ? null : slot;
|
||||
}
|
||||
|
||||
public Fi getNextSlotFile(){
|
||||
int i = 0;
|
||||
Fi file;
|
||||
@@ -150,7 +165,6 @@ public class Saves{
|
||||
}
|
||||
|
||||
public class SaveSlot{
|
||||
//public final int index;
|
||||
public final Fi file;
|
||||
boolean requestedPreview;
|
||||
SaveMeta meta;
|
||||
@@ -225,7 +239,7 @@ public class Saves{
|
||||
}
|
||||
|
||||
public boolean isHidden(){
|
||||
return getZone() != null;
|
||||
return isSector();
|
||||
}
|
||||
|
||||
public String getPlayTime(){
|
||||
@@ -268,8 +282,12 @@ public class Saves{
|
||||
return meta.mods;
|
||||
}
|
||||
|
||||
public Zone getZone(){
|
||||
return meta == null || meta.rules == null ? null : meta.rules.zone;
|
||||
public Sector getSector(){
|
||||
return meta == null || meta.rules == null ? null : meta.rules.sector;
|
||||
}
|
||||
|
||||
public boolean isSector(){
|
||||
return getSector() != null;
|
||||
}
|
||||
|
||||
public Gamemode mode(){
|
||||
@@ -311,7 +329,7 @@ public class Saves{
|
||||
|
||||
public void delete(){
|
||||
file.delete();
|
||||
saves.removeValue(this, true);
|
||||
saves.remove(this, true);
|
||||
if(this == current){
|
||||
current = null;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package mindustry.game;
|
||||
|
||||
import arc.*;
|
||||
import arc.assets.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.files.*;
|
||||
import arc.graphics.*;
|
||||
@@ -14,7 +15,7 @@ import arc.util.serialization.*;
|
||||
import mindustry.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.ctype.ContentType;
|
||||
import mindustry.entities.traits.BuilderTrait.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.game.Schematic.*;
|
||||
import mindustry.input.*;
|
||||
@@ -315,7 +316,7 @@ public class Schematics implements Loadable{
|
||||
for(int cy = y; cy <= y2; cy++){
|
||||
Tile linked = world.ltile(cx, cy);
|
||||
|
||||
if(linked != null && linked.entity != null && linked.entity.block.isVisible() && !(linked.block() instanceof BuildBlock)){
|
||||
if(linked != null && linked.entity != null && linked.entity.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;
|
||||
minx = Math.min(linked.x + bot, minx);
|
||||
@@ -344,9 +345,9 @@ public class Schematics implements Loadable{
|
||||
Tile tile = world.ltile(cx, cy);
|
||||
|
||||
if(tile != null && tile.entity != null && !counted.contains(tile.pos()) && !(tile.block() instanceof BuildBlock)
|
||||
&& (tile.entity.block.isVisible() || (tile.entity.block instanceof CoreBlock && Core.settings.getBool("coreselect")))){
|
||||
&& (tile.entity.block().isVisible() || (tile.entity.block() instanceof CoreBlock && Core.settings.getBool("coreselect")))){
|
||||
Object config = tile.entity.config();
|
||||
if(tile.block().posConfig){
|
||||
if(config instanceof Point2){
|
||||
config = Pos.get(Pos.x(config) + offsetX, Pos.y(config) + offsetY);
|
||||
}
|
||||
|
||||
@@ -375,7 +376,7 @@ public class Schematics implements Loadable{
|
||||
/** Loads a schematic from base64. May throw an exception. */
|
||||
public static Schematic readBase64(String schematic){
|
||||
try{
|
||||
return read(new ByteArrayInputStream(Base64Coder.decode(schematic)));
|
||||
return read(new ByteArrayInputStream(Base64Coder.decode(schematic.trim())));
|
||||
}catch(IOException e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import arc.util.serialization.Json.Serializable;
|
||||
import arc.util.serialization.JsonValue;
|
||||
import mindustry.content.*;
|
||||
import mindustry.ctype.ContentType;
|
||||
import mindustry.entities.type.BaseUnit;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
import static mindustry.Vars.content;
|
||||
@@ -19,7 +19,7 @@ public class SpawnGroup implements Serializable{
|
||||
public static final int never = Integer.MAX_VALUE;
|
||||
|
||||
/** The unit type spawned */
|
||||
public UnitType type;
|
||||
public UnitType type = UnitTypes.dagger;
|
||||
/** When this spawn should end */
|
||||
public int end = never;
|
||||
/** When this spawn should start */
|
||||
@@ -57,11 +57,11 @@ public class SpawnGroup implements Serializable{
|
||||
* Creates a unit, and assigns correct values based on this group's data.
|
||||
* This method does not add() the unit.
|
||||
*/
|
||||
public BaseUnit createUnit(Team team){
|
||||
BaseUnit unit = type.create(team);
|
||||
public Unitc createUnit(Team team){
|
||||
Unitc unit = type.create(team);
|
||||
|
||||
if(effect != null){
|
||||
unit.applyEffect(effect, 999999f);
|
||||
unit.apply(effect, 999999f);
|
||||
}
|
||||
|
||||
if(items != null){
|
||||
@@ -73,6 +73,7 @@ public class SpawnGroup implements Serializable{
|
||||
|
||||
@Override
|
||||
public void write(Json json){
|
||||
if(type == null) type = UnitTypes.dagger;
|
||||
json.writeValue("type", type.name);
|
||||
if(begin != 0) json.writeValue("begin", begin);
|
||||
if(end != never) json.writeValue("end", end);
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package mindustry.game;
|
||||
|
||||
import mindustry.annotations.Annotations.Serialize;
|
||||
import arc.struct.Array;
|
||||
import arc.struct.ObjectIntMap;
|
||||
import arc.math.Mathf;
|
||||
import arc.math.*;
|
||||
import arc.struct.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
@Serialize
|
||||
@@ -23,21 +22,24 @@ public class Stats{
|
||||
/** Friendly buildings destroyed. */
|
||||
public int buildingsDestroyed;
|
||||
|
||||
public RankResult calculateRank(Zone zone, boolean launched){
|
||||
public RankResult calculateRank(Sector zone, boolean launched){
|
||||
float score = 0;
|
||||
|
||||
//TODO implement wave/attack mode based score
|
||||
/*
|
||||
if(launched && zone.getRules().attackMode){
|
||||
score += 3f;
|
||||
}else if(wavesLasted >= zone.conditionWave){
|
||||
//each new launch period adds onto the rank 'points'
|
||||
score += (float)((wavesLasted - zone.conditionWave) / zone.launchPeriod + 1) * 1.2f;
|
||||
}
|
||||
}*/
|
||||
|
||||
int capacity = zone.loadout.findCore().itemCapacity;
|
||||
//TODO implement
|
||||
int capacity = 3000;//zone.loadout.findCore().itemCapacity;
|
||||
|
||||
//weigh used fractions
|
||||
float frac = 0f;
|
||||
Array<Item> obtainable = Array.with(zone.resources).select(i -> i.type == ItemType.material);
|
||||
Array<Item> obtainable = Array.with(zone.data.resources).select(i -> i instanceof Item && ((Item)i).type == ItemType.material).as(Item.class);
|
||||
for(Item item : obtainable){
|
||||
frac += Mathf.clamp((float)itemsDelivered.get(item, 0) / capacity) / (float)obtainable.size;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.blocks.storage.CoreBlock.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
@@ -17,6 +17,10 @@ public class Teams{
|
||||
/** Active teams. */
|
||||
private Array<TeamData> active = new Array<>();
|
||||
|
||||
public Teams(){
|
||||
active.add(get(Team.crux));
|
||||
}
|
||||
|
||||
public @Nullable CoreEntity closestEnemyCore(float x, float y, Team team){
|
||||
for(TeamData data : active){
|
||||
if(areEnemies(team, data.team)){
|
||||
@@ -50,10 +54,10 @@ public class Teams{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void eachEnemyCore(Team team, Cons<TileEntity> ret){
|
||||
public void eachEnemyCore(Team team, Cons<Tilec> ret){
|
||||
for(TeamData data : active){
|
||||
if(areEnemies(team, data.team)){
|
||||
for(TileEntity tile : data.cores){
|
||||
for(Tilec tile : data.cores){
|
||||
ret.get(tile);
|
||||
}
|
||||
}
|
||||
@@ -85,7 +89,6 @@ public class Teams{
|
||||
|
||||
/** Returns whether {@param other} is an enemy of {@param #team}. */
|
||||
public boolean areEnemies(Team team, Team other){
|
||||
//todo what about derelict?
|
||||
return team != other;
|
||||
}
|
||||
|
||||
@@ -95,11 +98,12 @@ public class Teams{
|
||||
|
||||
/** Do not modify. */
|
||||
public Array<TeamData> getActive(){
|
||||
active.removeAll(t -> !t.active());
|
||||
return active;
|
||||
}
|
||||
|
||||
public void registerCore(CoreEntity core){
|
||||
TeamData data = get(core.getTeam());
|
||||
TeamData data = get(core.team());
|
||||
//add core if not present
|
||||
if(!data.cores.contains(core)){
|
||||
data.cores.add(core);
|
||||
@@ -114,7 +118,7 @@ public class Teams{
|
||||
}
|
||||
|
||||
public void unregisterCore(CoreEntity entity){
|
||||
TeamData data = get(entity.getTeam());
|
||||
TeamData data = get(entity.team());
|
||||
//remove core
|
||||
data.cores.remove(entity);
|
||||
//unregister in active list
|
||||
@@ -125,7 +129,7 @@ public class Teams{
|
||||
}
|
||||
|
||||
private void updateEnemies(){
|
||||
if(!active.contains(get(state.rules.waveTeam))){
|
||||
if(state.rules.waves && !active.contains(get(state.rules.waveTeam))){
|
||||
active.add(get(state.rules.waveTeam));
|
||||
}
|
||||
|
||||
@@ -164,6 +168,14 @@ public class Teams{
|
||||
public CoreEntity core(){
|
||||
return cores.first();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return "TeamData{" +
|
||||
"cores=" + cores +
|
||||
", team=" + team +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
/** Represents a block made by this team that was destroyed somewhere on the map.
|
||||
|
||||
@@ -10,7 +10,7 @@ import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
@@ -162,7 +162,7 @@ public class Tutorial{
|
||||
},
|
||||
withdraw(() -> event("withdraw")){
|
||||
void begin(){
|
||||
state.teams.playerCores().first().items.add(Items.copper, 10);
|
||||
state.teams.playerCores().first().items().add(Items.copper, 10);
|
||||
}
|
||||
},
|
||||
deposit(() -> event("deposit")),
|
||||
@@ -240,18 +240,18 @@ public class Tutorial{
|
||||
//utility
|
||||
|
||||
static void placeBlocks(){
|
||||
TileEntity core = state.teams.playerCores().first();
|
||||
Tilec core = state.teams.playerCores().first();
|
||||
for(int i = 0; i < blocksToBreak; i++){
|
||||
world.ltile(core.tile.x + blockOffset, core.tile.y + i).remove();
|
||||
world.tile(core.tile.x + blockOffset, core.tile.y + i).setBlock(Blocks.scrapWall, state.rules.defaultTeam);
|
||||
world.ltile(core.tile().x + blockOffset, core.tile().y + i).remove();
|
||||
world.tile(core.tile().x + blockOffset, core.tile().y + i).setBlock(Blocks.scrapWall, state.rules.defaultTeam);
|
||||
}
|
||||
}
|
||||
|
||||
static boolean blocksBroken(){
|
||||
TileEntity core = state.teams.playerCores().first();
|
||||
Tilec 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;
|
||||
}
|
||||
}
|
||||
@@ -271,7 +271,7 @@ public class Tutorial{
|
||||
}
|
||||
|
||||
static int item(Item item){
|
||||
return state.rules.defaultTeam.data().noCores() ? 0 : state.rules.defaultTeam.core().items.get(item);
|
||||
return state.rules.defaultTeam.data().noCores() ? 0 : state.rules.defaultTeam.core().items().get(item);
|
||||
}
|
||||
|
||||
static boolean toggled(String name){
|
||||
|
||||
78
core/src/mindustry/game/Universe.java
Normal file
78
core/src/mindustry/game/Universe.java
Normal file
@@ -0,0 +1,78 @@
|
||||
package mindustry.game;
|
||||
|
||||
import arc.*;
|
||||
import arc.math.*;
|
||||
import arc.util.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class Universe{
|
||||
private long seconds;
|
||||
private float secondCounter;
|
||||
|
||||
public Universe(){
|
||||
load();
|
||||
}
|
||||
|
||||
public void updateGlobal(){
|
||||
//currently only updates one solar system
|
||||
updatePlanet(Planets.sun);
|
||||
}
|
||||
|
||||
private void updatePlanet(Planet planet){
|
||||
planet.position.setZero();
|
||||
planet.addParentOffset(planet.position);
|
||||
if(planet.parent != null){
|
||||
planet.position.add(planet.parent.position);
|
||||
}
|
||||
for(Planet child : planet.children){
|
||||
updatePlanet(child);
|
||||
}
|
||||
}
|
||||
|
||||
public void update(){
|
||||
secondCounter += Time.delta() / 60f;
|
||||
if(secondCounter >= 1){
|
||||
seconds += (int)secondCounter;
|
||||
secondCounter %= 1f;
|
||||
|
||||
//save every few seconds
|
||||
if(seconds % 10 == 1){
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
if(state.hasSector()){
|
||||
//update sector light
|
||||
float light = state.getSector().getLight();
|
||||
float alpha = Mathf.clamp(Mathf.map(light, 0f, 0.8f, 0.1f, 1f));
|
||||
//assign and map so darkness is not 100% dark
|
||||
state.rules.ambientLight.a = 1f - alpha;
|
||||
state.rules.lighting = !Mathf.equal(alpha, 1f);
|
||||
}
|
||||
}
|
||||
|
||||
public float secondsMod(float mod, float scale){
|
||||
return (seconds / scale) % mod;
|
||||
}
|
||||
|
||||
public long seconds(){
|
||||
return seconds;
|
||||
}
|
||||
|
||||
public float secondsf(){
|
||||
return seconds + secondCounter;
|
||||
}
|
||||
|
||||
private void save(){
|
||||
Core.settings.put("utime", seconds);
|
||||
Core.settings.save();
|
||||
}
|
||||
|
||||
private void load(){
|
||||
seconds = Core.settings.getLong("utime");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user