-
-
Save Arcath/0caa58e12428690a7d9f0450695acb78 to your computer and use it in GitHub Desktop.
Screeps Part 12 code examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get the total of all rcls added together (for state change on RCL up) | |
var rclTotal = 0 | |
_.forEach(Game.rooms, function(room){ | |
if(room.controller){ | |
if(room.controller.my){ | |
rclTotal += room.controller.level | |
} | |
} | |
}) | |
// Use a hash to check if anything in the game has changed | |
var hashCheck = { | |
codeRevision: 1, // Increment before deploy to force a new game state | |
rooms: Object.keys(Game.rooms).length, | |
creeps: Object.keys(Game.creeps).length, | |
spawns: Object.keys(Game.spawns).length, | |
structures: Object.keys(Game.structures).length, | |
sites: Object.keys(Game.constructionSites).length, | |
rclTotal: rclTotal | |
} | |
var newHash = Utils.hash(hashCheck) | |
if(Memory.stateCheck != newHash){ | |
// Game state has changed! | |
Memory.stateCheck = newHash | |
}else{ | |
// Game state is the same | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment