Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.24 KB | None | 0 0
  1. /*
  2. Author : Dale McKay
  3. Email : dalesmckay@gmail.com
  4. Notes : thanks to slowtarget for some initial ideas/functions
  5.  
  6. TODO :
  7. * Display foreign troop summary
  8. ____________________________________________________________
  9.  
  10. Copyright (C) 2010 Dale McKay, all rights reserved
  11. version 1.0, 9 April 2010
  12.  
  13. This software is provided 'as-is', without any express or implied warranty. In no event will the author be held liable for any damages arising from the use of this software.
  14.  
  15. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
  16. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  17. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  18. This notice may not be removed or altered from any source distribution.
  19. ____________________________________________________________
  20.  
  21. */
  22.  
  23. function fnExecuteScript() {
  24. try {
  25. var strVersion = "v7.6";
  26.  
  27. var unitDesc = {
  28. "spear": "Lanceiros",
  29. "sword": "Espadachins",
  30. "axe": "Bárbaros",
  31. "archer": "Arqueiros",
  32. "spy": "Exploradores",
  33. "light": "Cavalaria Leve",
  34. "marcher": "Arqueiros a Cavalo",
  35. "heavy": "Cavalaria Pesada",
  36. "ram": "Arietes",
  37. "catapult": "Catapultas",
  38. "knight": "Paladino",
  39. "snob": "Nobres",
  40. "militia": "Milícia",
  41. "offense": "Ofensiva",
  42. "defense": "Defensiva"
  43. };
  44.  
  45. function fnTranslate(id) {
  46. var translation = {
  47. "en": [
  48. "NT em aldeia de ataque",
  49. "NT em aldeia de defesa",
  50. "Outros Nobres",
  51. "Ataque Completo",
  52. "Ataque em 3/4",
  53. "Ataque em 1/2",
  54. "Ataque em 1/4",
  55. "Ataque Full com Catapulta",
  56. "Defesa Completa",
  57. "Defesa em 3/4",
  58. "Defesa em 1/2",
  59. "Defesa em 1/4",
  60. "Espionagem Completa",
  61. "Espionagem em 3/4",
  62. "Espionagem em 1/2",
  63. "Espionagem em 1/4",
  64. "Outros",
  65. "Sumário das Tropas",
  66. "Aldeias de Nobragem",
  67. "Aldeias de Ataque",
  68. "Aldeias de Defesa",
  69. "Aldeias de Espionagem",
  70. "Outros Tipos de Aldeias",
  71. "Tropas Ofensivas",
  72. "Tropas Defensivas",
  73. "Outras Unidades",
  74. "Total de Tropas",
  75. "Coordenadas"
  76. ]
  77. };
  78.  
  79. /* Default to English "en". */
  80. var lang = typeof(translation[win.game_data.market] == "undefined") ? "en" : win.game_data.market;
  81. if (typeof(translation[lang][id]) == "undefined") {
  82. return "";
  83. }
  84.  
  85. return translation[lang][id];
  86. }
  87.  
  88. function fnDebugLog(msg) {
  89. win.$("body").append("<span>" + msg + "</span><br/>");
  90. }
  91.  
  92. /* sendMethod = "GET" || "POST", params = json, type = xml,json,text */
  93. function fnAjaxRequest(url, sendMethod, params, type) {
  94. var error = null, payload = null;
  95.  
  96. win.$.ajax({
  97. "async": false,
  98. "url": url,
  99. "data": params,
  100. "dataType": type,
  101. "type": String(sendMethod || "GET").toUpperCase(),
  102. "error": function(req, status, err) {
  103. error = "ajax: " + status;
  104. },
  105. "success": function(data, status, req) {
  106. payload = data;
  107. }
  108. });
  109.  
  110. if (error) {
  111. throw(error);
  112. }
  113.  
  114. return payload;
  115. }
  116.  
  117. function fnCreateConfig(name) {
  118. return win.$(fnAjaxRequest("/interface.php", "GET", {"func": name}, "xml")).find("config");
  119. }
  120. function fnCreateWorldConfig() {
  121. return fnCreateConfig("get_config");
  122. }
  123. function fnCreateBuildingConfig() {
  124. return fnCreateConfig("get_building_info");
  125. }
  126. function fnCreateUnitConfig() {
  127. return fnCreateConfig("get_unit_info");
  128. }
  129.  
  130. function fnHasArchers() {
  131. return (parseInt(win.game_data.worldConfig.find("game archer").text() || "0", 10) > 0);
  132. }
  133. function fnHasChurch() {
  134. return (parseInt(win.game_data.worldConfig.find("game church").text() || "0", 10) > 0);
  135. }
  136. function fnHasNotebook() {
  137. return (win.$('[src*="note.png"],[class*="note-icon"]').length > 0);
  138. }
  139. function fnHasPaladin() {
  140. return (parseInt(win.game_data.worldConfig.find("game knight").text() || "0", 10) > 0);
  141. }
  142. function fnHasMilitia() {
  143. return (win.game_data.unitConfig.find("militia").length > 0);
  144. }
  145.  
  146. function fnGetTroopCount() {
  147. /* returns an array of: {"x":"xxx","y":"yyy","coords":"xxx|yyy","troops":[0,0,0,0,0,0,0,0,0,0,0,0,0]} */
  148.  
  149. /* Number of Columns - VillageColumn - ActionColumn */
  150. var gameVersion = parseFloat(win.game_data.version.match(/[\d|\.]+/g)[1]);
  151. var colCount = win.$('#units_table ' + ((gameVersion >= 7.1) ? 'thead' : 'tbody:eq(0)') + ' th').length - 2;
  152. var villageTroopInfo = [];
  153.  
  154. win.$('#units_table tbody' + ((gameVersion < 7.1) ? ':gt(0)' : '')).each(function(row, eleRow) {
  155. /* Reset for next Village */
  156. var villageData = {"troops": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]};
  157.  
  158. /* Village */
  159. coords = win.$(eleRow).find("td:eq(0)").text().match(/\d+\|\d+/g);
  160. coords = (coords ? coords[coords.length - 1].match(/(\d+)\|(\d+)/) : null);
  161. villageData.x = parseInt(coords[1], 10);
  162. villageData.y = parseInt(coords[2], 10);
  163. villageData.coords = coords[0];
  164.  
  165. /* Skip the Village Cell */
  166. win.$(eleRow).find("td:gt(0):not(:has(>a))").each(function(cell, eleCell) {
  167. /* Skip the RowType Cell */
  168. if (cell % colCount) {
  169. /* Ignore In the village (your own + foreign) */
  170. if (Math.floor(cell / colCount) != 1) {
  171. villageData.troops[cell % colCount - 1] += parseInt(win.$(eleCell).text() || "0", 10);
  172. }
  173. }
  174. });
  175.  
  176. /* Cache the Data */
  177. villageTroopInfo.push(villageData);
  178. });
  179.  
  180. return villageTroopInfo;
  181. }
  182.  
  183. function fnLogVersionInfo() {
  184. /*
  185. fnDebugLog("=========================");
  186. fnDebugLog("dalesmckay's Troop Summary: " + strVersion);
  187. */
  188. fnDebugLog("=========================");
  189. fnDebugLog("Premium: " + (win.game_data.isPremium ? "yes" : "no"));
  190. fnDebugLog("Church : " + (fnHasChurch() ? "yes" : "no"));
  191. fnDebugLog("Statue : " + (fnHasPaladin() ? "yes" : "no"));
  192. fnDebugLog("Archer : " + (fnHasArchers() ? "yes" : "no"));
  193. fnDebugLog("Militia: " + (fnHasMilitia() ? "yes" : "no"));
  194. fnDebugLog("Sitter : " + (win.location.href.match(/t\=\d+/i) ? "yes" : "no"));
  195. fnDebugLog("=========================");
  196. fnDebugLog("Version: " + win.game_data.version);
  197. fnDebugLog("World : " + win.game_data.world);
  198. fnDebugLog("Screen : " + win.game_data.screen);
  199. fnDebugLog("Mode : " + win.game_data.mode);
  200. fnDebugLog("URL : " + win.location.href);
  201. fnDebugLog("Browser: " + navigator.userAgent);
  202. fnDebugLog("=========================");
  203.  
  204. return true;
  205. }
  206.  
  207. function fnCriteriaToStr(criteria) {
  208. var valueStr = "";
  209.  
  210. if (criteria && (criteria.length > 0)) {
  211. for (var ii = 0; ii < criteria.length; ii++) {
  212. if (typeof(criteria[ii].minpop) != "undefined") {
  213. valueStr += (valueStr ? " and " : "") + "(" + unitDesc[criteria[ii].unit] + "[pop] >= " + criteria[ii].minpop + ")";
  214. }
  215. if (typeof(criteria[ii].maxpop) != "undefined") {
  216. valueStr += (valueStr ? " and " : "") + "(" + unitDesc[criteria[ii].unit] + "[pop] < " + criteria[ii].maxpop + ")";
  217. }
  218. }
  219. }
  220.  
  221. return valueStr;
  222. }
  223.  
  224. function fnCalculateTroopCount() {
  225. var maxGroups = 17;
  226. var outputSummary = {
  227. "Full Train Nuke": {
  228. "group": "Nobles",
  229. "criteria": [{"unit": "snob", "minpop": 400}, {"unit": "offense", "minpop": 19600}],
  230. "descID": 0
  231. },
  232. "Full Defense Train": {
  233. "group": "Nobles",
  234. "criteria": [{"unit": "snob", "minpop": 400}, {"unit": "defense", "minpop": 19600}],
  235. "descID": 1
  236. },
  237. "Other Nobles": {
  238. "group": "Nobles",
  239. "criteria": [{"unit": "snob", "minpop": 100}, {"unit": "defense", "maxpop": 19600}, {"unit": "offense", "maxpop": 19600}],
  240. "descID": 2
  241. },
  242. "Full Nuke": {
  243. "group": "Offensive",
  244. "criteria": [{"unit": "snob", "maxpop": 100}, {"unit": "offense", "minpop": 20000}],
  245. "descID": 3
  246. },
  247. "Semi Nuke": {
  248. "group": "Offensive",
  249. "criteria": [{"unit": "snob", "maxpop": 100}, {"unit": "offense", "minpop": 15000, "maxpop": 20000}],
  250. "descID": 4
  251. },
  252. "Half Nuke": {
  253. "group": "Offensive",
  254. "criteria": [{"unit": "snob", "maxpop": 100}, {"unit": "offense", "minpop": 10000, "maxpop": 15000}],
  255. "descID": 5
  256. },
  257. "Quarter Nuke": {
  258. "group": "Offensive",
  259. "criteria": [{"unit": "snob", "maxpop": 100}, {"unit": "offense", "minpop": 5000, "maxpop": 10000}],
  260. "descID": 6
  261. },
  262. "Cat Nuke": {
  263. "group": "Offensive",
  264. "criteria": [{"unit": "snob", "maxpop": 100}, {"unit": "catapult", "minpop": 800}, {"unit": "offense", "minpop": 20000}],
  265. "descID": 7
  266. },
  267. "Full Defense": {
  268. "group": "Defensive",
  269. "criteria": [{"unit": "snob", "maxpop": 100}, {"unit": "defense", "minpop": 20000}],
  270. "descID": 8
  271. },
  272. "Semi Defense": {
  273. "group": "Defensive",
  274. "criteria": [{"unit": "snob", "maxpop": 100}, {"unit": "defense", "minpop": 15000, "maxpop": 20000}],
  275. "descID": 9
  276. },
  277. "Half Defense": {
  278. "group": "Defensive",
  279. "criteria": [{"unit": "snob", "maxpop": 100}, {"unit": "defense", "minpop": 10000, "maxpop": 15000}],
  280. "descID": 10
  281. },
  282. "Quarter Defense": {
  283. "group": "Defensive",
  284. "criteria": [{"unit": "snob", "maxpop": 100}, {"unit": "defense", "minpop": 5000, "maxpop": 10000}],
  285. "descID": 11
  286. },
  287. "Full Scout": {
  288. "group": "Scouts",
  289. "criteria": [{"unit": "snob", "maxpop": 100}, {"unit": "spy", "minpop": 20000}],
  290. "descID": 12
  291. },
  292. "Semi Scout": {
  293. "group": "Scouts",
  294. "criteria": [{"unit": "snob", "maxpop": 100}, {"unit": "spy", "minpop": 15000, "maxpop": 20000}],
  295. "descID": 13
  296. },
  297. "Half Scout": {
  298. "group": "Scouts",
  299. "criteria": [{"unit": "snob", "maxpop": 100}, {"unit": "spy", "minpop": 10000, "maxpop": 15000}],
  300. "descID": 14
  301. },
  302. "Quarter Scout": {
  303. "group": "Scouts",
  304. "criteria": [{"unit": "snob", "maxpop": 100}, {"unit": "spy", "minpop": 5000, "maxpop": 10000}],
  305. "descID": 15
  306. },
  307. "Other": {
  308. "group": "Other",
  309. "criteria": [{"unit": "snob", "maxpop": 100}, {"unit": "spy", "maxpop": 5000}, {"unit": "defense", "maxpop": 5000}, {"unit": "offense", "maxpop": 5000}],
  310. "descID": 16
  311. }
  312. };
  313.  
  314. var ii, jj, village, total, index, count, unit, item, key, criteria, condition, isValid;
  315. var defense = ["spear", "sword", "heavy", "catapult"];
  316. var offense = ["axe", "light", "ram", "catapult"];
  317.  
  318. if (fnHasMilitia()) {
  319. defense.push("militia");
  320. }
  321.  
  322. if (fnHasArchers()) {
  323. defense.push("archer");
  324. offense.push("marcher");
  325. }
  326. /*
  327. if(fnHasPaladin()){
  328. offense.push("knight");
  329. }
  330. */
  331.  
  332. /* Initialize */
  333. var summary = {
  334. unitTotal: {"tally": 0, "population": 0},
  335. defense: {"tally": 0, "count": 0, "population": 0, "coords": []},
  336. offense: {"tally": 0, "count": 0, "population": 0, "coords": []}
  337. };
  338.  
  339. win.$(win.game_data.unitConfig).children().each(function(i, e) {
  340. summary[e.nodeName] = {"tally": 0, "count": 0, "population": 0, "coords": []};
  341. });
  342.  
  343. for (item in outputSummary) {
  344. if (outputSummary.hasOwnProperty(item)) {
  345. summary[item] = {"tally": 0, "count": 0, "population": 0, "coords": []};
  346. }
  347. }
  348.  
  349. var villageTroops = fnGetTroopCount();
  350. for (ii = 0; ii < villageTroops.length; ii++) {
  351. village = villageTroops[ii];
  352. total = {
  353. defense: {"tally": 0, "count": 0, "population": 0, "coords": []},
  354. offense: {"tally": 0, "count": 0, "population": 0, "coords": []}
  355. };
  356.  
  357. win.$(win.game_data.unitConfig).children().each(function(i, e) {
  358. total[e.nodeName] = {"tally": 0, "count": 0, "population": 0, "coords": []};
  359. });
  360.  
  361. /* Calculate total count & population for each unit type */
  362. index = 0;
  363. win.$(win.game_data.unitConfig).children().each(function(i, e) {
  364. var unit = e.nodeName;
  365. total[unit].count += village.troops[index];
  366. total[unit].population += village.troops[index] * parseInt(win.$(e).find("pop").text(), 10);
  367.  
  368. /* Defense */
  369. if (new RegExp('^(' + defense.join('|') + ')$').test(unit)) {
  370. total.defense.count += total[unit].count;
  371. total.defense.population += total[unit].population;
  372. }
  373.  
  374. /* Offense */
  375. if (new RegExp('^(' + offense.join('|') + ')$').test(unit)) {
  376. total.offense.count += total[unit].count;
  377. total.offense.population += total[unit].population;
  378. }
  379.  
  380. /* Units */
  381. summary[unit].count += total[unit].count;
  382. summary[unit].population += total[unit].population;
  383.  
  384. /* All Units */
  385. summary.unitTotal.tally += total[unit].count;
  386. summary.unitTotal.population += total[unit].population;
  387.  
  388. index++;
  389. });
  390.  
  391. summary.defense.count += total.defense.count;
  392. summary.defense.population += total.defense.population;
  393.  
  394. summary.offense.count += total.offense.count;
  395. summary.offense.population += total.offense.population;
  396.  
  397. /* Calculate other summaries */
  398. for (item in outputSummary) {
  399. if (outputSummary.hasOwnProperty(item)) {
  400. isValid = true;
  401.  
  402. for (jj = 0; jj < outputSummary[item].criteria.length; jj++) {
  403. criteria = outputSummary[item].criteria[jj];
  404.  
  405. if (!((typeof(criteria.minpop) == "undefined") || !criteria.minpop || (total[criteria.unit].population >= criteria.minpop))) {
  406. isValid = false;
  407. }
  408.  
  409. if (!((typeof(criteria.maxpop) == "undefined") || !criteria.maxpop || (total[criteria.unit].population < criteria.maxpop))) {
  410. isValid = false;
  411. }
  412. }
  413.  
  414. if (isValid) {
  415. summary[item].coords.push(village.coords);
  416. summary[item].tally++;
  417. }
  418. }
  419. }
  420. }
  421.  
  422. var groupSummary = {};
  423. for (item in outputSummary) {
  424. if (outputSummary.hasOwnProperty(item)) {
  425. if (typeof(groupSummary[outputSummary[item].group]) == "undefined") {
  426. groupSummary[outputSummary[item].group] = [];
  427. }
  428.  
  429. groupSummary[outputSummary[item].group].push(item);
  430. }
  431. }
  432.  
  433. var curGroup = maxGroups;
  434.  
  435. var docSource = "";
  436. docSource += "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n";
  437. docSource += "<html>\n";
  438. docSource += "\t<head>\n";
  439. docSource += "\t\t<title>Sumário das Tropas</title>\n";
  440. docSource += "\t\t<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\"/>\n";
  441.  
  442. /*
  443. docSource += "\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"http://" + win.location.hostname + "/style.php?type=game&amp;stamm_new_menu&amp;stamm&amp;overview&amp;1273236925\"/>\n";
  444. */
  445. docSource += "\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"http://" + win.location.hostname + "/merged/game.css\"/>\n";
  446.  
  447. docSource += "\t\t<script type=\"text/javascript\">\n";
  448. docSource += "\t\t\t<!--\n";
  449. docSource += "\t\t\tfunction fnShowCoords(id,description){\n";
  450. docSource += "\t\t\t\tvar coords={};\n";
  451. for (item in outputSummary) {
  452. if (outputSummary.hasOwnProperty(item)) {
  453. if (summary[item].coords.length) {
  454. docSource += "\t\t\t\tcoords[\"" + item + "\"] = \"" + summary[item].coords.join(" ") + "\";\n";
  455. }
  456. }
  457. }
  458. docSource += "\t\t\t\tdocument.getElementById(\"coords_group\").innerHTML = description;\n";
  459. docSource += "\n";
  460. docSource += "\t\t\t\tvar eleCoords = document.getElementById(\"coords_container\");\n";
  461. docSource += "\t\t\t\teleCoords.value = coords[id]?coords[id]:\"\";\n";
  462. docSource += "\t\t\t\teleCoords.focus();\n";
  463. docSource += "\t\t\t\teleCoords.select();\n";
  464. docSource += "\t\t\t}\n";
  465. docSource += "\t\t\t-->\n";
  466. docSource += "\t\t</script>\n";
  467. docSource += "\t</head>\n";
  468. docSource += "\n";
  469. docSource += "\t<body>\n";
  470. docSource += "\t\t<table align=\"center\"><tr><td>\n";
  471. docSource += "\t\t\t<table class=\"content-border\"><tr><td>\n";
  472. docSource += "\t\t\t\t<table class=\"main\" width=\"100%\" align=\"center\">\n";
  473. docSource += "\t\t\t\t\t<tr>\n";
  474. docSource += "\t\t\t\t\t\t<td id=\"content_value\">\n";
  475. docSource += "\t\t\t\t\t\t\t<h2>" + fnTranslate(curGroup++) + "<sup><span style=\"font-size:small;\">" + strVersion + "</span></sup></h2>\n";
  476. docSource += "\t\t\t\t\t\t\t<hr>\n";
  477.  
  478. docSource += "\t\t\t\t\t\t\t<table>\n";
  479. docSource += "\t\t\t\t\t\t\t\t<tr><td width=\"450\" valign=\"top\"><table class=\"vis\" width=\"100%\">\n";
  480. for (item in groupSummary) {
  481. if (groupSummary.hasOwnProperty(item)) {
  482. count = 0;
  483. docSource += "<tr><th colspan=\"2\">" + fnTranslate(curGroup++) + "</th></tr>\n";
  484. for (jj = 0; jj < groupSummary[item].length; jj++) {
  485. docSource += "\t\t\t\t\t\t\t\t<tr class=\"" + ((count++ % 2) ? "row_b" : "row_a") + "\">\n";
  486. docSource += "\t\t\t\t\t\t\t\t\t<td width=\"240\" style=\"white-space:nowrap;\"><a href=\"#\" onclick=\"fnShowCoords('" + groupSummary[item][jj] + "','" + fnTranslate(outputSummary[groupSummary[item][jj]].descID) + "');\" title=\"" + fnCriteriaToStr(outputSummary[groupSummary[item][jj]].criteria) + "\">&raquo;&nbsp; " + fnTranslate(outputSummary[groupSummary[item][jj]].descID) + "</a></td>\n";
  487. docSource += "\t\t\t\t\t\t\t\t\t<td width=\"240\"" + ((summary[groupSummary[item][jj]].tally > 0) ? "" : " class=\"hidden\"") + " style=\"text-align:right;\"><span>" + summary[groupSummary[item][jj]].tally + "</span></td>\n";
  488. docSource += "\t\t\t\t\t\t\t\t</tr>\n";
  489. }
  490. }
  491. }
  492. docSource += "\t\t\t\t\t\t\t</table>\n";
  493. docSource += "\t\t\t\t\t\t\t<td valign=\"top\">\n";
  494.  
  495. /* Offensive Units */
  496. docSource += "\t\t\t\t\t\t\t\t<table class=\"vis\" width=\"100%\">\n";
  497. docSource += "\t\t\t\t\t\t\t\t\t<tr><th colspan=\"2\" style=\"white-space:nowrap;\">" + fnTranslate(curGroup++) + "</th></tr>\n";
  498. count = 0;
  499. for (key in offense) {
  500. if (offense.hasOwnProperty(key)) {
  501. docSource += "\t\t\t\t\t\t\t\t\t<tr class=\"" + ((count++ % 2) ? "row_b" : "row_a") + "\"><td><img src=\"http://" + win.location.hostname + "/graphic/unit/unit_" + offense[key] + ".png?1\" alt=\"\"/></td><td style=\"white-space:nowrap;\"><span> " + summary[offense[key]].count + " " + unitDesc[offense[key]] + "</span></td></tr>\n";
  502. }
  503. }
  504. docSource += "\t\t\t\t\t\t\t\t</table>\n";
  505.  
  506. /* Defensive Units */
  507. docSource += "\t\t\t\t\t\t\t\t<table class=\"vis\" width=\"100%\">\n";
  508. docSource += "\t\t\t\t\t\t\t\t\t<tr><th colspan=\"2\" style=\"white-space:nowrap;\">" + fnTranslate(curGroup++) + "</th></tr>\n";
  509. count = 0;
  510. for (key in defense) {
  511. if (defense.hasOwnProperty(key)) {
  512. docSource += "\t\t\t\t\t\t\t\t\t<tr class=\"" + ((count++ % 2) ? "row_b" : "row_a") + "\"><td><img src=\"http://" + win.location.hostname + "/graphic/unit/unit_" + defense[key] + ".png?1\" alt=\"\"/></td><td style=\"white-space:nowrap;\"><span> " + summary[defense[key]].count + " " + unitDesc[defense[key]] + "</span></td></tr>\n";
  513. }
  514. }
  515. docSource += "\t\t\t\t\t\t\t\t</table>\n";
  516.  
  517. /* Other Units */
  518. docSource += "\t\t\t\t\t\t\t\t<table class=\"vis\" width=\"100%\">\n";
  519. docSource += "\t\t\t\t\t\t\t\t\t<tr><th colspan=\"2\" style=\"white-space:nowrap;\">" + fnTranslate(curGroup++) + "</th></tr>\n";
  520. count = 0;
  521. win.$(win.game_data.unitConfig).children().each(function(i, e) {
  522. var unit = e.nodeName;
  523. if (!new RegExp('^(' + defense.join('|') + '|' + offense.join('|') + ')$').test(unit)) {
  524. docSource += "\t\t\t\t\t\t\t\t\t<tr class=\"" + ((count++ % 2) ? "row_b" : "row_a") + "\"><td><img src=\"http://" + win.location.hostname + "/graphic/unit/unit_" + unit + ".png?1\" alt=\"\"/></td><td style=\"white-space:nowrap;\"><span> " + summary[unit].count + " " + unitDesc[unit] + "</span></td></tr>\n";
  525. }
  526. });
  527. docSource += "\t\t\t\t\t\t\t\t</table>\n";
  528.  
  529. /* Total Units */
  530. docSource += "\t\t\t\t\t\t\t\t<table class=\"vis\" width=\"100%\">\n";
  531. docSource += "\t\t\t\t\t\t\t\t\t<tr><th colspan=\"2\" style=\"white-space:nowrap;\">" + fnTranslate(curGroup++) + "</th></tr>\n";
  532. docSource += "\t\t\t\t\t\t\t\t\t<tr class=\"" + "row_a" + "\"><td><span>Contigente:</span></td><td style=\"white-space:nowrap;\"><span> " + summary.unitTotal.tally + "</span></td></tr>\n";
  533. docSource += "\t\t\t\t\t\t\t\t\t<tr class=\"" + "row_b" + "\"><td><span>População Total:</span></td><td style=\"white-space:nowrap;\"><span> " + summary.unitTotal.population + "</span></td></tr>\n";
  534. docSource += "\t\t\t\t\t\t\t\t</table>\n";
  535.  
  536. docSource += "\t\t\t\t\t\t\t</td>\n";
  537. docSource += "\t\t\t\t\t\t</td>\n";
  538. docSource += "\t\t\t\t\t</tr>\n";
  539. docSource += "\t\t\t\t</table>\n";
  540. docSource += "\t\t\t\t<hr>\n";
  541. docSource += "\t\t\t\t<table id=\"coordinate_table\" class=\"vis\" style=\"width:100%;\">\n";
  542. docSource += "\t\t\t\t\t<tr><th>" + fnTranslate(curGroup++) + ": <span id=\"coords_group\" style=\"font-weight:100;\"></span>\n";
  543. docSource += "\t\t\t\t\t<tr><td style=\"padding:1em;\"><textarea id=\"coords_container\" style=\"width:100%;\"></textarea></td></tr>\n";
  544. docSource += "\t\t\t\t</table>\n";
  545. docSource += "\t\t\t</table>\n";
  546. docSource += "\t\t</table>\n";
  547. docSource += "\t</body>\n";
  548. docSource += "</html>\n";
  549.  
  550. var popup = win.open('about:blank', 'dalesmckay_tw_troopsummary', 'width=460,height=730,scrollbars=yes');
  551. popup.document.open('text/html', 'replace');
  552. popup.document.write(docSource);
  553. popup.document.close();
  554. }
  555.  
  556.  
  557.  
  558. var win = (window.frames.length > 0) ? window.main : window;
  559.  
  560. /* HACK: fix null mode */
  561. if (!win.game_data.mode) {
  562. var vmode = win.$("#overview_menu td[class=selected] a").attr("href").match(/mode\=(\w*)/i);
  563. if (vmode) {
  564. win.game_data.mode = vmode[1];
  565. }
  566. }
  567.  
  568. win.game_data.isPremium = (win.$("#quickbar_outer").length > 0);
  569.  
  570. if (typeof(win.game_data.worldConfig) == "undefined") {
  571. win.game_data.worldConfig = fnCreateWorldConfig();
  572. }
  573.  
  574. if (typeof(win.game_data.unitConfig) == "undefined") {
  575. win.game_data.unitConfig = fnCreateUnitConfig();
  576. }
  577.  
  578. /* Todo: Handle different scripts by name */
  579. if (typeof(win.game_data.versionDumped) == "undefined") {
  580. win.game_data.versionDumped = fnLogVersionInfo();
  581. }
  582.  
  583. if (win.game_data.mode != "units") {
  584. throw("Execute o script em VISUALIZAÇÕES »» TROPAS »» TODOS\n[ Da opção: Todos | Próprias | Na Aldeia | Fora | Em trânsito | Defesa | Apoios ]");
  585. }
  586.  
  587. fnCalculateTroopCount();
  588.  
  589. void(0);
  590. }
  591. catch (objError) {
  592. var errMsg = String(objError.message || objError || "");
  593. if (errMsg) {
  594. fnDebugLog("Erro: " + errMsg);
  595. alert("Erro: " + errMsg);
  596. }
  597. }
  598. }
  599.  
  600. fnExecuteScript();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement