Choosing of Erekir launch sector based on loadout cost
This commit is contained in:
@@ -20,6 +20,8 @@ import mindustry.world.*;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public abstract class PlanetGenerator extends BasicGenerator implements HexMesher{
|
||||
protected static final ItemSeq tmpItems = new ItemSeq();
|
||||
|
||||
public int baseSeed = 0;
|
||||
public int seed = 0;
|
||||
|
||||
@@ -54,23 +56,42 @@ public abstract class PlanetGenerator extends BasicGenerator implements HexMeshe
|
||||
return sector.planet.allowLaunchToNumbered && (sector.hasBase() || sector.near().contains(Sector::hasBase));
|
||||
}
|
||||
|
||||
public Sector findLaunchCandidate(Sector destination, Sector selected){
|
||||
Sector launchSector = selected != null && selected.planet == destination.planet && selected.hasBase() ? selected: null;
|
||||
//directly nearby.
|
||||
if(destination.near().contains(launchSector)) return launchSector;
|
||||
public @Nullable Sector findLaunchCandidate(Sector destination, @Nullable Sector selected){
|
||||
if(!destination.allowLaunchLoadout() && destination.preset != null){
|
||||
tmpItems.clear();
|
||||
|
||||
Sector launchFrom = launchSector;
|
||||
if(launchFrom == null || (destination.preset == null && !destination.near().contains(launchSector))){
|
||||
//TODO pick one with the most resources
|
||||
launchFrom = destination.near().find(Sector::hasBase);
|
||||
if(launchFrom == null && destination.preset != null){
|
||||
if(launchSector != null) return launchSector;
|
||||
launchFrom = destination.planet.sectors.min(s -> !s.hasBase() ? Float.MAX_VALUE : s.tile.v.dst2(destination.tile.v));
|
||||
if(!launchFrom.hasBase()) launchFrom = null;
|
||||
var rules = destination.preset.generator.map.rules();
|
||||
for(var stack : rules.loadout){
|
||||
if(stack.item.isOnPlanet(destination.planet)){
|
||||
tmpItems.add(stack.item, stack.amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return launchFrom;
|
||||
//currently played (selected) sector has all the resources
|
||||
if(selected != null && selected.planet == destination.planet && selected.hasBase() && selected.items().has(tmpItems)){
|
||||
return selected;
|
||||
}else{
|
||||
//find the closest sector that has resources (ranked by distance, not item quantity)
|
||||
return destination.planet.sectors.min(s -> s.hasBase() && s.items().has(tmpItems), s -> s.tile.v.dst(destination.tile.v));
|
||||
}
|
||||
}else{
|
||||
Sector launchSector = selected != null && selected.planet == destination.planet && selected.hasBase() ? selected : null;
|
||||
//directly nearby.
|
||||
if(destination.near().contains(launchSector)) return launchSector;
|
||||
|
||||
Sector launchFrom = launchSector;
|
||||
if(launchFrom == null || destination.preset == null){
|
||||
//TODO pick one with the most resources
|
||||
launchFrom = destination.near().find(Sector::hasBase);
|
||||
if(launchFrom == null && destination.preset != null){
|
||||
if(launchSector != null) return launchSector;
|
||||
launchFrom = destination.planet.sectors.min(s -> !s.hasBase() ? Float.MAX_VALUE : s.tile.v.dst2(destination.tile.v));
|
||||
if(!launchFrom.hasBase()) launchFrom = null;
|
||||
}
|
||||
}
|
||||
|
||||
return launchFrom;
|
||||
}
|
||||
}
|
||||
|
||||
/** @return whether to allow landing on the specified procedural sector */
|
||||
|
||||
@@ -97,7 +97,7 @@ public class SerpuloPlanetGenerator extends PlanetGenerator{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sector findLaunchCandidate(Sector destination, Sector selected){
|
||||
public @Nullable Sector findLaunchCandidate(Sector destination, @Nullable Sector selected){
|
||||
if(destination.preset == null || !destination.preset.requireUnlock){
|
||||
if(selected != null && selected.isNear(destination) && allowNumberedLaunch(selected)){
|
||||
return selected;
|
||||
|
||||
@@ -68,7 +68,6 @@ public class LaunchLoadoutDialog extends BaseDialog{
|
||||
|
||||
if(!destination.allowLaunchLoadout()){
|
||||
resources.clear();
|
||||
//TODO this should be set to a proper loadout based on sector.
|
||||
if(destination.preset != null){
|
||||
var rules = destination.preset.generator.map.rules();
|
||||
for(var stack : rules.loadout){
|
||||
|
||||
@@ -430,10 +430,11 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
||||
return mode == planetLaunch ? sector.planet.generator.allowAcceleratorLanding(sector) : sector.planet.generator.allowLanding(sector);
|
||||
}
|
||||
|
||||
Sector findLauncher(Sector to){
|
||||
@Nullable Sector findLauncher(Sector to){
|
||||
if(mode == planetLaunch || to.planet.generator == null) return launchSector;
|
||||
|
||||
return to.planet.generator.findLaunchCandidate(to, launchSector);
|
||||
Sector candidate = to.planet.generator.findLaunchCandidate(to, launchSector);
|
||||
return candidate == null ? launchSector : candidate;
|
||||
}
|
||||
|
||||
boolean showing(){
|
||||
|
||||
Reference in New Issue
Block a user