farm plots & slightly improved hauling

pull/1/head
Valerie 2022-06-02 02:29:41 -04:00
parent cc77a0997e
commit a0604b4555
8 changed files with 296 additions and 9 deletions

View File

@ -124,11 +124,11 @@ public class JobBoard extends GameObject {
String availableJobsString = "";
for(Entry<IWorker, IJob> allocation : allocations.entrySet()) {
takenJobsString += " " + allocation.getKey().getName() + ": " + allocation.getValue().getName() + "\n";
takenJobsString += " " + allocation.getKey().getName() + ": " + allocation.getValue().getJobName() + "\n";
}
for(IJob job : availableJobs) {
availableJobsString += " " + job.getName() + "\n";
availableJobsString += " " + job.getJobName() + "\n";
}
return "Available Jobs: " + availableJobs.size() + "\n" + availableJobsString +

View File

@ -10,10 +10,10 @@ import xyz.valnet.engine.math.Vector4f;
import xyz.valnet.engine.scenegraph.IMouseCaptureArea;
import xyz.valnet.hadean.gameobjects.BottomBar;
import xyz.valnet.hadean.gameobjects.Camera;
import xyz.valnet.hadean.gameobjects.Stockpile;
import xyz.valnet.hadean.gameobjects.Terrain;
import xyz.valnet.hadean.gameobjects.inputlayer.BuildLayer;
import xyz.valnet.hadean.gameobjects.inputlayer.Selection;
import xyz.valnet.hadean.gameobjects.worldobjects.FarmPlot;
import xyz.valnet.hadean.interfaces.IBuildLayerListener;
import xyz.valnet.hadean.interfaces.ISelectable;
import xyz.valnet.hadean.interfaces.ISelectionChangeListener;
@ -71,8 +71,8 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap
public void select(float nx, float ny, float nw, float nh) {
x = (int)Math.floor(nx);
y = (int)Math.floor(ny);
ITileThing stockpile = new Stockpile(x, y);
terrain.getTile(x, y).placeThing(stockpile);
ITileThing thing = new FarmPlot(x, y);
terrain.getTile(x, y).placeThing(thing);
opened.set(false);
}

View File

@ -0,0 +1,157 @@
package xyz.valnet.hadean.gameobjects.worldobjects;
import xyz.valnet.engine.graphics.Drawing;
import xyz.valnet.engine.math.Vector2i;
import xyz.valnet.engine.math.Vector4f;
import xyz.valnet.hadean.gameobjects.JobBoard;
import xyz.valnet.hadean.interfaces.ISelectable;
import xyz.valnet.hadean.interfaces.ITileThing;
import xyz.valnet.hadean.interfaces.IWorkable;
import xyz.valnet.hadean.util.Action;
import xyz.valnet.hadean.util.Assets;
import xyz.valnet.hadean.util.Layers;
public class FarmPlot extends WorldObject implements IWorkable, ISelectable, ITileThing {
private float progress = 0f;
private int stage = 0;
private boolean planted = false;
private boolean mature = false;
private static int STAGE_LENGTH = 1000;
private static int MAX_STAGES = 4;
private JobBoard board;
public FarmPlot(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public void render() {
Drawing.setLayer(Layers.GROUND);
camera.draw(Assets.farmPlot, x, y);
if(planted) {
if(stage > 1) {
Drawing.setLayer(Layers.AIR);
camera.draw(Assets.growingRice[stage], x, y - 1, 1, 2);
} else {
camera.draw(Assets.growingRice[stage], x, y);
}
}
}
@Override
public void update(float dTime) {
super.update(dTime);
if(stage == MAX_STAGES - 1) {
return;
} if(planted) {
if(Math.random() > 0.95f) {
progress += 10;
if(progress >= STAGE_LENGTH) {
stage ++;
progress = 0;
if(stage == MAX_STAGES - 1) {
mature = true;
board.postJob(this);
}
}
}
} else if (progress >= STAGE_LENGTH) {
planted = true;
progress = 0;
}
}
@Override
public void start() {
super.start();
board = get(JobBoard.class);
board.postJob(this);
}
@Override
public boolean hasWork() {
return !planted || mature;
}
@Override
public Vector2i[] getWorablePositions() {
return new Vector2i[] {
new Vector2i((int) x, (int) y + 1),
new Vector2i((int) x, (int) y - 1),
new Vector2i((int) x + 1, (int) y),
new Vector2i((int) x - 1, (int) y)
};
}
@Override
public Vector2i getLocation() {
return new Vector2i((int) x, (int) y);
}
@Override
public String getJobName() {
return planted ? "Harvest Rice" : "Plant Rice";
}
@Override
public Vector4f getWorldBox() {
return new Vector4f(x, y, x + 1, y + 1);
}
@Override
public Action[] getActions() {
return new Action[] {};
}
@Override
public void runAction(Action action) {}
@Override
public String details() {
return "Planted | " + planted + "\n" +
"Stage | " + stage + "\n" +
"Progress | " + String.format("%.2f", (progress / STAGE_LENGTH) * 100) + "%";
}
@Override
public void doWork() {
progress ++;
if(mature && progress >= STAGE_LENGTH) {
mature = false;
planted = false;
stage = 0;
if(Math.random() < 0.3) {
getTile().placeThing(new Rice((int)x, (int)y));
}
}
}
@Override
public boolean isWalkable() {
return true;
}
@Override
public boolean shouldRemove() {
return false;
}
@Override
public void onRemove() {
}
@Override
public void updatePosition(int x, int y) {}
}

View File

@ -134,7 +134,7 @@ public class Log extends WorldObject implements ITileThing, ISelectable, IHaulab
}
@Override
public String getName() {
public String getJobName() {
return "Haul Log";
}

View File

@ -279,7 +279,7 @@ public class Pawn extends WorldObject implements ISelectable, IWorker {
@Override
public String details() {
IJob currentJob = jobboard.getJob(this);
String jobString = currentJob == null ? "No Job" : currentJob.getName();
String jobString = currentJob == null ? "No Job" : currentJob.getJobName();
return "" + name + "\n" +
"Held | " + getCarriedName() + "\n" +
"Job | " + jobString + "\n" +

View File

@ -0,0 +1,130 @@
package xyz.valnet.hadean.gameobjects.worldobjects;
import xyz.valnet.engine.graphics.Drawing;
import xyz.valnet.engine.math.Vector2i;
import xyz.valnet.engine.math.Vector4f;
import xyz.valnet.hadean.gameobjects.JobBoard;
import xyz.valnet.hadean.gameobjects.Stockpile;
import xyz.valnet.hadean.gameobjects.Tile;
import xyz.valnet.hadean.interfaces.IHaulable;
import xyz.valnet.hadean.interfaces.ISelectable;
import xyz.valnet.hadean.interfaces.ITileThing;
import xyz.valnet.hadean.util.Action;
import xyz.valnet.hadean.util.Assets;
import xyz.valnet.hadean.util.Layers;
import xyz.valnet.hadean.util.SmartBoolean;
import xyz.valnet.hadean.util.SmartBoolean.IListener;
public class Rice extends WorldObject implements ITileThing, ISelectable {
// private SmartBoolean haul;
private JobBoard jobboard;
@Override
public void start() {
super.start();
jobboard = get(JobBoard.class);
Rice that = this;
// haul = new SmartBoolean(false, new IListener() {
// @Override
// public void rise() {
// jobboard.postJob(that);
// }
// @Override
// public void fall() {
// jobboard.rescindJob(that);
// }
// });
}
public Rice(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public void render() {
Drawing.setLayer(Layers.AIR);
camera.draw(Assets.riceBag, x, y);
}
@Override
public boolean isWalkable() {
return true;
}
@Override
public boolean shouldRemove() {
return false;
}
@Override
public void onRemove() {}
@Override
public Vector4f getWorldBox() {
return new Vector4f(x, y, x + 1, y + 1);
}
@Override
public Action[] getActions() {
return new Action[] {};
}
@Override
public void runAction(Action action) {
}
@Override
public String details() {
return "Bag of Rice";
}
// @Override
// public boolean hasWork() {
// return haul.value();
// }
// @Override
// public Vector2i[] getWorablePositions() {
// return new Vector2i[] {
// new Vector2i((int)x + 1, (int)y),
// new Vector2i((int)x - 1, (int)y),
// new Vector2i((int)x, (int)y + 1),
// new Vector2i((int)x, (int)y - 1)
// };
// }
// @Override
// public Vector2i getLocation() {
// return new Vector2i((int)x, (int)y);
// }
// @Override
// public Log take() {
// haul.set(false);
// Tile tile = terrain.getTile((int)x, (int)y);
// tile.remove(this);
// return this;
// }
// @Override
// public Tile getDestination() {
// return get(Stockpile.class).getTile();
// }
@Override
public void updatePosition(int x, int y) {
this.x = x;
this.y = y;
}
// @Override
// public String getJobName() {
// return "Haul Log";
// }
}

View File

@ -137,7 +137,7 @@ public class Tree extends WorldObject implements ITileThing, ISelectable, IWorka
}
@Override
public String getName() {
public String getJobName() {
return "Chop " + name;
}
}

View File

@ -6,5 +6,5 @@ public interface IJob {
public boolean hasWork();
public Vector2i[] getWorablePositions();
public Vector2i getLocation();
public String getName();
public String getJobName();
}