New world generation methods
This commit is contained in:
@@ -195,6 +195,12 @@ public class World extends Module{
|
||||
generating = true;
|
||||
}
|
||||
|
||||
/**Call to signal the beginning of loading the map with a custom set of tiles.*/
|
||||
public void beginMapLoad(Tile[][] tiles){
|
||||
this.tiles = tiles;
|
||||
generating = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call to signify the end of map loading. Updates tile occlusions and sets up physics for the world.
|
||||
* A WorldLoadEvent will be fire.
|
||||
|
||||
@@ -15,7 +15,11 @@ import io.anuke.mindustry.maps.missions.WaveMission;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.world.ColorMapper;
|
||||
import io.anuke.mindustry.world.Edges;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Settings;
|
||||
import io.anuke.ucore.entities.Entities;
|
||||
import io.anuke.ucore.entities.EntityGroup;
|
||||
import io.anuke.ucore.entities.trait.Entity;
|
||||
import io.anuke.ucore.util.Bits;
|
||||
import io.anuke.ucore.util.GridMap;
|
||||
import io.anuke.ucore.util.Log;
|
||||
@@ -25,6 +29,7 @@ import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Sectors{
|
||||
private static final int sectorImageSize = 32;
|
||||
private static final boolean checkExpansion = false;
|
||||
private static final float sectorLargeChance = 0.24f;
|
||||
|
||||
private GridMap<Sector> grid = new GridMap<>();
|
||||
@@ -78,6 +83,7 @@ public class Sectors{
|
||||
sector.width += expandX;
|
||||
sector.height += expandY;
|
||||
|
||||
//remove old sector data to clear things up
|
||||
for(int x = sector.x; x < sector.x+sector.width; x++){
|
||||
for(int y = sector.y; y < sector.y+sector.height; y++){
|
||||
grid.put(x, y, null);
|
||||
@@ -87,13 +93,76 @@ public class Sectors{
|
||||
if(expandX < 0) sector.x += expandX;
|
||||
if(expandY < 0) sector.y += expandY;
|
||||
|
||||
sector.width += Math.abs(expandX);
|
||||
sector.height += Math.abs(expandY);
|
||||
|
||||
if(checkExpansion) {
|
||||
for (int x = sector.x; x < sector.x + sector.width; x++) {
|
||||
for (int y = sector.y; y < sector.y + sector.height; y++) {
|
||||
if (grid.get(x, y) != null && grid.get(x, y).complete) {
|
||||
//if a completed sector is hit, expansion failed
|
||||
if (expandX < 0) sector.x -= expandX;
|
||||
if (expandY < 0) sector.y -= expandY;
|
||||
sector.width -= Math.abs(expandX);
|
||||
sector.height -= Math.abs(expandY);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//add new sector spaces
|
||||
for(int x = sector.x; x < sector.x+sector.width; x++){
|
||||
for(int y = sector.y; y < sector.y+sector.height; y++){
|
||||
grid.put(x, y, sector);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
//sector map data should now be shifted and generated
|
||||
int shiftX = expandX < 0 ? -expandX*sectorSize : 0;
|
||||
int shiftY = expandY < 0 ? -expandY*sectorSize : 0;
|
||||
|
||||
for(EntityGroup<?> group : Entities.getAllGroups()){
|
||||
for(Entity entity : group.all()){
|
||||
entity.set(entity.getX() + shiftX * tilesize, entity.getY() + shiftY * tilesize);
|
||||
}
|
||||
}
|
||||
|
||||
//create *new* tile array
|
||||
Tile[][] newTiles = new Tile[sector.width * sectorSize][sector.height * sectorSize];
|
||||
|
||||
world.beginMapLoad(newTiles);
|
||||
|
||||
//shift existing tiles to new array
|
||||
for (int x = 0; x < (sector.width - Math.abs(expandX)); x++) {
|
||||
for (int y = 0; y < (sector.height - Math.abs(expandY)); y++) {
|
||||
Tile tile = world.rawTile(x, y);
|
||||
tile.x = (short)(x + shiftX);
|
||||
tile.y = (short)(y + shiftY);
|
||||
newTiles[x + shiftX][y + shiftY] = tile;
|
||||
}
|
||||
}
|
||||
|
||||
//create new tiles
|
||||
for (int sx = 0; sx < sector.width; sx++) {
|
||||
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){
|
||||
//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);
|
||||
newTiles[sx * sectorSize + x][sy * sectorSize + y] = new Tile(x + sx * tilesize, y + sy*tilesize, result.floor.id, result.wall.id, (byte)0, (byte)0, result.elevation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//end loading of map
|
||||
world.endMapLoad();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**Unlocks a sector. This shows nearby sectors.*/
|
||||
|
||||
@@ -8,7 +8,6 @@ import com.badlogic.gdx.utils.ObjectMap;
|
||||
import io.anuke.mindustry.content.Items;
|
||||
import io.anuke.mindustry.content.blocks.Blocks;
|
||||
import io.anuke.mindustry.content.blocks.OreBlocks;
|
||||
import io.anuke.mindustry.content.blocks.StorageBlocks;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.maps.MapTileData;
|
||||
import io.anuke.mindustry.maps.MapTileData.TileDataMarker;
|
||||
@@ -26,7 +25,8 @@ import io.anuke.ucore.util.Geometry;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.SeedRandom;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
import static io.anuke.mindustry.Vars.sectorSize;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
|
||||
public class WorldGenerator{
|
||||
@@ -73,6 +73,11 @@ public class WorldGenerator{
|
||||
generateOres(tiles, seed, genOres, null);
|
||||
}
|
||||
|
||||
/**'Prepares' a tile array by:<br>
|
||||
* - setting up multiblocks<br>
|
||||
* - updating cliff data<br>
|
||||
* - removing ores on cliffs<br>
|
||||
* Usually used before placing structures on a tile array.*/
|
||||
public void prepareTiles(Tile[][] tiles){
|
||||
|
||||
//find multiblocks
|
||||
@@ -82,14 +87,8 @@ public class WorldGenerator{
|
||||
for(int y = 0; y < tiles[0].length; y++){
|
||||
Tile tile = tiles[x][y];
|
||||
|
||||
Team team = tile.getTeam();
|
||||
|
||||
if(tile.block() == StorageBlocks.core){
|
||||
state.teams.get(team).cores.add(tile);
|
||||
}
|
||||
|
||||
if(tiles[x][y].block().isMultiblock()){
|
||||
multiblocks.add(tiles[x][y].packedPosition());
|
||||
if(tile.block().isMultiblock()){
|
||||
multiblocks.add(tile.packedPosition());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -134,6 +133,7 @@ public class WorldGenerator{
|
||||
tile.setBlock(Blocks.air);
|
||||
}
|
||||
|
||||
//remove ore veins on cliffs
|
||||
if(tile.floor() instanceof OreBlock && tile.hasCliffs()){
|
||||
tile.setFloor(((OreBlock)tile.floor()).base);
|
||||
}
|
||||
@@ -245,6 +245,17 @@ public class WorldGenerator{
|
||||
return generateTile(result, sectorX, sectorY, localX, localY, detailed, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the generation result from a specific sector at specific coordinates.
|
||||
* @param result where to put the generation results
|
||||
* @param sectorX X of the sector in terms of sector coordinates
|
||||
* @param sectorY Y of the sector in terms of sector coordinates
|
||||
* @param localX X in terms of local sector tile coordinates
|
||||
* @param localY Y in terms of local sector tile coordinates
|
||||
* @param detailed whether the tile result is 'detailed' (e.g. previews should not be detailed)
|
||||
* @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){
|
||||
int x = sectorX * sectorSize + localX + Short.MAX_VALUE;
|
||||
int y = sectorY * sectorSize + localY + Short.MAX_VALUE;
|
||||
|
||||
@@ -79,6 +79,14 @@ public class CoreBlock extends StorageBlock{
|
||||
if(entity != null) entity.solid = solid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProximityUpdate(Tile tile) {
|
||||
//add cores
|
||||
if(!state.teams.get(tile.getTeam()).cores.contains(tile, true)){
|
||||
state.teams.get(tile.getTeam()).cores.add(tile);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreak(Tile tile){
|
||||
return state.teams.get(tile.getTeam()).cores.size > 1;
|
||||
|
||||
Reference in New Issue
Block a user