C&C: Tiberium Alliances Map

Shows you the region map

  1. // ==UserScript==
  2. // @name C&C: Tiberium Alliances Map
  3. // @description Shows you the region map
  4. // @author Eistee
  5. // @version 15.11.28
  6. // @namespace http*://*.alliances.commandandconquer.com/*
  7. // @include http*://*.alliances.commandandconquer.com/*
  8. // @icon http://s3.amazonaws.com/uso_ss/icon/176516/large.png
  9. // @grant GM_getValue
  10. // @grant GM_log
  11. // @grant GM_openInTab
  12. // @grant GM_registerMenuCommand
  13. // @grant GM_setValue
  14. // @grant GM_xmlhttpRequest
  15. // ==/UserScript==
  16. /*
  17. Bugfix for DR01 Script: C&C: Tiberium Alliances Map
  18. Version: 1.6.9
  19. http://userscripts.org/scripts/show/152801
  20. __________________________________________________
  21. based on Tiberium Alliances Map (Nolana Kane) v1.8
  22. https://userscripts.org/scripts/show/135955
  23. contributors:
  24. KSX https://userscripts.org/scripts/show/149093
  25. 777lexa777 https://userscripts.org/scripts/show/149350
  26. */
  27. (function () {
  28. var TAMap_mainFunction = function () {
  29. function createMapTweak() {
  30. var TAMap = {};
  31. qx.Class.define("TAMap", {
  32. type : "singleton",
  33. extend : qx.core.Object,
  34. members : {
  35. version : "13.08.25",
  36. alliances : null,
  37. alliancesAreLoaded : false,
  38. buttonMap : null,
  39. blurInterval : null,
  40. drawingNow : false,
  41. initZoom : null,
  42. isInitialized : false,
  43. mapBox : null,
  44. mapCanvas : null,
  45. canvasElement : null,
  46. canvasWidth : null,
  47. canvasHeight : null,
  48. mapMouseCanvas : null,
  49. mapMouseWidget : null,
  50. scroll : null,
  51. scrollWidget : null,
  52. settingsWnd : null,
  53. mapUpdateTimer : null,
  54. relations : {
  55. enemies : null,
  56. enemiesById : null,
  57. enemyCoords : [],
  58. allies : null,
  59. nap : null
  60. },
  61. swObj : {
  62. isLoaded : false,
  63. refreshIcon : null,
  64. allianceSelect : null,
  65. allianceListItem : {},
  66. poiSelect : null,
  67. obfSectorName : null,
  68. obfAllianceList : null,
  69. obfAllianceId : null,
  70. obfAllianceName : null,
  71. settingFields : {},
  72. labels : {},
  73. chkBoxFields : {},
  74. coordButtons : {}
  75. },
  76. line : {
  77. 1 : {
  78. x : null,
  79. y : null
  80. },
  81. 2 : {
  82. x : null,
  83. y : null
  84. }
  85. },
  86. visOptions : null,
  87. visOpt_DEFAULTS : {
  88. selectedAllianceId : -1,
  89. selectedAllianceName : "<< None >>",
  90. poi : -2,
  91. vpWidth : null,
  92. vpHeight : null,
  93. showEnemies : true,
  94. showEnemyRange : true,
  95. mapBoxBounds : {
  96. height : 500,
  97. top : 33,
  98. left : 129,
  99. width : 500
  100. },
  101. settingsWndBounds : {
  102. height : 646,
  103. top : 48,
  104. left : 615,
  105. width : 524
  106. },
  107. chk : {
  108. showAlliancePois : false,
  109. showOwnCities : true,
  110. showSectionFrame : true,
  111. showBorderLine1 : false,
  112. showBorderLine2 : false,
  113. fadeMap : true
  114. },
  115. settingsPanel : {
  116. playerColor : "#7F0", // type = 1
  117. baseColor : "#550", // type = 2
  118. campColor : "midnightblue", // type = 3, CampType=2
  119. outpostColor : "royalblue", // type = 3, CampType=3
  120. poiColor : "orange", // type = 4, POIType != 0
  121. tunnelColor : "forestgreen", // type = 4, POIType = 0
  122. enemyBaseColor : "red",
  123. allianceTerrainColor : "rgba(255,255,255,0.5)",
  124. ownBaseColor : "rgba(0,255,0,0.5)",
  125. highlightColor : "rgba(200,255,200,1)",
  126. line1start : "800:796",
  127. line1end : "1387:921",
  128. line1color : "rgba(0,255,0,0.3)",
  129. line2start : "800:796",
  130. line2end : "1410:830",
  131. line2color : "rgba(255,255,0,0.3)",
  132. zoomFactor : 3
  133. }
  134. },
  135.  
  136. initialize : function () {
  137. console.log("\nTAMap v" + this.version + ": Loaded");
  138. this.init_vars();
  139. this.init_menuButton();
  140. this.init_mapBox();
  141. this.init_scroll();
  142. this.init_settingsWnd();
  143. this.init_settingsButton();
  144. this.init_mapBox_listeners();
  145. this.isInitialized = true;
  146. },
  147.  
  148. init_vars : function () {
  149. // cloning
  150. var vTemp = JSON.parse(JSON.stringify(this.visOpt_DEFAULTS));
  151. if (localStorage) {
  152. var sto = localStorage.getItem("TAMapStorage");
  153. if (sto != null) {
  154. // check visOptions integrity against DEFAULTS
  155. this.visOptions = JSON.parse(sto);
  156. for (var i in vTemp) {
  157. if (typeof this.visOptions[i] == "object") {
  158. for (var j in vTemp[i]) {
  159. if (typeof this.visOptions[i][j] == "undefined") {
  160. console.log("\nSolving inconsistency with visOptions." + i + "." + j + "\n");
  161. this.visOptions[i][j] = vTemp[i][j];
  162. }
  163. }
  164. } else if (typeof this.visOptions[i] == "undefined") {
  165. console.log("Solving inconsistency with visOptions." + i);
  166. this.visOptions[i] = vTemp[i];
  167. }
  168. }
  169. } else {
  170. this.visOptions = vTemp;
  171. }
  172. }
  173. this.initZoom = this.visOptions.settingsPanel.zoomFactor;
  174. this.worldHeight = ClientLib.Data.MainData.GetInstance().get_World().get_WorldHeight();
  175. this.worldWidth = ClientLib.Data.MainData.GetInstance().get_World().get_WorldWidth();
  176. this.canvasHeight = this.worldHeight * this.initZoom;
  177. this.canvasWidth = this.worldWidth * this.initZoom;
  178. },
  179.  
  180. init_menuButton : function () {
  181. this.buttonMap = new qx.ui.menu.Button("Map");
  182. this.buttonMap.addListener("click", this.toggleMap, this);
  183. var submenu = new qx.ui.menu.Menu();
  184. submenu.add(this.buttonMap);
  185. var bntScript = qx.core.Init.getApplication().getUIItem(ClientLib.Data.Missions.PATH.BAR_MENU).getScriptsButton();
  186. bntScript.Add("Map", null, submenu);
  187. },
  188.  
  189. init_mapBox : function () {
  190. // The Map window
  191. this.mapBox = new qx.ui.window.Window("Mini-Map [v" + this.version + "]");
  192. this.mapBox.setPadding(1);
  193. this.mapBox.setLayout(new qx.ui.layout.Grow());
  194. // this.mapBox.setLayout(new qx.ui.layout.VBox());
  195. this.mapBox.setShowMaximize(false);
  196. this.mapBox.setShowMinimize(false);
  197. this.mapBox.moveTo(this.visOptions.mapBoxBounds.left, this.visOptions.mapBoxBounds.top);
  198. this.mapBox.setHeight(this.visOptions.mapBoxBounds.height);
  199. this.mapBox.setWidth(this.visOptions.mapBoxBounds.width);
  200. this.mapBox.setMinWidth(10);
  201. this.mapBox.setMinHeight(10);
  202. this.mapBox.setBackgroundColor("black");
  203. },
  204.  
  205. init_scroll : function () {
  206. var cw = this.canvasWidth;
  207. var ch = this.canvasHeight;
  208. this.scroll = new qx.ui.container.Scroll();
  209.  
  210. //this.scroll.removeListener("mousewheel", this.scroll._onMouseWheel, this.scroll);
  211. this.scroll.addListener("mousewheel", function (evt) {
  212. console.log(evt.getWheelDelta());
  213. }, this);
  214.  
  215. this.mapBox.add(this.scroll);
  216.  
  217. this.scrollWidget = new qx.ui.core.Widget();
  218. this.scrollWidget.setMinHeight(ch);
  219. this.scrollWidget.setMinWidth(cw);
  220. this.scrollWidget.setHeight(ch);
  221. this.scrollWidget.setWidth(cw);
  222. this.scroll.add(this.scrollWidget);
  223.  
  224. this.canvasElement = new qx.html.Element("canvas", null, {
  225. id : "map",
  226. width : cw,
  227. height : ch
  228. });
  229. this.canvasElement.addListener("appear", function () {
  230. //console.log("appeared:" + this.canvasElement.getDomElement());
  231. this.createMapCanvas();
  232. }, this);
  233. this.scrollWidget.getContentElement().add(this.canvasElement);
  234. },
  235.  
  236. init_settingsWnd : function () {
  237. try {
  238. /* select box for alliances */
  239. var selectBox = new qx.ui.form.SelectBox();
  240. var _this = this;
  241. selectBox.addListener("changeSelection", function (e) {
  242. try {
  243. if (e != null && e.getData() && e.getData().length > 0) {
  244. var mod = e.getData()[0].getModel();
  245. console.log("Alliance selected: ");
  246. console.log(mod);
  247. console.log("e.getData()[0]: ");
  248. console.log(e.getData()[0]);
  249.  
  250. this.visOptions.selectedAllianceId = mod; // alliance ID or -1 for none
  251. console.log("saved: " + mod);
  252. this.visOptions.selectedAllianceName = this.swObj.allianceListItem[mod].getLabel();
  253. if (this.visOptions.selectedAllianceId != -1) {
  254. this.swObj.chkBoxFields.showAlliancePois.setEnabled(true);
  255. }
  256.  
  257. this.saveOptions();
  258. this.updateMap();
  259. }
  260. } catch (err) {
  261. console.log("alliance changeSelection error:");
  262. console.log(err);
  263. }
  264. }, this);
  265. this.swObj.allianceSelect = selectBox;
  266.  
  267. // this.mapBox.add(selectBox);
  268.  
  269. /* Select box for POI Type */
  270. selectBox = new qx.ui.form.SelectBox();
  271.  
  272. var currentSelection = this.visOptions.poi || -2;
  273. var makePoiItem = function (model, name) {
  274. var item = new qx.ui.form.ListItem(name, null, model);
  275. selectBox.add(item);
  276. if (currentSelection == model) {
  277. selectBox.setSelection([item]);
  278. }
  279. }
  280.  
  281. FPOI = ClientLib.Data.WorldSector.WorldObjectPointOfInterest.EPOIType;
  282. makePoiItem(-2, "<< All >>");
  283. makePoiItem(-1, "<< None >>");
  284. makePoiItem(FPOI.TiberiumMine, "Tiberium");
  285. makePoiItem(FPOI.CrystalMine, "Crystal");
  286. makePoiItem(FPOI.PowerVortex, "Reactor");
  287. makePoiItem(FPOI.Infantery, "Tungsten INF");
  288. makePoiItem(FPOI.Vehicle, "Uranium VEH");
  289. makePoiItem(FPOI.Air, "Aircraft");
  290. makePoiItem(FPOI.Defense, "Resonator DEF");
  291. //makePoiItem(FPOI.TunnelExit,"Tunnel Exit");
  292.  
  293. /* ClientLib.Base.EPOIType is not consistent with ClientLib.Data.WorldSector.WorldObjectPointOfInterest.EPOIType
  294. makePoiItem(ClientLib.Base.EPOIType.AirBonus, "Aircraft GNT (Off Air)");
  295. makePoiItem(ClientLib.Base.EPOIType.CrystalBonus, "Crystal CNH");
  296. makePoiItem(ClientLib.Base.EPOIType.DefenseBonus, "Resonator NT (Def)");
  297. makePoiItem(ClientLib.Base.EPOIType.InfanteryBonus, "Tungsten C (Off Inf)");
  298. makePoiItem(ClientLib.Base.EPOIType.PowerBonus, "Reactor (Power Bonus)");
  299. makePoiItem(ClientLib.Base.EPOIType.TiberiumBonus, "Tiberium CN");
  300. makePoiItem(ClientLib.Base.EPOIType.VehicleBonus, "Uranium C (Off Vehicles)");
  301. */
  302.  
  303. selectBox.addListener("changeSelection", function (e) {
  304. try {
  305. if (e != null && e.getData() && e.getData().length > 0) {
  306. console.log("POI selected " + e.getData()[0].getModel());
  307. _this.visOptions.poi = e.getData()[0].getModel(); // POI ID or -2 for all
  308. this.saveOptions();
  309. this.updateMap();
  310. }
  311. } catch (err) {
  312. console.log(err);
  313. }
  314. }, this);
  315. this.swObj.poiSelect = selectBox;
  316.  
  317.  
  318. /* Settings Window */
  319. this.settingsWnd = new qx.ui.window.Window("Map Settings");
  320. this.settingsWnd.setPadding(10);
  321. //this.mapBox.setLayout(new qx.ui.layout.Grow());
  322.  
  323. var layout = new qx.ui.layout.Grid();
  324. layout.setSpacing(5);
  325. layout.setColumnAlign(0, "right", "center");
  326. layout.setColumnAlign(1, "left", "center");
  327. layout.setColumnAlign(2, "left", "center");
  328. layout.setColumnAlign(3, "right", "center");
  329. layout.setColumnAlign(4, "left", "center");
  330. this.settingsWnd.setLayout(layout);
  331. this.settingsWnd.setShowMaximize(false);
  332. this.settingsWnd.setShowMinimize(false);
  333. this.settingsWnd.moveTo(this.visOptions.settingsWndBounds.left, this.visOptions.settingsWndBounds.top);
  334. this.settingsWnd.setHeight(this.visOptions.settingsWndBounds.height);
  335. this.settingsWnd.setWidth(this.visOptions.settingsWndBounds.width);
  336. this.settingsWnd.setMinWidth(10);
  337. this.settingsWnd.setMinHeight(10);
  338. this.settingsWnd.addListener("close", function () {
  339. this.visOptions.settingsWndBounds = this.settingsWnd.getBounds();
  340. this.saveOptions();
  341. }, this);
  342.  
  343. /* Reset Button */
  344. var resetAllOptions = new qx.ui.form.Button("Full Reset");
  345. resetAllOptions.set({
  346. appearance : "button-text-small",
  347. toolTipText : '<div style="color:#F22">Reset All options to default</div>',
  348. });
  349.  
  350. resetAllOptions.addListener("click", function () {
  351. if (confirm("Are you sure? This will return all settings to default.")) {
  352. if (isNaN(this.visOptions.settingsPanel.zoomFactor)) this.visOptions.settingsPanel.zoomFactor = 3;
  353. this.visOptions = JSON.parse(JSON.stringify(this.visOpt_DEFAULTS));
  354. this.saveOptions();
  355. for (var option in this.visOptions.chk) {
  356. //console.log("this.visOptions.chk." + option + " == " + this.visOptions.chk[option]);
  357. if (this.swObj.chkBoxFields[option]) {
  358. this.swObj.chkBoxFields[option].setValue(this.visOptions.chk[option]);
  359. } else {
  360. console.log(option + " ::: chkBoxFields does not exist.")
  361. }
  362. }
  363. for (var option in this.visOptions.settingsPanel) {
  364. if (option == "chk") {
  365. //do nothing
  366. } else if (this.swObj.settingFields[option]) {
  367. this.swObj.settingFields[option].setValue(String(this.visOptions.settingsPanel[option]));
  368. } else {
  369. console.log(option + " :: settingFields does not exist.")
  370. }
  371. }
  372. this.updateMap();
  373. this.scrollMapBox(false);
  374. }
  375. }, this);
  376. this.settingsWnd.add(resetAllOptions, {
  377. row : 14,
  378. column : 4
  379. });
  380.  
  381. this.makeLbl("- Highlight -", 0, 0);
  382. this.makeLbl("Alliance POIs:", 1, 0);
  383. this.settingsWnd.add(this.swObj.allianceSelect, { row : 1, column : 1 });
  384.  
  385. this.refreshIcon = new qx.ui.basic.Image("FactionUI/icons/icon_refresh_funds.png");
  386. this.settingsWnd.add(this.refreshIcon, { row : 1,column : 2 });
  387.  
  388. this.refreshIcon.addListener("click", function () {
  389. this.populateAllianceSelect();
  390. }, this);
  391.  
  392. this.makeLbl("POIs:", 2, 0);
  393. this.settingsWnd.add(this.swObj.poiSelect, {
  394. row : 2,
  395. column : 1
  396. });
  397. this.makeLbl("Alliance POIs:", 3, 0);
  398. /* Checkbox for alliance POIs */
  399. this.makeCheckbox("showAlliancePois",3,1);
  400. if (this.visOptions.selectedAllianceId == -1) {
  401. this.swObj.chkBoxFields.showAlliancePois.setEnabled(false);
  402. }
  403. this.makeLbl("Own Cities:", 4, 0);
  404. /* Checkbox for own bases */
  405. this.makeCheckbox("showOwnCities",4,1);
  406. this.makeLbl("Viewport Frame:", 5, 0);
  407. /* Checkbox for showSectionFrame */
  408. this.makeCheckbox("showSectionFrame",5,1);
  409.  
  410. bt = new qx.ui.basic.Label("- Colors -").set({
  411. value : '<a href="http://www.w3schools.com/html/html_colornames.asp" style="font-size:16px;font-weight:bold;color:orange" target="_blank">- Colors -</a>',
  412. rich : true,
  413. selectable : true
  414. });
  415. this.settingsWnd.add(bt, {
  416. row : 6,
  417. column : 1,
  418. });
  419. // bt.addListener("click", function() { window.open("http://www.w3schools.com/html/html_colornames.asp") });
  420.  
  421.  
  422. this.makeLbl("Alliance Terrain:", 7, 0);
  423. this.makeTxt("allianceTerrainColor", 7, 1);
  424.  
  425. this.makeLbl("Forg. Base:", 8, 0);
  426. this.makeTxt("baseColor", 8, 1);
  427.  
  428. this.makeLbl("Camp:", 9, 0);
  429. this.makeTxt("campColor", 9, 1);
  430.  
  431. this.makeLbl("Player:", 10, 0);
  432. this.makeTxt("playerColor", 10, 1);
  433.  
  434. this.makeLbl("Enemy:", 11, 0);
  435. this.makeTxt("enemyBaseColor", 11, 1);
  436. //this.swObj.settingFields.enemyBaseColor.setEnabled(false);
  437.  
  438. this.makeLbl("Outpost:", 12, 0);
  439. this.makeTxt("outpostColor", 12, 1);
  440.  
  441. this.makeLbl("POI:", 13, 0);
  442. this.makeTxt("poiColor", 13, 1);
  443.  
  444. this.makeLbl("Tunnel:", 14, 0);
  445. this.makeTxt("tunnelColor", 14, 1);
  446.  
  447. this.makeLbl("Own Base:", 15, 0);
  448. this.makeTxt("ownBaseColor", 15, 1);
  449. //this.swObj.settingFields.ownBaseColor.setEnabled(false);
  450.  
  451. this.makeLbl("Highlight:", 16, 0);
  452. this.makeTxt("highlightColor", 16, 1);
  453. //this.swObj.settingFields.highlightColor.setEnabled(false);
  454.  
  455. /* Line Options */
  456. this.makeLbl(",.-^-.,", 0, 2, "'-.,.-'", "green");
  457.  
  458. this.makeLbl("- Line -", 0, 3);
  459.  
  460.  
  461. this.makeLbl("Show Line", 1, 3);
  462. /* Checkbox for showBorderLine1 */
  463. this.makeCheckbox("showBorderLine1",1,4);
  464.  
  465. this.makeLbl("Line Start:", 2, 3);
  466. this.makeTxt("line1start", 2, 4);
  467. this.makeCoordsSelectionButton("line1start", 2, 5, "\u2607");
  468.  
  469. this.makeLbl("Line End:", 3, 3);
  470. this.makeTxt("line1end", 3, 4);
  471. this.makeCoordsSelectionButton("line1end", 3, 5, "\u2613");
  472.  
  473. this.makeLbl("Line 1 Color:", 4, 3);
  474. this.makeTxt("line1color", 4, 4);
  475.  
  476. this.makeLbl("Show Line 2", 5, 3);
  477. /* Checkbox for showBorderLine2 */
  478. this.makeCheckbox("showBorderLine2",5,4);
  479.  
  480. this.makeLbl("Line Start:", 6, 3);
  481. this.makeTxt("line2start", 6, 4);
  482. this.makeCoordsSelectionButton("line2start", 6, 5, "\u2607");
  483.  
  484. this.makeLbl("Line End:", 7, 3);
  485. this.makeTxt("line2end", 7, 4);
  486. this.makeCoordsSelectionButton("line2end", 7, 5, "\u2613");
  487.  
  488. this.makeLbl("Line 2 Color:", 8, 3);
  489. this.makeTxt("line2color", 8, 4);
  490.  
  491. this.makeLbl("Fade Map ?", 9, 3);
  492. this.makeCheckbox("fadeMap",9, 4);
  493.  
  494.  
  495. /* Zoom Buttons */
  496. this.makeLbl("Zoom Experimental!", 11, 4, null, "red");
  497. this.makeLbl("Zoom Factor:", 12, 3);
  498. this.makeTxt("zoomFactor", 12, 4);
  499. this.swObj.settingFields.zoomFactor.setValue(String(this.initZoom));
  500. this.swObj.settingFields.zoomFactor.setTextAlign("right");
  501. this.swObj.settingFields.zoomFactor.setEnabled(false);
  502. var btnZoomIn = new qx.ui.form.Button("Zoom In");
  503. btnZoomIn.set({
  504. appearance : "button-text-small",
  505. toolTipText : '<div style="color:#FFAAAA">!!!</div>you might need to reload after zooming in',
  506. });
  507. btnZoomIn.addListener("click", function () {
  508. if (isNaN(this.visOptions.settingsPanel.zoomFactor)) this.visOptions.settingsPanel.zoomFactor = 3;
  509. //increment +0.2
  510. this.visOptions.settingsPanel.zoomFactor = Math.round((this.visOptions.settingsPanel.zoomFactor + 0.2) * 10) / 10;
  511. this.swObj.settingFields.zoomFactor.setValue(String(this.visOptions.settingsPanel.zoomFactor));
  512. this.saveOptions();
  513. //this.fixScrollBounds();
  514. this.updateMapDelayed();
  515. this.scrollMapBox(true); // re-center
  516. }, this);
  517. this.settingsWnd.add(btnZoomIn, {
  518. row : 13,
  519. column : 3,
  520. });
  521.  
  522. var btnZoomOut = new qx.ui.form.Button("Zoom Out");
  523. btnZoomOut.set({
  524. appearance : "button-text-small",
  525. //toolTipText : "tuO mooZ"
  526. });
  527. this.settingsWnd.add(btnZoomOut, {
  528. row : 13,
  529. column : 4
  530. });
  531. btnZoomOut.addListener("click", function () {
  532. if (isNaN(this.visOptions.settingsPanel.zoomFactor)) this.visOptions.settingsPanel.zoomFactor = 3;
  533. this.visOptions.settingsPanel.zoomFactor = Math.round((this.visOptions.settingsPanel.zoomFactor - 0.2) * 10) / 10;
  534. this.swObj.settingFields.zoomFactor.setValue(String(this.visOptions.settingsPanel.zoomFactor));
  535. this.saveOptions();
  536. this.updateMap();
  537. this.scrollMapBox(false); // re-center
  538. }, this);
  539.  
  540. /* "Apply" button */
  541. var applyOptions = new qx.ui.form.Button("\u2611");
  542. applyOptions.set({
  543. appearance : "button-text-small",
  544. toolTipText : "Save and apply changes to lines colors"
  545. });
  546. applyOptions.addListener("click", function () {
  547. this.saveOptions();
  548. this.updateMap();
  549. this.scrollMapBox(false);
  550. }, this);
  551. this.settingsWnd.add(applyOptions, {
  552. row : 16,
  553. column : 5
  554. });
  555.  
  556. /* this.settingsWnd.addListener("appear", function () {
  557. console.log("settingsWnd appear event fired");
  558. // this.populateAllianceSelect();
  559. }, this);
  560. */
  561.  
  562. this.swObj.isLoaded = true;
  563. } catch (err) {
  564. console.log(err);
  565. }
  566. },
  567.  
  568. setMapUpdateTimer : function () {
  569. var _this = this;
  570. clearTimeout(this.mapUpdateTimer);
  571. if (this.mapBox.isVisible()){
  572. this.mapUpdateTimer = setTimeout(function (){
  573. _this.updateMap();
  574. _this.scrollMapBox();
  575. }, 1000);
  576. }
  577. },
  578.  
  579. init_mapBox_listeners : function () {
  580. // Gets called A LOT while "scrolling"
  581. phe.cnc.Util.attachNetEvent(ClientLib.Vis.VisMain.GetInstance().get_Region(), "PositionChange", ClientLib.Vis.PositionChange, this, this.setMapUpdateTimer);
  582.  
  583. this.mapBox.addListener("close", function () {
  584. if (this.settingsWnd.isVisible()) {
  585. this.visOptions.settingsWndBounds = this.settingsWnd.getBounds();
  586. this.settingsWnd.close();
  587. }
  588.  
  589. this.visOptions.mapBoxBounds = this.mapBox.getBounds();
  590. this.saveOptions();
  591. }, this);
  592.  
  593. this.mapBox.addListener("blur", function () {
  594. var _this = this;
  595. this.blurInterval = setInterval(function () {
  596. if (!_this.settingsWnd.isVisible() && _this.visOptions.chk.fadeMap) {
  597. _this.mapBox.setOpacity(0.5);
  598. clearInterval(this.blurInterval);
  599. }
  600. }, 1000)
  601. }, this);
  602. this.mapBox.addListener("focus", function () {
  603. //console.log("focus");
  604. clearInterval(this.blurInterval);
  605. this.mapBox.setOpacity(1);
  606. }, this);
  607. this.mapBox.addListener("mouseover", function () {
  608. this.mapBox.focus();
  609. }, this);
  610.  
  611. this.mapBox.addListener("resize", function () {
  612. var _this = this;
  613. setTimeout(function (e) {
  614. _this.scrollMapBox(false);
  615. }, 1000);
  616. //console.log("resized");
  617. //this.updateMap();
  618. }, this);
  619. },
  620.  
  621. init_settingsButton : function () {
  622. /* Settings Button */
  623. var bt = new qx.ui.form.Button("Settings");
  624. bt.set({
  625. appearance : "button-text-small",
  626. toolTipText : "Set filters for the map"
  627. });
  628. bt.addListener("click", function () {
  629. if (this.settingsWnd.isVisible()) {
  630. this.settingsWnd.close();
  631. } else {
  632. this.settingsWnd.moveTo(this.visOptions.settingsWndBounds.left, this.visOptions.settingsWndBounds.top);
  633. this.settingsWnd.open();
  634. }
  635. }, this);
  636. this.mapBox.getChildControl("captionbar").add(bt, {
  637. row : 0,
  638. column : 5
  639. });
  640. },
  641.  
  642. init_mapMouse : function () {
  643. var cw = this.canvasWidth;
  644. var ch = this.canvasHeight;
  645.  
  646. //this.mapMouseWidget.removeAll();
  647. //this.scrollWidget.removeAll();
  648. var vW = this.visOptions.vpWidth;
  649. var vH = this.visOptions.vpHeight;
  650. this.mapMouseWidget = new qx.html.Element("canvas", null, {
  651. id : "mapCursor",
  652. width : cw,
  653. height : ch
  654. });
  655. var cnv = this.mapMouseWidget.getDomElement();
  656. this.mapMouseCanvas = cnv;
  657. var ctx = this.mapMouseCanvas.getContext('2d');
  658. ctx.strokeStyle = "rgb(200,0,0)";
  659. ctx.lineWidth = 1;
  660. ctx.beginPath();
  661. ctx.moveTo(vW / 2, vH / 2);
  662. ctx.lineTo(cw, ch);
  663. ctx.stroke();
  664. },
  665.  
  666. createMapCanvas : function () {
  667. try {
  668. var canvas = this.canvasElement.getDomElement();
  669. if (this.mapCanvas == null) {
  670. this.mapCanvas = canvas;
  671. var _this = this;
  672. /*
  673. this.mapCanvas.addEventListener("mousedown", function (evt) {
  674. //start drag tracking
  675. },this);
  676. */
  677. this.mapCanvas.addEventListener("mousedown", function (evt) {
  678. try {
  679. var cnv = _this.mapCanvas.getBoundingClientRect();
  680. var mouseX = evt.clientX - cnv.left;
  681. var mouseY = evt.clientY - cnv.top;
  682. var zf = _this.visOptions.settingsPanel.zoomFactor;
  683. //console.log("clientX:Y:" + evt.clientX + ":" + evt.clientY);
  684. //console.log("offsets:" + cnv.left + "," + cnv.top);
  685. //console.log("M:" + mouseX + "," + mouseY);
  686.  
  687. var vm = ClientLib.Vis.VisMain.GetInstance();
  688. vm.CenterGridPosition(mouseX / zf, mouseY / zf);
  689.  
  690. _this.scrollMapBox(true);
  691.  
  692. setTimeout(function () {
  693. _this.updateMap();
  694. }, 500);
  695. } catch (err) {
  696. console.log(err);
  697. }
  698. }, false);
  699.  
  700. }
  701. this.updateMap();
  702. this.scrollMapBox(false);
  703. } catch (err) {
  704. console.log("createMapCanvas error:");
  705. console.log(err);
  706. }
  707. },
  708.  
  709. fixScrollBounds : function () {
  710. try {
  711. var cw = this.canvasWidth;
  712. var ch = this.canvasHeight;
  713. /*
  714. this.scrollWidget.setMinHeight(ch);
  715. this.scrollWidget.setMinWidth(cw);
  716. this.scrollWidget.setHeight(ch);
  717. this.scrollWidget.setWidth(cw);
  718. */
  719. this.canvasElement.removeAll();
  720. this.canvasElement = new qx.html.Element("canvas", null, {
  721. id : "map",
  722. width : cw,
  723. height : ch
  724. });
  725. //this.mapCanvas = this.canvasElement.getDomElement();
  726. this.createMapCanvas();
  727. /*
  728. var ctx = this.mapCanvas.getContext('2d');
  729. ctx.clearRect(0, 0, canvas.width, canvas.height);
  730. ctx.canvas.height = ch;
  731. ctx.canvas.width = cw;
  732. */
  733. } catch (e) {
  734. console.log("foooooooooooooook: ");
  735. console.log(e);
  736. }
  737. },
  738.  
  739. scrollMapBox : function (preFrameFlag) {
  740. // ScrollTo
  741. try {
  742. var vm = ClientLib.Vis.VisMain.GetInstance();
  743. var zf = parseFloat(this.visOptions.settingsPanel.zoomFactor);
  744.  
  745. var viewTopLeftX = vm.get_Region().get_PosX() / vm.get_Region().get_GridWidth() * zf;
  746. var viewTopLeftY = vm.get_Region().get_PosY() / vm.get_Region().get_GridHeight() * zf;
  747. var viewWidth = vm.get_Region().get_ViewWidth() / vm.get_Region().get_ZoomFactor() / vm.get_Region().get_GridWidth() * zf;
  748. var viewHeight = vm.get_Region().get_ViewHeight() / vm.get_Region().get_ZoomFactor() / vm.get_Region().get_GridHeight() * zf;
  749.  
  750. var ownCity = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentOwnCity();
  751. var cx = ownCity.get_PosX();
  752. var cy = ownCity.get_PosY();
  753. //console.log("city: "+cx*zf+","+cy*zf);
  754. //console.log("view: "+viewTopLeftX+","+viewTopLeftY);
  755. //console.log("vh: "+viewHeight);
  756. //console.log("vw: "+viewWidth);
  757.  
  758. var mb = this.mapBox.getBounds();
  759. this.scroll.setWidth(mb.width - 37);
  760. this.scroll.setHeight(mb.height - 70);
  761. var wd = Math.round((mb.width - 37) / 2);
  762. var ht = Math.round((mb.height - 70) / 2);
  763. this.visOptions.vpWidth = wd;
  764. this.visOptions.vpHeight = ht;
  765. //console.log("wd: "+wd);
  766. //console.log("ht: "+ht);
  767.  
  768. var sx = this.scroll.getScrollX();
  769. var sy = this.scroll.getScrollY();
  770. var stx = Math.round((viewTopLeftX + (viewWidth / 2)) - wd);
  771. this.scroll.scrollToX(stx);
  772. var sty = Math.round((viewTopLeftY + (viewHeight / 2)) - ht);
  773. this.scroll.scrollToY(sty);
  774.  
  775. if (this.visOptions.chk.showSectionFrame && preFrameFlag) {
  776. var ctx = this.mapCanvas.getContext('2d');
  777. ctx.strokeStyle = "rgba(255,0,0,0.5)";
  778. ctx.lineWidth = 1;
  779. ctx.strokeRect(viewTopLeftX, viewTopLeftY, viewWidth, viewHeight);
  780. }
  781. } catch (err) {
  782. console.log("scrollMapBox error:");
  783. console.log(err);
  784. }
  785. },
  786.  
  787. makeLbl : function (name, r, c, tooltiptxt, color) {
  788. var lbl = this.swObj.labels["r"+r+"c"+c] = new qx.ui.basic.Label(name);
  789. lbl.setTextColor(color || "white");
  790. lbl.setToolTipText(tooltiptxt || "");
  791. lbl.setHeight(28);
  792. this.settingsWnd.add(lbl, {
  793. row : r,
  794. column : c
  795. });
  796. },
  797.  
  798. makeTxt : function (option, r, c, color) {
  799. var value = this.visOptions.settingsPanel[option];
  800. var txtField = new qx.ui.form.TextField(String(value));
  801. txtField.setTextColor(color || "white");
  802. this.swObj.settingFields[option] = txtField;
  803. this.settingsWnd.add(txtField, {
  804. row : r,
  805. column : c
  806. });
  807. },
  808.  
  809. makeCheckbox : function (option, r, c) {
  810. var o = this.swObj.chkBoxFields[option] = new qx.ui.form.CheckBox();
  811. o.setValue(this.visOptions.chk[option]);
  812. o.addListener("changeValue", function () {
  813. this.visOptions.chk[option] = o.getValue();
  814. this.saveOptions();
  815. this.updateMap();
  816. },this);
  817. this.settingsWnd.add(o, {
  818. row : r,
  819. column : c
  820. });
  821. },
  822.  
  823. makeCoordsSelectionButton : function (option, row, col, text) {
  824. this.swObj.coordButtons[option] = new qx.ui.form.Button(text).set({
  825. appearance : "button-text-small",
  826. toolTipText : "Select a target or your own base on the map then click this to get the coords"
  827. });
  828. this.settingsWnd.add(this.swObj.coordButtons[option], {
  829. row : row,
  830. column : col
  831. });
  832. this.swObj.coordButtons[option].setWidth(30);
  833. this.swObj.coordButtons[option].addListener("click", function () {
  834. var x,
  835. y;
  836. var selObj = ClientLib.Vis.VisMain.GetInstance().get_SelectedObject();
  837. //console.log(selObj);
  838. var notSelObj = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentCity() || ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentOwnCity();
  839. //console.log(notSelObj);
  840. if (selObj != null) {
  841. x = selObj.get_RawX();
  842. y = selObj.get_RawY();
  843. } else if (notSelObj != null) {
  844. x = notSelObj.get_PosX();
  845. y = notSelObj.get_PosY();
  846. }
  847. var str = x + ":" + y;
  848.  
  849. this.swObj.settingFields[option].setValue(str);
  850. this.saveOptions();
  851. this.updateMap();
  852.  
  853. }, this);
  854. },
  855.  
  856. updateMapDelayed : function () {
  857. var _this = this;
  858. setTimeout(function(){
  859. _this.updateMap();
  860. },1000);
  861. },
  862.  
  863. updateMap : function () {
  864. this.drawingNow = true;
  865. var md = ClientLib.Data.MainData.GetInstance();
  866. var w = ClientLib.Data.MainData.GetInstance().get_World();
  867. var vm = ClientLib.Vis.VisMain.GetInstance(); //get_Region().get_ViewWidth()
  868. var rg = ClientLib.Vis.VisMain.GetInstance().get_Region(); // GetObjectFromPosition(oporcamp,coords).get_CampType()
  869. var canvas = this.mapCanvas;
  870. var ctx = canvas.getContext('2d');
  871. var zf = parseFloat(this.visOptions.settingsPanel.zoomFactor);
  872. var alliance = md.get_Alliance();
  873. var cx = 0;
  874. var cy = 0;
  875. var gw = rg.get_GridWidth();
  876. var gh = rg.get_GridHeight();
  877. var hilitePois = [];
  878. var sectors = this.getSectors(w);
  879.  
  880.  
  881. ctx.clearRect(0, 0, canvas.width, canvas.height);
  882.  
  883. /* ERelationType
  884. // Ally Enemy NAP Neutral None
  885. // 1 3 2 4 0
  886. // ClientLib.Data.MainData.GetInstance().get_Alliance().GetAllianceRelationshipsByType(webfrontend.gui.alliance.DiplomacyPage.ERelationTypeEnemy).l
  887. */
  888. this.relations.enemies = md.get_Alliance().GetAllianceRelationshipsByType(webfrontend.gui.alliance.DiplomacyPage.ERelationTypeEnemy, true).l;
  889. this.relations.allies = md.get_Alliance().GetAllianceRelationshipsByType(webfrontend.gui.alliance.DiplomacyPage.ERelationTypeAlly, true).l;
  890. this.relations.nap = md.get_Alliance().GetAllianceRelationshipsByType(webfrontend.gui.alliance.DiplomacyPage.ERelationTypeNAP, true).l;
  891.  
  892. this.relations.enemiesById = this.makeHash(this.relations.enemies, "OtherAllianceId");
  893. //console.log(this.relations.enemiesById);
  894.  
  895. /* for (var i in this.relations.enemies){
  896. console.log(this.relations.enemies[i]);
  897. this.relations.enemies[i].Id;
  898. this.relations.enemies[i].OtherAllianceName;
  899. this.relations.enemies[i].OtherAllianceId;
  900. } */
  901.  
  902. if (!this.swObj.obfAllianceId)
  903. this.swObj.obfAllianceId = this.getMemberNameByType(alliance, "number", 0);
  904. if (!this.swObj.obfAllianceName)
  905. this.swObj.obfAllianceName = this.getMemberNameByType(alliance, "string", 0);
  906.  
  907. var allianceName = alliance[this.swObj.obfAllianceName];
  908.  
  909. var sCount = 0;
  910. // Main Drawing Loop
  911. for (var i in sectors) {
  912. var s = sectors[i];
  913. sCount++;
  914. for (var x = 0; x < 32; x++) {
  915. for (var y = 0; y < 32; y++) {
  916. cx = s.ConvertToWorldX(x);
  917. cy = s.ConvertToWorldY(y);
  918. var wObj = w.GetObjectFromPosition(cx, cy);
  919. var rgObj = rg.GetObjectFromPosition(cx * gw, cy * gh);
  920.  
  921. if (wObj != null) {
  922. switch (wObj.Type) {
  923. case 1: {
  924. // player city
  925. // console.log("sector id: "+s.get_Id());
  926. var player = s.GetPlayerId(wObj);
  927. var alliance = s.GetAlliance(player.Alliance);
  928. if (player)
  929. console.log("p" + player);
  930. if (alliance)
  931. console.log("a" + alliance);
  932. if (alliance != null && this.visOptions.selectedAllianceId == alliance) {
  933. // broken
  934. ctx.fillStyle = this.visOptions.settingsPanel.highlightColor; // color var used below for POI highlighting
  935. ctx.fillRect(cx * zf, cy * zf, zf, zf);
  936. /* } else if (this.relations.enemiesById[allianceId]) {
  937. //} else if (this.isEnemy(enemies, alliance, s)) {
  938. // broken
  939. console.log("Enemy found: ");
  940. console.log(wObj);
  941. ctx.fillStyle = this.visOptions.settingsPanel.enemyBaseColor;
  942. ctx.fillRect(cx * zf, cy * zf, zf, zf);
  943. */
  944. } else {
  945. if (wObj.PlayerId && s.GetPlayerId(wObj).Id == md.get_Player().id) {
  946. ctx.fillStyle = this.visOptions.settingsPanel.ownBaseColor;
  947. } else {
  948. ctx.fillStyle = this.visOptions.settingsPanel.playerColor;
  949. }
  950. ctx.fillRect(cx * zf, cy * zf, zf, zf);
  951. }
  952. break;
  953. }
  954. case 2: {
  955. // forgotten base
  956. ctx.fillStyle = this.visOptions.settingsPanel.baseColor;
  957. ctx.fillRect(cx * zf, cy * zf, zf, zf);
  958. break;
  959. }
  960. case 3: {
  961. // Camp/Outpost
  962. // rgObj.get_VisObjectType() 15
  963. // CampType 2 / 3
  964. // current obf prop name GIVCUM
  965. // region might have a better solution
  966.  
  967. ctx.fillStyle = (rgObj && rgObj.get_CampType && rgObj.get_CampType() == 3) ? this.visOptions.settingsPanel.outpostColor : this.visOptions.settingsPanel.campColor;
  968. ctx.fillRect(cx * zf, cy * zf, zf, zf);
  969. break;
  970. }
  971. case 4: {
  972. // POI or tunnel
  973. /*
  974. Type:ClientLib.Data.WorldSector.WorldObjectPointOfInterest
  975. System.Int32 Id
  976. ClientLib.Data.WorldSector.WorldObjectPointOfInterest.EPOIType POIType
  977. System.Int32 Level
  978. System.Int64 OwnerAllianceId
  979. System.String OwnerAllianceName
  980. System.Void .ctor (ClientLib.Data.WorldSector.ObjectType type ,ClientLib.Data.World world ,System.String details ,System.Int32 pos)
  981. wObj: {} -->
  982. wObj.Type: 4
  983. wObj.SequenceId: 6805
  984. wObj.BNDYIS: 39
  985. wObj.MYTWLL: 1
  986. wObj.ADKRPM: 8527
  987. wObj.YQTUPE: 123
  988. wObj.HIFKIQ: "Alliance Name"
  989. wObj.LSVKAD: {} -->
  990. */
  991.  
  992. //console.log("POI/Tunnel ("+cx+":"+cy+" POIType:"+wObj[this.getNameByIdx(wObj,3)]+"):\n"+this.dump(wObj,"wObj",1,true));
  993.  
  994. if (!this.obfPOIType) {
  995. this.obfPOIType = this.getNameByIdx(wObj, 3);
  996. }
  997. if (!this.obfWorldObjectPointOfInterestAllianceName) {
  998. this.obfWorldObjectPointOfInterestAllianceName = this.getMemberNameByType(wObj, "string", 0);
  999. }
  1000. if (!this.obfWorldObjPOIAllyId) {
  1001. this.obfWorldObjPOIAllyId = this.getNameByIdx(wObj, 5);
  1002. }
  1003.  
  1004. if (wObj[this.obfPOIType] == 0) {
  1005. // Tunnel
  1006. ctx.fillStyle = this.visOptions.settingsPanel.tunnelColor;
  1007. } else {
  1008. // POI
  1009. ctx.fillStyle = this.visOptions.settingsPanel.poiColor;
  1010.  
  1011. // if not checked
  1012. if (!this.visOptions.chk.showAlliancePois) {
  1013. if (this.visOptions.poi == -2) {
  1014. // Selected POI = << All >>
  1015. hilitePois.push([cx, cy]);
  1016. } else if (this.visOptions.poi && this.visOptions.poi == wObj[this.obfPOIType]) {
  1017. // for some reasons, the constants in ClientLib are off by 1 [offset corrected]
  1018. hilitePois.push([cx, cy]);
  1019. }
  1020. // if checked & current POI is from selected Alliance
  1021. } else if (wObj[this.obfWorldObjPOIAllyId] == this.visOptions.selectedAllianceId) {
  1022. // if a poi type is selected & current POI is selected type
  1023. if (this.visOptions.poi >= 0 && this.visOptions.poi == wObj[this.obfPOIType]) {
  1024. // Selected Alliance POI
  1025. hilitePois.push([cx, cy]);
  1026. //if show all POIs selected
  1027. } else if (this.visOptions.poi == -2) {
  1028. // Selected POI = << All >>
  1029. hilitePois.push([cx, cy]);
  1030. } else {
  1031. console.log("perhaps visOptions.poi is empty?!");
  1032. }
  1033. }
  1034.  
  1035. }
  1036. ctx.fillRect(cx * zf, cy * zf, zf, zf);
  1037. break;
  1038. }
  1039. }
  1040. } else {
  1041. var terr = w.GetTerritoryTypeByCoordinates(cx, cy);
  1042.  
  1043. /* ClientLib.Data.ETerritoryType
  1044. // 0 1 2 3 4 5
  1045. // Own, Alliance, Neutral, Enemy, SpawnZone, Restricted */
  1046. switch (terr) {
  1047. case 0 /* ClientLib.Data.ETerritoryType.Own */
  1048. :
  1049. {
  1050. ctx.fillStyle = this.visOptions.settingsPanel.ownBaseColor;
  1051. ctx.fillRect(cx * zf, cy * zf, zf, zf);
  1052. break;
  1053. }
  1054. case 1 /* ClientLib.Data.ETerritoryType.Alliance */
  1055. :
  1056. {
  1057. ctx.fillStyle = this.visOptions.settingsPanel.allianceTerrainColor;
  1058. ctx.fillRect(cx * zf, cy * zf, zf, zf);
  1059. break;
  1060. }
  1061. case 2 /* ClientLib.Data.ETerritoryType.Neutral */
  1062. :
  1063. {
  1064. ctx.fillStyle = "rgba(128,128,128,0.1)";
  1065. ctx.fillRect(cx * zf, cy * zf, zf, zf);
  1066. break;
  1067. }
  1068. case 3 /* ClientLib.Data.ETerritoryType.Enemy */
  1069. :
  1070. {
  1071. if (w.GetOwner(cx, cy) != 1610612736) { // lol
  1072. ctx.fillStyle = "rgba(255,128,0,0.1)";
  1073. ctx.fillRect(cx * zf, cy * zf, zf, zf);
  1074. }
  1075. break;
  1076. }
  1077. /*
  1078. case ClientLib.Data.ETerritoryType.SpawnZone: { // 4
  1079. ctx.fillStyle = "rgba(255,255,0,0.5)";
  1080. ctx.fillRect(cx * zf, cy * zf, zf, zf);
  1081. break;
  1082. }
  1083. case ClientLib.Data.ETerritoryType.Restricted: { // 5
  1084. ctx.fillStyle = "rgba(255,0,255,0.5)";
  1085. ctx.fillRect(cx * zf, cy * zf, zf, zf);
  1086. break;
  1087. }
  1088. */
  1089. }
  1090. }
  1091.  
  1092. if (rgObj != null) {
  1093. switch (rgObj.get_VisObjectType()) {
  1094. /* ClientLib.Vis.VisObject.EObjectType.RegionCityType
  1095. // ClientLib.Vis.VisObject.EObjectType.RegionNPCBase
  1096. // ClientLib.Vis.VisObject.EObjectType.RegionNPCCamp
  1097. // ClientLib.Vis.VisObject.EObjectType.RegionPointOfInterest */
  1098. case 4: { // player
  1099. if (rgObj.get_Type() == 2) {
  1100. var allianceId = rgObj.get_AllianceId();
  1101. //console.log(allianceId);
  1102. if (this.relations.enemiesById[allianceId] != null) {
  1103. //console.log("Enemy found: ");
  1104. //console.log(rgObj);
  1105. //save coords and draw later
  1106. if (!this.relations.enemyCoords[cx]) {
  1107. this.relations.enemyCoords[cx] = [];
  1108. }
  1109. this.relations.enemyCoords[cx][cy] = 1;
  1110. }
  1111. //var playerId = rgObj.get_PlayerId();
  1112. //var playerName = rgObj.get_PlayerName();
  1113. } else if (rgObj.get_Type() == 0) { //self
  1114. //if (rgObj.IsOwnBase()) {
  1115. }
  1116. break;
  1117. }
  1118. case 16: { //POI
  1119. if (rgObj.get_Type() == 0) {
  1120. //Tunnel
  1121. }
  1122. //var ownerId = rgObj.get_OwnerAllianceId(); // returns 0 if owner has no alliance
  1123. //var ownerName = rgObj.get_OwnerAllianceName(); // returns "" if owner has no alliance
  1124. break;
  1125. }
  1126. }
  1127. }
  1128. }
  1129. }
  1130. }
  1131.  
  1132. //console.log("Sector objects scanned: " + sCount);
  1133. // paint enemies
  1134. if (this.visOptions.showEnemies) {
  1135. for (cx in this.relations.enemyCoords) {
  1136. for (cy in this.relations.enemyCoords[cx]) {
  1137. ctx.fillStyle = this.visOptions.settingsPanel.enemyBaseColor;
  1138. ctx.fillRect(cx * zf, cy * zf, zf, zf);
  1139.  
  1140. if (this.visOptions.showEnemyRange) {
  1141. ctx.beginPath();
  1142. ctx.arc(cx * zf, cy * zf, zf * 20, 0 * Math.PI, 2 * Math.PI);
  1143. ctx.fillStyle = "rgba(255,0,0,0.02)";
  1144. //ctx.fillStyle = "rgba(255,0,0,0.01)";
  1145. ctx.fill();
  1146. }
  1147. }
  1148. }
  1149. }
  1150. // paint home bases
  1151. if (this.visOptions.chk.showOwnCities) {
  1152. var ownCities = md.get_Cities().get_AllCities().d;
  1153. for (var i in ownCities) {
  1154. var city = ownCities[i];
  1155. var x = city.get_PosX() * zf;
  1156. var y = city.get_PosY() * zf;
  1157.  
  1158. ctx.strokeStyle = this.visOptions.settingsPanel.ownBaseColor;
  1159.  
  1160. ctx.beginPath();
  1161. ctx.arc(x + zf / 2, y + zf / 2, zf * 20, 0 * Math.PI, 2 * Math.PI);
  1162. ctx.stroke();
  1163.  
  1164. ctx.strokeStyle = "rgba(128,128,128,0.2)";
  1165. ctx.beginPath();
  1166. ctx.arc(x + zf / 2, y + zf / 2, zf * 40, 0 * Math.PI, 2 * Math.PI);
  1167. ctx.stroke();
  1168.  
  1169. }
  1170. }
  1171.  
  1172. // paint hilited pois
  1173. ctx.strokeStyle = this.visOptions.settingsPanel.highlightColor; //"rgba(200,255,200,1)";
  1174. ctx.lineWidth = 1;
  1175.  
  1176. hilitePois.forEach(function (poi) {
  1177. ctx.lineWidth = 1;
  1178. ctx.strokeRect(poi[0] * zf - 2, poi[1] * zf - 2, zf + 4, zf + 4);
  1179. });
  1180.  
  1181. // Section Frame
  1182. var topX = Math.floor(vm.get_Region().get_PosX() / vm.get_Region().get_GridWidth());
  1183. var topY = Math.floor(vm.get_Region().get_PosY() / vm.get_Region().get_GridHeight());
  1184. var width = vm.get_Region().get_ViewWidth() / vm.get_Region().get_ZoomFactor() / vm.get_Region().get_GridWidth();
  1185. var height = vm.get_Region().get_ViewHeight() / vm.get_Region().get_ZoomFactor() / vm.get_Region().get_GridHeight();
  1186. //var zfh = Math.round(0.5 * this.visOptions.settingsPanel.zoomFactor);
  1187. var zfh = zf / 2;
  1188. ctx.strokeStyle = "rgba(0,255,0,0.5)";
  1189. ctx.lineWidth = 1;
  1190. //console.log("Selection:" + topX + "," + topY + "w:" + width + "," + height);
  1191.  
  1192. /* broken
  1193. this.init_mapMouse();
  1194. */
  1195.  
  1196. if (this.visOptions.chk.showSectionFrame) {
  1197. ctx.strokeRect(topX * zf, topY * zf, width * zf, height * zf);
  1198. ctx.fillStyle = "rgba(128,128,128,0.2)";
  1199. ctx.fillRect(topX * zf, topY * zf, width * zf, height * zf);
  1200. }
  1201.  
  1202. //Draw Border line 1
  1203. if (this.visOptions.chk.showBorderLine1) {
  1204. var a = this.visOptions.settingsPanel.line1start.split(":");
  1205. var b = this.visOptions.settingsPanel.line1end.split(":");
  1206. ctx.strokeStyle = this.visOptions.settingsPanel.line1color;
  1207. ctx.lineWidth = zfh;
  1208. ctx.beginPath();
  1209. ctx.moveTo(a[0] * zf + zfh, a[1] * zf + zfh);
  1210. ctx.lineTo(b[0] * zf + zfh, b[1] * zf + zfh);
  1211. ctx.stroke();
  1212. ctx.lineWidth = 1;
  1213. }
  1214.  
  1215. //Draw Border line 2
  1216. if (this.visOptions.chk.showBorderLine2) {
  1217. var a = this.visOptions.settingsPanel.line2start.split(":");
  1218. var b = this.visOptions.settingsPanel.line2end.split(":");
  1219. ctx.strokeStyle = this.visOptions.settingsPanel.line2color;
  1220. ctx.lineWidth = zfh;
  1221. ctx.beginPath();
  1222. ctx.moveTo(a[0] * zf + zfh, a[1] * zf + zfh);
  1223. ctx.lineTo(b[0] * zf + zfh, b[1] * zf + zfh);
  1224. ctx.stroke();
  1225. ctx.lineWidth = 1;
  1226. }
  1227.  
  1228. this.drawingNow = false;
  1229. },
  1230.  
  1231. getSectors : function (w) { // work around obfuscated variable names
  1232. if (this.swObj.obfSectorName == null) {
  1233. // auto-detect sector name
  1234. Outer :
  1235. for (i in w) {
  1236. if (w[i].d) {
  1237. var maybeSector = w[i].d;
  1238. for (j in maybeSector) {
  1239. if (maybeSector[j].ConvertToWorldX) {
  1240. this.swObj.obfSectorName = i;
  1241. //console.log("Sector field:" + i);
  1242. break Outer;
  1243. }
  1244. break;
  1245. }
  1246. }
  1247. }
  1248. }
  1249. if (this.swObj.obfSectorName == null)
  1250. console.log("ERROR: getSectors(): obfuscated property not found!");
  1251. if (this.swObj.obfSectorName != null)
  1252. return w[this.swObj.obfSectorName].d;
  1253.  
  1254. /* if (w.KIH) { // old june version
  1255. return w.KIH.d;
  1256. } else if (w.RBJXOL) { // july
  1257. return w.RBJXOL.d;
  1258. } else if (w.IWEESP) {
  1259. return w.IWEESP.d; // closed beta 2 world
  1260. } else if (w.HYMYNV) { // mid july release
  1261. return w.HYMYNV.d;
  1262. } else if (w.ONQEIH) { // july 18th
  1263. return w.ONQEIH.d;
  1264. }
  1265. */
  1266. },
  1267.  
  1268. getAlliances : function (sector) { // work around obfuscated variable names. sector == current sector
  1269. try {
  1270. if (typeof(sector) == "undefinied" || sector === null) {
  1271. console.log("ERROR: getAlliances(sector): sector is not defined!");
  1272. return null;
  1273. }
  1274. if (this.swObj.obfAllianceList == null) {
  1275. // find alliance list dynamically
  1276.  
  1277. Outer :
  1278. for (i in sector) {
  1279. if (sector[i].d) {
  1280. var maybeAllianceList = sector[i].d;
  1281. for (j in maybeAllianceList) {
  1282. var maybeAlliance = maybeAllianceList[j];
  1283. var propnames = [];
  1284. for (p in maybeAlliance)
  1285. propnames.push(p);
  1286. var stringpropcount = 0;
  1287. var stringpropname = null;
  1288. if (propnames.length == 13) {
  1289. for (k = 0; k < propnames.length; k++) {
  1290. if (typeof(maybeAlliance[propnames[k]]) == "string") {
  1291. stringpropname = propnames[k];
  1292. stringpropcount++;
  1293. }
  1294. }
  1295. if (stringpropcount == 1) {
  1296. this.swObj.obfAllianceId = propnames[1]; //assuming this is allways the case :-)
  1297. this.swObj.obfAllianceName = stringpropname;
  1298. this.swObj.obfAllianceList = i;
  1299. //console.log("Alliances field:" + i);
  1300. break Outer;
  1301. }
  1302. }
  1303. break; // test only the first member
  1304. }
  1305. }
  1306. }
  1307.  
  1308. }
  1309. if (this.swObj.obfAllianceList == null) {
  1310. console.log("ERROR: getAlliances(): obfuscated member not found!");
  1311. return null;
  1312. } else
  1313. return sector[this.swObj.obfAllianceList].d;
  1314. /*
  1315. if (sector.WGH) {// june
  1316. return sector.WGH.d;
  1317. } else if (sector.QEKQND) {//july
  1318. return sector.QEKQND.d;
  1319. } else if (sector.GGUPEV){ // closed beta 2 world
  1320. return sector.GGUPEV.d;
  1321. } else if(sector.UFVPYE) {
  1322. return sector.UFVPYE.d; // July 11, 2012
  1323. } else if(sector.UEQLAO) {
  1324. return sector.UEQLAO.d; // July 18th
  1325. } */
  1326. } catch (err) {
  1327. console.log("getAlliances error:");
  1328. console.log(err);
  1329. }
  1330. },
  1331.  
  1332. makeHash : function (obj, unique) { //original key is written to the property hashKey
  1333. if (obj != null) {
  1334. try {
  1335. var temp = [];
  1336. for (var key in obj) {
  1337. var val = obj[key];
  1338. //console.log(val);
  1339. if (!temp[val[unique]]) {
  1340. temp[val[unique]] = [];
  1341. for (var key2 in obj[key]) {
  1342. if (key2 != unique) {
  1343. temp[val[unique]][key2] = obj[key][key2];
  1344. } else {
  1345. temp[val[unique]]["hashKey"] = key;
  1346. }
  1347. }
  1348. } else {
  1349. console.log("makeHash duplicate entry detected");
  1350. }
  1351.  
  1352. }
  1353. //console.log(temp);
  1354. return temp;
  1355. } catch (err) {
  1356. console.log("makeHash error: ");
  1357. console.log(err);
  1358. }
  1359. } else {
  1360. return false;
  1361. }
  1362. },
  1363.  
  1364. isEnemy : function (enemies, alliance, sector) {
  1365. if (alliance == null)
  1366. return false;
  1367. var enemy = enemies.l.filter(function (ele) {
  1368. return ele.OtherAllianceId == alliance.Id;
  1369. });
  1370. console.log(enemy);
  1371. return enemy.length > 0;
  1372. },
  1373.  
  1374. listAllAlliances : function () {
  1375. var alliances = [];
  1376. var w = ClientLib.Data.MainData.GetInstance().get_World();
  1377. if (!w)
  1378. console.log("ERROR: get_World() failed!");
  1379. var sectors = this.getSectors(w);
  1380. if (!sectors)
  1381. console.log("ERROR: getSectors() failed!");
  1382. for (var i in sectors) { // m_sectors
  1383. var s = sectors[i];
  1384. var all = this.getAlliances(s);
  1385. if (!all)
  1386. console.log("ERROR: getAlliances() failed!");
  1387. for (var j in all) { // m_alliances
  1388. var a = all[j];
  1389. alliances.push({
  1390. id : a[this.swObj.obfAllianceId],
  1391. name : a[this.swObj.obfAllianceName]
  1392. });
  1393. }
  1394. }
  1395. alliances.sort(function (s1, s2) {
  1396. var name1 = s1.name.toLowerCase();
  1397. var name2 = s2.name.toLowerCase();
  1398. if (name1 < name2)
  1399. return -1;
  1400. if (name1 > name2)
  1401. return 1;
  1402. return 0;
  1403. });
  1404. var allianceMap = {};
  1405. alliances.forEach(function (it) {
  1406. allianceMap[it.id] = it;
  1407. });
  1408. return allianceMap;
  1409. },
  1410.  
  1411. populateAllianceSelect : function () {
  1412. console.log("updating Filter");
  1413. var md = ClientLib.Data.MainData.GetInstance();
  1414.  
  1415. this.swObj.allianceSelect.removeAll();
  1416.  
  1417. this.swObj.allianceListItem["-1"] = new qx.ui.form.ListItem("<< None >>", null, -1);
  1418. this.swObj.allianceSelect.add(this.swObj.allianceListItem["-1"]);
  1419.  
  1420. var alliances = this.listAllAlliances(); // expensive operation
  1421. for (i in alliances) {
  1422. var a = alliances[i];
  1423. this.swObj.allianceListItem[a.id] = new qx.ui.form.ListItem(a.name, null, a.id);
  1424. if (a.id == this.visOptions.selectedAllianceId) {
  1425. selectedItem = tempItem;
  1426. }
  1427. this.swObj.allianceSelect.add(this.swObj.allianceListItem[a.id]);
  1428. }
  1429. if (this.visOptions.selectedAllianceId != -1) {
  1430. this.swObj.allianceSelect.setSelection([selectedItem]);
  1431. }
  1432. //this.swObj.allianceSelect.setEnabled(true);
  1433. if (this.visOptions.selectedAllianceId != -1) {
  1434. this.swObj.chkBoxFields.showAlliancePois.setEnabled(true);
  1435. }
  1436. //console.log([selectedItem]);
  1437. this.alliancesAreLoaded = true;
  1438. },
  1439.  
  1440. findAllianceById : function (s, id) {
  1441. var ra = null;
  1442. if (id != 0) {
  1443. for (var x = 1; s.GetAlliance(x) != null; x++) {
  1444. var a = s.GetAlliance(x);
  1445. if (a.FGTNFZ == id) {
  1446. ra = a;
  1447. }
  1448. }
  1449. }
  1450. return ra;
  1451. },
  1452.  
  1453. getMousePos : function (canvas, evt) {
  1454. // get canvas position
  1455. var cnv = canvas;
  1456. var top = 0;
  1457. var left = 0;
  1458. while (cnv && cnv.tagName != 'BODY') {
  1459. top += cnv.offsetTop;
  1460. left += cnv.offsetLeft;
  1461. cnv = cnv.offsetParent;
  1462. }
  1463.  
  1464. // return relative mouse position
  1465. var mouseX = evt.clientX - left + window.pageXOffset;
  1466. var mouseY = evt.clientY - top + window.pageYOffset;
  1467. return {
  1468. x : mouseX,
  1469. y : mouseY
  1470. };
  1471. },
  1472.  
  1473. saveOptions : function () {
  1474. for (var option in this.visOptions.settingsPanel) {
  1475. if (this.swObj.settingFields[option]) {
  1476. this.visOptions.settingsPanel[option] = this.swObj.settingFields[option].getValue();
  1477. } else {
  1478. console.log(option + " : settingFields does not exist. (applyOptions)")
  1479. }
  1480. }
  1481. if (localStorage) {
  1482. var str = JSON.stringify(this.visOptions);
  1483. localStorage.setItem("TAMapStorage", str);
  1484. }
  1485. },
  1486.  
  1487. toggleMap : function () {
  1488.  
  1489. if (this.mapBox.isVisible()) {
  1490. this.visOptions.mapBoxBounds = this.mapBox.getBounds();
  1491. this.saveOptions();
  1492. this.mapBox.close();
  1493. } else {
  1494. this.mapBox.open();
  1495. }
  1496. /*
  1497. //this.mapBox.open();
  1498. //var debugOutput = "";
  1499. //var sector = mainData.get_World().GetWorldSectorByCoords(current_city.get_PosX(), current_city.get_PosY());
  1500. //for (i in sector.m_Objects.d) {
  1501. // debugOutput += JSON.stringify(sector.m_Objects.d[i]) + "<br>";
  1502. //}
  1503. //console.log(debugOutput);
  1504. // this.canvasElement.setValue(debugOutput);
  1505. //var canvas = this.canvasElement.getDomElement();
  1506. //console.log("Canvas:" + canvas);
  1507. //var ctx = canvas.getContext('2d');
  1508. //console.log(ctx);
  1509. //ctx.fillStyle = "rgb(200,0,0)";
  1510. //ctx.fillRect (10, 10, 55, 50);
  1511. */
  1512. },
  1513.  
  1514. getNameByIdx : function (object, idx) {
  1515. var i = 0;
  1516. for (var n in object) {
  1517. if (i == idx)
  1518. return n;
  1519. i++;
  1520. }
  1521. return null;
  1522. },
  1523.  
  1524. getMemberNameByType : function (object, type, idx) {
  1525. var i = 0;
  1526. for (var n in object) {
  1527. var valueType = typeof(object[n]);
  1528. //console.log(n+" "+valueType);
  1529. if (type == valueType) {
  1530. if (i == idx)
  1531. return n;
  1532. i++;
  1533. }
  1534. }
  1535. return null;
  1536. },
  1537.  
  1538. dump : function (object, rootName, deep, includeFunction) {
  1539. //console.log("dump "+rootName);
  1540. var dumpInternal = function (obj, path) {
  1541. //console.log("DEBUG: dumpInternal(obj, "+path+") ind:"+ind+", deep:"+deep+", output.length:"+s.length);
  1542. if (obj === null) {
  1543. s += "" + path + ": {null}" + "\n";
  1544. return;
  1545. } else if (obj === undefined) {
  1546. s += "" + path + ": {undefined}" + "\n";
  1547. return;
  1548. }
  1549. var valueType = typeof(obj);
  1550. switch (valueType) {
  1551. case "function":
  1552. return;
  1553. // try{var fr=obj();}catch(ex){var fr=ex;}
  1554. // s+= "" + path +": "+ "{function} returns: "+fr + "\n";return;
  1555. case "object":
  1556. s += "" + path + ": {} -->" /*+ propValue.toString().substr(0,20)*/
  1557. + "\n";
  1558. break;
  1559. case "boolean":
  1560. s += "" + path + ": " + obj.toString() + "\n";
  1561. return;
  1562. case "number":
  1563. s += "" + path + ": " + obj.toString() + "\n";
  1564. return;
  1565. case "string":
  1566. s += "" + path + ": \"" + obj.toString() + "\"\n";
  1567. return;
  1568. default:
  1569. s += "" + path + " (" + valueType + "): " + obj.toString() + "\n";
  1570. return;
  1571. }
  1572.  
  1573. for (var o in objs) {
  1574. if (o === obj) {
  1575. s += "{!Recursion stoped!}\n";
  1576. return;
  1577. } else
  1578. objs.push(obj);
  1579. }
  1580. var members = [];
  1581. for (var p in obj)
  1582. members.push(p);
  1583. if (members.length > 1000) {
  1584. console.log("WARNING: dump() Too much members! " + members.length);
  1585. return;
  1586. } //TODO
  1587. if (deep > 0 && ind >= deep)
  1588. return;
  1589. if (/.GHPRYH$/.test())
  1590. return; //TODO
  1591. if (path.length > 30) {
  1592. console.log("WARNING: dump() Path too long!");
  1593. return;
  1594. } //TODO
  1595. ind++;
  1596. for (var propName in obj) {
  1597. dumpInternal(obj[propName], path + "." + propName);
  1598. }
  1599. ind--;
  1600. }
  1601. var objs = [];
  1602. var ind = 0;
  1603. var s = "";
  1604. if (typeof(rootName) == 'undefined')
  1605. rootName = "*";
  1606. if (typeof(deep) == 'undefined')
  1607. deep = 1;
  1608. if (typeof(includeFunction) == 'undefined')
  1609. includeFunction = false;
  1610. try {
  1611. dumpInternal(object, rootName);
  1612. } catch (ex) {
  1613. console.log("ERROR: dump() > " + ex);
  1614. }
  1615. return s;
  1616. }
  1617. }
  1618. });
  1619.  
  1620. }
  1621.  
  1622. function TAMap_checkIfLoaded() {
  1623. try {
  1624. if (typeof qx != 'undefined') {
  1625. var a = qx.core.Init.getApplication();
  1626. // application
  1627. var mb = qx.core.Init.getApplication().getMenuBar();
  1628. if (a && mb) {
  1629. createMapTweak();
  1630. window.TAMap.getInstance().initialize();
  1631. } else
  1632. window.setTimeout(TAMap_checkIfLoaded, 1000);
  1633. } else {
  1634. window.setTimeout(TAMap_checkIfLoaded, 1000);
  1635. }
  1636. } catch (err) {
  1637. if (typeof console != 'undefined')
  1638. console.log(err);
  1639. else if (window.opera)
  1640. opera.postError(err);
  1641. else
  1642. GM_log(err);
  1643. }
  1644. }
  1645.  
  1646. if (/commandandconquer\.com/i.test(document.domain)) {
  1647. window.setTimeout(TAMap_checkIfLoaded, 1000);
  1648. }
  1649. }
  1650. // injecting, because there seem to be problems when creating game interface with unsafeWindow
  1651. var TAMapScript = document.createElement("script");
  1652. var txt = TAMap_mainFunction.toString();
  1653. TAMapScript.innerHTML = "(" + txt + ")();";
  1654. TAMapScript.type = "text/javascript";
  1655. if (/commandandconquer\.com/i.test(document.domain)) {
  1656. document.getElementsByTagName("head")[0].appendChild(TAMapScript);
  1657. }
  1658.  
  1659. })();