From cdc4bdbaec1e90677bb9208d2664d8a9eb564384 Mon Sep 17 00:00:00 2001 From: Kaan Soral Date: Tue, 9 Jun 2020 16:18:30 +0300 Subject: [PATCH] Create functions.js --- cli/functions.js | 217 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 217 insertions(+) create mode 100644 cli/functions.js diff --git a/cli/functions.js b/cli/functions.js new file mode 100644 index 0000000..e19c2d6 --- /dev/null +++ b/cli/functions.js @@ -0,0 +1,217 @@ +var is_server=0; +var character={ + x:0, real_x:0, + y:0, real_y:0, + map:"main", + base:{h: 8, v: 7, vn: 2}, + processor:true, +} +var smart={ + moving:false, + map:"main",x:0,y:0, + on_done:function(){}, + plot:null, + edge:20, // getting 20px close to the target is enough + baby_edge:80, // start treading lightly when 60px close to the target or starting point + try_exact_spot: false, + use_town:false, + prune:{ + smooth:true, + map:true, + }, + flags:{} +}; + +function game_log(x) +{ + console.log("[MGL]: "+x); +} + +var queue=[],visited={},start=0,best=null; +var moves=[[0,15],[0,-15],[15,0],[-15,0]]; +var baby_steps=[[0,5],[0,-5],[5,0],[-5,0]]; +// baby_steps is a new logic, used just around the target or starting point, to get out of tough spots [08/03/19] + +function plot(index) +{ + if(index==-1) return; + plot(queue[index].i); // Recursively back-tracks the path we came from + smart.plot.push(queue[index]); +} + +function qpush(node) +{ + // If we haven't visited this location, adds the location to the queue + if(smart.prune.map && smart.flags.map && node.map!=smart.map) return; + if(visited[node.map+"-"+node.x+"-"+node.y]) return; + if(!node.i) node.i=start; // set the index, to aid the plot function + queue.push(node); + visited[node.map+"-"+node.x+"-"+node.y]=true; +} + +function smooth_path() +{ + var i=0,j; + while(i