Consistent request->plan naming

This commit is contained in:
Anuken
2022-02-22 16:17:22 -05:00
parent 7df4478f85
commit 040c43fe54
11 changed files with 267 additions and 269 deletions

View File

@@ -76,7 +76,7 @@ public class BuilderAI extends AIController{
if(unit.buildPlan() != null){ if(unit.buildPlan() != null){
if(!alwaysFlee) retreatTimer = 0f; if(!alwaysFlee) retreatTimer = 0f;
//approach request if building //approach plan if building
BuildPlan req = unit.buildPlan(); BuildPlan req = unit.buildPlan();
//clear break plan if another player is breaking something //clear break plan if another player is breaking something
@@ -99,10 +99,10 @@ public class BuilderAI extends AIController{
Build.validPlace(req.block, unit.team(), req.x, req.y, req.rotation))); Build.validPlace(req.block, unit.team(), req.x, req.y, req.rotation)));
if(valid){ if(valid){
//move toward the request //move toward the plan
moveTo(req.tile(), buildingRange - 20f); moveTo(req.tile(), buildingRange - 20f);
}else{ }else{
//discard invalid request //discard invalid plan
unit.plans.removeFirst(); unit.plans.removeFirst();
lastPlan = null; lastPlan = null;
} }
@@ -122,7 +122,7 @@ public class BuilderAI extends AIController{
if(build instanceof ConstructBuild cons){ if(build instanceof ConstructBuild cons){
float dist = Math.min(cons.dst(unit) - buildingRange, 0); float dist = Math.min(cons.dst(unit) - buildingRange, 0);
//make sure you can reach the request in time //make sure you can reach the plan in time
if(dist / unit.speed() < cons.buildCost * 0.9f){ if(dist / unit.speed() < cons.buildCost * 0.9f){
following = u; following = u;
found = true; found = true;
@@ -135,7 +135,7 @@ public class BuilderAI extends AIController{
//TODO this is bad, rebuild time should not depend on AI here //TODO this is bad, rebuild time should not depend on AI here
float rebuildTime = (unit.team.rules().rtsAi ? 12f : 2f) * 60f; float rebuildTime = (unit.team.rules().rtsAi ? 12f : 2f) * 60f;
//find new request //find new plan
if(!unit.team.data().blocks.isEmpty() && following == null && timer.get(timerTarget3, rebuildTime)){ if(!unit.team.data().blocks.isEmpty() && following == null && timer.get(timerTarget3, rebuildTime)){
Queue<BlockPlan> blocks = unit.team.data().blocks; Queue<BlockPlan> blocks = unit.team.data().blocks;
BlockPlan block = blocks.first(); BlockPlan block = blocks.first();
@@ -145,7 +145,7 @@ public class BuilderAI extends AIController{
blocks.removeFirst(); blocks.removeFirst();
}else if(Build.validPlace(content.block(block.block), unit.team(), block.x, block.y, block.rotation) && (!alwaysFlee || !nearEnemy(block.x, block.y))){ //it's valid }else if(Build.validPlace(content.block(block.block), unit.team(), block.x, block.y, block.rotation) && (!alwaysFlee || !nearEnemy(block.x, block.y))){ //it's valid
lastPlan = block; lastPlan = block;
//add build request //add build plan
unit.addBuild(new BuildPlan(block.x, block.y, block.rotation, content.block(block.block), block.config)); unit.addBuild(new BuildPlan(block.x, block.y, block.rotation, content.block(block.block), block.config));
//shift build plan to tail so next unit builds something else //shift build plan to tail so next unit builds something else
blocks.addLast(blocks.removeFirst()); blocks.addLast(blocks.removeFirst());

View File

@@ -69,9 +69,9 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{
Iterator<BuildPlan> it = plans.iterator(); Iterator<BuildPlan> it = plans.iterator();
while(it.hasNext()){ while(it.hasNext()){
BuildPlan req = it.next(); BuildPlan plan = it.next();
Tile tile = world.tile(req.x, req.y); Tile tile = world.tile(plan.x, plan.y);
if(tile == null || (req.breaking && tile.block() == Blocks.air) || (!req.breaking && ((tile.build != null && tile.build.rotation == req.rotation) || !req.block.rotate) && tile.block() == req.block)){ if(tile == null || (plan.breaking && tile.block() == Blocks.air) || (!plan.breaking && ((tile.build != null && tile.build.rotation == plan.rotation) || !plan.block.rotate) && tile.block() == plan.block)){
it.remove(); it.remove();
} }
} }
@@ -81,13 +81,13 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{
//nothing to build. //nothing to build.
if(buildPlan() == null) continue; if(buildPlan() == null) continue;
//find the next build request //find the next build plan
if(plans.size > 1){ if(plans.size > 1){
int total = 0; int total = 0;
BuildPlan req; BuildPlan plan;
while((!within((req = buildPlan()).tile(), finalPlaceDst) || shouldSkip(req, core)) && total < plans.size){ while((!within((plan = buildPlan()).tile(), finalPlaceDst) || shouldSkip(plan, core)) && total < plans.size){
plans.removeFirst(); plans.removeFirst();
plans.addLast(req); plans.addLast(plan);
total++; total++;
} }
} }
@@ -167,36 +167,36 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{
Draw.reset(); Draw.reset();
} }
void drawPlan(BuildPlan request, float alpha){ void drawPlan(BuildPlan plan, float alpha){
request.animScale = 1f; plan.animScale = 1f;
if(request.breaking){ if(plan.breaking){
control.input.drawBreaking(request); control.input.drawBreaking(plan);
}else{ }else{
request.block.drawPlan(request, control.input.allRequests(), plan.block.drawPlan(plan, control.input.allPlans(),
Build.validPlace(request.block, team, request.x, request.y, request.rotation) || control.input.requestMatches(request), Build.validPlace(plan.block, team, plan.x, plan.y, plan.rotation) || control.input.planMatches(plan),
alpha); alpha);
} }
} }
void drawPlanTop(BuildPlan request, float alpha){ void drawPlanTop(BuildPlan plan, float alpha){
if(!request.breaking){ if(!plan.breaking){
Draw.reset(); Draw.reset();
Draw.mixcol(Color.white, 0.24f + Mathf.absin(Time.globalTime, 6f, 0.28f)); Draw.mixcol(Color.white, 0.24f + Mathf.absin(Time.globalTime, 6f, 0.28f));
Draw.alpha(alpha); Draw.alpha(alpha);
request.block.drawPlanConfigTop(request, plans); plan.block.drawPlanConfigTop(plan, plans);
} }
} }
/** @return whether this request should be skipped, in favor of the next one. */ /** @return whether this plan should be skipped, in favor of the next one. */
boolean shouldSkip(BuildPlan request, @Nullable Building core){ boolean shouldSkip(BuildPlan plan, @Nullable Building core){
//requests that you have at least *started* are considered //plans that you have at least *started* are considered
if(state.rules.infiniteResources || team.rules().infiniteResources || request.breaking || core == null || request.isRotation(team) || (isBuilding() && !within(plans.last(), type.buildRange))) return false; if(state.rules.infiniteResources || team.rules().infiniteResources || plan.breaking || core == null || plan.isRotation(team) || (isBuilding() && !within(plans.last(), type.buildRange))) return false;
return (request.stuck && !core.items.has(request.block.requirements)) || (Structs.contains(request.block.requirements, i -> !core.items.has(i.item, Math.min(i.amount, 15)) && Mathf.round(i.amount * state.rules.buildCostMultiplier) > 0) && !request.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) && !plan.initialized);
} }
void removeBuild(int x, int y, boolean breaking){ void removeBuild(int x, int y, boolean breaking){
//remove matching request //remove matching plan
int idx = plans.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){ if(idx != -1){
plans.removeIndex(idx); plans.removeIndex(idx);
@@ -213,19 +213,19 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{
plans.clear(); plans.clear();
} }
/** Add another build requests to the tail of the queue, if it doesn't exist there yet. */ /** Add another build plans to the tail of the queue, if it doesn't exist there yet. */
void addBuild(BuildPlan place){ void addBuild(BuildPlan place){
addBuild(place, true); addBuild(place, true);
} }
/** Add another build requests to the queue, if it doesn't exist there yet. */ /** Add another build plans to the queue, if it doesn't exist there yet. */
void addBuild(BuildPlan place, boolean tail){ void addBuild(BuildPlan place, boolean tail){
if(!canBuild()) return; if(!canBuild()) return;
BuildPlan replace = null; BuildPlan replace = null;
for(BuildPlan request : plans){ for(BuildPlan plan : plans){
if(request.x == place.x && request.y == place.y){ if(plan.x == place.x && plan.y == place.y){
replace = request; replace = plan;
break; break;
} }
} }
@@ -253,9 +253,8 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{
return isBuilding() && updateBuilding; return isBuilding() && updateBuilding;
} }
/** Return the build request currently active, or the one at the top of the queue.*/ /** @return the build plan currently active, or the one at the top of the queue.*/
@Nullable @Nullable BuildPlan buildPlan(){
BuildPlan buildPlan(){
return plans.size == 0 ? null : plans.first(); return plans.size == 0 ? null : plans.first();
} }

View File

@@ -10,13 +10,13 @@ import mindustry.world.*;
import static mindustry.Vars.*; import static mindustry.Vars.*;
/** Class for storing build requests. Can be either a place or remove request. */ /** Class for storing build plans. Can be either a place or remove plan. */
public class BuildPlan implements Position, QuadTreeObject{ public class BuildPlan implements Position, QuadTreeObject{
/** Position and rotation of this request. */ /** Position and rotation of this plan. */
public int x, y, rotation; public int x, y, rotation;
/** Block being placed. If null, this is a breaking request.*/ /** Block being placed. If null, this is a breaking plan.*/
public @Nullable Block block; public @Nullable Block block;
/** Whether this is a break request.*/ /** Whether this is a break plan.*/
public boolean breaking; public boolean breaking;
/** Config int. Not used unless hasConfig is true.*/ /** Config int. Not used unless hasConfig is true.*/
public Object config; public Object config;
@@ -25,13 +25,13 @@ public class BuildPlan implements Position, QuadTreeObject{
/** Last progress.*/ /** Last progress.*/
public float progress; public float progress;
/** Whether construction has started for this request, and other special variables.*/ /** Whether construction has started for this plan, and other special variables.*/
public boolean initialized, worldContext = true, stuck; public boolean initialized, worldContext = true, stuck;
/** Visual scale. Used only for rendering.*/ /** Visual scale. Used only for rendering.*/
public float animScale = 0f; public float animScale = 0f;
/** This creates a build request. */ /** This creates a build plan. */
public BuildPlan(int x, int y, int rotation, Block block){ public BuildPlan(int x, int y, int rotation, Block block){
this.x = x; this.x = x;
this.y = y; this.y = y;
@@ -40,7 +40,7 @@ public class BuildPlan implements Position, QuadTreeObject{
this.breaking = false; this.breaking = false;
} }
/** This creates a build request with a config. */ /** This creates a build plan with a config. */
public BuildPlan(int x, int y, int rotation, Block block, Object config){ public BuildPlan(int x, int y, int rotation, Block block, Object config){
this.x = x; this.x = x;
this.y = y; this.y = y;
@@ -50,7 +50,7 @@ public class BuildPlan implements Position, QuadTreeObject{
this.config = config; this.config = config;
} }
/** This creates a remove request. */ /** This creates a remove plan. */
public BuildPlan(int x, int y){ public BuildPlan(int x, int y){
this.x = x; this.x = x;
this.y = y; this.y = y;

View File

@@ -247,10 +247,10 @@ public class Schematics implements Loadable{
Seq<BuildPlan> plans = schematic.tiles.map(t -> new BuildPlan(t.x, t.y, t.rotation, t.block, t.config)); Seq<BuildPlan> plans = schematic.tiles.map(t -> new BuildPlan(t.x, t.y, t.rotation, t.block, t.config));
Draw.flush(); Draw.flush();
//scale each request to fit schematic //scale each plan to fit schematic
Draw.trans().scale(resolution / tilesize, resolution / tilesize).translate(tilesize*1.5f, tilesize*1.5f); Draw.trans().scale(resolution / tilesize, resolution / tilesize).translate(tilesize*1.5f, tilesize*1.5f);
//draw requests //draw plans
plans.each(req -> { plans.each(req -> {
req.animScale = 1f; req.animScale = 1f;
req.worldContext = false; req.worldContext = false;
@@ -273,8 +273,8 @@ public class Schematics implements Loadable{
return previews.get(schematic); return previews.get(schematic);
} }
/** Creates an array of build requests from a schematic's data, centered on the provided x+y coordinates. */ /** Creates an array of build plans from a schematic's data, centered on the provided x+y coordinates. */
public Seq<BuildPlan> toRequests(Schematic schem, int x, int y){ public Seq<BuildPlan> toPlans(Schematic schem, int x, int y){
return schem.tiles.map(t -> new BuildPlan(t.x + x - schem.width/2, t.y + y - schem.height/2, t.rotation, t.block, t.config).original(t.x, t.y, schem.width, schem.height)) return schem.tiles.map(t -> new BuildPlan(t.x + x - schem.width/2, t.y + y - schem.height/2, t.rotation, t.block, t.config).original(t.x, t.y, schem.width, schem.height))
.removeAll(s -> (!s.block.isVisible() && !(s.block instanceof CoreBlock)) || !s.block.unlockedNow()).sort(Structs.comparingInt(s -> -s.block.schematicPriority)); .removeAll(s -> (!s.block.isVisible() && !(s.block instanceof CoreBlock)) || !s.block.unlockedNow()).sort(Structs.comparingInt(s -> -s.block.schematicPriority));
} }
@@ -655,7 +655,7 @@ public class Schematics implements Loadable{
p.set(cx, cy); p.set(cx, cy);
}); });
//rotate actual request, centered on its multiblock position //rotate actual plan, centered on its multiblock position
float wx = (req.x - ox) * tilesize + req.block.offset, wy = (req.y - oy) * tilesize + req.block.offset; float wx = (req.x - ox) * tilesize + req.block.offset, wy = (req.y - oy) * tilesize + req.block.offset;
float x = wx; float x = wx;
if(direction >= 0){ if(direction >= 0){

View File

@@ -38,9 +38,9 @@ public class DesktopInput extends InputHandler{
public PlaceMode mode; public PlaceMode mode;
/** Animation scale for line. */ /** Animation scale for line. */
public float selectScale; public float selectScale;
/** Selected build request for movement. */ /** Selected build plan for movement. */
public @Nullable BuildPlan sreq; public @Nullable BuildPlan sreq;
/** Whether player is currently deleting removal requests. */ /** Whether player is currently deleting removal plans. */
public boolean deleting = false, shouldShoot = false, panning = false; public boolean deleting = false, shouldShoot = false, panning = false;
/** Mouse pan speed. */ /** Mouse pan speed. */
public float panScale = 0.005f, panSpeed = 4.5f, panBoostSpeed = 15f; public float panScale = 0.005f, panSpeed = 4.5f, panBoostSpeed = 15f;
@@ -50,7 +50,7 @@ public class DesktopInput extends InputHandler{
public Tile prevSelected; public Tile prevSelected;
boolean showHint(){ boolean showHint(){
return ui.hudfrag.shown && Core.settings.getBool("hints") && selectRequests.isEmpty() && return ui.hudfrag.shown && Core.settings.getBool("hints") && selectPlans.isEmpty() &&
(!isBuilding && !Core.settings.getBool("buildautopause") || player.unit().isBuilding() || !player.dead() && !player.unit().spawnedByCore()); (!isBuilding && !Core.settings.getBool("buildautopause") || player.unit().isBuilding() || !player.dead() && !player.unit().spawnedByCore());
} }
@@ -84,7 +84,7 @@ public class DesktopInput extends InputHandler{
//schematic controls //schematic controls
group.fill(t -> { group.fill(t -> {
t.visible(() -> ui.hudfrag.shown && lastSchematic != null && !selectRequests.isEmpty()); t.visible(() -> ui.hudfrag.shown && lastSchematic != null && !selectPlans.isEmpty());
t.bottom(); t.bottom();
t.table(Styles.black6, b -> { t.table(Styles.black6, b -> {
b.defaults().left(); b.defaults().left();
@@ -186,38 +186,38 @@ public class DesktopInput extends InputHandler{
drawArrow(sreq.block, sreq.x, sreq.y, sreq.rotation, valid); drawArrow(sreq.block, sreq.x, sreq.y, sreq.rotation, valid);
} }
sreq.block.drawPlan(sreq, allRequests(), valid); sreq.block.drawPlan(sreq, allPlans(), valid);
drawSelected(sreq.x, sreq.y, sreq.block, getRequest(sreq.x, sreq.y, sreq.block.size, sreq) != null ? Pal.remove : Pal.accent); drawSelected(sreq.x, sreq.y, sreq.block, getPlan(sreq.x, sreq.y, sreq.block.size, sreq) != null ? Pal.remove : Pal.accent);
} }
//draw hover request //draw hover plans
if(mode == none && !isPlacing()){ if(mode == none && !isPlacing()){
BuildPlan req = getRequest(cursorX, cursorY); BuildPlan req = getPlan(cursorX, cursorY);
if(req != null){ if(req != null){
drawSelected(req.x, req.y, req.breaking ? req.tile().block() : req.block, Pal.accent); drawSelected(req.x, req.y, req.breaking ? req.tile().block() : req.block, Pal.accent);
} }
} }
//draw schematic requests //draw schematic plans
selectRequests.each(req -> { selectPlans.each(req -> {
req.animScale = 1f; req.animScale = 1f;
drawPlan(req); drawPlan(req);
}); });
selectRequests.each(this::drawOverPlan); selectPlans.each(this::drawOverPlan);
if(player.isBuilder()){ if(player.isBuilder()){
//draw things that may be placed soon //draw things that may be placed soon
if(mode == placing && block != null){ if(mode == placing && block != null){
for(int i = 0; i < lineRequests.size; i++){ for(int i = 0; i < linePlans.size; i++){
BuildPlan req = lineRequests.get(i); BuildPlan req = linePlans.get(i);
if(i == lineRequests.size - 1 && req.block.rotate){ if(i == linePlans.size - 1 && req.block.rotate){
drawArrow(block, req.x, req.y, req.rotation); drawArrow(block, req.x, req.y, req.rotation);
} }
drawPlan(lineRequests.get(i)); drawPlan(linePlans.get(i));
} }
lineRequests.each(this::drawOverPlan); linePlans.each(this::drawOverPlan);
}else if(isPlacing()){ }else if(isPlacing()){
if(block.rotate && block.drawArrow){ if(block.rotate && block.drawArrow){
drawArrow(block, cursorX, cursorY, rotation); drawArrow(block, cursorX, cursorY, rotation);
@@ -229,10 +229,10 @@ public class DesktopInput extends InputHandler{
if(block.saveConfig){ if(block.saveConfig){
Draw.mixcol(!valid ? Pal.breakInvalid : Color.white, (!valid ? 0.4f : 0.24f) + Mathf.absin(Time.globalTime, 6f, 0.28f)); Draw.mixcol(!valid ? Pal.breakInvalid : Color.white, (!valid ? 0.4f : 0.24f) + Mathf.absin(Time.globalTime, 6f, 0.28f));
brequest.set(cursorX, cursorY, rotation, block); bplan.set(cursorX, cursorY, rotation, block);
brequest.config = block.lastConfig; bplan.config = block.lastConfig;
block.drawPlanConfig(brequest, allRequests()); block.drawPlanConfig(bplan, allPlans());
brequest.config = null; bplan.config = null;
Draw.reset(); Draw.reset();
} }
@@ -333,7 +333,7 @@ public class DesktopInput extends InputHandler{
//zoom camera //zoom camera
if((!Core.scene.hasScroll() || Core.input.keyDown(Binding.diagonal_placement)) && !ui.chatfrag.shown() && Math.abs(Core.input.axisTap(Binding.zoom)) > 0 if((!Core.scene.hasScroll() || Core.input.keyDown(Binding.diagonal_placement)) && !ui.chatfrag.shown() && Math.abs(Core.input.axisTap(Binding.zoom)) > 0
&& !Core.input.keyDown(Binding.rotateplaced) && (Core.input.keyDown(Binding.diagonal_placement) || ((!player.isBuilder() || !isPlacing() || !block.rotate) && selectRequests.isEmpty()))){ && !Core.input.keyDown(Binding.rotateplaced) && (Core.input.keyDown(Binding.diagonal_placement) || ((!player.isBuilder() || !isPlacing() || !block.rotate) && selectPlans.isEmpty()))){
renderer.scaleCamera(Core.input.axisTap(Binding.zoom)); renderer.scaleCamera(Core.input.axisTap(Binding.zoom));
} }
@@ -379,8 +379,8 @@ public class DesktopInput extends InputHandler{
if(isPlacing() && mode == placing){ if(isPlacing() && mode == placing){
updateLine(selectX, selectY); updateLine(selectX, selectY);
}else if(!selectRequests.isEmpty() && !ui.chatfrag.shown()){ }else if(!selectPlans.isEmpty() && !ui.chatfrag.shown()){
rotateRequests(selectRequests, Mathf.sign(Core.input.axisTap(Binding.rotate))); rotatePlans(selectPlans, Mathf.sign(Core.input.axisTap(Binding.rotate)));
} }
} }
@@ -391,7 +391,7 @@ public class DesktopInput extends InputHandler{
cursorType = cursor.build.getCursor(); cursorType = cursor.build.getCursor();
} }
if((isPlacing() && player.isBuilder()) || !selectRequests.isEmpty()){ if((isPlacing() && player.isBuilder()) || !selectPlans.isEmpty()){
cursorType = SystemCursor.hand; cursorType = SystemCursor.hand;
} }
@@ -403,7 +403,7 @@ public class DesktopInput extends InputHandler{
cursorType = ui.targetCursor; cursorType = ui.targetCursor;
} }
if(getRequest(cursor.x, cursor.y) != null && mode == none){ if(getPlan(cursor.x, cursor.y) != null && mode == none){
cursorType = SystemCursor.hand; cursorType = SystemCursor.hand;
} }
@@ -430,8 +430,8 @@ public class DesktopInput extends InputHandler{
schematicX = tileX(getMouseX()); schematicX = tileX(getMouseX());
schematicY = tileY(getMouseY()); schematicY = tileY(getMouseY());
selectRequests.clear(); selectPlans.clear();
selectRequests.addAll(schematics.toRequests(schem, schematicX, schematicY)); selectPlans.addAll(schematics.toPlans(schem, schematicX, schematicY));
mode = none; mode = none;
} }
@@ -477,10 +477,10 @@ public class DesktopInput extends InputHandler{
buildWasAutoPaused = true; buildWasAutoPaused = true;
} }
if(!selectRequests.isEmpty()){ if(!selectPlans.isEmpty()){
int shiftX = rawCursorX - schematicX, shiftY = rawCursorY - schematicY; int shiftX = rawCursorX - schematicX, shiftY = rawCursorY - schematicY;
selectRequests.each(s -> { selectPlans.each(s -> {
s.x += shiftX; s.x += shiftX;
s.y += shiftY; s.y += shiftY;
}); });
@@ -512,26 +512,26 @@ public class DesktopInput extends InputHandler{
if(Core.input.keyTap(Binding.clear_building) || isPlacing()){ if(Core.input.keyTap(Binding.clear_building) || isPlacing()){
lastSchematic = null; lastSchematic = null;
selectRequests.clear(); selectPlans.clear();
} }
if(Core.input.keyRelease(Binding.schematic_select) && !Core.scene.hasKeyboard() && selectX == -1 && selectY == -1 && schemX != -1 && schemY != -1){ if(Core.input.keyRelease(Binding.schematic_select) && !Core.scene.hasKeyboard() && selectX == -1 && selectY == -1 && schemX != -1 && schemY != -1){
lastSchematic = schematics.create(schemX, schemY, rawCursorX, rawCursorY); lastSchematic = schematics.create(schemX, schemY, rawCursorX, rawCursorY);
useSchematic(lastSchematic); useSchematic(lastSchematic);
if(selectRequests.isEmpty()){ if(selectPlans.isEmpty()){
lastSchematic = null; lastSchematic = null;
} }
schemX = -1; schemX = -1;
schemY = -1; schemY = -1;
} }
if(!selectRequests.isEmpty()){ if(!selectPlans.isEmpty()){
if(Core.input.keyTap(Binding.schematic_flip_x)){ if(Core.input.keyTap(Binding.schematic_flip_x)){
flipRequests(selectRequests, true); flipPlans(selectPlans, true);
} }
if(Core.input.keyTap(Binding.schematic_flip_y)){ if(Core.input.keyTap(Binding.schematic_flip_y)){
flipRequests(selectRequests, false); flipPlans(selectPlans, false);
} }
} }
@@ -544,7 +544,7 @@ public class DesktopInput extends InputHandler{
} }
if(block == null || mode != placing){ if(block == null || mode != placing){
lineRequests.clear(); linePlans.clear();
} }
if(Core.input.keyTap(Binding.pause_building)){ if(Core.input.keyTap(Binding.pause_building)){
@@ -581,12 +581,12 @@ public class DesktopInput extends InputHandler{
if(Core.input.keyTap(Binding.select) && !Core.scene.hasMouse()){ if(Core.input.keyTap(Binding.select) && !Core.scene.hasMouse()){
tappedOne = false; tappedOne = false;
BuildPlan req = getRequest(cursorX, cursorY); BuildPlan req = getPlan(cursorX, cursorY);
if(Core.input.keyDown(Binding.break_block)){ if(Core.input.keyDown(Binding.break_block)){
mode = none; mode = none;
}else if(!selectRequests.isEmpty()){ }else if(!selectPlans.isEmpty()){
flushRequests(selectRequests); flushPlans(selectPlans);
}else if(isPlacing()){ }else if(isPlacing()){
selectX = cursorX; selectX = cursorX;
selectY = cursorY; selectY = cursorY;
@@ -616,8 +616,8 @@ public class DesktopInput extends InputHandler{
}else if(Core.input.keyTap(Binding.deselect) && isPlacing()){ }else if(Core.input.keyTap(Binding.deselect) && isPlacing()){
block = null; block = null;
mode = none; mode = none;
}else if(Core.input.keyTap(Binding.deselect) && !selectRequests.isEmpty()){ }else if(Core.input.keyTap(Binding.deselect) && !selectPlans.isEmpty()){
selectRequests.clear(); selectPlans.clear();
lastSchematic = null; lastSchematic = null;
}else if(Core.input.keyTap(Binding.break_block) && !Core.scene.hasMouse() && player.isBuilder() && !commandMode){ }else if(Core.input.keyTap(Binding.break_block) && !Core.scene.hasMouse() && player.isBuilder() && !commandMode){
//is recalculated because setting the mode to breaking removes potential multiblock cursor offset //is recalculated because setting the mode to breaking removes potential multiblock cursor offset
@@ -630,7 +630,7 @@ public class DesktopInput extends InputHandler{
} }
if(Core.input.keyDown(Binding.select) && mode == none && !isPlacing() && deleting){ if(Core.input.keyDown(Binding.select) && mode == none && !isPlacing() && deleting){
BuildPlan req = getRequest(cursorX, cursorY); BuildPlan req = getPlan(cursorX, cursorY);
if(req != null && req.breaking){ if(req != null && req.breaking){
player.unit().plans().remove(req); player.unit().plans().remove(req);
} }
@@ -656,8 +656,8 @@ public class DesktopInput extends InputHandler{
if(Core.input.keyRelease(Binding.break_block) || Core.input.keyRelease(Binding.select)){ if(Core.input.keyRelease(Binding.break_block) || Core.input.keyRelease(Binding.select)){
if(mode == placing && block != null){ //touch up while placing, place everything in selection if(mode == placing && block != null){ //touch up while placing, place everything in selection
flushRequests(lineRequests); flushPlans(linePlans);
lineRequests.clear(); linePlans.clear();
Events.fire(new LineConfirmEvent()); Events.fire(new LineConfirmEvent());
}else if(mode == breaking){ //touch up while breaking, break everything in selection }else if(mode == breaking){ //touch up while breaking, break everything in selection
removeSelection(selectX, selectY, cursorX, cursorY, !Core.input.keyDown(Binding.schematic_select) ? maxLength : Vars.maxSchematicSize); removeSelection(selectX, selectY, cursorX, cursorY, !Core.input.keyDown(Binding.schematic_select) ? maxLength : Vars.maxSchematicSize);
@@ -672,7 +672,7 @@ public class DesktopInput extends InputHandler{
tryDropItems(selected == null ? null : selected.build, Core.input.mouseWorld().x, Core.input.mouseWorld().y); tryDropItems(selected == null ? null : selected.build, Core.input.mouseWorld().x, Core.input.mouseWorld().y);
if(sreq != null){ if(sreq != null){
if(getRequest(sreq.x, sreq.y, sreq.block.size, sreq) != null){ if(getPlan(sreq.x, sreq.y, sreq.block.size, sreq) != null){
player.unit().plans().remove(sreq, true); player.unit().plans().remove(sreq, true);
} }
sreq = null; sreq = null;
@@ -783,7 +783,7 @@ public class DesktopInput extends InputHandler{
mode = none; mode = none;
block = null; block = null;
sreq = null; sreq = null;
selectRequests.clear(); selectPlans.clear();
} }
} }

View File

@@ -74,9 +74,9 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
public GestureDetector detector; public GestureDetector detector;
public PlaceLine line = new PlaceLine(); public PlaceLine line = new PlaceLine();
public BuildPlan resultreq; public BuildPlan resultreq;
public BuildPlan brequest = new BuildPlan(); public BuildPlan bplan = new BuildPlan();
public Seq<BuildPlan> lineRequests = new Seq<>(); public Seq<BuildPlan> linePlans = new Seq<>();
public Seq<BuildPlan> selectRequests = new Seq<>(); public Seq<BuildPlan> selectPlans = new Seq<>();
//for RTS controls //for RTS controls
public Seq<Unit> selectedUnits = new Seq<>(); public Seq<Unit> selectedUnits = new Seq<>();
@@ -89,15 +89,15 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
private Seq<BuildPlan> plansOut = new Seq<>(BuildPlan.class); private Seq<BuildPlan> plansOut = new Seq<>(BuildPlan.class);
private QuadTree<BuildPlan> playerPlanTree = new QuadTree<>(new Rect()); private QuadTree<BuildPlan> playerPlanTree = new QuadTree<>(new Rect());
private final Eachable<BuildPlan> allRequests = cons -> { private final Eachable<BuildPlan> allPlans = cons -> {
player.unit().plans().each(cons); player.unit().plans().each(cons);
selectRequests.each(cons); selectPlans.each(cons);
lineRequests.each(cons); linePlans.each(cons);
}; };
private final Eachable<BuildPlan> allSelectLines = cons -> { private final Eachable<BuildPlan> allSelectLines = cons -> {
selectRequests.each(cons); selectPlans.each(cons);
lineRequests.each(cons); linePlans.each(cons);
}; };
public InputHandler(){ public InputHandler(){
@@ -554,12 +554,12 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
return inputLocks.contains(Boolp::get); return inputLocks.contains(Boolp::get);
} }
public Eachable<BuildPlan> allRequests(){ public Eachable<BuildPlan> allPlans(){
return allRequests; return allPlans;
} }
public boolean isUsingSchematic(){ public boolean isUsingSchematic(){
return !selectRequests.isEmpty(); return !selectPlans.isEmpty();
} }
public void update(){ public void update(){
@@ -692,11 +692,11 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
Drawf.selected(x, y, block, color); Drawf.selected(x, y, block, color);
} }
public void drawBreaking(BuildPlan request){ public void drawBreaking(BuildPlan plan){
if(request.breaking){ if(plan.breaking){
drawBreaking(request.x, request.y); drawBreaking(plan.x, plan.y);
}else{ }else{
drawSelected(request.x, request.y, request.block, Pal.remove); drawSelected(plan.x, plan.y, plan.block, Pal.remove);
} }
} }
@@ -716,9 +716,9 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
} }
} }
public boolean requestMatches(BuildPlan request){ public boolean planMatches(BuildPlan plan){
Tile tile = world.tile(request.x, request.y); Tile tile = world.tile(plan.x, plan.y);
return tile != null && tile.build instanceof ConstructBuild cons && cons.current == request.block; return tile != null && tile.build instanceof ConstructBuild cons && cons.current == plan.block;
} }
public void drawBreaking(int x, int y){ public void drawBreaking(int x, int y){
@@ -730,7 +730,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
} }
public void useSchematic(Schematic schem){ public void useSchematic(Schematic schem){
selectRequests.addAll(schematics.toRequests(schem, player.tileX(), player.tileY())); selectPlans.addAll(schematics.toPlans(schem, player.tileX(), player.tileY()));
} }
protected void showSchematicSave(){ protected void showSchematicSave(){
@@ -755,10 +755,10 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
}); });
} }
public void rotateRequests(Seq<BuildPlan> requests, int direction){ public void rotatePlans(Seq<BuildPlan> plans, int direction){
int ox = schemOriginX(), oy = schemOriginY(); int ox = schemOriginX(), oy = schemOriginY();
requests.each(req -> { plans.each(req -> {
if(req.breaking) return; if(req.breaking) return;
req.pointConfig(p -> { req.pointConfig(p -> {
@@ -775,7 +775,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
p.set(cx, cy); p.set(cx, cy);
}); });
//rotate actual request, centered on its multiblock position //rotate actual plan, centered on its multiblock position
float wx = (req.x - ox) * tilesize + req.block.offset, wy = (req.y - oy) * tilesize + req.block.offset; float wx = (req.x - ox) * tilesize + req.block.offset, wy = (req.y - oy) * tilesize + req.block.offset;
float x = wx; float x = wx;
if(direction >= 0){ if(direction >= 0){
@@ -791,10 +791,10 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
}); });
} }
public void flipRequests(Seq<BuildPlan> requests, boolean x){ public void flipPlans(Seq<BuildPlan> plans, boolean x){
int origin = (x ? schemOriginX() : schemOriginY()) * tilesize; int origin = (x ? schemOriginX() : schemOriginY()) * tilesize;
requests.each(req -> { plans.each(req -> {
if(req.breaking) return; if(req.breaking) return;
float value = -((x ? req.x : req.y) * tilesize - origin + req.block.offset) + origin; float value = -((x ? req.x : req.y) * tilesize - origin + req.block.offset) + origin;
@@ -830,13 +830,13 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
return rawTileY(); return rawTileY();
} }
/** Returns the selection request that overlaps this position, or null. */ /** @return the selection plan that overlaps this position, or null. */
protected BuildPlan getRequest(int x, int y){ protected @Nullable BuildPlan getPlan(int x, int y){
return getRequest(x, y, 1, null); return getPlan(x, y, 1, null);
} }
/** Returns the selection request that overlaps this position, or null. */ /** Returns the selection plan that overlaps this position, or null. */
protected BuildPlan getRequest(int x, int y, int size, BuildPlan skip){ protected @Nullable BuildPlan getPlan(int x, int y, int size, BuildPlan skip){
float offset = ((size + 1) % 2) * tilesize / 2f; float offset = ((size + 1) % 2) * tilesize / 2f;
r2.setSize(tilesize * size); r2.setSize(tilesize * size);
r2.setCenter(x * tilesize + offset, y * tilesize + offset); r2.setCenter(x * tilesize + offset, y * tilesize + offset);
@@ -863,7 +863,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
if(test.get(req)) return req; if(test.get(req)) return req;
} }
return selectRequests.find(test); return selectPlans.find(test);
} }
protected void drawBreakSelection(int x1, int y1, int x2, int y2, int maxLength){ protected void drawBreakSelection(int x1, int y1, int x2, int y2, int maxLength){
@@ -891,7 +891,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
} }
} }
for(BuildPlan req : selectRequests){ for(BuildPlan req : selectPlans){
if(req.breaking) continue; if(req.breaking) continue;
if(req.bounds(Tmp.r2).overlaps(Tmp.r1)){ if(req.bounds(Tmp.r2).overlaps(Tmp.r1)){
drawBreaking(req); drawBreaking(req);
@@ -928,22 +928,22 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
Lines.rect(result.x, result.y, result.x2 - result.x, result.y2 - result.y); Lines.rect(result.x, result.y, result.x2 - result.x, result.y2 - result.y);
} }
protected void flushSelectRequests(Seq<BuildPlan> requests){ protected void flushSelectPlans(Seq<BuildPlan> plans){
for(BuildPlan req : requests){ for(BuildPlan req : plans){
if(req.block != null && validPlace(req.x, req.y, req.block, req.rotation)){ if(req.block != null && validPlace(req.x, req.y, req.block, req.rotation)){
BuildPlan other = getRequest(req.x, req.y, req.block.size, null); BuildPlan other = getPlan(req.x, req.y, req.block.size, null);
if(other == null){ if(other == null){
selectRequests.add(req.copy()); selectPlans.add(req.copy());
}else if(!other.breaking && other.x == req.x && other.y == req.y && other.block.size == req.block.size){ }else if(!other.breaking && other.x == req.x && other.y == req.y && other.block.size == req.block.size){
selectRequests.remove(other); selectPlans.remove(other);
selectRequests.add(req.copy()); selectPlans.add(req.copy());
} }
} }
} }
} }
protected void flushRequests(Seq<BuildPlan> requests){ protected void flushPlans(Seq<BuildPlan> plans){
for(BuildPlan req : requests){ for(BuildPlan req : plans){
if(req.block != null && validPlace(req.x, req.y, req.block, req.rotation)){ if(req.block != null && validPlace(req.x, req.y, req.block, req.rotation)){
BuildPlan copy = req.copy(); BuildPlan copy = req.copy();
req.block.onNewPlan(copy); req.block.onNewPlan(copy);
@@ -952,25 +952,25 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
} }
} }
protected void drawOverPlan(BuildPlan request){ protected void drawOverPlan(BuildPlan plan){
boolean valid = validPlace(request.x, request.y, request.block, request.rotation); boolean valid = validPlace(plan.x, plan.y, plan.block, plan.rotation);
Draw.reset(); Draw.reset();
Draw.mixcol(!valid ? Pal.breakInvalid : Color.white, (!valid ? 0.4f : 0.24f) + Mathf.absin(Time.globalTime, 6f, 0.28f)); Draw.mixcol(!valid ? Pal.breakInvalid : Color.white, (!valid ? 0.4f : 0.24f) + Mathf.absin(Time.globalTime, 6f, 0.28f));
Draw.alpha(1f); Draw.alpha(1f);
request.block.drawPlanConfigTop(request, allSelectLines); plan.block.drawPlanConfigTop(plan, allSelectLines);
Draw.reset(); Draw.reset();
} }
protected void drawPlan(BuildPlan request){ protected void drawPlan(BuildPlan plan){
request.block.drawPlan(request, allRequests(), validPlace(request.x, request.y, request.block, request.rotation)); plan.block.drawPlan(plan, allPlans(), validPlace(plan.x, plan.y, plan.block, plan.rotation));
} }
/** Draws a placement icon for a specific block. */ /** Draws a placement icon for a specific block. */
protected void drawPlan(int x, int y, Block block, int rotation){ protected void drawPlan(int x, int y, Block block, int rotation){
brequest.set(x, y, rotation, block); bplan.set(x, y, rotation, block);
brequest.animScale = 1f; bplan.animScale = 1f;
block.drawPlan(brequest, allRequests(), validPlace(x, y, block, rotation)); block.drawPlan(bplan, allPlans(), validPlace(x, y, block, rotation));
} }
/** Remove everything from the queue in a selection. */ /** Remove everything from the queue in a selection. */
@@ -1002,13 +1002,13 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
if(!flush){ if(!flush){
tryBreakBlock(wx, wy); tryBreakBlock(wx, wy);
}else if(validBreak(tile.x, tile.y) && !selectRequests.contains(r -> r.tile() != null && r.tile() == tile)){ }else if(validBreak(tile.x, tile.y) && !selectPlans.contains(r -> r.tile() != null && r.tile() == tile)){
selectRequests.add(new BuildPlan(tile.x, tile.y)); selectPlans.add(new BuildPlan(tile.x, tile.y));
} }
} }
} }
//remove build requests //remove build plans
Tmp.r1.set(result.x * tilesize, result.y * tilesize, (result.x2 - result.x) * tilesize, (result.y2 - result.y) * tilesize); Tmp.r1.set(result.x * tilesize, result.y * tilesize, (result.x2 - result.x) * tilesize, (result.y2 - result.y) * tilesize);
Iterator<BuildPlan> it = player.unit().plans().iterator(); Iterator<BuildPlan> it = player.unit().plans().iterator();
@@ -1019,7 +1019,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
} }
} }
it = selectRequests.iterator(); it = selectPlans.iterator();
while(it.hasNext()){ while(it.hasNext()){
BuildPlan req = it.next(); BuildPlan req = it.next();
if(!req.breaking && req.bounds(Tmp.r2).overlaps(Tmp.r1)){ if(!req.breaking && req.bounds(Tmp.r2).overlaps(Tmp.r1)){
@@ -1048,23 +1048,23 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
} }
protected void updateLine(int x1, int y1, int x2, int y2){ protected void updateLine(int x1, int y1, int x2, int y2){
lineRequests.clear(); linePlans.clear();
iterateLine(x1, y1, x2, y2, l -> { iterateLine(x1, y1, x2, y2, l -> {
rotation = l.rotation; rotation = l.rotation;
BuildPlan req = new BuildPlan(l.x, l.y, l.rotation, block, block.nextConfig()); BuildPlan req = new BuildPlan(l.x, l.y, l.rotation, block, block.nextConfig());
req.animScale = 1f; req.animScale = 1f;
lineRequests.add(req); linePlans.add(req);
}); });
if(Core.settings.getBool("blockreplace")){ if(Core.settings.getBool("blockreplace")){
lineRequests.each(req -> { linePlans.each(req -> {
Block replace = req.block.getReplacement(req, lineRequests); Block replace = req.block.getReplacement(req, linePlans);
if(replace.unlockedNow()){ if(replace.unlockedNow()){
req.block = replace; req.block = replace;
} }
}); });
block.handlePlacementLine(lineRequests); block.handlePlacementLine(linePlans);
} }
} }

View File

@@ -47,10 +47,10 @@ public class MobileInput extends InputHandler implements GestureListener{
/** Animation data for crosshair. */ /** Animation data for crosshair. */
public float crosshairScale; public float crosshairScale;
public Teamc lastTarget; public Teamc lastTarget;
/** Used for shifting build requests. */ /** Used for shifting build plans. */
public float shiftDeltaX, shiftDeltaY; public float shiftDeltaX, shiftDeltaY;
/** Place requests to be removed. */ /** Place plans to be removed. */
public Seq<BuildPlan> removals = new Seq<>(); public Seq<BuildPlan> removals = new Seq<>();
/** Whether the player is currently shifting all placed tiles. */ /** Whether the player is currently shifting all placed tiles. */
public boolean selecting; public boolean selecting;
@@ -60,7 +60,7 @@ public class MobileInput extends InputHandler implements GestureListener{
public PlaceMode mode = none; public PlaceMode mode = none;
/** Whether no recipe was available when switching to break mode. */ /** Whether no recipe was available when switching to break mode. */
public @Nullable Block lastBlock; public @Nullable Block lastBlock;
/** Last placed request. Used for drawing block overlay. */ /** Last placed plan. Used for drawing block overlay. */
public @Nullable BuildPlan lastPlaced; public @Nullable BuildPlan lastPlaced;
/** Down tracking for panning. */ /** Down tracking for panning. */
public boolean down = false; public boolean down = false;
@@ -103,17 +103,17 @@ public class MobileInput extends InputHandler implements GestureListener{
} }
} }
/** Returns whether this tile is in the list of requests, or at least colliding with one. */ /** Returns whether this tile is in the list of plans, or at least colliding with one. */
boolean hasRequest(Tile tile){ boolean hasPlan(Tile tile){
return getRequest(tile) != null; return getPlan(tile) != null;
} }
/** Returns whether this block overlaps any selection requests. */ /** Returns whether this block overlaps any selection plans. */
boolean checkOverlapPlacement(int x, int y, Block block){ boolean checkOverlapPlacement(int x, int y, Block block){
r2.setSize(block.size * tilesize); r2.setSize(block.size * tilesize);
r2.setCenter(x * tilesize + block.offset, y * tilesize + block.offset); r2.setCenter(x * tilesize + block.offset, y * tilesize + block.offset);
for(BuildPlan req : selectRequests){ for(BuildPlan req : selectPlans){
Tile other = req.tile(); Tile other = req.tile();
if(other == null || req.breaking) continue; if(other == null || req.breaking) continue;
@@ -141,12 +141,12 @@ public class MobileInput extends InputHandler implements GestureListener{
return false; return false;
} }
/** Returns the selection request that overlaps this tile, or null. */ /** Returns the selection plan that overlaps this tile, or null. */
BuildPlan getRequest(Tile tile){ BuildPlan getPlan(Tile tile){
r2.setSize(tilesize); r2.setSize(tilesize);
r2.setCenter(tile.worldx(), tile.worldy()); r2.setCenter(tile.worldx(), tile.worldy());
for(BuildPlan req : selectRequests){ for(BuildPlan req : selectPlans){
Tile other = req.tile(); Tile other = req.tile();
if(other == null) continue; if(other == null) continue;
@@ -165,10 +165,10 @@ public class MobileInput extends InputHandler implements GestureListener{
return null; return null;
} }
void removeRequest(BuildPlan request){ void removePlan(BuildPlan plan){
selectRequests.remove(request, true); selectPlans.remove(plan, true);
if(!request.breaking){ if(!plan.breaking){
removals.add(request); removals.add(plan);
} }
} }
@@ -220,48 +220,48 @@ public class MobileInput extends InputHandler implements GestureListener{
//confirm button //confirm button
table.button(Icon.ok, Styles.clearPartiali, () -> { table.button(Icon.ok, Styles.clearPartiali, () -> {
for(BuildPlan request : selectRequests){ for(BuildPlan plan : selectPlans){
Tile tile = request.tile(); Tile tile = plan.tile();
//actually place/break all selected blocks //actually place/break all selected blocks
if(tile != null){ if(tile != null){
if(!request.breaking){ if(!plan.breaking){
if(validPlace(request.x, request.y, request.block, request.rotation)){ if(validPlace(plan.x, plan.y, plan.block, plan.rotation)){
BuildPlan other = getRequest(request.x, request.y, request.block.size, null); BuildPlan other = getPlan(plan.x, plan.y, plan.block.size, null);
BuildPlan copy = request.copy(); BuildPlan copy = plan.copy();
if(other == null){ if(other == null){
player.unit().addBuild(copy); player.unit().addBuild(copy);
}else if(!other.breaking && other.x == request.x && other.y == request.y && other.block.size == request.block.size){ }else if(!other.breaking && other.x == plan.x && other.y == plan.y && other.block.size == plan.block.size){
player.unit().plans().remove(other); player.unit().plans().remove(other);
player.unit().addBuild(copy); player.unit().addBuild(copy);
} }
} }
rotation = request.rotation; rotation = plan.rotation;
}else{ }else{
tryBreakBlock(tile.x, tile.y); tryBreakBlock(tile.x, tile.y);
} }
} }
} }
//move all current requests to removal array so they fade out //move all current plans to removal array so they fade out
removals.addAll(selectRequests.select(r -> !r.breaking)); removals.addAll(selectPlans.select(r -> !r.breaking));
selectRequests.clear(); selectPlans.clear();
selecting = false; selecting = false;
}).visible(() -> !selectRequests.isEmpty()).name("confirmplace"); }).visible(() -> !selectPlans.isEmpty()).name("confirmplace");
} }
@Override @Override
public void buildUI(Group group){ public void buildUI(Group group){
Boolp schem = () -> lastSchematic != null && !selectRequests.isEmpty(); Boolp schem = () -> lastSchematic != null && !selectPlans.isEmpty();
group.fill(t -> { group.fill(t -> {
t.visible(() -> (player.unit().isBuilding() || block != null || mode == breaking || !selectRequests.isEmpty()) && !schem.get()); t.visible(() -> (player.unit().isBuilding() || block != null || mode == breaking || !selectPlans.isEmpty()) && !schem.get());
t.bottom().left(); t.bottom().left();
t.button("@cancel", Icon.cancel, () -> { t.button("@cancel", Icon.cancel, () -> {
player.unit().clearBuilding(); player.unit().clearBuilding();
selectRequests.clear(); selectPlans.clear();
mode = none; mode = none;
block = null; block = null;
}).width(155f).height(50f).margin(12f); }).width(155f).height(50f).margin(12f);
@@ -277,14 +277,14 @@ public class MobileInput extends InputHandler implements GestureListener{
b.button(Icon.save, style, this::showSchematicSave).disabled(f -> lastSchematic == null || lastSchematic.file != null); b.button(Icon.save, style, this::showSchematicSave).disabled(f -> lastSchematic == null || lastSchematic.file != null);
b.button(Icon.cancel, style, () -> { b.button(Icon.cancel, style, () -> {
selectRequests.clear(); selectPlans.clear();
lastSchematic = null; lastSchematic = null;
}); });
b.row(); b.row();
b.button(Icon.flipX, style, () -> flipRequests(selectRequests, true)); b.button(Icon.flipX, style, () -> flipPlans(selectPlans, true));
b.button(Icon.flipY, style, () -> flipRequests(selectRequests, false)); b.button(Icon.flipY, style, () -> flipPlans(selectPlans, false));
b.row(); b.row();
b.button(Icon.rotate, style, () -> rotateRequests(selectRequests, 1)); b.button(Icon.rotate, style, () -> rotatePlans(selectPlans, 1));
}).margin(4f); }).margin(4f);
}); });
@@ -294,18 +294,18 @@ public class MobileInput extends InputHandler implements GestureListener{
public void drawBottom(){ public void drawBottom(){
Lines.stroke(1f); Lines.stroke(1f);
//draw requests about to be removed //draw plans about to be removed
for(BuildPlan request : removals){ for(BuildPlan plan : removals){
Tile tile = request.tile(); Tile tile = plan.tile();
if(tile == null) continue; if(tile == null) continue;
request.animScale = Mathf.lerpDelta(request.animScale, 0f, 0.2f); plan.animScale = Mathf.lerpDelta(plan.animScale, 0f, 0.2f);
if(request.breaking){ if(plan.breaking){
drawSelected(request.x, request.y, tile.block(), Pal.remove); drawSelected(plan.x, plan.y, tile.block(), Pal.remove);
}else{ }else{
request.block.drawPlan(request, allRequests(), true); plan.block.drawPlan(plan, allPlans(), true);
} }
} }
@@ -319,15 +319,15 @@ public class MobileInput extends InputHandler implements GestureListener{
if(mode == placing && block != null){ if(mode == placing && block != null){
//draw placing //draw placing
for(int i = 0; i < lineRequests.size; i++){ for(int i = 0; i < linePlans.size; i++){
BuildPlan request = lineRequests.get(i); BuildPlan plan = linePlans.get(i);
if(i == lineRequests.size - 1 && request.block.rotate){ if(i == linePlans.size - 1 && plan.block.rotate){
drawArrow(block, request.x, request.y, request.rotation); drawArrow(block, plan.x, plan.y, plan.rotation);
} }
request.block.drawPlan(request, allRequests(), validPlace(request.x, request.y, request.block, request.rotation) && getRequest(request.x, request.y, request.block.size, null) == null); plan.block.drawPlan(plan, allPlans(), validPlace(plan.x, plan.y, plan.block, plan.rotation) && getPlan(plan.x, plan.y, plan.block.size, null) == null);
drawSelected(request.x, request.y, request.block, Pal.accent); drawSelected(plan.x, plan.y, plan.block, Pal.accent);
} }
lineRequests.each(this::drawOverPlan); linePlans.each(this::drawOverPlan);
}else if(mode == breaking){ }else if(mode == breaking){
drawBreakSelection(lineStartX, lineStartY, tileX, tileY); drawBreakSelection(lineStartX, lineStartY, tileX, tileY);
} }
@@ -346,39 +346,39 @@ public class MobileInput extends InputHandler implements GestureListener{
@Override @Override
public void drawOverSelect(){ public void drawOverSelect(){
//draw list of requests //draw list of plans
for(BuildPlan request : selectRequests){ for(BuildPlan plan : selectPlans){
Tile tile = request.tile(); Tile tile = plan.tile();
if(tile == null) continue; if(tile == null) continue;
if((!request.breaking && validPlace(tile.x, tile.y, request.block, request.rotation)) if((!plan.breaking && validPlace(tile.x, tile.y, plan.block, plan.rotation))
|| (request.breaking && validBreak(tile.x, tile.y))){ || (plan.breaking && validBreak(tile.x, tile.y))){
request.animScale = Mathf.lerpDelta(request.animScale, 1f, 0.2f); plan.animScale = Mathf.lerpDelta(plan.animScale, 1f, 0.2f);
}else{ }else{
request.animScale = Mathf.lerpDelta(request.animScale, 0.6f, 0.1f); plan.animScale = Mathf.lerpDelta(plan.animScale, 0.6f, 0.1f);
} }
Tmp.c1.set(Draw.getMixColor()); Tmp.c1.set(Draw.getMixColor());
if(!request.breaking && request == lastPlaced && request.block != null){ if(!plan.breaking && plan == lastPlaced && plan.block != null){
Draw.mixcol(); Draw.mixcol();
if(request.block.rotate) drawArrow(request.block, tile.x, tile.y, request.rotation); if(plan.block.rotate) drawArrow(plan.block, tile.x, tile.y, plan.rotation);
} }
Draw.reset(); Draw.reset();
drawPlan(request); drawPlan(plan);
if(!request.breaking){ if(!plan.breaking){
drawOverPlan(request); drawOverPlan(plan);
} }
//draw last placed request //draw last placed plan
if(!request.breaking && request == lastPlaced && request.block != null && request.block.drawArrow){ if(!plan.breaking && plan == lastPlaced && plan.block != null && plan.block.drawArrow){
boolean valid = validPlace(tile.x, tile.y, request.block, rotation); boolean valid = validPlace(tile.x, tile.y, plan.block, rotation);
Draw.mixcol(); Draw.mixcol();
request.block.drawPlace(tile.x, tile.y, rotation, valid); plan.block.drawPlace(tile.x, tile.y, rotation, valid);
drawOverlapCheck(request.block, tile.x, tile.y, valid); drawOverlapCheck(plan.block, tile.x, tile.y, valid);
} }
} }
@@ -399,15 +399,15 @@ public class MobileInput extends InputHandler implements GestureListener{
} }
@Override @Override
protected void drawPlan(BuildPlan request){ protected void drawPlan(BuildPlan plan){
if(request.tile() == null) return; if(plan.tile() == null) return;
brequest.animScale = request.animScale = Mathf.lerpDelta(request.animScale, 1f, 0.1f); bplan.animScale = plan.animScale = Mathf.lerpDelta(plan.animScale, 1f, 0.1f);
if(request.breaking){ if(plan.breaking){
drawSelected(request.x, request.y, request.tile().block(), Pal.remove); drawSelected(plan.x, plan.y, plan.tile().block(), Pal.remove);
}else{ }else{
request.block.drawPlan(request, allRequests(), validPlace(request.x, request.y, request.block, request.rotation)); plan.block.drawPlan(plan, allPlans(), validPlace(plan.x, plan.y, plan.block, plan.rotation));
drawSelected(request.x, request.y, request.block, Pal.accent); drawSelected(plan.x, plan.y, plan.block, Pal.accent);
} }
} }
@@ -417,15 +417,15 @@ public class MobileInput extends InputHandler implements GestureListener{
@Override @Override
protected int schemOriginX(){ protected int schemOriginX(){
Tmp.v1.setZero(); Tmp.v1.setZero();
selectRequests.each(r -> Tmp.v1.add(r.drawx(), r.drawy())); selectPlans.each(r -> Tmp.v1.add(r.drawx(), r.drawy()));
return World.toTile(Tmp.v1.scl(1f / selectRequests.size).x); return World.toTile(Tmp.v1.scl(1f / selectPlans.size).x);
} }
@Override @Override
protected int schemOriginY(){ protected int schemOriginY(){
Tmp.v1.setZero(); Tmp.v1.setZero();
selectRequests.each(r -> Tmp.v1.add(r.drawx(), r.drawy())); selectPlans.each(r -> Tmp.v1.add(r.drawx(), r.drawy()));
return World.toTile(Tmp.v1.scl(1f / selectRequests.size).y); return World.toTile(Tmp.v1.scl(1f / selectPlans.size).y);
} }
@Override @Override
@@ -440,8 +440,8 @@ public class MobileInput extends InputHandler implements GestureListener{
@Override @Override
public void useSchematic(Schematic schem){ public void useSchematic(Schematic schem){
selectRequests.clear(); selectPlans.clear();
selectRequests.addAll(schematics.toRequests(schem, World.toTile(Core.camera.position.x), World.toTile(Core.camera.position.y))); selectPlans.addAll(schematics.toPlans(schem, World.toTile(Core.camera.position.x), World.toTile(Core.camera.position.y)));
lastSchematic = schem; lastSchematic = schem;
} }
@@ -461,8 +461,8 @@ public class MobileInput extends InputHandler implements GestureListener{
//ignore off-screen taps //ignore off-screen taps
if(cursor == null || Core.scene.hasMouse(screenX, screenY)) return false; if(cursor == null || Core.scene.hasMouse(screenX, screenY)) return false;
//only begin selecting if the tapped block is a request //only begin selecting if the tapped block is a plan
selecting = hasRequest(cursor); selecting = hasPlan(cursor);
//call tap events //call tap events
if(pointer == 0 && !selecting){ if(pointer == 0 && !selecting){
@@ -501,7 +501,7 @@ public class MobileInput extends InputHandler implements GestureListener{
int tileY = tileY(screenY); int tileY = tileY(screenY);
if(mode == placing && isPlacing()){ if(mode == placing && isPlacing()){
flushSelectRequests(lineRequests); flushSelectPlans(linePlans);
Events.fire(new LineConfirmEvent()); Events.fire(new LineConfirmEvent());
}else if(mode == breaking){ }else if(mode == breaking){
removeSelection(lineStartX, lineStartY, tileX, tileY, true); removeSelection(lineStartX, lineStartY, tileX, tileY, true);
@@ -509,10 +509,10 @@ public class MobileInput extends InputHandler implements GestureListener{
lineMode = false; lineMode = false;
}else if(mode == schematicSelect){ }else if(mode == schematicSelect){
selectRequests.clear(); selectPlans.clear();
lastSchematic = schematics.create(lineStartX, lineStartY, lastLineX, lastLineY); lastSchematic = schematics.create(lineStartX, lineStartY, lastLineX, lastLineY);
useSchematic(lastSchematic); useSchematic(lastSchematic);
if(selectRequests.isEmpty()){ if(selectPlans.isEmpty()){
lastSchematic = null; lastSchematic = null;
} }
schematicMode = false; schematicMode = false;
@@ -566,7 +566,7 @@ public class MobileInput extends InputHandler implements GestureListener{
//ignore off-screen taps //ignore off-screen taps
if(cursor == null) return false; if(cursor == null) return false;
//remove request if it's there //remove plan if it's there
//long pressing enables line mode otherwise //long pressing enables line mode otherwise
lineStartX = cursor.x; lineStartX = cursor.x;
lineStartY = cursor.y; lineStartY = cursor.y;
@@ -605,16 +605,16 @@ public class MobileInput extends InputHandler implements GestureListener{
checkTargets(worldx, worldy); checkTargets(worldx, worldy);
} }
//remove if request present //remove if plan present
if(hasRequest(cursor)){ if(hasPlan(cursor)){
removeRequest(getRequest(cursor)); removePlan(getPlan(cursor));
}else if(mode == placing && isPlacing() && validPlace(cursor.x, cursor.y, block, rotation) && !checkOverlapPlacement(cursor.x, cursor.y, block)){ }else if(mode == placing && isPlacing() && validPlace(cursor.x, cursor.y, block, rotation) && !checkOverlapPlacement(cursor.x, cursor.y, block)){
//add to selection queue if it's a valid place position //add to selection queue if it's a valid place position
selectRequests.add(lastPlaced = new BuildPlan(cursor.x, cursor.y, rotation, block, block.nextConfig())); selectPlans.add(lastPlaced = new BuildPlan(cursor.x, cursor.y, rotation, block, block.nextConfig()));
block.onNewPlan(lastPlaced); block.onNewPlan(lastPlaced);
}else if(mode == breaking && validBreak(linked.x,linked.y) && !hasRequest(linked)){ }else if(mode == breaking && validBreak(linked.x,linked.y) && !hasPlan(linked)){
//add to selection queue if it's a valid BREAK position //add to selection queue if it's a valid BREAK position
selectRequests.add(new BuildPlan(linked.x, linked.y)); selectPlans.add(new BuildPlan(linked.x, linked.y));
}else{ }else{
//control units //control units
if(count == 2){ if(count == 2){
@@ -650,7 +650,7 @@ public class MobileInput extends InputHandler implements GestureListener{
super.updateState(); super.updateState();
if(state.isMenu()){ if(state.isMenu()){
selectRequests.clear(); selectPlans.clear();
removals.clear(); removals.clear();
mode = none; mode = none;
manualShooting = false; manualShooting = false;
@@ -671,7 +671,7 @@ public class MobileInput extends InputHandler implements GestureListener{
} }
//zoom camera //zoom camera
if(!locked && Math.abs(Core.input.axisTap(Binding.zoom)) > 0 && !Core.input.keyDown(Binding.rotateplaced) && (Core.input.keyDown(Binding.diagonal_placement) || ((!player.isBuilder() || !isPlacing() || !block.rotate) && selectRequests.isEmpty()))){ if(!locked && Math.abs(Core.input.axisTap(Binding.zoom)) > 0 && !Core.input.keyDown(Binding.rotateplaced) && (Core.input.keyDown(Binding.diagonal_placement) || ((!player.isBuilder() || !isPlacing() || !block.rotate) && selectPlans.isEmpty()))){
renderer.scaleCamera(Core.input.axisTap(Binding.zoom)); renderer.scaleCamera(Core.input.axisTap(Binding.zoom));
} }
@@ -751,15 +751,14 @@ public class MobileInput extends InputHandler implements GestureListener{
updateLine(lineStartX, lineStartY, lx, ly); updateLine(lineStartX, lineStartY, lx, ly);
} }
}else{ }else{
lineRequests.clear(); linePlans.clear();
lineScale = 0f; lineScale = 0f;
} }
//remove place requests that have disappeared //remove place plans that have disappeared
for(int i = removals.size - 1; i >= 0; i--){ for(int i = removals.size - 1; i >= 0; i--){
BuildPlan request = removals.get(i);
if(request.animScale <= 0.0001f){ if(removals.get(i).animScale <= 0.0001f){
removals.remove(i); removals.remove(i);
i--; i--;
} }
@@ -815,7 +814,7 @@ public class MobileInput extends InputHandler implements GestureListener{
//do not pan with manual shooting enabled //do not pan with manual shooting enabled
if(!down || manualShooting) return false; if(!down || manualShooting) return false;
if(selecting){ //pan all requests if(selecting){ //pan all plans
shiftDeltaX += deltaX; shiftDeltaX += deltaX;
shiftDeltaY += deltaY; shiftDeltaY += deltaY;
@@ -823,8 +822,8 @@ public class MobileInput extends InputHandler implements GestureListener{
int shiftedY = (int)(shiftDeltaY / tilesize); int shiftedY = (int)(shiftDeltaY / tilesize);
if(Math.abs(shiftedX) > 0 || Math.abs(shiftedY) > 0){ if(Math.abs(shiftedX) > 0 || Math.abs(shiftedY) > 0){
for(BuildPlan req : selectRequests){ for(BuildPlan req : selectPlans){
if(req.breaking) continue; //don't shift removal requests if(req.breaking) continue; //don't shift removal plans
req.x += shiftedX; req.x += shiftedX;
req.y += shiftedY; req.y += shiftedY;
} }

View File

@@ -313,11 +313,11 @@ public class TypeIO{
/** @return the maximum acceptable amount of plans to send over the network */ /** @return the maximum acceptable amount of plans to send over the network */
public static int getMaxPlans(Queue<BuildPlan> plans){ public static int getMaxPlans(Queue<BuildPlan> plans){
//limit to 10 to prevent buffer overflows //limit to 10 to prevent buffer overflows
int usedRequests = Math.min(plans.size, 10); int used = Math.min(plans.size, 10);
int totalLength = 0; int totalLength = 0;
//prevent buffer overflow by checking config length //prevent buffer overflow by checking config length
for(int i = 0; i < usedRequests; i++){ for(int i = 0; i < used; i++){
BuildPlan plan = plans.get(i); BuildPlan plan = plans.get(i);
if(plan.config instanceof byte[] b){ if(plan.config instanceof byte[] b){
totalLength += b.length; totalLength += b.length;
@@ -328,12 +328,12 @@ public class TypeIO{
} }
if(totalLength > 500){ if(totalLength > 500){
usedRequests = i + 1; used = i + 1;
break; break;
} }
} }
return usedRequests; return used;
} }
//on the network, plans must be capped by size //on the network, plans must be capped by size
@@ -367,7 +367,7 @@ public class TypeIO{
} }
public static BuildPlan readPlan(Reads read){ public static BuildPlan readPlan(Reads read){
BuildPlan currentRequest; BuildPlan current;
byte type = read.b(); byte type = read.b();
int position = read.i(); int position = read.i();
@@ -377,20 +377,20 @@ public class TypeIO{
} }
if(type == 1){ //remove if(type == 1){ //remove
currentRequest = new BuildPlan(Point2.x(position), Point2.y(position)); current = new BuildPlan(Point2.x(position), Point2.y(position));
}else{ //place }else{ //place
short block = read.s(); short block = read.s();
byte rotation = read.b(); byte rotation = read.b();
boolean hasConfig = read.b() == 1; boolean hasConfig = read.b() == 1;
Object config = readObject(read); Object config = readObject(read);
currentRequest = new BuildPlan(Point2.x(position), Point2.y(position), rotation, content.block(block)); current = new BuildPlan(Point2.x(position), Point2.y(position), rotation, content.block(block));
//should always happen, but is kept for legacy reasons just in case //should always happen, but is kept for legacy reasons just in case
if(hasConfig){ if(hasConfig){
currentRequest.config = config; current.config = config;
} }
} }
return currentRequest; return current;
} }
public static void writePlans(Writes write, BuildPlan[] plans){ public static void writePlans(Writes write, BuildPlan[] plans){
@@ -399,8 +399,8 @@ public class TypeIO{
return; return;
} }
write.s((short)plans.length); write.s((short)plans.length);
for(BuildPlan request : plans){ for(BuildPlan plan : plans){
writePlan(write, request); writePlan(write, plan);
} }
} }
@@ -412,9 +412,9 @@ public class TypeIO{
BuildPlan[] reqs = new BuildPlan[reqamount]; BuildPlan[] reqs = new BuildPlan[reqamount];
for(int i = 0; i < reqamount; i++){ for(int i = 0; i < reqamount; i++){
BuildPlan request = readPlan(read); BuildPlan plan = readPlan(read);
if(request != null){ if(plan != null){
reqs[i] = request; reqs[i] = plan;
} }
} }

View File

@@ -603,7 +603,7 @@ public class Block extends UnlockableContent implements Senseable{
} }
/** @return a possible replacement for this block when placed in a line by the player. */ /** @return a possible replacement for this block when placed in a line by the player. */
public Block getReplacement(BuildPlan req, Seq<BuildPlan> requests){ public Block getReplacement(BuildPlan req, Seq<BuildPlan> plans){
return this; return this;
} }
@@ -612,7 +612,7 @@ public class Block extends UnlockableContent implements Senseable{
} }
/** Mutates the given list of requests used during line placement. */ /** Mutates the given list of plans used during line placement. */
public void handlePlacementLine(Seq<BuildPlan> plans){ public void handlePlacementLine(Seq<BuildPlan> plans){
} }

View File

@@ -105,10 +105,10 @@ public class Conveyor extends Block implements Autotiler{
} }
@Override @Override
public Block getReplacement(BuildPlan req, Seq<BuildPlan> requests){ public Block getReplacement(BuildPlan req, Seq<BuildPlan> plans){
if(junctionReplacement == null) return this; if(junctionReplacement == null) return this;
Boolf<Point2> cont = p -> requests.contains(o -> o.x == req.x + p.x && o.y == req.y + p.y && (req.block instanceof Conveyor || req.block instanceof Junction)); Boolf<Point2> cont = p -> plans.contains(o -> o.x == req.x + p.x && o.y == req.y + p.y && (req.block instanceof Conveyor || req.block instanceof Junction));
return cont.get(Geometry.d4(req.rotation)) && return cont.get(Geometry.d4(req.rotation)) &&
cont.get(Geometry.d4(req.rotation - 2)) && cont.get(Geometry.d4(req.rotation - 2)) &&
req.tile() != null && req.tile() != null &&

View File

@@ -112,10 +112,10 @@ public class Conduit extends LiquidBlock implements Autotiler{
} }
@Override @Override
public Block getReplacement(BuildPlan req, Seq<BuildPlan> requests){ public Block getReplacement(BuildPlan req, Seq<BuildPlan> plans){
if(junctionReplacement == null) return this; if(junctionReplacement == null) return this;
Boolf<Point2> cont = p -> requests.contains(o -> o.x == req.x + p.x && o.y == req.y + p.y && o.rotation == req.rotation && (req.block instanceof Conduit || req.block instanceof LiquidJunction)); Boolf<Point2> cont = p -> plans.contains(o -> o.x == req.x + p.x && o.y == req.y + p.y && o.rotation == req.rotation && (req.block instanceof Conduit || req.block instanceof LiquidJunction));
return cont.get(Geometry.d4(req.rotation)) && return cont.get(Geometry.d4(req.rotation)) &&
cont.get(Geometry.d4(req.rotation - 2)) && cont.get(Geometry.d4(req.rotation - 2)) &&
req.tile() != null && req.tile() != null &&