mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-11 03:08:38 +07:00
Added water check
This commit is contained in:
parent
ad45bebbdc
commit
ea3e16ee16
Binary file not shown.
@ -302,6 +302,10 @@ public class PlanetDialog extends FloatingDialog{
|
||||
|
||||
stable.addButton("Launch", () -> {
|
||||
if(selected != null){
|
||||
if(selected.hasAttribute(SectorAttribute.naval)){
|
||||
ui.showInfo("You need a naval loadout to launch here.");
|
||||
return;
|
||||
}
|
||||
control.playSector(selected);
|
||||
hide();
|
||||
}
|
||||
|
@ -10,10 +10,12 @@ import mindustry.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.core.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.net.Net;
|
||||
import mindustry.type.*;
|
||||
import mindustry.type.Sector.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.storage.CoreBlock.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
@ -50,7 +52,7 @@ public class SectorDataGenerator{
|
||||
ObjectSet<Content> content = new ObjectSet<>();
|
||||
|
||||
world.loadSector(sector);
|
||||
int waterFloors = 0, totalFloors = 0;
|
||||
float waterFloors = 0, totalFloors = 0;
|
||||
state.rules.sector = sector;
|
||||
|
||||
for(Tile tile : world.tiles){
|
||||
@ -66,7 +68,7 @@ public class SectorDataGenerator{
|
||||
if(!tile.block().isStatic()){
|
||||
totalFloors ++;
|
||||
if(liquid == Liquids.water){
|
||||
waterFloors ++;
|
||||
waterFloors += tile.floor().isDeep() ? 1f : 0.5f;
|
||||
}
|
||||
floors.increment(tile.floor());
|
||||
if(tile.overlay() != Blocks.air){
|
||||
@ -75,6 +77,27 @@ public class SectorDataGenerator{
|
||||
}
|
||||
}
|
||||
|
||||
CoreEntity entity = Team.sharded.core();
|
||||
int cx = entity.tileX(), cy = entity.tileY();
|
||||
|
||||
int nearTiles = 0;
|
||||
int waterCheckRad = 5;
|
||||
|
||||
//check for water presence
|
||||
for(int rx = -waterCheckRad; rx <= waterCheckRad; rx++){
|
||||
for(int ry = -waterCheckRad; ry <= waterCheckRad; ry++){
|
||||
Tile tile = world.tile(cx + rx, cy + ry);
|
||||
if(tile == null || tile.floor().liquidDrop != null){
|
||||
nearTiles ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//naval sector guaranteed
|
||||
if(nearTiles >= 4){
|
||||
waterFloors = totalFloors;
|
||||
}
|
||||
|
||||
//sort counts in descending order
|
||||
Array<ObjectIntMap.Entry<Block>> entries = floors.entries().toArray();
|
||||
entries.sort(e -> -e.value);
|
||||
@ -91,8 +114,7 @@ public class SectorDataGenerator{
|
||||
data.resources = content.asArray().sort(Structs.comps(Structs.comparing(Content::getContentType), Structs.comparingInt(c -> c.id))).toArray(UnlockableContent.class);
|
||||
|
||||
//50% water -> naval attribute
|
||||
//TODO also select sectors with water spawns
|
||||
if((float)waterFloors / totalFloors >= 0.6f){
|
||||
if(waterFloors / totalFloors >= 0.6f){
|
||||
data.attributes |= (1 << SectorAttribute.naval.ordinal());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user