mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-11 11:17:11 +07:00
Per-sector ore gen
This commit is contained in:
parent
8d20c46228
commit
4eab89d73e
@ -48,7 +48,7 @@ public class Vars{
|
||||
public static final int maxNameLength = 40;
|
||||
public static final float itemSize = 5f;
|
||||
public static final int tilesize = 8;
|
||||
public static final int sectorSize = 130;
|
||||
public static final int sectorSize = 120;
|
||||
public static final int mapPadding = 3;
|
||||
public static final int invalidSector = Integer.MAX_VALUE;
|
||||
public static Locale[] locales;
|
||||
|
@ -8,7 +8,6 @@ import io.anuke.mindustry.game.Saves.SaveSlot;
|
||||
import io.anuke.mindustry.game.SpawnGroup;
|
||||
import io.anuke.mindustry.maps.missions.Mission;
|
||||
import io.anuke.mindustry.maps.missions.VictoryMission;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.ucore.util.Bits;
|
||||
|
||||
@ -35,7 +34,7 @@ public class Sector{
|
||||
/**Enemies spawned at this sector.*/
|
||||
public transient Array<SpawnGroup> spawns;
|
||||
/**Ores that appear in this sector.*/
|
||||
public transient Array<Item> ores = new Array<>();
|
||||
//public transient Array<Item> ores = new Array<>();
|
||||
/**Difficulty of the sector, measured by calculating distance from origin and applying scaling.*/
|
||||
public transient int difficulty;
|
||||
/**Items the player starts with on this sector.*/
|
||||
|
@ -11,6 +11,7 @@ import io.anuke.mindustry.io.SaveIO;
|
||||
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.type.Item;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.world.ColorMapper;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
@ -153,10 +154,12 @@ public class Sectors{
|
||||
for (int sy = 0; sy < sector.height; sy++) {
|
||||
//if this sector is a 'new sector (not part of the current save data...)
|
||||
if(sx < -expandX || sy < -expandY || sx >= sector.width - expandX || sy >= sector.height - expandY){
|
||||
GenResult result = new GenResult();
|
||||
Array<Item> ores = getOres(sx + sector.x, sy + sector.y);
|
||||
//gen tiles in sector
|
||||
for (int x = 0; x < sectorSize; x++) {
|
||||
for (int y = 0; y < sectorSize; y++) {
|
||||
GenResult result = world.generator().generateTile(sx + sector.x, sy + sector.y, x, y);
|
||||
world.generator().generateTile(result, sx + sector.x, sy + sector.y, x, y, true, null, ores);
|
||||
newTiles[sx * sectorSize + x][sy * sectorSize + y] = new Tile(x + sx * sectorSize, y + sy*sectorSize, result.floor.id, result.wall.id, (byte)0, (byte)0, result.elevation);
|
||||
}
|
||||
}
|
||||
@ -170,6 +173,15 @@ public class Sectors{
|
||||
return true;
|
||||
}
|
||||
|
||||
public Array<Item> getOres(int x, int y){
|
||||
if(x == 0 && y == 0){
|
||||
return Array.with(Items.copper);
|
||||
}else if(x == 1 && y == 0){
|
||||
return Array.with(Items.copper, Items.lead, Items.coal);
|
||||
}
|
||||
return Array.with(Items.copper);
|
||||
}
|
||||
|
||||
/**Unlocks a sector. This shows nearby sectors.*/
|
||||
public void completeSector(int x, int y){
|
||||
createSector(x, y);
|
||||
@ -259,7 +271,7 @@ public class Sectors{
|
||||
|
||||
sector.spawns = sector.missions.first().getWaves(sector);
|
||||
|
||||
sector.ores.addAll(Items.copper);
|
||||
//sector.ores.addAll(Items.copper);
|
||||
|
||||
//set starter items
|
||||
if(sector.difficulty > 12){ //now with titanium
|
||||
|
@ -4,8 +4,11 @@ import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.content.Items;
|
||||
import io.anuke.mindustry.content.UnitTypes;
|
||||
import io.anuke.mindustry.content.blocks.*;
|
||||
import io.anuke.mindustry.maps.generation.Generation;
|
||||
import io.anuke.mindustry.maps.missions.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
/**Just a class for returning the list of tutorial missions.*/
|
||||
public class TutorialSector{
|
||||
|
||||
@ -30,7 +33,31 @@ public class TutorialSector{
|
||||
new BlockMission(UnitBlocks.daggerFactory).setMessage("$tutorial.daggerfactory"),
|
||||
new UnitMission(UnitTypes.dagger).setMessage("$tutorial.dagger"),
|
||||
new ExpandMission(-1, 0),
|
||||
new BattleMission().setMessage("$tutorial.battle")
|
||||
new BattleMission(){
|
||||
public void generate(Generation gen){}
|
||||
|
||||
@Override
|
||||
public boolean isComplete(){
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onBegin(){
|
||||
super.onBegin();
|
||||
generateBase();
|
||||
}
|
||||
}.setMessage("$tutorial.battle")
|
||||
);
|
||||
}
|
||||
|
||||
private static void generateBase(){
|
||||
int x = sectorSize/2, y = sectorSize/2;
|
||||
world.setBlock(world.tile(x, y), StorageBlocks.core, waveTeam);
|
||||
world.setBlock(world.tile(x + 1, y + 2), TurretBlocks.duo, waveTeam);
|
||||
world.setBlock(world.tile(x + 1, y - 2), TurretBlocks.duo, waveTeam);
|
||||
world.setBlock(world.tile(x - 1, y + 2), UnitBlocks.daggerFactory, waveTeam);
|
||||
world.setBlock(world.tile(x - 1, y - 3), UnitBlocks.daggerFactory, waveTeam);
|
||||
|
||||
//since placed() is not called here, add core manually
|
||||
state.teams.get(waveTeam).cores.add(world.tile(x, y));
|
||||
}
|
||||
}
|
||||
|
@ -186,10 +186,11 @@ public class WorldGenerator{
|
||||
SeedRandom rnd = new SeedRandom(sector.getSeed());
|
||||
Generation gena = new Generation(sector, tiles, tiles.length, tiles[0].length, rnd);
|
||||
Array<GridPoint2> spawnpoints = sector.currentMission().getSpawnPoints(gena);
|
||||
Array<Item> ores = world.sectors().getOres(sector.x, sector.y);
|
||||
|
||||
for(int x = 0; x < width; x++){
|
||||
for(int y = 0; y < height; y++){
|
||||
GenResult result = generateTile(this.result, sector.x, sector.y, x, y, true, spawnpoints);
|
||||
GenResult result = generateTile(this.result, sector.x, sector.y, x, y, true, spawnpoints, ores);
|
||||
Tile tile = new Tile(x, y, result.floor.id, result.wall.id, (byte)0, (byte)0, result.elevation);
|
||||
tiles[x][y] = tile;
|
||||
}
|
||||
@ -214,7 +215,7 @@ public class WorldGenerator{
|
||||
}
|
||||
}
|
||||
|
||||
generateOres(tiles, sector.getSeed(), true, sector.ores);
|
||||
//generateOres(tiles, sector.getSeed(), true, ores);
|
||||
|
||||
for(int x = 0; x < tiles.length; x++){
|
||||
for(int y = 0; y < tiles[0].length; y++){
|
||||
@ -238,7 +239,7 @@ public class WorldGenerator{
|
||||
}
|
||||
|
||||
public GenResult generateTile(int sectorX, int sectorY, int localX, int localY, boolean detailed){
|
||||
return generateTile(result, sectorX, sectorY, localX, localY, detailed, null);
|
||||
return generateTile(result, sectorX, sectorY, localX, localY, detailed, null, null);
|
||||
}
|
||||
|
||||
//TODO include ore in result
|
||||
@ -253,7 +254,7 @@ public class WorldGenerator{
|
||||
* @param spawnpoints list of player spawnpoints, can be null
|
||||
* @return the GenResult passed in with its values modified
|
||||
*/
|
||||
public GenResult generateTile(GenResult result, int sectorX, int sectorY, int localX, int localY, boolean detailed, Array<GridPoint2> spawnpoints){
|
||||
public GenResult generateTile(GenResult result, int sectorX, int sectorY, int localX, int localY, boolean detailed, Array<GridPoint2> spawnpoints, Array<Item> ores){
|
||||
int x = sectorX * sectorSize + localX + Short.MAX_VALUE;
|
||||
int y = sectorY * sectorSize + localY + Short.MAX_VALUE;
|
||||
|
||||
@ -321,6 +322,19 @@ public class WorldGenerator{
|
||||
wall = decoration.get(floor);
|
||||
}
|
||||
|
||||
if(ores != null && ((Floor) floor).hasOres && wall == Blocks.air){
|
||||
int offsetX = 10 + x, offsetY = 10 + y;
|
||||
for(int i = ores.size - 1; i >= 0; i--){
|
||||
Item entry = ores.get(i);
|
||||
if(sim.octaveNoise2D(1, 0.7, 1f / (10 + i * 3), offsetX, offsetY) / 4f +
|
||||
Math.abs(0.5f - sim.octaveNoise2D(2, 0.7, 1f / (50 + i * 2), offsetX, offsetY)) > 0.35f &&
|
||||
Math.abs(0.5f - sim2.octaveNoise2D(1, 1, 1f / (55 + i * 4), offsetX, offsetY)) > 0.33f){
|
||||
floor = OreBlocks.get(floor, entry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result.wall = wall;
|
||||
result.floor = floor;
|
||||
result.elevation = (byte) Math.max(elevation, 0);
|
||||
|
@ -7,12 +7,15 @@ import static io.anuke.mindustry.Vars.threads;
|
||||
|
||||
/**A mission which simply runs a single action and is completed instantly.*/
|
||||
public abstract class ActionMission extends Mission{
|
||||
private Runnable runner;
|
||||
protected Runnable runner;
|
||||
|
||||
public ActionMission(Runnable runner){
|
||||
this.runner = runner;
|
||||
}
|
||||
|
||||
public ActionMission(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete(){
|
||||
threads.run(runner);
|
||||
|
@ -0,0 +1,35 @@
|
||||
package io.anuke.mindustry.maps.missions;
|
||||
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public class BlockLocMission extends Mission{
|
||||
private final Block block;
|
||||
private final int x, y, rotation;
|
||||
|
||||
public BlockLocMission(Block block, int x, int y, int rotation){
|
||||
this.block = block;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
public BlockLocMission(Block block, int x, int y){
|
||||
this.block = block;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.rotation = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isComplete(){
|
||||
return world.tile(x, y).block() == block && (!block.rotate || world.tile(x,y).getRotation() == rotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String displayString(){
|
||||
return Bundles.format("text.mission.block", block.formalName);
|
||||
}
|
||||
}
|
@ -32,6 +32,12 @@ public class BlockMission extends Mission{
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete(){
|
||||
super.onComplete();
|
||||
complete = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isComplete(){
|
||||
return complete;
|
||||
|
@ -4,14 +4,34 @@ import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
/**An action mission which simply expands the sector.*/
|
||||
public class ExpandMission extends ActionMission{
|
||||
private boolean done = false;
|
||||
|
||||
public ExpandMission(int expandX, int expandY){
|
||||
super(() -> {
|
||||
runner = () -> {
|
||||
if(headless){
|
||||
world.sectors().expandSector(world.getSector(), expandX, expandY);
|
||||
done = true;
|
||||
}else{
|
||||
ui.loadLogic(() -> world.sectors().expandSector(world.getSector(), expandX, expandY));
|
||||
ui.loadLogic(() -> {
|
||||
world.sectors().expandSector(world.getSector(), expandX, expandY);
|
||||
done = true;
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBegin(){
|
||||
runner.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isComplete(){
|
||||
return done;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete(){
|
||||
done = false;
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ public class GenViewDialog extends FloatingDialog{
|
||||
Pixmap pixmap = new Pixmap(sectorSize, sectorSize, Format.RGBA8888);
|
||||
for(int i = 0; i < sectorSize; i++){
|
||||
for(int j = 0; j < sectorSize; j++){
|
||||
world.generator().generateTile(result, wx, wy, i, j, true, null);
|
||||
world.generator().generateTile(result, wx, wy, i, j, true, null, null);
|
||||
pixmap.drawPixel(i, sectorSize - 1 - j, ColorMapper.colorFor(result.floor, result.wall, Team.none, result.elevation, (byte)0));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user