Advertisement
Guest User

research.js

a guest
Dec 23rd, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Updated to reflect R67 changes
  2. //Edited to make changes to TerraForm easier to deal with
  3. //fixed pph for TF
  4. //RMagician 22 Dec 2014
  5.  
  6. //written by RMagician, 23 Dec 2014
  7. //Uses bonus % to confirm is Planet Type is Terra Form
  8. //Note: Will return False Negative if no bonus is taking advantage of max extra research
  9. //there seems to be some sort of error calling the function
  10. /*
  11. function AreWeTerraForm(minr, maxr, textcheck)
  12. {
  13.     var l = '';
  14.     for (var k = minr+1; k <= maxr; k++) {
  15.         l = k.toString() + '%';
  16.         if (textcheck.match(l)) {
  17.             return true;
  18.         }
  19.     }
  20. }
  21. */
  22.  
  23. function MaxScis()
  24. {
  25.     var tds = document.getElementsByTagName("form")[0]
  26.     if(tds)
  27.     {
  28.         var maintable = tds
  29.         var cellHTML = tds.parentNode.innerHTML;
  30.         var lead = cellHTML.indexOf("scientists.<br>You have <b>");
  31.         var posStart = lead + 27;
  32.         var without_resource = cellHTML.substring(posStart, cellHTML.length);
  33.         var posEnd = without_resource.indexOf("</b>");
  34.         var maxScis = without_resource.substring(0, posEnd).replace(/,/g , "");
  35.  
  36.         var forms = document.getElementsByTagName('input');
  37.         for(var i = 0; i< forms.length; i++)
  38.         {  
  39.             if(forms[i].name)
  40.             {
  41.                 forms[i].parentNode.innerHTML += ' - <a href="javascript:Empty();Fill(' + forms[i].name + ',' + maxScis + ')">Max</a>';
  42.             }
  43.         }
  44.     }
  45. }
  46.  
  47. MaxScis();
  48.  
  49. function SciStatusLink()
  50. {
  51.     var newElement = '<div id="scidiv" style="display:inline;">( <a href="javascript:ResearchStatus()" id="scilink" onclick="">Scientists Status</a> )</div>'
  52.  
  53.     var trs = document.getElementsByTagName("div")    
  54.     for(var i = 0; i< trs.length; i++)
  55.     {        
  56.         if(trs[i].innerHTML.match("2000-2012 - BSG Online Games") && !trs[i].innerHTML.match("can get your scientists"))
  57.         {    
  58.             trs[i].innerHTML = newElement + " " + trs[i].innerHTML;      
  59.         }
  60.     }
  61. }
  62.  
  63. function ResearchStatus()
  64. {
  65.     var rLand = fLand();  
  66.     var pph = 1;
  67.     pph = (Math.floor(pph * 100) / 100);
  68.    
  69.      
  70.     //Doesn't take Oceanic nor Research Station into account
  71.     //var OCEANIC_DISADVANTAGE = 25; //not being used
  72.     var TERRA_MAX_BONUS = 20;
  73.     var TERRA_R_EFFIENCE = 50;
  74.     var TerraF = false;
  75.    
  76.     //Bonus when maxed
  77.     var POP_BONUS = 20;
  78.     var POWER_BONUS = 50;
  79.     var MILI_BONUS = 30;
  80.     var MONEY_BONUS = 25;
  81.     var FDC_BONUS = 25;
  82.     var RWCE_BONUS = 20;
  83.    
  84.     //Research Factors  
  85.     //Factor * intended bonus * land * land
  86.     var POP_FACTOR = 0.000466;
  87.     var POWER_FACTOR = 0.000124;
  88.     var MILI_FACTOR = 0.0002;
  89.     var MONEY_FACTOR = 0.000436;
  90.     var FDC_FACTOR = 0.00068;
  91.     var RWCE_FACTOR = 0.00051;
  92.    
  93.     var xBonus = 0; //will be used to store multiplier for TF/Oc
  94.    
  95.     //using these for loops
  96.     var k = 0;
  97.     var l = 0;
  98.    
  99.    
  100.    
  101.    
  102.     var tds = document.getElementsByTagName("div");    
  103.     for(var j = 0; j< tds.length; j++)
  104.     {                                    
  105.         if(tds[j].innerHTML.match("you can get your scientists to research new technologies to better improve your kingdom")&&!tds[j].innerHTML.match("<div class=\"gameDiv\""))  
  106.         {
  107.             var maintable = tds[j];
  108.             var srows = maintable.getElementsByTagName("tr");      
  109.             if(srows)
  110.             {                                  
  111.                 for(var i = 0; i< srows.length; i++)
  112.                 {                                                                                  
  113.                     var cellrow = srows[i];
  114.                     var cells = cellrow.cells;  
  115.                                          
  116.                     if(cellrow.innerHTML.match("<td colspan=\"6\">"))
  117.                     {              
  118.                         cellrow.innerHTML = '<td colspan="7"><input value="Research" class="button" type="submit"></td>';
  119.                     }
  120.                    
  121.                     if(cells[1])
  122.                     {                                                  
  123.                         var prequired = 0;
  124.                         var leeway = 0;
  125.                         var newElement = document.createElement("TD");      
  126.                         var currentPoints = cells[2].innerHTML.replace(/,/g , "");  
  127.                        
  128.                              
  129.                         if(cellrow.innerHTML.match("Population Bonus"))
  130.                         {        
  131.                        
  132.                             /* this would be better if it were a function on its own */
  133.                             //checking if PT = TF
  134.                             if  (! (TerraF)) {
  135.                                 //TerraF = AreWeTerraForm(20,40,cellrow.innerHTML);
  136.                                
  137.                                 //notice 21 to 40 is pop bonus + TF research bonus
  138.                                 for (k = POP_BONUS + 1; k <= (POP_BONUS + TERRA_MAX_BONUS); k++) {
  139.                                     l = k.toString();
  140.                                     l += "%";
  141.                                     if (cellrow.innerHTML.match(l)) {
  142.                                         TerraF = true;
  143.                                         xBonus = TERRA_MAX_BONUS;
  144.                                         pph = 1+(TERRA_R_EFFIENCE/100);
  145.                                     }
  146.                                 }
  147.                             }
  148.                                    
  149.  
  150.                             leeway = Math.floor(Math.sqrt((currentPoints) / (POP_FACTOR * (POP_BONUS+xBonus))) - rLand);
  151.                             prequired = Math.floor(rLand * rLand  * (POP_FACTOR * (POP_BONUS+xBonus)));
  152.                            
  153.                             if(cells[2].innerHTML.replace(/,/g , "") < prequired)
  154.                             {
  155.                                 cells[3].style.color = "#FF0000";
  156.                             }
  157.                            
  158.                            
  159.                         } else if(cellrow.innerHTML.match("Power Bonus")) {
  160.                            
  161.                             /* this would be better if it were a function on its own */
  162.                             //checking if PT = TF
  163.                             if  (! (TerraF)) {
  164.                                 //notice 51 to 70 is power bonus + TF research bonus
  165.                                 for (k = POWER_BONUS+1; k <= (POWER_BONUS+TERRA_MAX_BONUS); k++) {
  166.                                      l = k.toString();
  167.                                     l += "%";
  168.                                     if (cellrow.innerHTML.match(l)) {
  169.                                         TerraF = true;
  170.                                         xBonus = TERRA_MAX_BONUS;
  171.                                         pph = 1+(TERRA_R_EFFIENCE/100);
  172.                                     }
  173.                                 }
  174.                             }
  175.                                                        
  176.                            
  177.                             leeway = Math.floor(Math.sqrt((currentPoints) / (POWER_FACTOR * (POWER_BONUS+xBonus))) - rLand);
  178.                             prequired = Math.floor(rLand * rLand  * (POWER_FACTOR * (POWER_BONUS+xBonus)));
  179.                            
  180.                             if(cells[2].innerHTML.replace(/,/g , "") < prequired)
  181.                             {
  182.                                 cells[3].style.color = "#FF0000";
  183.                             }
  184.                                                        
  185.                            
  186.                         } else if(cellrow.innerHTML.match("Military Bonus")) {
  187.                        
  188.                             /* this would be better if it were a function on its own */
  189.                             //checking if PT = TF
  190.                             if  (! (TerraF)) {
  191.                                 //notice 51 to 70 is power bonus + TF research bonus
  192.                                 for (k = MILI_BONUS+1; k <= (MILI_BONUS+TERRA_MAX_BONUS); k++) {
  193.                                      l = k.toString();
  194.                                     l += "%";
  195.                                     if (cellrow.innerHTML.match(l)) {
  196.                                         TerraF = true;
  197.                                         xBonus = TERRA_MAX_BONUS;
  198.                                         pph = 1+(TERRA_R_EFFIENCE/100);
  199.                                     }
  200.                                 }
  201.                             }
  202.                                                        
  203.                            
  204.                             leeway = Math.floor(Math.sqrt((currentPoints) / (MILI_FACTOR * (MILI_BONUS+xBonus))) - rLand);
  205.                             prequired = Math.floor(rLand * rLand  * (MILI_FACTOR * (MILI_BONUS+xBonus)));
  206.                            
  207.                             if(cells[2].innerHTML.replace(/,/g , "") < prequired)
  208.                             {
  209.                                 cells[3].style.color = "#FF0000";
  210.                             }
  211.                            
  212.                         }   else if(cellrow.innerHTML.match("Money Bonus")) {
  213.                             /* this would be better if it were a function on its own */
  214.                             //checking if PT = TF
  215.                             if  (! (TerraF)) {
  216.                                 //notice 51 to 70 is power bonus + TF research bonus
  217.                                 for (k = MONEY_BONUS+1; k <= (MONEY_BONUS+TERRA_MAX_BONUS); k++) {
  218.                                      l = k.toString();
  219.                                     l += "%";
  220.                                     if (cellrow.innerHTML.match(l)) {
  221.                                         TerraF = true;
  222.                                         xBonus = TERRA_MAX_BONUS;
  223.                                         pph = 1+(TERRA_R_EFFIENCE/100);
  224.                                     }
  225.                                 }
  226.                             }
  227.                                                        
  228.                            
  229.                             leeway = Math.floor(Math.sqrt((currentPoints) / (MONEY_FACTOR * (MONEY_BONUS+xBonus))) - rLand);
  230.                             prequired = Math.floor(rLand * rLand  * (MONEY_FACTOR * (MONEY_BONUS+xBonus)));
  231.                            
  232.                             if(cells[2].innerHTML.replace(/,/g , "") < prequired)
  233.                             {
  234.                                 cells[3].style.color = "#FF0000";
  235.                             }
  236.                            
  237.                         } else if(cellrow.innerHTML.match("Frequency Decryption Center")) {
  238.                             /* this would be better if it were a function on its own */
  239.                             //checking if PT = TF
  240.                             if  (! (TerraF)) {
  241.                                 //notice 51 to 70 is power bonus + TF research bonus
  242.                                 for (k = FDC_BONUS+1; k <= (FDC_BONUS+TERRA_MAX_BONUS); k++) {
  243.                                      l = k.toString();
  244.                                     l += "%";
  245.                                     if (cellrow.innerHTML.match(l)) {
  246.                                         TerraF = true;
  247.                                         xBonus = TERRA_MAX_BONUS;
  248.                                         pph = 1+(TERRA_R_EFFIENCE/100);
  249.                                     }
  250.                                 }
  251.                             }
  252.                                                        
  253.                            
  254.                             leeway = Math.floor(Math.sqrt((currentPoints) / (FDC_FACTOR * (FDC_BONUS+xBonus))) - rLand);
  255.                             prequired = Math.floor(rLand * rLand  * (FDC_FACTOR * (FDC_BONUS+xBonus)));
  256.                            
  257.                             if(cells[2].innerHTML.replace(/,/g , "") < prequired)
  258.                             {
  259.                                 cells[3].style.color = "#FF0000";
  260.                             }
  261.                        
  262.                         } else if(cellrow.innerHTML.match("Reactor Warp Core Efficiency")) {
  263.                             /* this would be better if it were a function on its own */
  264.                             //checking if PT = TF
  265.                             if  (! (TerraF)) {
  266.                                 //notice 51 to 70 is power bonus + TF research bonus
  267.                                 for (k = RWCE_BONUS+1; k <= (RWCE_BONUS+TERRA_MAX_BONUS); k++) {
  268.                                      l = k.toString();
  269.                                     l += "%";
  270.                                     if (cellrow.innerHTML.match(l)) {
  271.                                         TerraF = true;
  272.                                         xBonus = TERRA_MAX_BONUS;
  273.                                         pph = 1+(TERRA_R_EFFIENCE/100);
  274.                                     }
  275.                                 }
  276.                             }
  277.                                                        
  278.                            
  279.                             leeway = Math.floor(Math.sqrt((currentPoints) / (RWCE_FACTOR * (RWCE_BONUS+xBonus))) - rLand);
  280.                             prequired = Math.floor(rLand * rLand  * (RWCE_FACTOR * (RWCE_BONUS+xBonus)));
  281.                            
  282.                             if(cells[2].innerHTML.replace(/,/g , "") < prequired)
  283.                             {
  284.                                 cells[3].style.color = "#FF0000";
  285.                             }
  286.                         }
  287.                         else if(cellrow.innerHTML.match("Dragoons") && ! cellrow.innerHTML.match("Laser"))
  288.                         {
  289.                                 prequired = 60000
  290.                         }
  291.                         else if(cellrow.innerHTML.match("Laser Dragoons"))
  292.                         {
  293.                                 prequired = 72000
  294.                         }
  295.                         else if(cellrow.innerHTML.match("Fighters"))
  296.                         {
  297.                                 prequired = 150000
  298.                         }
  299.                         else if(cellrow.innerHTML.match("S.C.O.U.T.E.R."))
  300.                         {
  301.                                 prequired = 15000
  302.                         }
  303.                         else if(cellrow.innerHTML.match("Vesudian Core"))
  304.                         {
  305.                                 prequired = 500000
  306.                         }
  307.                         else if(cellrow.innerHTML.match("Fusion Technology"))
  308.                         {
  309.                                 prequired = 30000
  310.                         }
  311.                         else if(cellrow.innerHTML.match("Energy Core"))
  312.                         {
  313.                                 prequired = 50000
  314.                         }
  315.                         else if(cellrow.innerHTML.match("Probe"))
  316.                         {
  317.                                 prequired = 92000
  318.                         }
  319.                         else if(cellrow.innerHTML.match("Longevity"))
  320.                         {
  321.                                 prequired = 100000
  322.                         }                      
  323.                    
  324.                         if(prequired>0)
  325.                         {                                                                                                
  326.  
  327.                             var scis = cells[1].innerHTML.replace(/,/g , "");        
  328.                             var points = cells[2].innerHTML.replace(/,/g , "");
  329.                             cells[2].innerHTML = currentPoints + ' / ' + CommaFormatted(prequired);  
  330.                                                                                        
  331.                             var hleft = CommaFormatted(Math.ceil((prequired - points) / (scis * pph)));      
  332.                             if(!hleft)
  333.                             {
  334.                                 hleft = "Infinite";  
  335.                             }
  336.                            
  337.                             if(points >= prequired)
  338.                             {
  339.                                 hleft = "Completed";
  340.                             }
  341.                        
  342.                             if(leeway > 0)
  343.                             {
  344.                                 hleft = leeway + " Land";
  345.                             } else {
  346.                                 if(hleft!="Infinite" && hleft!="Completed")
  347.                                 {
  348.                                     hleft += " Hours";
  349.                                 }
  350.                             }
  351.  
  352.                             newElement.innerHTML = hleft;
  353.                             cells[2].parentNode.insertBefore(newElement, cells[3].nextSibling);
  354.                         }
  355.  
  356.  
  357.                         if(cellrow.innerHTML.match("Number of scientists"))
  358.                         {    
  359.                             cells[1].innerHTML = "Number of Scis";
  360.                             cells[2].innerHTML = "Points / Required";                                          
  361.                             newElement.innerHTML = 'Hours Left/Leeway';
  362.                             cells[2].parentNode.insertBefore(newElement, cells[3].nextSibling);                                                                          
  363.                         }
  364.                     }
  365.                 }
  366.             }
  367.         }
  368.     }    
  369.    
  370.     document.getElementById("scilink").href = "http://www.starkingdoms.com/game/terranova/research/"
  371. }
  372.  
  373. var script2 = document.createElement("script");
  374. script2.type = "application/javascript";
  375. script2.innerHTML = ";" + SciStatusLink + ResearchStatus + ";ResearchStatus(); ";
  376. document.body.appendChild(script2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement