New ore system / Multiblock fixes

This commit is contained in:
Anuken
2019-03-12 13:28:00 -04:00
parent e4875903f1
commit 8ad6f3abcc
30 changed files with 1594 additions and 3260 deletions

View File

@@ -203,7 +203,7 @@ public class BlockIndexer{
for(int x = Math.max(0, tile.x - oreQuadrantSize / 2); x < tile.x + oreQuadrantSize / 2 && x < world.width(); x++){
for(int y = Math.max(0, tile.y - oreQuadrantSize / 2); y < tile.y + oreQuadrantSize / 2 && y < world.height(); y++){
Tile res = world.tile(x, y);
if(res.block() == Blocks.air && res.floor().itemDrop == item){
if(res.block() == Blocks.air && res.drop() == item){
return res;
}
}
@@ -241,9 +241,9 @@ public class BlockIndexer{
for(int x = quadrantX * structQuadrantSize; x < world.width() && x < (quadrantX + 1) * structQuadrantSize; x++){
for(int y = quadrantY * structQuadrantSize; y < world.height() && y < (quadrantY + 1) * structQuadrantSize; y++){
Tile result = world.tile(x, y);
if( result == null || result.floor().itemDrop == null || !scanOres.contains(result.floor().itemDrop)) continue;
if( result == null || result.drop() == null || !scanOres.contains(result.drop())) continue;
itemSet.add(result.floor().itemDrop);
itemSet.add(result.drop());
}
}
@@ -320,8 +320,8 @@ public class BlockIndexer{
Tile tile = world.tile(x, y);
//add position of quadrant to list when an ore is found
if(tile.floor().itemDrop != null && scanOres.contains(tile.floor().itemDrop) && tile.block() == Blocks.air){
ores.get(tile.floor().itemDrop).add(world.tile(
if(tile.drop() != null && scanOres.contains(tile.drop()) && tile.block() == Blocks.air){
ores.get(tile.drop()).add(world.tile(
//make sure to clamp quadrant middle position, since it might go off bounds
Mathf.clamp(qx * oreQuadrantSize + oreQuadrantSize / 2, 0, world.width() - 1),
Mathf.clamp(qy * oreQuadrantSize + oreQuadrantSize / 2, 0, world.height() - 1)));

View File

@@ -7,7 +7,6 @@ import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.graphics.CacheLayer;
import io.anuke.mindustry.type.Category;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.ItemStack;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
@@ -28,7 +27,8 @@ import io.anuke.mindustry.world.blocks.units.UnitFactory;
import io.anuke.mindustry.world.consumers.ConsumeItemFilter;
import io.anuke.mindustry.world.consumers.ConsumeLiquidFilter;
import static io.anuke.mindustry.Vars.*;
import static io.anuke.mindustry.Vars.state;
import static io.anuke.mindustry.Vars.world;
public class Blocks implements ContentList{
public static Block
@@ -39,6 +39,9 @@ public class Blocks implements ContentList{
iceSnow, sandWater, duneRocks, sandRocks, stainedRocks, moss, stainedRocksRed, stainedStoneRed, stainedRocksYellow, stainedStoneYellow, stainedBoulder, grass, salt,
metalFloor, metalFloorDamaged, metalFloor2, metalFloor3, metalFloor5, ignarock, magmarock, hotrock, snowrocks,
//ores
oreCopper, oreLead, oreScrap, oreCoal, oreTitanium, oreThorium,
//crafting
siliconSmelter, kiln, graphitePress, plastaniumCompressor, multiPress, phaseWeaver, surgeSmelter, pyratiteMixer, blastMixer, cryofluidMixer,
melter, separator, sporePress, pulverizer, incinerator,
@@ -145,7 +148,7 @@ public class Blocks implements ContentList{
}};
stone = new Floor("stone"){{
hasOres = true;
}};
craters = new Floor("craters"){{
@@ -170,12 +173,10 @@ public class Blocks implements ContentList{
sand = new Floor("sand"){{
itemDrop = Items.sand;
hasOres = true;
playerUnmineable = true;
}};
holostone = new Floor("holostone"){{
hasOres = true;
edgeStyle = "blocky";
}};
@@ -226,7 +227,6 @@ public class Blocks implements ContentList{
}};
pine = new StaticWall("pine"){{
//fillsTile = false;
variants = 0;
}};
@@ -253,7 +253,6 @@ public class Blocks implements ContentList{
}};
stainedStoneRed = new Floor("stained-stone-red"){{
hasOres = true;
variants = 1;
}};
@@ -308,6 +307,16 @@ public class Blocks implements ContentList{
blendGroup = ignarock;
}};
//endregion
//region ore
oreCopper = new OreBlock(Items.copper);
oreLead = new OreBlock(Items.lead);
oreScrap = new OreBlock(Items.scrap);
oreCoal = new OreBlock(Items.coal);
oreTitanium = new OreBlock(Items.titanium);
oreThorium = new OreBlock(Items.thorium);
//endregion
//region crafting
@@ -1418,23 +1427,6 @@ public class Blocks implements ContentList{
consumes.powerBuffered(120f);
}};
//endregion
//region ores
//create ores for every floor and item combination necessary
for(Item item : content.items()){
if(!item.genOre) continue;
for(Block block : content.blocks()){
if(block instanceof Floor && ((Floor) block).hasOres){
new OreBlock(item, (Floor) block);
}
}
}
//special variants
new OreBlock(Items.scrap, (Floor)snow);
//endregion
}
}

View File

@@ -15,7 +15,6 @@ public class Items implements ContentList{
type = ItemType.material;
hardness = 1;
cost = 0.6f;
genOre = true;
alwaysUnlocked = true;
}};
@@ -23,7 +22,6 @@ public class Items implements ContentList{
type = ItemType.material;
hardness = 1;
cost = 0.9f;
genOre = true;
}};
metaglass = new Item("metaglass", Color.valueOf("ebeef5")){{
@@ -40,14 +38,12 @@ public class Items implements ContentList{
explosiveness = 0.4f;
flammability = 1f;
hardness = 2;
genOre = true;
}};
titanium = new Item("titanium", Color.valueOf("8da1e3")){{
type = ItemType.material;
hardness = 3;
cost = 1.1f;
genOre = true;
}};
thorium = new Item("thorium", Color.valueOf("f9a3c7")){{
@@ -56,11 +52,10 @@ public class Items implements ContentList{
hardness = 4;
radioactivity = 1f;
cost = 1.4f;
genOre = true;
}};
scrap = new Item("scrap", Color.valueOf("777777")){{
genOre = true;
}};
silicon = new Item("silicon", Color.valueOf("53565c")){{

View File

@@ -45,7 +45,7 @@ public class DrawOperation{
}else if(type == OpType.team.ordinal()){
tile.setTeam(Team.all[to]);
}else if(type == OpType.ore.ordinal()){
tile.setOre(to);
tile.setOreByte(to);
}
});
editor.renderer().updatePoint(tile.x, tile.y);

View File

@@ -1,11 +1,13 @@
package io.anuke.mindustry.editor;
import io.anuke.mindustry.content.Blocks;
import io.anuke.mindustry.editor.DrawOperation.OpType;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.gen.TileOp;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Floor;
import io.anuke.mindustry.world.blocks.OreBlock;
import io.anuke.mindustry.world.modules.ConsumeModule;
import io.anuke.mindustry.world.modules.ItemModule;
import io.anuke.mindustry.world.modules.LiquidModule;
@@ -19,12 +21,30 @@ public class EditorTile extends Tile{
super(x, y, floor, wall);
}
@Override
public Team getTeam(){
return Team.all[getTeamID()];
}
@Override
public void setFloor(Floor type){
if(type instanceof OreBlock){
//don't place on liquids
if(!floor().isLiquid) setOreByte(type.id);
return;
}
Block previous = floor();
if(previous == type) return;
Block ore = oreBlock();
if(previous == type && ore == Blocks.air) return;
super.setFloor(type);
op(TileOp.get(x, y, (byte)OpType.floor.ordinal(), previous.id, type.id));
//ore may get nullified so make sure to save editrs
if(oreBlock() != ore){
op(TileOp.get(x, y, (byte)OpType.ore.ordinal(), ore.id, oreBlock().id));
}
if(previous != type){
op(TileOp.get(x, y, (byte)OpType.floor.ordinal(), previous.id, type.id));
}
}
@Override
@@ -52,10 +72,10 @@ public class EditorTile extends Tile{
}
@Override
public void setOre(byte ore){
byte previous = getRotation();
public void setOreByte(byte ore){
byte previous = getOreByte();
if(previous == ore) return;
super.setOre(ore);
super.setOreByte(ore);
op(TileOp.get(x, y, (byte)OpType.ore.ordinal(), previous, ore));
}

View File

@@ -3,6 +3,7 @@ package io.anuke.mindustry.editor;
import io.anuke.arc.collection.ObjectMap;
import io.anuke.arc.files.FileHandle;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.util.Log;
import io.anuke.arc.util.Pack;
import io.anuke.arc.util.Structs;
import io.anuke.mindustry.content.Blocks;
@@ -52,6 +53,7 @@ public class MapEditor{
tiles = createTiles(map.width, map.height);
tags.putAll(map.tags);
MapIO.readTiles(map, tiles);
checkTiles();
renderer.resize(width(), height());
loading = false;
}
@@ -60,9 +62,46 @@ public class MapEditor{
reset();
this.tiles = tiles;
checkTiles();
renderer.resize(width(), height());
}
//adds missing blockparts
void checkTiles(){
//clear block parts first
for(int x = 0; x < width(); x ++){
for(int y = 0; y < height(); y++){
if(tiles[x][y].block() == Blocks.part){
tiles[x][y].setBlock(Blocks.air);
tiles[x][y].setLinkByte((byte)0);
}
}
}
//set up missing blockparts
for(int x = 0; x < width(); x ++){
for(int y = 0; y < height(); y ++){
Block drawBlock = tiles[x][y].block();
if(drawBlock.isMultiblock()){
int offsetx = -(drawBlock.size - 1) / 2;
int offsety = -(drawBlock.size - 1) / 2;
for(int dx = 0; dx < drawBlock.size; dx++){
for(int dy = 0; dy < drawBlock.size; dy++){
int worldx = dx + offsetx + x;
int worldy = dy + offsety + y;
if(Structs.inBounds(worldx, worldy, width(), height()) && !(dx + offsetx == 0 && dy + offsety == 0)){
Tile tile = tiles[worldx][worldy];
tile.setBlock(Blocks.part);
tile.setLinkByte(Pack.byteByte((byte) (dx + offsetx + 8), (byte) (dy + offsety + 8)));
}
}
}
}
}
}
}
public void load(Runnable r){
loading = true;
r.run();
@@ -137,6 +176,7 @@ public class MapEditor{
Tile tile = tiles[worldx][worldy];
if(i == 1){
tile.setBlock(Blocks.part);
tile.setLinked((byte)(dx + offsetx), (byte)(dy + offsety));
}else{
byte link = tile.getLinkByte();
@@ -170,10 +210,11 @@ public class MapEditor{
if(!isfloor){
byte link = tile.getLinkByte();
Log.info("Remove linkd: " + tiles[x][y]);
if(tile.block().isMultiblock()){
removeLinked(wx, wy);
}else if(link != 0){
}else if(link != 0 && tiles[x][y].block() == Blocks.part){
removeLinked(wx - (Pack.leftByte(link) - 8), wy - (Pack.rightByte(link) - 8));
}
}

View File

@@ -422,6 +422,12 @@ public class MapEditorDialog extends Dialog implements Disposable{
}
}
if(Core.input.keyTap(KeyCode.ESCAPE)){
if(!menu.isShown()){
menu.show();
}
}
if(Core.input.keyTap(KeyCode.R)){
editor.rotation = Mathf.mod(editor.rotation + 1, 4);
}

View File

@@ -139,6 +139,8 @@ public class MapRenderer implements Disposable{
region = !Core.atlas.isFound(wall.editorIcon()) ? Core.atlas.find("clear-editor") : wall.editorIcon();
offsetX = tilesize/2f - region.getWidth()/2f * Draw.scl;
offsetY = tilesize/2f - region.getHeight()/2f * Draw.scl;
}else if(wall == Blocks.air && tile.oreBlock() != null){
region = tile.oreBlock().editorVariantRegions()[Mathf.randomSeed(idxWall, 0, tile.oreBlock().editorVariantRegions().length-1)];;
}else{
region = Core.atlas.find("clear-editor");
}

View File

@@ -252,10 +252,10 @@ public interface BuilderTrait extends Entity, TeamTrait{
TileEntity core = unit.getClosestCore();
if(core == null || tile.block() != Blocks.air || dst(tile.worldx(), tile.worldy()) > mineDistance
|| tile.floor().itemDrop == null || !unit.acceptsItem(tile.floor().itemDrop) || !canMine(tile.floor().itemDrop)){
|| tile.drop() == null || !unit.acceptsItem(tile.drop()) || !canMine(tile.drop())){
setMineTile(null);
}else{
Item item = tile.floor().itemDrop;
Item item = tile.drop();
unit.rotation = Mathf.slerpDelta(unit.rotation, unit.angleTo(tile.worldx(), tile.worldy()), 0.4f);
if(Mathf.chance(Time.delta() * (0.06 - item.hardness * 0.01) * getMinePower())){

View File

@@ -137,7 +137,7 @@ public class MinimapRenderer implements Disposable{
private int colorFor(Tile tile){
tile = tile.target();
return MapIO.colorFor(tile.floor(), tile.block(), tile.getTeam());
return MapIO.colorFor(tile.floor(), tile.block(), tile.oreBlock(), tile.getTeam());
}
@Override

View File

@@ -230,9 +230,9 @@ public abstract class InputHandler implements InputProcessor{
boolean canMine(Tile tile){
return !Core.scene.hasMouse()
&& tile.floor().itemDrop != null && tile.floor().itemDrop.hardness <= player.mech.drillPower
&& tile.drop() != null && tile.drop().hardness <= player.mech.drillPower
&& !tile.floor().playerUnmineable
&& player.acceptsItem(tile.floor().itemDrop)
&& player.acceptsItem(tile.drop())
&& tile.block() == Blocks.air && player.dst(tile.worldx(), tile.worldy()) <= Player.mineDistance;
}

View File

@@ -7,6 +7,7 @@ import io.anuke.arc.files.FileHandle;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.Pixmap;
import io.anuke.arc.graphics.Pixmap.Format;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.util.Pack;
import io.anuke.arc.util.Structs;
import io.anuke.mindustry.content.Blocks;
@@ -66,13 +67,19 @@ public class MapIO{
CachedTile tile = new CachedTile(){
@Override
public void setFloor(Floor type){
floor.drawPixel(x, floor.getHeight() - 1 - y, colorFor(type, Blocks.air, getTeam()));
floor.drawPixel(x, floor.getHeight() - 1 - y, colorFor(type, Blocks.air, Blocks.air, getTeam()));
}
@Override
public void setOreByte(byte b){
if(b != 0)
floor.drawPixel(x, floor.getHeight() - 1 - y, colorFor(floor(), Blocks.air, content.block(b), getTeam()));
}
@Override
protected void changed(){
super.changed();
int c = colorFor(Blocks.air, block(), getTeam());
int c = colorFor(Blocks.air, block(), Blocks.air, getTeam());
if(c != black) wall.drawPixel(x, floor.getHeight() - 1 - y, c);
}
};
@@ -91,17 +98,17 @@ public class MapIO{
for(int x = 0; x < pixmap.getWidth(); x++){
for(int y = 0; y < pixmap.getHeight(); y++){
Tile tile = tiles[x][y];
pixmap.drawPixel(x, pixmap.getHeight() - 1 - y, colorFor(tile.floor(), tile.block(), tile.getTeam()));
pixmap.drawPixel(x, pixmap.getHeight() - 1 - y, colorFor(tile.floor(), tile.block(), tile.oreBlock(), tile.getTeam()));
}
}
return pixmap;
}
public static int colorFor(Block floor, Block wall, Team team){
public static int colorFor(Block floor, Block wall, Block ore, Team team){
if(wall.synthetic()){
return team.intColor;
}
return Color.rgba8888(wall.solid ? wall.color : floor.color);
return Color.rgba8888(wall.solid ? wall.color : ore == Blocks.air ? floor.color : ore.color);
}
public static void writeMap(FileHandle file, Map map, Tile[][] tiles) throws IOException{
@@ -130,13 +137,13 @@ public class MapIO{
for(int i = 0; i < tiles.length * tiles[0].length; i++){
Tile tile = tiles[i % width][i / width];
stream.writeByte(tile.getFloorID());
stream.writeByte(tile.getOre());
stream.writeByte(tile.getOreByte());
int consecutives = 0;
for(int j = i + 1; j < width * height && consecutives < 255; j++){
Tile nextTile = tiles[j % width][j / width];
if(nextTile.getFloorID() != tile.getFloorID() || nextTile.block() != Blocks.air || nextTile.getOre() != tile.getOre()){
if(nextTile.getFloorID() != tile.getFloorID() || nextTile.block() != Blocks.air || nextTile.getOreByte() != tile.getOreByte()){
break;
}
@@ -258,13 +265,13 @@ public class MapIO{
Tile tile = tiles.get(x, y);
tile.setFloor((Floor)content.block(floorid));
tile.setOre(oreid);
tile.setOreByte(oreid);
for(int j = i + 1; j < i + 1 + consecutives; j++){
int newx = j % width, newy = j / width;
Tile newTile = tiles.get(newx, newy);
newTile.setFloor((Floor)content.block(floorid));
newTile.setOre(oreid);
newTile.setOreByte(oreid);
}
i += consecutives;
@@ -323,6 +330,7 @@ public class MapIO{
tile.setFloor(block.floor);
tile.setBlock(block.wall);
if(block.ore != null) tile.setOre(block.ore);
//place core
if(color == Color.rgba8888(Color.GREEN)){
@@ -384,9 +392,10 @@ public class MapIO{
String[] split = name.split("-");
String itemName = split[1], floorName = split[2];
Item item = content.getByName(ContentType.item, itemName);
Block oreBlock = item == null ? null : content.getByName(ContentType.block, "ore-" + item.name);
Block floor = content.getByName(ContentType.block, floorName);
if(item != null && floor != null){
oreMap.put(id, item.id);
if(oreBlock != null && floor != null){
oreMap.put(id, oreBlock.id);
block = floor;
}else{
block = Blocks.air;
@@ -406,18 +415,22 @@ public class MapIO{
byte floorb = stream.readByte();
byte blockb = stream.readByte();
byte rotTeamb = stream.readByte();
byte linkb = stream.readByte();
stream.readByte(); //unused stuff
byte link = stream.readByte();
stream.readByte();//unused stuff
tile.setFloor((Floor)content.block(map.get(floorb, 0)));
tile.setBlock(content.block(map.get(blockb, 0)));
tile.setRotation(Pack.leftByte(rotTeamb));
if(tile.block().synthetic()){
tile.setTeam(Team.all[Mathf.clamp(Pack.rightByte(rotTeamb), 0, Team.all.length)]);
}
if(tile.block() == Blocks.part){
tile.setLinkByte(linkb);
tile.setLinkByte(link);
}
if(oreMap.containsKey(floorb)){
tile.setOre((byte)oreMap.get(floorb, 0));
tile.setOreByte((byte)oreMap.get(floorb, 0));
}
}
}

View File

@@ -51,13 +51,13 @@ public abstract class SaveFileVersion{
for(int i = 0; i < world.width() * world.height(); i++){
Tile tile = world.tile(i % world.width(), i / world.width());
stream.writeByte(tile.getFloorID());
stream.writeByte(tile.getOre());
stream.writeByte(tile.getOreByte());
int consecutives = 0;
for(int j = i + 1; j < world.width() * world.height() && consecutives < 255; j++){
Tile nextTile = world.tile(j % world.width(), j / world.width());
if(nextTile.getFloorID() != tile.getFloorID() || nextTile.getOre() != tile.getOre()){
if(nextTile.getFloorID() != tile.getFloorID() || nextTile.getOreByte() != tile.getOreByte()){
break;
}
@@ -122,12 +122,12 @@ public abstract class SaveFileVersion{
int consecutives = stream.readUnsignedByte();
tiles[x][y] = new Tile(x, y, floorid, (byte)0);
tiles[x][y].setOre(oreid);
tiles[x][y].setOreByte(oreid);
for(int j = i + 1; j < i + 1 + consecutives; j++){
int newx = j % width, newy = j / width;
Tile newTile = new Tile(newx, newy, floorid, (byte)0);
newTile.setOre(oreid);
newTile.setOreByte(oreid);
tiles[newx][newy] = newTile;
}

View File

@@ -6,8 +6,6 @@ import io.anuke.arc.util.noise.Simplex;
import io.anuke.mindustry.content.Blocks;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Floor;
import io.anuke.mindustry.world.blocks.OreBlock;
public class BasicGenerator extends RandomGenerator{
private Array<Item> ores;
@@ -31,13 +29,14 @@ public class BasicGenerator extends RandomGenerator{
public void generate(int x, int y){
floor = Blocks.stone;
if(ores != null && ((Floor) floor).hasOres){
if(ores != null){
int offsetX = x - 4, offsetY = y + 23;
for(int i = ores.size - 1; i >= 0; i--){
Item entry = ores.get(i);
if(Math.abs(0.5f - sim.octaveNoise2D(2, 0.7, 1f / (50 + i * 2), offsetX, offsetY)) > 0.23f &&
Math.abs(0.5f - sim2.octaveNoise2D(1, 1, 1f / (40 + i * 4), offsetX, offsetY)) > 0.32f){
floor = OreBlock.get(floor, entry);
//floor = OreBlock.get(floor, entry);
break;
}
}

View File

@@ -14,14 +14,13 @@ import io.anuke.mindustry.type.Loadout;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Floor;
import io.anuke.mindustry.world.blocks.OreBlock;
import io.anuke.mindustry.world.blocks.StaticWall;
import io.anuke.mindustry.world.blocks.storage.CoreBlock;
import io.anuke.mindustry.world.blocks.storage.StorageBlock;
import java.io.IOException;
import static io.anuke.mindustry.Vars.*;
import static io.anuke.mindustry.Vars.world;
public class MapGenerator extends Generator{
private Map map;
@@ -159,10 +158,7 @@ public class MapGenerator extends Generator{
double dst = Mathf.dst(x, y);
if(dst < frad && Structs.inBounds(wx, wy, tiles) && (dst <= rad || Mathf.chance(0.5))){
Tile tile = tiles[wx][wy];
if(tile.floor() instanceof OreBlock){
OreBlock block = (OreBlock)tile.floor();
tile.setFloor(block.base);
}
tile.clearOre();
}
}
}

View File

@@ -5,9 +5,12 @@ import io.anuke.arc.collection.Array;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.arc.scene.ui.layout.Table;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.game.UnlockableContent;
import io.anuke.mindustry.ui.ContentDisplay;
import io.anuke.mindustry.world.blocks.Floor;
import io.anuke.mindustry.world.blocks.OreBlock;
import static io.anuke.mindustry.Vars.content;
public class Item extends UnlockableContent implements Comparable<Item>{
public final Color color;
@@ -28,8 +31,6 @@ public class Item extends UnlockableContent implements Comparable<Item>{
* 1 cost = 1 tick added to build time
*/
public float cost = 3f;
/**Whether this item has ores generated for it.*/
public boolean genOre = false;
/**If true, item is always unlocked.*/
public boolean alwaysUnlocked = false;
@@ -101,6 +102,6 @@ public class Item extends UnlockableContent implements Comparable<Item>{
/**Allocates a new array containing all items the generate ores.*/
public static Array<Item> getAllOres(){
return Vars.content.items().select(i -> i.genOre);
return content.blocks().select(b -> b instanceof OreBlock).map(b -> ((Floor)b).itemDrop);
}
}

View File

@@ -3,13 +3,10 @@ package io.anuke.mindustry.type;
import io.anuke.arc.collection.Array;
import io.anuke.arc.collection.IntMap;
import io.anuke.mindustry.content.Blocks;
import io.anuke.mindustry.content.Items;
import io.anuke.mindustry.game.Content;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Pos;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Floor;
import io.anuke.mindustry.world.blocks.OreBlock;
import io.anuke.mindustry.world.blocks.storage.CoreBlock;
import static io.anuke.mindustry.Vars.defaultTeam;
@@ -27,7 +24,7 @@ public class Loadout extends Content{
put('2', new BlockEntry(Blocks.coreFoundation));
put('3', new BlockEntry(Blocks.coreNucleus));
put('C', new BlockEntry(Blocks.mechanicalDrill, Items.copper));
put('C', new BlockEntry(Blocks.mechanicalDrill, Blocks.oreCopper));
}};
private final IntMap<BlockEntry> blocks = new IntMap<>();
@@ -79,8 +76,7 @@ public class Loadout extends Content{
tile.setRotation((byte)entry.value.rotation);
if(entry.value.ore != null){
for(Tile t : tile.getLinkedTiles(outArray)){
Floor floor = t.floor();
t.setFloor(OreBlock.get(floor, entry.value.ore) == null ? OreBlock.get(Blocks.stone, entry.value.ore) : OreBlock.get(floor, entry.value.ore));
t.setOre(entry.value.ore);
}
}
}
@@ -93,10 +89,10 @@ public class Loadout extends Content{
static class BlockEntry{
final Block block;
final Item ore;
final Block ore;
final int rotation;
BlockEntry(Block block, Item ore){
BlockEntry(Block block, Block ore){
this.block = block;
this.ore = ore;
this.rotation = 0;

View File

@@ -13,6 +13,7 @@ import io.anuke.arc.scene.ui.ButtonGroup;
import io.anuke.arc.scene.ui.Image;
import io.anuke.arc.scene.ui.ImageButton;
import io.anuke.arc.scene.ui.layout.Table;
import io.anuke.mindustry.content.Blocks;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.type.TileEntity;
import io.anuke.mindustry.game.EventType.UnlockEvent;
@@ -26,7 +27,6 @@ import io.anuke.mindustry.type.ItemStack;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Block.Icon;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.OreBlock;
import static io.anuke.mindustry.Vars.*;
@@ -340,6 +340,6 @@ public class PlacementFragment extends Fragment{
/** Returns the block currently being hovered over in the world. */
Block tileDisplayBlock(){
return hoverTile == null ? null : hoverTile.block().synthetic() ? hoverTile.block() : hoverTile.floor() instanceof OreBlock ? hoverTile.floor() : null;
return hoverTile == null ? null : hoverTile.block().synthetic() ? hoverTile.block() : hoverTile.oreBlock() != Blocks.air ? hoverTile.oreBlock() : null;
}
}

View File

@@ -17,6 +17,11 @@ public class CachedTile extends Tile{
super(0, 0);
}
@Override
public Team getTeam(){
return Team.all[getTeamID()];
}
@Override
protected void preChanged(){
super.setTeam(Team.none);

View File

@@ -3,10 +3,8 @@ package io.anuke.mindustry.world;
import io.anuke.arc.collection.IntMap;
import io.anuke.arc.graphics.Color;
import io.anuke.mindustry.content.Blocks;
import io.anuke.mindustry.content.Items;
import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.world.blocks.Floor;
import io.anuke.mindustry.world.blocks.OreBlock;
public class LegacyColorMapper implements ContentList{
private static IntMap<LegacyBlock> blockMap = new IntMap<>();
@@ -38,10 +36,14 @@ public class LegacyColorMapper implements ContentList{
map("6e501e", Blocks.stainedStoneRed);
map("ed5334", Blocks.stainedStoneRed);
map("292929", Blocks.tar);
map("c3a490", OreBlock.get(Blocks.stone, Items.copper));
map("161616", OreBlock.get(Blocks.stone, Items.coal));
map("6277bc", OreBlock.get(Blocks.stone, Items.titanium));
map("83bc58", OreBlock.get(Blocks.stone, Items.thorium));
map("c3a490", Blocks.stone, Blocks.air, Blocks.oreCopper);
map("161616", Blocks.stone, Blocks.air, Blocks.oreCoal);
map("6277bc", Blocks.stone, Blocks.air, Blocks.oreTitanium);
map("83bc58", Blocks.stone, Blocks.air, Blocks.oreThorium);
}
private void map(String color, Block block, Block wall, Block ore){
blockMap.put(Color.rgba8888(Color.valueOf(color)), new LegacyBlock(block, wall, ore));
}
private void map(String color, Block block, Block wall){
@@ -55,10 +57,18 @@ public class LegacyColorMapper implements ContentList{
public static class LegacyBlock{
public final Floor floor;
public final Block wall;
public final Block ore;
public LegacyBlock(Block floor, Block wall){
this.floor = (Floor) floor;
this.wall = wall;
this.ore = null;
}
public LegacyBlock(Block floor, Block wall, Block ore){
this.floor = (Floor) floor;
this.wall = wall;
this.ore = ore;
}
}

View File

@@ -9,9 +9,10 @@ import io.anuke.arc.math.geom.Position;
import io.anuke.arc.math.geom.Vector2;
import io.anuke.arc.util.Pack;
import io.anuke.mindustry.content.Blocks;
import io.anuke.mindustry.entities.type.TileEntity;
import io.anuke.mindustry.entities.traits.TargetTrait;
import io.anuke.mindustry.entities.type.TileEntity;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.world.blocks.BlockPart;
import io.anuke.mindustry.world.blocks.Floor;
import io.anuke.mindustry.world.modules.ConsumeModule;
@@ -40,7 +41,7 @@ public class Tile implements Position, TargetTrait{
/** Team ordinal. */
private byte team;
/**Ore that is on top of this (floor) block.*/
private byte ore;
private byte ore = 0;
public Tile(int x, int y){
this.x = (short) x;
@@ -162,6 +163,7 @@ public class Tile implements Position, TargetTrait{
public void setFloor(Floor type){
this.floor = type;
this.ore = 0;
}
public byte getRotation(){
@@ -221,7 +223,7 @@ public class Tile implements Position, TargetTrait{
}
public void setLinkByte(byte b){
this.link = 0;
this.link = b;
}
/** Sets this to a linked tile, which sets the block to a part. dx and dy can only be -8-7. */
@@ -327,14 +329,30 @@ public class Tile implements Position, TargetTrait{
return getTeam() == Team.none || team == getTeam();
}
public byte getOre(){
public byte getOreByte(){
return ore;
}
public void setOre(byte ore){
public void setOreByte(byte ore){
this.ore = ore;
}
public void setOre(Block floor){
setOreByte(floor.id);
}
public void clearOre(){
this.ore = 0;
}
public Floor oreBlock(){
return (Floor)content.block(ore);
}
public Item drop(){
return ore == 0 ? floor.itemDrop : ((Floor)content.block(ore)).itemDrop;
}
public void updateOcclusion(){
cost = 1;
boolean occluded = false;

View File

@@ -7,6 +7,7 @@ import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Geometry;
import io.anuke.arc.math.geom.Point2;
import io.anuke.mindustry.content.Blocks;
import io.anuke.mindustry.content.Fx;
import io.anuke.mindustry.content.StatusEffects;
import io.anuke.mindustry.entities.Effects.Effect;
@@ -45,8 +46,6 @@ public class Floor extends Block{
public Liquid liquidDrop = null;
/** item that drops from this block, used for drills */
public Item itemDrop = null;
/** Whether ores generate on this block. */
public boolean hasOres = false;
/** whether this block can be drowned in */
public boolean isLiquid;
/** Heat of this block, 0 at baseline. Used for calculating output of thermal generators.*/
@@ -110,6 +109,10 @@ public class Floor extends Block{
Mathf.random.setSeed(tile.pos());
Draw.rect(variantRegions[Mathf.randomSeed(tile.pos(), 0, Math.max(0, variantRegions.length - 1))], tile.worldx(), tile.worldy());
Floor floor = tile.oreBlock();
if(floor != Blocks.air){
floor.draw(tile);
}
drawEdges(tile);
}

View File

@@ -1,28 +1,18 @@
package io.anuke.mindustry.world.blocks;
import io.anuke.arc.collection.ObjectMap;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.math.Mathf;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
public class OreBlock extends Floor{
private static final ObjectMap<Item, ObjectMap<Block, Floor>> oreBlockMap = new ObjectMap<>();
public Floor base;
public OreBlock(Item ore, Floor base){
super("ore-" + ore.name + "-" + base.name);
this.localizedName = ore.localizedName() + " " + base.localizedName;
public OreBlock(Item ore){
super("ore-" + ore.name);
this.localizedName = ore.localizedName();
this.itemDrop = ore;
this.base = base;
this.variants = 3;
this.edge = base.name;
this.blendGroup = base.blendGroup;
this.color.set(ore.color);
oreBlockMap.getOr(ore, ObjectMap::new).put(base, this);
}
@Override
@@ -38,22 +28,5 @@ public class OreBlock extends Floor{
@Override
public void draw(Tile tile){
Draw.rect(variantRegions[Mathf.randomSeed(tile.pos(), 0, Math.max(0, variantRegions.length - 1))], tile.worldx(), tile.worldy());
drawEdges(tile);
}
@Override
public boolean doEdge(Floor floor, boolean f){
return floor != base && super.doEdge(floor, f);
}
@Override
protected boolean edgeOnto(Floor other){
return other != base;
}
public static Floor get(Block floor, Item item){
if(!oreBlockMap.containsKey(item) || !oreBlockMap.get(item).containsKey(floor)) return null;
return oreBlockMap.get(item).get(floor);
}
}

View File

@@ -18,6 +18,7 @@ import io.anuke.mindustry.entities.type.TileEntity;
import io.anuke.mindustry.graphics.Layer;
import io.anuke.mindustry.graphics.Pal;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.ItemType;
import io.anuke.mindustry.ui.Bar;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
@@ -182,7 +183,7 @@ public class Drill extends Block{
}
itemArray.sort((item1, item2) -> Integer.compare(oreCount.get(item1, 0), oreCount.get(item2, 0)));
itemArray.sort((item1, item2) -> item1.genOre && !item2.genOre ? 1 : item1.genOre == item2.genOre ? 0 : -1);
itemArray.sort((item1, item2) -> Boolean.compare(item1.type == ItemType.material, item2.type == ItemType.material));
if(itemArray.size == 0){
return;
@@ -259,12 +260,12 @@ public class Drill extends Block{
}
public Item getDrop(Tile tile){
return tile.floor().itemDrop;
return tile.drop();
}
public boolean isValid(Tile tile){
if(tile == null) return false;
Item drops = tile.floor().itemDrop;
Item drops = tile.drop();
return drops != null && drops.hardness <= tier;
}