New block color and ore system
Before Width: | Height: | Size: 253 B After Width: | Height: | Size: 252 B |
Before Width: | Height: | Size: 260 B After Width: | Height: | Size: 259 B |
Before Width: | Height: | Size: 259 B After Width: | Height: | Size: 228 B |
Before Width: | Height: | Size: 240 B After Width: | Height: | Size: 261 B |
Before Width: | Height: | Size: 256 B After Width: | Height: | Size: 270 B |
Before Width: | Height: | Size: 241 B After Width: | Height: | Size: 222 B |
Before Width: | Height: | Size: 249 B After Width: | Height: | Size: 259 B |
Before Width: | Height: | Size: 234 B After Width: | Height: | Size: 246 B |
Before Width: | Height: | Size: 268 B After Width: | Height: | Size: 265 B |
Before Width: | Height: | Size: 251 B After Width: | Height: | Size: 265 B |
Before Width: | Height: | Size: 246 B After Width: | Height: | Size: 256 B |
Before Width: | Height: | Size: 243 B After Width: | Height: | Size: 256 B |
Before Width: | Height: | Size: 253 B After Width: | Height: | Size: 239 B |
Before Width: | Height: | Size: 252 B After Width: | Height: | Size: 265 B |
Before Width: | Height: | Size: 266 B After Width: | Height: | Size: 235 B |
Before Width: | Height: | Size: 114 KiB After Width: | Height: | Size: 116 KiB |
@ -12,7 +12,9 @@ import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.*;
|
||||
|
||||
public class Blocks extends BlockList implements ContentList{
|
||||
public static Block air, spawn, blockpart, space, metalfloor, deepwater, water, lava, oil, stone, blackstone, iron, lead, coal, titanium, thorium, dirt, sand, ice, snow, grass, shrub, rock, icerock, blackrock;
|
||||
public static Block air, spawn, blockpart, space, metalfloor, deepwater, water, lava, oil, stone, blackstone, dirt, sand, ice, snow, grass, shrub, rock, icerock, blackrock;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
@ -39,6 +41,7 @@ public class Blocks extends BlockList implements ContentList{
|
||||
cacheLayer = CacheLayer.space;
|
||||
solid = true;
|
||||
blend = false;
|
||||
minimapColor = Color.valueOf("000001");
|
||||
}};
|
||||
|
||||
metalfloor = new Floor("metalfloor") {{
|
||||
@ -55,6 +58,7 @@ public class Blocks extends BlockList implements ContentList{
|
||||
statusIntensity = 1f;
|
||||
drownTime = 140f;
|
||||
cacheLayer = CacheLayer.water;
|
||||
minimapColor = Color.valueOf("465a96");
|
||||
}};
|
||||
|
||||
water = new Floor("water") {{
|
||||
@ -66,6 +70,7 @@ public class Blocks extends BlockList implements ContentList{
|
||||
liquidDrop = Liquids.water;
|
||||
isLiquid = true;
|
||||
cacheLayer = CacheLayer.water;
|
||||
minimapColor = Color.valueOf("506eb4");
|
||||
}};
|
||||
|
||||
lava = new Floor("lava") {{
|
||||
@ -78,6 +83,7 @@ public class Blocks extends BlockList implements ContentList{
|
||||
liquidDrop = Liquids.lava;
|
||||
isLiquid = true;
|
||||
cacheLayer = CacheLayer.lava;
|
||||
minimapColor = Color.valueOf("ed5334");
|
||||
}};
|
||||
|
||||
oil = new Floor("oil") {{
|
||||
@ -89,52 +95,42 @@ public class Blocks extends BlockList implements ContentList{
|
||||
liquidDrop = Liquids.oil;
|
||||
isLiquid = true;
|
||||
cacheLayer = CacheLayer.oil;
|
||||
minimapColor = Color.valueOf("292929");
|
||||
}};
|
||||
|
||||
stone = new Floor("stone") {{
|
||||
hasOres = true;
|
||||
drops = new ItemStack(Items.stone, 1);
|
||||
blends = block -> block != this && !(block instanceof Ore);
|
||||
minimapColor = Color.valueOf("323232");
|
||||
}};
|
||||
|
||||
blackstone = new Floor("blackstone") {{
|
||||
drops = new ItemStack(Items.stone, 1);
|
||||
minimapColor = Color.valueOf("252525");
|
||||
}};
|
||||
|
||||
iron = new Ore("tungsten") {{
|
||||
drops = new ItemStack(Items.tungsten, 1);
|
||||
dirt = new Floor("dirt"){{
|
||||
minimapColor = Color.valueOf("6e501e");
|
||||
}};
|
||||
|
||||
lead = new Ore("lead") {{
|
||||
drops = new ItemStack(Items.lead, 1);
|
||||
}};
|
||||
|
||||
coal = new Ore("coal") {{
|
||||
drops = new ItemStack(Items.coal, 1);
|
||||
}};
|
||||
|
||||
titanium = new Ore("titanium") {{
|
||||
drops = new ItemStack(Items.titanium, 1);
|
||||
}};
|
||||
|
||||
thorium = new Ore("thorium") {{
|
||||
drops = new ItemStack(Items.thorium, 1);
|
||||
}};
|
||||
|
||||
dirt = new Floor("dirt");
|
||||
|
||||
sand = new Floor("sand") {{
|
||||
drops = new ItemStack(Items.sand, 1);
|
||||
minimapColor = Color.valueOf("988a67");
|
||||
}};
|
||||
|
||||
ice = new Floor("ice") {{
|
||||
dragMultiplier = 0.2f;
|
||||
minimapColor = Color.valueOf("c4e3e7");
|
||||
}};
|
||||
|
||||
snow = new Floor("snow");
|
||||
snow = new Floor("snow"){{
|
||||
minimapColor = Color.valueOf("c2d1d2");
|
||||
}};
|
||||
|
||||
grass = new Floor("grass"){{
|
||||
hasOres = true;
|
||||
minimapColor = Color.valueOf("549d5b");
|
||||
}};
|
||||
|
||||
shrub = new Rock("shrub");
|
||||
|
34
core/src/io/anuke/mindustry/content/blocks/OreBlocks.java
Normal file
@ -0,0 +1,34 @@
|
||||
package io.anuke.mindustry.content.blocks;
|
||||
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import io.anuke.mindustry.content.Items;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.blocks.Floor;
|
||||
import io.anuke.mindustry.world.blocks.OreBlock;
|
||||
|
||||
public class OreBlocks extends BlockList {
|
||||
private static final ObjectMap<Item, ObjectMap<Block, Block>> oreBlockMap = new ObjectMap<>();
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
Item[] ores = {Items.tungsten, Items.lead, Items.coal, Items.titanium, Items.thorium};
|
||||
|
||||
for(Item item : ores){
|
||||
ObjectMap<Block, Block> map = new ObjectMap<>();
|
||||
oreBlockMap.put(item, map);
|
||||
|
||||
for(Block block : Block.all()){
|
||||
if(block instanceof Floor && ((Floor) block).hasOres){
|
||||
map.put(block, new OreBlock(item, (Floor) block));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Block get(Block floor, Item item){
|
||||
if(!oreBlockMap.containsKey(item)) throw new IllegalArgumentException("Item '" + item + "' is not an ore!");
|
||||
if(!oreBlockMap.get(item).containsKey(floor)) throw new IllegalArgumentException("Block '" + floor.name + "' does not support ores!");
|
||||
return oreBlockMap.get(item).get(floor);
|
||||
}
|
||||
}
|
@ -23,6 +23,7 @@ import io.anuke.mindustry.type.ContentList;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.type.StatusEffect;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.ColorMapper;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.function.Consumer;
|
||||
import io.anuke.ucore.util.Log;
|
||||
@ -83,6 +84,10 @@ public class ContentLoader {
|
||||
new PowerBlocks(),
|
||||
new CraftingBlocks(),
|
||||
new UpgradeBlocks(),
|
||||
new OreBlocks(),
|
||||
|
||||
//not really a content class, but this makes initialization easier
|
||||
new ColorMapper(),
|
||||
|
||||
//recipes
|
||||
new Recipes(),
|
||||
|
@ -9,7 +9,6 @@ import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import io.anuke.mindustry.content.blocks.Blocks;
|
||||
import io.anuke.mindustry.core.Platform;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.io.Map;
|
||||
@ -18,8 +17,6 @@ import io.anuke.mindustry.io.MapMeta;
|
||||
import io.anuke.mindustry.io.MapTileData;
|
||||
import io.anuke.mindustry.ui.dialogs.FloatingDialog;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.ColorMapper;
|
||||
import io.anuke.mindustry.world.ColorMapper.BlockPair;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
@ -365,8 +362,8 @@ public class MapEditorDialog extends Dialog implements Disposable{
|
||||
public void updateSelectedBlock(){
|
||||
Block block = editor.getDrawBlock();
|
||||
int i = 0;
|
||||
for(BlockPair pair : ColorMapper.getPairs()){
|
||||
if(pair.wall == block || (pair.wall == Blocks.air && pair.floor == block)){
|
||||
for(Block test : Block.all()){
|
||||
if(block == test){
|
||||
blockgroup.getButtons().get(i).setChecked(true);
|
||||
break;
|
||||
}
|
||||
|
@ -1,218 +0,0 @@
|
||||
package io.anuke.mindustry.editor;
|
||||
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.badlogic.gdx.utils.OrderedMap;
|
||||
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.ColorMapper;
|
||||
import io.anuke.mindustry.world.ColorMapper.BlockPair;
|
||||
import io.anuke.mindustry.content.blocks.Blocks;
|
||||
import io.anuke.mindustry.world.blocks.Floor;
|
||||
import io.anuke.ucore.graphics.Pixmaps;
|
||||
import io.anuke.ucore.noise.RidgedPerlin;
|
||||
import io.anuke.ucore.noise.Simplex;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
public class MapFilter{
|
||||
private ObjectMap<String, GenPref> prefs = map(
|
||||
pref("replace", "whether to replace blocks"),
|
||||
pref("terrain", "generate new terrain"),
|
||||
pref("circle", "generate terrain in a circle"),
|
||||
pref("distort", "distort the map image"),
|
||||
pref("sand", "add patches of sand"),
|
||||
pref("grass", "add patches of grass"),
|
||||
pref("stone", "add patches of stone"),
|
||||
pref("blackstone", "add patches of black stone"),
|
||||
pref("allgrass", "fill map with grass"),
|
||||
pref("allsnow", "fill map with snow"),
|
||||
pref("allsand", "fill map with sand"),
|
||||
pref("water", "add lakes"),
|
||||
pref("oil", "add oil lakes"),
|
||||
pref("lavariver", "add lava rivers"),
|
||||
pref("slavariver", "ad small lava rivers"),
|
||||
pref("river", "add rivers"),
|
||||
pref("iceriver", "add frozen rivers"),
|
||||
pref("oilriver", "add oil rivers")
|
||||
);
|
||||
|
||||
private Simplex sim = new Simplex();
|
||||
private RidgedPerlin rid = new RidgedPerlin(1, 10);
|
||||
private RidgedPerlin rid2 = new RidgedPerlin(1, 6);
|
||||
private RidgedPerlin rid3 = new RidgedPerlin(1, 6);
|
||||
|
||||
public MapFilter(){
|
||||
prefs.get("replace").enabled = true;
|
||||
prefs.get("terrain").enabled = true;
|
||||
randomize();
|
||||
}
|
||||
|
||||
public void randomize(){
|
||||
sim.setSeed(Mathf.random(999999));
|
||||
rid.setSeed(Mathf.random(999999));
|
||||
rid2.setSeed(Mathf.random(999999));
|
||||
rid3.setSeed(Mathf.random(999999));
|
||||
}
|
||||
|
||||
public ObjectMap<String, GenPref> getPrefs(){
|
||||
return prefs;
|
||||
}
|
||||
|
||||
public Pixmap process(Pixmap pixmap){
|
||||
if(prefs.get("terrain").enabled){
|
||||
for(int x = 0; x < pixmap.getWidth(); x++){
|
||||
for(int y = 0; y < pixmap.getHeight(); y++){
|
||||
float dist = Vector2.dst((float) x / pixmap.getWidth(), (float) y / pixmap.getHeight(), 0.5f, 0.5f) * 2f;
|
||||
double noise = sim.octaveNoise2D(6, 0.6, 1 / 180.0, x, y + 9999) / (prefs.get("circle").enabled ? 1.7 : 1f) + dist / 10f;
|
||||
|
||||
if(dist > 0.8){
|
||||
noise += 2 * (dist - 0.8);
|
||||
}
|
||||
|
||||
Block block = Blocks.stone;
|
||||
|
||||
pixmap.drawPixel(x, y, ColorMapper.getColor(block));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Pixmap src = Pixmaps.copy(pixmap);
|
||||
|
||||
for(int x = 0; x < pixmap.getWidth(); x++){
|
||||
for(int y = 0; y < pixmap.getHeight(); y++){
|
||||
int dx = 0, dy = 0;
|
||||
|
||||
if(prefs.get("distort").enabled){
|
||||
double intensity = 12;
|
||||
double scale = 80;
|
||||
double octaves = 4;
|
||||
double falloff = 0.6;
|
||||
double nx = (sim.octaveNoise2D(octaves, falloff, 1 / scale, x, y) - 0.5f) * intensity;
|
||||
double ny = (sim.octaveNoise2D(octaves, falloff, 1 / scale, x, y + 99999) - 0.5f) * intensity;
|
||||
dx = (int) nx;
|
||||
dy = (int) ny;
|
||||
}
|
||||
|
||||
int pix = src.getPixel(x + dx, y + dy);
|
||||
|
||||
BlockPair pair = ColorMapper.get(pix);
|
||||
Block block = pair == null ? null : pair.wall == Blocks.air ? pair.floor : pair.wall;
|
||||
|
||||
if(block == null)
|
||||
continue;
|
||||
|
||||
boolean floor = block instanceof Floor;
|
||||
|
||||
double noise = sim.octaveNoise2D(4, 0.6, 1 / 170.0, x, y) + sim.octaveNoise2D(1, 1.0, 1 / 5.0, x, y) / 18.0;
|
||||
double nwater = sim.octaveNoise2D(1, 1.0, 1 / 130.0, x, y);
|
||||
noise += nwater / 5.0;
|
||||
|
||||
double noil = sim.octaveNoise2D(1, 1.0, 1 / 150.0, x + 9999, y) + sim.octaveNoise2D(1, 1.0, 1 / 2.0, x, y) / 290.0;
|
||||
|
||||
if(floor){
|
||||
if(nwater > 0.93 && prefs.get("water").enabled){
|
||||
block = Blocks.water;
|
||||
if(nwater > 0.943){
|
||||
block = Blocks.deepwater;
|
||||
}
|
||||
}
|
||||
|
||||
if(noil > 0.95 && prefs.get("oil").enabled){
|
||||
block = Blocks.dirt;
|
||||
if(noil > 0.955){
|
||||
block = Blocks.oil;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(floor && prefs.get("lavariver").enabled){
|
||||
double lava = rid.getValue(x, y, 1 / 100f);
|
||||
double t = 0.6;
|
||||
if(lava > t){
|
||||
block = Blocks.lava;
|
||||
}else if(lava > t - 0.2){
|
||||
block = Blocks.blackstone;
|
||||
}
|
||||
}
|
||||
|
||||
if(floor && prefs.get("slavariver").enabled){
|
||||
double lava = rid.getValue(x, y, 1 / 40f);
|
||||
double t = 0.7;
|
||||
if(lava > t){
|
||||
block = Blocks.lava;
|
||||
}else if(lava > t - 0.3){
|
||||
block = Blocks.blackstone;
|
||||
}
|
||||
}
|
||||
|
||||
if(floor && prefs.get("oilriver").enabled){
|
||||
double lava = rid3.getValue(x, y, 1 / 100f);
|
||||
double t = 0.9;
|
||||
if(lava > t){
|
||||
block = Blocks.oil;
|
||||
}else if(lava > t - 0.2){
|
||||
block = Blocks.dirt;
|
||||
}
|
||||
}
|
||||
|
||||
if(floor && prefs.get("river").enabled){
|
||||
double riv = rid2.getValue(x, y, 1 / 140f);
|
||||
double t = 0.4;
|
||||
|
||||
if(riv > t + 0.1){
|
||||
block = Blocks.deepwater;
|
||||
}else if(riv > t){
|
||||
block = Blocks.water;
|
||||
}else if(riv > t - 0.2){
|
||||
block = Blocks.grass;
|
||||
}
|
||||
}
|
||||
|
||||
if(floor && prefs.get("iceriver").enabled){
|
||||
double riv = rid2.getValue(x, y, 1 / 140f);
|
||||
double t = 0.4;
|
||||
|
||||
if(riv > t + 0.1){
|
||||
block = Blocks.ice;
|
||||
}else if(riv > t){
|
||||
block = Blocks.ice;
|
||||
}else if(riv > t - 0.2){
|
||||
block = Blocks.snow;
|
||||
}
|
||||
}
|
||||
|
||||
pixmap.drawPixel(x, y, ColorMapper.getColor(block));
|
||||
}
|
||||
}
|
||||
|
||||
src.dispose();
|
||||
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
private static OrderedMap<String, GenPref> map(GenPref...objects){
|
||||
OrderedMap<String, GenPref> prefs = new OrderedMap<>();
|
||||
|
||||
for(int i = 0; i < objects.length; i ++){
|
||||
GenPref pref = objects[i];
|
||||
prefs.put(pref.name, pref);
|
||||
}
|
||||
return prefs;
|
||||
}
|
||||
|
||||
private GenPref pref(String name, String desc){
|
||||
return new GenPref(name, desc);
|
||||
}
|
||||
|
||||
class GenPref{
|
||||
public final String name;
|
||||
public final String description;
|
||||
public boolean enabled;
|
||||
|
||||
GenPref(String name, String description){
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
}
|
||||
}
|
@ -138,8 +138,8 @@ public class MinimapRenderer implements Disposable{
|
||||
}
|
||||
|
||||
private int colorFor(Tile tile){
|
||||
int color = tile.breakable() ? tile.target().getTeam().intColor : ColorMapper.getColor(tile.block());
|
||||
if(color == 0) color = ColorMapper.getColor(tile.floor());
|
||||
int color = tile.breakable() ? tile.target().getTeam().intColor : ColorMapper.getBlockColor(tile.block());
|
||||
if(color == 0) color = ColorMapper.getBlockColor(tile.floor());
|
||||
if(tile.cliffs != 0){
|
||||
tmpColor.set(color);
|
||||
tmpColor.mul(1.5f, 1.5f, 1.5f, 1f);
|
||||
|
@ -12,7 +12,6 @@ import io.anuke.mindustry.io.MapTileData.DataPosition;
|
||||
import io.anuke.mindustry.io.MapTileData.TileDataMarker;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.ColorMapper;
|
||||
import io.anuke.mindustry.world.ColorMapper.BlockPair;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@ -42,9 +41,9 @@ public class MapIO {
|
||||
data.read(marker);
|
||||
Block floor = Block.getByID(marker.floor);
|
||||
Block wall = Block.getByID(marker.wall);
|
||||
int wallc = ColorMapper.getColor(wall);
|
||||
if(wallc == 0 && (wall.update || wall.solid || wall.breakable)) wallc = Color.rgba8888(Team.values()[marker.team].color);
|
||||
wallc = wallc == 0 ? ColorMapper.getColor(floor) : wallc;
|
||||
int wallc = ColorMapper.getBlockColor(wall);
|
||||
if(wallc == 0 && (wall.update || wall.solid || wall.breakable)) wallc = Team.values()[marker.team].intColor;
|
||||
wallc = wallc == 0 ? ColorMapper.getBlockColor(floor) : wallc;
|
||||
if(marker.elevation > 0){
|
||||
float scaling = 1f + marker.elevation/8f;
|
||||
color.set(wallc);
|
||||
@ -65,15 +64,15 @@ public class MapIO {
|
||||
|
||||
for(int x = 0; x < data.width(); x ++){
|
||||
for(int y = 0; y < data.height(); y ++){
|
||||
BlockPair pair = ColorMapper.get(pixmap.getPixel(y, pixmap.getWidth() - 1 - x));
|
||||
Block block = ColorMapper.getByColor(pixmap.getPixel(y, pixmap.getWidth() - 1 - x));
|
||||
|
||||
if(pair == null){
|
||||
if(block == null){
|
||||
data.write(x, y, DataPosition.floor, (byte)Blocks.stone.id);
|
||||
data.write(x, y, DataPosition.wall, (byte)Blocks.air.id);
|
||||
}else{
|
||||
data.write(x, y, DataPosition.floor, (byte)pair.floor.id);
|
||||
data.write(x, y, DataPosition.wall, (byte)pair.wall.id);
|
||||
data.write(x, y, DataPosition.floor, (byte)block.id);
|
||||
}
|
||||
|
||||
data.write(x, y, DataPosition.wall, (byte)Blocks.air.id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,6 +118,8 @@ public class Block extends BaseBlock implements UnlockableContent{
|
||||
public boolean configurable;
|
||||
/**Whether this block consumes touchDown events when tapped.*/
|
||||
public boolean consumesTap;
|
||||
/**The color of this block when displayed on the minimap or map preview.*/
|
||||
public Color minimapColor = Color.CLEAR;
|
||||
|
||||
public Block(String name) {
|
||||
this.name = name;
|
||||
|
@ -2,95 +2,36 @@ package io.anuke.mindustry.world;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.IntIntMap;
|
||||
import com.badlogic.gdx.utils.IntMap;
|
||||
import com.badlogic.gdx.utils.IntMap.Entry;
|
||||
import com.badlogic.gdx.utils.ObjectIntMap;
|
||||
import io.anuke.mindustry.content.blocks.Blocks;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
import io.anuke.mindustry.type.ContentList;
|
||||
|
||||
public class ColorMapper{
|
||||
/**maps color IDs to their actual RGBA8888 colors*/
|
||||
private static int[] colorIDS;
|
||||
/**Maps RGBA8888 colors to pair IDs.*/
|
||||
private static IntIntMap reverseIDs = new IntIntMap();
|
||||
public class ColorMapper implements ContentList{
|
||||
private static IntMap<Block> blockMap = new IntMap<>();
|
||||
private static ObjectIntMap<Block> colorMap = new ObjectIntMap<>();
|
||||
|
||||
private static ObjectIntMap<Block> reverseColors = new ObjectIntMap<>();
|
||||
private static Array<BlockPair> pairs = new Array<>();
|
||||
private static IntMap<BlockPair> colors;
|
||||
@Override
|
||||
public void load() {
|
||||
for(Block block : Block.all()){
|
||||
int color = Color.rgba8888(block.minimapColor);
|
||||
if(color == 0) continue; //skip blocks that are not mapped
|
||||
|
||||
private static void init(){
|
||||
if(colors != null) return;
|
||||
|
||||
colors = map(
|
||||
"323232", pair(Blocks.stone),
|
||||
"50965a", pair(Blocks.grass),
|
||||
"506eb4", pair(Blocks.water),
|
||||
"465a96", pair(Blocks.deepwater),
|
||||
"252525", pair(Blocks.blackstone),
|
||||
"988a67", pair(Blocks.sand),
|
||||
"c2d1d2", pair(Blocks.snow),
|
||||
"c4e3e7", pair(Blocks.ice),
|
||||
"6e501e", pair(Blocks.dirt),
|
||||
"ed5334", pair(Blocks.lava),
|
||||
"292929", pair(Blocks.oil),
|
||||
"a0b0c8", pair(Blocks.iron),
|
||||
"161616", pair(Blocks.coal),
|
||||
"6277bc", pair(Blocks.titanium),
|
||||
"c594dc", pair(Blocks.thorium),
|
||||
"9790b5", pair(Blocks.lead),
|
||||
"000000", pair(Blocks.space)
|
||||
);
|
||||
}
|
||||
|
||||
public static BlockPair get(int color){
|
||||
init();
|
||||
return colors.get(color);
|
||||
}
|
||||
|
||||
public static Array<BlockPair> getPairs(){
|
||||
init();
|
||||
return pairs;
|
||||
}
|
||||
|
||||
public static int getColor(Block block){
|
||||
init();
|
||||
return reverseColors.get(block, 0);
|
||||
}
|
||||
|
||||
private static BlockPair pair(Block floor, Block wall){
|
||||
return new BlockPair(floor, wall);
|
||||
}
|
||||
|
||||
private static BlockPair pair(Block floor){
|
||||
return new BlockPair(floor, Blocks.air);
|
||||
}
|
||||
|
||||
private static IntMap<BlockPair> map(Object...objects){
|
||||
colorIDS = new int[objects.length/2];
|
||||
IntMap<BlockPair> colors = new IntMap<>();
|
||||
for(int i = 0; i < objects.length/2; i ++){
|
||||
int color = Color.rgba8888(Color.valueOf((String)objects[i*2]));
|
||||
colors.put(color, (BlockPair)objects[i*2+1]);
|
||||
pairs.add((BlockPair)objects[i*2+1]);
|
||||
colorIDS[i] = color;
|
||||
reverseIDs.put(color, i);
|
||||
}
|
||||
for(Entry<BlockPair> e : colors.entries()){
|
||||
reverseColors.put(e.value.wall == Blocks.air ? e.value.floor : e.value.wall, e.key);
|
||||
}
|
||||
return colors;
|
||||
}
|
||||
|
||||
public static class BlockPair{
|
||||
public final Block floor, wall;
|
||||
|
||||
public Block dominant(){
|
||||
return wall == Blocks.air ? floor : wall;
|
||||
}
|
||||
|
||||
private BlockPair(Block floor, Block wall){
|
||||
this.floor = floor;
|
||||
this.wall = wall;
|
||||
blockMap.put(color, block);
|
||||
colorMap.put(block, color);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<? extends Content> getAll() {
|
||||
return new Array<>();
|
||||
}
|
||||
|
||||
public static Block getByColor(int color){
|
||||
return blockMap.get(color);
|
||||
}
|
||||
|
||||
public static int getBlockColor(Block block){
|
||||
return colorMap.get(block, 0);
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public class Floor extends Block{
|
||||
protected TextureRegion[] edgeRegions;
|
||||
protected TextureRegion[] cliffRegions;
|
||||
protected Vector2[] offsets;
|
||||
protected Predicate<Block> blends = block -> block != this;
|
||||
protected Predicate<Floor> blends = block -> block != this && !block.blendOverride(this);
|
||||
protected boolean blend = true;
|
||||
|
||||
/**edge fallback, used mainly for ores*/
|
||||
@ -157,7 +157,11 @@ public class Floor extends Block{
|
||||
drawEdges(tile, false);
|
||||
}
|
||||
|
||||
private void drawEdges(Tile tile, boolean sameLayer){
|
||||
public boolean blendOverride(Block block){
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void drawEdges(Tile tile, boolean sameLayer){
|
||||
if(!blend || tile.cliffs > 0) return;
|
||||
|
||||
for(int i = 0; i < 8; i ++){
|
||||
|
61
core/src/io/anuke/mindustry/world/blocks/OreBlock.java
Normal file
@ -0,0 +1,61 @@
|
||||
package io.anuke.mindustry.world.blocks;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
|
||||
public class OreBlock extends Floor {
|
||||
protected Floor base;
|
||||
|
||||
public OreBlock(Item ore, Floor base){
|
||||
super("ore-" + ore.name + "-" + base.name);
|
||||
this.drops = new ItemStack(ore, 1);
|
||||
this.base = base;
|
||||
this.variants = 3;
|
||||
this.minimapColor = ore.color;
|
||||
this.blends = block -> false;
|
||||
this.edge = base.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
|
||||
Draw.rect(base.variants > 0 ? (base.name + MathUtils.random(1, base.variants)) : base.name, tile.worldx(), tile.worldy());
|
||||
|
||||
int rand = variants > 0 ? MathUtils.random(1, variants) : 0;
|
||||
|
||||
Draw.color(0f, 0f, 0f, 0.2f);
|
||||
Draw.rect(variants > 0 ? (drops.item.name + rand) : name, tile.worldx(), tile.worldy() - 1);
|
||||
Draw.color();
|
||||
Draw.rect(variants > 0 ? (drops.item.name + rand) : name, tile.worldx(), tile.worldy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureRegion[] getIcon() {
|
||||
if(icon == null){
|
||||
icon = new TextureRegion[]{Draw.region(drops.item.name + "1")};
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawNonLayer(Tile tile){
|
||||
MathUtils.random.setSeed(tile.id());
|
||||
|
||||
base.drawEdges(tile, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawEdges(Tile tile, boolean sameLayer){
|
||||
base.drawEdges(tile, sameLayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean blendOverride(Block block) {
|
||||
return block == base;
|
||||
}
|
||||
}
|
@ -2,11 +2,14 @@ package io.anuke.mindustry.world.mapgen;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.IntArray;
|
||||
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.io.MapTileData;
|
||||
import io.anuke.mindustry.io.MapTileData.TileDataMarker;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.noise.RidgedPerlin;
|
||||
@ -24,11 +27,11 @@ public class WorldGenerator {
|
||||
oreIndex = 0;
|
||||
|
||||
Array<OreEntry> ores = Array.with(
|
||||
new OreEntry(Blocks.iron, 0.3f, seed),
|
||||
new OreEntry(Blocks.coal, 0.284f, seed),
|
||||
new OreEntry(Blocks.lead, 0.28f, seed),
|
||||
new OreEntry(Blocks.titanium, 0.27f, seed),
|
||||
new OreEntry(Blocks.thorium, 0.26f, seed)
|
||||
new OreEntry(Items.tungsten, 0.3f, seed),
|
||||
new OreEntry(Items.coal, 0.284f, seed),
|
||||
new OreEntry(Items.lead, 0.28f, seed),
|
||||
new OreEntry(Items.titanium, 0.27f, seed),
|
||||
new OreEntry(Items.thorium, 0.26f, seed)
|
||||
);
|
||||
|
||||
IntArray multiblocks = new IntArray();
|
||||
@ -110,7 +113,8 @@ public class WorldGenerator {
|
||||
if(entry.noise.octaveNoise2D(2, 0.7, 1f / (2 + i*2), x, y)/2f +
|
||||
entry.ridge.getValue(x, y, 1f / (28 + i*4)) >= 2.0f - entry.frequency*4.0f
|
||||
&& entry.ridge.getValue(x+9999, y+9999, 1f/100f) > 0.4){
|
||||
tile.setFloor(entry.block);
|
||||
tile.setFloor(OreBlocks.get(tile.floor(), entry.item));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -120,14 +124,14 @@ public class WorldGenerator {
|
||||
|
||||
static class OreEntry{
|
||||
final float frequency;
|
||||
final Block block;
|
||||
final Item item;
|
||||
final Simplex noise;
|
||||
final RidgedPerlin ridge;
|
||||
final int index;
|
||||
|
||||
OreEntry(Block block, float frequency, int seed) {
|
||||
OreEntry(Item item, float frequency, int seed) {
|
||||
this.frequency = frequency;
|
||||
this.block = block;
|
||||
this.item = item;
|
||||
this.noise = new Simplex(seed + oreIndex);
|
||||
this.ridge = new RidgedPerlin(seed + oreIndex, 2);
|
||||
this.index = oreIndex ++;
|
||||
|