chore: Introduction to agent resetting
This commit is contained in:
parent
a87d4ecb2f
commit
84ef4a5290
@ -9,3 +9,4 @@ const UnitsCount = ((ColumnsOfGroupsCount * RowsOfGroupsCount) * UnitsInGroupCou
|
||||
const AgentMoveSpeed = 60 /* 1 - slowest, 89 - fastest */
|
||||
const AgentRotationSpeed = 60 /* 1 - slowest, 89 - fastest */
|
||||
const AgentWaitTime = 500 /* in miliseconds */
|
||||
const AgentStartPosition = { x: 6, y: 0 }
|
||||
|
@ -57,4 +57,13 @@ class Agent extends AgentController {
|
||||
this.ownedProductAmount = amount;
|
||||
this.ownedProduct = product;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel all agent actions, teleport to start position
|
||||
*/
|
||||
reset() {
|
||||
this.cancelAllActions();
|
||||
|
||||
this.position = AgentStartPosition;
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@ class AgentController {
|
||||
this.currentAction = this.actions.STATIONARY;
|
||||
|
||||
// Pozycja i rotacja
|
||||
this.position = { x: 6, y: 0 };
|
||||
this.position = AgentStartPosition;
|
||||
this.rotation = { z: 0 };
|
||||
this.update();
|
||||
}
|
||||
@ -95,6 +95,8 @@ class AgentController {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const cycle = () => {
|
||||
if (this.currentAction == this.actions.STATIONARY) return resolve();
|
||||
|
||||
let { speed } = this;
|
||||
speed *= (actionCost - 1) * 4 + 1;
|
||||
|
||||
@ -259,13 +261,17 @@ class AgentController {
|
||||
}
|
||||
|
||||
findPathTo(dx, dy, sx, sy) {
|
||||
if (Grid.instance.getGrid()[dx][dy] == GRID_FIELD_TYPE.SHELF || Grid.instance.getGrid()[dx][dy] == GRID_FIELD_TYPE.STORAGE) {
|
||||
const position = { x: sx, y: sy };
|
||||
const rotation = this.rotation.z;
|
||||
|
||||
if (Grid.instance.getGrid()[dx][dy] == GRID_FIELD_TYPE.SHELF ||
|
||||
Grid.instance.getGrid()[dx][dy] == GRID_FIELD_TYPE.STORAGE) {
|
||||
if (Grid.instance.getGrid()[dx][dy - 1] == GRID_FIELD_TYPE.PATH) {
|
||||
return Pathfinding.search({ position: { x: sx, y: sy }, rotation: this.rotation.z }, { position: { x: dx, y: dy - 1 }, rotation: 180 });
|
||||
return Pathfinding.search({ position, rotation }, { position: { x: dx, y: dy - 1 }, rotation: 180 });
|
||||
}
|
||||
return Pathfinding.search({ position: { x: sx, y: sy }, rotation: this.rotation.z }, { position: { x: dx, y: dy + 1 }, rotation: 0 });
|
||||
return Pathfinding.search({ position, rotation }, { position: { x: dx, y: dy + 1 }, rotation: 0 });
|
||||
}
|
||||
return Pathfinding.search({ position: { x: sx, y: sy }, rotation: this.rotation.z }, { position: { x: dx, y: dy }, rotation: this.rotation.z });
|
||||
return Pathfinding.search({ position, rotation }, { position: { x: dx, y: dy }, rotation });
|
||||
}
|
||||
|
||||
clearCanvas() {
|
||||
@ -288,4 +294,12 @@ class AgentController {
|
||||
this.ctx.closePath();
|
||||
this.ctx.stroke();
|
||||
}
|
||||
|
||||
cancelAllActions() {
|
||||
this.ownedProduct = Product.REGISTRY.empty;
|
||||
this.ownedProductAmount = 0;
|
||||
this.currentPath = [];
|
||||
this.currentAction = this.actions.STATIONARY;
|
||||
this.currentPathIndex = 0;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user