|
|
|
|
@@ -28,7 +28,7 @@ abstract class BuilderComp implements Unitc{
|
|
|
|
|
|
|
|
|
|
@Import float x, y, rotation;
|
|
|
|
|
|
|
|
|
|
Queue<BuildRequest> requests = new Queue<>();
|
|
|
|
|
Queue<BuildPlan> plans = new Queue<>();
|
|
|
|
|
transient float buildSpeed = 1f;
|
|
|
|
|
transient boolean building = true;
|
|
|
|
|
|
|
|
|
|
@@ -44,32 +44,32 @@ abstract class BuilderComp implements Unitc{
|
|
|
|
|
|
|
|
|
|
float finalPlaceDst = state.rules.infiniteResources ? Float.MAX_VALUE : buildingRange;
|
|
|
|
|
|
|
|
|
|
Iterator<BuildRequest> it = requests.iterator();
|
|
|
|
|
Iterator<BuildPlan> it = plans.iterator();
|
|
|
|
|
while(it.hasNext()){
|
|
|
|
|
BuildRequest req = it.next();
|
|
|
|
|
BuildPlan req = it.next();
|
|
|
|
|
Tile tile = world.tile(req.x, req.y);
|
|
|
|
|
if(tile == null || (req.breaking && tile.block() == Blocks.air) || (!req.breaking && (tile.rotation() == req.rotation || !req.block.rotate) && tile.block() == req.block)){
|
|
|
|
|
it.remove();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Tilec core = closestCore();
|
|
|
|
|
Tilec core = core();
|
|
|
|
|
|
|
|
|
|
//nothing to build.
|
|
|
|
|
if(buildRequest() == null) return;
|
|
|
|
|
if(buildPlan() == null) return;
|
|
|
|
|
|
|
|
|
|
//find the next build request
|
|
|
|
|
if(requests.size > 1){
|
|
|
|
|
if(plans.size > 1){
|
|
|
|
|
int total = 0;
|
|
|
|
|
BuildRequest req;
|
|
|
|
|
while((dst((req = buildRequest()).tile()) > finalPlaceDst || shouldSkip(req, core)) && total < requests.size){
|
|
|
|
|
requests.removeFirst();
|
|
|
|
|
requests.addLast(req);
|
|
|
|
|
BuildPlan req;
|
|
|
|
|
while((dst((req = buildPlan()).tile()) > finalPlaceDst || shouldSkip(req, core)) && total < plans.size){
|
|
|
|
|
plans.removeFirst();
|
|
|
|
|
plans.addLast(req);
|
|
|
|
|
total++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BuildRequest current = buildRequest();
|
|
|
|
|
BuildPlan current = buildPlan();
|
|
|
|
|
|
|
|
|
|
if(dst(current.tile()) > finalPlaceDst) return;
|
|
|
|
|
|
|
|
|
|
@@ -91,11 +91,11 @@ abstract class BuilderComp implements Unitc{
|
|
|
|
|
}else if(!current.initialized && current.breaking && Build.validBreak(team(), current.x, current.y)){
|
|
|
|
|
Build.beginBreak(team(), current.x, current.y);
|
|
|
|
|
}else{
|
|
|
|
|
requests.removeFirst();
|
|
|
|
|
plans.removeFirst();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}else if(tile.team() != team()){
|
|
|
|
|
requests.removeFirst();
|
|
|
|
|
plans.removeFirst();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -130,8 +130,8 @@ abstract class BuilderComp implements Unitc{
|
|
|
|
|
/** Draw all current build requests. Does not draw the beam effect, only the positions. */
|
|
|
|
|
void drawBuildRequests(){
|
|
|
|
|
|
|
|
|
|
for(BuildRequest request : requests){
|
|
|
|
|
if(request.progress > 0.01f || (buildRequest() == request && request.initialized && (dst(request.x * tilesize, request.y * tilesize) <= buildingRange || state.isEditor()))) continue;
|
|
|
|
|
for(BuildPlan request : plans){
|
|
|
|
|
if(request.progress > 0.01f || (buildPlan() == request && request.initialized && (dst(request.x * tilesize, request.y * tilesize) <= buildingRange || state.isEditor()))) continue;
|
|
|
|
|
|
|
|
|
|
request.animScale = 1f;
|
|
|
|
|
if(request.breaking){
|
|
|
|
|
@@ -146,7 +146,7 @@ abstract class BuilderComp implements Unitc{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @return whether this request should be skipped, in favor of the next one. */
|
|
|
|
|
boolean shouldSkip(BuildRequest request, @Nullable Tilec core){
|
|
|
|
|
boolean shouldSkip(BuildPlan request, @Nullable Tilec core){
|
|
|
|
|
//requests that you have at least *started* are considered
|
|
|
|
|
if(state.rules.infiniteResources || request.breaking || core == null) return false;
|
|
|
|
|
//TODO these are bad criteria
|
|
|
|
|
@@ -155,53 +155,54 @@ abstract class BuilderComp implements Unitc{
|
|
|
|
|
|
|
|
|
|
void removeBuild(int x, int y, boolean breaking){
|
|
|
|
|
//remove matching request
|
|
|
|
|
int idx = requests.indexOf(req -> req.breaking == breaking && req.x == x && req.y == y);
|
|
|
|
|
int idx = plans.indexOf(req -> req.breaking == breaking && req.x == x && req.y == y);
|
|
|
|
|
if(idx != -1){
|
|
|
|
|
requests.removeIndex(idx);
|
|
|
|
|
plans.removeIndex(idx);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Return whether this builder's place queue contains items. */
|
|
|
|
|
boolean isBuilding(){
|
|
|
|
|
return requests.size != 0;
|
|
|
|
|
return plans.size != 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Clears the placement queue. */
|
|
|
|
|
void clearBuilding(){
|
|
|
|
|
requests.clear();
|
|
|
|
|
plans.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Add another build requests to the tail of the queue, if it doesn't exist there yet. */
|
|
|
|
|
void addBuild(BuildRequest place){
|
|
|
|
|
void addBuild(BuildPlan place){
|
|
|
|
|
addBuild(place, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Add another build requests to the queue, if it doesn't exist there yet. */
|
|
|
|
|
void addBuild(BuildRequest place, boolean tail){
|
|
|
|
|
BuildRequest replace = null;
|
|
|
|
|
for(BuildRequest request : requests){
|
|
|
|
|
void addBuild(BuildPlan place, boolean tail){
|
|
|
|
|
BuildPlan replace = null;
|
|
|
|
|
for(BuildPlan request : plans){
|
|
|
|
|
if(request.x == place.x && request.y == place.y){
|
|
|
|
|
replace = request;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(replace != null){
|
|
|
|
|
requests.remove(replace);
|
|
|
|
|
plans.remove(replace);
|
|
|
|
|
}
|
|
|
|
|
Tile tile = world.tile(place.x, place.y);
|
|
|
|
|
if(tile != null && tile.entity instanceof BuildEntity){
|
|
|
|
|
place.progress = tile.<BuildEntity>ent().progress;
|
|
|
|
|
}
|
|
|
|
|
if(tail){
|
|
|
|
|
requests.addLast(place);
|
|
|
|
|
plans.addLast(place);
|
|
|
|
|
}else{
|
|
|
|
|
requests.addFirst(place);
|
|
|
|
|
plans.addFirst(place);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Return the build requests currently active, or the one at the top of the queue.*/
|
|
|
|
|
@Nullable BuildRequest buildRequest(){
|
|
|
|
|
return requests.size == 0 ? null : requests.first();
|
|
|
|
|
/** Return the build request currently active, or the one at the top of the queue.*/
|
|
|
|
|
@Nullable
|
|
|
|
|
BuildPlan buildPlan(){
|
|
|
|
|
return plans.size == 0 ? null : plans.first();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@@ -211,15 +212,15 @@ abstract class BuilderComp implements Unitc{
|
|
|
|
|
//TODO check correctness
|
|
|
|
|
Draw.z(Layer.flyingUnit);
|
|
|
|
|
|
|
|
|
|
BuildRequest request = buildRequest();
|
|
|
|
|
Tile tile = world.tile(request.x, request.y);
|
|
|
|
|
BuildPlan plan = buildPlan();
|
|
|
|
|
Tile tile = world.tile(plan.x, plan.y);
|
|
|
|
|
|
|
|
|
|
if(dst(tile) > buildingRange && !state.isEditor()){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int size = request.breaking ? tile.block().size : request.block.size;
|
|
|
|
|
float tx = request.drawx(), ty = request.drawy();
|
|
|
|
|
int size = plan.breaking ? tile.block().size : plan.block.size;
|
|
|
|
|
float tx = plan.drawx(), ty = plan.drawy();
|
|
|
|
|
|
|
|
|
|
Lines.stroke(1f, Pal.accent);
|
|
|
|
|
float focusLen = 3.8f + Mathf.absin(Time.time(), 1.1f, 0.6f);
|
|
|
|
|
|