Skip to content

own implementation of isRoomAvailable #437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/extends/room/intel.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ Room.requestIntel = function (roomname) {
Game.rooms[roomname].saveIntel()
return
}
if (!Game.map.isRoomAvailable(roomname)) {
if (!qlib.map.isRoomAvailableForCreeps(roomname)) {
return
}
if (!qlib.map.reachableFromEmpire(roomname, 'manhattan')) {
Expand Down Expand Up @@ -279,7 +279,7 @@ Room.getScoutTarget = function (creep) {
let testRoom
for (testRoom of targetRooms) {
// Filter out invalid rooms
if (!Game.map.isRoomAvailable(testRoom)) {
if (!qlib.map.isRoomAvailableForCreeps(testRoom)) {
continue
}

Expand Down Expand Up @@ -311,7 +311,7 @@ Room.getScoutTarget = function (creep) {
let oldest = 0
let testRoom
for (testRoom of adjacent) {
if (!Game.map.isRoomAvailable(testRoom)) {
if (Game.map.getRoomStatus(testRoom) !== 'closed') {
continue
}
const roominfo = Room.getIntel(testRoom)
Expand Down
2 changes: 1 addition & 1 deletion src/extends/room/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ Room.isHallway = function (name) {
}

Room.isClaimable = function (name) {
if (!Game.map.isRoomAvailable(name)) {
if (!qlib.map.isRoomAvailableForCreeps(name)) {
return false
}
const coords = Room.getCoordinates(name)
Expand Down
11 changes: 10 additions & 1 deletion src/lib/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const PATH_WEIGHT_HOSTILE = 10
const PATH_WEIGHT_HOSTILE_RESERVATION = 5

module.exports.getRoomScore = function (toRoom, fromRoom, opts = {}) {
if (!Game.map.isRoomAvailable(toRoom)) {
if (!qlib.map.isRoomAvailableForCreeps(toRoom)) {
return Infinity
}
if (!module.exports.reachableFromEmpire(toRoom)) {
Expand Down Expand Up @@ -123,3 +123,12 @@ module.exports.getRoomScore = function (toRoom, fromRoom, opts = {}) {
}
return scores.WEIGHT_NEUTRAL ? scores.WEIGHT_NEUTRAL : PATH_WEIGHT_NEUTRAL
}

// Checks whether this room is available and our creeps can probably enter it
module.exports.isRoomAvailableForCreeps = function (roomName) {
const ourZone = Game.map.getRoomStatus(Object.values(Game.creeps)[0].room.name).status
// Room is available if it's in the same zone with us ('normal', 'novice' or 'respawn'),
// as trespassing between these is not possible.
// Check againt 'closed' status is also coverd as out creeps can't be in closed areas.
return ourZone === Game.map.getRoomStatus(roomName).status
}