remove buildable metadata. new simple work job
parent
fe29860988
commit
54229b1f2e
|
|
@ -1,9 +1,7 @@
|
|||
package xyz.valnet.hadean.designation;
|
||||
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.Tree;
|
||||
import xyz.valnet.hadean.interfaces.BuildableMetadata;
|
||||
|
||||
@BuildableMetadata(category = "Jobs", name = "Chop Trees")
|
||||
public class CutTreesDesignation extends Designation<Tree> {
|
||||
|
||||
@Override
|
||||
|
|
@ -15,4 +13,9 @@ public class CutTreesDesignation extends Designation<Tree> {
|
|||
protected void designate(Tree thing) {
|
||||
thing.runAction(Tree.ACTION_CHOP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBuildTabName() {
|
||||
return "ChopTrees";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.hadean.interfaces.BuildType;
|
||||
import xyz.valnet.hadean.interfaces.IBuildable;
|
||||
import xyz.valnet.hadean.interfaces.ISelectable;
|
||||
|
||||
|
|
@ -44,6 +45,15 @@ public abstract class Designation<T extends ISelectable> extends GameObject impl
|
|||
return !( aLeftOfB || aRightOfB || aAboveB || aBelowB );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBuildTabCategory() {
|
||||
return "Jobs";
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuildType getBuildType() {
|
||||
return BuildType.AREA;
|
||||
}
|
||||
|
||||
protected abstract Class<T> getType();
|
||||
protected abstract void designate(T thing);
|
||||
|
|
|
|||
|
|
@ -1,12 +1,9 @@
|
|||
package xyz.valnet.hadean.designation;
|
||||
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Item;
|
||||
import xyz.valnet.hadean.interfaces.BuildableMetadata;
|
||||
|
||||
@BuildableMetadata(category = "Jobs", name = "Haul Items")
|
||||
public class HaulItemDesignation extends Designation<Item> {
|
||||
|
||||
|
||||
@Override
|
||||
protected Class<Item> getType() {
|
||||
return Item.class;
|
||||
|
|
@ -16,4 +13,9 @@ public class HaulItemDesignation extends Designation<Item> {
|
|||
protected void designate(Item thing) {
|
||||
thing.runAction(Item.HAUL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBuildTabName() {
|
||||
return "Haul Items";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import xyz.valnet.engine.scenegraph.GameObject;
|
|||
import xyz.valnet.engine.scenegraph.IMouseCaptureArea;
|
||||
import xyz.valnet.engine.scenegraph.ITransient;
|
||||
import xyz.valnet.hadean.gameobjects.Camera;
|
||||
import xyz.valnet.hadean.interfaces.BuildableMetadata;
|
||||
import xyz.valnet.hadean.interfaces.BuildType;
|
||||
import xyz.valnet.hadean.interfaces.IBuildLayerListener;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
import xyz.valnet.hadean.util.Layers;
|
||||
|
|
@ -24,9 +24,9 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea, ITransi
|
|||
|
||||
private IBuildLayerListener listener = null;
|
||||
|
||||
private BuildableMetadata.Type type = BuildableMetadata.Type.AREA;
|
||||
private BuildType type = BuildType.AREA;
|
||||
|
||||
public void setBuildType(BuildableMetadata.Type type) {
|
||||
public void setBuildType(BuildType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea, ITransi
|
|||
@Override
|
||||
public void update(float dTime) {
|
||||
if(listener == null) return;
|
||||
if(type == BuildableMetadata.Type.SINGLE && mouseDown) return;
|
||||
if(type == BuildType.SINGLE && mouseDown) return;
|
||||
|
||||
broadcastWorldCoords();
|
||||
}
|
||||
|
|
@ -96,7 +96,7 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea, ITransi
|
|||
mouseDown = true;
|
||||
x = worldcoords.x;
|
||||
y = worldcoords.y;
|
||||
if(type == BuildableMetadata.Type.SINGLE) {
|
||||
if(type == BuildType.SINGLE) {
|
||||
listener.build(x, y);
|
||||
}
|
||||
}
|
||||
|
|
@ -106,7 +106,7 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea, ITransi
|
|||
public void mouseUp(int button) {
|
||||
if(button == 0 && active && mouseDown) {
|
||||
mouseDown = false;
|
||||
if(type == BuildableMetadata.Type.AREA) {
|
||||
if(type == BuildType.AREA) {
|
||||
Vector2i worldcoords = camera.screen2world(App.mouseX, App.mouseY).asInt();
|
||||
int x1 = x;
|
||||
int y1 = y;
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ public class JobBoard extends GameObject {
|
|||
private List<Job> toRemove = new ArrayList<Job>();
|
||||
private Map<Pawn, Job> allocations = new HashMap<Pawn, Job>();
|
||||
|
||||
public Job postSimpleWorkJob(String name, IWorkable subject) {
|
||||
Job job = add(new Job(name));
|
||||
public Job postSimpleWorkJob(IWorkable subject) {
|
||||
Job job = add(new Job(subject.getJobName()));
|
||||
job.addStep(job.new Work(subject));
|
||||
postJob(job);
|
||||
return job;
|
||||
|
|
@ -236,5 +236,4 @@ public class JobBoard extends GameObject {
|
|||
"Taken Jobs: " + allocations.size() + "\n" + takenJobsString +
|
||||
"Impossible Jobs: " + impossibleJobs + "\n" + impossibleJobsString;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
package xyz.valnet.hadean.gameobjects.jobs;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.hadean.interfaces.IWorkable;
|
||||
|
||||
public class SimpleWorkable implements IWorkable {
|
||||
|
||||
private final String name;
|
||||
private float work = 0;
|
||||
private float MAX_WORK = 0;
|
||||
private IProgressUpdateCallback callback;
|
||||
private IGetPositionsFunction positions;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IGetPositionsFunction extends Serializable {
|
||||
public Vector2i[] get();
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IProgressUpdateCallback extends Serializable {
|
||||
public void progress(float progress);
|
||||
}
|
||||
|
||||
public SimpleWorkable(String name, float maxWork, IGetPositionsFunction positionsFunction, IProgressUpdateCallback callback) {
|
||||
this.name = name;
|
||||
this.MAX_WORK = maxWork;
|
||||
this.positions = positionsFunction;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doWork(float dTime) {
|
||||
work += dTime;
|
||||
callback.progress(work / MAX_WORK);
|
||||
return work >= MAX_WORK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector2i[] getWorkablePositions() {
|
||||
return positions.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getJobName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -124,7 +124,7 @@ public class Tile extends WorldObject implements IWorkable {
|
|||
pingNeighbors();
|
||||
|
||||
if(thing instanceof FarmPlot) {
|
||||
get(JobBoard.class).postSimpleWorkJob("Till Soil", this);
|
||||
get(JobBoard.class).postSimpleWorkJob(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import xyz.valnet.hadean.gameobjects.worldobjects.zones.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.interfaces.BuildableMetadata;
|
||||
import xyz.valnet.hadean.interfaces.BuildType;
|
||||
import xyz.valnet.hadean.interfaces.IBuildLayerListener;
|
||||
import xyz.valnet.hadean.interfaces.IBuildable;
|
||||
import xyz.valnet.hadean.interfaces.ISelectable;
|
||||
|
|
@ -60,16 +60,16 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IBuildLay
|
|||
public record BuildableRecord(
|
||||
String name,
|
||||
Constructor<? extends IBuildable> constructor,
|
||||
BuildableMetadata.Type type
|
||||
BuildType type
|
||||
) {}
|
||||
|
||||
public static void registerBuildable(Class<? extends IBuildable> clazz) {
|
||||
try {
|
||||
BuildableMetadata annotation = clazz.getAnnotation(BuildableMetadata.class);
|
||||
if(annotation == null) {
|
||||
DebugTab.log(clazz + " has no buildable data annotation");
|
||||
return;
|
||||
}
|
||||
// BuildableMetadata annotation = clazz.getAnnotation(BuildableMetadata.class);
|
||||
// if(annotation == null) {
|
||||
// DebugTab.log(clazz + " has no buildable data annotation");
|
||||
// return;
|
||||
// }
|
||||
|
||||
Constructor<? extends IBuildable> constructor = (Constructor<? extends IBuildable>) clazz.getConstructor();
|
||||
if(constructor.getParameterCount() != 0) {
|
||||
|
|
@ -77,9 +77,11 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IBuildLay
|
|||
return;
|
||||
}
|
||||
|
||||
String category = annotation.category();
|
||||
String name = annotation.name();
|
||||
BuildableMetadata.Type type = annotation.type();
|
||||
IBuildable buildable = constructor.newInstance();
|
||||
|
||||
String category = buildable.getBuildTabCategory();
|
||||
String name = buildable.getBuildTabName();
|
||||
BuildType type = buildable.getBuildType();
|
||||
|
||||
DebugTab.log("Added " + category + " / " + name);
|
||||
|
||||
|
|
|
|||
|
|
@ -43,4 +43,9 @@ public abstract class Buildable extends WorldObject implements IBuildable, ITile
|
|||
public Detail[] getDetails() {
|
||||
return new Detail[] {};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBuildTabName() {
|
||||
return getName();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ public class Tree extends WorldObject implements ITileThing, ISelectable, IWorka
|
|||
public void runAction(Action action) {
|
||||
if(action == ACTION_CHOP) {
|
||||
if(chopJob == null) {
|
||||
chopJob = get(JobBoard.class).postSimpleWorkJob("Chop Tree", this);
|
||||
chopJob = get(JobBoard.class).postSimpleWorkJob(this);
|
||||
} else {
|
||||
chopJob.close();
|
||||
chopJob = null;
|
||||
|
|
@ -125,7 +125,7 @@ public class Tree extends WorldObject implements ITileThing, ISelectable, IWorka
|
|||
|
||||
@Override
|
||||
public String getJobName() {
|
||||
return "Chop " + name;
|
||||
return "Chop Tree";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,143 +1,23 @@
|
|||
package xyz.valnet.hadean.gameobjects.worldobjects.constructions;
|
||||
|
||||
import xyz.valnet.engine.graphics.Color;
|
||||
import xyz.valnet.engine.graphics.Sprite;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.hadean.gameobjects.jobs.Job;
|
||||
import xyz.valnet.hadean.gameobjects.jobs.JobBoard;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.Buildable;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Item;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Log;
|
||||
import xyz.valnet.hadean.interfaces.BuildableMetadata;
|
||||
import xyz.valnet.hadean.interfaces.IItemReceiver;
|
||||
import xyz.valnet.hadean.interfaces.IWorkable;
|
||||
import xyz.valnet.hadean.util.Action;
|
||||
import xyz.valnet.hadean.interfaces.IItemPredicate;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
import xyz.valnet.hadean.util.Layers;
|
||||
import xyz.valnet.hadean.util.detail.BooleanDetail;
|
||||
import xyz.valnet.hadean.util.detail.Detail;
|
||||
import xyz.valnet.hadean.util.detail.ObjectDetail;
|
||||
import xyz.valnet.hadean.util.detail.PercentDetail;
|
||||
|
||||
@BuildableMetadata(category = "Furniture", name = "Bed", type = BuildableMetadata.Type.SINGLE)
|
||||
public class Bed extends Buildable implements IItemReceiver, IWorkable {
|
||||
|
||||
private int logs = 0;
|
||||
private float work = 0;
|
||||
private final float maxWork = 500;
|
||||
|
||||
private Job job = null;
|
||||
public class Bed extends Construction {
|
||||
|
||||
@Override
|
||||
protected Vector2i getDimensions() {
|
||||
return new Vector2i(1, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void create() {
|
||||
super.create();
|
||||
job = add(new Job("Build Bed"));
|
||||
job.addStep(job.new PickupItemByPredicate(Log.LOG_PREDICATE));
|
||||
job.addStep(job.new DropoffPredicateAtItemReceiver(this, Log.LOG_PREDICATE));
|
||||
job.addStep(job.new Work(this));
|
||||
get(JobBoard.class).postJob(job);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
super.render();
|
||||
Vector2i pos = getWorldPosition().xy();
|
||||
|
||||
if(isBuilt()) {
|
||||
camera.draw(Layers.GROUND, Assets.bed, pos.x, pos.y, 1, 2);
|
||||
} else {
|
||||
float p = work / maxWork;
|
||||
float b = 4;
|
||||
|
||||
Assets.flat.pushColor(Color.grey(b).withAlpha(0.5f));
|
||||
camera.draw(Layers.GROUND, Assets.bed, pos.x, pos.y, 1, 2);
|
||||
Assets.flat.popColor();
|
||||
|
||||
if(logs > 0) {
|
||||
camera.drawProgressBar(p, getWorldBox());
|
||||
}
|
||||
// Assets.uiFrame.draw(box.x -3, box.y - 6, (int)Math.round(lerp(0, box.z + 6, p)), 4);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Bed";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean receive(Item item) {
|
||||
if(item == null) return false;
|
||||
if(!item.matches(Log.LOG_PREDICATE)) return false;
|
||||
remove(item);
|
||||
logs ++;
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isBuilt() {
|
||||
return work >= maxWork;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doWork(float dTime) {
|
||||
work += dTime;
|
||||
return isBuilt();
|
||||
}
|
||||
|
||||
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),
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector2i[] getWorkablePositions() {
|
||||
return getBorders();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJobName() {
|
||||
return "Build Bed";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector2i[] getItemDropoffLocations() {
|
||||
return getBorders();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Action[] getActions() {
|
||||
return new Action[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runAction(Action action) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Detail[] getDetails() {
|
||||
return new Detail[] {
|
||||
new BooleanDetail("Built", isBuilt()),
|
||||
new PercentDetail("Work", work / maxWork, 1),
|
||||
new ObjectDetail<Integer>("Logs", logs),
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWalkable() {
|
||||
return false;
|
||||
|
|
@ -152,4 +32,19 @@ public class Bed extends Buildable implements IItemReceiver, IWorkable {
|
|||
public void onRemove() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IItemPredicate getBuildingMaterial() {
|
||||
return Log.LOG_PREDICATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getBuildingMaterialCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sprite getDefaultSprite() {
|
||||
return Assets.bed;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,9 +11,11 @@ import xyz.valnet.hadean.gameobjects.jobs.JobBoard;
|
|||
import xyz.valnet.hadean.gameobjects.worldobjects.Buildable;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Boulder;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Item;
|
||||
import xyz.valnet.hadean.interfaces.BuildType;
|
||||
import xyz.valnet.hadean.interfaces.IItemPredicate;
|
||||
import xyz.valnet.hadean.interfaces.IItemReceiver;
|
||||
import xyz.valnet.hadean.interfaces.IWorkable;
|
||||
import xyz.valnet.hadean.util.Action;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
import xyz.valnet.hadean.util.Layers;
|
||||
|
||||
|
|
@ -47,7 +49,6 @@ public abstract class Construction extends Buildable implements IItemReceiver {
|
|||
}
|
||||
if(!isBuilt()) {
|
||||
Job job = get(JobBoard.class).postSimpleWorkJob(
|
||||
"Build " + getName(),
|
||||
new IWorkable() {
|
||||
@Override
|
||||
public boolean doWork(float dTime) {
|
||||
|
|
@ -77,7 +78,7 @@ public abstract class Construction extends Buildable implements IItemReceiver {
|
|||
return 1000;
|
||||
}
|
||||
|
||||
public boolean isBuilt() {
|
||||
public final boolean isBuilt() {
|
||||
return work >= getMaxWork();
|
||||
}
|
||||
|
||||
|
|
@ -112,7 +113,7 @@ public abstract class Construction extends Buildable implements IItemReceiver {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean receive(Item item) {
|
||||
public final boolean receive(Item item) {
|
||||
if(item == null) return false;
|
||||
if(!item.matches(Boulder.BOULDER_PREDICATE)) return false;
|
||||
remove(item);
|
||||
|
|
@ -125,7 +126,6 @@ public abstract class Construction extends Buildable implements IItemReceiver {
|
|||
return getWorldBox().toXYWH().asInt().getBorders();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
Sprite sprite = getDefaultSprite();
|
||||
|
|
@ -135,12 +135,35 @@ public abstract class Construction extends Buildable implements IItemReceiver {
|
|||
float b = 4;
|
||||
|
||||
Assets.flat.pushColor(Color.grey(b).withAlpha(0.5f));
|
||||
camera.draw(Layers.GROUND, Assets.quarry, getWorldPosition());
|
||||
camera.draw(Layers.GROUND, getDefaultSprite(), getWorldPosition());
|
||||
Assets.flat.popColor();
|
||||
|
||||
camera.drawProgressBar(getBuildProgress(), getWorldBox());
|
||||
if(getBuildProgress() > 0) {
|
||||
camera.drawProgressBar(getBuildProgress(), getWorldBox());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Sprite getDefaultSprite();
|
||||
|
||||
@Override
|
||||
public BuildType getBuildType() {
|
||||
return BuildType.SINGLE;
|
||||
}
|
||||
@Override
|
||||
public String getBuildTabCategory() {
|
||||
return "Buildings";
|
||||
}
|
||||
@Override
|
||||
public String getBuildTabName() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Action[] getActions() {
|
||||
return new Action[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runAction(Action action) {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,14 @@
|
|||
package xyz.valnet.hadean.gameobjects.worldobjects.constructions;
|
||||
|
||||
import xyz.valnet.engine.graphics.Color;
|
||||
import xyz.valnet.engine.graphics.Sprite;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.hadean.gameobjects.jobs.Job;
|
||||
import xyz.valnet.hadean.gameobjects.jobs.JobBoard;
|
||||
import xyz.valnet.hadean.gameobjects.jobs.SimpleWorkable;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Boulder;
|
||||
import xyz.valnet.hadean.interfaces.BuildableMetadata;
|
||||
import xyz.valnet.hadean.interfaces.IItemPredicate;
|
||||
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 Construction {
|
||||
|
||||
private Job digJob = null;
|
||||
|
|
@ -29,32 +25,14 @@ public class Quarry extends Construction {
|
|||
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() {
|
||||
digJob = get(JobBoard.class).postSimpleWorkJob(new SimpleWorkable("Mine at Quarry", 5000, () -> {
|
||||
return new Vector2i[] {
|
||||
getWorldPosition().xy().south().east()
|
||||
};
|
||||
}, (progress) -> {
|
||||
digProgress = progress;
|
||||
}));
|
||||
|
||||
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();
|
||||
|
|
|
|||
|
|
@ -2,48 +2,18 @@ package xyz.valnet.hadean.gameobjects.worldobjects.constructions;
|
|||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import xyz.valnet.engine.graphics.Color;
|
||||
import xyz.valnet.engine.graphics.Sprite;
|
||||
import xyz.valnet.engine.graphics.Tile16.Direction;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.hadean.HadeanGame;
|
||||
import xyz.valnet.hadean.gameobjects.jobs.Job;
|
||||
import xyz.valnet.hadean.gameobjects.jobs.JobBoard;
|
||||
import xyz.valnet.hadean.gameobjects.terrain.Tile;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.Buildable;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Boulder;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Item;
|
||||
import xyz.valnet.hadean.interfaces.BuildableMetadata;
|
||||
import xyz.valnet.hadean.interfaces.IItemReceiver;
|
||||
import xyz.valnet.hadean.interfaces.BuildType;
|
||||
import xyz.valnet.hadean.interfaces.IItemPredicate;
|
||||
import xyz.valnet.hadean.interfaces.IPingable;
|
||||
import xyz.valnet.hadean.interfaces.IWorkable;
|
||||
import xyz.valnet.hadean.util.Action;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
import xyz.valnet.hadean.util.Layers;
|
||||
import xyz.valnet.hadean.util.detail.BooleanDetail;
|
||||
import xyz.valnet.hadean.util.detail.Detail;
|
||||
import xyz.valnet.hadean.util.detail.ObjectDetail;
|
||||
import xyz.valnet.hadean.util.detail.PercentDetail;
|
||||
|
||||
@BuildableMetadata(category = "Structure", name = "Wall", type = BuildableMetadata.Type.SINGLE)
|
||||
public class Wall extends Buildable implements IItemReceiver, IWorkable, IPingable {
|
||||
|
||||
private int boulders = 0;
|
||||
private float work = 0;
|
||||
private final float maxWork = 500;
|
||||
|
||||
private Job job = null;
|
||||
|
||||
@Override
|
||||
protected void create() {
|
||||
super.create();
|
||||
job = add(new Job("Build Wall"));
|
||||
if(!HadeanGame.debugView) {
|
||||
job.addStep(job.new PickupItemByPredicate(Boulder.BOULDER_PREDICATE));
|
||||
job.addStep(job.new DropoffPredicateAtItemReceiver(this, Boulder.BOULDER_PREDICATE));
|
||||
}
|
||||
job.addStep(job.new Work(this));
|
||||
get(JobBoard.class).postJob(job);
|
||||
}
|
||||
public class Wall extends Construction implements IPingable {
|
||||
|
||||
@Override
|
||||
protected void start() {
|
||||
|
|
@ -51,79 +21,11 @@ public class Wall extends Buildable implements IItemReceiver, IWorkable, IPingab
|
|||
ping();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
super.render();
|
||||
Vector2i pos = getWorldPosition().xy();
|
||||
|
||||
if(isBuilt()) {
|
||||
float b = 0.7f;
|
||||
Assets.flat.pushColor(Color.grey(b));
|
||||
camera.draw(Layers.GROUND, Assets.wall.getTextureFor(wallSides), pos.x, pos.y);
|
||||
Assets.flat.popColor();
|
||||
} else {
|
||||
float p = work / maxWork;
|
||||
float b = 4;
|
||||
|
||||
Assets.flat.pushColor(Color.grey(b).withAlpha(0.5f));
|
||||
camera.draw(Layers.GROUND, Assets.wall.getTextureFor(wallSides), pos.x, pos.y);
|
||||
Assets.flat.popColor();
|
||||
|
||||
if(boulders > 0) {
|
||||
camera.drawProgressBar(p, getWorldBox());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Wall";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean receive(Item item) {
|
||||
if(item == null) return false;
|
||||
if(!item.matches(Boulder.BOULDER_PREDICATE)) return false;
|
||||
remove(item);
|
||||
boulders ++;
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isBuilt() {
|
||||
return work >= maxWork;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doWork(float dTime) {
|
||||
work += dTime;
|
||||
return isBuilt();
|
||||
}
|
||||
|
||||
private Vector2i[] getBorders() {
|
||||
Vector2i pos = getWorldPosition().xy();
|
||||
return new Vector2i[] {
|
||||
pos.north(),
|
||||
pos.east(),
|
||||
pos.south(),
|
||||
pos.west()
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector2i[] getWorkablePositions() {
|
||||
return getBorders();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJobName() {
|
||||
return "Build Wall";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector2i[] getItemDropoffLocations() {
|
||||
return getBorders();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Action[] getActions() {
|
||||
return new Action[0];
|
||||
|
|
@ -134,19 +36,6 @@ public class Wall extends Buildable implements IItemReceiver, IWorkable, IPingab
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Detail[] getDetails() {
|
||||
return new Detail[] {
|
||||
new BooleanDetail("Built", isBuilt()),
|
||||
new PercentDetail("Work", work / maxWork, 1),
|
||||
new ObjectDetail<Integer>("Logs", boulders),
|
||||
new BooleanDetail("North", wallSides.contains(Direction.NORTH)),
|
||||
new BooleanDetail("East", wallSides.contains(Direction.EAST)),
|
||||
new BooleanDetail("South", wallSides.contains(Direction.SOUTH)),
|
||||
new BooleanDetail("West", wallSides.contains(Direction.WEST)),
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWalkable() {
|
||||
return !isBuilt();
|
||||
|
|
@ -181,4 +70,34 @@ public class Wall extends Buildable implements IItemReceiver, IWorkable, IPingab
|
|||
Tile west = terrain.getTile(pos.x + 1, pos.y);
|
||||
if(west != null && west.has(Wall.class)) wallSides.add(Direction.WEST);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBuildTabCategory() {
|
||||
return "Structure";
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuildType getBuildType() {
|
||||
return BuildType.LINE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IItemPredicate getBuildingMaterial() {
|
||||
return Boulder.BOULDER_PREDICATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getBuildingMaterialCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sprite getDefaultSprite() {
|
||||
return Assets.wall.getTextureFor(EnumSet.noneOf(Direction.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getMaxWork() {
|
||||
return super.getMaxWork();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,15 +3,12 @@ package xyz.valnet.hadean.gameobjects.worldobjects.zones;
|
|||
import xyz.valnet.engine.graphics.Color;
|
||||
import xyz.valnet.engine.math.Vector4i;
|
||||
import xyz.valnet.hadean.gameobjects.terrain.Tile;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.Buildable;
|
||||
import xyz.valnet.hadean.interfaces.BuildableMetadata;
|
||||
import xyz.valnet.hadean.util.Action;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
import xyz.valnet.hadean.util.Layers;
|
||||
import xyz.valnet.hadean.util.detail.Detail;
|
||||
|
||||
@BuildableMetadata(category = "Zones", name = "Farm Plot")
|
||||
public class FarmPlot extends Buildable {
|
||||
public class FarmPlot extends Zone {
|
||||
|
||||
@Override
|
||||
public void renderAlpha() {
|
||||
|
|
|
|||
|
|
@ -6,16 +6,13 @@ import xyz.valnet.engine.graphics.Color;
|
|||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.math.Vector4i;
|
||||
import xyz.valnet.hadean.gameobjects.terrain.Tile;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.Buildable;
|
||||
import xyz.valnet.hadean.interfaces.BuildableMetadata;
|
||||
import xyz.valnet.hadean.interfaces.ISelectable;
|
||||
import xyz.valnet.hadean.util.Action;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
import xyz.valnet.hadean.util.Layers;
|
||||
import xyz.valnet.hadean.util.detail.Detail;
|
||||
|
||||
@BuildableMetadata(category = "Zones", name = "Stockpile")
|
||||
public class Stockpile extends Buildable {
|
||||
public class Stockpile extends Zone {
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
package xyz.valnet.hadean.gameobjects.worldobjects.zones;
|
||||
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.Buildable;
|
||||
import xyz.valnet.hadean.interfaces.BuildType;
|
||||
|
||||
public abstract class Zone extends Buildable {
|
||||
|
||||
@Override
|
||||
public String getBuildTabCategory() {
|
||||
return "Zones";
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuildType getBuildType() {
|
||||
return BuildType.AREA;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWalkable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package xyz.valnet.hadean.interfaces;
|
||||
|
||||
public enum BuildType {
|
||||
AREA,
|
||||
LINE,
|
||||
SINGLE
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
package xyz.valnet.hadean.interfaces;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface BuildableMetadata {
|
||||
|
||||
public enum Type {
|
||||
AREA,
|
||||
LINE,
|
||||
SINGLE
|
||||
}
|
||||
|
||||
public String name();
|
||||
public String category();
|
||||
public Type type() default Type.AREA;
|
||||
}
|
||||
|
|
@ -3,6 +3,11 @@ package xyz.valnet.hadean.interfaces;
|
|||
public interface IBuildable {
|
||||
|
||||
public void buildAt(int x, int y, int w, int h);
|
||||
@Deprecated
|
||||
public void buildAt(int x, int y);
|
||||
|
||||
public String getBuildTabCategory();
|
||||
public BuildType getBuildType();
|
||||
public String getBuildTabName();
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue