Added new wave spawning system
This commit is contained in:
@@ -2,12 +2,12 @@ package io.anuke.mindustry.ai;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.Bits;
|
||||
import io.anuke.mindustry.content.AmmoTypes;
|
||||
import io.anuke.mindustry.content.UnitTypes;
|
||||
import io.anuke.mindustry.entities.units.BaseUnit;
|
||||
import io.anuke.mindustry.entities.units.Squad;
|
||||
import io.anuke.mindustry.game.EventType.WorldLoadEvent;
|
||||
import io.anuke.mindustry.game.SpawnGroup;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.game.WaveCreator;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Events;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
@@ -23,6 +23,8 @@ public class WaveSpawner {
|
||||
|
||||
private Bits quadrants;
|
||||
|
||||
private Array<SpawnGroup> groups;
|
||||
|
||||
private Array<FlyerSpawn> flySpawns = new Array<>();
|
||||
private Array<GroundSpawn> groundSpawns = new Array<>();
|
||||
|
||||
@@ -62,11 +64,20 @@ public class WaveSpawner {
|
||||
}
|
||||
|
||||
public void spawnEnemies(){
|
||||
int spawned = Math.min(state.wave, 6);
|
||||
int groundGroups = 1 + state.wave / 20;
|
||||
int flyGroups = state.wave / 20;
|
||||
int flyGroups = 0;
|
||||
int groundGroups = 0;
|
||||
|
||||
//add extra groups if necessary
|
||||
//count total subgroups spawned by flying/group types
|
||||
for(SpawnGroup group : groups){
|
||||
int amount = group.getGroupsSpawned(state.wave);
|
||||
if(group.type.isFlying){
|
||||
flyGroups += amount;
|
||||
}else{
|
||||
groundGroups += amount;
|
||||
}
|
||||
}
|
||||
|
||||
//add extra groups if the total exceeds it
|
||||
for (int i = 0; i < groundGroups - groundSpawns.size; i++) {
|
||||
GroundSpawn spawn = new GroundSpawn();
|
||||
findLocation(spawn);
|
||||
@@ -79,45 +90,49 @@ public class WaveSpawner {
|
||||
flySpawns.add(spawn);
|
||||
}
|
||||
|
||||
if(state.wave % 20 == 0){
|
||||
for(FlyerSpawn spawn : flySpawns) findLocation(spawn);
|
||||
for(GroundSpawn spawn : groundSpawns) findLocation(spawn);
|
||||
}
|
||||
//store index of last used fly/ground spawn locations
|
||||
int flyCount = 0, groundCount = 0;
|
||||
|
||||
for(GroundSpawn spawn : groundSpawns){
|
||||
checkQuadrant(spawn.x, spawn.y);
|
||||
if(!getQuad(spawn.x, spawn.y)){
|
||||
findLocation(spawn);
|
||||
}
|
||||
for(SpawnGroup group : groups){
|
||||
int groups = group.getGroupsSpawned(state.wave);
|
||||
int spawned = group.getUnitsSpawned(state.wave);
|
||||
|
||||
Squad squad = new Squad();
|
||||
for (int i = 0; i < groups; i++) {
|
||||
Squad squad = new Squad();
|
||||
float spawnX, spawnY;
|
||||
float spread;
|
||||
|
||||
for(int i = 0; i < spawned; i ++){
|
||||
BaseUnit unit = UnitTypes.scout.create(Team.red);
|
||||
unit.inventory.addAmmo(AmmoTypes.bulletLead);
|
||||
unit.setWave();
|
||||
unit.setSquad(squad);
|
||||
unit.set(spawn.x * quadsize * tilesize + quadsize * tilesize/2f + Mathf.range(quadsize*tilesize/3f),
|
||||
spawn.y * quadsize * tilesize + quadsize * tilesize/2f + Mathf.range(quadsize*tilesize/3));
|
||||
unit.add();
|
||||
}
|
||||
}
|
||||
if(group.type.isFlying){
|
||||
FlyerSpawn spawn = flySpawns.get(flyCount);
|
||||
//TODO verify flyer spawn
|
||||
|
||||
for(FlyerSpawn spawn : flySpawns){
|
||||
Squad squad = new Squad();
|
||||
float addition = 40f;
|
||||
float spread = addition / 1.5f;
|
||||
float margin = 40f; //how far away from the edge flying units spawn
|
||||
spawnX = world.width() *tilesize/2f + Mathf.sqrwavex(spawn.angle) * (world.width()/2f*tilesize + margin);
|
||||
spawnY = world.height() * tilesize/2f + Mathf.sqrwavey(spawn.angle) * (world.height()/2f*tilesize + margin);
|
||||
spread = margin / 1.5f;
|
||||
|
||||
float baseX = world.width() *tilesize/2f + Mathf.sqrwavex(spawn.angle) * (world.width()/2f*tilesize + addition),
|
||||
baseY = world.height() * tilesize/2f + Mathf.sqrwavey(spawn.angle) * (world.height()/2f*tilesize + addition);
|
||||
flyCount ++;
|
||||
}else{
|
||||
GroundSpawn spawn = groundSpawns.get(groundCount);
|
||||
checkQuadrant(spawn.x, spawn.y);
|
||||
if(!getQuad(spawn.x, spawn.y)){
|
||||
findLocation(spawn);
|
||||
}
|
||||
|
||||
for(int i = 0; i < spawned; i ++){
|
||||
BaseUnit unit = UnitTypes.vtol.create(Team.red);
|
||||
unit.inventory.addAmmo(AmmoTypes.bulletLead);
|
||||
unit.setWave();
|
||||
unit.setSquad(squad);
|
||||
unit.set(baseX + Mathf.range(spread), baseY + Mathf.range(spread));
|
||||
unit.add();
|
||||
spawnX = spawn.x * quadsize * tilesize + quadsize * tilesize/2f;
|
||||
spawnY = spawn.y * quadsize * tilesize + quadsize * tilesize/2f;
|
||||
spread = quadsize*tilesize/3f;
|
||||
|
||||
groundCount ++;
|
||||
}
|
||||
|
||||
for (int j = 0; j < spawned; j++) {
|
||||
BaseUnit unit = group.createUnit(Team.red);
|
||||
unit.setWave();
|
||||
unit.setSquad(squad);
|
||||
unit.set(spawnX + Mathf.range(spread), spawnY + Mathf.range(spread));
|
||||
unit.add();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -150,6 +165,10 @@ public class WaveSpawner {
|
||||
flySpawns.clear();
|
||||
groundSpawns.clear();
|
||||
quadrants = new Bits(quadWidth() * quadHeight());
|
||||
|
||||
if(groups == null){
|
||||
groups = WaveCreator.getSpawns();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean getQuad(int quadx, int quady){
|
||||
@@ -164,6 +183,7 @@ public class WaveSpawner {
|
||||
}
|
||||
}
|
||||
|
||||
//TODO instead of randomly scattering locations around the map, find spawns close to each other
|
||||
private void findLocation(GroundSpawn spawn){
|
||||
spawn.x = -1;
|
||||
spawn.y = -1;
|
||||
@@ -182,6 +202,7 @@ public class WaveSpawner {
|
||||
});
|
||||
}
|
||||
|
||||
//TODO instead of randomly scattering locations around the map, find spawns close to each other
|
||||
private void findLocation(FlyerSpawn spawn){
|
||||
spawn.angle = Mathf.random(360f);
|
||||
}
|
||||
@@ -197,18 +218,10 @@ public class WaveSpawner {
|
||||
private class FlyerSpawn{
|
||||
//square angle
|
||||
float angle;
|
||||
|
||||
FlyerSpawn(){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private class GroundSpawn{
|
||||
//quadrant spawn coordinates
|
||||
int x, y;
|
||||
|
||||
GroundSpawn(){
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user