Skip to content
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

own implementation of isRoomAvailable #437

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
style fix
den-kozlov committed Oct 3, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit e36047f5834f1017de3a537c679768a26b511ed9
8 changes: 3 additions & 5 deletions src/lib/map.js
Original file line number Diff line number Diff line change
@@ -125,12 +125,10 @@ module.exports.getRoomScore = function (toRoom, fromRoom, opts = {}) {
}

// Our own implementation of depricated function
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Our own implementation of depricated function
// Checks whether this room is available and our creeps can probably enter it

module.exports.isRoomAvailable = function(roomName) {
if (!global.homeRoomStatus) {
global.homeRoomStatus = Game.map.getRoomStatus(_.values(Game.spawns)[0].room.name).status;
}
module.exports.isRoomAvailable = function (roomName) {
const homeRoomStatus = Game.map.getRoomStatus(_.values(Game.spawns)[0].room.name).status
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line throws an exception when there are no spawns left. The empire is only dead when all creeps are dead too. I'd check for Game.creeps as a fallback when there are no Game.spawns.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there's no point in checking spawns then. The check can be done against creeps object as they are in the same zone. This can be replaced with 'normal' constant, but it will hurt people using Novice and Respawn zones.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right after spawning there are no creeps yet though 😉

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No guarantee of a spawn either if using auto mode on private servers 😉 May want to use _.keys(Game.rooms)[0] instead since that will always exist.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An observer could have been used to observe a room outside the zone

// Inside novice areas the only rooms available are novice rooms.
// Same goes with respawn areas.
// Home room can't be closed, so this case is also coverd.
return homeRoomStatus === Game.map.getRoomStatus(roomName).status
}
}