Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- javascript:
- 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";
- buildings=new Array("q","b","s","g","a","y","l","u","m","d","c","i","f","r","h","w");
- realBuildings=new Array("main","barracks","stable","garage","snob","smith","place","statue","market","wood","stone","iron","farm","storage","hide","wall");
- assocBuildings=[];/*need to build associative array so "q"=>0, etc----------------------*/
- assocRealBuildings=[];
- version=0.2;
- i=1;
- doneSomething=0;
- maxLevel=new Array(30,25,20,15,1,20,1,1,25,30,30,30,30,30,10,20);
- for(dd in buildings){
- assocBuildings[buildings[dd]]=dd;
- assocRealBuildings[realBuildings[dd]]=dd;
- }
- offset=4;
- comArr=buildStr.split(";");
- rows=document.getElementById("buildings_table").rows;
- stopRows=0;
- function beforeBuildcheck(){
- cells=rows[i].cells;
- incoming=0;
- totalLevels=0;
- if(cells[2].innerHTML.indexOf("attack.png")!=-1){
- incoming=1;
- }
- currPoints=cells[3].innerText.split(".").join("");
- currVillName=cells[2].innerText.trim();
- d=0;
- currVillID=cells[2].getElementsByTagName("a")[0].href.match(/village=\d+/i)[0].match(/\d+/);
- currBuildingLvl=[];
- currAbleToBuild=[];
- currBuildingBuildStatus=[];
- skippedAny=0;
- /*------------activate -----------*/
- BuildingOverview.toggle_upgrade_buildings(currVillID);
- setTimeout('loadWait()',10);
- }
- function loadWait(){
- if(cells[0].className=="build_icon"){
- afterBuildcheck();
- }else{
- setTimeout('loadWait()',500);
- }
- }
- function afterBuildcheck(){
- /*find the current buildings levels*/
- while(d<buildings.length){
- currBuildingLvl[d]=cells[d+offset].innerText;
- totalLevels=parseInt(totalLevels)+parseInt(currBuildingLvl[d]);
- /* --- check if it can be built --- */
- currAbleToBuild[d]=0;
- if(cells[d+offset].innerHTML.indexOf("a href")!=-1){
- /*checks for both lack of res and lack of tech*/
- currAbleToBuild[d]=1;
- }
- d++;
- }
- /*------------ADD IN BUILDINGS ALREADY IN THE QUE------------------------*/
- queCell=cells[20];
- queLength=0;
- demQueLength=0;
- que=queCell.getElementsByTagName("li");
- for(q=0;q<que.length;q++){
- curLi=que[q];
- upOrDown=curLi.getElementsByTagName("div")[0].style.backgroundColor;
- level=1;
- queLength++;
- if(upOrDown=="#ff0000"){
- /* god this is getting a bit iffy
- if it is red, it's being demolished
- */
- queLength--;
- demQueLength++;
- level=-1;
- }
- img=curLi.getElementsByTagName("img")[1].src.split("/buildings/")[1].split(".")[0];
- currBuildingLvl[assocRealBuildings[img]]=currBuildingLvl[assocRealBuildings[img]]*1+level;
- currBuildingBuildStatus[assocRealBuildings[img]]=level;
- }
- /*go through the commandArr*/
- for(n=0;n<comArr.length;n++){
- failCmd=0;
- currCmd=comArr[n].split(":");
- failCriteria=1;
- currCriteria=currCmd[0];
- oB=currCriteria.substr(0,1);
- oC=currCriteria.substr(1,1);
- oN=currCriteria.substr(2);
- /*
- oB = building to compare
- oC= comparison operator to use
- oN = number to compare with
- */
- nB=currBuildingLvl[assocBuildings[oB]];
- if(oB=="n"){
- nB=incoming;
- }
- if(oB=="t"){
- nB=totalLevels;
- }
- if(oB=="p"){
- nB=currPoints;
- }
- nB=parseInt(nB);
- oN=parseInt(oN);
- /* nB=(float)nB; */
- if(oC=="<"){
- dfd=nB<oN;
- /* alert("<\n"+nB+":"+oN+"\n"+dfd+"::"); */
- if(nB<oN){
- failCriteria=0;
- }
- }
- if(oC==">"){
- dfd=nB>oN;
- /* alert(">\n"+nB+":"+oN+"\n"+dfd+"::"); */
- if(nB>oN){
- failCriteria=0;
- }
- }
- if(oC=="="){
- dfd=nB==oN;
- /* alert("equals\n"+nB+"="+oN+"::"+dfd); */
- if(nB==oN){
- failCriteria=0;
- }
- }
- /* alert("n"+n+",oC:"+oC+"\n"+oB+"::"+nB+"\n"+comArr[n]+"\n"+failCriteria); */
- if(!failCriteria){
- /*IT SHOULD BUILD THAT BUILDING, if possible*/
- target=currCmd[1].substr(1);
- action=currCmd[1].substr(0,1);
- /*command*/
- doBuild=0;
- if(action=="b"){
- doBuild=1;
- }
- if(action=="l"){
- doBuild=1;
- if(skippedAny==1){
- doBuild=2;
- log(realBuildings[assocBuildings[target]] +" skipped to preserve res in "+currVillName);
- }
- }
- if(action=="d"){
- /* check if it can be demolished */
- doBuild=2;
- if(assocBuildings[target]!='undefined'){
- targetBuilding=assocBuildings[target];
- currLvl=parseInt(currBuildingLvl[targetBuilding]);
- currStatus=currBuildingBuildStatus[targetBuilding];
- if(currStatus!=1){
- if(currLvl>0){
- if(demQueLength<5&&queLength<5&&!skippedAny){
- stopRows=1;
- n=comArr.length;
- BuildingOverview.upgrade_building(parseInt(currVillID),realBuildings[targetBuilding],1);
- log(realBuildings[targetBuilding]+" demolished (l"+(currLvl)+") in "+currVillName);
- cells[2].style.backgroundColor="#00FF00";
- doneSomething=1;
- }else{
- log(realBuildings[targetBuilding]+" can't be demolished in "+currVillName+" - dem que full/construction que at 5/skipped");
- }
- }
- }
- }
- }
- if(doBuild==1){
- /* check if it is buildable */
- if(assocBuildings[target]!='undefined'){
- targetBuilding=assocBuildings[target];
- currMaxLevel=maxLevel[targetBuilding];
- able=currAbleToBuild[targetBuilding];
- currStatus=currBuildingBuildStatus[targetBuilding];
- currLvl=parseInt(currBuildingLvl[targetBuilding]);
- if(currLvl+1<=currMaxLevel){
- if(currStatus!=-1){
- if(queLength<5){
- if(able){
- stopRows=0;
- n=comArr.length;
- doneSomething=1;
- BuildingOverview.upgrade_building(parseInt(currVillID),realBuildings[targetBuilding],0);
- log(realBuildings[targetBuilding]+" built (l"+(currLvl+1)+") in "+currVillName);
- cells[2].style.backgroundColor="#00FF00";
- }else{
- if(action=="l"){
- /*don't count as a skip if it is a delay-build*/
- }else{
- skippedAny=1;
- }
- log(realBuildings[targetBuilding]+" skipped in "+currVillName+" due to unable to build");
- }
- }else{
- /* don't add any one if the que is at least 5 long - in fact, terminate early */
- log(currVillName +" - can't add "+realBuildings[targetBuilding]+" - build que full");
- }
- }else{
- /* can't build while demolishing... don't count as a skip*/
- }
- }else{
- /* silly, can't be built any more - don't count as a skip */
- }
- }else{
- alert("Unknown building : "+target+"\n"+currVillName);
- }
- }else{
- if(doBuild==0){
- /* don't alert if its just skipped */
- alert("Unsupported operation : "+action+ "\n"+currVillName+":"+target);
- }
- }
- /*target cell*/
- /* and not if that building is currently having the opposite done */
- /* mark the row if it builds */
- }
- }
- i++;
- if(i>=rows.length&&!doneSomething){
- alert("Completed for the time being!");
- }
- if(i<rows.length&&!doneSomething){
- if(!stopRows){
- beforeBuildcheck();
- }
- log(currVillName + " finished, going to next village");
- }
- }
- function log(str){
- document.body.appendChild(document.createTextNode(str));
- document.body.appendChild(document.createElement('br'));
- }
- if(window.location.href.indexOf("mode=buildings")!=-1){
- var nemoAlreadyRun;
- if(!nemoAlreadyRun){
- log("nemo building overview assistant - v"+String(version));
- }
- nemoAlreadyRun=1;
- beforeBuildcheck();
- }
- void(0);
- /*
- pseudo-pseudocode:
- go through all villages on the table
- 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
- go through the building string, foreach
- check whether the conditions are true to build that AND check whether it is possible to build that
- if yes, build that, unset all variables used, and terminate execution
- if no, go to the next condition
- string definitions:
- q= headquarters
- b= barracks
- s= stable
- g= workshop
- a= acadamy
- y= smithy
- u= statue
- l= rally point
- m= market
- d= wood
- c= clay
- i= iron
- f= farm
- r= warehouse
- h= hiding place
- w= wall
- n= incomings
- t= total building levels
- p= points
- comparisons -
- <
- >
- =
- instruction :
- end instruction ;
- instructions
- b - build
- d - destroy
- l - low priority build //if it has skipped any before this, it will not build this, in order to conserve resources
- //will need some way of making it skip to the next village?
- //huh, i can just make it skip to the next village if it reaches the end of the command string/arr
- //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
- example
- w<20&n=1:bw; //build wall if it's below 20 and there are incomings
- q<30&t<150:bq; //build hq if its below 30 and total village levels are below 150
- 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";
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement