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(!alwaysFlee) retreatTimer = 0f;
//approach request if building
//approach plan if building
BuildPlan req = unit.buildPlan();
//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)));
if(valid){
//move toward the request
//move toward the plan
moveTo(req.tile(), buildingRange - 20f);
}else{
//discard invalid request
//discard invalid plan
unit.plans.removeFirst();
lastPlan = null;
}
@@ -122,7 +122,7 @@ public class BuilderAI extends AIController{
if(build instanceof ConstructBuild cons){
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){
following = u;
found = true;
@@ -135,7 +135,7 @@ public class BuilderAI extends AIController{
//TODO this is bad, rebuild time should not depend on AI here
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)){
Queue<BlockPlan> blocks = unit.team.data().blocks;
BlockPlan block = blocks.first();
@@ -145,7 +145,7 @@ public class BuilderAI extends AIController{
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
lastPlan = block;
//add build request
//add build plan
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
blocks.addLast(blocks.removeFirst());

View File

@@ -69,9 +69,9 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{
Iterator<BuildPlan> it = plans.iterator();
while(it.hasNext()){
BuildPlan req = it.next();
Tile tile = world.tile(req.x, req.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)){
BuildPlan plan = it.next();
Tile tile = world.tile(plan.x, plan.y);
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();
}
}
@@ -81,13 +81,13 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{
//nothing to build.
if(buildPlan() == null) continue;
//find the next build request
//find the next build plan
if(plans.size > 1){
int total = 0;
BuildPlan req;
while((!within((req = buildPlan()).tile(), finalPlaceDst) || shouldSkip(req, core)) && total < plans.size){
BuildPlan plan;
while((!within((plan = buildPlan()).tile(), finalPlaceDst) || shouldSkip(plan, core)) && total < plans.size){
plans.removeFirst();
plans.addLast(req);
plans.addLast(plan);
total++;
}
}
@@ -167,36 +167,36 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{
Draw.reset();
}
void drawPlan(BuildPlan request, float alpha){
request.animScale = 1f;
if(request.breaking){
control.input.drawBreaking(request);
void drawPlan(BuildPlan plan, float alpha){
plan.animScale = 1f;
if(plan.breaking){
control.input.drawBreaking(plan);
}else{
request.block.drawPlan(request, control.input.allRequests(),
Build.validPlace(request.block, team, request.x, request.y, request.rotation) || control.input.requestMatches(request),
plan.block.drawPlan(plan, control.input.allPlans(),
Build.validPlace(plan.block, team, plan.x, plan.y, plan.rotation) || control.input.planMatches(plan),
alpha);
}
}
void drawPlanTop(BuildPlan request, float alpha){
if(!request.breaking){
void drawPlanTop(BuildPlan plan, float alpha){
if(!plan.breaking){
Draw.reset();
Draw.mixcol(Color.white, 0.24f + Mathf.absin(Time.globalTime, 6f, 0.28f));
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. */
boolean shouldSkip(BuildPlan request, @Nullable Building core){
//requests 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;
/** @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;
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){
//remove matching request
//remove matching plan
int idx = plans.indexOf(req -> req.breaking == breaking && req.x == x && req.y == y);
if(idx != -1){
plans.removeIndex(idx);
@@ -213,19 +213,19 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{
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){
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){
if(!canBuild()) return;
BuildPlan replace = null;
for(BuildPlan request : plans){
if(request.x == place.x && request.y == place.y){
replace = request;
for(BuildPlan plan : plans){
if(plan.x == place.x && plan.y == place.y){
replace = plan;
break;
}
}
@@ -253,9 +253,8 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{
return isBuilding() && updateBuilding;
}
/** Return the build request currently active, or the one at the top of the queue.*/
@Nullable
BuildPlan buildPlan(){
/** @return the build plan currently active, or the one at the top of the queue.*/
@Nullable BuildPlan buildPlan(){
return plans.size == 0 ? null : plans.first();
}

View File

@@ -10,13 +10,13 @@ import mindustry.world.*;
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{
/** Position and rotation of this request. */
/** Position and rotation of this plan. */
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;
/** Whether this is a break request.*/
/** Whether this is a break plan.*/
public boolean breaking;
/** Config int. Not used unless hasConfig is true.*/
public Object config;
@@ -25,13 +25,13 @@ public class BuildPlan implements Position, QuadTreeObject{
/** Last 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;
/** Visual scale. Used only for rendering.*/
public float animScale = 0f;
/** This creates a build request. */
/** This creates a build plan. */
public BuildPlan(int x, int y, int rotation, Block block){
this.x = x;
this.y = y;
@@ -40,7 +40,7 @@ public class BuildPlan implements Position, QuadTreeObject{
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){
this.x = x;
this.y = y;
@@ -50,7 +50,7 @@ public class BuildPlan implements Position, QuadTreeObject{
this.config = config;
}
/** This creates a remove request. */
/** This creates a remove plan. */
public BuildPlan(int x, int y){
this.x = x;
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));
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 requests
//draw plans
plans.each(req -> {
req.animScale = 1f;
req.worldContext = false;
@@ -273,8 +273,8 @@ public class Schematics implements Loadable{
return previews.get(schematic);
}
/** Creates an array of build requests from a schematic's data, centered on the provided x+y coordinates. */
public Seq<BuildPlan> toRequests(Schematic schem, int x, int y){
/** Creates an array of build plans from a schematic's data, centered on the provided x+y coordinates. */
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))
.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);
});
//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 x = wx;
if(direction >= 0){

View File

@@ -38,9 +38,9 @@ public class DesktopInput extends InputHandler{
public PlaceMode mode;
/** Animation scale for line. */
public float selectScale;
/** Selected build request for movement. */
/** Selected build plan for movement. */
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;
/** Mouse pan speed. */
public float panScale = 0.005f, panSpeed = 4.5f, panBoostSpeed = 15f;
@@ -50,7 +50,7 @@ public class DesktopInput extends InputHandler{
public Tile prevSelected;
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());
}
@@ -84,7 +84,7 @@ public class DesktopInput extends InputHandler{
//schematic controls
group.fill(t -> {
t.visible(() -> ui.hudfrag.shown && lastSchematic != null && !selectRequests.isEmpty());
t.visible(() -> ui.hudfrag.shown && lastSchematic != null && !selectPlans.isEmpty());
t.bottom();
t.table(Styles.black6, b -> {
b.defaults().left();
@@ -186,38 +186,38 @@ public class DesktopInput extends InputHandler{
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()){
BuildPlan req = getRequest(cursorX, cursorY);
BuildPlan req = getPlan(cursorX, cursorY);
if(req != null){
drawSelected(req.x, req.y, req.breaking ? req.tile().block() : req.block, Pal.accent);
}
}
//draw schematic requests
selectRequests.each(req -> {
//draw schematic plans
selectPlans.each(req -> {
req.animScale = 1f;
drawPlan(req);
});
selectRequests.each(this::drawOverPlan);
selectPlans.each(this::drawOverPlan);
if(player.isBuilder()){
//draw things that may be placed soon
if(mode == placing && block != null){
for(int i = 0; i < lineRequests.size; i++){
BuildPlan req = lineRequests.get(i);
if(i == lineRequests.size - 1 && req.block.rotate){
for(int i = 0; i < linePlans.size; i++){
BuildPlan req = linePlans.get(i);
if(i == linePlans.size - 1 && req.block.rotate){
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()){
if(block.rotate && block.drawArrow){
drawArrow(block, cursorX, cursorY, rotation);
@@ -229,10 +229,10 @@ public class DesktopInput extends InputHandler{
if(block.saveConfig){
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);
brequest.config = block.lastConfig;
block.drawPlanConfig(brequest, allRequests());
brequest.config = null;
bplan.set(cursorX, cursorY, rotation, block);
bplan.config = block.lastConfig;
block.drawPlanConfig(bplan, allPlans());
bplan.config = null;
Draw.reset();
}
@@ -333,7 +333,7 @@ public class DesktopInput extends InputHandler{
//zoom camera
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));
}
@@ -379,8 +379,8 @@ public class DesktopInput extends InputHandler{
if(isPlacing() && mode == placing){
updateLine(selectX, selectY);
}else if(!selectRequests.isEmpty() && !ui.chatfrag.shown()){
rotateRequests(selectRequests, Mathf.sign(Core.input.axisTap(Binding.rotate)));
}else if(!selectPlans.isEmpty() && !ui.chatfrag.shown()){
rotatePlans(selectPlans, Mathf.sign(Core.input.axisTap(Binding.rotate)));
}
}
@@ -391,7 +391,7 @@ public class DesktopInput extends InputHandler{
cursorType = cursor.build.getCursor();
}
if((isPlacing() && player.isBuilder()) || !selectRequests.isEmpty()){
if((isPlacing() && player.isBuilder()) || !selectPlans.isEmpty()){
cursorType = SystemCursor.hand;
}
@@ -403,7 +403,7 @@ public class DesktopInput extends InputHandler{
cursorType = ui.targetCursor;
}
if(getRequest(cursor.x, cursor.y) != null && mode == none){
if(getPlan(cursor.x, cursor.y) != null && mode == none){
cursorType = SystemCursor.hand;
}
@@ -430,8 +430,8 @@ public class DesktopInput extends InputHandler{
schematicX = tileX(getMouseX());
schematicY = tileY(getMouseY());
selectRequests.clear();
selectRequests.addAll(schematics.toRequests(schem, schematicX, schematicY));
selectPlans.clear();
selectPlans.addAll(schematics.toPlans(schem, schematicX, schematicY));
mode = none;
}
@@ -477,10 +477,10 @@ public class DesktopInput extends InputHandler{
buildWasAutoPaused = true;
}
if(!selectRequests.isEmpty()){
if(!selectPlans.isEmpty()){
int shiftX = rawCursorX - schematicX, shiftY = rawCursorY - schematicY;
selectRequests.each(s -> {
selectPlans.each(s -> {
s.x += shiftX;
s.y += shiftY;
});
@@ -512,26 +512,26 @@ public class DesktopInput extends InputHandler{
if(Core.input.keyTap(Binding.clear_building) || isPlacing()){
lastSchematic = null;
selectRequests.clear();
selectPlans.clear();
}
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);
useSchematic(lastSchematic);
if(selectRequests.isEmpty()){
if(selectPlans.isEmpty()){
lastSchematic = null;
}
schemX = -1;
schemY = -1;
}
if(!selectRequests.isEmpty()){
if(!selectPlans.isEmpty()){
if(Core.input.keyTap(Binding.schematic_flip_x)){
flipRequests(selectRequests, true);
flipPlans(selectPlans, true);
}
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){
lineRequests.clear();
linePlans.clear();
}
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()){
tappedOne = false;
BuildPlan req = getRequest(cursorX, cursorY);
BuildPlan req = getPlan(cursorX, cursorY);
if(Core.input.keyDown(Binding.break_block)){
mode = none;
}else if(!selectRequests.isEmpty()){
flushRequests(selectRequests);
}else if(!selectPlans.isEmpty()){
flushPlans(selectPlans);
}else if(isPlacing()){
selectX = cursorX;
selectY = cursorY;
@@ -616,8 +616,8 @@ public class DesktopInput extends InputHandler{
}else if(Core.input.keyTap(Binding.deselect) && isPlacing()){
block = null;
mode = none;
}else if(Core.input.keyTap(Binding.deselect) && !selectRequests.isEmpty()){
selectRequests.clear();
}else if(Core.input.keyTap(Binding.deselect) && !selectPlans.isEmpty()){
selectPlans.clear();
lastSchematic = null;
}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
@@ -630,7 +630,7 @@ public class DesktopInput extends InputHandler{
}
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){
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(mode == placing && block != null){ //touch up while placing, place everything in selection
flushRequests(lineRequests);
lineRequests.clear();
flushPlans(linePlans);
linePlans.clear();
Events.fire(new LineConfirmEvent());
}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);
@@ -672,7 +672,7 @@ public class DesktopInput extends InputHandler{
tryDropItems(selected == null ? null : selected.build, Core.input.mouseWorld().x, Core.input.mouseWorld().y);
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);
}
sreq = null;
@@ -783,7 +783,7 @@ public class DesktopInput extends InputHandler{
mode = none;
block = null;
sreq = null;
selectRequests.clear();
selectPlans.clear();
}
}

View File

@@ -74,9 +74,9 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
public GestureDetector detector;
public PlaceLine line = new PlaceLine();
public BuildPlan resultreq;
public BuildPlan brequest = new BuildPlan();
public Seq<BuildPlan> lineRequests = new Seq<>();
public Seq<BuildPlan> selectRequests = new Seq<>();
public BuildPlan bplan = new BuildPlan();
public Seq<BuildPlan> linePlans = new Seq<>();
public Seq<BuildPlan> selectPlans = new Seq<>();
//for RTS controls
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 QuadTree<BuildPlan> playerPlanTree = new QuadTree<>(new Rect());
private final Eachable<BuildPlan> allRequests = cons -> {
private final Eachable<BuildPlan> allPlans = cons -> {
player.unit().plans().each(cons);
selectRequests.each(cons);
lineRequests.each(cons);
selectPlans.each(cons);
linePlans.each(cons);
};
private final Eachable<BuildPlan> allSelectLines = cons -> {
selectRequests.each(cons);
lineRequests.each(cons);
selectPlans.each(cons);
linePlans.each(cons);
};
public InputHandler(){
@@ -554,12 +554,12 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
return inputLocks.contains(Boolp::get);
}
public Eachable<BuildPlan> allRequests(){
return allRequests;
public Eachable<BuildPlan> allPlans(){
return allPlans;
}
public boolean isUsingSchematic(){
return !selectRequests.isEmpty();
return !selectPlans.isEmpty();
}
public void update(){
@@ -692,11 +692,11 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
Drawf.selected(x, y, block, color);
}
public void drawBreaking(BuildPlan request){
if(request.breaking){
drawBreaking(request.x, request.y);
public void drawBreaking(BuildPlan plan){
if(plan.breaking){
drawBreaking(plan.x, plan.y);
}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){
Tile tile = world.tile(request.x, request.y);
return tile != null && tile.build instanceof ConstructBuild cons && cons.current == request.block;
public boolean planMatches(BuildPlan plan){
Tile tile = world.tile(plan.x, plan.y);
return tile != null && tile.build instanceof ConstructBuild cons && cons.current == plan.block;
}
public void drawBreaking(int x, int y){
@@ -730,7 +730,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
}
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(){
@@ -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();
requests.each(req -> {
plans.each(req -> {
if(req.breaking) return;
req.pointConfig(p -> {
@@ -775,7 +775,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
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 x = wx;
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;
requests.each(req -> {
plans.each(req -> {
if(req.breaking) return;
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();
}
/** Returns the selection request that overlaps this position, or null. */
protected BuildPlan getRequest(int x, int y){
return getRequest(x, y, 1, null);
/** @return the selection plan that overlaps this position, or null. */
protected @Nullable BuildPlan getPlan(int x, int y){
return getPlan(x, y, 1, null);
}
/** Returns the selection request that overlaps this position, or null. */
protected BuildPlan getRequest(int x, int y, int size, BuildPlan skip){
/** Returns the selection plan that overlaps this position, or null. */
protected @Nullable BuildPlan getPlan(int x, int y, int size, BuildPlan skip){
float offset = ((size + 1) % 2) * tilesize / 2f;
r2.setSize(tilesize * size);
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;
}
return selectRequests.find(test);
return selectPlans.find(test);
}
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.bounds(Tmp.r2).overlaps(Tmp.r1)){
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);
}
protected void flushSelectRequests(Seq<BuildPlan> requests){
for(BuildPlan req : requests){
protected void flushSelectPlans(Seq<BuildPlan> plans){
for(BuildPlan req : plans){
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){
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){
selectRequests.remove(other);
selectRequests.add(req.copy());
selectPlans.remove(other);
selectPlans.add(req.copy());
}
}
}
}
protected void flushRequests(Seq<BuildPlan> requests){
for(BuildPlan req : requests){
protected void flushPlans(Seq<BuildPlan> plans){
for(BuildPlan req : plans){
if(req.block != null && validPlace(req.x, req.y, req.block, req.rotation)){
BuildPlan copy = req.copy();
req.block.onNewPlan(copy);
@@ -952,25 +952,25 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
}
}
protected void drawOverPlan(BuildPlan request){
boolean valid = validPlace(request.x, request.y, request.block, request.rotation);
protected void drawOverPlan(BuildPlan plan){
boolean valid = validPlace(plan.x, plan.y, plan.block, plan.rotation);
Draw.reset();
Draw.mixcol(!valid ? Pal.breakInvalid : Color.white, (!valid ? 0.4f : 0.24f) + Mathf.absin(Time.globalTime, 6f, 0.28f));
Draw.alpha(1f);
request.block.drawPlanConfigTop(request, allSelectLines);
plan.block.drawPlanConfigTop(plan, allSelectLines);
Draw.reset();
}
protected void drawPlan(BuildPlan request){
request.block.drawPlan(request, allRequests(), validPlace(request.x, request.y, request.block, request.rotation));
protected void drawPlan(BuildPlan plan){
plan.block.drawPlan(plan, allPlans(), validPlace(plan.x, plan.y, plan.block, plan.rotation));
}
/** Draws a placement icon for a specific block. */
protected void drawPlan(int x, int y, Block block, int rotation){
brequest.set(x, y, rotation, block);
brequest.animScale = 1f;
block.drawPlan(brequest, allRequests(), validPlace(x, y, block, rotation));
bplan.set(x, y, rotation, block);
bplan.animScale = 1f;
block.drawPlan(bplan, allPlans(), validPlace(x, y, block, rotation));
}
/** Remove everything from the queue in a selection. */
@@ -1002,13 +1002,13 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
if(!flush){
tryBreakBlock(wx, wy);
}else if(validBreak(tile.x, tile.y) && !selectRequests.contains(r -> r.tile() != null && r.tile() == tile)){
selectRequests.add(new BuildPlan(tile.x, tile.y));
}else if(validBreak(tile.x, tile.y) && !selectPlans.contains(r -> r.tile() != null && r.tile() == tile)){
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);
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()){
BuildPlan req = it.next();
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){
lineRequests.clear();
linePlans.clear();
iterateLine(x1, y1, x2, y2, l -> {
rotation = l.rotation;
BuildPlan req = new BuildPlan(l.x, l.y, l.rotation, block, block.nextConfig());
req.animScale = 1f;
lineRequests.add(req);
linePlans.add(req);
});
if(Core.settings.getBool("blockreplace")){
lineRequests.each(req -> {
Block replace = req.block.getReplacement(req, lineRequests);
linePlans.each(req -> {
Block replace = req.block.getReplacement(req, linePlans);
if(replace.unlockedNow()){
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. */
public float crosshairScale;
public Teamc lastTarget;
/** Used for shifting build requests. */
/** Used for shifting build plans. */
public float shiftDeltaX, shiftDeltaY;
/** Place requests to be removed. */
/** Place plans to be removed. */
public Seq<BuildPlan> removals = new Seq<>();
/** Whether the player is currently shifting all placed tiles. */
public boolean selecting;
@@ -60,7 +60,7 @@ public class MobileInput extends InputHandler implements GestureListener{
public PlaceMode mode = none;
/** Whether no recipe was available when switching to break mode. */
public @Nullable Block lastBlock;
/** Last placed request. Used for drawing block overlay. */
/** Last placed plan. Used for drawing block overlay. */
public @Nullable BuildPlan lastPlaced;
/** Down tracking for panning. */
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. */
boolean hasRequest(Tile tile){
return getRequest(tile) != null;
/** Returns whether this tile is in the list of plans, or at least colliding with one. */
boolean hasPlan(Tile tile){
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){
r2.setSize(block.size * tilesize);
r2.setCenter(x * tilesize + block.offset, y * tilesize + block.offset);
for(BuildPlan req : selectRequests){
for(BuildPlan req : selectPlans){
Tile other = req.tile();
if(other == null || req.breaking) continue;
@@ -141,12 +141,12 @@ public class MobileInput extends InputHandler implements GestureListener{
return false;
}
/** Returns the selection request that overlaps this tile, or null. */
BuildPlan getRequest(Tile tile){
/** Returns the selection plan that overlaps this tile, or null. */
BuildPlan getPlan(Tile tile){
r2.setSize(tilesize);
r2.setCenter(tile.worldx(), tile.worldy());
for(BuildPlan req : selectRequests){
for(BuildPlan req : selectPlans){
Tile other = req.tile();
if(other == null) continue;
@@ -165,10 +165,10 @@ public class MobileInput extends InputHandler implements GestureListener{
return null;
}
void removeRequest(BuildPlan request){
selectRequests.remove(request, true);
if(!request.breaking){
removals.add(request);
void removePlan(BuildPlan plan){
selectPlans.remove(plan, true);
if(!plan.breaking){
removals.add(plan);
}
}
@@ -220,48 +220,48 @@ public class MobileInput extends InputHandler implements GestureListener{
//confirm button
table.button(Icon.ok, Styles.clearPartiali, () -> {
for(BuildPlan request : selectRequests){
Tile tile = request.tile();
for(BuildPlan plan : selectPlans){
Tile tile = plan.tile();
//actually place/break all selected blocks
if(tile != null){
if(!request.breaking){
if(validPlace(request.x, request.y, request.block, request.rotation)){
BuildPlan other = getRequest(request.x, request.y, request.block.size, null);
BuildPlan copy = request.copy();
if(!plan.breaking){
if(validPlace(plan.x, plan.y, plan.block, plan.rotation)){
BuildPlan other = getPlan(plan.x, plan.y, plan.block.size, null);
BuildPlan copy = plan.copy();
if(other == null){
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().addBuild(copy);
}
}
rotation = request.rotation;
rotation = plan.rotation;
}else{
tryBreakBlock(tile.x, tile.y);
}
}
}
//move all current requests to removal array so they fade out
removals.addAll(selectRequests.select(r -> !r.breaking));
selectRequests.clear();
//move all current plans to removal array so they fade out
removals.addAll(selectPlans.select(r -> !r.breaking));
selectPlans.clear();
selecting = false;
}).visible(() -> !selectRequests.isEmpty()).name("confirmplace");
}).visible(() -> !selectPlans.isEmpty()).name("confirmplace");
}
@Override
public void buildUI(Group group){
Boolp schem = () -> lastSchematic != null && !selectRequests.isEmpty();
Boolp schem = () -> lastSchematic != null && !selectPlans.isEmpty();
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.button("@cancel", Icon.cancel, () -> {
player.unit().clearBuilding();
selectRequests.clear();
selectPlans.clear();
mode = none;
block = null;
}).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.cancel, style, () -> {
selectRequests.clear();
selectPlans.clear();
lastSchematic = null;
});
b.row();
b.button(Icon.flipX, style, () -> flipRequests(selectRequests, true));
b.button(Icon.flipY, style, () -> flipRequests(selectRequests, false));
b.button(Icon.flipX, style, () -> flipPlans(selectPlans, true));
b.button(Icon.flipY, style, () -> flipPlans(selectPlans, false));
b.row();
b.button(Icon.rotate, style, () -> rotateRequests(selectRequests, 1));
b.button(Icon.rotate, style, () -> rotatePlans(selectPlans, 1));
}).margin(4f);
});
@@ -294,18 +294,18 @@ public class MobileInput extends InputHandler implements GestureListener{
public void drawBottom(){
Lines.stroke(1f);
//draw requests about to be removed
for(BuildPlan request : removals){
Tile tile = request.tile();
//draw plans about to be removed
for(BuildPlan plan : removals){
Tile tile = plan.tile();
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){
drawSelected(request.x, request.y, tile.block(), Pal.remove);
if(plan.breaking){
drawSelected(plan.x, plan.y, tile.block(), Pal.remove);
}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){
//draw placing
for(int i = 0; i < lineRequests.size; i++){
BuildPlan request = lineRequests.get(i);
if(i == lineRequests.size - 1 && request.block.rotate){
drawArrow(block, request.x, request.y, request.rotation);
for(int i = 0; i < linePlans.size; i++){
BuildPlan plan = linePlans.get(i);
if(i == linePlans.size - 1 && plan.block.rotate){
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);
drawSelected(request.x, request.y, request.block, Pal.accent);
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(plan.x, plan.y, plan.block, Pal.accent);
}
lineRequests.each(this::drawOverPlan);
linePlans.each(this::drawOverPlan);
}else if(mode == breaking){
drawBreakSelection(lineStartX, lineStartY, tileX, tileY);
}
@@ -346,39 +346,39 @@ public class MobileInput extends InputHandler implements GestureListener{
@Override
public void drawOverSelect(){
//draw list of requests
for(BuildPlan request : selectRequests){
Tile tile = request.tile();
//draw list of plans
for(BuildPlan plan : selectPlans){
Tile tile = plan.tile();
if(tile == null) continue;
if((!request.breaking && validPlace(tile.x, tile.y, request.block, request.rotation))
|| (request.breaking && validBreak(tile.x, tile.y))){
request.animScale = Mathf.lerpDelta(request.animScale, 1f, 0.2f);
if((!plan.breaking && validPlace(tile.x, tile.y, plan.block, plan.rotation))
|| (plan.breaking && validBreak(tile.x, tile.y))){
plan.animScale = Mathf.lerpDelta(plan.animScale, 1f, 0.2f);
}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());
if(!request.breaking && request == lastPlaced && request.block != null){
if(!plan.breaking && plan == lastPlaced && plan.block != null){
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();
drawPlan(request);
if(!request.breaking){
drawOverPlan(request);
drawPlan(plan);
if(!plan.breaking){
drawOverPlan(plan);
}
//draw last placed request
if(!request.breaking && request == lastPlaced && request.block != null && request.block.drawArrow){
boolean valid = validPlace(tile.x, tile.y, request.block, rotation);
//draw last placed plan
if(!plan.breaking && plan == lastPlaced && plan.block != null && plan.block.drawArrow){
boolean valid = validPlace(tile.x, tile.y, plan.block, rotation);
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
protected void drawPlan(BuildPlan request){
if(request.tile() == null) return;
brequest.animScale = request.animScale = Mathf.lerpDelta(request.animScale, 1f, 0.1f);
protected void drawPlan(BuildPlan plan){
if(plan.tile() == null) return;
bplan.animScale = plan.animScale = Mathf.lerpDelta(plan.animScale, 1f, 0.1f);
if(request.breaking){
drawSelected(request.x, request.y, request.tile().block(), Pal.remove);
if(plan.breaking){
drawSelected(plan.x, plan.y, plan.tile().block(), Pal.remove);
}else{
request.block.drawPlan(request, allRequests(), validPlace(request.x, request.y, request.block, request.rotation));
drawSelected(request.x, request.y, request.block, Pal.accent);
plan.block.drawPlan(plan, allPlans(), validPlace(plan.x, plan.y, plan.block, plan.rotation));
drawSelected(plan.x, plan.y, plan.block, Pal.accent);
}
}
@@ -417,15 +417,15 @@ public class MobileInput extends InputHandler implements GestureListener{
@Override
protected int schemOriginX(){
Tmp.v1.setZero();
selectRequests.each(r -> Tmp.v1.add(r.drawx(), r.drawy()));
return World.toTile(Tmp.v1.scl(1f / selectRequests.size).x);
selectPlans.each(r -> Tmp.v1.add(r.drawx(), r.drawy()));
return World.toTile(Tmp.v1.scl(1f / selectPlans.size).x);
}
@Override
protected int schemOriginY(){
Tmp.v1.setZero();
selectRequests.each(r -> Tmp.v1.add(r.drawx(), r.drawy()));
return World.toTile(Tmp.v1.scl(1f / selectRequests.size).y);
selectPlans.each(r -> Tmp.v1.add(r.drawx(), r.drawy()));
return World.toTile(Tmp.v1.scl(1f / selectPlans.size).y);
}
@Override
@@ -440,8 +440,8 @@ public class MobileInput extends InputHandler implements GestureListener{
@Override
public void useSchematic(Schematic schem){
selectRequests.clear();
selectRequests.addAll(schematics.toRequests(schem, World.toTile(Core.camera.position.x), World.toTile(Core.camera.position.y)));
selectPlans.clear();
selectPlans.addAll(schematics.toPlans(schem, World.toTile(Core.camera.position.x), World.toTile(Core.camera.position.y)));
lastSchematic = schem;
}
@@ -461,8 +461,8 @@ public class MobileInput extends InputHandler implements GestureListener{
//ignore off-screen taps
if(cursor == null || Core.scene.hasMouse(screenX, screenY)) return false;
//only begin selecting if the tapped block is a request
selecting = hasRequest(cursor);
//only begin selecting if the tapped block is a plan
selecting = hasPlan(cursor);
//call tap events
if(pointer == 0 && !selecting){
@@ -501,7 +501,7 @@ public class MobileInput extends InputHandler implements GestureListener{
int tileY = tileY(screenY);
if(mode == placing && isPlacing()){
flushSelectRequests(lineRequests);
flushSelectPlans(linePlans);
Events.fire(new LineConfirmEvent());
}else if(mode == breaking){
removeSelection(lineStartX, lineStartY, tileX, tileY, true);
@@ -509,10 +509,10 @@ public class MobileInput extends InputHandler implements GestureListener{
lineMode = false;
}else if(mode == schematicSelect){
selectRequests.clear();
selectPlans.clear();
lastSchematic = schematics.create(lineStartX, lineStartY, lastLineX, lastLineY);
useSchematic(lastSchematic);
if(selectRequests.isEmpty()){
if(selectPlans.isEmpty()){
lastSchematic = null;
}
schematicMode = false;
@@ -566,7 +566,7 @@ public class MobileInput extends InputHandler implements GestureListener{
//ignore off-screen taps
if(cursor == null) return false;
//remove request if it's there
//remove plan if it's there
//long pressing enables line mode otherwise
lineStartX = cursor.x;
lineStartY = cursor.y;
@@ -605,16 +605,16 @@ public class MobileInput extends InputHandler implements GestureListener{
checkTargets(worldx, worldy);
}
//remove if request present
if(hasRequest(cursor)){
removeRequest(getRequest(cursor));
//remove if plan present
if(hasPlan(cursor)){
removePlan(getPlan(cursor));
}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
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);
}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
selectRequests.add(new BuildPlan(linked.x, linked.y));
selectPlans.add(new BuildPlan(linked.x, linked.y));
}else{
//control units
if(count == 2){
@@ -650,7 +650,7 @@ public class MobileInput extends InputHandler implements GestureListener{
super.updateState();
if(state.isMenu()){
selectRequests.clear();
selectPlans.clear();
removals.clear();
mode = none;
manualShooting = false;
@@ -671,7 +671,7 @@ public class MobileInput extends InputHandler implements GestureListener{
}
//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));
}
@@ -751,15 +751,14 @@ public class MobileInput extends InputHandler implements GestureListener{
updateLine(lineStartX, lineStartY, lx, ly);
}
}else{
lineRequests.clear();
linePlans.clear();
lineScale = 0f;
}
//remove place requests that have disappeared
//remove place plans that have disappeared
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);
i--;
}
@@ -815,7 +814,7 @@ public class MobileInput extends InputHandler implements GestureListener{
//do not pan with manual shooting enabled
if(!down || manualShooting) return false;
if(selecting){ //pan all requests
if(selecting){ //pan all plans
shiftDeltaX += deltaX;
shiftDeltaY += deltaY;
@@ -823,8 +822,8 @@ public class MobileInput extends InputHandler implements GestureListener{
int shiftedY = (int)(shiftDeltaY / tilesize);
if(Math.abs(shiftedX) > 0 || Math.abs(shiftedY) > 0){
for(BuildPlan req : selectRequests){
if(req.breaking) continue; //don't shift removal requests
for(BuildPlan req : selectPlans){
if(req.breaking) continue; //don't shift removal plans
req.x += shiftedX;
req.y += shiftedY;
}

View File

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

View File

@@ -105,10 +105,10 @@ public class Conveyor extends Block implements Autotiler{
}
@Override
public Block getReplacement(BuildPlan req, Seq<BuildPlan> requests){
public Block getReplacement(BuildPlan req, Seq<BuildPlan> plans){
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)) &&
cont.get(Geometry.d4(req.rotation - 2)) &&
req.tile() != null &&

View File

@@ -112,10 +112,10 @@ public class Conduit extends LiquidBlock implements Autotiler{
}
@Override
public Block getReplacement(BuildPlan req, Seq<BuildPlan> requests){
public Block getReplacement(BuildPlan req, Seq<BuildPlan> plans){
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)) &&
cont.get(Geometry.d4(req.rotation - 2)) &&
req.tile() != null &&