stockpiles
parent
d8352fbc9a
commit
064326a023
8
idea.md
8
idea.md
|
|
@ -24,3 +24,11 @@ wishes to do work, and the job will be released.
|
||||||
# IMouseCaptureArea
|
# 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.engine.scenegraph.GameObject;
|
||||||
import xyz.valnet.hadean.gameobjects.Camera;
|
import xyz.valnet.hadean.gameobjects.Camera;
|
||||||
import xyz.valnet.hadean.gameobjects.ITileThing;
|
import xyz.valnet.hadean.gameobjects.ITileThing;
|
||||||
|
import xyz.valnet.hadean.gameobjects.Log;
|
||||||
import xyz.valnet.hadean.gameobjects.Tree;
|
import xyz.valnet.hadean.gameobjects.Tree;
|
||||||
import xyz.valnet.hadean.util.Assets;
|
import xyz.valnet.hadean.util.Assets;
|
||||||
|
|
||||||
|
|
@ -37,14 +38,21 @@ public class Tile extends GameObject {
|
||||||
public void start() {
|
public void start() {
|
||||||
camera = get(Camera.class);
|
camera = get(Camera.class);
|
||||||
|
|
||||||
if(Math.random() > 0.90) {
|
if(Math.random() > 0.99) {
|
||||||
Tree tree = new Tree(x, y);
|
Tree tree = new Tree(x, y);
|
||||||
stuff.add(tree);
|
stuff.add(tree);
|
||||||
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) {
|
public void placeThing(ITileThing thing) {
|
||||||
|
thing.updatePosition(x, y);
|
||||||
stuff.add(thing);
|
stuff.add(thing);
|
||||||
if(thing instanceof GameObject) {
|
if(thing instanceof GameObject) {
|
||||||
add((GameObject)thing);
|
add((GameObject)thing);
|
||||||
|
|
|
||||||
|
|
@ -4,4 +4,5 @@ public interface ITileThing {
|
||||||
public boolean isWalkable();
|
public boolean isWalkable();
|
||||||
public boolean shouldRemove();
|
public boolean shouldRemove();
|
||||||
public void onRemove();
|
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.math.Vector4f;
|
||||||
import xyz.valnet.engine.scenegraph.GameObject;
|
import xyz.valnet.engine.scenegraph.GameObject;
|
||||||
import xyz.valnet.hadean.Layers;
|
import xyz.valnet.hadean.Layers;
|
||||||
|
import xyz.valnet.hadean.Tile;
|
||||||
import xyz.valnet.hadean.util.Action;
|
import xyz.valnet.hadean.util.Action;
|
||||||
import xyz.valnet.hadean.util.Assets;
|
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 Camera camera;
|
||||||
|
private Terrain terrain;
|
||||||
|
|
||||||
private int x, y;
|
private int x, y;
|
||||||
|
|
||||||
|
|
@ -24,6 +26,7 @@ public class Log extends GameObject implements ITileThing, ISelectable, IHaulabl
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
camera = get(Camera.class);
|
camera = get(Camera.class);
|
||||||
|
terrain = get(Terrain.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -54,13 +57,21 @@ public class Log extends GameObject implements ITileThing, ISelectable, IHaulabl
|
||||||
return new Vector4f(x, y, x + 1, y + 1);
|
return new Vector4f(x, y, x + 1, y + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final Action ACTION_HAUL = new Action("Haul");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Action[] getActions() {
|
public Action[] getActions() {
|
||||||
return new Action[] {};
|
return new Action[] {
|
||||||
|
ACTION_HAUL
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void runAction(Action action) {}
|
public void runAction(Action action) {
|
||||||
|
if(action == ACTION_HAUL) {
|
||||||
|
haul = !haul;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String details() {
|
public String details() {
|
||||||
|
|
@ -69,26 +80,41 @@ public class Log extends GameObject implements ITileThing, ISelectable, IHaulabl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasWork() {
|
public boolean hasWork() {
|
||||||
// TODO Auto-generated method stub
|
return haul;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Vector2i[] getWorablePositions() {
|
public Vector2i[] getWorablePositions() {
|
||||||
// TODO Auto-generated method stub
|
return new Vector2i[] {
|
||||||
return null;
|
new Vector2i(x + 1, y),
|
||||||
}
|
new Vector2i(x - 1, y),
|
||||||
|
new Vector2i(x, y + 1),
|
||||||
@Override
|
new Vector2i(x, y - 1)
|
||||||
public void doWork() {
|
};
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Vector2i getLocation() {
|
public Vector2i getLocation() {
|
||||||
// TODO Auto-generated method stub
|
return new Vector2i(x, y);
|
||||||
return null;
|
}
|
||||||
|
|
||||||
|
@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
|
@Override
|
||||||
public void update(float dTime) {
|
public void update(float dTime) {
|
||||||
|
|
||||||
// then, try to do work!
|
// cleanup current job...
|
||||||
if(currentJob != null && currentJob.hasWork()) {
|
if(currentJob != null && !currentJob.hasWork()) {
|
||||||
if(getCurrentPos().isOneOf(currentJob.getWorablePositions())) {
|
currentJob = null;
|
||||||
currentJob.doWork();
|
}
|
||||||
|
|
||||||
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO possibly take care of needs here idk
|
||||||
}
|
}
|
||||||
|
|
||||||
// firstly, TRY PATHING.
|
|
||||||
if(path != null && !path.isComplete()) {
|
if(path != null && !path.isComplete()) {
|
||||||
move();
|
move();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// then try to get work?!
|
// try to do your work!
|
||||||
if(counter == 0) {
|
if(currentJob != null && currentJob.hasWork()) {
|
||||||
currentJob = null;
|
if(getCurrentPos().isOneOf(currentJob.getWorablePositions())) {
|
||||||
tryStartWork();
|
if(currentJob instanceof IWorkable) {
|
||||||
|
((IWorkable)currentJob).doWork();
|
||||||
|
} else if (currentJob instanceof IHaulable) {
|
||||||
if(currentJob == null && (path == null || path.isComplete())) {
|
if(carrying == null) {
|
||||||
// then wander...
|
IHaulable thing = (IHaulable) currentJob;
|
||||||
newPath();
|
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() {
|
private Vector2i getCurrentPos() {
|
||||||
return new Vector2i((int)Math.floor(x), (int)Math.floor(y));
|
return new Vector2i((int)Math.floor(x), (int)Math.floor(y));
|
||||||
}
|
}
|
||||||
|
|
||||||
private IWorkable currentJob;
|
private IJob currentJob;
|
||||||
|
|
||||||
private void tryStartWork() {
|
private void tryStartWork() {
|
||||||
List<IWorkable> workables = getAll(IWorkable.class)
|
List<IJob> workables = getAll(IJob.class)
|
||||||
.stream()
|
.stream()
|
||||||
.filter(workable -> workable.hasWork())
|
.filter(workable -> workable.hasWork())
|
||||||
.sorted(new Comparator<IWorkable>() {
|
.sorted(new Comparator<IJob>() {
|
||||||
@Override
|
@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 distA = a.getLocation().distanceTo((int)x, (int)y);
|
||||||
float distB = b.getLocation().distanceTo((int)x, (int)y);
|
float distB = b.getLocation().distanceTo((int)x, (int)y);
|
||||||
if(distA > distB) return -1;
|
if(distA > distB) return -1;
|
||||||
|
|
@ -162,7 +192,7 @@ public class Pawn extends GameObject implements ISelectable {
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
if(workables.size() > 0) {
|
if(workables.size() > 0) {
|
||||||
for(IWorkable job : workables) {
|
for(IJob job : workables) {
|
||||||
if(!job.hasWork()) continue;
|
if(!job.hasWork()) continue;
|
||||||
Vector2i[] workablePositions = job.getWorablePositions();
|
Vector2i[] workablePositions = job.getWorablePositions();
|
||||||
Path bestPathToJob = pathfinder.getBestPath(
|
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
|
@Override
|
||||||
public String details() {
|
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) {
|
if(!toRemove.isEmpty()) {
|
||||||
selected.remove(removeMe);
|
for(ISelectable removeMe : toRemove) {
|
||||||
|
selected.remove(removeMe);
|
||||||
|
}
|
||||||
|
toRemove.clear();
|
||||||
|
broadcastSelectionChanged();
|
||||||
}
|
}
|
||||||
toRemove.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import xyz.valnet.engine.graphics.Drawing;
|
||||||
import xyz.valnet.engine.math.Vector4f;
|
import xyz.valnet.engine.math.Vector4f;
|
||||||
import xyz.valnet.engine.scenegraph.GameObject;
|
import xyz.valnet.engine.scenegraph.GameObject;
|
||||||
import xyz.valnet.hadean.Layers;
|
import xyz.valnet.hadean.Layers;
|
||||||
|
import xyz.valnet.hadean.Tile;
|
||||||
import xyz.valnet.hadean.util.Action;
|
import xyz.valnet.hadean.util.Action;
|
||||||
import xyz.valnet.hadean.util.Assets;
|
import xyz.valnet.hadean.util.Assets;
|
||||||
|
|
||||||
|
|
@ -11,6 +12,7 @@ public class Stockpile extends GameObject implements ITileThing, ISelectable {
|
||||||
|
|
||||||
private int x, y;
|
private int x, y;
|
||||||
private Camera camera;
|
private Camera camera;
|
||||||
|
private Terrain terrain;
|
||||||
|
|
||||||
public Stockpile(int x, int y) {
|
public Stockpile(int x, int y) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
|
|
@ -20,6 +22,7 @@ public class Stockpile extends GameObject implements ITileThing, ISelectable {
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
camera = get(Camera.class);
|
camera = get(Camera.class);
|
||||||
|
terrain = get(Terrain.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -62,4 +65,14 @@ public class Stockpile extends GameObject implements ITileThing, ISelectable {
|
||||||
return "";
|
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() {
|
public Vector2i getLocation() {
|
||||||
return new Vector2i(x, y);
|
return new Vector2i(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePosition(int x, int y) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue