Refactoring
This commit is contained in:
@@ -90,9 +90,9 @@ public class EventType{
|
||||
/** Called when a zone's requirements are met. */
|
||||
public static class ZoneRequireCompleteEvent{
|
||||
public final SectorPreset zoneMet, zoneForMet;
|
||||
public final Objective objective;
|
||||
public final Objectives.Objective objective;
|
||||
|
||||
public ZoneRequireCompleteEvent(SectorPreset zoneMet, SectorPreset zoneForMet, Objective objective){
|
||||
public ZoneRequireCompleteEvent(SectorPreset zoneMet, SectorPreset zoneForMet, Objectives.Objective objective){
|
||||
this.zoneMet = zoneMet;
|
||||
this.zoneForMet = zoneForMet;
|
||||
this.objective = objective;
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package mindustry.game;
|
||||
|
||||
import arc.*;
|
||||
import arc.files.*;
|
||||
import arc.math.*;
|
||||
import arc.struct.*;
|
||||
import arc.files.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.*;
|
||||
import mindustry.content.*;
|
||||
@@ -22,7 +21,6 @@ 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(){
|
||||
@@ -39,10 +37,6 @@ 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());
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
package mindustry.game;
|
||||
|
||||
import arc.*;
|
||||
import arc.audio.*;
|
||||
import arc.struct.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import mindustry.*;
|
||||
|
||||
public class LoopControl{
|
||||
private ObjectMap<Sound, SoundData> sounds = new ObjectMap<>();
|
||||
|
||||
public void play(Sound sound, Position pos, float volume){
|
||||
if(Vars.headless) return;
|
||||
|
||||
float baseVol = sound.calcFalloff(pos.getX(), pos.getY());
|
||||
float vol = baseVol * volume;
|
||||
|
||||
SoundData data = sounds.getOr(sound, SoundData::new);
|
||||
data.volume += vol;
|
||||
data.volume = Mathf.clamp(data.volume, 0f, 1f);
|
||||
data.total += baseVol;
|
||||
data.sum.add(pos.getX() * baseVol, pos.getY() * baseVol);
|
||||
}
|
||||
|
||||
public void update(){
|
||||
float avol = Core.settings.getInt("ambientvol", 100) / 100f;
|
||||
|
||||
sounds.each((sound, data) -> {
|
||||
data.curVolume = Mathf.lerpDelta(data.curVolume, data.volume * avol, 0.2f);
|
||||
|
||||
boolean play = data.curVolume > 0.01f;
|
||||
float pan = Mathf.zero(data.total, 0.0001f) ? 0f : sound.calcPan(data.sum.x / data.total, data.sum.y / data.total);
|
||||
if(data.soundID <= 0){
|
||||
if(play){
|
||||
data.soundID = sound.loop(data.curVolume, 1f, pan);
|
||||
}
|
||||
}else{
|
||||
if(data.curVolume <= 0.01f){
|
||||
sound.stop();
|
||||
data.soundID = -1;
|
||||
return;
|
||||
}
|
||||
sound.setPan(data.soundID, pan, data.curVolume);
|
||||
}
|
||||
|
||||
data.volume = 0f;
|
||||
data.total = 0f;
|
||||
data.sum.setZero();
|
||||
});
|
||||
}
|
||||
|
||||
private class SoundData{
|
||||
float volume;
|
||||
float total;
|
||||
Vec2 sum = new Vec2();
|
||||
|
||||
int soundID;
|
||||
float curVolume;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
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(){
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,190 +0,0 @@
|
||||
package mindustry.game;
|
||||
|
||||
import arc.*;
|
||||
import arc.audio.*;
|
||||
import arc.math.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.gen.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
/** Controls playback of multiple music tracks.*/
|
||||
public class MusicControl{
|
||||
protected static final float finTime = 120f, foutTime = 120f, musicInterval = 60 * 60 * 3f, musicChance = 0.6f, musicWaveChance = 0.5f;
|
||||
|
||||
/** normal, ambient music, plays at any time */
|
||||
public Array<Music> ambientMusic = Array.with();
|
||||
/** darker music, used in times of conflict */
|
||||
public Array<Music> darkMusic = Array.with();
|
||||
protected Music lastRandomPlayed;
|
||||
protected Interval timer = new Interval();
|
||||
protected @Nullable Music current;
|
||||
protected float fade;
|
||||
protected boolean silenced;
|
||||
|
||||
public MusicControl(){
|
||||
Events.on(ClientLoadEvent.class, e -> reload());
|
||||
|
||||
//only run music 10 seconds after a wave spawns
|
||||
Events.on(WaveEvent.class, e -> Time.run(60f * 10f, () -> {
|
||||
if(Mathf.chance(musicWaveChance)){
|
||||
playRandom();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
protected void reload(){
|
||||
current = null;
|
||||
fade = 0f;
|
||||
ambientMusic = Array.with(Musics.game1, Musics.game3, Musics.game4, Musics.game6);
|
||||
darkMusic = Array.with(Musics.game2, Musics.game5, Musics.game7);
|
||||
}
|
||||
|
||||
public void stop(){
|
||||
silenced = true;
|
||||
if(current != null){
|
||||
current.stop();
|
||||
current = null;
|
||||
fade = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
/** Update and play the right music track.*/
|
||||
public void update(){
|
||||
if(state.isMenu()){
|
||||
silenced = false;
|
||||
if(ui.planet.isShown()){
|
||||
play(Musics.launch);
|
||||
}else if(ui.editor.isShown()){
|
||||
play(Musics.editor);
|
||||
}else{
|
||||
play(Musics.menu);
|
||||
}
|
||||
}else if(state.rules.editor){
|
||||
silenced = false;
|
||||
play(Musics.editor);
|
||||
}else{
|
||||
//this just fades out the last track to make way for ingame music
|
||||
silence();
|
||||
|
||||
//play music at intervals
|
||||
if(timer.get(musicInterval)){
|
||||
//chance to play it per interval
|
||||
if(Mathf.chance(musicChance)){
|
||||
playRandom();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Plays a random track.*/
|
||||
protected void playRandom(){
|
||||
if(isDark()){
|
||||
playOnce(darkMusic.random(lastRandomPlayed));
|
||||
}else{
|
||||
playOnce(ambientMusic.random(lastRandomPlayed));
|
||||
}
|
||||
}
|
||||
|
||||
/** Whether to play dark music.*/
|
||||
protected boolean isDark(){
|
||||
if(state.teams.get(player.team()).hasCore() && state.teams.get(player.team()).core().healthf() < 0.85f){
|
||||
//core damaged -> dark
|
||||
return true;
|
||||
}
|
||||
|
||||
//it may be dark based on wave
|
||||
if(Mathf.chance((float)(Math.log10((state.wave - 17f)/19f) + 1) / 4f)){
|
||||
return true;
|
||||
}
|
||||
|
||||
//dark based on enemies
|
||||
return Mathf.chance(state.enemies / 70f + 0.1f);
|
||||
}
|
||||
|
||||
/** 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.*/
|
||||
protected void play(@Nullable Music music){
|
||||
if(!shouldPlay()){
|
||||
if(current != null){
|
||||
current.setVolume(0);
|
||||
}
|
||||
|
||||
fade = 0f;
|
||||
return;
|
||||
}
|
||||
|
||||
//update volume of current track
|
||||
if(current != null){
|
||||
current.setVolume(fade * Core.settings.getInt("musicvol") / 100f);
|
||||
}
|
||||
|
||||
//do not update once the track has faded out completely, just stop
|
||||
if(silenced){
|
||||
return;
|
||||
}
|
||||
|
||||
if(current == null && music != null){
|
||||
//begin playing in a new track
|
||||
current = music;
|
||||
current.setLooping(true);
|
||||
current.setVolume(fade = 0f);
|
||||
current.play();
|
||||
silenced = false;
|
||||
}else if(current == music && music != null){
|
||||
//fade in the playing track
|
||||
fade = Mathf.clamp(fade + Time.delta()/finTime);
|
||||
}else if(current != null){
|
||||
//fade out the current track
|
||||
fade = Mathf.clamp(fade - Time.delta()/foutTime);
|
||||
|
||||
if(fade <= 0.01f){
|
||||
//stop current track when it hits 0 volume
|
||||
current.stop();
|
||||
current = null;
|
||||
silenced = true;
|
||||
if(music != null){
|
||||
//play newly scheduled track
|
||||
current = music;
|
||||
current.setVolume(fade = 0f);
|
||||
current.setLooping(true);
|
||||
current.play();
|
||||
silenced = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Plays a music track once and only once. If something is already playing, does nothing.*/
|
||||
protected void playOnce(Music music){
|
||||
if(current != null || music == null || !shouldPlay()) return; //do not interrupt already-playing tracks
|
||||
|
||||
//save last random track played to prevent duplicates
|
||||
lastRandomPlayed = music;
|
||||
|
||||
//set fade to 1 and play it, stopping the current when it's done
|
||||
fade = 1f;
|
||||
current = music;
|
||||
current.setVolume(1f);
|
||||
current.setLooping(false);
|
||||
current.setCompletionListener(m -> {
|
||||
if(current == m){
|
||||
current = null;
|
||||
fade = 0f;
|
||||
}
|
||||
});
|
||||
current.play();
|
||||
}
|
||||
|
||||
protected boolean shouldPlay(){
|
||||
return Core.settings.getInt("musicvol") > 0;
|
||||
}
|
||||
|
||||
/** Fades out the current track, unless it has already been silenced. */
|
||||
protected void silence(){
|
||||
play(null);
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package mindustry.game;
|
||||
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import mindustry.game.Objectives.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
/** Defines a specific objective for a game. */
|
||||
public interface Objective{
|
||||
|
||||
/** @return whether this objective is met. */
|
||||
boolean complete();
|
||||
|
||||
/** @return the string displayed when this objective is completed, in imperative form.
|
||||
* e.g. when the objective is 'complete 10 waves', this would display "complete 10 waves".
|
||||
* If this objective should not be displayed, should return null.*/
|
||||
@Nullable String display();
|
||||
|
||||
/** Build a display for this zone requirement.*/
|
||||
default void build(Table table){
|
||||
|
||||
}
|
||||
|
||||
default SectorPreset zone(){
|
||||
return this instanceof ZoneObjective ? ((ZoneObjective)this).zone : null;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package mindustry.game;
|
||||
|
||||
import arc.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
@@ -93,4 +94,25 @@ public class Objectives{
|
||||
public abstract static class ZoneObjective implements Objective{
|
||||
public @NonNull SectorPreset zone;
|
||||
}
|
||||
|
||||
/** Defines a specific objective for a game. */
|
||||
public static interface Objective{
|
||||
|
||||
/** @return whether this objective is met. */
|
||||
boolean complete();
|
||||
|
||||
/** @return the string displayed when this objective is completed, in imperative form.
|
||||
* e.g. when the objective is 'complete 10 waves', this would display "complete 10 waves".
|
||||
* If this objective should not be displayed, should return null.*/
|
||||
@Nullable String display();
|
||||
|
||||
/** Build a display for this zone requirement.*/
|
||||
default void build(Table table){
|
||||
|
||||
}
|
||||
|
||||
default SectorPreset zone(){
|
||||
return this instanceof ZoneObjective ? ((ZoneObjective)this).zone : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,8 +62,6 @@ public class Rules{
|
||||
public int unitCap = 0;
|
||||
/** Sector for saves that have them.*/
|
||||
public @Nullable Sector sector;
|
||||
/** Region that save is on. Indicates campaign. TODO not implemented. */
|
||||
public @Nullable MapRegion region;
|
||||
/** Spawn layout. */
|
||||
public Array<SpawnGroup> spawns = new Array<>();
|
||||
/** Determines if there should be limited respawns. */
|
||||
|
||||
@@ -16,8 +16,7 @@ public class Schematic implements Publishable, Comparable<Schematic>{
|
||||
public final Array<Stile> tiles;
|
||||
public StringMap tags;
|
||||
public int width, height;
|
||||
public @Nullable
|
||||
Fi file;
|
||||
public @Nullable Fi file;
|
||||
/** Associated mod. If null, no mod is associated with this schematic. */
|
||||
public @Nullable LoadedMod mod;
|
||||
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
package mindustry.game;
|
||||
|
||||
import arc.audio.*;
|
||||
import arc.math.*;
|
||||
import arc.util.*;
|
||||
|
||||
/** A simple class for playing a looping sound at a position.*/
|
||||
public class SoundLoop{
|
||||
private static final float fadeSpeed = 0.05f;
|
||||
|
||||
private final Sound sound;
|
||||
private int id = -1;
|
||||
private float volume, baseVolume;
|
||||
|
||||
public SoundLoop(Sound sound, float baseVolume){
|
||||
this.sound = sound;
|
||||
this.baseVolume = baseVolume;
|
||||
}
|
||||
|
||||
public void update(float x, float y, boolean play){
|
||||
if(baseVolume < 0) return;
|
||||
|
||||
if(id < 0){
|
||||
if(play){
|
||||
id = sound.loop(sound.calcVolume(x, y) * volume * baseVolume, 1f, sound.calcPan(x, y));
|
||||
}
|
||||
}else{
|
||||
//fade the sound in or out
|
||||
if(play){
|
||||
volume = Mathf.clamp(volume + fadeSpeed * Time.delta());
|
||||
}else{
|
||||
volume = Mathf.clamp(volume - fadeSpeed * Time.delta());
|
||||
if(volume <= 0.001f){
|
||||
sound.stop(id);
|
||||
id = -1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
sound.setPan(id, sound.calcPan(x, y), sound.calcVolume(x, y) * volume * baseVolume);
|
||||
}
|
||||
}
|
||||
|
||||
public void stop(){
|
||||
if(id != -1){
|
||||
sound.stop(id);
|
||||
id = -1;
|
||||
volume = baseVolume = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
4
core/src/mindustry/game/Turns.java
Normal file
4
core/src/mindustry/game/Turns.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package mindustry.game;
|
||||
|
||||
public class Turns{
|
||||
}
|
||||
@@ -69,8 +69,7 @@ public class Universe{
|
||||
}
|
||||
|
||||
private void save(){
|
||||
Core.settings.put("utime", seconds);
|
||||
Core.settings.save();
|
||||
Core.settings.putSave("utime", seconds);
|
||||
}
|
||||
|
||||
private void load(){
|
||||
|
||||
Reference in New Issue
Block a user