quarrys exist and work, but are a little buggy...

bottom-bar
Ivory 2023-01-11 05:09:35 -05:00
parent 6bec854463
commit 9b12ee7417
13 changed files with 241 additions and 17 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 29 KiB

View File

@ -39,4 +39,20 @@ public class Vector2i implements Serializable {
return new Vector2f(x, y);
}
public Vector2i north() {
return new Vector2i(x, y - 1);
}
public Vector2i east() {
return new Vector2i(x + 1, y);
}
public Vector2i south() {
return new Vector2i(x, y + 1);
}
public Vector2i west() {
return new Vector2i(x - 1, y);
}
}

View File

@ -76,6 +76,10 @@ public class Camera extends GameObject {
draw(layer, sprite, pos.x, pos.y, 1, 1);
}
public void draw(float layer, Sprite sprite, Vector4i pos) {
draw(layer, sprite, pos.x, pos.y, pos.z, pos.w);
}
public void draw(float layer, Sprite sprite, float x, float y, float w, float h) {
Vector2f screenPos = world2screen(x, y);
Drawing.setLayer(layer + (((y + h) - minY) / (maxY - minY)));

View File

@ -115,6 +115,8 @@ public class SelectionLayer extends GameObject implements IMouseCaptureArea, ITr
List<ISelectable> selectables = getAll(ISelectable.class);
int prio = Integer.MIN_VALUE;
for(ISelectable thing : selectables) {
Vector4f thingBox = thing.getWorldBox();
if(rectanglesIntersect(
@ -123,9 +125,20 @@ public class SelectionLayer extends GameObject implements IMouseCaptureArea, ITr
thingBox.x, thingBox.y,
thingBox.z, thingBox.w
)) {
System.out.println("Considering selecting " + thing);
int thingPrio = thing.getSelectPriority().toValue();
if(thingPrio > prio) {
newSelection.clear();
prio = thingPrio;
System.out.println("updated prio to " + prio);
System.out.println("List cleared");
}
if(thingPrio >= prio) {
System.out.println("added " + thing);
newSelection.add(thing);
}
}
}
animation = 0;
updateSelection(newSelection);

View File

@ -20,6 +20,7 @@ import xyz.valnet.hadean.gameobjects.inputlayer.SelectionLayer;
import xyz.valnet.hadean.gameobjects.worldobjects.FarmPlot;
import xyz.valnet.hadean.gameobjects.worldobjects.Stockpile;
import xyz.valnet.hadean.gameobjects.worldobjects.constructions.Bed;
import xyz.valnet.hadean.gameobjects.worldobjects.constructions.Quarry;
import xyz.valnet.hadean.gameobjects.worldobjects.constructions.Wall;
import xyz.valnet.hadean.input.Button;
import xyz.valnet.hadean.input.IButtonListener;
@ -63,6 +64,8 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap
BuildTab.registerBuildable(Wall.class);
BuildTab.registerBuildable(Quarry.class);
BuildTab.registerBuildable(FarmPlot.class);
BuildTab.registerBuildable(Stockpile.class);
}

View File

@ -3,11 +3,14 @@ package xyz.valnet.hadean.gameobjects.worldobjects;
import xyz.valnet.engine.math.Vector2i;
import xyz.valnet.hadean.gameobjects.Tile;
import xyz.valnet.hadean.interfaces.IBuildable;
import xyz.valnet.hadean.interfaces.ISelectable;
import xyz.valnet.hadean.interfaces.ITileThing;
import xyz.valnet.hadean.util.Action;
import xyz.valnet.hadean.util.detail.Detail;
public abstract class Buildable extends WorldObject implements IBuildable, ITileThing {
public abstract class Buildable extends WorldObject implements IBuildable, ITileThing, ISelectable {
protected Vector2i getDefaultDimensions() {
protected Vector2i getDimensions() {
return new Vector2i(1, 1);
}
@ -18,10 +21,26 @@ public abstract class Buildable extends WorldObject implements IBuildable, ITile
@Override
public void buildAt(int x, int y) {
Vector2i dim = getDefaultDimensions();
Vector2i dim = getDimensions();
setPosition(x, y, dim.x, dim.y);
}
@Override
public void onPlaced(Tile tile) {}
@Override
public Action[] getActions() {
// TODO Auto-generated method stub
return new Action[] {};
}
@Override
public void runAction(Action action) {
}
@Override
public Detail[] getDetails() {
return new Detail[] {};
}
}

View File

@ -14,7 +14,7 @@ import xyz.valnet.hadean.util.Layers;
import xyz.valnet.hadean.util.detail.Detail;
@BuildableMetadata(category = "Zones", name = "Stockpile")
public class Stockpile extends Buildable implements ISelectable {
public class Stockpile extends Buildable {
@Override
public void render() {
@ -81,4 +81,8 @@ public class Stockpile extends Buildable implements ISelectable {
@Override
public void onPlaced(Tile tile) {}
@Override
public ISelectable.Priority getSelectPriority() {
return ISelectable.Priority.LOW;
}
}

View File

@ -203,6 +203,11 @@ public abstract class Agent extends WorldObject implements ISelectable {
return new Action[0];
}
@Override
public ISelectable.Priority getSelectPriority() {
return ISelectable.Priority.HIGH;
}
public Vector2i getDestination() {
if(nextPath != null) return nextPath.getDestination().getPosition();
if(path == null) return null;

View File

@ -30,7 +30,7 @@ public class Bed extends Buildable implements IItemReceiver, IWorkable, ISelecta
private Job job = null;
@Override
protected Vector2i getDefaultDimensions() {
protected Vector2i getDimensions() {
return new Vector2i(1, 2);
}

View File

@ -0,0 +1,143 @@
package xyz.valnet.hadean.gameobjects.worldobjects.constructions;
import xyz.valnet.engine.math.Vector2i;
import xyz.valnet.engine.math.Vector4f;
import xyz.valnet.hadean.gameobjects.Job;
import xyz.valnet.hadean.gameobjects.JobBoard;
import xyz.valnet.hadean.gameobjects.worldobjects.Buildable;
import xyz.valnet.hadean.gameobjects.worldobjects.items.Boulder;
import xyz.valnet.hadean.interfaces.BuildableMetadata;
import xyz.valnet.hadean.interfaces.IWorkable;
import xyz.valnet.hadean.util.Assets;
import xyz.valnet.hadean.util.Layers;
@BuildableMetadata(category = "Buildings", name = "Quarry", type = BuildableMetadata.Type.SINGLE)
public class Quarry extends Buildable {
private float work = 0;
private static float MAX_WORK = 10000;
private Job digJob = null;
@Override
public void create() {
super.create();
get(JobBoard.class).postSimpleWorkJob("Build Quarry", new IWorkable() {
@Override
public boolean doWork(float dTime) {
work += dTime;
return isBuilt();
}
@Override
public Vector2i[] getWorkablePositions() {
return new Vector2i[] {
getWorldPosition().xy().south().east()
};
}
@Override
public String getJobName() {
return "Build Quarry";
}
});
}
@Override
public void render() {
if(isBuilt()) {
camera.draw(Layers.TILES, Assets.quarry, getWorldPosition());
if(digJob != null && !digJob.isCompleted()) {
camera.drawProgressBar(digProgress, getWorldBox());
}
} else {
float p = work / MAX_WORK;
float b = 4;
Assets.flat.pushColor(new Vector4f(b, b, b, 0.5f));
camera.draw(Layers.GROUND, Assets.quarry, getWorldPosition());
Assets.flat.popColor();
camera.drawProgressBar(p, getWorldBox());
}
}
@Override
public Vector2i getDimensions() {
return new Vector2i(3, 3);
}
private float digProgress = 0;
private void tryCreateDigJob() {
if(!isBuilt()) return;
if (digJob != null) return;
if (terrain.getTile(getWorldPosition().xy().south().east()).has(Boulder.class)) return;
digJob = get(JobBoard.class)
.postSimpleWorkJob("Mine at Quarry", new IWorkable() {
private static float MAX_WORK = 5000;
private float work = 0;
@Override
public boolean doWork(float dTime) {
work += dTime;
digProgress = work / MAX_WORK;
return work >= MAX_WORK;
}
@Override
public Vector2i[] getWorkablePositions() {
return new Vector2i[] {
getWorldPosition().xy().south().east()
};
}
@Override
public String getJobName() {
return "Mine at Quarry";
}
});
digJob.registerClosedListener(() -> {
digProgress = 0;
Vector2i dropPos = getWorldPosition().xy().south().east();
Boulder boulder = new Boulder(dropPos.x, dropPos.y);
add(boulder);
boulder.runAction(Boulder.HAUL);
digJob = null;
});
}
@Override
public void update(float dTime) {
super.update(dTime);
tryCreateDigJob();
}
private boolean isBuilt() {
return work >= MAX_WORK;
}
@Override
public boolean isWalkable() {
return true;
}
@Override
public boolean shouldRemove() {
return false;
}
@Override
public void onRemove() {
}
@Override
public String getName() {
return "Quarry";
}
}

View File

@ -100,15 +100,10 @@ public class Wall extends Buildable implements IItemReceiver, IWorkable, ISelect
private Vector2i[] getBorders() {
Vector2i pos = getWorldPosition().xy();
return new Vector2i[] {
new Vector2i(pos.x, pos.y - 1),
new Vector2i(pos.x - 1, pos.y),
new Vector2i(pos.x + 1, pos.y),
new Vector2i(pos.x - 1, pos.y + 1),
new Vector2i(pos.x + 1, pos.y + 1),
new Vector2i(pos.x, pos.y + 2),
pos.north(),
pos.east(),
pos.south(),
pos.west()
};
}
@ -152,7 +147,7 @@ public class Wall extends Buildable implements IItemReceiver, IWorkable, ISelect
@Override
public boolean isWalkable() {
return false;
return isBuilt();
}
@Override

View File

@ -5,9 +5,29 @@ import xyz.valnet.hadean.util.Action;
import xyz.valnet.hadean.util.detail.Detail;
public interface ISelectable {
public enum Priority {
LOW(-10),
NORMAL(0),
HIGH(10);
private int value;
Priority(int value) {
this.value = value;
}
public int toValue() {
return value;
}
}
public Vector4f getWorldBox();
public Action[] getActions();
public void runAction(Action action);
public Detail[] getDetails();
public default void selectedRender() {}
public default Priority getSelectPriority() {
return Priority.NORMAL;
}
}

View File

@ -1,8 +1,10 @@
package xyz.valnet.hadean.interfaces;
import java.io.Serializable;
import xyz.valnet.engine.math.Vector2i;
public interface IWorkable {
public interface IWorkable extends Serializable {
public boolean doWork(float dTime);
public Vector2i[] getWorkablePositions();
public String getJobName();