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.*;
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

View File

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

View File

@ -366,7 +366,7 @@ public class Control extends Module{
}
//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().save();
if(!headless){

View File

@ -215,7 +215,23 @@ public class Renderer extends RendererModule{
blocks.processBlocks();
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);
blocks.drawBlocks(Layer.placement);

View File

@ -230,16 +230,13 @@ public class World extends Module{
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);
EntityPhysics.resizeTree(0, 0, width * tilesize, height * tilesize);
Timers.mark();
generator.generateMap(tiles, sector.x, sector.y);
Log.info("Time to generate base map: {0}", Timers.elapsed());
Log.info("Time to generate fully without additional events: {0}", Timers.elapsed());
generator.generateMap(tiles, sector);
endMapLoad();

View File

@ -25,7 +25,7 @@ public class MapEditor{
private byte elevation;
private int rotation;
private Block drawBlock = Blocks.stone;
private Team drawTeam = Team.none;
private Team drawTeam = Team.blue;
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;
}
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){

View File

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

View File

@ -1,6 +1,5 @@
package io.anuke.mindustry.io.versions;
import com.badlogic.gdx.utils.IntMap;
import com.badlogic.gdx.utils.TimeUtils;
import io.anuke.mindustry.content.blocks.Blocks;
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.io.SaveFileVersion;
import io.anuke.mindustry.maps.Map;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.BlockPart;
import io.anuke.ucore.core.Timers;
@ -41,6 +39,7 @@ public class Save16 extends SaveFileVersion{
int sector = stream.readInt(); //sector ID
//general state
byte mode = stream.readByte();
String mapname = stream.readUTF();
Map map = world.maps().getByName(mapname);
@ -59,19 +58,6 @@ public class Save16 extends SaveFileVersion{
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
byte groups = stream.readByte();
@ -171,16 +157,6 @@ public class Save16 extends SaveFileVersion{
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--
int groups = 0;

View File

@ -4,8 +4,8 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.game.Saves.SaveSlot;
import io.anuke.mindustry.game.SpawnGroup;
import io.anuke.mindustry.maps.goals.Goal;
import io.anuke.mindustry.maps.goals.WaveGoal;
import io.anuke.mindustry.maps.goals.Mission;
import io.anuke.mindustry.maps.goals.WaveMission;
import io.anuke.ucore.util.Bits;
import static io.anuke.mindustry.Vars.control;
@ -21,11 +21,15 @@ public class Sector{
public int size = 1;
/**Display texture. Needs to be disposed.*/
public transient Texture texture;
/**Goal of this sector-- what needs to be accomplished to unlock it.*/
public transient Goal goal = new WaveGoal(30);
/**Mission of this sector-- what needs to be accomplished to unlock it.*/
public transient Mission mission = new WaveMission(30);
/**Enemies spawned at this sector.*/
public transient Array<SpawnGroup> spawns = new Array<>();
public int getSeed(){
return Bits.packInt(x, y);
}
public SaveSlot getSave(){
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.game.Team;
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.Edges;
import io.anuke.ucore.core.Settings;
@ -75,6 +76,7 @@ public class Sectors{
sector.y = (short)y;
sector.complete = false;
sector.size = isLarge ? 2 : 1;
initSector(sector);
for(int cx = 0; cx < sector.size; cx++){
for(int cy = 0; cy < sector.size; cy++){
@ -90,6 +92,7 @@ public class Sectors{
for(Sector sector : out){
createTexture(sector);
initSector(sector);
for(int cx = 0; cx < sector.size; cx++){
for(int cy = 0; cy < sector.size; cy++){
grid.put(sector.x + cx, sector.y + cy, sector);
@ -113,6 +116,10 @@ public class Sectors{
Settings.save();
}
private void initSector(Sector sector){
sector.mission = new BattleMission();
}
private int round2(int i){
if(i < 0){
i --;

View File

@ -11,6 +11,7 @@ import io.anuke.mindustry.content.blocks.StorageBlocks;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.maps.MapTileData;
import io.anuke.mindustry.maps.MapTileData.TileDataMarker;
import io.anuke.mindustry.maps.Sector;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.world.Block;
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.Simplex;
import io.anuke.ucore.noise.VoronoiNoise;
import io.anuke.ucore.util.Bits;
import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.Mathf;
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;
long seed = Bits.packLong(sectorX, sectorY);
SeedRandom rnd = new SeedRandom(seed);
SeedRandom rnd = new SeedRandom(sector.getSeed());
for(int x = 0; x < width; x++){
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);
tiles[x][y] = tile;
}
@ -204,7 +203,9 @@ public class WorldGenerator{
tiles[coreX][coreY].setBlock(StorageBlocks.core);
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){

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.*;
public class WaveGoal implements Goal{
public class WaveMission implements Mission{
private final int target;
public WaveGoal(int target){
public WaveMission(int target){
this.target = target;
}

View File

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

View File

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