mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-10 07:07:03 +07:00
Moved some methods around
This commit is contained in:
parent
4b36a6d5bd
commit
a2a9cffdee
@ -176,7 +176,7 @@ public class Control implements ApplicationListener, Loadable{
|
||||
});
|
||||
|
||||
Events.on(UnitDestroyEvent.class, e -> {
|
||||
if(world.isCampaign()){
|
||||
if(state.isCampaign()){
|
||||
data.unlockContent(e.unit.type());
|
||||
}
|
||||
});
|
||||
@ -448,7 +448,7 @@ public class Control implements ApplicationListener, Loadable{
|
||||
if(!state.is(State.menu)){
|
||||
input.update();
|
||||
|
||||
if(world.isCampaign()){
|
||||
if(state.isCampaign()){
|
||||
for(Tilec tile : state.teams.cores(player.team())){
|
||||
for(Item item : content.items()){
|
||||
if(tile.items().has(item)){
|
||||
|
@ -1,11 +1,13 @@
|
||||
package mindustry.core;
|
||||
|
||||
import arc.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
import static mindustry.Vars.net;
|
||||
|
||||
public class GameState{
|
||||
/** Current wave number, can be anything in non-wave modes. */
|
||||
@ -34,6 +36,20 @@ public class GameState{
|
||||
state = astate;
|
||||
}
|
||||
|
||||
/**Note that being in a campaign does not necessarily mean having a sector. */
|
||||
public boolean isCampaign(){
|
||||
return rules.sector != null;
|
||||
}
|
||||
|
||||
public boolean hasSector(){
|
||||
return rules.sector != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Sector getSector(){
|
||||
return rules.sector;
|
||||
}
|
||||
|
||||
public boolean isEditor(){
|
||||
return rules.editor;
|
||||
}
|
||||
|
@ -31,9 +31,9 @@ public class Logic implements ApplicationListener{
|
||||
|
||||
public Logic(){
|
||||
Events.on(WaveEvent.class, event -> {
|
||||
if(world.isCampaign()){
|
||||
if(state.isCampaign()){
|
||||
//TODO implement
|
||||
//world.getSector().updateWave(state.wave);
|
||||
//state.getSector().updateWave(state.wave);
|
||||
}
|
||||
});
|
||||
|
||||
@ -101,7 +101,7 @@ public class Logic implements ApplicationListener{
|
||||
Events.fire(new PlayEvent());
|
||||
|
||||
//add starting items
|
||||
if(!world.isCampaign()){
|
||||
if(!state.isCampaign()){
|
||||
for(TeamData team : state.teams.getActive()){
|
||||
if(team.hasCore()){
|
||||
Tilec entity = team.core();
|
||||
@ -130,7 +130,7 @@ public class Logic implements ApplicationListener{
|
||||
public void runWave(){
|
||||
spawner.spawnEnemies();
|
||||
state.wave++;
|
||||
state.wavetime = world.isCampaign() && world.getSector().isLaunchWave(state.wave) ? state.rules.waveSpacing * state.rules.launchWaveMultiplier : state.rules.waveSpacing;
|
||||
state.wavetime = state.isCampaign() && state.getSector().isLaunchWave(state.wave) ? state.rules.waveSpacing * state.rules.launchWaveMultiplier : state.rules.waveSpacing;
|
||||
|
||||
Events.fire(new WaveEvent());
|
||||
}
|
||||
@ -152,7 +152,7 @@ public class Logic implements ApplicationListener{
|
||||
}
|
||||
|
||||
if(alive != null && !state.gameOver){
|
||||
if(world.isCampaign() && alive == state.rules.defaultTeam){
|
||||
if(state.isCampaign() && alive == state.rules.defaultTeam){
|
||||
//in attack maps, a victorious game over is equivalent to a launch
|
||||
Call.launchZone();
|
||||
}else{
|
||||
@ -173,9 +173,9 @@ public class Logic implements ApplicationListener{
|
||||
Fx.launch.at(tile);
|
||||
}
|
||||
|
||||
if(world.isCampaign()){
|
||||
if(state.isCampaign()){
|
||||
//TODO implement
|
||||
//world.getSector().setLaunched();
|
||||
//state.getSector().setLaunched();
|
||||
}
|
||||
|
||||
Time.runTask(30f, () -> {
|
||||
@ -212,7 +212,7 @@ public class Logic implements ApplicationListener{
|
||||
}
|
||||
|
||||
if(!state.isPaused()){
|
||||
if(world.isCampaign()){
|
||||
if(state.isCampaign()){
|
||||
universe.update();
|
||||
}
|
||||
Time.update();
|
||||
|
@ -178,14 +178,6 @@ public class World{
|
||||
return generating;
|
||||
}
|
||||
|
||||
public boolean isCampaign(){
|
||||
return getSector() != null;
|
||||
}
|
||||
|
||||
public Sector getSector(){
|
||||
return state.rules.sector;
|
||||
}
|
||||
|
||||
public void loadGenerator(int width, int height, Cons<Tiles> generator){
|
||||
beginMapLoad();
|
||||
|
||||
@ -352,13 +344,13 @@ public class World{
|
||||
}
|
||||
|
||||
//TODO tweak noise and radius
|
||||
if(world.isCampaign()){
|
||||
if(state.isCampaign()){
|
||||
int circleBlend = 14;
|
||||
//quantized angle
|
||||
float offset = getSector().rect.rotation + 90;
|
||||
float offset = state.getSector().rect.rotation + 90;
|
||||
float angle = Angles.angle(x, y, tiles.width/2, tiles.height/2) + offset;
|
||||
//polygon sides, depends on sector
|
||||
int sides = getSector().tile.corners.length;
|
||||
int sides = state.getSector().tile.corners.length;
|
||||
float step = 360f / sides;
|
||||
//prev and next angles of poly
|
||||
float prev = Mathf.round(angle, step);
|
||||
|
@ -70,7 +70,7 @@ public abstract class UnlockableContent extends MappableContent{
|
||||
|
||||
/** @return whether this content is unlocked, or the player is in a custom game. */
|
||||
public final boolean unlockedCur(){
|
||||
return Vars.data.isUnlocked(this) || !Vars.world.isCampaign();
|
||||
return Vars.data.isUnlocked(this) || !Vars.state.isCampaign();
|
||||
}
|
||||
|
||||
public final boolean locked(){
|
||||
|
@ -45,7 +45,7 @@ public class Universe{
|
||||
}
|
||||
|
||||
//update sector light
|
||||
float light = world.getSector().getLight();
|
||||
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;
|
||||
|
@ -27,8 +27,8 @@ public class FileMapGenerator implements WorldGenerator{
|
||||
SaveIO.load(map.file);
|
||||
|
||||
for(Tile tile : tiles){
|
||||
if(tile.block() instanceof StorageBlock && !(tile.block() instanceof CoreBlock) && world.getSector() != null){
|
||||
for(Content content : world.getSector().data.resources){
|
||||
if(tile.block() instanceof StorageBlock && !(tile.block() instanceof CoreBlock) && state.getSector() != null){
|
||||
for(Content content : state.getSector().data.resources){
|
||||
if(content instanceof Item && Mathf.chance(0.3)){
|
||||
tile.entity.items().add((Item)content, Math.min(Mathf.random(500), tile.block().itemCapacity));
|
||||
}
|
||||
|
@ -91,6 +91,6 @@ public class DatabaseDialog extends FloatingDialog{
|
||||
}
|
||||
|
||||
boolean unlocked(UnlockableContent content){
|
||||
return (!Vars.world.isCampaign() && !Vars.state.is(State.menu)) || content.unlocked();
|
||||
return (!Vars.state.isCampaign() && !Vars.state.is(State.menu)) || content.unlocked();
|
||||
}
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ public class GameOverDialog extends FloatingDialog{
|
||||
t.add(Core.bundle.format("stat.playtime", control.saves.getCurrent().getPlayTime()));
|
||||
t.row();
|
||||
}
|
||||
if(world.isCampaign() && !state.stats.itemsDelivered.isEmpty()){
|
||||
if(state.isCampaign() && !state.stats.itemsDelivered.isEmpty()){
|
||||
t.add("$stat.delivered");
|
||||
t.row();
|
||||
for(Item item : content.items()){
|
||||
@ -80,14 +80,14 @@ public class GameOverDialog extends FloatingDialog{
|
||||
}
|
||||
}
|
||||
|
||||
if(world.isCampaign()){
|
||||
RankResult result = state.stats.calculateRank(world.getSector(), state.launched);
|
||||
if(state.isCampaign()){
|
||||
RankResult result = state.stats.calculateRank(state.getSector(), state.launched);
|
||||
t.add(Core.bundle.format("stat.rank", result.rank + result.modifier));
|
||||
t.row();
|
||||
}
|
||||
}).pad(12);
|
||||
|
||||
if(world.isCampaign()){
|
||||
if(state.isCampaign()){
|
||||
buttons.addButton("$continue", () -> {
|
||||
hide();
|
||||
state.set(State.menu);
|
||||
|
@ -41,7 +41,7 @@ public class PausedDialog extends FloatingDialog{
|
||||
cont.addImageTextButton("$back", Icon.left, this::hide).colspan(2).width(dw * 2 + 20f);
|
||||
|
||||
cont.row();
|
||||
if(world.isCampaign()){
|
||||
if(state.isCampaign()){
|
||||
cont.addImageTextButton("$techtree", Icon.tree, ui.tech::show);
|
||||
}else{
|
||||
cont.addImageTextButton("$database", Icon.book, ui.database::show);
|
||||
@ -49,7 +49,7 @@ public class PausedDialog extends FloatingDialog{
|
||||
cont.addImageTextButton("$settings", Icon.settings, ui.settings::show);
|
||||
|
||||
if(!state.rules.tutorial){
|
||||
if(!world.isCampaign() && !state.isEditor()){
|
||||
if(!state.isCampaign() && !state.isEditor()){
|
||||
cont.row();
|
||||
cont.addImageTextButton("$savegame", Icon.save, save::show);
|
||||
cont.addImageTextButton("$loadgame", Icon.upload, load::show).disabled(b -> net.active());
|
||||
@ -79,7 +79,7 @@ public class PausedDialog extends FloatingDialog{
|
||||
cont.addRowImageTextButton("$back", Icon.play, this::hide);
|
||||
cont.addRowImageTextButton("$settings", Icon.settings, ui.settings::show);
|
||||
|
||||
if(!world.isCampaign() && !state.isEditor()){
|
||||
if(!state.isCampaign() && !state.isEditor()){
|
||||
cont.addRowImageTextButton("$save", Icon.save, save::show);
|
||||
|
||||
cont.row();
|
||||
|
@ -84,7 +84,7 @@ public class HudFragment extends Fragment{
|
||||
}else{
|
||||
ui.chatfrag.toggle();
|
||||
}
|
||||
}else if(world.isCampaign()){
|
||||
}else if(state.isCampaign()){
|
||||
ui.tech.show();
|
||||
}else{
|
||||
ui.database.show();
|
||||
@ -497,10 +497,10 @@ public class HudFragment extends Fragment{
|
||||
}
|
||||
|
||||
private boolean inLaunchWave(){
|
||||
return world.isCampaign() &&
|
||||
world.getSector().metCondition() &&
|
||||
return state.isCampaign() &&
|
||||
state.getSector().metCondition() &&
|
||||
!net.client() &&
|
||||
state.wave % world.getSector().launchPeriod == 0 && !spawner.isSpawning();
|
||||
state.wave % state.getSector().launchPeriod == 0 && !spawner.isSpawning();
|
||||
}
|
||||
|
||||
private boolean canLaunch(){
|
||||
@ -559,7 +559,7 @@ public class HudFragment extends Fragment{
|
||||
}else{
|
||||
builder.append(Core.bundle.get("launch"));
|
||||
builder.append("\n");
|
||||
builder.append(Core.bundle.format("launch.next", state.wave + world.getSector().launchPeriod));
|
||||
builder.append(Core.bundle.format("launch.next", state.wave + state.getSector().launchPeriod));
|
||||
builder.append("\n");
|
||||
}
|
||||
builder.append("[]\n");
|
||||
|
@ -440,7 +440,7 @@ public class PlacementFragment extends Fragment{
|
||||
}
|
||||
|
||||
boolean unlocked(Block block){
|
||||
return !world.isCampaign() || data.isUnlocked(block);
|
||||
return !state.isCampaign() || data.isUnlocked(block);
|
||||
}
|
||||
|
||||
/** Returns the currently displayed block in the top box. */
|
||||
|
@ -376,7 +376,7 @@ public class Block extends BlockStorage{
|
||||
/** Call when some content is produced. This unlocks the content if it is applicable. */
|
||||
public void useContent(Tile tile, UnlockableContent content){
|
||||
//only unlocks content in zones
|
||||
if(!headless && tile.team() == player.team() && world.isCampaign()){
|
||||
if(!headless && tile.team() == player.team() && state.isCampaign()){
|
||||
logic.handleContent(content);
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ public class ItemSelection{
|
||||
int i = 0;
|
||||
|
||||
for(T item : items){
|
||||
if(!data.isUnlocked(item) && world.isCampaign()) continue;
|
||||
if(!data.isUnlocked(item) && state.isCampaign()) continue;
|
||||
|
||||
ImageButton button = cont.addImageButton(Tex.whiteui, Styles.clearToggleTransi, 24, () -> control.input.frag.config.hideConfig()).group(group).get();
|
||||
button.changed(() -> consumer.get(button.isChecked() ? item : null));
|
||||
|
@ -47,7 +47,7 @@ public class ItemTurret extends CooledTurret{
|
||||
@Override
|
||||
public void build(Tile tile, Table table){
|
||||
MultiReqImage image = new MultiReqImage();
|
||||
content.items().each(i -> filter.get(i) && (!world.isCampaign() || data.isUnlocked(i)), item -> image.add(new ReqImage(new ItemImage(item.icon(Cicon.medium)),
|
||||
content.items().each(i -> filter.get(i) && (!state.isCampaign() || data.isUnlocked(i)), item -> image.add(new ReqImage(new ItemImage(item.icon(Cicon.medium)),
|
||||
() -> tile.entity != null && !((ItemTurretEntity)tile.entity).ammo.isEmpty() && ((ItemEntry)tile.<ItemTurretEntity>ent().ammo.peek()).item == item)));
|
||||
|
||||
table.add(image).size(8 * 4);
|
||||
|
@ -16,8 +16,7 @@ import mindustry.world.Tile;
|
||||
import mindustry.world.meta.BlockStat;
|
||||
import mindustry.world.meta.StatUnit;
|
||||
|
||||
import static mindustry.Vars.data;
|
||||
import static mindustry.Vars.world;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class LaunchPad extends StorageBlock{
|
||||
public final int timerLaunch = timers++;
|
||||
@ -73,7 +72,7 @@ public class LaunchPad extends StorageBlock{
|
||||
public void update(Tile tile){
|
||||
Tilec entity = tile.entity;
|
||||
|
||||
if(world.isCampaign() && entity.consValid() && entity.items().total() >= itemCapacity && entity.timer(timerLaunch, launchTime / entity.timeScale())){
|
||||
if(state.isCampaign() && entity.consValid() && entity.items().total() >= itemCapacity && entity.timer(timerLaunch, launchTime / entity.timeScale())){
|
||||
for(Item item : Vars.content.items()){
|
||||
Events.fire(Trigger.itemLaunch);
|
||||
Fx.padlaunch.at(tile);
|
||||
|
@ -35,7 +35,7 @@ public class ConsumeItemFilter extends Consume{
|
||||
@Override
|
||||
public void build(Tile tile, Table table){
|
||||
MultiReqImage image = new MultiReqImage();
|
||||
content.items().each(i -> filter.get(i) && (!world.isCampaign() || data.isUnlocked(i)), item -> image.add(new ReqImage(new ItemImage(item.icon(Cicon.medium), 1), () -> tile.entity != null && tile.entity.items() != null && tile.entity.items().has(item))));
|
||||
content.items().each(i -> filter.get(i) && (!state.isCampaign() || data.isUnlocked(i)), item -> image.add(new ReqImage(new ItemImage(item.icon(Cicon.medium), 1), () -> tile.entity != null && tile.entity.items() != null && tile.entity.items().has(item))));
|
||||
|
||||
table.add(image).size(8 * 4);
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ public enum BuildVisibility{
|
||||
shown(() -> true),
|
||||
debugOnly(() -> false),
|
||||
sandboxOnly(() -> Vars.state.rules.infiniteResources),
|
||||
campaignOnly(() -> Vars.world.isCampaign()),
|
||||
campaignOnly(() -> Vars.state.isCampaign()),
|
||||
lightingOnly(() -> Vars.state.rules.lighting);
|
||||
|
||||
private final Boolp visible;
|
||||
|
@ -188,7 +188,7 @@ public class SStats implements SteamUserStatsCallback{
|
||||
Events.on(LoseEvent.class, e -> {
|
||||
if(campaign()){
|
||||
//TODO implement
|
||||
//if(world.getSector().metCondition() && (state.wave - world.getSector().conditionWave) / world.getSector().launchPeriod >= 1){
|
||||
//if(state.getSector().metCondition() && (state.wave - state.getSector().conditionWave) / state.getSector().launchPeriod >= 1){
|
||||
// skipLaunching2Death.complete();
|
||||
//}
|
||||
}
|
||||
@ -240,7 +240,7 @@ public class SStats implements SteamUserStatsCallback{
|
||||
SStat.attacksWon.add();
|
||||
}
|
||||
|
||||
RankResult result = state.stats.calculateRank(world.getSector(), state.launched);
|
||||
RankResult result = state.stats.calculateRank(state.getSector(), state.launched);
|
||||
if(result.rank == Rank.S) earnSRank.complete();
|
||||
if(result.rank == Rank.SS) earnSSRank.complete();
|
||||
}
|
||||
@ -274,7 +274,7 @@ public class SStats implements SteamUserStatsCallback{
|
||||
}
|
||||
|
||||
private boolean campaign(){
|
||||
return Vars.world.isCampaign();
|
||||
return Vars.state.isCampaign();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user