Many campaign changes
This commit is contained in:
82
core/src/mindustry/maps/SectorDamage.java
Normal file
82
core/src/mindustry/maps/SectorDamage.java
Normal file
@@ -0,0 +1,82 @@
|
||||
package mindustry.maps;
|
||||
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.storage.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class SectorDamage{
|
||||
//direct damage is for testing only
|
||||
private static final boolean direct = false;
|
||||
|
||||
//TODO amount of damage could be related to wave spacing
|
||||
public static void apply(float turns){
|
||||
Tiles tiles = world.tiles;
|
||||
|
||||
Queue<Tile> frontier = new Queue<>();
|
||||
float[][] values = new float[tiles.width][tiles.height];
|
||||
float damage = turns*50;
|
||||
|
||||
//phase one: find all spawnpoints
|
||||
for(Tile tile : tiles){
|
||||
if((tile.block() instanceof CoreBlock && tile.team() == state.rules.waveTeam) || tile.overlay() == Blocks.spawn){
|
||||
frontier.add(tile);
|
||||
values[tile.x][tile.y] = damage;
|
||||
}
|
||||
}
|
||||
|
||||
float falloff = (damage) / (Math.max(tiles.width, tiles.height) * Mathf.sqrt2);
|
||||
int peak = 0;
|
||||
|
||||
//phase two: propagate the damage
|
||||
while(!frontier.isEmpty()){
|
||||
peak = Math.max(peak, frontier.size);
|
||||
Tile tile = frontier.removeFirst();
|
||||
float currDamage = values[tile.x][tile.y] - falloff;
|
||||
|
||||
for(int i = 0; i < 4; i++){
|
||||
int cx = tile.x + Geometry.d4x[i], cy = tile.y + Geometry.d4y[i];
|
||||
|
||||
//propagate to new tiles
|
||||
if(tiles.in(cx, cy) && values[cx][cy] < currDamage){
|
||||
Tile other = tiles.getn(cx, cy);
|
||||
float resultDamage = currDamage;
|
||||
|
||||
//damage the tile if it's not friendly
|
||||
if(other.entity != null && other.team() != state.rules.waveTeam){
|
||||
resultDamage -= other.entity.health();
|
||||
|
||||
if(direct){
|
||||
other.entity.damage(currDamage);
|
||||
}else{ //indirect damage happens at game load time
|
||||
other.entity.health(other.entity.health() - currDamage);
|
||||
|
||||
//remove the block when destroyed
|
||||
if(other.entity.health() < 0){
|
||||
if(!other.floor().solid && !other.floor().isLiquid && Mathf.chance(0.4)){
|
||||
Effects.rubble(other.entity.x(), other.entity.y(), other.block().size);
|
||||
}
|
||||
|
||||
other.remove();
|
||||
}
|
||||
}
|
||||
|
||||
}else if(other.solid() && !other.synthetic()){ //skip damage propagation through solid blocks
|
||||
continue;
|
||||
}
|
||||
|
||||
if(resultDamage > 0 && values[cx][cy] < resultDamage){
|
||||
frontier.addLast(other);
|
||||
values[cx][cy] = resultDamage;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package mindustry.maps.generators;
|
||||
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.game.*;
|
||||
@@ -9,10 +10,40 @@ import mindustry.world.*;
|
||||
public class BaseGenerator{
|
||||
|
||||
public void generate(Tiles tiles, Array<Tile> cores, Tile spawn, Team team, Sector sector){
|
||||
//algorithm idea: make it spawn prefab turret setups and route resources to them with conveyors from chunks of ore drill setups
|
||||
|
||||
GridBits used = new GridBits(tiles.width, tiles.height);
|
||||
Queue<Tile> frontier = new Queue<>();
|
||||
for(Tile tile : cores){
|
||||
frontier.add(tile);
|
||||
}
|
||||
|
||||
int count = 2000;
|
||||
int total = 0;
|
||||
|
||||
while(total++ < count){
|
||||
Tile tile = frontier.removeFirst();
|
||||
for(int i = 0; i < 4; i++){
|
||||
int cx = tile.x + Geometry.d4x[i], cy = tile.y + Geometry.d4y[i];
|
||||
if(tiles.in(cx, cy) && !used.get(cx, cy)){
|
||||
Tile other = tiles.getn(cx, cy);
|
||||
|
||||
if(!other.solid()){
|
||||
frontier.addLast(other);
|
||||
}
|
||||
used.set(cx, cy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(Tile tile : frontier){
|
||||
tile.setBlock(Blocks.copperWall, team);
|
||||
}
|
||||
|
||||
for(Tile tile : cores){
|
||||
tile.clearOverlay();
|
||||
tile.setBlock(Blocks.coreShard, team);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -260,9 +260,10 @@ public class TODOPlanetGenerator extends PlanetGenerator{
|
||||
}
|
||||
});
|
||||
|
||||
//TODO PLACE CORRECT LOADOUT
|
||||
Schematics.placeLoadout(Loadouts.advancedShard, spawn.x, spawn.y);
|
||||
|
||||
if(sector.hostility > 0.02f){
|
||||
if(sector.hasEnemyBase()){
|
||||
new BaseGenerator().generate(tiles, enemies.map(r -> tiles.getn(r.x, r.y)), tiles.get(spawn.x, spawn.y), state.rules.waveTeam, sector);
|
||||
|
||||
state.rules.attackMode = true;
|
||||
|
||||
Reference in New Issue
Block a user