Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Module code goes here. Use 'module.exports' to export things:
- * module.exports.thing = 'a thing';
- *
- * You can import it from another modules like this:
- * var mod = require('main.path');
- * mod.thing == 'a thing'; // true
- */
- module.exports =
- {
- find : function (input)
- {
- var hash = ""
- if (_.isArray(input))
- {
- hash = input[0].x+" "+ input[0].y+" "+ input[0].roomName+" "+ input[1].x+" "+input[1].y+" "+input[1].roomName
- // need to convert it to a hash
- } else if (_.isString(input)){
- // it is a string
- hash = input
- console.log("HASH!!")
- }
- var found_path = []
- if (this.memory[hash] == undefined)
- {
- if (_.isString(input))
- {
- // reconstruct the paramaters from the hash
- var hash_arr = hash.split(" ")
- var pos1 = new RoomPosition(hash_arr[0], hash_arr[1], hash_arr[2]);
- var pos2 = new RoomPosition(hash_arr[3], hash_arr[4], hash_arr[5]);
- found_path = pos1.findPathTo( pos2)
- } else {
- found_path = input[0].findPathTo( input[1])
- this.memory[hash] =found_path
- }
- } else {
- found_path = this.memory[hash]
- }
- console.log(">>"+hash+" path length "+this.memory[hash])
- return [hash,found_path]
- },
- continue_to : function (creep,dest)
- {
- var path_data = ""
- if (creep.memory.path_hash == undefined && dest != undefined)
- {
- path_data = this.find([creep.pos, dest.pos])
- creep.memory.path_hash = path_data[0]
- } else if (creep.memory.path_hash != undefined) {
- path_data = this.find(creep.memory.path_hash)
- }
- if (creep.memory.path_step == undefined)
- {
- creep.memory.path_step = 0
- }
- //console.log("dir "+ path_data[1][creep.memory.path_step].direction)
- if (path_data[1][creep.memory.path_step] == undefined || path_data[1][creep.memory.path_step].direction == undefined)
- {
- delete creep.memory.path_step
- delete creep.memory.path_hash
- } else if (creep.move(path_data[1][creep.memory.path_step].direction) == 0){
- creep.memory.path_step = creep.memory.path_step + 1
- }
- // move(direction)
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement