Added battle misson / Team block colors / Mission worldgen

This commit is contained in:
Anuken
2018-07-23 20:44:33 -04:00
parent ecf9a3cbc9
commit 7448eb32cc
18 changed files with 146 additions and 103 deletions

View File

@@ -12,7 +12,7 @@ import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.*; import io.anuke.mindustry.world.blocks.*;
public class Blocks extends BlockList implements ContentList{ public class Blocks extends BlockList implements ContentList{
public static Block air, spawn, blockpart, space, metalfloor, deepwater, water, lava, oil, stone, blackstone, dirt, sand, ice, snow, grass, shrub, rock, icerock, blackrock; public static Block air, blockpart, space, metalfloor, deepwater, water, lava, oil, stone, blackstone, dirt, sand, ice, snow, grass, shrub, rock, icerock, blackrock;
@Override @Override

View File

@@ -35,65 +35,65 @@ public class ContentLoader{
private static OrderedMap<String, Array<Content>> contentMap = new OrderedMap<>(); private static OrderedMap<String, Array<Content>> contentMap = new OrderedMap<>();
private static ObjectSet<Consumer<Content>> initialization = new ObjectSet<>(); private static ObjectSet<Consumer<Content>> initialization = new ObjectSet<>();
private static ContentList[] content = { private static ContentList[] content = {
//effects //effects
new BlockFx(), new BlockFx(),
new BulletFx(), new BulletFx(),
new EnvironmentFx(), new EnvironmentFx(),
new ExplosionFx(), new ExplosionFx(),
new Fx(), new Fx(),
new ShootFx(), new ShootFx(),
new UnitFx(), new UnitFx(),
//items //items
new Items(), new Items(),
//status effects //status effects
new StatusEffects(), new StatusEffects(),
//liquids //liquids
new Liquids(), new Liquids(),
//bullets //bullets
new ArtilleryBullets(), new ArtilleryBullets(),
new FlakBullets(), new FlakBullets(),
new MissileBullets(), new MissileBullets(),
new StandardBullets(), new StandardBullets(),
new TurretBullets(), new TurretBullets(),
new WeaponBullets(), new WeaponBullets(),
//ammotypes //ammotypes
new AmmoTypes(), new AmmoTypes(),
//weapons //weapons
new Weapons(), new Weapons(),
//mechs //mechs
new Mechs(), new Mechs(),
//units //units
new UnitTypes(), new UnitTypes(),
//blocks //blocks
new Blocks(), new Blocks(),
new DefenseBlocks(), new DefenseBlocks(),
new DistributionBlocks(), new DistributionBlocks(),
new ProductionBlocks(), new ProductionBlocks(),
new TurretBlocks(), new TurretBlocks(),
new DebugBlocks(), new DebugBlocks(),
new LiquidBlocks(), new LiquidBlocks(),
new StorageBlocks(), new StorageBlocks(),
new UnitBlocks(), new UnitBlocks(),
new PowerBlocks(), new PowerBlocks(),
new CraftingBlocks(), new CraftingBlocks(),
new UpgradeBlocks(), new UpgradeBlocks(),
new OreBlocks(), new OreBlocks(),
//not really a content class, but this makes initialization easier //not really a content class, but this makes initialization easier
new ColorMapper(), new ColorMapper(),
//recipes //recipes
new Recipes(), new Recipes(),
}; };
/** /**

View File

@@ -366,7 +366,7 @@ public class Control extends Module{
} }
//check unlocked sectors //check unlocked sectors
if(world.getSector() != null && world.getSector().goal.isComplete() && !world.getSector().complete){ if(world.getSector() != null && world.getSector().mission.isComplete() && !world.getSector().complete){
world.sectors().completeSector(world.getSector().x, world.getSector().y); world.sectors().completeSector(world.getSector().x, world.getSector().y);
world.sectors().save(); world.sectors().save();
if(!headless){ if(!headless){

View File

@@ -215,7 +215,23 @@ public class Renderer extends RendererModule{
blocks.processBlocks(); blocks.processBlocks();
blocks.drawShadows(); blocks.drawShadows();
blocks.drawBlocks(Layer.block); for(Team team : Team.all){
if(blocks.isTeamShown(team)){
boolean outline = team != players[0].getTeam() && team != Team.none;
if(outline){
Shaders.outline.color.set(team.color);
Graphics.beginShaders(Shaders.outline);
}
blocks.drawTeamBlocks(Layer.block, team);
if(outline){
Graphics.endShaders();
}
}
}
blocks.skipLayer(Layer.block);
Graphics.shader(Shaders.blockbuild, false); Graphics.shader(Shaders.blockbuild, false);
blocks.drawBlocks(Layer.placement); blocks.drawBlocks(Layer.placement);

View File

@@ -230,16 +230,13 @@ public class World extends Module{
Tile[][] tiles = createTiles(width, height); Tile[][] tiles = createTiles(width, height);
Map map = new Map("Sector [" + sector.x + ", " + sector.y + "]", new MapMeta(0, new ObjectMap<>(), width, height, null), true, () -> null); Map map = new Map("Sector " + sector.x + ", " + sector.y, new MapMeta(0, new ObjectMap<>(), width, height, null), true, () -> null);
setMap(map); setMap(map);
EntityPhysics.resizeTree(0, 0, width * tilesize, height * tilesize); EntityPhysics.resizeTree(0, 0, width * tilesize, height * tilesize);
Timers.mark(); Timers.mark();
generator.generateMap(tiles, sector.x, sector.y); generator.generateMap(tiles, sector);
Log.info("Time to generate base map: {0}", Timers.elapsed());
Log.info("Time to generate fully without additional events: {0}", Timers.elapsed());
endMapLoad(); endMapLoad();

View File

@@ -25,7 +25,7 @@ public class MapEditor{
private byte elevation; private byte elevation;
private int rotation; private int rotation;
private Block drawBlock = Blocks.stone; private Block drawBlock = Blocks.stone;
private Team drawTeam = Team.none; private Team drawTeam = Team.blue;
public MapEditor(){ public MapEditor(){

View File

@@ -280,7 +280,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
if(Math.abs(py - y) <= 0.0001f) velocity.y = 0f; if(Math.abs(py - y) <= 0.0001f) velocity.y = 0f;
} }
velocity.scl(Mathf.clamp(1f - drag * floor.dragMultiplier * Timers.delta())); velocity.scl(Mathf.clamp(1f - drag * (isFlying() ? 1f : floor.dragMultiplier) * Timers.delta()));
} }
public void applyEffect(StatusEffect effect, float intensity){ public void applyEffect(StatusEffect effect, float intensity){

View File

@@ -1,6 +1,7 @@
package io.anuke.mindustry.graphics; package io.anuke.mindustry.graphics;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.IntSet;
import com.badlogic.gdx.utils.Sort; import com.badlogic.gdx.utils.Sort;
import io.anuke.mindustry.content.blocks.Blocks; import io.anuke.mindustry.content.blocks.Blocks;
import io.anuke.mindustry.game.EventType.TileChangeEvent; import io.anuke.mindustry.game.EventType.TileChangeEvent;
@@ -25,6 +26,7 @@ public class BlockRenderer{
private FloorRenderer floorRenderer; private FloorRenderer floorRenderer;
private Array<BlockRequest> requests = new Array<>(initialRequests); private Array<BlockRequest> requests = new Array<>(initialRequests);
private IntSet teamChecks = new IntSet();
private int lastCamX, lastCamY, lastRangeX, lastRangeY; private int lastCamX, lastCamY, lastRangeX, lastRangeY;
private Layer lastLayer; private Layer lastLayer;
private int requestidx = 0; private int requestidx = 0;
@@ -65,7 +67,11 @@ public class BlockRenderer{
Draw.color(); Draw.color();
} }
/**Process all blocks to draw, simultaneously drawing block shadows.*/ public boolean isTeamShown(Team team){
return teamChecks.contains(team.ordinal());
}
/**Process all blocks to draw, simultaneously updating the block shadow framebuffer.*/
public void processBlocks(){ public void processBlocks(){
iterateidx = 0; iterateidx = 0;
lastLayer = null; lastLayer = null;
@@ -86,6 +92,7 @@ public class BlockRenderer{
shadows.setSize(shadowW, shadowH); shadows.setSize(shadowW, shadowH);
} }
teamChecks.clear();
requestidx = 0; requestidx = 0;
Graphics.end(); Graphics.end();
@@ -106,6 +113,7 @@ public class BlockRenderer{
if(tile != null){ if(tile != null){
Block block = tile.block(); Block block = tile.block();
Team team = tile.getTeam();
if(!expanded && block != Blocks.air && world.isAccessible(x, y)){ if(!expanded && block != Blocks.air && world.isAccessible(x, y)){
tile.block().drawShadow(tile); tile.block().drawShadow(tile);
@@ -114,6 +122,7 @@ public class BlockRenderer{
if(block != Blocks.air){ if(block != Blocks.air){
if(!expanded){ if(!expanded){
addRequest(tile, Layer.block); addRequest(tile, Layer.block);
teamChecks.add(team.ordinal());
} }
if(block.expanded || !expanded){ if(block.expanded || !expanded){
@@ -194,7 +203,9 @@ public class BlockRenderer{
synchronized(Tile.tileSetLock){ synchronized(Tile.tileSetLock){
Block block = req.tile.block(); Block block = req.tile.block();
if(req.layer == block.layer){ if(req.layer == Layer.block){
block.draw(req.tile);
}else if(req.layer == block.layer){
block.drawLayer(req.tile); block.drawLayer(req.tile);
}else if(req.layer == block.layer2){ }else if(req.layer == block.layer2){
block.drawLayer2(req.tile); block.drawLayer2(req.tile);

View File

@@ -1,6 +1,5 @@
package io.anuke.mindustry.io.versions; package io.anuke.mindustry.io.versions;
import com.badlogic.gdx.utils.IntMap;
import com.badlogic.gdx.utils.TimeUtils; import com.badlogic.gdx.utils.TimeUtils;
import io.anuke.mindustry.content.blocks.Blocks; import io.anuke.mindustry.content.blocks.Blocks;
import io.anuke.mindustry.content.blocks.StorageBlocks; import io.anuke.mindustry.content.blocks.StorageBlocks;
@@ -12,7 +11,6 @@ import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.game.Version; import io.anuke.mindustry.game.Version;
import io.anuke.mindustry.io.SaveFileVersion; import io.anuke.mindustry.io.SaveFileVersion;
import io.anuke.mindustry.maps.Map; import io.anuke.mindustry.maps.Map;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.BlockPart; import io.anuke.mindustry.world.blocks.BlockPart;
import io.anuke.ucore.core.Timers; import io.anuke.ucore.core.Timers;
@@ -41,6 +39,7 @@ public class Save16 extends SaveFileVersion{
int sector = stream.readInt(); //sector ID int sector = stream.readInt(); //sector ID
//general state //general state
byte mode = stream.readByte(); byte mode = stream.readByte();
String mapname = stream.readUTF(); String mapname = stream.readUTF();
Map map = world.maps().getByName(mapname); Map map = world.maps().getByName(mapname);
@@ -59,19 +58,6 @@ public class Save16 extends SaveFileVersion{
state.spawner.read(stream); state.spawner.read(stream);
//block header
int blocksize = stream.readInt();
IntMap<Block> blockMap = new IntMap<>();
for(int i = 0; i < blocksize; i++){
String name = stream.readUTF();
int id = stream.readShort();
blockMap.put(id, Block.getByName(name));
}
//entities //entities
byte groups = stream.readByte(); byte groups = stream.readByte();
@@ -171,16 +157,6 @@ public class Save16 extends SaveFileVersion{
state.spawner.write(stream); state.spawner.write(stream);
//--BLOCK HEADER--
stream.writeInt(Block.all().size);
for(int i = 0; i < Block.all().size; i++){
Block block = Block.all().get(i);
stream.writeUTF(block.name);
stream.writeShort(block.id);
}
//--ENTITIES-- //--ENTITIES--
int groups = 0; int groups = 0;

View File

@@ -4,8 +4,8 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.game.Saves.SaveSlot; import io.anuke.mindustry.game.Saves.SaveSlot;
import io.anuke.mindustry.game.SpawnGroup; import io.anuke.mindustry.game.SpawnGroup;
import io.anuke.mindustry.maps.goals.Goal; import io.anuke.mindustry.maps.goals.Mission;
import io.anuke.mindustry.maps.goals.WaveGoal; import io.anuke.mindustry.maps.goals.WaveMission;
import io.anuke.ucore.util.Bits; import io.anuke.ucore.util.Bits;
import static io.anuke.mindustry.Vars.control; import static io.anuke.mindustry.Vars.control;
@@ -21,11 +21,15 @@ public class Sector{
public int size = 1; public int size = 1;
/**Display texture. Needs to be disposed.*/ /**Display texture. Needs to be disposed.*/
public transient Texture texture; public transient Texture texture;
/**Goal of this sector-- what needs to be accomplished to unlock it.*/ /**Mission of this sector-- what needs to be accomplished to unlock it.*/
public transient Goal goal = new WaveGoal(30); public transient Mission mission = new WaveMission(30);
/**Enemies spawned at this sector.*/ /**Enemies spawned at this sector.*/
public transient Array<SpawnGroup> spawns = new Array<>(); public transient Array<SpawnGroup> spawns = new Array<>();
public int getSeed(){
return Bits.packInt(x, y);
}
public SaveSlot getSave(){ public SaveSlot getSave(){
return control.getSaves().getByID(saveID); return control.getSaves().getByID(saveID);
} }

View File

@@ -8,6 +8,7 @@ import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.game.Team; import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.maps.generation.WorldGenerator.GenResult; import io.anuke.mindustry.maps.generation.WorldGenerator.GenResult;
import io.anuke.mindustry.maps.goals.BattleMission;
import io.anuke.mindustry.world.ColorMapper; import io.anuke.mindustry.world.ColorMapper;
import io.anuke.mindustry.world.Edges; import io.anuke.mindustry.world.Edges;
import io.anuke.ucore.core.Settings; import io.anuke.ucore.core.Settings;
@@ -75,6 +76,7 @@ public class Sectors{
sector.y = (short)y; sector.y = (short)y;
sector.complete = false; sector.complete = false;
sector.size = isLarge ? 2 : 1; sector.size = isLarge ? 2 : 1;
initSector(sector);
for(int cx = 0; cx < sector.size; cx++){ for(int cx = 0; cx < sector.size; cx++){
for(int cy = 0; cy < sector.size; cy++){ for(int cy = 0; cy < sector.size; cy++){
@@ -90,6 +92,7 @@ public class Sectors{
for(Sector sector : out){ for(Sector sector : out){
createTexture(sector); createTexture(sector);
initSector(sector);
for(int cx = 0; cx < sector.size; cx++){ for(int cx = 0; cx < sector.size; cx++){
for(int cy = 0; cy < sector.size; cy++){ for(int cy = 0; cy < sector.size; cy++){
grid.put(sector.x + cx, sector.y + cy, sector); grid.put(sector.x + cx, sector.y + cy, sector);
@@ -113,6 +116,10 @@ public class Sectors{
Settings.save(); Settings.save();
} }
private void initSector(Sector sector){
sector.mission = new BattleMission();
}
private int round2(int i){ private int round2(int i){
if(i < 0){ if(i < 0){
i --; i --;

View File

@@ -11,6 +11,7 @@ import io.anuke.mindustry.content.blocks.StorageBlocks;
import io.anuke.mindustry.game.Team; import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.maps.MapTileData; import io.anuke.mindustry.maps.MapTileData;
import io.anuke.mindustry.maps.MapTileData.TileDataMarker; import io.anuke.mindustry.maps.MapTileData.TileDataMarker;
import io.anuke.mindustry.maps.Sector;
import io.anuke.mindustry.type.Item; import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
@@ -18,7 +19,6 @@ import io.anuke.mindustry.world.blocks.Floor;
import io.anuke.ucore.noise.RidgedPerlin; import io.anuke.ucore.noise.RidgedPerlin;
import io.anuke.ucore.noise.Simplex; import io.anuke.ucore.noise.Simplex;
import io.anuke.ucore.noise.VoronoiNoise; import io.anuke.ucore.noise.VoronoiNoise;
import io.anuke.ucore.util.Bits;
import io.anuke.ucore.util.Geometry; import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.SeedRandom; import io.anuke.ucore.util.SeedRandom;
@@ -167,14 +167,13 @@ public class WorldGenerator{
} }
} }
public void generateMap(Tile[][] tiles, int sectorX, int sectorY){ public void generateMap(Tile[][] tiles, Sector sector){
int width = tiles.length, height = tiles[0].length; int width = tiles.length, height = tiles[0].length;
long seed = Bits.packLong(sectorX, sectorY); SeedRandom rnd = new SeedRandom(sector.getSeed());
SeedRandom rnd = new SeedRandom(seed);
for(int x = 0; x < width; x++){ for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){ for(int y = 0; y < height; y++){
GenResult result = generateTile(sectorX, sectorY, x, y); GenResult result = generateTile(sector.x, sector.y, x, y);
Tile tile = new Tile(x, y, (byte)result.floor.id, (byte)result.wall.id, (byte)0, (byte)0, result.elevation); Tile tile = new Tile(x, y, (byte)result.floor.id, (byte)result.wall.id, (byte)0, (byte)0, result.elevation);
tiles[x][y] = tile; tiles[x][y] = tile;
} }
@@ -204,7 +203,9 @@ public class WorldGenerator{
tiles[coreX][coreY].setBlock(StorageBlocks.core); tiles[coreX][coreY].setBlock(StorageBlocks.core);
tiles[coreX][coreY].setTeam(Team.blue); tiles[coreX][coreY].setTeam(Team.blue);
prepareTiles(tiles, seed, true); sector.mission.generate(tiles, sector);
prepareTiles(tiles, sector.getSeed(), true);
} }
public GenResult generateTile(int sectorX, int sectorY, int localX, int localY){ public GenResult generateTile(int sectorX, int sectorY, int localX, int localY){

View File

@@ -0,0 +1,26 @@
package io.anuke.mindustry.maps.goals;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.content.blocks.StorageBlocks;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.maps.Sector;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.util.Mathf;
public class BattleMission implements Mission{
@Override
public void generate(Tile[][] tiles, Sector sector){
int x = Mathf.randomSeed(sector.getSeed(), 1, tiles.length - 2);
int y = Mathf.randomSeed(sector.getSeed(), 1, tiles[0].length - 2);
tiles[x][y].setBlock(StorageBlocks.core);
tiles[x][y].setTeam(Team.red);
}
@Override
public boolean isComplete(){
//TODO check all enemy teams, not just the first
return Vars.state.teams.getTeams(false).first().cores.size == 0;
}
}

View File

@@ -1,5 +0,0 @@
package io.anuke.mindustry.maps.goals;
public interface Goal{
boolean isComplete();
}

View File

@@ -0,0 +1,10 @@
package io.anuke.mindustry.maps.goals;
import io.anuke.mindustry.maps.Sector;
import io.anuke.mindustry.world.Tile;
public interface Mission{
boolean isComplete();
default void generate(Tile[][] tiles, Sector sector){}
}

View File

@@ -2,10 +2,10 @@ package io.anuke.mindustry.maps.goals;
import static io.anuke.mindustry.Vars.*; import static io.anuke.mindustry.Vars.*;
public class WaveGoal implements Goal{ public class WaveMission implements Mission{
private final int target; private final int target;
public WaveGoal(int target){ public WaveMission(int target){
this.target = target; this.target = target;
} }

View File

@@ -31,7 +31,7 @@ public class PowerSmelter extends PowerBlock{
protected float minFlux = 0.2f; protected float minFlux = 0.2f;
protected int fluxNeeded = 1; protected int fluxNeeded = 1;
protected float baseFluxChance = 0.15f; protected float baseFluxChance = 0.25f;
protected boolean useFlux = false; protected boolean useFlux = false;
protected float heatUpTime = 80f; protected float heatUpTime = 80f;

View File

@@ -27,7 +27,7 @@ public class Smelter extends Block{
protected Item result; protected Item result;
protected float minFlux = 0.2f; protected float minFlux = 0.2f;
protected float baseFluxChance = 0.15f; protected float baseFluxChance = 0.25f;
protected boolean useFlux = false; protected boolean useFlux = false;
protected float craftTime = 20f; protected float craftTime = 20f;