mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-03-09 04:09:07 +07:00
Basic crater map / Spray tool / Crater floor / canProduce()
This commit is contained in:
parent
55e1759b47
commit
e9e2cd614d
BIN
core/assets-raw/sprites/blocks/environment/craters1.png
Normal file
BIN
core/assets-raw/sprites/blocks/environment/craters1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
BIN
core/assets-raw/sprites/blocks/environment/craters2.png
Normal file
BIN
core/assets-raw/sprites/blocks/environment/craters2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
BIN
core/assets-raw/sprites/blocks/environment/craters3.png
Normal file
BIN
core/assets-raw/sprites/blocks/environment/craters3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
BIN
core/assets-raw/sprites/ui/icons/icon-spray.png
Normal file
BIN
core/assets-raw/sprites/ui/icons/icon-spray.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 920 B |
BIN
core/assets/maps/craters.mmap
Normal file
BIN
core/assets/maps/craters.mmap
Normal file
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Before Width: | Height: | Size: 989 KiB After Width: | Height: | Size: 992 KiB |
@ -32,7 +32,7 @@ public class Blocks implements ContentList{
|
||||
public static Block
|
||||
|
||||
//environment
|
||||
air, blockpart, spawn, space, metalfloor, deepwater, water, tar, stone, blackstone, dirt, sand, ice, snow,
|
||||
air, blockpart, spawn, space, metalfloor, deepwater, water, tar, stone, craters, blackstone, dirt, sand, ice, snow,
|
||||
grass, shrub, rock, icerock, blackrock, rocks,
|
||||
|
||||
//crafting
|
||||
@ -76,9 +76,7 @@ public class Blocks implements ContentList{
|
||||
public void load(){
|
||||
//region environment
|
||||
|
||||
air = new Floor("air"){
|
||||
{
|
||||
blend = false;
|
||||
air = new Floor("air"){{
|
||||
alwaysReplace = true;
|
||||
}
|
||||
|
||||
@ -104,7 +102,6 @@ public class Blocks implements ContentList{
|
||||
variants = 0;
|
||||
cacheLayer = CacheLayer.space;
|
||||
solid = true;
|
||||
blend = false;
|
||||
minimapColor = Color.valueOf("000001");
|
||||
}};
|
||||
|
||||
@ -152,9 +149,11 @@ public class Blocks implements ContentList{
|
||||
|
||||
stone = new Floor("stone"){{
|
||||
hasOres = true;
|
||||
blends = block -> block != this && !(block instanceof OreBlock);
|
||||
minimapColor = Color.valueOf("323232");
|
||||
playerUnmineable = true;
|
||||
}};
|
||||
|
||||
craters = new Floor("craters"){{
|
||||
minimapColor = Color.valueOf("323232");
|
||||
}};
|
||||
|
||||
blackstone = new Floor("blackstone"){{
|
||||
@ -828,7 +827,6 @@ public class Blocks implements ContentList{
|
||||
launchThreshold = 500;
|
||||
launchTime = 60f * 10;
|
||||
launchChunkSize = 100;
|
||||
alwaysUnlocked = true;
|
||||
}};
|
||||
|
||||
vault = new Vault("vault"){{
|
||||
|
@ -58,7 +58,7 @@ public class Zones implements ContentList{
|
||||
}};
|
||||
}};
|
||||
|
||||
craters = new Zone("craters", new MapGenerator("groundZero", 1)){{ //TODO implement
|
||||
craters = new Zone("craters", new MapGenerator("craters", 1){{ distortion = 1.44f; }}){{ //TODO implement
|
||||
deployCost = ItemStack.with(Items.copper, 300);
|
||||
startingItems = ItemStack.with(Items.copper, 200);
|
||||
conditionWave = 15;
|
||||
|
@ -57,7 +57,7 @@ public enum EditorTool{
|
||||
editor.draw(x, y, Blocks.air);
|
||||
}
|
||||
},
|
||||
elevation{
|
||||
spray{
|
||||
{
|
||||
edit = true;
|
||||
draggable = true;
|
||||
@ -65,7 +65,7 @@ public enum EditorTool{
|
||||
|
||||
@Override
|
||||
public void touched(MapEditor editor, int x, int y){
|
||||
editor.elevate(x, y);
|
||||
editor.draw(x, y, editor.getDrawBlock(), 0.012);
|
||||
}
|
||||
},
|
||||
line{
|
||||
@ -99,7 +99,6 @@ public enum EditorTool{
|
||||
|
||||
byte bf = data.read(x, y, DataPosition.floor);
|
||||
byte bw = data.read(x, y, DataPosition.wall);
|
||||
be = data.read(x, y, DataPosition.elevation);
|
||||
boolean synth = editor.getDrawBlock().synthetic();
|
||||
byte brt = Pack.byteByte((byte) editor.getDrawRotation(), (byte) editor.getDrawTeam().ordinal());
|
||||
|
||||
|
@ -17,14 +17,13 @@ import io.anuke.mindustry.world.blocks.Floor;
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
|
||||
public class MapEditor{
|
||||
public static final int[] brushSizes = {1, 2, 3, 4, 5, 9, 15};
|
||||
public static final int[] brushSizes = {1, 2, 3, 4, 5, 9, 15, 20};
|
||||
|
||||
private MapTileData map;
|
||||
private ObjectMap<String, String> tags = new ObjectMap<>();
|
||||
private MapRenderer renderer = new MapRenderer(this);
|
||||
|
||||
private int brushSize = 1;
|
||||
private byte elevation;
|
||||
private int rotation;
|
||||
private Block drawBlock = Blocks.stone;
|
||||
private Team drawTeam = Team.blue;
|
||||
@ -54,14 +53,6 @@ public class MapEditor{
|
||||
renderer.resize(map.width(), map.height());
|
||||
}
|
||||
|
||||
public byte getDrawElevation(){
|
||||
return elevation;
|
||||
}
|
||||
|
||||
public void setDrawElevation(int elevation){
|
||||
this.elevation = (byte) elevation;
|
||||
}
|
||||
|
||||
public int getDrawRotation(){
|
||||
return rotation;
|
||||
}
|
||||
@ -99,7 +90,10 @@ public class MapEditor{
|
||||
}
|
||||
|
||||
public void draw(int x, int y, Block drawBlock){
|
||||
draw(x, y, drawBlock, 1.0);
|
||||
}
|
||||
|
||||
public void draw(int x, int y, Block drawBlock, double chance){
|
||||
byte writeID = drawBlock.id;
|
||||
byte partID = Blocks.blockpart.id;
|
||||
byte rotationTeam = Pack.byteByte(drawBlock.rotate ? (byte)rotation : 0, drawBlock.synthetic() ? (byte)drawTeam.ordinal() : 0);
|
||||
@ -151,10 +145,9 @@ public class MapEditor{
|
||||
|
||||
onWrite(x, y, prev);
|
||||
}else{
|
||||
|
||||
for(int rx = -brushSize; rx <= brushSize; rx++){
|
||||
for(int ry = -brushSize; ry <= brushSize; ry++){
|
||||
if(Mathf.dst(rx, ry) <= brushSize - 0.5f){
|
||||
if(Mathf.dst(rx, ry) <= brushSize - 0.5f && (chance >= 0.999 || Mathf.chance(chance))){
|
||||
int wx = x + rx, wy = y + ry;
|
||||
|
||||
if(wx < 0 || wy < 0 || wx >= map.width() || wy >= map.height()){
|
||||
@ -175,7 +168,6 @@ public class MapEditor{
|
||||
|
||||
if(isfloor){
|
||||
map.write(wx, wy, DataPosition.floor, writeID);
|
||||
map.write(wx, wy, DataPosition.elevation, elevation);
|
||||
}else{
|
||||
map.write(wx, wy, DataPosition.wall, writeID);
|
||||
map.write(wx, wy, DataPosition.link, (byte) 0);
|
||||
@ -189,30 +181,6 @@ public class MapEditor{
|
||||
}
|
||||
}
|
||||
|
||||
public void elevate(int x, int y){
|
||||
if(x < 0 || y < 0 || x >= map.width() || y >= map.height()){
|
||||
return;
|
||||
}
|
||||
|
||||
for(int rx = -brushSize; rx <= brushSize; rx++){
|
||||
for(int ry = -brushSize; ry <= brushSize; ry++){
|
||||
if(Mathf.dst(rx, ry) <= brushSize - 0.5f){
|
||||
int wx = x + rx, wy = y + ry;
|
||||
|
||||
if(wx < 0 || wy < 0 || wx >= map.width() || wy >= map.height()){
|
||||
continue;
|
||||
}
|
||||
|
||||
TileDataMarker prev = getPrev(wx, wy, true);
|
||||
|
||||
map.write(wx, wy, DataPosition.elevation, elevation);
|
||||
|
||||
onWrite(x + rx, y + ry, prev);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void removeLinked(int x, int y){
|
||||
Block block = content.block(map.read(x, y, DataPosition.wall));
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.anuke.mindustry.editor;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.collection.Array;
|
||||
import io.anuke.arc.collection.ObjectMap;
|
||||
import io.anuke.arc.files.FileHandle;
|
||||
import io.anuke.arc.function.Consumer;
|
||||
@ -27,6 +28,7 @@ import io.anuke.mindustry.maps.MapTileData;
|
||||
import io.anuke.mindustry.ui.dialogs.FloatingDialog;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Block.Icon;
|
||||
import io.anuke.mindustry.world.blocks.OreBlock;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.InputStream;
|
||||
@ -43,6 +45,7 @@ public class MapEditorDialog extends Dialog implements Disposable{
|
||||
private FloatingDialog menu;
|
||||
private boolean saved = false;
|
||||
private boolean shownWithMap = false;
|
||||
private Array<Block> blocksOut = new Array<>();
|
||||
|
||||
private ButtonGroup<ImageButton> blockgroup;
|
||||
|
||||
@ -387,7 +390,7 @@ public class MapEditorDialog extends Dialog implements Disposable{
|
||||
tools.row();
|
||||
|
||||
addTool.accept(EditorTool.fill);
|
||||
addTool.accept(EditorTool.elevation);
|
||||
addTool.accept(EditorTool.spray);
|
||||
|
||||
ImageButton rotate = tools.addImageButton("icon-arrow-16", "clear", 16 * 2f, () -> editor.setDrawRotation((editor.getDrawRotation() + 1) % 4)).get();
|
||||
rotate.getImage().update(() -> {
|
||||
@ -498,7 +501,13 @@ public class MapEditorDialog extends Dialog implements Disposable{
|
||||
|
||||
int i = 0;
|
||||
|
||||
for(Block block : Vars.content.blocks()){
|
||||
blocksOut.clear();
|
||||
blocksOut.addAll(Vars.content.blocks());
|
||||
blocksOut.sort((b1, b2) -> b1.synthetic() && !b2.synthetic() ? 1 : b2.synthetic() && !b1.synthetic() ? -1 :
|
||||
b1 instanceof OreBlock && !(b2 instanceof OreBlock) ? 1 : !(b1 instanceof OreBlock) && b2 instanceof OreBlock ? -1 :
|
||||
Integer.compare(b1.id, b2.id));
|
||||
|
||||
for(Block block : blocksOut){
|
||||
TextureRegion region = block.icon(Icon.medium);
|
||||
|
||||
if(region == Core.atlas.find("jjfgj")) continue;
|
||||
|
@ -24,7 +24,6 @@ public class MapRenderer implements Disposable{
|
||||
private IntSet delayedUpdates = new IntSet();
|
||||
private MapEditor editor;
|
||||
private int width, height;
|
||||
private Color tmpColor = Color.WHITE.cpy();
|
||||
|
||||
public MapRenderer(MapEditor editor){
|
||||
this.editor = editor;
|
||||
|
@ -146,7 +146,7 @@ public class MapView extends Element implements GestureListener{
|
||||
|
||||
Point2 p = project(x, y);
|
||||
|
||||
if(drawing && tool.draggable){
|
||||
if(drawing && tool.draggable && !(p.x == lastx && p.y == lasty)){
|
||||
ui.editor.resetSaved();
|
||||
Array<Point2> points = br.line(lastx, lasty, p.x, p.y);
|
||||
for(Point2 point : points){
|
||||
|
@ -40,7 +40,7 @@ public class IndexedRenderer implements Disposable{
|
||||
program.setUniformMatrix4("u_projTrans", BatchShader.copyTransform(combined));
|
||||
program.setUniformi("u_texture", 0);
|
||||
|
||||
mesh.render(program, GL20.GL_TRIANGLES, 0, vertices.length / 5);
|
||||
mesh.render(program, GL20.GL_TRIANGLES, 0, vertices.length / vsize);
|
||||
|
||||
program.end();
|
||||
}
|
||||
@ -187,14 +187,6 @@ public class IndexedRenderer implements Disposable{
|
||||
return transMatrix;
|
||||
}
|
||||
|
||||
public void setTransformMatrix(Matrix3 matrix){
|
||||
transMatrix = matrix;
|
||||
}
|
||||
|
||||
public Matrix3 getProjectionMatrix(){
|
||||
return projMatrix;
|
||||
}
|
||||
|
||||
public void setProjectionMatrix(Matrix3 matrix){
|
||||
projMatrix = matrix;
|
||||
}
|
||||
|
@ -50,7 +50,6 @@ public class MapIO{
|
||||
for(int y = 0; y < data.height(); y++){
|
||||
for(int x = 0; x < data.width(); x++){
|
||||
data.read(marker);
|
||||
byte elev = y >= data.height() - 1 ? 0 : data.read(x, y + 1, DataPosition.elevation);
|
||||
Block floor = content.block(marker.floor);
|
||||
Block wall = content.block(marker.wall);
|
||||
int color = ColorMapper.colorFor(floor, wall, Team.all[marker.team]);
|
||||
|
@ -138,7 +138,8 @@ public class MapTileData{
|
||||
}
|
||||
|
||||
public enum DataPosition{
|
||||
floor, wall, link, rotationTeam, elevation
|
||||
floor, wall, link, rotationTeam,
|
||||
@Deprecated elevation
|
||||
}
|
||||
|
||||
public class TileDataMarker{
|
||||
|
@ -18,6 +18,9 @@ public class MapGenerator extends Generator{
|
||||
private Map map;
|
||||
private String mapName;
|
||||
|
||||
/**How much the landscape is randomly distorted.*/
|
||||
public float distortion = 3;
|
||||
|
||||
/**The amount of final enemy spawns used. -1 to use everything in the map.
|
||||
* This amount of enemy spawns is selected randomly from the map.*/
|
||||
public int enemySpawns = -1;
|
||||
@ -70,9 +73,8 @@ public class MapGenerator extends Generator{
|
||||
for(int x = 0; x < data.width(); x++){
|
||||
for(int y = 0; y < data.height(); y++){
|
||||
final double scl = 10;
|
||||
final int mag = 3;
|
||||
int newX = Mathf.clamp((int)(simplex.octaveNoise2D(1, 1, 1.0 / scl, x, y) * mag + x), 0, data.width()-1);
|
||||
int newY = Mathf.clamp((int)(simplex.octaveNoise2D(1, 1, 1.0 / scl, x + 9999, y + 9999) * mag + y), 0, data.height()-1);
|
||||
int newX = Mathf.clamp((int)(simplex.octaveNoise2D(1, 1, 1.0 / scl, x, y) * distortion + x), 0, data.width()-1);
|
||||
int newY = Mathf.clamp((int)(simplex.octaveNoise2D(1, 1, 1.0 / scl, x + 9999, y + 9999) * distortion + y), 0, data.height()-1);
|
||||
if(tiles[newX][newY].block() != Blocks.spawn && !tiles[x][y].block().synthetic()&& !tiles[newX][newY].block().synthetic()){
|
||||
tiles[x][y].setBlock(tiles[newX][newY].block());
|
||||
}
|
||||
|
@ -271,4 +271,9 @@ public abstract class BlockStorage extends UnlockableContent{
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Returns whether this block's inventory has space and is ready for production.*/
|
||||
public boolean canProduce(Tile tile){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -2,13 +2,10 @@ package io.anuke.mindustry.world.blocks;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.entities.Effects.Effect;
|
||||
import io.anuke.arc.function.Predicate;
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
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.Vector2;
|
||||
import io.anuke.mindustry.content.Fx;
|
||||
import io.anuke.mindustry.content.StatusEffects;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
@ -17,8 +14,6 @@ import io.anuke.mindustry.type.StatusEffect;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
|
||||
public class Floor extends Block{
|
||||
/** number of different variant regions to use */
|
||||
public int variants;
|
||||
@ -52,12 +47,7 @@ public class Floor extends Block{
|
||||
public boolean isLiquid;
|
||||
/** if true, this block cannot be mined by players. useful for annoying things like sand. */
|
||||
public boolean playerUnmineable = false;
|
||||
protected TextureRegion edgeRegion;
|
||||
protected TextureRegion[] edgeRegions;
|
||||
protected TextureRegion[] variantRegions;
|
||||
protected Vector2[] offsets;
|
||||
protected Predicate<Floor> blends = block -> block != this && !block.blendOverride(this);
|
||||
protected boolean blend = true;
|
||||
|
||||
public Floor(String name){
|
||||
super(name);
|
||||
@ -68,36 +58,6 @@ public class Floor extends Block{
|
||||
public void load(){
|
||||
super.load();
|
||||
|
||||
if(blend){
|
||||
edgeRegion = Core.atlas.has(name + "edge") ? Core.atlas.find(name + "edge") : Core.atlas.find(edge + "edge");
|
||||
edgeRegions = new TextureRegion[8];
|
||||
offsets = new Vector2[8];
|
||||
|
||||
for(int i = 0; i < 8; i++){
|
||||
int dx = Geometry.d8[i].x, dy = Geometry.d8[i].y;
|
||||
|
||||
TextureRegion result = new TextureRegion();
|
||||
|
||||
int padSize = (int)(tilesize/Draw.scl/2);
|
||||
int texSize = (int)(tilesize/Draw.scl);
|
||||
int totSize = padSize + texSize;
|
||||
|
||||
int sx = -dx * texSize + padSize/2, sy = -dy * texSize + padSize/2;
|
||||
int x = Mathf.clamp(sx, 0, totSize);
|
||||
int y = Mathf.clamp(sy, 0, totSize);
|
||||
int w = Mathf.clamp(sx + texSize, 0, totSize) - x, h = Mathf.clamp(sy + texSize, 0, totSize) - y;
|
||||
|
||||
float rx = Mathf.clamp(dx * texSize, 0, texSize - w);
|
||||
float ry = Mathf.clamp(dy * texSize, 0, texSize - h);
|
||||
|
||||
result.setTexture(edgeRegion.getTexture());
|
||||
result.set(edgeRegion.getX() + x, edgeRegion.getY() + y + h, w, -h);
|
||||
|
||||
edgeRegions[i] = result;
|
||||
offsets[i] = new Vector2(-padSize + rx, -padSize + ry);
|
||||
}
|
||||
}
|
||||
|
||||
//load variant regions for drawing
|
||||
if(variants > 0){
|
||||
variantRegions = new TextureRegion[variants];
|
||||
@ -127,8 +87,6 @@ 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());
|
||||
|
||||
//drawEdges(tile, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -136,8 +94,4 @@ public class Floor extends Block{
|
||||
return new TextureRegion[]{Core.atlas.find(Core.atlas.has(name) ? name : name + "1")};
|
||||
}
|
||||
|
||||
public boolean blendOverride(Block block){
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -117,6 +117,11 @@ public class Drill extends Block{
|
||||
return new TextureRegion[]{Core.atlas.find(name), Core.atlas.find(name + "-rotator"), Core.atlas.find(name + "-top")};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProduce(Tile tile){
|
||||
return tile.entity.items.total() < itemCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
@ -60,6 +60,17 @@ public class PowerCrafter extends Block{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProduce(Tile tile){
|
||||
if(outputItem != null && tile.entity.items.get(outputItem) >= itemCapacity){
|
||||
return false;
|
||||
}
|
||||
if(outputLiquid != null && tile.entity.liquids.get(outputLiquid) >= liquidCapacity - 0.01f){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
GenericCrafterEntity entity = tile.entity();
|
||||
|
@ -9,9 +9,11 @@ import java.io.IOException;
|
||||
|
||||
public class ConsumeModule extends BlockModule{
|
||||
private boolean valid;
|
||||
private TileEntity entity;
|
||||
|
||||
public void update(TileEntity entity){
|
||||
boolean prevValid = valid;
|
||||
this.entity = entity;
|
||||
boolean prevValid = valid();
|
||||
valid = true;
|
||||
|
||||
for(Consume cons : entity.tile.block().consumes.all()){
|
||||
@ -26,7 +28,7 @@ public class ConsumeModule extends BlockModule{
|
||||
}
|
||||
|
||||
public boolean valid(){
|
||||
return valid;
|
||||
return valid && (entity == null || entity.tile.block().canProduce(entity.tile));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user