Added sector mission display and generation

This commit is contained in:
Anuken
2018-07-28 22:06:01 -04:00
parent a045ec9d46
commit b2d61a93d9
8 changed files with 45 additions and 9 deletions

View File

@@ -28,6 +28,8 @@ public class Sector{
public transient Array<SpawnGroup> spawns = new Array<>();
/**Ores that appear in this sector.*/
public transient Array<Item> ores = new Array<>();
/**Difficulty of the sector, measured by calculating distance from origin.*/
public transient int difficulty;
public int getSeed(){
return Bits.packInt(x, y);

View File

@@ -10,6 +10,7 @@ import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.maps.generation.WorldGenerator.GenResult;
import io.anuke.mindustry.maps.missions.BattleMission;
import io.anuke.mindustry.maps.missions.WaveMission;
import io.anuke.mindustry.world.ColorMapper;
import io.anuke.mindustry.world.Edges;
import io.anuke.ucore.core.Settings;
@@ -130,15 +131,23 @@ public class Sectors{
}
private void initSector(Sector sector){
sector.mission = new BattleMission();
sector.difficulty = (int)(Mathf.dst(sector.x, sector.y)/2);
if(sector.difficulty < 1){
sector.mission = new WaveMission(30);
}else{
sector.mission = Mathf.choose(
new BattleMission(sector.difficulty),
new WaveMission(30 + sector.difficulty*5 + Mathf.randomSeed(sector.getSeed(), 0, 5)*5)
);
}
//add all ores for now since material differences aren't well handled yet
sector.ores.addAll(Items.tungsten, Items.coal, Items.lead, Items.thorium, Items.titanium);
}
private int round2(int i){
if(i < 0){
i --;
}
if(i < 0) i --;
return i/2*2;
}

View File

@@ -5,8 +5,19 @@ import io.anuke.mindustry.content.blocks.StorageBlocks;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.maps.Sector;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.util.Bundles;
public class BattleMission implements Mission{
private final int difficulty;
public BattleMission(int difficulty){
this.difficulty = difficulty;
}
@Override
public String displayString(){
return Bundles.get("text.mission.battle");
}
@Override
public void generate(Tile[][] tiles, Sector sector){

View File

@@ -5,6 +5,7 @@ import io.anuke.mindustry.world.Tile;
public interface Mission{
boolean isComplete();
String displayString();
default void generate(Tile[][] tiles, Sector sector){}
}

View File

@@ -1,5 +1,7 @@
package io.anuke.mindustry.maps.missions;
import io.anuke.ucore.util.Bundles;
import static io.anuke.mindustry.Vars.*;
public class WaveMission implements Mission{
@@ -9,6 +11,11 @@ public class WaveMission implements Mission{
this.target = target;
}
@Override
public String displayString(){
return Bundles.format("text.mission.wave", target);
}
@Override
public boolean isComplete(){
return state.wave >= target;

View File

@@ -12,7 +12,6 @@ import io.anuke.ucore.scene.Element;
import io.anuke.ucore.scene.event.ClickListener;
import io.anuke.ucore.scene.event.InputEvent;
import io.anuke.ucore.scene.event.InputListener;
import io.anuke.ucore.scene.ui.TextButton;
import io.anuke.ucore.scene.ui.layout.Unit;
import io.anuke.ucore.scene.utils.Cursors;
import io.anuke.ucore.scene.utils.ScissorStack;
@@ -37,18 +36,21 @@ public class SectorsDialog extends FloatingDialog{
addCloseButton();
content().label(() -> Bundles.format("text.sector", selected == null ? "<none>" :
content().label(() -> Bundles.format("text.sector", selected == null ? Bundles.get("text.none") :
(selected.x + ", " + selected.y + (!selected.complete && selected.saveID != -1 ? " " + Bundles.get("text.sector.locked") : ""))
+ (selected.saveID == -1 ? " " + Bundles.get("text.sector.unexplored") :
(selected.hasSave() ? " [accent]/[white] " + Bundles.format("text.sector.time", selected.getSave().getPlayTime()) : ""))));
content().row();
content().label(() -> Bundles.format("text.mission", selected == null ? Bundles.get("text.none") : selected.mission.displayString()));
content().row();
content().add(new SectorView()).grow();
content().row();
buttons().addImageTextButton("$text.sector.deploy", "icon-play", 10*3, () -> {
hide();
ui.loadLogic(() -> world.sectors().playSector(selected));
}).size(230f, 64f).name("deploy-button").disabled(b -> selected == null);
}).size(230f, 64f).disabled(b -> selected == null)
.update(t -> t.setText(selected != null && selected.hasSave() ? "$text.sector.resume" : "$text.sector.deploy"));
if(debug){
buttons().addButton("unlock", () -> world.sectors().completeSector(selected.x, selected.y)).size(230f, 64f).disabled(b -> selected == null);
@@ -56,7 +58,6 @@ public class SectorsDialog extends FloatingDialog{
}
void selectSector(Sector sector){
buttons().<TextButton>find("deploy-button").setText(sector.hasSave() ? "$text.sector.resume" : "$text.sector.deploy");
selected = sector;
}