stockpiles
parent
d8352fbc9a
commit
064326a023
10
idea.md
10
idea.md
|
|
@ -23,4 +23,12 @@ wishes to do work, and the job will be released.
|
|||
|
||||
# IMouseCaptureArea
|
||||
|
||||
its just a name, but reframe current mouse shit to it.
|
||||
its just a name, but reframe current mouse shit to it.
|
||||
|
||||
# Create class for x/y positioned things.
|
||||
|
||||
can be STUPID SIMPLE TO START
|
||||
|
||||
# Convert ITileThing to class
|
||||
|
||||
getTile() needs to be a common method.
|
||||
|
|
@ -10,6 +10,7 @@ import xyz.valnet.engine.math.Vector4f;
|
|||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.hadean.gameobjects.Camera;
|
||||
import xyz.valnet.hadean.gameobjects.ITileThing;
|
||||
import xyz.valnet.hadean.gameobjects.Log;
|
||||
import xyz.valnet.hadean.gameobjects.Tree;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
|
||||
|
|
@ -37,14 +38,21 @@ public class Tile extends GameObject {
|
|||
public void start() {
|
||||
camera = get(Camera.class);
|
||||
|
||||
if(Math.random() > 0.90) {
|
||||
if(Math.random() > 0.99) {
|
||||
Tree tree = new Tree(x, y);
|
||||
stuff.add(tree);
|
||||
add(tree);
|
||||
}
|
||||
|
||||
if(Math.random() > 0.98) {
|
||||
Log log = new Log(x, y);
|
||||
stuff.add(log);
|
||||
add(log);
|
||||
}
|
||||
}
|
||||
|
||||
public void placeThing(ITileThing thing) {
|
||||
thing.updatePosition(x, y);
|
||||
stuff.add(thing);
|
||||
if(thing instanceof GameObject) {
|
||||
add((GameObject)thing);
|
||||
|
|
|
|||
|
|
@ -4,4 +4,5 @@ public interface ITileThing {
|
|||
public boolean isWalkable();
|
||||
public boolean shouldRemove();
|
||||
public void onRemove();
|
||||
public void updatePosition(int x, int y);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,12 +5,14 @@ import xyz.valnet.engine.math.Vector2i;
|
|||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.hadean.Layers;
|
||||
import xyz.valnet.hadean.Tile;
|
||||
import xyz.valnet.hadean.util.Action;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
|
||||
public class Log extends GameObject implements ITileThing, ISelectable, IHaulable, IWorkable {
|
||||
public class Log extends GameObject implements ITileThing, ISelectable, IHaulable {
|
||||
|
||||
private Camera camera;
|
||||
private Terrain terrain;
|
||||
|
||||
private int x, y;
|
||||
|
||||
|
|
@ -24,6 +26,7 @@ public class Log extends GameObject implements ITileThing, ISelectable, IHaulabl
|
|||
@Override
|
||||
public void start() {
|
||||
camera = get(Camera.class);
|
||||
terrain = get(Terrain.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -54,13 +57,21 @@ public class Log extends GameObject implements ITileThing, ISelectable, IHaulabl
|
|||
return new Vector4f(x, y, x + 1, y + 1);
|
||||
}
|
||||
|
||||
private static final Action ACTION_HAUL = new Action("Haul");
|
||||
|
||||
@Override
|
||||
public Action[] getActions() {
|
||||
return new Action[] {};
|
||||
return new Action[] {
|
||||
ACTION_HAUL
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runAction(Action action) {}
|
||||
public void runAction(Action action) {
|
||||
if(action == ACTION_HAUL) {
|
||||
haul = !haul;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String details() {
|
||||
|
|
@ -69,26 +80,41 @@ public class Log extends GameObject implements ITileThing, ISelectable, IHaulabl
|
|||
|
||||
@Override
|
||||
public boolean hasWork() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
return haul;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector2i[] getWorablePositions() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doWork() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
return new Vector2i[] {
|
||||
new Vector2i(x + 1, y),
|
||||
new Vector2i(x - 1, y),
|
||||
new Vector2i(x, y + 1),
|
||||
new Vector2i(x, y - 1)
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector2i getLocation() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return new Vector2i(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Log take() {
|
||||
haul = false;
|
||||
Tile tile = terrain.getTile(x, 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,46 +112,76 @@ public class Pawn extends GameObject implements ISelectable {
|
|||
@Override
|
||||
public void update(float dTime) {
|
||||
|
||||
// then, try to do work!
|
||||
if(currentJob != null && currentJob.hasWork()) {
|
||||
if(getCurrentPos().isOneOf(currentJob.getWorablePositions())) {
|
||||
currentJob.doWork();
|
||||
// cleanup current job...
|
||||
if(currentJob != null && !currentJob.hasWork()) {
|
||||
currentJob = null;
|
||||
}
|
||||
|
||||
// if you dont have a job
|
||||
if(currentJob == null && carrying == null) {
|
||||
// and its a frame to try and get one...
|
||||
if(counter == 0) {
|
||||
tryStartWork();
|
||||
}
|
||||
|
||||
// if we still dont have a job, try path to wander.
|
||||
if(currentJob == null && (path == null || path.isComplete())) {
|
||||
newPath();
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO possibly take care of needs here idk
|
||||
}
|
||||
|
||||
// firstly, TRY PATHING.
|
||||
if(path != null && !path.isComplete()) {
|
||||
move();
|
||||
return;
|
||||
}
|
||||
|
||||
// then try to get work?!
|
||||
if(counter == 0) {
|
||||
currentJob = null;
|
||||
tryStartWork();
|
||||
|
||||
|
||||
if(currentJob == null && (path == null || path.isComplete())) {
|
||||
// then wander...
|
||||
newPath();
|
||||
// try to do your work!
|
||||
if(currentJob != null && currentJob.hasWork()) {
|
||||
if(getCurrentPos().isOneOf(currentJob.getWorablePositions())) {
|
||||
if(currentJob instanceof IWorkable) {
|
||||
((IWorkable)currentJob).doWork();
|
||||
} else if (currentJob instanceof IHaulable) {
|
||||
if(carrying == null) {
|
||||
IHaulable thing = (IHaulable) currentJob;
|
||||
Log log = thing.take();
|
||||
carrying = log;
|
||||
Vector2i dst = thing.getDestination().getCoords();
|
||||
path = pathfinder.getPath((int)x, (int)y, dst.x, dst.y);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
} else if (carrying != null) {
|
||||
// if we're at our destination, or if for some reason we just like
|
||||
// didnt make it? but our path is so totally completed...
|
||||
if(carrying.getDestination() == this.getTile() || path == null || path.isComplete()) {
|
||||
this.getTile().placeThing((ITileThing) carrying);
|
||||
carrying = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Tile getTile() {
|
||||
return terrain.getTile((int) x, (int) y);
|
||||
}
|
||||
|
||||
private Vector2i getCurrentPos() {
|
||||
return new Vector2i((int)Math.floor(x), (int)Math.floor(y));
|
||||
}
|
||||
|
||||
private IWorkable currentJob;
|
||||
private IJob currentJob;
|
||||
|
||||
private void tryStartWork() {
|
||||
List<IWorkable> workables = getAll(IWorkable.class)
|
||||
List<IJob> workables = getAll(IJob.class)
|
||||
.stream()
|
||||
.filter(workable -> workable.hasWork())
|
||||
.sorted(new Comparator<IWorkable>() {
|
||||
.sorted(new Comparator<IJob>() {
|
||||
@Override
|
||||
public int compare(IWorkable a, IWorkable b) {
|
||||
public int compare(IJob a, IJob b) {
|
||||
float distA = a.getLocation().distanceTo((int)x, (int)y);
|
||||
float distB = b.getLocation().distanceTo((int)x, (int)y);
|
||||
if(distA > distB) return -1;
|
||||
|
|
@ -162,7 +192,7 @@ public class Pawn extends GameObject implements ISelectable {
|
|||
.toList();
|
||||
|
||||
if(workables.size() > 0) {
|
||||
for(IWorkable job : workables) {
|
||||
for(IJob job : workables) {
|
||||
if(!job.hasWork()) continue;
|
||||
Vector2i[] workablePositions = job.getWorablePositions();
|
||||
Path bestPathToJob = pathfinder.getBestPath(
|
||||
|
|
@ -264,9 +294,15 @@ public class Pawn extends GameObject implements ISelectable {
|
|||
}
|
||||
}
|
||||
|
||||
private String getCarriedName() {
|
||||
if(carrying == null) return "Nothing";
|
||||
String[] names = carrying.getClass().getName().split("\\.");
|
||||
return names[names.length - 1];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String details() {
|
||||
return "IM A PAWNNNNN!!!!";
|
||||
return "Held | " + getCarriedName();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,10 +55,13 @@ public class Selection extends GameObject implements IMouseListener {
|
|||
}
|
||||
}
|
||||
}
|
||||
for(ISelectable removeMe : toRemove) {
|
||||
selected.remove(removeMe);
|
||||
if(!toRemove.isEmpty()) {
|
||||
for(ISelectable removeMe : toRemove) {
|
||||
selected.remove(removeMe);
|
||||
}
|
||||
toRemove.clear();
|
||||
broadcastSelectionChanged();
|
||||
}
|
||||
toRemove.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import xyz.valnet.engine.graphics.Drawing;
|
|||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.hadean.Layers;
|
||||
import xyz.valnet.hadean.Tile;
|
||||
import xyz.valnet.hadean.util.Action;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
|
||||
|
|
@ -11,6 +12,7 @@ public class Stockpile extends GameObject implements ITileThing, ISelectable {
|
|||
|
||||
private int x, y;
|
||||
private Camera camera;
|
||||
private Terrain terrain;
|
||||
|
||||
public Stockpile(int x, int y) {
|
||||
this.x = x;
|
||||
|
|
@ -20,6 +22,7 @@ public class Stockpile extends GameObject implements ITileThing, ISelectable {
|
|||
@Override
|
||||
public void start() {
|
||||
camera = get(Camera.class);
|
||||
terrain = get(Terrain.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -61,5 +64,15 @@ public class Stockpile extends GameObject implements ITileThing, ISelectable {
|
|||
public String details() {
|
||||
return "";
|
||||
}
|
||||
|
||||
public Tile getTile() {
|
||||
return terrain.getTile(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePosition(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -122,4 +122,10 @@ public class Tree extends GameObject implements ITileThing, ISelectable, IWorkab
|
|||
public Vector2i getLocation() {
|
||||
return new Vector2i(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePosition(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue