Base bugfixes

This commit is contained in:
Anuken
2020-06-05 16:33:55 -04:00
parent 597d58e843
commit 50422aaac5
12 changed files with 74 additions and 49 deletions

View File

@@ -1,4 +0,0 @@
mschxœ%‹Ñ
à E¯Z»BÊ>Ä—ý³2[Õ•ýýr)!9 çL
Ãî·õñ å8bu—ÏÙe_?óšÎVÓ»·R1…²ãO¶9µ¸¹³ô"c<E28093>}ó-·Ö”3€E
†07,¡y+<2B>‡aJÝHgèË×<C38B>71@sXF<58>©oHàIc

View File

@@ -1,2 +0,0 @@
mschxś%LŃ
Ă <*…AÇ>Ä·ý<C2B7>kC+ŘV˘˛ßźYIrwÜ%Á„É`<ĂÁ0o‡×rĺĚâż!%źlŚq+ľ\MĆ3źÜŽPăâW‰©§k,Uâ§ŐK0oňŢ÷}.ŔÜ<07>ąače”Fµµ€%ęĘuKAwB*ţ™˝?X=V"5ť~˙ě

View File

@@ -0,0 +1 @@
mschxœ-Ïknƒ0à±<C3A0>]Ò$mZ”ªgàP!’Á/©·ï.S~ðY »;Æ ßÅ>>ãü ¸üŒÝ:Ä¥oÇÔ§„²ÍãÖýæ ~ŽiË(×1åøè&TýÒ

View File

@@ -0,0 +1 @@
mschx<>M־a0 אַLDB׀sp¨)ֵ<>ְF&‰סלˆ³sׁר£i³ץֻ+NP ₪ׁAך¾ןsה£6rhnvװ®<D7B0>µ¡±ויJPg½,ה88<38>ץְ<D7A5>v0 צ³½“k<E2809C>םשD¦c

View File

@@ -0,0 +1,2 @@
mschxœ%ŒA
Ã0 'VKÝB ~ˆeãKjçÐÇ—J HbwV,<2C>0p«é<C2AB>y”´/%ARŸymí“{¬mÉ„½­©Ç-Õ¼FU%O]<n@ðÞq‡ãâzez°Tµ¦\¹˜Í_er¾Mö6ZÉÏ™¬ûÐâe

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -4,6 +4,7 @@ import arc.*;
import arc.struct.*; import arc.struct.*;
import arc.util.ArcAnnotate.*; import arc.util.ArcAnnotate.*;
import arc.util.*; import arc.util.*;
import mindustry.ctype.*;
import mindustry.game.*; import mindustry.game.*;
import mindustry.game.Schematic.*; import mindustry.game.Schematic.*;
import mindustry.type.*; import mindustry.type.*;
@@ -20,16 +21,16 @@ import static mindustry.Vars.tilesize;
public class BaseRegistry{ public class BaseRegistry{
public Array<BasePart> cores = new Array<>(); public Array<BasePart> cores = new Array<>();
public Array<BasePart> parts = new Array<>(); public Array<BasePart> parts = new Array<>();
public ObjectMap<Item, Array<BasePart>> itemParts = new ObjectMap<>(); public ObjectMap<Content, Array<BasePart>> reqParts = new ObjectMap<>();
public Array<BasePart> forItem(Item item){ public Array<BasePart> forResource(Content item){
return itemParts.get(item, Array::new); return reqParts.get(item, Array::new);
} }
public void load(){ public void load(){
cores.clear(); cores.clear();
parts.clear(); parts.clear();
itemParts.clear(); reqParts.clear();
String[] names = Core.files.internal("basepartnames").readString().split("\n"); String[] names = Core.files.internal("basepartnames").readString().split("\n");
@@ -42,9 +43,6 @@ public class BaseRegistry{
int drills = 0; int drills = 0;
for(Stile tile : schem.tiles){ for(Stile tile : schem.tiles){
//make note of occupied positions
tile.block.iterateTaken(tile.x, tile.y, part.occupied::set);
//keep track of core type //keep track of core type
if(tile.block instanceof CoreBlock){ if(tile.block instanceof CoreBlock){
part.core = tile.block; part.core = tile.block;
@@ -53,17 +51,17 @@ public class BaseRegistry{
//save the required resource based on item source - multiple sources are not allowed //save the required resource based on item source - multiple sources are not allowed
if(tile.block instanceof ItemSource){ if(tile.block instanceof ItemSource){
Item config = (Item)tile.config; Item config = (Item)tile.config;
if(config != null) part.requiredItem = config; if(config != null) part.required = config;
} }
//same for liquids - this is not used yet //same for liquids - this is not used yet
if(tile.block instanceof LiquidSource){ if(tile.block instanceof LiquidSource){
Liquid config = (Liquid)tile.config; Liquid config = (Liquid)tile.config;
if(config != null) part.requiredLiquid = config; if(config != null) part.required = config;
} }
//calculate averages //calculate averages
if(tile.block instanceof Drill){ if(tile.block instanceof Drill || tile.block instanceof Pump){
Tmp.v1.add(tile.x*tilesize + tile.block.offset(), tile.y*tilesize + tile.block.offset()); Tmp.v1.add(tile.x*tilesize + tile.block.offset(), tile.y*tilesize + tile.block.offset());
drills ++; drills ++;
} }
@@ -74,7 +72,7 @@ public class BaseRegistry{
if(part.core != null){ if(part.core != null){
cores.add(part); cores.add(part);
}else if(part.requiredItem == null){ }else if(part.required == null){
parts.add(part); parts.add(part);
} }
@@ -87,9 +85,8 @@ public class BaseRegistry{
part.centerY = part.schematic.height/2; part.centerY = part.schematic.height/2;
} }
if(part.requiredItem != null){ if(part.required != null) reqParts.get(part.required, Array::new).add(part);
itemParts.get(part.requiredItem, Array::new).add(part);
}
}catch(IOException e){ }catch(IOException e){
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@@ -97,18 +94,16 @@ public class BaseRegistry{
cores.sort(Structs.comps(Structs.comparingFloat(b -> b.core.health), Structs.comparingFloat(b -> b.tier))); cores.sort(Structs.comps(Structs.comparingFloat(b -> b.core.health), Structs.comparingFloat(b -> b.tier)));
parts.sort(); parts.sort();
itemParts.each((key, arr) -> arr.sort()); reqParts.each((key, arr) -> arr.sort());
} }
public static class BasePart implements Comparable<BasePart>{ public static class BasePart implements Comparable<BasePart>{
public final Schematic schematic; public final Schematic schematic;
public final GridBits occupied;
//offsets for drills //offsets for drills
public int centerX, centerY; public int centerX, centerY;
public @Nullable Liquid requiredLiquid; public @Nullable Content required;
public @Nullable Item requiredItem;
public @Nullable Block core; public @Nullable Block core;
//total build cost //total build cost
@@ -116,7 +111,6 @@ public class BaseRegistry{
public BasePart(Schematic schematic){ public BasePart(Schematic schematic){
this.schematic = schematic; this.schematic = schematic;
this.occupied = new GridBits(schematic.width, schematic.height);
} }
@Override @Override

View File

@@ -36,6 +36,7 @@ public class BaseGenerator{
this.tiles = tiles; this.tiles = tiles;
this.team = team; this.team = team;
this.cores = cores; this.cores = cores;
Mathf.random.setSeed(sector.id);
for(Block block : content.blocks()){ for(Block block : content.blocks()){
if(block instanceof OreBlock && block.asFloor().itemDrop != null){ if(block instanceof OreBlock && block.asFloor().itemDrop != null){
@@ -43,20 +44,22 @@ public class BaseGenerator{
} }
} }
float costBudget = 1000;
Array<Block> wallsSmall = content.blocks().select(b -> b instanceof Wall && b.size == 1); Array<Block> wallsSmall = content.blocks().select(b -> b instanceof Wall && b.size == 1);
Array<Block> wallsLarge = content.blocks().select(b -> b instanceof Wall && b.size == 2); Array<Block> wallsLarge = content.blocks().select(b -> b instanceof Wall && b.size == 2);
float bracket = 0.1f; float bracket = 0.1f;
int wallAngle = 70; //180 for full coverage int wallAngle = 70; //180 for full coverage
double resourceChance = 0.4; double resourceChance = 0.4;
double nonResourceChance = 0.0007; double nonResourceChance = 0.0005;
BasePart coreschem = bases.cores.getFrac(bracket); BasePart coreschem = bases.cores.getFrac(bracket);
Block wall = wallsSmall.getFrac(bracket), wallLarge = wallsLarge.getFrac(bracket); Block wall = wallsSmall.getFrac(bracket), wallLarge = wallsLarge.getFrac(bracket);
for(Tile tile : cores){ for(Tile tile : cores){
tile.clearOverlay(); tile.clearOverlay();
Schematics.placeLoadout(coreschem.schematic, tile.x, tile.y, team, coreschem.requiredItem == null ? Blocks.oreCopper : ores.get(coreschem.requiredItem)); Schematics.placeLoadout(coreschem.schematic, tile.x, tile.y, team, coreschem.required instanceof Item ? ores.get((Item)coreschem.required) : Blocks.oreCopper);
//fill core with every type of item (even non-material) //fill core with every type of item (even non-material)
Tilec entity = tile.entity; Tilec entity = tile.entity;
@@ -65,14 +68,16 @@ public class BaseGenerator{
} }
} }
//first pass: random item specific schematics //random schematics
pass(tile -> { pass(tile -> {
if(tile.overlay().itemDrop != null && Mathf.chance(resourceChance)){ if(!tile.block().alwaysReplace) return;
Array<BasePart> parts = bases.forItem(tile.overlay().itemDrop);
if((tile.drop() != null || (tile.floor().liquidDrop != null && Mathf.chance(nonResourceChance * 2))) && Mathf.chance(resourceChance)){
Array<BasePart> parts = bases.forResource(tile.drop() != null ? tile.drop() : tile.floor().liquidDrop);
if(!parts.isEmpty()){ if(!parts.isEmpty()){
tryPlace(parts.random(), tile.x, tile.y); tryPlace(parts.random(), tile.x, tile.y);
} }
}else if(tile.overlay().itemDrop == null && Mathf.chance(nonResourceChance)){ }else if(Mathf.chance(nonResourceChance)){
tryPlace(bases.parts.random(), tile.x, tile.y); tryPlace(bases.parts.random(), tile.x, tile.y);
} }
}); });
@@ -142,33 +147,35 @@ public class BaseGenerator{
int rotation = Mathf.range(2); int rotation = Mathf.range(2);
axis.set((int)(part.schematic.width / 2f), (int)(part.schematic.height / 2f)); axis.set((int)(part.schematic.width / 2f), (int)(part.schematic.height / 2f));
Schematic result = rotate(part.schematic, rotation); Schematic result = rotate(part.schematic, rotation);
int rotdeg = rotation*90;
rotator.set(part.centerX, part.centerY).rotateAround(axis, rotation * 90); rotator.set(part.centerX, part.centerY).rotateAround(axis, rotdeg);
//bottom left schematic corner
int cx = x - (int)rotator.x; int cx = x - (int)rotator.x;
int cy = y - (int)rotator.y; int cy = y - (int)rotator.y;
for(int rx = cx; rx <= cx + result.width; rx++){ for(Stile tile : result.tiles){
for(int ry = cy; ry <= cy + result.height; ry++){ int realX = tile.x + cx, realY = tile.y + cy;
Tile tile = tiles.get(rx, ry); if(isTaken(tile.block, realX, realY)){
int ox = rx - cx, oy = ry - cy; return false;
rotator.set(ox, oy).rotateAround(axis, rotation * 90);
ox = (int)rotator.x;
oy = (int)rotator.y;
if(tile == null || ((!tile.block().alwaysReplace || world.getDarkness(rx, ry) > 0) && part.occupied.get(ox, oy))){
return false;
}
} }
} }
if(part.requiredItem != null){ if(part.required instanceof Item){
for(Stile tile : result.tiles){ for(Stile tile : result.tiles){
if(tile.block instanceof Drill){ if(tile.block instanceof Drill){
tile.block.iterateTaken(tile.x + cx, tile.y + cy, (ex, ey) -> {
tiles.getn(ex, ey).setOverlay(ores.get(part.requiredItem));
//random ores nearby to make it look more natural tile.block.iterateTaken(tile.x + cx, tile.y + cy, (ex, ey) -> {
tiles.getc(ex + Mathf.range(1), ey + Mathf.range(1)).setOverlay(ores.get(part.requiredItem));
if(!tiles.getn(ex, ey).floor().isLiquid){
tiles.getn(ex, ey).setOverlay(ores.get((Item)part.required));
}
Tile rand = tiles.getc(ex + Mathf.range(1), ey + Mathf.range(1));
if(!rand.floor().isLiquid){
//random ores nearby to make it look more natural
rand.setOverlay(ores.get((Item)part.required));
}
}); });
} }
} }
@@ -179,10 +186,36 @@ public class BaseGenerator{
return true; return true;
} }
boolean isTaken(Block block, int x, int y){
if(block.isMultiblock()){
int offsetx = -(block.size - 1) / 2;
int offsety = -(block.size - 1) / 2;
for(int dx = 0; dx < block.size; dx++){
for(int dy = 0; dy < block.size; dy++){
if(overlaps(dx + offsetx + x, dy + offsety + y)){
return true;
}
}
}
}else{
return overlaps(x, y);
}
return false;
}
boolean overlaps(int x, int y){
Tile tile = tiles.get(x, y);
return tile == null || !tile.block().alwaysReplace || world.getDarkness(x, y) > 0;
}
Schematic rotate(Schematic input, int times){ Schematic rotate(Schematic input, int times){
if(times == 0) return input; if(times == 0) return input;
boolean sign = times < 0; boolean sign = times > 0;
for(int i = 0; i < Math.abs(times); i++){ for(int i = 0; i < Math.abs(times); i++){
input = rotated(input, sign); input = rotated(input, sign);
} }