Skip to content

Commit

Permalink
Found a transportation bug
Browse files Browse the repository at this point in the history
  • Loading branch information
marek-hanzal committed Jan 31, 2025
1 parent b7d57a8 commit 2a29ef0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
6 changes: 6 additions & 0 deletions apps/pico/src/app/derivean/service/withBuildingGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ export const withBuildingGraph = async ({
(waypointX - buildingX) ** 2 + (waypointY - buildingY) ** 2,
);

/**
* TODO Building and waypoints are in different spaces, thus lengths are not correct:
* - Building lives inside a land (so it has relative coordinates)
* - Waypoints lives in a map (so it has absolute coordinates)
*/

graph.addEdge(buildingId, waypointId, {
type: "building-waypoint",
length,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,24 @@ export const withTransportRoute = async ({

const route = path.slice(1, -1);

const length = graph.getEdgeAttribute(
waypointId,
route.length ? route[0] : targetId,
"length",
);
const move = withProgressPerTick({
road: length,
weight: weight * amount,
speed: 32,
});

console.info("\t\t\t\t-- Resolved movement", {
waypointId,
target: route.length ? route[0] : targetId,
length,
progress: Math.min(100, progress + move),
});

/**
* We're at the end, move the goods to target inventory.
*
Expand All @@ -135,6 +153,20 @@ export const withTransportRoute = async ({
"\t\t\t\t-- Resolving inventory transaction (transport at destination)",
);

if (progress + move < 100) {
console.info("\t\t\t\t-- Last waypoint, transport in progress", {
progress: progress + move,
});
await tx
.updateTable("Transport")
.set({
progress: Math.min(100, progress + move),
})
.where("id", "=", id)
.execute();
continue;
}

const inventory = await tx
.selectFrom("Inventory as i")
.select(["i.id", "i.amount", "i.limit"])
Expand Down Expand Up @@ -187,19 +219,6 @@ export const withTransportRoute = async ({
continue;
}

const length = graph.getEdgeAttribute(waypointId, route[0], "length");
const move = withProgressPerTick({
road: length,
weight: weight * amount,
speed: 32,
});

console.info("\t\t\t\t-- Resolved movement", {
waypointId: route[0],
length,
progress: move,
});

if (progress + move >= 100) {
/**
* Move the goods to the next waypoint.
Expand Down

0 comments on commit 2a29ef0

Please sign in to comment.