New system for Serpulo sector loss (WIP)

This commit is contained in:
Anuken
2025-09-07 14:14:24 -04:00
parent a20cfcf9ea
commit 8cb528264b
20 changed files with 176 additions and 98 deletions

View File

@@ -114,12 +114,35 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{
if(plans.size > 1){
int total = 0;
int size = plans.size;
BuildPlan plan;
while((!within((plan = buildPlan()).tile(), finalPlaceDst) || shouldSkip(plan, core)) && total < size){
float bestDst = Float.MAX_VALUE;
boolean foundAny = false;
int bestIndex = -1;
while(total < size){
var plan = buildPlan();
float dst = plan.dst2(this);
boolean within = dst <= finalPlaceDst*finalPlaceDst;
//if it's a valid plan within range, break out of the loop
if(within && !shouldSkip(plan, core)){
foundAny = true;
break;
}else if(within && dst < bestDst){ //it's still bad, but at least it's within build radius
bestIndex = total;
bestDst = dst;
}
plans.removeFirst();
plans.addLast(plan);
total++;
}
//all the plans were useless, and the current one can't be reached. skip to the closest one, if applicable
if(!foundAny && bestIndex > 0 && !within(buildPlan(), finalPlaceDst)){
//this is slow, but should be rare in practice
for(int i = 0; i < bestIndex; i++){
plans.addLast(plans.removeFirst());
}
}
}
BuildPlan current = buildPlan();
@@ -236,10 +259,10 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{
/** @return whether this plan should be skipped, in favor of the next one. */
boolean shouldSkip(BuildPlan plan, @Nullable Building core){
//plans that you have at least *started* are considered
if(state.rules.infiniteResources || team.rules().infiniteResources || plan.breaking || core == null || plan.isRotation(team) || (isBuilding() && !within(plans.last(), type.buildRange))) return false;
if(state.rules.infiniteResources || team.rules().infiniteResources || plan.breaking || core == null || plan.isRotation(team) || plan.isDerelictRepair()) return false;
return (plan.stuck && !core.items.has(plan.block.requirements)) || (Structs.contains(plan.block.requirements, i -> !core.items.has(i.item, Math.min(i.amount, 15)) && Mathf.round(i.amount * state.rules.buildCostMultiplier) > 0) && !plan.initialized);
return (plan.stuck && !core.items.has(plan.block.requirements)) ||
(Structs.contains(plan.block.requirements, i -> !core.items.has(i.item, Math.min(i.amount, 15)) && Mathf.round(i.amount * state.rules.buildCostMultiplier) > 0));
}
void removeBuild(int x, int y, boolean breaking){

View File

@@ -1333,6 +1333,12 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
}
}
/** Called when this block is derelict repaired. */
@CallSuper
public void onRepaired(){
placed();
}
public boolean isCommandable(){
return block.commandable;
}