Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. javascript:
  2. var buildStr=typeof(buildStr)=="string"?buildStr:"l=0:bl;a=0:la;n=1:bw;t<150:bq;q<21:bq;r<25:br;f<20:bf;b<15:bb;s<10:bs;g<4:bg;y<10:by;d<25:bd;c<25:bc;i<25:bi;b<25:bb;s<20:bs;f<30:lf;r<30:lr;y<20:ly;d<30:ld;c<30:lc;i<30:li;m<20:lm;u<1:bu;h<6:bh;h>6:dh;m>20:dm;q>21:dq";
  3. buildings=new Array("q","b","s","g","a","y","l","u","m","d","c","i","f","r","h","w");
  4. realBuildings=new Array("main","barracks","stable","garage","snob","smith","place","statue","market","wood","stone","iron","farm","storage","hide","wall");
  5. assocBuildings=[];/*need to build associative array so "q"=>0, etc----------------------*/
  6. assocRealBuildings=[];
  7. version=0.2;
  8. i=1;
  9. doneSomething=0;
  10. maxLevel=new Array(30,25,20,15,1,20,1,1,25,30,30,30,30,30,10,20);
  11. for(dd in buildings){
  12.     assocBuildings[buildings[dd]]=dd;
  13.     assocRealBuildings[realBuildings[dd]]=dd;
  14. }
  15. offset=4;
  16. comArr=buildStr.split(";");
  17. rows=document.getElementById("buildings_table").rows;
  18.  
  19. stopRows=0;
  20. function beforeBuildcheck(){
  21.     cells=rows[i].cells;
  22.     incoming=0;
  23.     totalLevels=0;
  24.     if(cells[2].innerHTML.indexOf("attack.png")!=-1){
  25.         incoming=1;
  26.     }
  27.     currPoints=cells[3].innerText.split(".").join("");
  28.     currVillName=cells[2].innerText.trim();
  29.     d=0;
  30.    
  31.     currVillID=cells[2].getElementsByTagName("a")[0].href.match(/village=\d+/i)[0].match(/\d+/);
  32.     currBuildingLvl=[];
  33.     currAbleToBuild=[];
  34.     currBuildingBuildStatus=[];
  35.     skippedAny=0;
  36.     /*------------activate -----------*/
  37.     BuildingOverview.toggle_upgrade_buildings(currVillID);
  38.     setTimeout('loadWait()',10);
  39. }
  40. function loadWait(){
  41.     if(cells[0].className=="build_icon"){
  42.         afterBuildcheck();
  43.     }else{
  44.         setTimeout('loadWait()',500);
  45.     }
  46.  
  47. }
  48. function afterBuildcheck(){
  49.     /*find the current buildings levels*/
  50.     while(d<buildings.length){
  51.         currBuildingLvl[d]=cells[d+offset].innerText;
  52.         totalLevels=parseInt(totalLevels)+parseInt(currBuildingLvl[d]);
  53.         /* --- check if it can be built    --- */
  54.         currAbleToBuild[d]=0;
  55.         if(cells[d+offset].innerHTML.indexOf("a href")!=-1){
  56.             /*checks for both lack of res and lack of tech*/
  57.             currAbleToBuild[d]=1;
  58.         }
  59.         d++;
  60.     }
  61.     /*------------ADD IN BUILDINGS ALREADY IN THE QUE------------------------*/
  62.     queCell=cells[20];
  63.     queLength=0;
  64.     demQueLength=0;
  65.     que=queCell.getElementsByTagName("li");
  66.     for(q=0;q<que.length;q++){
  67.         curLi=que[q];
  68.         upOrDown=curLi.getElementsByTagName("div")[0].style.backgroundColor;
  69.         level=1;
  70.         queLength++;
  71.         if(upOrDown=="#ff0000"){
  72.             /* god this is getting a bit iffy
  73.             if it is red, it's being demolished
  74.             */
  75.             queLength--;
  76.             demQueLength++;
  77.             level=-1;
  78.         }
  79.         img=curLi.getElementsByTagName("img")[1].src.split("/buildings/")[1].split(".")[0];
  80.         currBuildingLvl[assocRealBuildings[img]]=currBuildingLvl[assocRealBuildings[img]]*1+level;
  81.         currBuildingBuildStatus[assocRealBuildings[img]]=level;
  82.     }
  83.     /*go through the commandArr*/
  84.     for(n=0;n<comArr.length;n++){
  85.         failCmd=0;
  86.         currCmd=comArr[n].split(":");
  87.         failCriteria=1;
  88.         currCriteria=currCmd[0];
  89.         oB=currCriteria.substr(0,1);
  90.         oC=currCriteria.substr(1,1);
  91.         oN=currCriteria.substr(2);
  92.         /*
  93.         oB = building to compare
  94.         oC= comparison operator to use
  95.         oN = number to compare with
  96.         */
  97.         nB=currBuildingLvl[assocBuildings[oB]];
  98.         if(oB=="n"){
  99.             nB=incoming;
  100.         }
  101.         if(oB=="t"){
  102.             nB=totalLevels;
  103.         }
  104.         if(oB=="p"){
  105.             nB=currPoints;
  106.         }
  107.         nB=parseInt(nB);
  108.         oN=parseInt(oN);
  109.         /* nB=(float)nB; */
  110.         if(oC=="<"){
  111.             dfd=nB<oN;
  112.             /* alert("<\n"+nB+":"+oN+"\n"+dfd+"::"); */
  113.             if(nB<oN){
  114.                 failCriteria=0;
  115.             }
  116.         }
  117.         if(oC==">"){
  118.             dfd=nB>oN;
  119.             /* alert(">\n"+nB+":"+oN+"\n"+dfd+"::"); */
  120.             if(nB>oN){
  121.                 failCriteria=0;
  122.             }
  123.         }
  124.         if(oC=="="){
  125.             dfd=nB==oN;
  126.             /* alert("equals\n"+nB+"="+oN+"::"+dfd); */
  127.             if(nB==oN){
  128.                 failCriteria=0;
  129.             }
  130.         }
  131.         /* alert("n"+n+",oC:"+oC+"\n"+oB+"::"+nB+"\n"+comArr[n]+"\n"+failCriteria);  */
  132.        
  133.         if(!failCriteria){
  134.             /*IT SHOULD BUILD THAT BUILDING, if possible*/
  135.             target=currCmd[1].substr(1);
  136.             action=currCmd[1].substr(0,1);
  137.             /*command*/
  138.             doBuild=0;
  139.             if(action=="b"){
  140.                 doBuild=1;
  141.             }
  142.             if(action=="l"){
  143.                 doBuild=1;
  144.                 if(skippedAny==1){
  145.                     doBuild=2;
  146.                     log(realBuildings[assocBuildings[target]] +" skipped to preserve res in "+currVillName);
  147.                 }
  148.             }
  149.             if(action=="d"){
  150.                 /* check if it can be demolished */
  151.                 doBuild=2;
  152.                 if(assocBuildings[target]!='undefined'){
  153.                     targetBuilding=assocBuildings[target];
  154.                     currLvl=parseInt(currBuildingLvl[targetBuilding]);
  155.                     currStatus=currBuildingBuildStatus[targetBuilding];
  156.                     if(currStatus!=1){
  157.                         if(currLvl>0){
  158.                             if(demQueLength<5&&queLength<5&&!skippedAny){
  159.                                 stopRows=1;
  160.                                 n=comArr.length;
  161.                                 BuildingOverview.upgrade_building(parseInt(currVillID),realBuildings[targetBuilding],1);
  162.                                 log(realBuildings[targetBuilding]+" demolished (l"+(currLvl)+") in "+currVillName);
  163.                                 cells[2].style.backgroundColor="#00FF00";
  164.                                 doneSomething=1;
  165.                             }else{
  166.                                 log(realBuildings[targetBuilding]+" can't be demolished in "+currVillName+" - dem que full/construction que at 5/skipped");
  167.                             }
  168.                         }
  169.                     }
  170.                 }
  171.             }
  172.             if(doBuild==1){
  173.                 /* check if it is buildable */
  174.                 if(assocBuildings[target]!='undefined'){
  175.                     targetBuilding=assocBuildings[target];
  176.                     currMaxLevel=maxLevel[targetBuilding];
  177.                     able=currAbleToBuild[targetBuilding];
  178.                     currStatus=currBuildingBuildStatus[targetBuilding];
  179.                     currLvl=parseInt(currBuildingLvl[targetBuilding]);
  180.                     if(currLvl+1<=currMaxLevel){
  181.                         if(currStatus!=-1){
  182.                             if(queLength<5){
  183.                                 if(able){
  184.                                     stopRows=0;
  185.                                     n=comArr.length;
  186.                                     doneSomething=1;
  187.                                     BuildingOverview.upgrade_building(parseInt(currVillID),realBuildings[targetBuilding],0);
  188.                                     log(realBuildings[targetBuilding]+" built (l"+(currLvl+1)+") in "+currVillName);
  189.                                     cells[2].style.backgroundColor="#00FF00";
  190.                                 }else{
  191.                                     if(action=="l"){
  192.                                         /*don't count as a skip if it is a delay-build*/
  193.                                     }else{
  194.                                         skippedAny=1;
  195.                                     }
  196.                                     log(realBuildings[targetBuilding]+" skipped in "+currVillName+" due to unable to build");
  197.                                 }
  198.                             }else{
  199.                                 /* don't add any one if the que is at least 5 long - in fact, terminate early */
  200.                                 log(currVillName +" - can't add "+realBuildings[targetBuilding]+" - build que full");
  201.                             }
  202.                         }else{
  203.                             /* can't build while demolishing... don't count as a skip*/
  204.                         }
  205.                     }else{
  206.                         /* silly, can't be built any more - don't count as a skip  */
  207.                     }
  208.                 }else{
  209.                     alert("Unknown building : "+target+"\n"+currVillName);
  210.                 }
  211.  
  212.             }else{
  213.                 if(doBuild==0){
  214.                     /* don't alert if its just skipped  */
  215.                     alert("Unsupported operation : "+action+ "\n"+currVillName+":"+target);
  216.                 }
  217.             }
  218.             /*target cell*/
  219.            
  220.             /* and not if that building is currently having the opposite done */
  221.             /* mark the row if it builds */
  222.         }
  223.     }
  224.     i++;
  225.     if(i>=rows.length&&!doneSomething){
  226.         alert("Completed for the time being!");
  227.     }
  228.     if(i<rows.length&&!doneSomething){
  229.         if(!stopRows){
  230.             beforeBuildcheck();
  231.         }
  232.         log(currVillName + " finished, going to next village");
  233.     }
  234.  
  235. }
  236. function log(str){
  237.     document.body.appendChild(document.createTextNode(str));
  238.     document.body.appendChild(document.createElement('br'));
  239. }
  240. if(window.location.href.indexOf("mode=buildings")!=-1){
  241.     var nemoAlreadyRun;
  242.     if(!nemoAlreadyRun){
  243.         log("nemo building overview assistant - v"+String(version));
  244.     }
  245.     nemoAlreadyRun=1;
  246.     beforeBuildcheck();
  247. }
  248. void(0);
  249. /*
  250. pseudo-pseudocode:
  251.  
  252. go through all villages on the table
  253.     find out its current building levels (including those in the que), if it has incomings,  total building levels, and whether each building can be built
  254.     go through the building string, foreach
  255.         check whether the conditions are true to build that AND check whether it is possible to build that
  256.             if yes, build that, unset all variables used, and terminate execution
  257.             if no, go to the next condition
  258.            
  259.            
  260. string definitions:
  261. q= headquarters
  262. b= barracks
  263. s= stable      
  264. g= workshop
  265. a= acadamy
  266. y= smithy
  267. u= statue
  268. l= rally point
  269. m= market
  270. d= wood
  271. c= clay
  272. i= iron
  273. f= farm
  274. r= warehouse
  275. h= hiding place
  276. w= wall
  277. n= incomings
  278. t= total building levels
  279. p= points
  280.  
  281. comparisons -
  282. <
  283. >
  284. =
  285. instruction :
  286. end instruction ;
  287. instructions
  288. b - build
  289. d - destroy
  290. l - low priority build //if it has skipped any before this, it will not build this, in order to conserve resources
  291. //will need some way of making it skip to the next village?
  292. //huh, i can just make it skip to the next village if it reaches the end of the command string/arr
  293. //also, skipping a low priority build for lack of resources, doesn't count as skipping with regards to all later lowpriority - not building a level 20 market does mean it will build a rally point
  294. example
  295. w<20&n=1:bw;    //build wall if it's below 20 and there are incomings
  296.  
  297. q<30&t<150:bq; //build hq if its below 30 and total village levels are below 150
  298.  
  299. buildStr="l=0:bl;a=0:la;w<20&n=1:bw;q<30&t<150:bq;q<21:bq;r<25:br;f<20:bf;b<15:bb;s<10:bs;w<5:bw;y<10:by;w<25:bw;c<25:bc;i<25:bi;b<25:bb;s<20:bs;f<30:lf;r<30:lr;y<20:ly;w<30:lw;c<30:lc;i<30:li;m<20:lm;u<1:bu;h<6:bh;b>6:dh;m>21:dm;w>6:dw;q>21:dq";
  300. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement