Skip to content

Commit

Permalink
fluid shoving
Browse files Browse the repository at this point in the history
  • Loading branch information
CarsonBurke committed May 28, 2024
1 parent 5ce35d3 commit b1f25b6
Showing 1 changed file with 44 additions and 13 deletions.
57 changes: 44 additions & 13 deletions src/room/creeps/creepMoveProcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,23 +260,45 @@ export class CreepMoveProcs {

static tryRunMoveRequest(creep: Creep | PowerCreep, moveTargets: MoveTargets) {
// revisit this in the future
if (creep instanceof Creep && creep.spawning) return
/* if (creep instanceof Creep && creep.spawning) return */

const moveRequest = creep.moveRequest
/* const moveRequest = creep.moveRequest
if (!moveRequest) return
// If the creep is already registered to move where it wants to
if (creep.moveTarget === moveRequest) return
if (creep.moveTarget === moveRequest) return */

if (Game.flags[FlagNames.debugMoveRequests]) {
if (creep.moveRequest && Game.flags[FlagNames.debugMoveRequests]) {
creep.room.targetVisual(creep.pos, unpackCoord(creep.moveRequest), true)
}

// Target coord

let targetCoord: Coord | undefined = creep.moveRequest
? unpackCoord(creep.moveRequest)
: /* creep.actionCoord */ undefined

if (!targetCoord) return
if (packCoord(targetCoord) === creep.moveTarget) return

if (creep.moveTarget) {
delete moveTargets[creep.moveTarget]
delete creep.moveTarget
}

/* const reservationType = creep.room.roomManager.reservedCoords.get(packCoord(creep.pos))
if (reservationType === ReservedCoordTypes.spawning) {
delete creep.moveRequest
delete creep.actionCoord
if (CreepMoveProcs.shove(creep, moveTargets, new Set(), -100) < 0) {
return
}
CreepMoveProcs.assignMoveTarget(creep, packCoord(creep.pos), moveTargets)
return
} */

if (CreepMoveProcs.shove(creep, moveTargets, new Set(), 0) < 0) {
return
}
Expand All @@ -295,22 +317,15 @@ export class CreepMoveProcs {
): number {
let targetCoord: Coord | undefined = creep.moveRequest
? unpackCoord(creep.moveRequest)
: creep.actionCoord
: /* creep.actionCoord */ undefined

const creepMemory = Memory.creeps[creep.name]
if (!targetCoord && creepMemory[CreepMemoryKeys.goalPos]) {
targetCoord = unpackPos(creepMemory[CreepMemoryKeys.goalPos])
}

visitedCreeps.add(creep.name)

const { room } = creep
const terrain = room.getTerrain()

if (targetCoord && areCoordsEqual(creep.pos, targetCoord)) {
cost += 1
}

// For each adjacent and containing position for the creep

for (const coord of CreepMoveProcs.getMoveOptions(creep, targetCoord)) {
Expand Down Expand Up @@ -409,6 +424,14 @@ export class CreepMoveProcs {

const creepInWay = Game.creeps[creepInWayName] || Game.powerCreeps[creepInWayName]
if (creepInWay) {
let creepInWayTargetCoord: Coord | undefined = creepInWay.moveRequest
? unpackCoord(creepInWay.moveRequest)
: /* creepInWay.actionCoord */ undefined

if (creepInWayTargetCoord && areCoordsEqual(coord, creepInWayTargetCoord)) {
potentialCost += 1
}

// Cosider increasing cost if the creep wants to stay at its present coord

const creepInWayCost = CreepMoveProcs.shove(
Expand Down Expand Up @@ -478,12 +501,20 @@ export class CreepMoveProcs {
return moveOptions
}

if (targetCoord) {
if (targetCoord && getRange(creep.pos, targetCoord) <= 1) {
if (areCoordsEqual(targetCoord, creep.pos)) {
return moveOptions
}

moveOptions.unshift(targetCoord)
creep.moveOptions = moveOptions
return moveOptions
}

// Consider sorting by range to action coord, where closer is more preferred
moveOptions.push(...findAdjacentCoordsToCoord(creep.pos))

creep.moveOptions = moveOptions
return moveOptions
}

Expand Down

0 comments on commit b1f25b6

Please sign in to comment.