Adjustable core position (#307)
* Made starting core position configurable and fixed tutorial sector core position * Refactored classes to use a public int interface and a GridPoint2 as internal storage * Battle missions now spawn the core at 50, 50 again * Default player cores are now created at the first spawnpoint * Manually fixed formatting which was not caught by auto formatter
This commit is contained in:
@@ -30,7 +30,8 @@ public class TutorialSector{
|
||||
//TODO fill turret with items mission
|
||||
//new BlockMission(ProductionBlocks.mechanicalDrill).setMessage("$tutorial.drillturret"),
|
||||
|
||||
new WaveMission(2).setMessage("$tutorial.waves"),
|
||||
// Create a wave mission which spawns the core at 60, 60 rather than in the center of the map
|
||||
new WaveMission(2, 60, 60).setMessage("$tutorial.waves"),
|
||||
|
||||
new ItemMission(Items.lead, 150).setMessage("$tutorial.lead"),
|
||||
new ItemMission(Items.copper, 250).setMessage("$tutorial.morecopper"),
|
||||
|
||||
@@ -12,8 +12,24 @@ import io.anuke.ucore.util.Bundles;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class BattleMission extends Mission{
|
||||
public class BattleMission extends MissionWithStartingCore{
|
||||
final int spacing = 30;
|
||||
public static final int defaultXCorePos = 50;
|
||||
public static final int defaultYCorePos = 50;
|
||||
|
||||
/** Creates a battle mission with the player core being at (@defaultXCorePos, @defaultYCorePos) */
|
||||
public BattleMission(){
|
||||
this(defaultXCorePos, defaultYCorePos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a wave survival with the player core being at a custom location.
|
||||
* @param xCorePos The X coordinate of the custom core position.
|
||||
* @param yCorePos The Y coordinate of the custom core position.
|
||||
*/
|
||||
public BattleMission(int xCorePos, int yCorePos){
|
||||
super(xCorePos, yCorePos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIcon(){
|
||||
@@ -37,7 +53,7 @@ public class BattleMission extends Mission{
|
||||
|
||||
@Override
|
||||
public void generate(Generation gen){
|
||||
generateCoreAt(gen, 50, 50, defaultTeam);
|
||||
generateCoreAtFirstSpawnPoint(gen, defaultTeam);
|
||||
|
||||
if(state.teams.get(defaultTeam).cores.size == 0){
|
||||
return;
|
||||
|
||||
@@ -100,10 +100,4 @@ public abstract class Mission{
|
||||
}
|
||||
|
||||
public void generate(Generation gen){}
|
||||
|
||||
public void generateCoreAt(Generation gen, int coreX, int coreY, Team team){
|
||||
gen.tiles[coreX][coreY].setBlock(StorageBlocks.core);
|
||||
gen.tiles[coreX][coreY].setTeam(team);
|
||||
state.teams.get(team).cores.add(gen.tiles[coreX][coreY]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package io.anuke.mindustry.maps.missions;
|
||||
|
||||
import com.badlogic.gdx.math.GridPoint2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.content.blocks.StorageBlocks;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.maps.generation.Generation;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
|
||||
import static io.anuke.mindustry.Vars.state;
|
||||
|
||||
public abstract class MissionWithStartingCore extends Mission{
|
||||
|
||||
|
||||
/** Stores a custom starting location for the core, or null if the default calculation (map center) shall be used. */
|
||||
private final GridPoint2 customStartingPoint;
|
||||
|
||||
/** Default constructor. Missions created this way will have a player starting core in the center of the map. */
|
||||
MissionWithStartingCore(){
|
||||
this.customStartingPoint = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a mission with a core on a non-default location.
|
||||
* @param xCorePos The x coordinate of the custom core position.
|
||||
* @param yCorePos The y coordinate of the custom core position.
|
||||
*/
|
||||
MissionWithStartingCore(int xCorePos, int yCorePos){
|
||||
this.customStartingPoint = new GridPoint2(xCorePos, yCorePos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a player core based on generation parameters.
|
||||
* @param gen The generation parameters which provide the map size.
|
||||
* @param team The team to generate the core for.
|
||||
*/
|
||||
public void generateCoreAtFirstSpawnPoint(Generation gen, Team team){
|
||||
Array<GridPoint2> spawnPoints = getSpawnPoints(gen);
|
||||
if(spawnPoints == null || spawnPoints.size == 0){
|
||||
throw new IllegalArgumentException("A MissionWithStartingCore subclass did not provide a spawn point in getSpawnPoints(). However, at least one point must always be provided.");
|
||||
}
|
||||
|
||||
Tile startingCoreTile = gen.tiles[spawnPoints.first().x][spawnPoints.first().y];
|
||||
startingCoreTile.setBlock(StorageBlocks.core);
|
||||
startingCoreTile.setTeam(team);
|
||||
state.teams.get(team).cores.add(startingCoreTile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the spawn point in the center of the map or at a custom location which was provided through the constructor.
|
||||
* @param gen The generation parameters which provide the map size.
|
||||
* @return The center of the map or a custom location.
|
||||
* @implNote Must return an array with at least one entry.
|
||||
*/
|
||||
@Override
|
||||
public Array<GridPoint2> getSpawnPoints(Generation gen){
|
||||
if(this.customStartingPoint == null){
|
||||
return Array.with(new GridPoint2(gen.width / 2, gen.height / 2));
|
||||
}else{
|
||||
return Array.with(this.customStartingPoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,13 +15,30 @@ import static io.anuke.mindustry.Vars.state;
|
||||
import static io.anuke.mindustry.Vars.waveTeam;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public class WaveMission extends Mission{
|
||||
public class WaveMission extends MissionWithStartingCore{
|
||||
private final int target;
|
||||
|
||||
/**
|
||||
* Creates a wave survival mission with the player core being in the center of the map.
|
||||
* @param target The number of waves to be survived.
|
||||
*/
|
||||
public WaveMission(int target){
|
||||
super();
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a wave survival with the player core being at a custom location.
|
||||
* @param target The number of waves to be survived.
|
||||
* @param xCorePos The X coordinate of the custom core position.
|
||||
* @param yCorePos The Y coordinate of the custom core position.
|
||||
*/
|
||||
public WaveMission(int target, int xCorePos, int yCorePos){
|
||||
super(xCorePos, yCorePos);
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Array<SpawnGroup> getWaves(Sector sector){
|
||||
return Waves.getSpawns();
|
||||
@@ -29,8 +46,7 @@ public class WaveMission extends Mission{
|
||||
|
||||
@Override
|
||||
public void generate(Generation gen){
|
||||
int coreX = gen.width/2, coreY = gen.height/2;
|
||||
generateCoreAt(gen, coreX, coreY, Team.blue);
|
||||
generateCoreAtFirstSpawnPoint(gen, Team.blue);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,9 +87,4 @@ public class WaveMission extends Mission{
|
||||
public boolean isComplete(){
|
||||
return state.wave > target && Vars.unitGroups[Vars.waveTeam.ordinal()].size() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<GridPoint2> getSpawnPoints(Generation gen){
|
||||
return Array.with(new GridPoint2(gen.width/2, gen.height/2));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user