Start of groundwork for dynamic bases
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
package io.anuke.mindustry.maps.generation;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.Predicate;
|
||||
import io.anuke.mindustry.content.blocks.StorageBlocks;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.blocks.production.Drill;
|
||||
import io.anuke.mindustry.world.consumers.ConsumePower;
|
||||
|
||||
public class FortressGenerator{
|
||||
private final static int minCoreDst = 60;
|
||||
@@ -11,7 +16,6 @@ public class FortressGenerator{
|
||||
private Generation gen;
|
||||
|
||||
public void generate(Generation gen, Team team, int coreX, int coreY, int enemyX, int enemyY){
|
||||
|
||||
this.enemyX = enemyX;
|
||||
this.enemyY = enemyY;
|
||||
this.coreX = coreX;
|
||||
@@ -24,5 +28,24 @@ public class FortressGenerator{
|
||||
|
||||
void gen(){
|
||||
gen.tiles[enemyX][enemyY].setBlock(StorageBlocks.core, team);
|
||||
|
||||
Array<Block> drills = find(b -> b instanceof Drill && !b.consumes.has(ConsumePower.class));
|
||||
|
||||
for(int x = 0; x < gen.width; x++){
|
||||
for(int y = 0; y < gen.height; y++){
|
||||
//TODO place valid drills
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Array<Block> find(Predicate<Block> pred){
|
||||
Array<Block> out = new Array<>();
|
||||
for(Block block : Block.all()){
|
||||
if(pred.evaluate(block)){
|
||||
out.add(block);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
package io.anuke.mindustry.maps.generation;
|
||||
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.maps.Sector;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.production.Drill;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.SeedRandom;
|
||||
|
||||
public class Generation{
|
||||
@@ -17,4 +22,69 @@ public class Generation{
|
||||
this.height = height;
|
||||
this.random = random;
|
||||
}
|
||||
|
||||
//TODO implement
|
||||
Item drillItem(int x, int y, Drill block){
|
||||
if(block.isMultiblock()){
|
||||
Item result = null;
|
||||
int offsetx = -(block.size - 1) / 2;
|
||||
int offsety = -(block.size - 1) / 2;
|
||||
|
||||
for(int dx = 0; dx < block.size; dx++){
|
||||
for(int dy = 0; dy < block.size; dy++){
|
||||
int worldx = dx + offsetx + x;
|
||||
int worldy = dy + offsety + y;
|
||||
if(!Mathf.inBounds(worldx, worldy, tiles)){
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}else{
|
||||
return tiles[x][y].floor().drops == null ? null : tiles[x][y].floor().drops.item;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canPlace(int x, int y, Block block){
|
||||
if(block.isMultiblock()){
|
||||
int offsetx = -(block.size - 1) / 2;
|
||||
int offsety = -(block.size - 1) / 2;
|
||||
|
||||
for(int dx = 0; dx < block.size; dx++){
|
||||
for(int dy = 0; dy < block.size; dy++){
|
||||
int worldx = dx + offsetx + x;
|
||||
int worldy = dy + offsety + y;
|
||||
if(!Mathf.inBounds(worldx, worldy, tiles) || !tiles[worldx][worldy].block().alwaysReplace){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}else{
|
||||
return tiles[x][y].block().alwaysReplace;
|
||||
}
|
||||
}
|
||||
|
||||
public void setBlock(int x, int y, Block block, Team team){
|
||||
tiles[x][y].setBlock(block, team);
|
||||
if(block.isMultiblock()){
|
||||
int offsetx = -(block.size - 1) / 2;
|
||||
int offsety = -(block.size - 1) / 2;
|
||||
|
||||
for(int dx = 0; dx < block.size; dx++){
|
||||
for(int dy = 0; dy < block.size; dy++){
|
||||
int worldx = dx + offsetx + x;
|
||||
int worldy = dy + offsety + y;
|
||||
if(!(worldx == x && worldy == y) && Mathf.inBounds(worldx, worldy, tiles)){
|
||||
Tile toplace = tiles[worldx][worldy];
|
||||
if(toplace != null){
|
||||
toplace.setLinked((byte) (dx + offsetx), (byte) (dy + offsety));
|
||||
toplace.setTeam(team);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user