/* Mapfarming, etc .*/ function mapfarm(){/* Map farming for lazy people v0.1.0 (author: Penguindrum)*/ /* Instructions: click once and continue doing this. If stuff is weird, a message wil pop up telling you more. */ /* Don't move the map while clicking, this will mess up the labels and it may stop working. If you really want to move it click reset first. */ /* Because normal map farming takes 2 clicks per village, the first click selects the next village and the next one either sends an attack or determines that nothing will be sent depending on the last report and the settings. */ /* If you look above the map there's a village ID, a village queue and a reset button. */ /* The ID box contains 0 if the next farm can be selected, -1 if it's waiting for something to finish and every number above 0 is the selected village ID. */ /* The village queue contains the villages ordered from close to far. The next ID is the leftmost one. */ /* The reset button will remove all labels, the ID box and the queue. */ /* When a village is selected a white label appears on that village containing the distance. After the second click the colour is changed according to the settings and a letter will be added to the label. */ /* The letter is 'A','B' or 'X'. The first 2 correspond to the farm preset it sent, the X means that the village did not meet sending criteria. */ /* Settings are explained and edited after this part. */ /* Report types: 0 = No report; 1 = Green; 2 = Yellow; 3 = Red; 4 = Blue; 5 = RedYellow; 6 = RedBlue; If you don't know what they mean go to reports and look at the filters. */ /* Colours for the different types of report. */ dotc = ['black','green','yellow','red','yellow','purple','cyan']; /* list with 2 lists in it, first list is for A second for B. Fill with report types. */fp = [[0,1,4],[]]; /* List containing 2 bools, first is for attack, second for return. If true then all villages with that symbol are filtered. */fl = [true,true]; /* Maximum distance of current vill to the farm, vills that are further away are filtered. */dst = 18; function asp(a){$("#mf").append("");} function d(a,b){k=cd(a,b);return sq(pw(k[0],2)+pw(k[1],2));} function sq(a){return Math.sqrt(a);} function pw(a,b){return Math.pow(a,b);} function p(a){return parseInt(a);} function abs(a){return Math.abs(a);} function pw(a,b){return Math.pow(a,b);} function cd(a,b){return [abs(a[0]-b[0]),abs(a[1]-b[1])];} function rd(a,b){b=(b==undefined?1:pw(10,b));return (Math.round(b*a))/b;} cc = game_data.village.coord.split("|"); cm = $("#cm"); ft = $("#ft"); if(!cm.length){cm=false;}if(!ft.length){ft=false;} function flt(){ function ptc(a){return [cb[0][0]+((a.left-cb[0][1])/53),cb[1][0]+((a.top-cb[1][1])/38)];} eval("TWMap.context.ajaxDone = "+TWMap.context.ajaxDone.toString().replace(/b":\s+if \([\w.]+\)\ {\s+/, '$&$$("#mf").append("'+j('nu','1',0,1)+'");')); $("#content_value").prepend("
VillageID: "+j("cm",'0',1,1,6)+" Village queue: "+j("ft",'',1,1,200)+"
"); map = $("#map_container"); cb = [$("#map_coord_x > div").first(),$("#map_coord_y > div").first()].map(function(c,i){return [p(c.html()),eval("c.offset()."+(i?'top':'left'))];}); al = []; rl = []; map.find('img[id^="map_cmdicons_"]').each(function(){t=$(this).attr('id').substring(13).split("_");((t[1]==1)?al.push(t[0]):rl.push(t[0]));}); bb=[]; map.find('img[src$="_left.png"]').each(function(i){ t=$(this); r=[t.offset(),t.attr('id').substring(12)]; r.unshift(ptc(r[0])); r.unshift(d(cc,r[0])); r.push([(al.indexOf(r[3])>-1),(rl.indexOf(r[3])>-1)]); if(r[0]<=dst){bb.push(r);} }); bb = bb.sort(function(a,b){return a[0]-b[0];}).filter(function(a){return (!((a[4][0]&&fl[0])||(a[4][1]&&fl[1])));}); bb.forEach(function(a){asp(a);}); $('#ft').val(bb.map(function(a){return a[3];}).join(',')); } function sf(b,v){a=TWMap.context.ajaxRegister;a("mp_farm_"+b,eval("TWMap.urls.ctx.mp_farm_"+b).replace(/__village__/,v));$("#mp_farm_"+b).click();} function dot(v){ cm.val('-1'); $.getJSON( TWMap.urls.villagePopup.replace(/__village__/,v), function(a){ dt =((a["0"].attack==undefined)?0:a["0"].attack.dot); b=$("#"+v); cm.val('0'); if (fp[0].indexOf(dt)>=0){sf('a',v);b.prepend("A ");} else if (fp[1].indexOf(dt)>=0){sf('b',v);b.prepend("B ");} else{b.prepend("X ");} b.css('background-color',dotc[dt]).show(); } ); } function j(c, v, h, i, s) {return "";} function n() {location.href = $("#village_switch_right").attr('href');} function cs(id){$("#"+id).show();} if (!document.URL.match("&screen=map")){if (confirm("Werkt alleen op de kaart.\nWilt u hier naar toe gaan?")){location.href = '{game}&screen=map';}return false;} else if ($('#nu').length){if (confirm('U heeft niet genoeg eenheden meer om mee aan te vallen.\nKlik op ok om naar het volgende dorp te gaan.')){n()};return;} else if (cm&&cm.val()=="-1"){return;} else if (cm&&cm.val()!=="0"){dot(cm.val());return;} else if (ft&&ft.val()){l=ft.val().split(",");i=l.shift();ft.val(l.join(","));cs(i);cm.val(i);return;} else if ($('#mf').length){if (confirm("Geen farms meer aanwezig in dit gebied.\nProbeer te resetten en de kaart in de buurt rond te slepen.\nOf klik op ok om naar het volgende dorp te gaan.")){n();}return;} else{return flt();} }