Throne3d

NAFS (latest update 2014-08-28 00:20)

May 29th, 2014
24,715
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 69.50 KB | None | 0 0
  1. var serverTimezones = {"en" : " GMT+0100", "zz" : " GMT+0200", "no" : " GMT+0200"};
  2. var resourceSp = [0, 30, 35, 41, 47, 55, 64, 74, 86, 100, 117, 136, 158, 184, 214, 249, 289, 337, 391, 455, 530, 616, 717, 833,
  3.                     969, 1127, 1311, 1525, 1774, 2063, 2400];
  4. var warehouseC = [0, 1000, 1229, 1512, 1859, 2285, 2810, 3454, 4247, 5222, 6420, 7893, 9705, 11932, 14670, 18037, 22177, 27266,
  5.                     33523, 41217, 50675, 62305, 76604, 94184, 115798, 142373, 175047, 215219, 264611, 325337, 400000];
  6. var carry = {"spear": 25, "sword": 15, "axe": 10, "archer": 10, "scout": 0, "lc": 80, "ma": 50, "hc": 50, "ram": 0, "cat": 0, "paladin": 100}
  7. var speed = {"spear": 18, "sword": 22, "axe": 18, "archer": 18, "scout": 9, "lc": 10, "ma": 10, "hc": 11, "ram": 30, "cat": 30}
  8. var xmlConfig;
  9. /*HQ (1), Barracks (0), Stable (0), Workshop (0), Church (0), Academy (0), Smithy (0), Rally Point (0), Statue (0), Market (0),
  10.     Timber Camp (leave), Clay Pit (leave), Iron Mine (leave), Farm (1), Warehouse (leave), Hiding Place (impossible), Wall (0)*/
  11. var ramsRequired = [0, 2, 4, 7, 10, 14, 19, 24, 30, 37, 45, 55, 65, 77, 91, 106, 124, 143, 166, 191, 219];
  12. var ramsMin = [0, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6];
  13. var catsRequiredTo = [
  14.     /*From [0,1,2, 3, 4, 5, 6, 7, 8, 9,10,11,12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,  29,  30]*/
  15.     /* 0*/ [0,2,6,10,15,21,28,36,45,56,68,82,98,115,136,159,185,215,248,286,328,376,430,490,558,634,720,815,922,1041,1175],
  16.     /* 1*/ [0,0,2, 6,11,17,23,31,39,49,61,74,89,106,126,148,173,202,234,270,312,358,410,469,534,508,691,784,888,1005,1135],
  17.     /* 2*/ [0,0,0, 2, 7,12,18,25,33,43,54,66,81, 97,116,137,161,189,220,255,295,340,390,447,511,583,663,754,855, 968,1095],
  18.     /* 3*/ [0,0,0, 0, 3, 7,13,20,27,36,47,59,72, 88,106,126,149,176,206,240,278,321,370,425,487,557,635,723,821, 932,1055],
  19.     /* 4*/ [0,0,0, 0, 0, 3, 8,14,21,30,40,51,64, 79, 96,115,137,163,192,224,261,303,350,403,463,531,607,692,788, 895,1015],
  20.     /* 5*/ [0,0,0, 0, 0, 0, 3, 9,15,23,32,43,55, 69, 86,104,126,150,177,209,244,285,330,382,440,505,579,661,754, 859, 976],
  21.     /* 6*/ [0,0,0, 0, 0, 0, 0, 3, 9,17,25,35,47, 60, 76, 93,114,137,163,193,227,266,310,360,416,479,550,631,721, 822, 936],
  22.     /* 7*/ [0,0,0, 0, 0, 0, 0, 0, 3,10,18,28,38, 51, 66, 82,102,124,149,178,211,248,290,338,392,453,522,600,687, 786, 896],
  23.     /* 8*/ [0,0,0, 0, 0, 0, 0, 0, 0, 4,11,20,30, 42, 56, 72, 90,111,135,162,194,230,270,316,368,427,494,569,654, 749, 856],
  24.     /* 9*/ [0,0,0, 0, 0, 0, 0, 0, 0, 0, 4,12,22, 33, 46, 61, 78, 98,121,147,177,211,250,294,345,401,466,538,620, 713, 816],
  25.     /*10*/ [0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 4,13, 23, 36, 50, 66, 85,107,132,160,193,230,273,321,376,438,508,587, 676, 777],
  26.     /*11*/ [0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 14, 26, 39, 54, 72, 92,116,143,175,210,251,297,350,409,477,553, 640, 737],
  27.     /*12*/ [0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  5, 16, 28, 42, 59, 78,101,127,156,190,229,273,324,381,446,520, 603, 697],
  28.     /*13*/ [0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  6, 17, 30, 46, 64, 85,110,138,170,207,250,298,353,415,486, 567, 657],
  29.     /*14*/ [0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  6, 18, 33, 50, 70, 93,120,150,186,226,272,325,385,453, 530, 617],
  30.     /*15*/ [0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  6, 20, 36, 54, 76,101,130,164,202,246,297,354,419, 493, 578],
  31.     /*16*/ [0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  7, 22, 39, 59, 83,110,142,178,220,268,323,386, 457, 538],
  32.     /*17*/ [0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  8, 24, 43, 65, 90,120,155,195,240,292,352, 420, 498],
  33.     /*18*/ [0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0,  8, 26, 46, 70, 98,131,169,212,262,319, 384, 458],
  34.     /*19*/ [0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0,  0,  9, 28, 50, 77,107,143,184,231,285, 347, 418],
  35.     /*20*/ [0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0,  0,  0, 10, 30, 55, 84,117,156,200,252, 311, 379],
  36.     /*21*/ [0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 10, 33, 60, 91,127,170,218, 274, 339],
  37.     /*22*/ [0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 11, 36, 65, 99,139,185, 238, 299],
  38.     /*23*/ [0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 12, 39, 71,108,151, 201, 259],
  39.     /*24*/ [0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 13, 43, 77,118, 165, 219],
  40.     /*25*/ [0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 15, 47, 84, 128, 180],
  41.     /*26*/ [0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 16, 51,  92, 140],
  42.     /*27*/ [0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 17,  55, 100],
  43.     /*28*/ [0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  19,  60],
  44.     /*29*/ [0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,   0,  20],
  45.     /*30*/ [0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,   0,   0]
  46. ];
  47. var catsMin = [0,2,2,2,3,3,3,3,3,4,4,4,5,5,6,6,6,7,8,8,9,10,10,11,12,13,15,16,17,19,20];
  48. var months = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
  49. var _a = {
  50.     "en" : {
  51.         "Headquarters" : "Headquarters",
  52.         "Barracks" : "Barracks",
  53.         "Stable" : "Stable",
  54.         "Workshop" : "Workshop",
  55.         "Church" : "Church",
  56.         "First church" : "First church",
  57.         "Academy" : "Academy",
  58.         "Smithy" : "Smithy",
  59.         "Rally point" : "Rally point",
  60.         "Statue" : "Statue",
  61.         "Market" : "Market",
  62.         "Timber camp" : "Timber camp",
  63.         "Clay pit" : "Clay pit",
  64.         "Iron mine" : "Iron mine",
  65.         "Farm" : "Farm",
  66.         "Warehouse" : "Warehouse",
  67.         "Hiding place" : "Hiding place",
  68.         "Wall" : "Wall",
  69.         "Please run this from the 'attacks' menu!" : "Please run this from the 'attacks' menu on the reports page (not all)!",
  70.         "SAVED" : "SAVED",
  71.         "Saved" : "Saved",
  72.         "NOT SAVED" : "NOT SAVED (Village disabled?)",
  73.         "Are you sure you've imported some reports?" : "Are you sure you've imported some reports?",
  74.         "Changed" : "Changed",
  75.         "Attack on" : "Attack on",
  76.         "No villages left to attack! Either add more villages, or wait for the attacks to complete." : "No villages left to attack! Either add more villages, or wait for the attacks to complete.",
  77.         "Add to farm list for " : "Add to farm list for ",
  78.         "Enable farm for " : "Enable farm for ",
  79.         "Disable farm for " : "Disable farm for ",
  80.         "Added" : "Added",
  81.         "Enabled" : "Enabled",
  82.         "Disabled" : "Disabled",
  83.         "Level" : "Level",
  84.         "jan" : "Jan",
  85.         "feb" : "Feb",
  86.         "mar" : "Mar",
  87.         "apr" : "Apr",
  88.         "may" : "May",
  89.         "jun" : "Jun",
  90.         "jul" : "Jul",
  91.         "aug" : "Aug",
  92.         "sep" : "Sep",
  93.         "oct" : "Oct",
  94.         "nov" : "Nov",
  95.         "dec" : "Dec",
  96.         "Coordinates" : "Coordinates",
  97.         "Tribe" : "Tribe",
  98.         "Actions" : "Actions",
  99.         "Defender" : "Defender"
  100.     },
  101.     "no" : {
  102.         "Headquarters" : "Hovedkvarter",
  103.         "Barracks" : "Brakker",
  104.         "Stable" : "Stall",
  105.         "Workshop" : "Verksted",
  106.         "Church" : "Kirke",
  107.         "First church" : "Første Kirke",
  108.         "Academy" : "Akademi",
  109.         "Smithy" : "Smie",
  110.         "Rally point" : "Samlingsplass",
  111.         "Statue" : "Statue",
  112.         "Market" : "Marked",
  113.         "Timber camp" : "Hogstfelt",
  114.         "Clay pit" : "Leirgrav",
  115.         "Iron mine" : "Jerngruve",
  116.         "Farm" : "Gård",
  117.         "Warehouse" : "Varehus",
  118.         "Hiding place" : "Skjulested",
  119.         "Wall" : "Mur",
  120.         "Please run this from the 'attacks' menu!" : "Vennligst kjør dette scrtiptet fra 'angrep' menyen på rapport siden (ikke alle).",
  121.         "SAVED" : "LAGRET",
  122.         "Saved" : "Lagret",
  123.         "NOT SAVED" : "IKKE LAGRET (Landsby deaktivert?)",
  124.         "Are you sure you've imported some reports?" : "Er du sikker på at du har importert rapporter?",
  125.         "Changed" : "Endret",
  126.         "Attack on" : "Angrep på",
  127.         "No villages left to attack! Either add more villages, or wait for the attacks to complete." : "Ingen flere byer igjen til å angripe! Vennligst legg til flere byer, eller vent til angrepene har truffet.",
  128.         "Add to farm list for " : "Legg til i listen over farms for ",
  129.         "Enable farm for " : "Aktiver farm for ",
  130.         "Disable farm for " : "Deaktiver farm for ",
  131.         "Added" : "Lagt til",
  132.         "Enabled" : "Aktivert",
  133.         "Disabled" : "Deaktivert",
  134.         "Level" : "Nivå",
  135.         "jan" : "Jan",
  136.         "feb" : "Feb",
  137.         "mar" : "Mar",
  138.         "apr" : "Apr",
  139.         "may" : "Mai",
  140.         "jun" : "Juni",
  141.         "jul" : "Juli",
  142.         "aug" : "Aug",
  143.         "sep" : "Sep",
  144.         "oct" : "Okt",
  145.         "nov" : "Nov",
  146.         "dec" : "Des",
  147.         "Coordinates" : "Koordinater",
  148.         "Tribe" : "Stamme",
  149.         "Actions" : "Handlinger",
  150.         "Defender" : "Forsvarer"
  151.     }
  152. };
  153. var worldLetters = window.location.host.split(/\W+/)[0].substring(0, 2);
  154. var lang = (localStorage && localStorage.twstuffz && JSON.parse(localStorage.twstuffz)["settings"] && JSON.parse(localStorage.twstuffz)["settings"]["lang"]) || (_a[worldLetters] && worldLetters) || "en";
  155. var catables = [
  156.     {"name" : _("Farm"), "deloc" : "farm", "lowest" : (getSetting("catFarmToZero", false) ? 1 : 12), "select" : "farm"},
  157.     {"name" : _("Headquarters"), "deloc" : "hq", "lowest" : 1, "select" : "main"},
  158.     {"name" : _("Barracks"), "deloc" : "barracks", "lowest" : 0, "select" : "barracks"},
  159.     {"name" : _("Stable"), "deloc" : "stable", "lowest" : 0, "select" : "stable"},
  160.     {"name" : _("Workshop"), "deloc" : "workshop", "lowest" : 0, "select" : "garage"},
  161.     {"name" : _("Academy"), "deloc" : "academy", "lowest" : 0, "select" : "snob"},
  162.     {"name" : _("Smithy"), "deloc" : "smithy", "lowest" : 0, "select" : "smith"},
  163.     {"name" : _("Rally point"), "deloc" : "rally", "lowest" : 0, "select" : "place"},
  164.     {"name" : _("Statue"), "deloc" : "statue", "lowest" : 0, "select" : "statue"},
  165.     {"name" : _("Market"), "deloc" : "market", "lowest" : 0, "select" : "market"}
  166. ];
  167.  
  168. function _(thing){
  169.     return (_a[lang] && _a[lang][thing]) || (_a["en"] && _a["en"][thing]) || thing;
  170. }
  171.  
  172. /*
  173. Changelog:
  174. 2014-08-27, 1.0.7:
  175. -Allows changing of minimum wall level required to send rams.
  176.  
  177. 2014-08-19, 1.0.6:
  178. -New option to prevent import of reports with a player as the defender
  179. -Truly fixed the localization thing (and the stupid page thing - beta has changed that village overview page YET AGAIN)
  180.  
  181. 2014-08-19, 1.0.5c:
  182. -Fixed localizations (duh. forgot to add it for "Coordinates" >_>)
  183.  
  184. 2014-08-19, 1.0.5b:
  185. -Fixed it to work with the new report layout (oops?)
  186. -Fixed it to work with the new village overview layout (hopefully?)
  187.  
  188. 2014-08-15, 1.0.5a:
  189. -Allows more troop variety...
  190.  
  191. 2014-08-01, 1.0.5:
  192. -Now allows the choice of axes or spears (or whichever is available) for catapulting.
  193. -Now allows the choice of spears, swords, axes, LC and mounted archers for regular farming.
  194.  
  195. 2014-07-28, 1.0.4b:
  196. -Fixed a bug relating to ignorance of the "ram" config...
  197.  
  198. 2014-06-29, 1.0.4a:
  199. -Fixed a bug relating to an attack having no millisecond value in the date...
  200.  
  201. 2014-06-28, 1.0.4:
  202. -Modified how it handles dates... made it work on Opera with weird months and stuuf (stupid non-locale handling... y u no follo Chrome? D:<)
  203.  
  204. 2014-06-24, 1.0.3:
  205. -Slight change to method of retrieving resources in village (might have ignored thousands previously? o.o)
  206.  
  207. 2014-06-14, 1.0.2:
  208. -Catapults farm to level 12 now... (Configurable)
  209. -Slight change in the handling of "catsRequiredTo[one/zero]" - now a double array [to][from] instead of To(One/Zero)[from]...
  210.  
  211. 2014-06-14, 1.0.1:
  212. -Allow setting the number of scouts to send
  213.  
  214. 2014-06-07, 1.0.0:
  215. -First release! (Kinda already been released to some people though... and will be released more...)
  216. -Since last version (betas, duh), will now disable banned villages, villages that are too large to be attacked (if on a world with the 140% rule thingy)
  217. -Also has a config script!
  218.  
  219. */
  220.  
  221. function getQuery(name) {
  222.     name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
  223.     var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
  224.         results = regex.exec(location.search);
  225.     return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
  226. }
  227.  
  228. function getQueryFromHaystack(haystack, name){
  229.     name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
  230.     var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
  231.         results = regex.exec(haystack);
  232.     return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
  233. }
  234.  
  235. function getLocalCoords() {
  236.     return $("#menu_row2").text().split("(")[1].split(")")[0].split("|");
  237. }
  238.  
  239. function getLocalName() {
  240.     return $("#menu_row2 a.nowrap").text();
  241. }
  242.  
  243. function getXML(){
  244.     if (xmlConfig === undefined){
  245.         if (window.XMLHttpRequest){
  246.             xmlhttp = new XMLHttpRequest();
  247.         } else {
  248.             xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  249.         }
  250.         xmlhttp.open("GET", window.location.protocol + "//" + window.location.host + "/interface.php?func=get_config", false);
  251.         xmlhttp.send();
  252.         xmlConfig = xmlhttp.responseXML;
  253.     }
  254.     return xmlConfig;
  255. }
  256.  
  257. function getWorldSpeed(){
  258.     return parseFloat(getXML().getElementsByTagName("speed")[0].childNodes[0].nodeValue);
  259. }
  260.  
  261. function getUnitSpeed(){
  262.     return parseFloat(getXML().getElementsByTagName("unit_speed")[0].childNodes[0].nodeValue);
  263. }
  264.  
  265. var settings;
  266.  
  267. /*Settings change: javascript:void(jQuery.getScript('http://pastebin.com/raw.php?i=Vx28j5bu'));
  268.  *javascript:
  269.  */
  270.  
  271. function changeConfig(){
  272.     function clearDisabledFarms(where){
  273.         if (!localStorage) return false;
  274.         if (!localStorage["twstuffz"]) localStorage["twstuffz"] = "{}";
  275.         var twStuffz = JSON.parse(localStorage["twstuffz"]);
  276.        
  277.         if (typeof where === "undefined"){
  278.             for (place in twStuffz){
  279.                 if (place.indexOf(",") !== -1){
  280.                     clearDisabledFarms(place);
  281.                 }
  282.             }
  283.         } else {
  284.             if (place.indexOf(",") !== -1 && twStuffz[place]){
  285.                 vil = twStuffz[place];
  286.                 for (i=0; i<vil.length; i++){
  287.                     if (vil[i].disabled){
  288.                         vil.splice(i, 1);
  289.                         i--;
  290.                     }
  291.                 }
  292.                 localStorage["twstuffz"] = JSON.stringify(twStuffz);
  293.             }
  294.         }
  295.     }
  296.     function getSetting(index, defaul){
  297.         if (!localStorage) return false;
  298.         if (!localStorage["twstuffz"]) localStorage["twstuffz"] = "{}";
  299.         var twStuffz = JSON.parse(localStorage["twstuffz"]);
  300.         if (!twStuffz.settings) twStuffz.settings = {};
  301.         if (typeof twStuffz.settings[index] === "undefined"){
  302.             twStuffz.settings[index] = defaul;
  303.             localStorage["twstuffz"] = JSON.stringify(twStuffz);
  304.         }
  305.         if (twStuffz.settings[index] === "true") return true;
  306.         if (twStuffz.settings[index] === "false") return false;
  307.         return twStuffz.settings[index];
  308.     }
  309.     function changeSetting(index, value){
  310.         if (!localStorage) return false;
  311.         if (!localStorage["twstuffz"]) localStorage["twstuffz"] = "{}";
  312.         var twStuffz = JSON.parse(localStorage["twstuffz"]);
  313.         if (!twStuffz.settings) twStuffz.settings = {};
  314.        
  315.         if (value === "true") value = true;
  316.         if (value === "false") value = false;
  317.        
  318.         twStuffz.settings[index] = value;
  319.         localStorage["twstuffz"] = JSON.stringify(twStuffz);
  320.         return true;
  321.     }
  322.     alert("We will now change the settings of this farming script! Please do not CANCEL, nor type in random stuff, as you will have to redo this!");
  323.     changeSetting("rescout", prompt("Should we re-scout farms with old/stale reports? (true/false)", getSetting("rescout", true)) == "true");
  324.     changeSetting("farm", prompt("Should we farm villages? (true/false)", getSetting("farm", true)) == "true");
  325.     if (getSetting("rescout", true) == true) changeSetting("minScout", parseInt(prompt("How many scouts to send at a minimum per attack?", getSetting("minScout", 1))));
  326.     if (getSetting("farm", true) == true) changeSetting("minLC", parseInt(prompt("How many troops to send at a minimum per farming attack?", getSetting("minLC", 6))));
  327.     if (getSetting("farm", true) == true) {
  328.         var farmWith = prompt("Which troops should we farm with? (spear, sword, axe, archer, lc, ma, hc - separate by commas, no spaces)",
  329.                                 getSetting("farmWith", "lc"));
  330.         var farmWiths = farmWith.replace(/\s+/g, "").split(",");
  331.         farmWiths.forEach(function(element, index, array){
  332.             if (["spear", "sword", "axe", "archer", "lc", "ma", "hc"].indexOf(element.toLowerCase().replace(/[sS]$/, "")) === -1){
  333.                 alert("Invalid unit type: " + element.toLowerCase());
  334.             } else {
  335.                 array[index] = element.toLowerCase().replace(/[sS]$/, "");
  336.             }
  337.         });
  338.         changeSetting("farmWith", farmWiths.join(","));
  339.     }
  340.     changeSetting("hoursToRescout", parseInt(prompt("How many hours until a report expires? (Affected by world speed)", getSetting("hoursToRescout", 36))));
  341.     if (getSetting("rescout", true) == true) changeSetting("hoursToStale", parseInt(prompt("How many hours until a report becomes 'stale' and may be rescouted? (Affected by world speed)", getSetting("hoursToStale", 10))));
  342.     changeSetting("catapult", prompt("Should we use catapults to shape farms? (true/false)", getSetting("catapult", true)) == "true");
  343.     if (getSetting("catapult", true) == true) changeSetting("catFarmToZero", prompt("Should we catapult farms to zero? (Otherwise about level 12 - true/false)", getSetting("catFarmToZero", false)) == "true")
  344.     changeSetting("ram", prompt("Should we use rams to knock down farm walls? (true/false)", getSetting("ram", true)) == "true");
  345.     changeSetting("minWallRam", parseInt(prompt("What should the minimum wall level required to send rams be?", getSetting("minWallRam", 1))));
  346.     if (getSetting("catapult", true) == true || getSetting("ram", true) == true){
  347.         var shapeAlong = prompt("Which troops should we send along with catapults/rams? (spear, sword, axe, archer, lc, ma, hc - separate by commas, no spaces)",
  348.                                 getSetting("shapeAlong", "axe"));
  349.         var shapeAlongs = shapeAlong.replace(/\s+/g, "").split(",");
  350.         shapeAlongs.forEach(function(element, index, array){
  351.             if (["spear", "sword", "axe", "archer", "lc", "ma", "hc"].indexOf(element.toLowerCase().replace(/[sS]$/, "")) === -1){
  352.                 alert("Invalid unit type: " + element.toLowerCase());
  353.             } else {
  354.                 array[index] = element.toLowerCase().replace(/[sS]$/, "");
  355.             }
  356.         });
  357.         changeSetting("shapeAlong", shapeAlongs.join(","));
  358.     }
  359.     if (getSetting("ram", true) == true || getSetting("catapult", true) == true) changeSetting("minAxe", parseInt(prompt("How many troops to send at a minimum along with catapults per shaping attack?", getSetting("minAxe", 25))));
  360.     changeSetting("playerimport", prompt("Should we import reports with players as the defenders? (true/false)", getSetting("playerimport", true)) == "true");
  361.     if (prompt("Clear disabled villages from the farm list? (true/false)", "false") == "true") clearDisabledFarms();
  362. }
  363.  
  364. function getSetting(index, defaul){
  365.     if ((index === "hoursToRescout" || index === "hoursToStale") && !getSetting("rescout", true)){
  366.         return 300000;
  367.     }
  368.     if (!settings){
  369.         if (!localStorage) return false;
  370.         if (!localStorage["twstuffz"]) localStorage["twstuffz"] = "{}";
  371.         var twStuffz = JSON.parse(localStorage["twstuffz"]);
  372.         if (!twStuffz.settings) twStuffz.settings = {};
  373.         settings = twStuffz.settings;
  374.     }
  375.     if (typeof settings[index] === "undefined"){
  376.         if (!localStorage) return false;
  377.         if (!localStorage["twstuffz"]) localStorage["twstuffz"] = "{}";
  378.         var twStuffz = JSON.parse(localStorage["twstuffz"]);
  379.         if (!twStuffz.settings) twStuffz.settings = {};
  380.         twStuffz.settings[index] = defaul;
  381.         settings[index] = defaul;
  382.         localStorage["twstuffz"] = JSON.stringify(twStuffz);
  383.     }
  384.     if (settings[index] === "true") return true;
  385.     if (settings[index] === "false") return false;
  386.     return settings[index];
  387. }
  388.  
  389. /*
  390. function changeSetting(index, value){
  391.     if (!localStorage) return false;
  392.     if (!localStorage["twstuffz"]) localStorage["twstuffz"] = "{}";
  393.     var twStuffz = JSON.parse(localStorage["twstuffz"]);
  394.     if (!twStuffz.settings) twStuffz.settings = {};
  395.     twStuffz.settings[index] = value;
  396.     localStorage["twstuffz"] = JSON.stringify(twStuffz);
  397.     return true;
  398. }
  399. */
  400.  
  401. function changeSetting(index, value){
  402.     if (!localStorage) return false;
  403.     if (!localStorage["twstuffz"]) localStorage["twstuffz"] = "{}";
  404.     var twStuffz = JSON.parse(localStorage["twstuffz"]);
  405.     if (!twStuffz.settings) twStuffz.settings = {};
  406.    
  407.     if (value === "true") value = true;
  408.     if (value === "false") value = false;
  409.    
  410.     twStuffz.settings[index] = value;
  411.     localStorage["twstuffz"] = JSON.stringify(twStuffz);
  412.     /*twstuffs {
  413.         settings : {
  414.             rescout: true(/false),
  415.             farm: true(/false),
  416.             minLC: 6,
  417.             minAxe: 25,
  418.             hoursToRescout: 36,
  419.             hoursToStale: 10,
  420.             catapult: true(/false),
  421.             ram: true(/false),
  422.             ...
  423.         },
  424.         xxx|yyy : [ ... ]
  425.     }
  426.     */
  427.     settings[index] = value;
  428.     return true;
  429. }
  430.  
  431. function addReport(reportID, localCoords, vilCoords, wood, clay, iron, battleTime, buildings){
  432.     if (!localStorage) return false;
  433.     if (!localStorage["twstuffz"]) localStorage["twstuffz"] = "{}";
  434.     var twStuffz = JSON.parse(localStorage["twstuffz"]);
  435.     if (!twStuffz[localCoords]) twStuffz[localCoords] = [];
  436.     var vilIndex;
  437.     twStuffz[localCoords].forEach(function(element, index) {
  438.         if (element.coords === (vilCoords[0] + "|" + vilCoords[1])) vilIndex = index;
  439.     });
  440.     if (typeof vilIndex === "undefined"){
  441.         vilIndex = twStuffz[localCoords].push({
  442.             coords: (vilCoords[0] + "|" + vilCoords[1]),
  443.             disabled: false,
  444.             distance: (Math.floor(Math.sqrt(Math.pow(vilCoords[0]-localCoords[0],2)+Math.pow(vilCoords[1]-localCoords[1],2))*100)/100),
  445.             reports: [ ]
  446.         });
  447.         twStuffz[localCoords].sort(function(a, b){
  448.             return a.distance - b.distance;
  449.         });
  450.     }
  451.    
  452.     var vilIndex = undefined;
  453.     twStuffz[localCoords].forEach(function(element, index) {
  454.         if (element.coords === (vilCoords[0] + "|" + vilCoords[1])) vilIndex = index;
  455.     });
  456.    
  457.     if (typeof vilIndex === "undefined"){ /*Something has gone wrong! Not there even after we created it; wut?*/
  458.         console.log("just created, no exist. wut.");
  459.         return false;
  460.     }
  461.    
  462.     if (twStuffz[localCoords][vilIndex].disabled){
  463.         return false;
  464.     }
  465.    
  466.     if (typeof buildings["barracks"] === "undefined") buildings["barracks"] = 0;
  467.     if (typeof buildings["rally"] === "undefined") buildings["rally"] = 0;
  468.     if (typeof buildings["stable"] === "undefined") buildings["stable"] = 0;
  469.     if (typeof buildings["workshop"] === "undefined") buildings["workshop"] = 0;
  470.     if (typeof buildings["academy"] === "undefined") buildings["academy"] = 0;
  471.     if (typeof buildings["smithy"] === "undefined") buildings["smithy"] = 0;
  472.     if (typeof buildings["statue"] === "undefined") buildings["statue"] = 0;
  473.     if (typeof buildings["market"] === "undefined") buildings["market"] = 0;
  474.     if (typeof buildings["hq"] === "undefined") buildings["hq"] = 0;
  475.     if (typeof buildings["farm"] === "undefined") buildings["farm"] = 0;
  476.     if (typeof buildings["wall"] === "undefined") buildings["wall"] = 0;
  477.    
  478.     battleTime = Number(battleTime);
  479.     var exists = false;
  480.     twStuffz[localCoords][vilIndex]["reports"].forEach(function(element){
  481.         if (element["reportID"] === reportID) exists = true;
  482.     });
  483.     if (!exists) twStuffz[localCoords][vilIndex]["reports"].push({
  484.         "reportID" : reportID,
  485.         "battleTime" : battleTime,
  486.         "wood" : wood,
  487.         "clay" : clay,
  488.         "iron" : iron,
  489.         "buildings" : buildings
  490.     });
  491.    
  492.     twStuffz[localCoords][vilIndex]["reports"].sort(function(a, b) {
  493.         return b["battleTime"] - a["battleTime"];
  494.     });
  495.    
  496.     while (twStuffz[localCoords][vilIndex]["reports"].length > 1) { twStuffz[localCoords][vilIndex]["reports"].pop() };
  497.    
  498.     localStorage["twstuffz"] = JSON.stringify(twStuffz);
  499.     return true;
  500. }
  501.  
  502. function insertUnits(troops, minTroops){
  503.     if (getQuery("screen") !== "place"){
  504.         console.log("Wrong screen. Should be at rally point.");
  505.         return false;
  506.     }
  507.     if (typeof minTroops === "undefined") minTroops = {};
  508.    
  509.     if (troops["scout"]) troops["spy"] = troops["scout"];
  510.     if (minTroops["scout"]) minTroops["spy"] = minTroops["scout"];
  511.     if (troops["lc"]) troops["light"] = troops["lc"];
  512.     if (minTroops["lc"]) troops["light"] = troops["lc"];
  513.    
  514.     var maxSpy = parseInt($("#unit_input_spy").parent("td").text().split("(")[1].split(")")[0]),
  515.         maxSpear = parseInt($("#unit_input_spear").parent("td").text().split("(")[1].split(")")[0]),
  516.         maxSword = parseInt($("#unit_input_sword").parent("td").text().split("(")[1].split(")")[0]),
  517.         maxAxe = parseInt($("#unit_input_axe").parent("td").text().split("(")[1].split(")")[0]),
  518.         maxArcher = $("#unit_input_archer").length > 0 ? parseInt($("#unit_input_archer").parent("td").text().split("(")[1].split(")")[0]) : 0,
  519.         maxLight = parseInt($("#unit_input_light").parent("td").text().split("(")[1].split(")")[0]),
  520.         maxMA = $("#unit_input_marcher").length > 0 ? parseInt($("#unit_input_marcher").parent("td").text().split("(")[1].split(")")[0]) : 0,
  521.         maxHeavy = parseInt($("#unit_input_heavy").parent("td").text().split("(")[1].split(")")[0]),
  522.         maxRam = parseInt($("#unit_input_ram").parent("td").text().split("(")[1].split(")")[0]),
  523.         maxCatapult = parseInt($("#unit_input_catapult").parent("td").text().split("(")[1].split(")")[0]);
  524.    
  525.     var doneGood = true;
  526.    
  527.     $("#unit_input_archer").length < 1 && delete troops["archer"] && delete minTroops["archer"];
  528.     $("#unit_input_marcher").length < 1 && delete troops["ma"] && delete minTroops["ma"];
  529.    
  530.     if ((minTroops["spy"] && minTroops["spy"] > maxSpy) || (!minTroops["spy"] && troops["spy"] && troops["spy"] > maxSpy)) doneGood = false;
  531.     if ((minTroops["spear"] && minTroops["spear"] > maxSpear) || (!minTroops["spear"] && troops["spear"] && troops["spear"] > maxSpear)) doneGood = false;
  532.     if ((minTroops["sword"] && minTroops["sword"] > maxSword) || (!minTroops["sword"] && troops["sword"] && troops["sword"] > maxSword)) doneGood = false;
  533.     if ((minTroops["axe"] && minTroops["axe"] > maxAxe) || (!minTroops["axe"] && troops["axe"] && troops["axe"] > maxAxe)) doneGood = false;
  534.     if ((minTroops["archer"] && minTroops["archer"] > maxArcher) || (!minTroops["archer"] && troops["archer"] && troops["archer"] > maxArcher)) doneGood = false;
  535.     if ((minTroops["light"] && minTroops["light"] > maxLight) || (!minTroops["light"] && troops["light"] && troops["light"] > maxLight)) doneGood = false;
  536.     if ((minTroops["ma"] && minTroops["ma"] > maxMA) || (!minTroops["ma"] && troops["ma"] && troops["ma"] > maxMA)) doneGood = false;
  537.     if ((minTroops["heavy"] && minTroops["heavy"] > maxHeavy) || (!minTroops["heavy"] && troops["heavy"] && troops["heavy"] > maxHeavy)) doneGood = false;
  538.     if ((minTroops["ram"] && minTroops["ram"] > maxRam) || (!minTroops["ram"] && troops["ram"] && troops["ram"] > maxRam)) doneGood = false;
  539.     if ((minTroops["catapult"] && minTroops["catapult"] > maxCatapult) || (!minTroops["catapult"] && troops["catapult"] && troops["catapult"] > maxCatapult)) doneGood = false;
  540.    
  541.     if (doneGood){
  542.         troops["spy"] && $("#unit_input_spy").val((troops["spy"] <= maxSpy) ? troops["spy"] : maxSpy);
  543.         troops["spear"] && $("#unit_input_spear").val((troops["spear"] <= maxSpear) ? troops["spear"] : maxSpear);
  544.         troops["sword"] && $("#unit_input_sword").val((troops["sword"] <= maxSword) ? troops["sword"] : maxSword);
  545.         troops["axe"] && $("#unit_input_axe").val((troops["axe"] <= maxAxe) ? troops["axe"] : maxAxe);
  546.         troops["archer"] && $("#unit_input_archer").val((troops["archer"] <= maxArcher) ? troops["archer"] : maxArcher);
  547.         troops["light"] && $("#unit_input_light").val((troops["light"] <= maxLight) ? troops["light"] : maxLight);
  548.         troops["ma"] && $("#unit_input_marcher").val((troops["ma"] <= maxMA) ? troops["ma"] : maxMA);
  549.         troops["heavy"] && $("#unit_input_heavy").val((troops["heavy"] <= maxHeavy) ? troops["heavy"] : maxHeavy);
  550.         troops["ram"] && $("#unit_input_ram").val((troops["ram"] <= maxRam) ? troops["ram"] : maxRam);
  551.         troops["catapult"] && $("#unit_input_catapult").val((troops["catapult"] <= maxCatapult) ? troops["catapult"] : maxCatapult);
  552.     }
  553.    
  554.     (!doneGood || !troops["spy"]) && $("#unit_input_spy").val() !== "" && $("#unit_input_spy").val("");
  555.     (!doneGood || !troops["spear"]) && $("#unit_input_spear").val() !== "" && $("#unit_input_spear").val("");
  556.     (!doneGood || !troops["sword"]) && $("#unit_input_sword").val() !== "" && $("#unit_input_sword").val("");
  557.     (!doneGood || !troops["axe"]) && $("#unit_input_axe").val() !== "" && $("#unit_input_axe").val("");
  558.     (!doneGood || !troops["archer"]) && $("#unit_input_archer").val() !== "" && $("#unit_input_archer").val("");
  559.     (!doneGood || !troops["light"]) && $("#unit_input_light").val() !== "" && $("#unit_input_light").val("");
  560.     (!doneGood || !troops["ma"]) && $("#unit_input_marcher").val() !== "" && $("#unit_input_marcher").val("");
  561.     (!doneGood || !troops["heavy"]) && $("#unit_input_heavy").val() !== "" && $("#unit_input_heavy").val("");
  562.     (!doneGood || !troops["ram"]) && $("#unit_input_ram").val() !== "" && $("#unit_input_ram").val("");
  563.     (!doneGood || !troops["catapult"]) && $("#unit_input_catapult").val() !== "" && $("#unit_input_catapult").val("");
  564.    
  565.     return doneGood;
  566. }
  567.  
  568. function def(){
  569.     if (!localStorage){ alert("ERROR: You don't have LocalStorage! Please update to a newer browser - this script won't work for you."); return; }
  570.     if (getQuery("screen") === "report"){
  571.         if (getQuery("view") === "" && (getQuery("mode") === "all" || getQuery("mode") === "")) {
  572.             if ($("#twswarning").length === 0)
  573.                 $("#report_list").before($("<span id='twswarning' style='color:#F00;font-weight:bold;'>" + _("Please run this from the 'attacks' menu!") + "</span>"));
  574.         } else if (getQuery("view") === "" && getQuery("mode") === "attack"){
  575.             /*We're on the report screen.*/
  576.             $("#report_list tbody tr:has(img) .quickedit-content").each(function(index){
  577.                 /*var name = this.innerText.split("(")[1].split(")")[0];
  578.                 if (name !== getLocalName()) //not from this village
  579.                     return;*/
  580.                 var coords = $(this).text().trim().split("(")[2].split(")")[0].split("|");
  581.                 var localCoords = getLocalCoords();
  582.                 /*this.innerHTML += " - " + (Math.round(Math.sqrt(Math.pow(coords[0] - localCoords[0], 2) + Math.pow(coords[1] - localCoords[1], 2)) * 100) / 100);*/
  583.                 var a = jQuery.ajax($("a", $(this)).attr("href"), {type: "GET", dataType:"html", async:false});
  584.                 var b = a.responseText;
  585.                 var c = $("<div></div>");
  586.                 c.get(0).id = "TWSReportThing";
  587.                 c.html(b);
  588.                 if (doReport(c, getQueryFromHaystack($("a", $(this)).attr("href"), "view"))){
  589.                     this.innerHTML += " - " + _("SAVED");
  590.                     $("input[type='checkbox']", $(this).parent().parent().parent()).prop("checked", true);
  591.                 } else {
  592.                     this.innerHTML += " - " + _("NOT SAVED");
  593.                 }
  594.             });
  595.         } else {
  596.             doReport(document, getQuery("view"));
  597.         }
  598.     //$("#units_form").length === 0 : we r not on regular rally page.
  599.     //$("#units_form").length >= 1  : we r on regular rally page.
  600.     } else if (getQuery("screen") === "place" && $("#units_form").length === 0){
  601.         var twStuffz = localStorage && localStorage.twstuffz && JSON.parse(localStorage.twstuffz);
  602.         var localCoords = getLocalCoords();
  603.         var twStuffzLocal = twStuffz && twStuffz[localCoords];
  604.         if (!twStuffzLocal){
  605.             console && console.log && console.log("Go import some reports fgs >.>");
  606.         } else {
  607.             var vilCoords = $(".village_anchor").text().split("(")[1].split(")")[0].split("|");
  608.             var vilIndex;
  609.             twStuffzLocal.forEach(function(element, index) {
  610.                 if (element.coords === (vilCoords[0] + "|" + vilCoords[1])) vilIndex = index;
  611.             });
  612.             if (typeof vilIndex === "undefined"){
  613.                 console && console.log && console.log("Go import some reports for this village fgs >.>");
  614.             } else {
  615.                 var villageDat = twStuffzLocal[vilIndex]
  616.                 var latestReport = villageDat && villageDat["reports"] && villageDat["reports"][0];
  617.                 if (latestReport){
  618.                     var catThing;
  619.                     catables.forEach(function(element, index, array){
  620.                         if (catThing) return;
  621.                         if (latestReport
  622.                           && latestReport["buildings"]
  623.                           && latestReport["buildings"][element.deloc]
  624.                           && latestReport["buildings"][element.deloc] > element.lowest) {
  625.                             element.current = latestReport["buildings"][element.deloc];
  626.                             catThing = element;
  627.                         }
  628.                     });
  629.                     if (catThing){
  630.                         $("select[name='building']").val(catThing.select);
  631.                         $("select[name='building']").after($("#catThingy").get(0) || $("<span id='catThingy' style='color:#0A0;'>" + _("Changed") + "</span>").get(0));
  632.                        
  633.                     }
  634.                     $("#troop_confirm_go").focus();
  635.                 }
  636.             }
  637.         }
  638.     //$("#units_form").length === 0 : we r not on regular rally page.
  639.     //$("#units_form").length >= 1  : we r on regular rally page.
  640.     } else if (getQuery("screen") === "place" && $("#units_form").length >= 1){
  641.         var linke = ($("#twstuffzerror").length >= 1) ? $("#twstuffzerror") : $("<span id='twstuffzerror'>ERROR_MSG</span>").css("color", "#F00");
  642.         linke.css("display", "none");
  643.         $($("#units_form table").get(0)).before(linke);
  644.         (function(){
  645.             var twStuffz = localStorage && localStorage["twstuffz"] && JSON.parse(localStorage["twstuffz"]);
  646.             var twStuffzLocal = twStuffz && twStuffz[getLocalCoords()];
  647.             if (!twStuffzLocal){
  648.                 linke.text(_("Are you sure you've imported some reports?")).css("display", "block");
  649.             } else {
  650.                 var errorBoxText = $(".error_box").text().trim();
  651.                 if (errorBoxText.indexOf("can only attack each other when the bigger player's points") !== -1
  652.                     || errorBoxText.indexOf("has been banned and cannot be attacked") !== -1){
  653.                     //Go disable teh village. - banned or too large/small.
  654.                     var vilCoords = $(".village-name").length >= 1 && $(".village-name").text().trim().split("(")[1].split(")")[0];
  655.                     if (vilCoords){
  656.                         var twStuffz = localStorage && localStorage["twstuffz"] && JSON.parse(localStorage["twstuffz"]);
  657.                         var twStuffzLocal = twStuffz && twStuffz[getLocalCoords()];
  658.                         var vilIndex;
  659.                         twStuffzLocal.forEach(function(element, index) {
  660.                             if (element.coords === vilCoords) vilIndex = index;
  661.                         });
  662.                         twStuffz[getLocalCoords()][vilIndex].disabled = true;
  663.                         localStorage.twstuffz = JSON.stringify(twStuffz);
  664.                         $(".error_box").html("Previous farm disabled... (Please <a href='" + window.location.href.replace("&try=confirm", "").replace(/\&target\=\d*/, "") + "'>reopen rally point</a>)");
  665.                     }
  666.                 } else {
  667.                     linke.css("display", "none").text("ERROR_MSG");
  668.                     /* First check for things to (catapult and) ram. Reports expire in 36 hours / world speed.*/
  669.                     var troopsEntered = false;
  670.                     twStuffzLocal.forEach(function(element, index, array){
  671.                         if (troopsEntered) return false;
  672.                         var alreadyAttacking = false;
  673.                         $(".quickedit-content span").each(function(){
  674.                             if ($(this).text().trim().indexOf(_("Attack on")) !== -1 && $(this).text().trim().split("(")[1].split(")")[0] === element.coords)
  675.                                 alreadyAttacking = true;
  676.                         });
  677.         /*Wall (0), HQ (1), Barracks (0), Stable (0), Workshop (0), Church (0), Academy (0), Smithy (0), Rally Point (0), Statue (0), Market (0),
  678.         Timber Camp (leave), Clay Pit (leave), Iron Mine (leave), Farm (1), Warehouse (leave), Hiding Place (impossible)*/
  679.                         if (!alreadyAttacking && !element["disabled"]){
  680.                             var latestReport = element && element["reports"] && element["reports"][0];
  681.                             var shouldCat = getSetting("catapult", true);
  682.                             var shouldRam = getSetting("ram", true);
  683.                             var wall = (shouldRam) ? latestReport && latestReport["buildings"] && latestReport["buildings"]["wall"] : 0;
  684.                             if (!shouldCat && !shouldRam) return;
  685.                             var catThing;
  686.                             if (shouldCat) catables.forEach(function(element, index, array){
  687.                                 if (catThing) return;
  688.                                 if (latestReport
  689.                                   && latestReport["buildings"]
  690.                                   && latestReport["buildings"][element.deloc]
  691.                                   && latestReport["buildings"][element.deloc] > element.lowest) {
  692.                                     element.current = latestReport["buildings"][element.deloc];
  693.                                     catThing = element;
  694.                                 }
  695.                             });
  696.                             if (latestReport && (Number(new Date()) - latestReport.battleTime) < ((getSetting("hoursToRescout", 36) * 60 * 60 * 1000) / getWorldSpeed())
  697.                                   && latestReport["buildings"] && (latestReport["buildings"]["wall"] > getSetting("minWallRam", 1) || catThing)){
  698.                                 var units = {spy:getSetting("minScout", 1)};
  699.                                 var shapeAlong = getSetting("farmAlong", "axe").split(",");
  700.                                 if (wall >= getSetting("minWallRam", 1)) units["ram"] = ramsRequired[wall];
  701.                                 if (catThing) units["catapult"] = catsRequiredTo[catThing.lowest][catThing.current];
  702.                                 var minUnits = {spy:getSetting("minScout", 1)};
  703.                                 if (wall >= getSetting("minWallRam", 1)) minUnits["ram"] = ramsMin[wall];
  704.                                 if (catThing) minUnits["catapult"] = catsMin[catThing.current];
  705.                                
  706.                                 for (var i=0; i<shapeAlong.length; i++){
  707.                                     if (troopsEntered) break;
  708.                                     units[shapeAlong[i]] = getSetting("minAxe", 25);
  709.                                     minUnits[shapeAlong[i]] = getSetting("minAxe", 25);
  710.                                    
  711.                                     if (insertUnits(units, minUnits)){
  712.                                         $("#inputx").val(element.coords.split("|")[0]);
  713.                                         $("#inputy").val(element.coords.split("|")[1]);
  714.                                        
  715.                                         $('#unit_input_spear').focus();
  716.                                         troopsEntered = true;
  717.                                     } else {
  718.                                         if (catThing){
  719.                                             delete units.ram;
  720.                                             delete minUnits.ram;
  721.                                         }
  722.                                         if (insertUnits(units, minUnits)){
  723.                                             $("#inputx").val(element.coords.split("|")[0]);
  724.                                             $("#inputy").val(element.coords.split("|")[1]);
  725.                                            
  726.                                             $('#unit_input_spear').focus();
  727.                                             troopsEntered = true;
  728.                                         } else {
  729.                                             if (wall > 0){
  730.                                                 units.ram = ramsRequired[wall];
  731.                                                 minUnits.ram = ramsMin[wall];
  732.                                                 delete units.catapult;
  733.                                                 delete minUnits.catapult;
  734.                                                 if (insertUnits(units, minUnits)){
  735.                                                     $("#inputx").val(element.coords.split("|")[0]);
  736.                                                     $("#inputy").val(element.coords.split("|")[1]);
  737.                                                    
  738.                                                     $('#unit_input_spear').focus();
  739.                                                     troopsEntered = true;
  740.                                                 }
  741.                                             }
  742.                                         }
  743.                                     }
  744.                                 }
  745.                             } /*else continue as if village no existo*/
  746.                         } /*else continue as if village no existo.*/
  747.                     });
  748.                     /*Let's check for things to just... y'know... farm via LC. Reports expire in 36 hours / world speed.*/
  749.                     if (getSetting("farm", true))
  750.                     twStuffzLocal.forEach(function(element, index, array){
  751.                         if (troopsEntered) return false;
  752.                         var alreadyAttacking = false;
  753.                         $(".quickedit-content span").each(function(){
  754.                             if ($(this).text().trim().indexOf(_("Attack on")) !== -1 && $(this).text().trim().split("(")[1].split(")")[0] === element.coords)
  755.                                 alreadyAttacking = true;
  756.                         });
  757.                         if (!alreadyAttacking && !element["disabled"]){
  758.                             var latestReport = element && element["reports"] && element["reports"][0];
  759.                             if (latestReport && (Number(new Date()) - latestReport.battleTime) < ((getSetting("hoursToRescout", 36) * 60 * 60 * 1000) / getWorldSpeed())){
  760.                                 var wood = latestReport.wood,
  761.                                     clay = latestReport.clay,
  762.                                     iron = latestReport.iron;
  763.                                 var woodCamp = latestReport.buildings.woodcamp,
  764.                                     clayCamp = latestReport.buildings.claycamp,
  765.                                     ironCamp = latestReport.buildings.ironcamp,
  766.                                     warehouse = latestReport.buildings.warehouse;
  767.                                 var hoursAgo = (Number(new Date()) - latestReport.battleTime) / 60 / 60 / 1000;
  768.                                 var wood2 = wood + (resourceSp[woodCamp] * hoursAgo * getWorldSpeed()),
  769.                                     clay2 = clay + (resourceSp[clayCamp] * hoursAgo * getWorldSpeed()),
  770.                                     iron2 = iron + (resourceSp[ironCamp] * hoursAgo * getWorldSpeed());
  771.                                 wood2 = (wood2 > warehouseC[warehouse]) ? warehouseC[warehouse] : wood2;
  772.                                 clay2 = (clay2 > warehouseC[warehouse]) ? warehouseC[warehouse] : clay2;
  773.                                 iron2 = (iron2 > warehouseC[warehouse]) ? warehouseC[warehouse] : iron2;
  774.                                 var distance = element.distance;
  775.                                 var farmWith = getSetting("farmWith", "lc").split(",");
  776.                                 for (var i=0; i<farmWith.length; i++){
  777.                                     if (troopsEntered) break;
  778.                                     var hours = distance * (speed[farmWith[i]] / getUnitSpeed()) / 60;
  779.                                     var wood3 = wood2 + (resourceSp[woodCamp] * hours * getWorldSpeed()),
  780.                                         clay3 = clay2 + (resourceSp[clayCamp] * hours * getWorldSpeed()),
  781.                                         iron3 = iron2 + (resourceSp[ironCamp] * hours * getWorldSpeed());
  782.                                     wood3 = (wood3 > warehouseC[warehouse]) ? warehouseC[warehouse] : wood3;
  783.                                     clay3 = (clay3 > warehouseC[warehouse]) ? warehouseC[warehouse] : clay3;
  784.                                     iron3 = (iron3 > warehouseC[warehouse]) ? warehouseC[warehouse] : iron3;
  785.                                     if ((wood3 + clay3 + iron3) / carry[farmWith[i]] + 0.25 >= getSetting("minLC", 6)){
  786.                                         var units = {spy:getSetting("minScout", 1)},
  787.                                             minUnits = {spy:getSetting("minScout", 1)};
  788.                                         minUnits[farmWith[i]] = getSetting("minLC", 6);
  789.                                         units[farmWith[i]] = Math.floor((wood3 + clay3 + iron3) / carry[farmWith[i]] + 0.25);
  790.                                         if (insertUnits(units, minUnits)){
  791.                                             $("#inputx").val(element.coords.split("|")[0]);
  792.                                             $("#inputy").val(element.coords.split("|")[1]);
  793.                                            
  794.                                             $('#unit_input_spear').focus();
  795.                                             troopsEntered = true;
  796.                                         }
  797.                                     }
  798.                                 }
  799.                                
  800.                                
  801.                             }
  802.                         }
  803.                     });
  804.                     /*Okay. Nothing left under current report expiration. Time to re-scout dem viwwagez (that are over 10 hours / world speed old).*/
  805.                     if (getSetting("rescout", true))
  806.                     twStuffzLocal.forEach(function(element, index, array){
  807.                         if (troopsEntered) return false;
  808.                         var alreadyAttacking = false;
  809.                         $(".quickedit-content span").each(function(){
  810.                             if ($(this).text().trim().indexOf(_("Attack on")) !== -1 && $(this).text().trim().split("(")[1].split(")")[0] === element.coords)
  811.                                 alreadyAttacking = true;
  812.                         });
  813.                         if (!alreadyAttacking && !element["disabled"]){
  814.                             var latestReport = element && element["reports"] && element["reports"][0];
  815.                             if ((latestReport && (Number(new Date()) - latestReport.battleTime) > ((getSetting("hoursToStale", 10) * 60 * 60 * 1000) / getWorldSpeed())) || !latestReport){
  816.                                 if (insertUnits({spy:getSetting("minScout", 1)})){
  817.                                     $("#inputx").val(element.coords.split("|")[0]);
  818.                                     $("#inputy").val(element.coords.split("|")[1]);
  819.                                    
  820.                                     $('#unit_input_spear').focus();
  821.                                     troopsEntered = true;
  822.                                 }
  823.                             }
  824.                         }
  825.                     });
  826.                    
  827.                     if (!troopsEntered) {
  828.                         linke.text(_("No villages left to attack! Either add more villages, or wait for the attacks to complete.")).css("display", "block");
  829.                     }
  830.                 }
  831.             }
  832.         })();
  833.     } else if (getQuery("screen") === "info_village"){
  834.         var vilTable = $("#content_value table table[width='100%']");
  835.         var vilCoords = $("tr:contains('" + _("Coordinates") + "')", vilTable).text().split(":")[1].split("|");
  836.         var localCoords = getLocalCoords();
  837.         var tribe = $("tr:contains('" + _("Tribe") + "')", vilTable)
  838.        
  839.         if (!localStorage) return false;
  840.         if (!localStorage["twstuffz"]) localStorage["twstuffz"] = "{}";
  841.         var twStuffz = JSON.parse(localStorage["twstuffz"]);
  842.         if (!twStuffz[localCoords]) twStuffz[localCoords] = [];
  843.         var vilIndex;
  844.         twStuffz[localCoords].forEach(function(element, index) {
  845.             if (element.coords === (vilCoords[0] + "|" + vilCoords[1])) vilIndex = index;
  846.         });
  847.         var clickText = "";
  848.         var type = -2;
  849.         if (typeof vilIndex === "undefined"){
  850.             clickText = _("Add to farm list for ") + getLocalName();
  851.             type = -1;
  852.         } else if (twStuffz[localCoords][vilIndex].disabled){
  853.             clickText = _("Enable farm for ") + getLocalName();
  854.             type = 1;
  855.         } else {
  856.             clickText = _("Disable farm for ") + getLocalName();
  857.             type = 0;
  858.         }
  859.         var thingy = $("<tr><td colspan='2'></td></tr>");
  860.         var thingy2 = $("<tr><td colspan='2'></td></tr>").css("display", "none");
  861.         $("td", thingy).append($("<a style='cursor:pointer;'>» " + clickText + "</a>").on("click", function(){
  862.             if (!localStorage) return false;
  863.             if (!localStorage["twstuffz"]) localStorage["twstuffz"] = "{}";
  864.             var twStuffz = JSON.parse(localStorage["twstuffz"]);
  865.             if (!twStuffz[localCoords]) twStuffz[localCoords] = [];
  866.             if (type === -1){
  867.                 vilIndex = twStuffz[localCoords].push({
  868.                     coords: (vilCoords[0] + "|" + vilCoords[1]),
  869.                     disabled: false,
  870.                     distance: (Math.floor(Math.sqrt(Math.pow(vilCoords[0]-localCoords[0],2)+Math.pow(vilCoords[1]-localCoords[1],2))*100)/100),
  871.                     reports: [ ]
  872.                 });
  873.                 twStuffz[localCoords].sort(function(a, b){
  874.                     return a.distance - b.distance;
  875.                 });
  876.                 $("td", thingy2).text(_("Added"));
  877.             } else {
  878.                 var vilIndex;
  879.                 twStuffz[localCoords].forEach(function(element, index) {
  880.                     if (element.coords === (vilCoords[0] + "|" + vilCoords[1])) vilIndex = index;
  881.                 });
  882.                 if (type === 0){
  883.                     twStuffz[localCoords][vilIndex].disabled = true;
  884.                     $("td", thingy2).text(_("Disabled"));
  885.                 } else {
  886.                     twStuffz[localCoords][vilIndex].disabled = false;
  887.                     $("td", thingy2).text(_("Enabled"));
  888.                 }
  889.             }
  890.             localStorage["twstuffz"] = JSON.stringify(twStuffz);
  891.             thingy.css("display", "none");
  892.             thingy2.css("display", "");
  893.         }));
  894.         ($("tr:contains('" + _("Actions") + "')", vilTable).length > 0 ? $("tr:contains('" + _("Actions") + "')", vilTable) : tribe).after(thingy).after(thingy2);
  895.     }
  896. }
  897.  
  898. /*Returns: WENTWELL (boolean) - used to decide whether to add "SAVED" onto the end or not...*/
  899. function doReport(doc, reportID){
  900.     /*We're on *a* report screen.*/
  901.     var espionage = $("#attack_spy_resources, #attack_spy_buildings_left", doc);
  902.     if (espionage.length >= 1) {
  903.         /* NEW REPORT STYUHL */
  904.         var repTable = espionage.parent().parent().parent();
  905.         var defender = $("#attack_info_def th:not(:contains('" + _("Defender") + "'))", repTable);
  906.         if (!getSetting("playerimport", true) && defender.length >= 1 && !defender.text().match("---")){
  907.             var linkd = $("<span>" + _("Saved") + "</span>");
  908.             repTable.parent().before(linkd);
  909.             linkd.text("Defender seems to be a player, and config says not to import - not saved");
  910.             console && console.log && console.log("Not saved a report! - Player as defender, config says no.");
  911.             return false;
  912.         }
  913.        
  914.         var resources = $("#attack_spy_resources td", repTable);
  915.         var resz = resources.text().trim().split("  ");
  916.         if (resources.get(0).innerHTML.indexOf("wood") === -1){
  917.             resz.unshift("0");
  918.         }
  919.         if (resources.get(0).innerHTML.indexOf("stone") === -1){
  920.             if (resz[1]) { resz.push(resz[1]); resz[1] = "0"; }
  921.             else resz.push("0");
  922.         }
  923.         if (resources.get(0).innerHTML.indexOf("iron") === -1){
  924.             resz.push("0");
  925.         }
  926.         var wood = parseInt(resz[0].replace(".", "")),
  927.             clay = parseInt(resz[1].replace(".", "")),
  928.             iron = parseInt(resz[2].replace(".", ""));
  929.         var battleTimeText = $($("tr td", repTable).get(1)).text().trim().replace(/:\d{3}/, "") + serverTimezones[window.location.host.split(/\W+/)[0].substring(0, 2)];
  930.         /* Format: MMM(M?) D(D), YYYY HH:mm:ss:mmm GMT+HHmm */
  931.         var timeThings = battleTimeText.match(/[\w-+]+/g);
  932.         var month = 0;
  933.         for (var i=0; i<months.length; i++){
  934.             if (timeThings[0].match(new RegExp(_(months[i]),"i"))) {
  935.                 month = i+1;
  936.             }
  937.         }
  938.         var date = parseInt(timeThings[1]);
  939.         var year = parseInt(timeThings[2]);
  940.         var hour = parseInt(timeThings[3]);
  941.         var minute = parseInt(timeThings[4]);
  942.         var second = parseInt(timeThings[5]);
  943.         var offsets = timeThings[6].replace("GMT", "");
  944.         var offsetz = [];
  945.         offsetz[0] = offsets.substring(0, 1);
  946.         offsetz[1] = offsets.substring(1, 3);
  947.         offsetz[2] = offsets.substring(3, 5);
  948.         var offset = ((offsetz[0] === "+") ? -1 : 1) * (parseInt(offsetz[1])*60 + parseInt(offsetz[2]));
  949.         minute += offset;
  950.        
  951.         var day = new Date();
  952.         day.setUTCFullYear(year);
  953.         day.setUTCMonth(month-1);
  954.         day.setUTCDate(date);
  955.         day.setUTCHours(hour);
  956.         day.setUTCMinutes(minute);
  957.         day.setUTCSeconds(second);
  958.        
  959.         var battleTime = day;
  960.         var buildings;
  961.         if ($("#attack_spy_building_data", repTable).length >= 1){
  962.             buildings = JSON.parse($("#attack_spy_building_data", repTable).val());
  963.             var woodCamp, clayCamp, ironCamp, warehouse;
  964.             buildings.forEach(function(element, index, array){
  965.                 if (element.id === "wood") woodCamp = parseInt(element.level);
  966.                 if (element.id === "stone") clayCamp = parseInt(element.level);
  967.                 if (element.id === "iron") ironCamp = parseInt(element.level);
  968.                 if (element.id === "storage") warehouse = parseInt(element.level);
  969.                 if (element.id === "wall") wall = parseInt(element.level);
  970.             });
  971.             woodCamp = (isNaN(woodCamp)) ? 0 : woodCamp;
  972.             clayCamp = (isNaN(clayCamp)) ? 0 : clayCamp;
  973.             ironCamp = (isNaN(ironCamp)) ? 0 : ironCamp;
  974.             warehouse = (isNaN(warehouse)) ? 0 : warehouse;
  975.             wall = (isNaN(wall)) ? 0 : wall;
  976.         } else {
  977.             var woodCamp = 5,
  978.                 clayCamp = 5,
  979.                 ironCamp = 5,
  980.                 warehouse = 10,
  981.                 wall = 0;
  982.         }
  983.         var hoursAgo = (new Date() - battleTime) / 60 / 60 / 1000;
  984.         var wood2 = wood + (resourceSp[woodCamp] * hoursAgo * getWorldSpeed()),
  985.             clay2 = clay + (resourceSp[clayCamp] * hoursAgo * getWorldSpeed()),
  986.             iron2 = iron + (resourceSp[ironCamp] * hoursAgo * getWorldSpeed());
  987.         wood2 = (wood2 > warehouseC[warehouse]) ? warehouseC[warehouse] : wood2;
  988.         clay2 = (clay2 > warehouseC[warehouse]) ? warehouseC[warehouse] : clay2;
  989.         iron2 = (iron2 > warehouseC[warehouse]) ? warehouseC[warehouse] : iron2;
  990.        
  991.         var vilCoords = $($("#attack_info_def span a", repTable).get(0)).text().split("(")[1].split(")")[0].split("|"),
  992.             localCoords = $($("#attack_info_att span a", repTable).get(0)).text().split("(")[1].split(")")[0].split("|"),
  993.             distance = Math.round(Math.sqrt(Math.pow(vilCoords[0] - localCoords[0], 2) + Math.pow(vilCoords[1] - localCoords[1], 2)) * 100) / 100,
  994.             hours = distance * (speed.lc / getUnitSpeed()) / 60;
  995.         var wood3 = wood2 + (resourceSp[woodCamp] * hours * getWorldSpeed()),
  996.             clay3 = clay2 + (resourceSp[clayCamp] * hours * getWorldSpeed()),
  997.             iron3 = iron2 + (resourceSp[ironCamp] * hours * getWorldSpeed());
  998.         wood3 = (wood3 > warehouseC[warehouse]) ? warehouseC[warehouse] : wood3;
  999.         clay3 = (clay3 > warehouseC[warehouse]) ? warehouseC[warehouse] : clay3;
  1000.         iron3 = (iron3 > warehouseC[warehouse]) ? warehouseC[warehouse] : iron3;
  1001.         var buildz = {};
  1002.         buildz["woodcamp"] = woodCamp;
  1003.         buildz["claycamp"] = clayCamp;
  1004.         buildz["ironcamp"] = ironCamp;
  1005.         buildz["warehouse"] = warehouse;
  1006.         buildz["wall"] = wall;
  1007.        
  1008.         if (buildings) {
  1009.             buildings.forEach(function(element, index, array){
  1010.                 if (element.id === "barracks") buildz.barracks = parseInt(element.level);
  1011.                 if (element.id === "place") buildz.rally = parseInt(element.level);
  1012.                 if (element.id === "stable") buildz.stable = parseInt(element.level);
  1013.                 if (element.id === "garage") buildz.workshop = parseInt(element.level);
  1014.                 if (element.id === "snob") buildz.academy = parseInt(element.level);
  1015.                 if (element.id === "smith") buildz.smithy = parseInt(element.level);
  1016.                 if (element.id === "statue") buildz.statue = parseInt(element.level);
  1017.                 if (element.id === "market") buildz.market = parseInt(element.level);
  1018.                 if (element.id === "main") buildz.hq = parseInt(element.level);
  1019.                 if (element.id === "farm") buildz.farm = parseInt(element.level);
  1020.             });
  1021.         }
  1022.        
  1023.         buildz.barracks = buildz.barracks || 0;
  1024.         buildz.rally = buildz.rally || 0;
  1025.         buildz.stable = buildz.stable || 0;
  1026.         buildz.workshop = buildz.workshop || 0;
  1027.         buildz.academy = buildz.academy || 0;
  1028.         buildz.smithy = buildz.smithy || 0;
  1029.         buildz.statue = buildz.statue || 0;
  1030.         buildz.market = buildz.market || 0;
  1031.         buildz.hq = buildz.hq || 0;
  1032.         buildz.farm = buildz.farm || 0;
  1033.        
  1034.         var linkd = $("<span>" + _("Saved") + "</span>");
  1035.         linkd.css("display", "none");
  1036.        
  1037.         repTable.parent().before(linkd);
  1038.         var wentWell = false;
  1039.         (function(){
  1040.             if (addReport(parseInt(reportID), localCoords, vilCoords, wood, clay, iron, battleTime, buildz)){
  1041.                 linkd.text(_("Saved"));
  1042.                 linkd.css("display", "block").css("color", "");
  1043.                 console && console.log && console.log("Saved a report! - " + localCoords[0] + "|" + localCoords[1] + " - " + vilCoords[0] + "|" + vilCoords[1] + " - " + parseInt(reportID));
  1044.                 wentWell = true;
  1045.             } else {
  1046.                 linkd.text("Oops! There was an error.");
  1047.                 linkd.css("display", "block").css("color", "#F00");
  1048.                 console && console.log && console.log("Error with a report! - " + localCoords[0] + "|" + localCoords[1] + " - " + vilCoords[0] + "|" + vilCoords[1] + " - " + parseInt(reportID));
  1049.             }
  1050.         })();
  1051.        
  1052.         var lcA1 = Math.floor((wood + clay + iron) / carry.lc + 0.25),
  1053.             lcA2 = Math.floor((wood2 + clay2 + iron2) / carry.lc + 0.25),
  1054.             lcA3 = Math.floor((wood3 + clay3 + iron3) / carry.lc + 0.25);
  1055.     } else if ($("#attack_spy", doc).length >= 1) {
  1056.         /*OLD STYLE *BLERGH* */
  1057.         var espionage = $("#attack_spy", doc);
  1058.         var repTable = espionage.parent().parent().parent();
  1059.         var defender = $("#attack_info_def th:not(:contains('" + _("Defender") + "'))", repTable);
  1060.         if (!getSetting("playerimport", true) && defender.length >= 1 && !defender.text().match("---")){
  1061.             var linkd = $("<span>" + _("Saved") + "</span>");
  1062.             repTable.parent().before(linkd);
  1063.             linkd.text("Defender seems to be a player, and config says not to import - not saved");
  1064.             console && console.log && console.log("Not saved a report! - Player as defender, config says no.");
  1065.             return false;
  1066.         }
  1067.        
  1068.         var resources = $($("tr td", espionage).get(0));
  1069.         var resz = resources.text().trim().split("  ");
  1070.         if (resources.get(0).innerHTML.indexOf("wood") === -1){
  1071.             resz.unshift("0");
  1072.         }
  1073.         if (resources.get(0).innerHTML.indexOf("stone") === -1){
  1074.             if (resz[1]) { resz.push(resz[1]); resz[1] = "0"; }
  1075.             else resz.push("0");
  1076.         }
  1077.         if (resources.get(0).innerHTML.indexOf("iron") === -1){
  1078.             resz.push("0");
  1079.         }
  1080.         var wood = parseInt(resz[0].replace(".", "")),
  1081.             clay = parseInt(resz[1].replace(".", "")),
  1082.             iron = parseInt(resz[2].replace(".", ""));
  1083.         var battleTimeText = $($("tr td", repTable).get(1)).text().trim().replace(/:\d{3}/, "") + serverTimezones[window.location.host.split(/\W+/)[0].substring(0, 2)];
  1084.         /* Format: MMM(M?) D(D), YYYY HH:mm:ss:mmm GMT+HHmm */
  1085.         var timeThings = battleTimeText.match(/[\w-+]+/g);
  1086.         var month = 0;
  1087.         for (var i=0; i<months.length; i++){
  1088.             if (timeThings[0].match(new RegExp(_(months[i]),"i"))) {
  1089.                 month = i+1;
  1090.             }
  1091.         }
  1092.         var date = parseInt(timeThings[1]);
  1093.         var year = parseInt(timeThings[2]);
  1094.         var hour = parseInt(timeThings[3]);
  1095.         var minute = parseInt(timeThings[4]);
  1096.         var second = parseInt(timeThings[5]);
  1097.         var offsets = timeThings[6].replace("GMT", "");
  1098.         var offsetz = [];
  1099.         offsetz[0] = offsets.substring(0, 1);
  1100.         offsetz[1] = offsets.substring(1, 3);
  1101.         offsetz[2] = offsets.substring(3, 5);
  1102.         var offset = ((offsetz[0] === "+") ? -1 : 1) * (parseInt(offsetz[1])*60 + parseInt(offsetz[2]));
  1103.         minute += offset;
  1104.        
  1105.         var day = new Date();
  1106.         day.setUTCFullYear(year);
  1107.         day.setUTCMonth(month-1);
  1108.         day.setUTCDate(date);
  1109.         day.setUTCHours(hour);
  1110.         day.setUTCMinutes(minute);
  1111.         day.setUTCSeconds(second);
  1112.        
  1113.         var battleTime = day;
  1114.         var buildings;
  1115.         if ($("tr", espionage).length >= 2){
  1116.             buildings = espionage.text();
  1117.             var woodCamp = parseInt(buildings.replace(new RegExp("[\\s\\S]*" + _("Timber camp") + " \\(" + _("Level") + " "), "").replace(/\)[\s\S]*/, "")),
  1118.                 clayCamp = parseInt(buildings.replace(new RegExp("[\\s\\S]*" + _("Clay pit") + " \\(" + _("Level") + " "), "").replace(/\)[\s\S]*/, "")),
  1119.                 ironCamp = parseInt(buildings.replace(new RegExp("[\\s\\S]*" + _("Iron mine") + " \\(" + _("Level") + " "), "").replace(/\)[\s\S]*/, "")),
  1120.                 warehouse = parseInt(buildings.replace(new RegExp("[\\s\\S]*" + _("Warehouse") + " \\(" + _("Level") + " "), "").replace(/\)[\s\S]*/, "")),
  1121.                 wall = parseInt(buildings.replace(new RegExp("[\\s\\S]*" + _("Wall") + " \\(" + _("Level") + " "), "").replace(/\)[\s\S]*/, ""));
  1122.             woodCamp = (isNaN(woodCamp)) ? 0 : woodCamp;
  1123.             clayCamp = (isNaN(clayCamp)) ? 0 : clayCamp;
  1124.             ironCamp = (isNaN(ironCamp)) ? 0 : ironCamp;
  1125.             warehouse = (isNaN(warehouse)) ? 0 : warehouse;
  1126.             wall = (isNaN(wall)) ? 0 : wall;
  1127.         } else {
  1128.             var woodCamp = 5,
  1129.                 clayCamp = 5,
  1130.                 ironCamp = 5,
  1131.                 warehouse = 10,
  1132.                 wall = 0;
  1133.         }
  1134.         var hoursAgo = (new Date() - battleTime) / 60 / 60 / 1000;
  1135.         var wood2 = wood + (resourceSp[woodCamp] * hoursAgo * getWorldSpeed()),
  1136.             clay2 = clay + (resourceSp[clayCamp] * hoursAgo * getWorldSpeed()),
  1137.             iron2 = iron + (resourceSp[ironCamp] * hoursAgo * getWorldSpeed());
  1138.         wood2 = (wood2 > warehouseC[warehouse]) ? warehouseC[warehouse] : wood2;
  1139.         clay2 = (clay2 > warehouseC[warehouse]) ? warehouseC[warehouse] : clay2;
  1140.         iron2 = (iron2 > warehouseC[warehouse]) ? warehouseC[warehouse] : iron2;
  1141.         /* vilCoords = $(".quickedit-label", repTable).text().split("(")[2].split(")")[0].split("|") */
  1142.         var vilCoords = $($("#attack_info_def span a", repTable).get(0)).text().split("(")[1].split(")")[0].split("|"),
  1143.             localCoords = $($("#attack_info_att span a", repTable).get(0)).text().split("(")[1].split(")")[0].split("|"), /* getLocalCoords() */
  1144.             distance = Math.round(Math.sqrt(Math.pow(vilCoords[0] - localCoords[0], 2) + Math.pow(vilCoords[1] - localCoords[1], 2)) * 100) / 100,
  1145.             hours = distance * (speed.lc / getUnitSpeed()) / 60;
  1146.         var wood3 = wood2 + (resourceSp[woodCamp] * hours * getWorldSpeed()),
  1147.             clay3 = clay2 + (resourceSp[clayCamp] * hours * getWorldSpeed()),
  1148.             iron3 = iron2 + (resourceSp[ironCamp] * hours * getWorldSpeed());
  1149.         wood3 = (wood3 > warehouseC[warehouse]) ? warehouseC[warehouse] : wood3;
  1150.         clay3 = (clay3 > warehouseC[warehouse]) ? warehouseC[warehouse] : clay3;
  1151.         iron3 = (iron3 > warehouseC[warehouse]) ? warehouseC[warehouse] : iron3;
  1152.         var buildz = {};
  1153.         buildz["woodcamp"] = woodCamp;
  1154.         buildz["claycamp"] = clayCamp;
  1155.         buildz["ironcamp"] = ironCamp;
  1156.         buildz["warehouse"] = warehouse;
  1157.         buildz["wall"] = wall;
  1158.         /*CHURCH*/
  1159.         buildz.barracks = buildings && parseInt(buildings.replace(new RegExp("[\\s\\S]*" + _("Barracks") + " \\(" + _("Level") + " "), "").replace(/\)[\s\S]*/, "")) || 0,
  1160.         buildz.rally = buildings && parseInt(buildings.replace(new RegExp("[\\s\\S]*" + _("Rally point") + " \\(" + _("Level") + " "), "").replace(/\)[\s\S]*/, "")) || 0,
  1161.         buildz.stable = buildings && parseInt(buildings.replace(new RegExp("[\\s\\S]*" + _("Stable") + " \\(" + _("Level") + " "), "").replace(/\)[\s\S]*/, "")) || 0,
  1162.         buildz.workshop = buildings && parseInt(buildings.replace(new RegExp("[\\s\\S]*" + _("Workshop") + " \\(" + _("Level") + " "), "").replace(/\)[\s\S]*/, "")) || 0,
  1163.         buildz.academy = buildings && parseInt(buildings.replace(new RegExp("[\\s\\S]*" + _("Academy") + " \\(" + _("Level") + " "), "").replace(/\)[\s\S]*/, "")) || 0,
  1164.         buildz.smithy = buildings && parseInt(buildings.replace(new RegExp("[\\s\\S]*" + _("Smithy") + " \\(" + _("Level") + " "), "").replace(/\)[\s\S]*/, "")) || 0,
  1165.         buildz.statue = buildings && parseInt(buildings.replace(new RegExp("[\\s\\S]*" + _("Statue") + " \\(" + _("Level") + " "), "").replace(/\)[\s\S]*/, "")) || 0,
  1166.         buildz.market = buildings && parseInt(buildings.replace(new RegExp("[\\s\\S]*" + _("Market") + " \\(" + _("Level") + " "), "").replace(/\)[\s\S]*/, "")) || 0,
  1167.         buildz.hq = buildings && parseInt(buildings.replace(new RegExp("[\\s\\S]*" + _("Headquarters") + " \\(" + _("Level") + " "), "").replace(/\)[\s\S]*/, "")) || 0,
  1168.         buildz.farm = buildings && parseInt(buildings.replace(new RegExp("[\\s\\S]*" + _("Farm") + " \\(" + _("Level") + " "), "").replace(/\)[\s\S]*/, "")) || 0;
  1169.         var linkd = $("<span>" + _("Saved") + "</span>");
  1170.         linkd.css("display", "none");
  1171.        
  1172.         repTable.parent().before(linkd);
  1173.         var wentWell = false;
  1174.         (function(){
  1175.             /*
  1176.             if ($("th[width=400] span.quickedit-label", repTable).get(0).innerText.split("(")[1].split(")")[0] !== getLocalName() && linkd.css("display") === "none") {
  1177.                 linkd.text("This report doesn't appear to come from this village - Are you sure? ");
  1178.                 linkd.css("display", "block").css("color", "#F00");
  1179.                 console && console.log && console.log("Report not from this village - " + vilCoords[0] + "|" + vilCoords[1] + " - " + parseInt(reportID));
  1180.             } else {
  1181.             */
  1182.             if (addReport(parseInt(reportID), localCoords, vilCoords, wood, clay, iron, battleTime, buildz)){
  1183.                 linkd.text("Saved");
  1184.                 linkd.css("display", "block").css("color", "");
  1185.                 console && console.log && console.log("Saved a report! - " + localCoords[0] + "|" + localCoords[1] + " - " + vilCoords[0] + "|" + vilCoords[1] + " - " + parseInt(reportID));
  1186.                 wentWell = true;
  1187.             } else {
  1188.                 linkd.text("Oops! There was an error.");
  1189.                 linkd.css("display", "block").css("color", "#F00");
  1190.                 console && console.log && console.log("Error with a report! - " + localCoords[0] + "|" + localCoords[1] + " - " + vilCoords[0] + "|" + vilCoords[1] + " - " + parseInt(reportID));
  1191.             }
  1192.             /* } */
  1193.         })();
  1194.        
  1195.         var lcA1 = Math.floor((wood + clay + iron) / carry.lc + 0.25),
  1196.             lcA2 = Math.floor((wood2 + clay2 + iron2) / carry.lc + 0.25),
  1197.             lcA3 = Math.floor((wood3 + clay3 + iron3) / carry.lc + 0.25);
  1198.     }
  1199.     return wentWell;
  1200. }
Add Comment
Please, Sign In to add comment