Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- javascript:
- /*Dates must be your time
- n,mode,min
- 0,1,200 will send ALL minus 0 IF there are more than 200
- 20,1,3000 will send ALL minus 20 IF there are more than 3000
- 20,2,30 will send 20 IF there are more than 30
- mode 1 - if there are less troops than the number to leave behind, don't send any
- mode 2 - if there are less troops than the number to send, send all
- put config of slowest troop first
- */
- var startWindow=new Date("10 June 2011 00:00:00");
- var endWindow=new Date("30 July 2012 00:00:00");
- var coords = '';
- var options ={
- fakeLeave:10,
- scouts:1,
- alertOnNoTroops:0,
- useFirstTroop:0,
- alertOnTroops:0
- };
- var config = {
- ram: [0,0,0],
- catapult: [30,2,35],
- spear: [0,0,0],
- sword: [0,0,0],
- axe: [0,0,0],
- archer: [0,0,0],
- light: [0,0,0],
- marcher: [0,0,0],
- heavy: [30,2,35],
- spy: [1,2,0]
- };
- var speeds= {
- spear:1080,
- sword:1320,
- axe:1080,
- archer:1080,
- light:600,
- marcher:600,
- heavy:660,
- ram:1800,
- catapult:1800,
- spy: 500
- };
- curTime=new Date();
- function dist(x1,y1,x2,y2){
- x=x1-x2;
- y=y1-y2;
- return Math.sqrt(x*x+y*y);
- }
- curSec=curTime.getTime()/1000;
- firstSec=startWindow.getTime()/1000;
- finalSec=endWindow.getTime()/1000;
- var newCoords=[];
- var nCSpd=[];
- var d=0;
- var win = (window.frames.length > 0) ? window.main : window;
- var eleForm = win.document.getElementById('units_form');
- var coord = coords.split(' ');
- var curVill=win.document.getElementsByTagName("b")[0].innerText.split("|");
- var xCo=curVill[0].split("(")[1];
- var yCo=curVill[1].split(")")[0];
- win.$("input[class=unitsInput]").attr("value", "0");
- var number=[];
- /* check if the troops config is present */
- var configSpeed=0;
- var successful=1;
- for(var unit in config){
- number[unit]=parseInt(eleForm[unit].nextSibling.nextSibling.innerHTML.match(/\d+/));
- if(number[unit]<config[unit][2]){
- successful=0;
- }else{
- configSpeed=Math.max(configSpeed,speeds[unit]);
- }
- }
- if(successful==1){
- if(options.alertOnTroops){
- alert("Config found");
- }
- /* fill out the troops, and it's at the assigned speed speed */
- for(var unit in config){
- mode=config[unit][1];
- n=config[unit][0];
- nUnits=number[unit];
- unitsToSend=0;
- if(mode==1){
- /* leave behind */
- unitsToSend=Math.max(nUnits-n,0);
- }
- if(mode==2){
- unitsToSend=Math.min(n,nUnits);
- }
- eleForm[unit].value=unitsToSend;
- }
- for(var target in coord){
- tCo=coord[target].split("|");
- tX=tCo[0];
- tY=tCo[1];
- travelTime=dist(tX,tY,xCo,yCo)*configSpeed;
- arriveTime=curSec+travelTime;
- if(arriveTime>firstSec&&arriveTime<finalSec){
- newCoords[d]=coord[target];
- d++;
- }
- }
- }else{
- if(options.alertOnNoTroops){
- alert("Troops do not meet config requirements");
- }
- for(var unit in config){
- if(newCoords.length>0&&options.useFirstTroop==1){
- }else{
- if(number[unit]>options.fakeLeave+1){
- for(var target in coord){
- tCo=coord[target].split("|");
- tX=tCo[0];
- tY=tCo[1];
- travelTime=dist(tX,tY,xCo,yCo)*speeds[unit];
- arriveTime=curSec+travelTime;
- if(arriveTime>firstSec&&arriveTime<finalSec){
- newCoords[d]=coord[target];
- nCSpd[d]=unit;
- d++;
- }
- }
- }/*else, there are not enough, leave all behind*/
- }
- }
- }
- if(newCoords.length>0){
- nC=Math.floor(Math.random()*newCoords.length);
- tCoord=newCoords[nC].split("|");
- eleForm.x.value = tCoord[0];
- eleForm.y.value = tCoord[1];
- }else{
- alert("Cannot reach in time window, either no units in village fakeLeave set too high");
- }
- if(successful==0){
- eleForm[nCSpd[nC]].value=1;
- eleForm['spy'].value=Math.min(options.scouts,number['spy']);
- }
- void(0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement